Procházet zdrojové kódy

Patch all exes in current folder

Bepis před 7 roky
rodič
revize
e40c87137f
1 změnil soubory, kde provedl 25 přidání a 23 odebrání
  1. 25 23
      BepInEx.Patcher/Program.cs

+ 25 - 23
BepInEx.Patcher/Program.cs

@@ -18,37 +18,39 @@ namespace BepInEx.Patcher
 
         static void Main(string[] args)
         {
-            string managedDir = Environment.CurrentDirectory + @"\KoikatuTrial_Data\Managed";
-            if (!Directory.Exists(managedDir))
-                Error($"\"{managedDir}\" not found.");
+            foreach (string exePath in Directory.GetFiles(Directory.GetCurrentDirectory()))
+            {
 
-            string unityOutputDLL = Path.GetFullPath($"{managedDir}\\UnityEngine.dll");
-            if (!File.Exists(unityOutputDLL))
-                Error("\"UnityEngine.dll\" not found.");
+                string managedDir = Environment.CurrentDirectory + $@"\{Path.GetFileNameWithoutExtension(exePath)}_Data\Managed";
+                string unityOutputDLL = Path.GetFullPath($"{managedDir}\\UnityEngine.dll");
 
-            string unityOriginalDLL = Path.GetFullPath($"{managedDir}\\UnityEngine.dll.bak");
-            if (!File.Exists(unityOriginalDLL))
-                File.Copy(unityOutputDLL, unityOriginalDLL);
+                if (!Directory.Exists(managedDir) || !File.Exists(unityOutputDLL))
+                    continue;
 
-            string harmony = Path.GetFullPath($"{managedDir}\\0Harmony.dll");
-            File.WriteAllBytes(harmony, Resources._0Harmony);
+                string unityOriginalDLL = Path.GetFullPath($"{managedDir}\\UnityEngine.dll.bak");
+                if (!File.Exists(unityOriginalDLL))
+                    File.Copy(unityOutputDLL, unityOriginalDLL);
 
-            string injectedDLL = Path.GetFullPath($"{managedDir}\\BepInEx.dll");
-            File.WriteAllBytes(injectedDLL, Resources.BepInEx);
+                string harmony = Path.GetFullPath($"{managedDir}\\0Harmony.dll");
+                File.WriteAllBytes(harmony, Resources._0Harmony);
 
-            var defaultResolver = new DefaultAssemblyResolver();
-            defaultResolver.AddSearchDirectory(managedDir);
-            var rp = new ReaderParameters
-            {
-                AssemblyResolver = defaultResolver
-            };
+                string injectedDLL = Path.GetFullPath($"{managedDir}\\BepInEx.dll");
+                File.WriteAllBytes(injectedDLL, Resources.BepInEx);
+
+                var defaultResolver = new DefaultAssemblyResolver();
+                defaultResolver.AddSearchDirectory(managedDir);
+                var rp = new ReaderParameters
+                {
+                    AssemblyResolver = defaultResolver
+                };
 
-            AssemblyDefinition unity = AssemblyDefinition.ReadAssembly(unityOriginalDLL, rp);
-            AssemblyDefinition injected = AssemblyDefinition.ReadAssembly(injectedDLL, rp);
+                AssemblyDefinition unity = AssemblyDefinition.ReadAssembly(unityOriginalDLL, rp);
+                AssemblyDefinition injected = AssemblyDefinition.ReadAssembly(injectedDLL, rp);
 
-            InjectAssembly(unity, injected);
+                InjectAssembly(unity, injected);
             
-            unity.Write(unityOutputDLL);
+                unity.Write(unityOutputDLL);
+            }
         }
 
         static void InjectAssembly(AssemblyDefinition unity, AssemblyDefinition injected)