Explorar el Código

Change patcher output directory to Game Root

Usagirei hace 7 años
padre
commit
e4644203f8
Se han modificado 2 ficheros con 16 adiciones y 9 borrados
  1. 1 1
      BepInEx.Patcher/BepInEx.Patcher.csproj
  2. 15 8
      BepInEx.Patcher/Program.cs

+ 1 - 1
BepInEx.Patcher/BepInEx.Patcher.csproj

@@ -18,7 +18,7 @@
     <DebugSymbols>true</DebugSymbols>
     <DebugType>full</DebugType>
     <Optimize>false</Optimize>
-    <OutputPath>K:\KoikatuTrial_Data\Managed\</OutputPath>
+    <OutputPath>K:\</OutputPath>
     <DefineConstants>DEBUG;TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>

+ 15 - 8
BepInEx.Patcher/Program.cs

@@ -59,20 +59,27 @@ namespace BepInEx.Patcher
         static void InjectAssembly(AssemblyDefinition unity, AssemblyDefinition injected)
         {
             //Entry point
-            var originalInjectMethod = injected.MainModule.Types.First(x => x.Name == "Chainloader").Methods.First(x => x.Name == "Initialize");
+            var originalInjectMethod = injected.MainModule.Types.First(x => x.Name == "Chainloader")
+                .Methods.First(x => x.Name == "Initialize");
 
             var injectMethod = unity.MainModule.Import(originalInjectMethod);
 
-            var sceneManager = unity.MainModule.Types.First(x => x.Name == "SceneManager");
+            var sceneManager = unity.MainModule.Types.First(x => x.Name == "Application");
 
-            ILProcessor IL;
+            var voidType = unity.MainModule.Import(typeof(void));
+            var cctor = new MethodDefinition(".cctor",
+                Mono.Cecil.MethodAttributes.Static
+                | Mono.Cecil.MethodAttributes.Private
+                | Mono.Cecil.MethodAttributes.HideBySig
+                | Mono.Cecil.MethodAttributes.SpecialName
+                | Mono.Cecil.MethodAttributes.RTSpecialName,
+                voidType);
 
-            foreach (var loadScene in sceneManager.Methods.Where(x => x.Name == "LoadScene"))
-            {
-                IL = loadScene.Body.GetILProcessor();
+            var ilp = cctor.Body.GetILProcessor();
+            ilp.Append(ilp.Create(OpCodes.Call, injectMethod));
+            ilp.Append(ilp.Create(OpCodes.Ret));
 
-                IL.InsertBefore(loadScene.Body.Instructions[0], IL.Create(OpCodes.Call, injectMethod));
-            }
+            sceneManager.Methods.Add(cctor);
         }
     }
 }