Browse Source

Performed some cleanup

pull/1/head
Anairkoen Schno 5 years ago
parent
commit
4412bd2f04
17 changed files with 126 additions and 61 deletions
  1. +4
    -0
      BSIPA.sln.DotSettings
  2. +26
    -19
      IPA.Injector/Injector.cs
  3. +1
    -1
      IPA.Injector/Properties/AssemblyInfo.cs
  4. +7
    -6
      IPA.Loader/Config/ConfigProviders/JsonConfigProvider.cs
  5. +5
    -3
      IPA.Loader/Config/SelfConfig.cs
  6. +1
    -0
      IPA.Loader/IPA.Loader.csproj
  7. +4
    -4
      IPA.Loader/Loader/PluginManifest.cs
  8. +4
    -1
      IPA.Loader/Logging/LogPrinter.cs
  9. +33
    -6
      IPA.Loader/Logging/Logger.cs
  10. +5
    -5
      IPA.Loader/Logging/Printers/GZFilePrinter.cs
  11. +1
    -1
      IPA.Loader/Logging/Printers/GlobalLogFilePrinter.cs
  12. +2
    -2
      IPA.Loader/Logging/Printers/PluginLogFilePrinter.cs
  13. +1
    -1
      IPA.Loader/Logging/Printers/PluginSubLogPrinter.cs
  14. +23
    -3
      IPA.Loader/Logging/StandardLogger.cs
  15. +3
    -3
      IPA.Loader/Updating/SelfPlugin.cs
  16. +6
    -6
      IPA/Properties/AssemblyInfo.cs
  17. BIN
      Refs/UnityEngine.CoreModule.dll

+ 4
- 0
BSIPA.sln.DotSettings View File

@ -1,5 +1,9 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=InconsistentNaming/@EntryIndexedValue">WARNING</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INT_ALIGN_BINARY_EXPRESSIONS/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INT_ALIGN_FIELDS/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INT_ALIGN_METHODS/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INT_ALIGN_PROPERTIES/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=BS/@EntryIndexedValue">BS</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IPA/@EntryIndexedValue">IPA</s:String>


+ 26
- 19
IPA.Injector/Injector.cs View File

@ -1,4 +1,5 @@
using IPA.Injector.Backups;
using IPA.Config;
using IPA.Injector.Backups;
using IPA.Loader;
using IPA.Logging;
using Mono.Cecil;
@ -8,7 +9,6 @@ using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using IPA.Config;
using UnityEngine;
using static IPA.Logging.Logger;
using MethodAttributes = Mono.Cecil.MethodAttributes;
@ -24,8 +24,8 @@ namespace IPA.Injector
public static void Main(string[] args)
{ // entry point for doorstop
// At this point, literally nothing but mscorlib is loaded,
// and since this class doesn't have any static fields that
// aren't defined in mscorlib, we can control exactly what
// and since this class doesn't have any static fields that
// aren't defined in mscorlib, we can control exactly what
// gets loaded.
try
@ -38,7 +38,7 @@ namespace IPA.Injector
SelfConfig.Set();
loader.Debug("Prepping bootstrapper");
InstallBootstrapPatch();
Updates.InstallPendingUpdates();
@ -63,7 +63,7 @@ namespace IPA.Injector
var cAsmName = Assembly.GetExecutingAssembly().GetName();
loader.Debug("Finding backup");
var backupPath = Path.Combine(Environment.CurrentDirectory, "IPA","Backups","Beat Saber");
var backupPath = Path.Combine(Environment.CurrentDirectory, "IPA", "Backups", "Beat Saber");
var bkp = BackupManager.FindLatestBackup(backupPath);
if (bkp == null)
loader.Warn("No backup found! Was BSIPA installed using the installer?");
@ -71,6 +71,7 @@ namespace IPA.Injector
loader.Debug("Ensuring patch on UnityEngine.CoreModule exists");
#region Insert patch into UnityEngine.CoreModule.dll
{
var unityPath = Path.Combine(Environment.CurrentDirectory, "Beat Saber_Data", "Managed",
"UnityEngine.CoreModule.dll");
@ -103,7 +104,7 @@ namespace IPA.Injector
if (m.IsRuntimeSpecialName && m.Name == ".cctor")
cctor = m;
var cbs = unityModDef.ImportReference(((Action) CreateBootstrapper).Method);
var cbs = unityModDef.ImportReference(((Action)CreateBootstrapper).Method);
if (cctor == null)
{
@ -129,17 +130,18 @@ namespace IPA.Injector
ilp.Replace(ins, ilp.Create(OpCodes.Call, cbs));
modified = true;
break;
case 0:
{
var methodRef = ins.Operand as MethodReference;
if (methodRef?.FullName != cbs.FullName)
{
ilp.Replace(ins, ilp.Create(OpCodes.Call, cbs));
modified = true;
var methodRef = ins.Operand as MethodReference;
if (methodRef?.FullName != cbs.FullName)
{
ilp.Replace(ins, ilp.Create(OpCodes.Call, cbs));
modified = true;
}
break;
}
break;
}
case 1 when ins.OpCode != OpCodes.Ret:
ilp.Replace(ins, ilp.Create(OpCodes.Ret));
modified = true;
@ -154,11 +156,13 @@ namespace IPA.Injector
unityAsmDef.Write(unityPath);
}
}
#endregion
#endregion Insert patch into UnityEngine.CoreModule.dll
loader.Debug("Ensuring Assembly-CSharp is virtualized");
#region Virtualize Assembly-CSharp.dll
{
var ascPath = Path.Combine(Environment.CurrentDirectory, "Beat Saber_Data", "Managed",
"Assembly-CSharp.dll");
@ -166,10 +170,12 @@ namespace IPA.Injector
var ascModule = VirtualizedModule.Load(ascPath);
ascModule.Virtualize(cAsmName, () => bkp?.Add(ascPath));
}
#endregion
#endregion Virtualize Assembly-CSharp.dll
}
private static bool _bootstrapped;
private static void CreateBootstrapper()
{
if (_bootstrapped) return;
@ -184,12 +190,13 @@ namespace IPA.Injector
// need to reinit streams singe Unity seems to redirect stdout
WinConsole.InitializeStreams();
var bootstrapper = new GameObject("NonDestructiveBootstrapper").AddComponent<Bootstrapper>();
bootstrapper.Destroyed += Bootstrapper_Destroyed;
}
private static bool _loadingDone;
private static void Bootstrapper_Destroyed()
{
// wait for plugins to finish loading
@ -199,4 +206,4 @@ namespace IPA.Injector
PluginComponent.Create();
}
}
}
}

+ 1
- 1
IPA.Injector/Properties/AssemblyInfo.cs View File

@ -34,4 +34,4 @@ using System.Runtime.InteropServices;
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.12.0")]
[assembly: AssemblyFileVersion("3.12.0")]
[assembly: AssemblyFileVersion("3.12.0")]

+ 7
- 6
IPA.Loader/Config/ConfigProviders/JsonConfigProvider.cs View File

@ -1,10 +1,10 @@
using System;
using IPA.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Specialized;
using System.ComponentModel;
using System.IO;
using IPA.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace IPA.Config.ConfigProviders
{
@ -20,13 +20,14 @@ namespace IPA.Config.ConfigProviders
// TODO: create a wrapper that allows empty object creation
public dynamic Dynamic => jsonObj;
public bool HasChanged { get; private set; }
public bool InMemoryChanged { get; set; }
public DateTime LastModified => File.GetLastWriteTime(Filename + ".json");
private string _filename;
public string Filename
{
get => _filename;
@ -115,4 +116,4 @@ namespace IPA.Config.ConfigProviders
InMemoryChanged = true;
}
}
}
}

+ 5
- 3
IPA.Loader/Config/SelfConfig.cs View File

@ -1,6 +1,6 @@
using System.IO;
using IPA.Logging;
using IPA.Logging;
using IPA.Utilities;
using System.IO;
namespace IPA.Config
{
@ -28,6 +28,7 @@ namespace IPA.Config
}
public static Ref<SelfConfig> SelfConfigRef;
public static void Set()
{
LoaderConfig = Config.GetProviderFor(Path.Combine("UserData", IPA_Name), "toml", "json");
@ -43,6 +44,7 @@ namespace IPA.Config
public bool ShowCallSource = false;
public bool ShowDebug = false;
}
public DebugObject Debug = new DebugObject();
}
}
}

+ 1
- 0
IPA.Loader/IPA.Loader.csproj View File

@ -61,6 +61,7 @@
<Compile Include="Config\IConfigProvider.cs" />
<Compile Include="Config\SelfConfig.cs" />
<Compile Include="Loader\Composite\CompositeBSPlugin.cs" />
<Compile Include="Loader\Features\Feature.cs" />
<Compile Include="Loader\PluginLoader.cs" />
<Compile Include="Loader\PluginManifest.cs" />
<Compile Include="Logging\Printers\PluginSubLogPrinter.cs" />


+ 4
- 4
IPA.Loader/Loader/PluginManifest.cs View File

@ -1,7 +1,7 @@
using System.Collections.Generic;
using IPA.JsonConverters;
using IPA.JsonConverters;
using Newtonsoft.Json;
using SemVer;
using System.Collections.Generic;
namespace IPA.Loader
{
@ -24,7 +24,7 @@ namespace IPA.Loader
[JsonProperty("author", Required = Required.Always)]
public string Author;
[JsonProperty("dependsOn", Required = Required.DisallowNull, ItemConverterType = typeof(SemverRangeConverter))]
public Dictionary<string, Range> Dependencies = new Dictionary<string, Range>();
@ -40,4 +40,4 @@ namespace IPA.Loader
[JsonProperty("loadAfter", Required = Required.DisallowNull)]
public string[] LoadAfter = new string[0];
}
}
}

+ 4
- 1
IPA.Loader/Logging/LogPrinter.cs View File

@ -11,6 +11,7 @@ namespace IPA.Logging
/// Provides a filter for which log levels to allow through.
/// </summary>
public abstract Logger.LogLevel Filter { get; set; }
/// <summary>
/// Prints a provided message from a given log at the specified time.
/// </summary>
@ -19,15 +20,17 @@ namespace IPA.Logging
/// <param name="logName">the name of the log that created this message</param>
/// <param name="message">the message</param>
public abstract void Print(Logger.Level level, DateTime time, string logName, string message);
/// <summary>
/// Called before the first print in a group. May be called multiple times.
/// Use this to create file handles and the like.
/// </summary>
public virtual void StartPrint() { }
/// <summary>
/// Called after the last print in a group. May be called multiple times.
/// Use this to dispose file handles and the like.
/// </summary>
public virtual void EndPrint() { }
}
}
}

+ 33
- 6
IPA.Loader/Logging/Logger.cs View File

@ -1,4 +1,5 @@
using System;
// ReSharper disable InconsistentNaming
namespace IPA.Logging
@ -9,6 +10,7 @@ namespace IPA.Logging
public abstract class Logger
{
private static Logger _log;
internal static Logger log
{
get
@ -18,6 +20,7 @@ namespace IPA.Logging
return _log;
}
}
internal static Logger updater => log.GetChildLogger("Updater");
internal static Logger libLoader => log.GetChildLogger("LibraryLoader");
internal static Logger loader => log.GetChildLogger("Loader");
@ -38,22 +41,27 @@ namespace IPA.Logging
/// No associated level. These never get shown.
/// </summary>
None = 0,
/// <summary>
/// A debug message.
/// </summary>
Debug = 1,
/// <summary>
/// An informational message.
/// </summary>
Info = 2,
/// <summary>
/// A warning message.
/// </summary>
Warning = 4,
/// <summary>
/// An error message.
/// </summary>
Error = 8,
/// <summary>
/// A critical error message.
/// </summary>
@ -70,22 +78,27 @@ namespace IPA.Logging
/// Allow no messages through.
/// </summary>
None = Level.None,
/// <summary>
/// Only shows Debug messages.
/// </summary>
DebugOnly = Level.Debug,
/// <summary>
/// Only shows info messages.
/// </summary>
InfoOnly = Level.Info,
/// <summary>
/// Only shows Warning messages.
/// </summary>
WarningOnly = Level.Warning,
/// <summary>
/// Only shows Error messages.
/// </summary>
ErrorOnly = Level.Error,
/// <summary>
/// Only shows Critical messages.
/// </summary>
@ -95,14 +108,17 @@ namespace IPA.Logging
/// Shows all messages error and up.
/// </summary>
ErrorUp = ErrorOnly | CriticalOnly,
/// <summary>
/// Shows all messages warning and up.
/// </summary>
WarningUp = WarningOnly | ErrorUp,
/// <summary>
/// Shows all messages info and up.
/// </summary>
InfoUp = InfoOnly | WarningUp,
/// <summary>
/// Shows all messages.
/// </summary>
@ -120,19 +136,22 @@ namespace IPA.Logging
/// <param name="level">the level of the message</param>
/// <param name="message">the message to log</param>
public abstract void Log(Level level, string message);
/// <summary>
/// A basic log function taking an exception to log.
/// </summary>
/// <param name="level">the level of the message</param>
/// <param name="e">the exception to log</param>
public virtual void Log(Level level, Exception e) => Log(level, e.ToString());
/// <summary>
/// Sends a debug message.
/// Sends a debug message.
/// Equivalent to Log(Level.Debug, message);
/// <see cref="Log(Level, string)"/>
/// </summary>
/// <param name="message">the message to log</param>
public virtual void Debug(string message) => Log(Level.Debug, message);
/// <summary>
/// Sends an exception as a debug message.
/// Equivalent to Log(Level.Debug, e);
@ -140,13 +159,15 @@ namespace IPA.Logging
/// </summary>
/// <param name="e">the exception to log</param>
public virtual void Debug(Exception e) => Log(Level.Debug, e);
/// <summary>
/// Sends an info message.
/// Sends an info message.
/// Equivalent to Log(Level.Info, message).
/// <see cref="Log(Level, string)"/>
/// </summary>
/// <param name="message">the message to log</param>
public virtual void Info(string message) => Log(Level.Info, message);
/// <summary>
/// Sends an exception as an info message.
/// Equivalent to Log(Level.Info, e);
@ -154,13 +175,15 @@ namespace IPA.Logging
/// </summary>
/// <param name="e">the exception to log</param>
public virtual void Info(Exception e) => Log(Level.Info, e);
/// <summary>
/// Sends a warning message.
/// Sends a warning message.
/// Equivalent to Log(Level.Warning, message).
/// <see cref="Log(Level, string)"/>
/// </summary>
/// <param name="message">the message to log</param>
public virtual void Warn(string message) => Log(Level.Warning, message);
/// <summary>
/// Sends an exception as a warning message.
/// Equivalent to Log(Level.Warning, e);
@ -168,13 +191,15 @@ namespace IPA.Logging
/// </summary>
/// <param name="e">the exception to log</param>
public virtual void Warn(Exception e) => Log(Level.Warning, e);
/// <summary>
/// Sends an error message.
/// Sends an error message.
/// Equivalent to Log(Level.Error, message).
/// <see cref="Log(Level, string)"/>
/// </summary>
/// <param name="message">the message to log</param>
public virtual void Error(string message) => Log(Level.Error, message);
/// <summary>
/// Sends an exception as an error message.
/// Equivalent to Log(Level.Error, e);
@ -182,13 +207,15 @@ namespace IPA.Logging
/// </summary>
/// <param name="e">the exception to log</param>
public virtual void Error(Exception e) => Log(Level.Error, e);
/// <summary>
/// Sends a critical message.
/// Sends a critical message.
/// Equivalent to Log(Level.Critical, message).
/// <see cref="Log(Level, string)"/>
/// </summary>
/// <param name="message">the message to log</param>
public virtual void Critical(string message) => Log(Level.Critical, message);
/// <summary>
/// Sends an exception as a critical message.
/// Equivalent to Log(Level.Critical, e);
@ -197,4 +224,4 @@ namespace IPA.Logging
/// <param name="e">the exception to log</param>
public virtual void Critical(Exception e) => Log(Level.Critical, e);
}
}
}

+ 5
- 5
IPA.Loader/Logging/Printers/GZFilePrinter.cs View File

@ -12,17 +12,19 @@ namespace IPA.Logging.Printers
public abstract class GZFilePrinter : LogPrinter, IDisposable
{
[DllImport("Kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
static extern bool CreateHardLink(
private static extern bool CreateHardLink(
string lpFileName,
string lpExistingFileName,
IntPtr lpSecurityAttributes
);
private FileInfo fileInfo;
/// <summary>
/// The <see cref="StreamWriter"/> that writes to the GZip file.
/// </summary>
protected StreamWriter FileWriter;
private GZipStream zstream;
private FileStream fstream;
@ -99,9 +101,7 @@ namespace IPA.Logging.Printers
fstream.Dispose();
}
/// <summary>
/// Disposes the file printer.
/// </summary>
/// <inheritdoc />
public void Dispose()
{
Dispose(true);
@ -128,4 +128,4 @@ namespace IPA.Logging.Printers
}
}
}
}
}

+ 1
- 1
IPA.Loader/Logging/Printers/GlobalLogFilePrinter.cs View File

@ -38,4 +38,4 @@ namespace IPA.Logging.Printers
return finfo;
}
}
}
}

+ 2
- 2
IPA.Loader/Logging/Printers/PluginLogFilePrinter.cs View File

@ -21,7 +21,7 @@ namespace IPA.Logging.Printers
/// <returns></returns>
protected override FileInfo GetFileInfo()
{
var logsDir = new DirectoryInfo(Path.Combine("Logs",name));
var logsDir = new DirectoryInfo(Path.Combine("Logs", name));
logsDir.Create();
var finfo = new FileInfo(Path.Combine(logsDir.FullName, $"{DateTime.Now:yyyy.MM.dd.HH.mm}.log"));
return finfo;
@ -49,4 +49,4 @@ namespace IPA.Logging.Printers
FileWriter.WriteLine(Logger.LogFormat, line, logName, time, level.ToString().ToUpper());
}
}
}
}

+ 1
- 1
IPA.Loader/Logging/Printers/PluginSubLogPrinter.cs View File

@ -52,4 +52,4 @@ namespace IPA.Logging.Printers
FileWriter.WriteLine("[{2} @ {1:HH:mm:ss}] {0}", line, time, level.ToString().ToUpper());
}
}
}
}

+ 23
- 3
IPA.Loader/Logging/StandardLogger.cs View File

@ -51,6 +51,10 @@ namespace IPA.Logging
new GlobalLogFilePrinter()
};
/// <summary>
/// Adds to the default printer pool that all printers inherit from. Printers added this way will be passed every message from every logger.
/// </summary>
/// <param name="printer"></param>
internal static void AddDefaultPrinter(LogPrinter printer)
{
defaultPrinters.Add(printer);
@ -63,11 +67,16 @@ namespace IPA.Logging
/// All levels defined by this filter will be sent to loggers. All others will be ignored.
/// </summary>
public static LogLevel PrintFilter { get; set; } = LogLevel.All;
private readonly List<LogPrinter> printers = new List<LogPrinter>();
private readonly StandardLogger parent;
private readonly Dictionary<string, StandardLogger> children = new Dictionary<string, StandardLogger>();
/// <summary>
/// Configures internal debug settings based on the config passed in.
/// </summary>
/// <param name="cfg"></param>
internal static void Configure(SelfConfig cfg)
{
showSourceClass = cfg.Debug.ShowCallSource;
@ -102,6 +111,11 @@ namespace IPA.Logging
}
}
/// <summary>
/// Gets a child printer with the given name, either constructing a new one or using one that was already made.
/// </summary>
/// <param name="name"></param>
/// <returns>a child <see cref="StandardLogger"/> with the given sub-name</returns>
internal StandardLogger GetChild(string name)
{
if (!children.TryGetValue(name, out var child))
@ -140,7 +154,7 @@ namespace IPA.Logging
Time = DateTime.Now
});
}
/// <inheritdoc />
/// <summary>
/// An override to <see cref="M:IPA.Logging.Logger.Debug(System.String)" /> which shows the method that called it.
@ -169,6 +183,9 @@ namespace IPA.Logging
private static readonly BlockingCollection<LogMessage> logQueue = new BlockingCollection<LogMessage>();
private static Thread logThread;
/// <summary>
/// The log printer thread for <see cref="StandardLogger"/>.
/// </summary>
private static void LogThread()
{
var started = new HashSet<LogPrinter>();
@ -222,6 +239,9 @@ namespace IPA.Logging
}
}
/// <summary>
/// Stops and joins the log printer thread.
/// </summary>
internal static void StopLogThread()
{
logQueue.CompleteAdding();
@ -248,4 +268,4 @@ namespace IPA.Logging
throw new InvalidOperationException();
}
}
}
}

+ 3
- 3
IPA.Loader/Updating/SelfPlugin.cs View File

@ -1,5 +1,5 @@
using System;
using IPA.Config;
using IPA.Config;
using System;
using UnityEngine.SceneManagement;
namespace IPA.Updating
@ -47,4 +47,4 @@ namespace IPA.Updating
{
}
}
}
}

+ 6
- 6
IPA/Properties/AssemblyInfo.cs View File

@ -1,7 +1,7 @@
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("IPA.Installer")]
@ -13,8 +13,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
@ -24,12 +24,12 @@ using System.Runtime.InteropServices;
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.12.0")]
[assembly: AssemblyFileVersion("3.12.0")]
[assembly: AssemblyFileVersion("3.12.0")]

BIN
Refs/UnityEngine.CoreModule.dll View File


Loading…
Cancel
Save