Browse Source

Documented some stuff

pull/46/head
Anairkoen Schno 6 years ago
parent
commit
cf9634f622
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 Include="UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\Libs\UnityEngine.CoreModule.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>


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

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


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

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


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

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

+ 1
- 2
IllusionPlugin/IniFile.cs View File

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


+ 41
- 3
IllusionPlugin/Logger.cs View File

@ -7,6 +7,9 @@ using System.Threading;
using IllusionPlugin;
namespace IllusionPlugin {
/// <summary>
/// A general purpose logging class for any plugin to use.
/// </summary>
public class Logger {
private static BlockingCollection<logMessage> _logQueue;
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") {
SetupStatic();
_logFile = GetPath(modName);
_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)
{
SetupStatic();
@ -60,24 +71,40 @@ namespace IllusionPlugin {
_logFile.Create().Close();
}
/// <summary>
/// Sends a message to the log.
/// </summary>
/// <param name="msg">the message to send</param>
public void Log(string msg) {
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(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) {
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(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) {
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(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) {
if(!_watcherThread.IsAlive) throw new Exception("Logger is Closed!");
//_logQueue.Add(new logMessage($"[WARNING @ {DateTime.Now:HH:mm:ss} | {ModName}] {msg}", WarningLevel.Warning));
@ -114,7 +141,10 @@ namespace IllusionPlugin {
kvp.Value.Dispose();
}
}
/// <summary>
/// Stops the logger background thread.
/// </summary>
public static void Stop() {
_threadRunning = false;
_watcherThread.Join();
@ -144,7 +174,15 @@ namespace IllusionPlugin {
}
}
/// <summary>
///
/// </summary>
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) {
return new Logger(plugin);
}


+ 12
- 0
IllusionPlugin/ModPrefs.cs View File

@ -15,6 +15,10 @@ namespace IllusionPlugin
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) {
Instance = new IniFile(Path.Combine(Environment.CurrentDirectory, $"UserData/ModPrefs/{plugin.Name}.ini"));
ModPrefses.Add(plugin, this);
@ -159,7 +163,15 @@ namespace IllusionPlugin
}
/// <summary>
/// An extension class for IBeatSaberPlugins.
/// </summary>
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) {
return ModPrefs.ModPrefses.First(o => o.Key == plugin).Value;
}


Loading…
Cancel
Save