Browse Source

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

pull/46/head
Anairkoen Schno 4 years ago
parent
commit
30cb531c31
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>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Lib.Harmony">
<Version>1.2.0.1</Version>
</PackageReference>
<PackageReference Include="Mono.Cecil">
<Version>0.10.4</Version>
</PackageReference>


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

@ -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
}
}


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

@ -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();


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

@ -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<string, string>();
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}");


+ 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 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;
/// <summary>
/// The standard format for log messages.


Loading…
Cancel
Save