From 30cb531c312b35e5cbc617b5d4b4d5d6bbb87eef Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Sun, 1 Dec 2019 01:12:56 -0600 Subject: [PATCH] Added more indirection around Harmony at injection, as well as some debug printing during reference lookup --- IPA.Injector/IPA.Injector.csproj | 3 --- IPA.Injector/Injector.cs | 20 +++++++++++--------- IPA.Loader/Loader/HarmonyProtector.cs | 7 ++++++- IPA.Loader/Loader/LibLoader.cs | 7 +++++++ IPA.Loader/Logging/Logger.cs | 2 +- 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/IPA.Injector/IPA.Injector.csproj b/IPA.Injector/IPA.Injector.csproj index 2a239fb9..d1dced37 100644 --- a/IPA.Injector/IPA.Injector.csproj +++ b/IPA.Injector/IPA.Injector.csproj @@ -113,9 +113,6 @@ - - 1.2.0.1 - 0.10.4 diff --git a/IPA.Injector/Injector.cs b/IPA.Injector/Injector.cs index 4172449d..6731d944 100644 --- a/IPA.Injector/Injector.cs +++ b/IPA.Injector/Injector.cs @@ -45,6 +45,8 @@ namespace IPA.Injector if (Environment.GetCommandLineArgs().Contains("--verbose")) WinConsole.Initialize(); + Console.WriteLine("Setting up library loading"); + SetupLibraryLoading(); /*var otherNewtonsoft = Path.Combine( @@ -62,13 +64,13 @@ namespace IPA.Injector // this is weird, but it prevents Mono from having issues loading the type. // IMPORTANT: NO CALLS TO ANY LOGGER CAN HAPPEN BEFORE THIS var unused = StandardLogger.PrintFilter; - #region // Above hack explaination +#region // Above hack explaination /* * Due to an unknown bug in the version of Mono that Unity uses, if the first access to StandardLogger * is a call to a constructor, then Mono fails to load the type correctly. However, if the first access is to * the above static property (or maybe any, but I don't really know) it behaves as expected and works fine. */ - #endregion +#endregion log.Debug("Initializing logger"); @@ -125,7 +127,7 @@ namespace IPA.Injector private static void InstallHarmonyProtections() { // proxy function to delay resolution - HarmonyProtector.Protect(); + HarmonyProtectorProxy.ProtectNull(); } private static void InstallBootstrapPatch() @@ -144,7 +146,7 @@ namespace IPA.Injector loader.Debug("Ensuring patch on UnityEngine.CoreModule exists"); - #region Insert patch into UnityEngine.CoreModule.dll +#region Insert patch into UnityEngine.CoreModule.dll { var unityPath = Path.Combine(managedPath, @@ -236,7 +238,7 @@ namespace IPA.Injector CriticalSection.ExitExecuteSection(); } - #endregion Insert patch into UnityEngine.CoreModule.dll +#endregion Insert patch into UnityEngine.CoreModule.dll loader.Debug("Ensuring Assembly-CSharp is virtualized"); @@ -244,7 +246,7 @@ namespace IPA.Injector var ascPath = Path.Combine(managedPath, "Assembly-CSharp.dll"); - #region Virtualize Assembly-CSharp.dll +#region Virtualize Assembly-CSharp.dll { CriticalSection.EnterExecuteSection(); @@ -255,9 +257,9 @@ namespace IPA.Injector CriticalSection.ExitExecuteSection(); } - #endregion Virtualize Assembly-CSharp.dll +#endregion Virtualize Assembly-CSharp.dll - #region Anti-Yeet +#region Anti-Yeet CriticalSection.EnterExecuteSection(); @@ -285,7 +287,7 @@ namespace IPA.Injector CriticalSection.ExitExecuteSection(); - #endregion +#endregion } } diff --git a/IPA.Loader/Loader/HarmonyProtector.cs b/IPA.Loader/Loader/HarmonyProtector.cs index 80e5a1f1..35b84b3d 100644 --- a/IPA.Loader/Loader/HarmonyProtector.cs +++ b/IPA.Loader/Loader/HarmonyProtector.cs @@ -4,12 +4,17 @@ using System.Reflection; namespace IPA.Loader { + internal static class HarmonyProtectorProxy + { + public static void ProtectNull() => HarmonyProtector.Protect(); + } + internal static class HarmonyProtector { private static HarmonyInstance instance; private static Assembly selfAssem; private static Assembly harmonyAssem; - + public static void Protect(HarmonyInstance inst = null) { selfAssem = Assembly.GetExecutingAssembly(); diff --git a/IPA.Loader/Loader/LibLoader.cs b/IPA.Loader/Loader/LibLoader.cs index a729034c..c75fc887 100644 --- a/IPA.Loader/Loader/LibLoader.cs +++ b/IPA.Loader/Loader/LibLoader.cs @@ -53,6 +53,8 @@ namespace IPA.Loader internal static void Configure() { + Console.WriteLine("Configuring up library loading"); + SetupAssemblyFilenames(true); AppDomain.CurrentDomain.AssemblyResolve -= AssemblyLibLoader; AppDomain.CurrentDomain.AssemblyResolve += AssemblyLibLoader; @@ -62,6 +64,8 @@ namespace IPA.Loader { if (FilenameLocations == null || force) { + Console.WriteLine("Calculating assembly filenames"); + FilenameLocations = new Dictionary(); foreach (var fn in TraverseTree(LibraryPath, s => s != NativeLibraryPath)) @@ -69,6 +73,7 @@ namespace IPA.Loader Log(Logger.Level.Critical, $"Multiple instances of {fn.Name} exist in Libs! Ignoring {fn.FullName}"); else FilenameLocations.Add(fn.Name, fn.FullName); + foreach (var kvp in FilenameLocations) Console.WriteLine(kvp); if (!SetDefaultDllDirectories(LoadLibraryFlags.LOAD_LIBRARY_SEARCH_USER_DIRS | LoadLibraryFlags.LOAD_LIBRARY_SEARCH_SYSTEM32 | LoadLibraryFlags.LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LoadLibraryFlags.LOAD_LIBRARY_SEARCH_APPLICATION_DIR)) @@ -119,6 +124,8 @@ namespace IPA.Loader SetupAssemblyFilenames(); + Console.WriteLine($"Looking for {asmName.Name} {asmName.Version} ({asmName.Name}.{asmName.Version}.dll)"); + var testFile = $"{asmName.Name}.{asmName.Version}.dll"; Log(Logger.Level.Debug, $"Looking for file {testFile}"); diff --git a/IPA.Loader/Logging/Logger.cs b/IPA.Loader/Logging/Logger.cs index a724adf7..5d9c3441 100644 --- a/IPA.Loader/Logging/Logger.cs +++ b/IPA.Loader/Logging/Logger.cs @@ -38,7 +38,7 @@ namespace IPA.Logging internal static Logger loader => log.GetChildLogger("Loader"); internal static Logger features => loader.GetChildLogger("Features"); internal static Logger config => log.GetChildLogger("Config"); - internal static bool LogCreated => _log != null || UnityLogProvider.Logger != null; + internal static bool LogCreated => _log != null; /// /// The standard format for log messages.