diff --git a/BSIPA.sln.DotSettings b/BSIPA.sln.DotSettings index 3bbe3c40..0c0f1d5a 100644 --- a/BSIPA.sln.DotSettings +++ b/BSIPA.sln.DotSettings @@ -1,5 +1,9 @@  WARNING + False + False + False + False BS IPA diff --git a/IPA.Injector/Injector.cs b/IPA.Injector/Injector.cs index c6ff86c8..dd218caa 100644 --- a/IPA.Injector/Injector.cs +++ b/IPA.Injector/Injector.cs @@ -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.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(); } } -} +} \ No newline at end of file diff --git a/IPA.Injector/Properties/AssemblyInfo.cs b/IPA.Injector/Properties/AssemblyInfo.cs index 97c824a2..0b0212a3 100644 --- a/IPA.Injector/Properties/AssemblyInfo.cs +++ b/IPA.Injector/Properties/AssemblyInfo.cs @@ -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")] \ No newline at end of file diff --git a/IPA.Loader/Config/ConfigProviders/JsonConfigProvider.cs b/IPA.Loader/Config/ConfigProviders/JsonConfigProvider.cs index c0b018b0..84396786 100644 --- a/IPA.Loader/Config/ConfigProviders/JsonConfigProvider.cs +++ b/IPA.Loader/Config/ConfigProviders/JsonConfigProvider.cs @@ -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; } } -} +} \ No newline at end of file diff --git a/IPA.Loader/Config/SelfConfig.cs b/IPA.Loader/Config/SelfConfig.cs index d83097df..80f87b37 100644 --- a/IPA.Loader/Config/SelfConfig.cs +++ b/IPA.Loader/Config/SelfConfig.cs @@ -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 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(); } -} +} \ No newline at end of file diff --git a/IPA.Loader/IPA.Loader.csproj b/IPA.Loader/IPA.Loader.csproj index 995a137e..e8cc333f 100644 --- a/IPA.Loader/IPA.Loader.csproj +++ b/IPA.Loader/IPA.Loader.csproj @@ -61,6 +61,7 @@ + diff --git a/IPA.Loader/Loader/PluginManifest.cs b/IPA.Loader/Loader/PluginManifest.cs index d24e8f52..f7b25207 100644 --- a/IPA.Loader/Loader/PluginManifest.cs +++ b/IPA.Loader/Loader/PluginManifest.cs @@ -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 Dependencies = new Dictionary(); @@ -40,4 +40,4 @@ namespace IPA.Loader [JsonProperty("loadAfter", Required = Required.DisallowNull)] public string[] LoadAfter = new string[0]; } -} +} \ No newline at end of file diff --git a/IPA.Loader/Logging/LogPrinter.cs b/IPA.Loader/Logging/LogPrinter.cs index 2c82e9f6..0bbaef3e 100644 --- a/IPA.Loader/Logging/LogPrinter.cs +++ b/IPA.Loader/Logging/LogPrinter.cs @@ -11,6 +11,7 @@ namespace IPA.Logging /// Provides a filter for which log levels to allow through. /// public abstract Logger.LogLevel Filter { get; set; } + /// /// Prints a provided message from a given log at the specified time. /// @@ -19,15 +20,17 @@ namespace IPA.Logging /// the name of the log that created this message /// the message public abstract void Print(Logger.Level level, DateTime time, string logName, string message); + /// /// Called before the first print in a group. May be called multiple times. /// Use this to create file handles and the like. /// public virtual void StartPrint() { } + /// /// Called after the last print in a group. May be called multiple times. /// Use this to dispose file handles and the like. /// public virtual void EndPrint() { } } -} +} \ No newline at end of file diff --git a/IPA.Loader/Logging/Logger.cs b/IPA.Loader/Logging/Logger.cs index fcbc7de7..00fc1790 100644 --- a/IPA.Loader/Logging/Logger.cs +++ b/IPA.Loader/Logging/Logger.cs @@ -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. /// None = 0, + /// /// A debug message. /// Debug = 1, + /// /// An informational message. /// Info = 2, + /// /// A warning message. /// Warning = 4, + /// /// An error message. /// Error = 8, + /// /// A critical error message. /// @@ -70,22 +78,27 @@ namespace IPA.Logging /// Allow no messages through. /// None = Level.None, + /// /// Only shows Debug messages. /// DebugOnly = Level.Debug, + /// /// Only shows info messages. /// InfoOnly = Level.Info, + /// /// Only shows Warning messages. /// WarningOnly = Level.Warning, + /// /// Only shows Error messages. /// ErrorOnly = Level.Error, + /// /// Only shows Critical messages. /// @@ -95,14 +108,17 @@ namespace IPA.Logging /// Shows all messages error and up. /// ErrorUp = ErrorOnly | CriticalOnly, + /// /// Shows all messages warning and up. /// WarningUp = WarningOnly | ErrorUp, + /// /// Shows all messages info and up. /// InfoUp = InfoOnly | WarningUp, + /// /// Shows all messages. /// @@ -120,19 +136,22 @@ namespace IPA.Logging /// the level of the message /// the message to log public abstract void Log(Level level, string message); + /// /// A basic log function taking an exception to log. /// /// the level of the message /// the exception to log public virtual void Log(Level level, Exception e) => Log(level, e.ToString()); + /// - /// Sends a debug message. + /// Sends a debug message. /// Equivalent to Log(Level.Debug, message); /// /// /// the message to log public virtual void Debug(string message) => Log(Level.Debug, message); + /// /// Sends an exception as a debug message. /// Equivalent to Log(Level.Debug, e); @@ -140,13 +159,15 @@ namespace IPA.Logging /// /// the exception to log public virtual void Debug(Exception e) => Log(Level.Debug, e); + /// - /// Sends an info message. + /// Sends an info message. /// Equivalent to Log(Level.Info, message). /// /// /// the message to log public virtual void Info(string message) => Log(Level.Info, message); + /// /// Sends an exception as an info message. /// Equivalent to Log(Level.Info, e); @@ -154,13 +175,15 @@ namespace IPA.Logging /// /// the exception to log public virtual void Info(Exception e) => Log(Level.Info, e); + /// - /// Sends a warning message. + /// Sends a warning message. /// Equivalent to Log(Level.Warning, message). /// /// /// the message to log public virtual void Warn(string message) => Log(Level.Warning, message); + /// /// Sends an exception as a warning message. /// Equivalent to Log(Level.Warning, e); @@ -168,13 +191,15 @@ namespace IPA.Logging /// /// the exception to log public virtual void Warn(Exception e) => Log(Level.Warning, e); + /// - /// Sends an error message. + /// Sends an error message. /// Equivalent to Log(Level.Error, message). /// /// /// the message to log public virtual void Error(string message) => Log(Level.Error, message); + /// /// Sends an exception as an error message. /// Equivalent to Log(Level.Error, e); @@ -182,13 +207,15 @@ namespace IPA.Logging /// /// the exception to log public virtual void Error(Exception e) => Log(Level.Error, e); + /// - /// Sends a critical message. + /// Sends a critical message. /// Equivalent to Log(Level.Critical, message). /// /// /// the message to log public virtual void Critical(string message) => Log(Level.Critical, message); + /// /// Sends an exception as a critical message. /// Equivalent to Log(Level.Critical, e); @@ -197,4 +224,4 @@ namespace IPA.Logging /// the exception to log public virtual void Critical(Exception e) => Log(Level.Critical, e); } -} +} \ No newline at end of file diff --git a/IPA.Loader/Logging/Printers/GZFilePrinter.cs b/IPA.Loader/Logging/Printers/GZFilePrinter.cs index eb25ff56..5f39d9cc 100644 --- a/IPA.Loader/Logging/Printers/GZFilePrinter.cs +++ b/IPA.Loader/Logging/Printers/GZFilePrinter.cs @@ -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; + /// /// The that writes to the GZip file. /// protected StreamWriter FileWriter; + private GZipStream zstream; private FileStream fstream; @@ -99,9 +101,7 @@ namespace IPA.Logging.Printers fstream.Dispose(); } - /// - /// Disposes the file printer. - /// + /// public void Dispose() { Dispose(true); @@ -128,4 +128,4 @@ namespace IPA.Logging.Printers } } } -} +} \ No newline at end of file diff --git a/IPA.Loader/Logging/Printers/GlobalLogFilePrinter.cs b/IPA.Loader/Logging/Printers/GlobalLogFilePrinter.cs index fffcb27d..59329a54 100644 --- a/IPA.Loader/Logging/Printers/GlobalLogFilePrinter.cs +++ b/IPA.Loader/Logging/Printers/GlobalLogFilePrinter.cs @@ -38,4 +38,4 @@ namespace IPA.Logging.Printers return finfo; } } -} +} \ No newline at end of file diff --git a/IPA.Loader/Logging/Printers/PluginLogFilePrinter.cs b/IPA.Loader/Logging/Printers/PluginLogFilePrinter.cs index bae0d762..eda96b21 100644 --- a/IPA.Loader/Logging/Printers/PluginLogFilePrinter.cs +++ b/IPA.Loader/Logging/Printers/PluginLogFilePrinter.cs @@ -21,7 +21,7 @@ namespace IPA.Logging.Printers /// 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()); } } -} +} \ No newline at end of file diff --git a/IPA.Loader/Logging/Printers/PluginSubLogPrinter.cs b/IPA.Loader/Logging/Printers/PluginSubLogPrinter.cs index d501c862..54bdead2 100644 --- a/IPA.Loader/Logging/Printers/PluginSubLogPrinter.cs +++ b/IPA.Loader/Logging/Printers/PluginSubLogPrinter.cs @@ -52,4 +52,4 @@ namespace IPA.Logging.Printers FileWriter.WriteLine("[{2} @ {1:HH:mm:ss}] {0}", line, time, level.ToString().ToUpper()); } } -} +} \ No newline at end of file diff --git a/IPA.Loader/Logging/StandardLogger.cs b/IPA.Loader/Logging/StandardLogger.cs index 6ae7b2b5..3ee2eb07 100644 --- a/IPA.Loader/Logging/StandardLogger.cs +++ b/IPA.Loader/Logging/StandardLogger.cs @@ -51,6 +51,10 @@ namespace IPA.Logging new GlobalLogFilePrinter() }; + /// + /// Adds to the default printer pool that all printers inherit from. Printers added this way will be passed every message from every logger. + /// + /// 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. /// public static LogLevel PrintFilter { get; set; } = LogLevel.All; + private readonly List printers = new List(); private readonly StandardLogger parent; private readonly Dictionary children = new Dictionary(); - + + /// + /// Configures internal debug settings based on the config passed in. + /// + /// internal static void Configure(SelfConfig cfg) { showSourceClass = cfg.Debug.ShowCallSource; @@ -102,6 +111,11 @@ namespace IPA.Logging } } + /// + /// Gets a child printer with the given name, either constructing a new one or using one that was already made. + /// + /// + /// a child with the given sub-name internal StandardLogger GetChild(string name) { if (!children.TryGetValue(name, out var child)) @@ -140,7 +154,7 @@ namespace IPA.Logging Time = DateTime.Now }); } - + /// /// /// An override to which shows the method that called it. @@ -169,6 +183,9 @@ namespace IPA.Logging private static readonly BlockingCollection logQueue = new BlockingCollection(); private static Thread logThread; + /// + /// The log printer thread for . + /// private static void LogThread() { var started = new HashSet(); @@ -222,6 +239,9 @@ namespace IPA.Logging } } + /// + /// Stops and joins the log printer thread. + /// internal static void StopLogThread() { logQueue.CompleteAdding(); @@ -248,4 +268,4 @@ namespace IPA.Logging throw new InvalidOperationException(); } } -} +} \ No newline at end of file diff --git a/IPA.Loader/Updating/SelfPlugin.cs b/IPA.Loader/Updating/SelfPlugin.cs index 852af2f7..78c2b35e 100644 --- a/IPA.Loader/Updating/SelfPlugin.cs +++ b/IPA.Loader/Updating/SelfPlugin.cs @@ -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 { } } -} +} \ No newline at end of file diff --git a/IPA/Properties/AssemblyInfo.cs b/IPA/Properties/AssemblyInfo.cs index 33be5758..d76c55bc 100644 --- a/IPA/Properties/AssemblyInfo.cs +++ b/IPA/Properties/AssemblyInfo.cs @@ -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")] \ No newline at end of file diff --git a/Refs/UnityEngine.CoreModule.dll b/Refs/UnityEngine.CoreModule.dll index 0913c47b..a802a5c6 100644 Binary files a/Refs/UnityEngine.CoreModule.dll and b/Refs/UnityEngine.CoreModule.dll differ