Browse Source

Added more indirection around Harmony at injection, as well as some debug printing during reference lookup

4.0.0-beta
Anairkoen Schno 5 years ago
parent
commit
d54720509f
5 changed files with 25 additions and 14 deletions
  1. +0
    -3
      IPA.Injector/IPA.Injector.csproj
  2. +11
    -9
      IPA.Injector/Injector.cs
  3. +6
    -1
      IPA.Loader/Loader/HarmonyProtector.cs
  4. +7
    -0
      IPA.Loader/Loader/LibLoader.cs
  5. +1
    -1
      IPA.Loader/Logging/Logger.cs

+ 0
- 3
IPA.Injector/IPA.Injector.csproj View File

@ -113,9 +113,6 @@
</Content> </Content>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Lib.Harmony">
<Version>1.2.0.1</Version>
</PackageReference>
<PackageReference Include="Mono.Cecil"> <PackageReference Include="Mono.Cecil">
<Version>0.10.4</Version> <Version>0.10.4</Version>
</PackageReference> </PackageReference>


+ 11
- 9
IPA.Injector/Injector.cs View File

@ -45,6 +45,8 @@ namespace IPA.Injector
if (Environment.GetCommandLineArgs().Contains("--verbose")) if (Environment.GetCommandLineArgs().Contains("--verbose"))
WinConsole.Initialize(); WinConsole.Initialize();
Console.WriteLine("Setting up library loading");
SetupLibraryLoading(); SetupLibraryLoading();
/*var otherNewtonsoft = Path.Combine( /*var otherNewtonsoft = Path.Combine(
@ -62,13 +64,13 @@ namespace IPA.Injector
// this is weird, but it prevents Mono from having issues loading the type. // this is weird, but it prevents Mono from having issues loading the type.
// IMPORTANT: NO CALLS TO ANY LOGGER CAN HAPPEN BEFORE THIS // IMPORTANT: NO CALLS TO ANY LOGGER CAN HAPPEN BEFORE THIS
var unused = StandardLogger.PrintFilter; 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 * 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 * 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. * 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"); log.Debug("Initializing logger");
@ -125,7 +127,7 @@ namespace IPA.Injector
private static void InstallHarmonyProtections() private static void InstallHarmonyProtections()
{ // proxy function to delay resolution { // proxy function to delay resolution
HarmonyProtector.Protect();
HarmonyProtectorProxy.ProtectNull();
} }
private static void InstallBootstrapPatch() private static void InstallBootstrapPatch()
@ -144,7 +146,7 @@ namespace IPA.Injector
loader.Debug("Ensuring patch on UnityEngine.CoreModule exists"); 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, var unityPath = Path.Combine(managedPath,
@ -236,7 +238,7 @@ namespace IPA.Injector
CriticalSection.ExitExecuteSection(); CriticalSection.ExitExecuteSection();
} }
#endregion Insert patch into UnityEngine.CoreModule.dll
#endregion Insert patch into UnityEngine.CoreModule.dll
loader.Debug("Ensuring Assembly-CSharp is virtualized"); loader.Debug("Ensuring Assembly-CSharp is virtualized");
@ -244,7 +246,7 @@ namespace IPA.Injector
var ascPath = Path.Combine(managedPath, var ascPath = Path.Combine(managedPath,
"Assembly-CSharp.dll"); "Assembly-CSharp.dll");
#region Virtualize Assembly-CSharp.dll
#region Virtualize Assembly-CSharp.dll
{ {
CriticalSection.EnterExecuteSection(); CriticalSection.EnterExecuteSection();
@ -255,9 +257,9 @@ namespace IPA.Injector
CriticalSection.ExitExecuteSection(); CriticalSection.ExitExecuteSection();
} }
#endregion Virtualize Assembly-CSharp.dll
#endregion Virtualize Assembly-CSharp.dll
#region Anti-Yeet
#region Anti-Yeet
CriticalSection.EnterExecuteSection(); CriticalSection.EnterExecuteSection();
@ -285,7 +287,7 @@ namespace IPA.Injector
CriticalSection.ExitExecuteSection(); CriticalSection.ExitExecuteSection();
#endregion
#endregion
} }
} }


+ 6
- 1
IPA.Loader/Loader/HarmonyProtector.cs View File

@ -4,12 +4,17 @@ using System.Reflection;
namespace IPA.Loader namespace IPA.Loader
{ {
internal static class HarmonyProtectorProxy
{
public static void ProtectNull() => HarmonyProtector.Protect();
}
internal static class HarmonyProtector internal static class HarmonyProtector
{ {
private static HarmonyInstance instance; private static HarmonyInstance instance;
private static Assembly selfAssem; private static Assembly selfAssem;
private static Assembly harmonyAssem; private static Assembly harmonyAssem;
public static void Protect(HarmonyInstance inst = null) public static void Protect(HarmonyInstance inst = null)
{ {
selfAssem = Assembly.GetExecutingAssembly(); selfAssem = Assembly.GetExecutingAssembly();


+ 7
- 0
IPA.Loader/Loader/LibLoader.cs View File

@ -53,6 +53,8 @@ namespace IPA.Loader
internal static void Configure() internal static void Configure()
{ {
Console.WriteLine("Configuring up library loading");
SetupAssemblyFilenames(true); SetupAssemblyFilenames(true);
AppDomain.CurrentDomain.AssemblyResolve -= AssemblyLibLoader; AppDomain.CurrentDomain.AssemblyResolve -= AssemblyLibLoader;
AppDomain.CurrentDomain.AssemblyResolve += AssemblyLibLoader; AppDomain.CurrentDomain.AssemblyResolve += AssemblyLibLoader;
@ -62,6 +64,8 @@ namespace IPA.Loader
{ {
if (FilenameLocations == null || force) if (FilenameLocations == null || force)
{ {
Console.WriteLine("Calculating assembly filenames");
FilenameLocations = new Dictionary<string, string>(); FilenameLocations = new Dictionary<string, string>();
foreach (var fn in TraverseTree(LibraryPath, s => s != NativeLibraryPath)) 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}"); Log(Logger.Level.Critical, $"Multiple instances of {fn.Name} exist in Libs! Ignoring {fn.FullName}");
else FilenameLocations.Add(fn.Name, 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 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)) | LoadLibraryFlags.LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LoadLibraryFlags.LOAD_LIBRARY_SEARCH_APPLICATION_DIR))
@ -119,6 +124,8 @@ namespace IPA.Loader
SetupAssemblyFilenames(); SetupAssemblyFilenames();
Console.WriteLine($"Looking for {asmName.Name} {asmName.Version} ({asmName.Name}.{asmName.Version}.dll)");
var testFile = $"{asmName.Name}.{asmName.Version}.dll"; var testFile = $"{asmName.Name}.{asmName.Version}.dll";
Log(Logger.Level.Debug, $"Looking for file {testFile}"); Log(Logger.Level.Debug, $"Looking for file {testFile}");


+ 1
- 1
IPA.Loader/Logging/Logger.cs View File

@ -38,7 +38,7 @@ namespace IPA.Logging
internal static Logger loader => log.GetChildLogger("Loader"); internal static Logger loader => log.GetChildLogger("Loader");
internal static Logger features => loader.GetChildLogger("Features"); internal static Logger features => loader.GetChildLogger("Features");
internal static Logger config => log.GetChildLogger("Config"); internal static Logger config => log.GetChildLogger("Config");
internal static bool LogCreated => _log != null || UnityLogProvider.Logger != null;
internal static bool LogCreated => _log != null;
/// <summary> /// <summary>
/// The standard format for log messages. /// The standard format for log messages.


Loading…
Cancel
Save