Browse Source

Documented some stuff

refactor
Anairkoen Schno 6 years ago
parent
commit
7b6250a75a
7 changed files with 67 additions and 5 deletions
  1. +1
    -0
      IllusionInjector/IllusionInjector.csproj
  2. +3
    -0
      IllusionPlugin/BeatSaber/IEnhancedBeatSaberPlugin.cs
  3. +3
    -0
      IllusionPlugin/IPA/IEnhancedPlugin.cs
  4. +6
    -0
      IllusionPlugin/IPA/IGenericEnhancedPlugin.cs
  5. +1
    -2
      IllusionPlugin/IniFile.cs
  6. +41
    -3
      IllusionPlugin/Logger.cs
  7. +12
    -0
      IllusionPlugin/ModPrefs.cs

+ 1
- 0
IllusionInjector/IllusionInjector.csproj View File

@ -43,6 +43,7 @@
</Reference> </Reference>
<Reference Include="UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> <Reference Include="UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\Libs\UnityEngine.CoreModule.dll</HintPath> <HintPath>..\Libs\UnityEngine.CoreModule.dll</HintPath>
<Private>False</Private>
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>


+ 3
- 0
IllusionPlugin/BeatSaber/IEnhancedBeatSaberPlugin.cs View File

@ -4,6 +4,9 @@ using System.Text;
namespace IllusionPlugin namespace IllusionPlugin
{ {
/// <summary>
/// An enhanced version of a standard BeatSaber plugin.
/// </summary>
public interface IEnhancedBeatSaberPlugin : IBeatSaberPlugin, IGenericEnhancedPlugin public interface IEnhancedBeatSaberPlugin : IBeatSaberPlugin, IGenericEnhancedPlugin
{ {
} }


+ 3
- 0
IllusionPlugin/IPA/IEnhancedPlugin.cs View File

@ -4,6 +4,9 @@ using System.Text;
namespace IllusionPlugin namespace IllusionPlugin
{ {
/// <summary>
/// An enhanced version of the standard IPA plugin.
/// </summary>
[Obsolete("When building plugins for Beat Saber, use IEnhancedBeatSaberPlugin")] [Obsolete("When building plugins for Beat Saber, use IEnhancedBeatSaberPlugin")]
public interface IEnhancedPlugin : IPlugin, IGenericEnhancedPlugin public interface IEnhancedPlugin : IPlugin, IGenericEnhancedPlugin
{ {


+ 6
- 0
IllusionPlugin/IPA/IGenericEnhancedPlugin.cs View File

@ -6,6 +6,9 @@ using System.Threading.Tasks;
namespace IllusionPlugin namespace IllusionPlugin
{ {
/// <summary>
/// A generic interface for the modification for enhanced plugins.
/// </summary>
public interface IGenericEnhancedPlugin public interface IGenericEnhancedPlugin
{ {
/// <summary> /// <summary>
@ -14,6 +17,9 @@ namespace IllusionPlugin
/// <example>{ "PlayClub", "PlayClubStudio" }</example> /// <example>{ "PlayClub", "PlayClubStudio" }</example>
string[] Filter { get; } string[] Filter { get; }
/// <summary>
/// Called after Update.
/// </summary>
void OnLateUpdate(); void OnLateUpdate();
} }
} }

+ 1
- 2
IllusionPlugin/IniFile.cs View File

@ -62,7 +62,7 @@ namespace IllusionPlugin
/// <summary> /// <summary>
/// INIFile Constructor. /// INIFile Constructor.
/// </summary> /// </summary>
/// <PARAM name="INIPath"></PARAM>
/// <PARAM name="iniPath"></PARAM>
public IniFile(string iniPath) public IniFile(string iniPath)
{ {
IniFileInfo = new FileInfo(iniPath); IniFileInfo = new FileInfo(iniPath);
@ -88,7 +88,6 @@ namespace IllusionPlugin
/// </summary> /// </summary>
/// <PARAM name="Section"></PARAM> /// <PARAM name="Section"></PARAM>
/// <PARAM name="Key"></PARAM> /// <PARAM name="Key"></PARAM>
/// <PARAM name="Path"></PARAM>
/// <returns></returns> /// <returns></returns>
public string IniReadValue(string Section, string Key) public string IniReadValue(string Section, string Key)
{ {


+ 41
- 3
IllusionPlugin/Logger.cs View File

@ -7,6 +7,9 @@ using System.Threading;
using IllusionPlugin; using IllusionPlugin;
namespace IllusionPlugin { namespace IllusionPlugin {
/// <summary>
/// A general purpose logging class for any plugin to use.
/// </summary>
public class Logger { public class Logger {
private static BlockingCollection<logMessage> _logQueue; private static BlockingCollection<logMessage> _logQueue;
private static Thread _watcherThread; private static Thread _watcherThread;
@ -47,12 +50,20 @@ namespace IllusionPlugin {
} }
} }
/// <summary>
/// Creates a logger with the specified name.
/// </summary>
/// <param name="modName">the name of the logger</param>
public Logger(string modName = "Default") { public Logger(string modName = "Default") {
SetupStatic(); SetupStatic();
_logFile = GetPath(modName); _logFile = GetPath(modName);
_logFile.Create().Close(); _logFile.Create().Close();
} }
/// <summary>
/// Creates a logger for the specified plugin.
/// </summary>
/// <param name="plugin">the plugin to associate the logger with</param>
public Logger(IBeatSaberPlugin plugin) public Logger(IBeatSaberPlugin plugin)
{ {
SetupStatic(); SetupStatic();
@ -60,24 +71,40 @@ namespace IllusionPlugin {
_logFile.Create().Close(); _logFile.Create().Close();
} }
/// <summary>
/// Sends a message to the log.
/// </summary>
/// <param name="msg">the message to send</param>
public void Log(string msg) { public void Log(string msg) {
if(!_watcherThread.IsAlive) throw new Exception("Logger is Closed!"); if(!_watcherThread.IsAlive) throw new Exception("Logger is Closed!");
//_logQueue.Add(new logMessage($"[LOG @ {DateTime.Now:HH:mm:ss} | {ModName}] {msg}", WarningLevel.Log)); //_logQueue.Add(new logMessage($"[LOG @ {DateTime.Now:HH:mm:ss} | {ModName}] {msg}", WarningLevel.Log));
_logQueue.Add(new logMessage(msg, this, DateTime.Now, WarningLevel.Log)); _logQueue.Add(new logMessage(msg, this, DateTime.Now, WarningLevel.Log));
} }
/// <summary>
/// Sends an error to the log.
/// </summary>
/// <param name="msg">the message to send</param>
public void Error(string msg) { public void Error(string msg) {
if(!_watcherThread.IsAlive) throw new Exception("Logger is Closed!"); if(!_watcherThread.IsAlive) throw new Exception("Logger is Closed!");
//_logQueue.Add(new logMessage($"[ERROR @ {DateTime.Now:HH:mm:ss} | {ModName}] {msg}", WarningLevel.Error)); //_logQueue.Add(new logMessage($"[ERROR @ {DateTime.Now:HH:mm:ss} | {ModName}] {msg}", WarningLevel.Error));
_logQueue.Add(new logMessage(msg, this, DateTime.Now, WarningLevel.Error)); _logQueue.Add(new logMessage(msg, this, DateTime.Now, WarningLevel.Error));
} }
/// <summary>
/// Sends an exception to the log.
/// </summary>
/// <param name="msg">the message to send</param>
public void Exception(string msg) { public void Exception(string msg) {
if(!_watcherThread.IsAlive) throw new Exception("Logger is Closed!"); if(!_watcherThread.IsAlive) throw new Exception("Logger is Closed!");
//_logQueue.Add(new logMessage($"[EXCEPTION @ {DateTime.Now:HH:mm:ss} | {ModName}] {msg}", WarningLevel.Exception)); //_logQueue.Add(new logMessage($"[EXCEPTION @ {DateTime.Now:HH:mm:ss} | {ModName}] {msg}", WarningLevel.Exception));
_logQueue.Add(new logMessage(msg, this, DateTime.Now, WarningLevel.Exception)); _logQueue.Add(new logMessage(msg, this, DateTime.Now, WarningLevel.Exception));
} }
/// <summary>
/// Sends a warning to the log.
/// </summary>
/// <param name="msg">the message to send</param>
public void Warning(string msg) { public void Warning(string msg) {
if(!_watcherThread.IsAlive) throw new Exception("Logger is Closed!"); if(!_watcherThread.IsAlive) throw new Exception("Logger is Closed!");
//_logQueue.Add(new logMessage($"[WARNING @ {DateTime.Now:HH:mm:ss} | {ModName}] {msg}", WarningLevel.Warning)); //_logQueue.Add(new logMessage($"[WARNING @ {DateTime.Now:HH:mm:ss} | {ModName}] {msg}", WarningLevel.Warning));
@ -114,7 +141,10 @@ namespace IllusionPlugin {
kvp.Value.Dispose(); kvp.Value.Dispose();
} }
} }
/// <summary>
/// Stops the logger background thread.
/// </summary>
public static void Stop() { public static void Stop() {
_threadRunning = false; _threadRunning = false;
_watcherThread.Join(); _watcherThread.Join();
@ -144,7 +174,15 @@ namespace IllusionPlugin {
} }
} }
/// <summary>
///
/// </summary>
public static class LoggerExtensions { public static class LoggerExtensions {
/// <summary>
/// Gets a logger for the provided plugin.
/// </summary>
/// <param name="plugin">the plugin to get a logger for</param>
/// <returns>a Logger instance</returns>
public static Logger GetLogger(this IBeatSaberPlugin plugin) { public static Logger GetLogger(this IBeatSaberPlugin plugin) {
return new Logger(plugin); return new Logger(plugin);
} }


+ 12
- 0
IllusionPlugin/ModPrefs.cs View File

@ -15,6 +15,10 @@ namespace IllusionPlugin
private IniFile Instance; private IniFile Instance;
/// <summary>
/// Constructs a ModPrefs object for the provide plugin.
/// </summary>
/// <param name="plugin">the plugin to get the preferences file for</param>
public ModPrefs(IBeatSaberPlugin plugin) { public ModPrefs(IBeatSaberPlugin plugin) {
Instance = new IniFile(Path.Combine(Environment.CurrentDirectory, $"UserData/ModPrefs/{plugin.Name}.ini")); Instance = new IniFile(Path.Combine(Environment.CurrentDirectory, $"UserData/ModPrefs/{plugin.Name}.ini"));
ModPrefses.Add(plugin, this); ModPrefses.Add(plugin, this);
@ -159,7 +163,15 @@ namespace IllusionPlugin
} }
/// <summary>
/// An extension class for IBeatSaberPlugins.
/// </summary>
public static class ModPrefsExtensions { public static class ModPrefsExtensions {
/// <summary>
/// Gets the ModPrefs object for the provided plugin.
/// </summary>
/// <param name="plugin">the plugin wanting the prefrences</param>
/// <returns>the ModPrefs object</returns>
public static ModPrefs GetModPrefs(this IBeatSaberPlugin plugin) { public static ModPrefs GetModPrefs(this IBeatSaberPlugin plugin) {
return ModPrefs.ModPrefses.First(o => o.Key == plugin).Value; return ModPrefs.ModPrefses.First(o => o.Key == plugin).Value;
} }


Loading…
Cancel
Save