From 85ee88e1ca9d9631859873324b689aceb421f7de Mon Sep 17 00:00:00 2001 From: exdownloader Date: Mon, 23 Apr 2018 16:27:56 +0100 Subject: [PATCH] Patcher downgrade --- BepInEx.Patcher/BepInEx.Patcher.csproj | 52 +++++++++++----- BepInEx.Patcher/FodyWeavers.xml | 4 -- BepInEx.Patcher/Program.cs | 51 +++++++--------- BepInEx.Patcher/Resources.Designer.cs | 83 ++++++++++++++++++++++++++ BepInEx.Patcher/Resources.resx | 68 +++++++++++++++++++++ BepInEx.Patcher/packages.config | 6 +- BepInEx.sln | 5 +- BepInEx/BepInEx.csproj | 2 +- BepInEx/Chainloader.cs | 4 +- BepInEx/Config.cs | 5 +- 10 files changed, 224 insertions(+), 56 deletions(-) delete mode 100644 BepInEx.Patcher/FodyWeavers.xml create mode 100644 BepInEx.Patcher/Resources.Designer.cs create mode 100644 BepInEx.Patcher/Resources.resx diff --git a/BepInEx.Patcher/BepInEx.Patcher.csproj b/BepInEx.Patcher/BepInEx.Patcher.csproj index d826d22..16d4cdf 100644 --- a/BepInEx.Patcher/BepInEx.Patcher.csproj +++ b/BepInEx.Patcher/BepInEx.Patcher.csproj @@ -1,5 +1,6 @@  + Debug @@ -8,7 +9,7 @@ Exe BepInEx.Patcher BepInEx.Patcher - v4.5.2 + v3.5 512 true @@ -17,14 +18,15 @@ AnyCPU - true - full + false + none false ..\bin\ DEBUG;TRACE prompt 4 false + Off AnyCPU @@ -37,11 +39,9 @@ false - - ..\packages\Costura.Fody.2.0.0\lib\net452\Costura.dll - - ..\packages\Mono.Cecil.0.10.0\lib\net40\Mono.Cecil.dll + ..\packages\Mono.Cecil.0.10.0\lib\net35\Mono.Cecil.dll + True @@ -53,14 +53,26 @@ + + True + True + Resources.resx + - - Designer - + + ResXFileCodeGenerator + Resources.Designer.cs + + + + + + + @@ -68,9 +80,21 @@ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - + + - - + + + + + + + + + + + + + + \ No newline at end of file diff --git a/BepInEx.Patcher/FodyWeavers.xml b/BepInEx.Patcher/FodyWeavers.xml deleted file mode 100644 index c6e1b7c..0000000 --- a/BepInEx.Patcher/FodyWeavers.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/BepInEx.Patcher/Program.cs b/BepInEx.Patcher/Program.cs index 021e531..d67371f 100644 --- a/BepInEx.Patcher/Program.cs +++ b/BepInEx.Patcher/Program.cs @@ -1,12 +1,8 @@ -using BepInEx.Common; -using Mono.Cecil; +using Mono.Cecil; using Mono.Cecil.Cil; using System; -using System.Collections.Generic; using System.IO; using System.Linq; -using System.Reflection; -using System.Text; namespace BepInEx.Patcher { @@ -22,34 +18,33 @@ namespace BepInEx.Patcher static void Main(string[] args) { - string unityOutputDLL = Path.GetFullPath(@"KoikatuTrial_Data\Managed\UnityEngine.dll"); + string managedDir = Environment.CurrentDirectory + @"\KoikatuTrial_Data\Managed"; + if (!Directory.Exists(managedDir)) + Error($"\"{managedDir}\" not found."); + + string unityOutputDLL = Path.GetFullPath($"{managedDir}\\UnityEngine.dll"); if (!File.Exists(unityOutputDLL)) Error("\"UnityEngine.dll\" not found."); - string unityOriginalDLL = Path.GetFullPath(@"KoikatuTrial_Data\Managed\UnityEngine.dll.bak"); + string unityOriginalDLL = Path.GetFullPath($"{managedDir}\\UnityEngine.dll.bak"); if (!File.Exists(unityOriginalDLL)) File.Copy(unityOutputDLL, unityOriginalDLL); - - string injectedDLL = Path.GetFullPath(@"KoikatuTrial_Data\Managed\BepInEx.dll"); - if (!File.Exists(unityOutputDLL)) - Error("\"BepInEx.dll\" not found."); - - string referenceDir = Path.GetFullPath(@"KoikatuTrial_Data\Managed"); + string harmony = Path.GetFullPath($"{managedDir}\\0Harmony.dll"); + File.WriteAllBytes(harmony, Resources._0Harmony); + string injectedDLL = Path.GetFullPath($"{managedDir}\\BepInEx.dll"); + File.WriteAllBytes(injectedDLL, Resources.BepInEx); var defaultResolver = new DefaultAssemblyResolver(); - defaultResolver.AddSearchDirectory(referenceDir); - - AssemblyDefinition unity = AssemblyDefinition.ReadAssembly(unityOriginalDLL, new ReaderParameters + defaultResolver.AddSearchDirectory(managedDir); + var rp = new ReaderParameters { AssemblyResolver = defaultResolver - }); - AssemblyDefinition injected = AssemblyDefinition.ReadAssembly(injectedDLL, new ReaderParameters - { - AssemblyResolver = defaultResolver - }); + }; + AssemblyDefinition unity = AssemblyDefinition.ReadAssembly(unityOriginalDLL, rp); + AssemblyDefinition injected = AssemblyDefinition.ReadAssembly(injectedDLL, rp); InjectAssembly(unity, injected); @@ -62,17 +57,17 @@ namespace BepInEx.Patcher var originalInjectMethod = injected.MainModule.Types.First(x => x.Name == "Chainloader") .Methods.First(x => x.Name == "Initialize"); - var injectMethod = unity.MainModule.Import(originalInjectMethod); + var injectMethod = unity.MainModule.ImportReference(originalInjectMethod); var sceneManager = unity.MainModule.Types.First(x => x.Name == "Application"); - var voidType = unity.MainModule.Import(typeof(void)); + var voidType = unity.MainModule.ImportReference(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, + MethodAttributes.Static + | MethodAttributes.Private + | MethodAttributes.HideBySig + | MethodAttributes.SpecialName + | MethodAttributes.RTSpecialName, voidType); var ilp = cctor.Body.GetILProcessor(); diff --git a/BepInEx.Patcher/Resources.Designer.cs b/BepInEx.Patcher/Resources.Designer.cs new file mode 100644 index 0000000..5c60b46 --- /dev/null +++ b/BepInEx.Patcher/Resources.Designer.cs @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace BepInEx.Patcher { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("BepInEx.Patcher.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized resource of type System.Byte[]. + /// + internal static byte[] _0Harmony { + get { + object obj = ResourceManager.GetObject("_0Harmony", resourceCulture); + return ((byte[])(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Byte[]. + /// + internal static byte[] BepInEx { + get { + object obj = ResourceManager.GetObject("BepInEx", resourceCulture); + return ((byte[])(obj)); + } + } + } +} diff --git a/BepInEx.Patcher/Resources.resx b/BepInEx.Patcher/Resources.resx new file mode 100644 index 0000000..a7366c1 --- /dev/null +++ b/BepInEx.Patcher/Resources.resx @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + ..\bin\BepInEx.dll;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\bin\0Harmony.dll;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BepInEx.Patcher/packages.config b/BepInEx.Patcher/packages.config index bdc9af8..a6d422c 100644 --- a/BepInEx.Patcher/packages.config +++ b/BepInEx.Patcher/packages.config @@ -1,6 +1,6 @@  - - - + + + \ No newline at end of file diff --git a/BepInEx.sln b/BepInEx.sln index e758079..bb8e853 100644 --- a/BepInEx.sln +++ b/BepInEx.sln @@ -1,11 +1,14 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.27130.2036 +VisualStudioVersion = 15.0.27130.2027 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BepInEx", "BepInEx\BepInEx.csproj", "{4FFBA620-F5ED-47F9-B90C-DAD1316FD9B9}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BepInEx.Patcher", "BepInEx.Patcher\BepInEx.Patcher.csproj", "{DC89F18B-235B-4C01-AB31-AF40DCE5C4C7}" + ProjectSection(ProjectDependencies) = postProject + {4FFBA620-F5ED-47F9-B90C-DAD1316FD9B9} = {4FFBA620-F5ED-47F9-B90C-DAD1316FD9B9} + EndProjectSection EndProject Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "BepInEx.Common", "BepInEx.Common\BepInEx.Common.shproj", "{D8DEEEF7-28F5-4F13-A004-C581CE051CDC}" EndProject diff --git a/BepInEx/BepInEx.csproj b/BepInEx/BepInEx.csproj index ada2bfb..99adbc0 100644 --- a/BepInEx/BepInEx.csproj +++ b/BepInEx/BepInEx.csproj @@ -17,7 +17,7 @@ AnyCPU none true - ..\bin\KoikatuTrial_Data\Managed\ + ..\bin\ TRACE prompt 4 diff --git a/BepInEx/Chainloader.cs b/BepInEx/Chainloader.cs index 1a0ded7..317bbfa 100644 --- a/BepInEx/Chainloader.cs +++ b/BepInEx/Chainloader.cs @@ -56,9 +56,9 @@ namespace BepInEx UnityEngine.Object.DontDestroyOnLoad(ManagerObject); - if (Directory.Exists(Utility.PluginsDirectory)) + if (Directory.Exists(Common.Utility.PluginsDirectory)) { - var pluginTypes = TypeLoader.LoadTypes(Utility.PluginsDirectory).ToList(); + var pluginTypes = TypeLoader.LoadTypes(Common.Utility.PluginsDirectory).ToList(); BepInLogger.Log($"{pluginTypes.Count} plugins found"); diff --git a/BepInEx/Config.cs b/BepInEx/Config.cs index 3dbb4f6..8c40c04 100644 --- a/BepInEx/Config.cs +++ b/BepInEx/Config.cs @@ -1,5 +1,4 @@ -using BepInEx.Common; -using System; +using System; using System.Collections.Generic; using System.IO; using System.Text.RegularExpressions; @@ -13,7 +12,7 @@ namespace BepInEx { private static Dictionary> cache = new Dictionary>(); - private static string configPath => Path.Combine(Utility.PluginsDirectory, "config.ini"); + private static string configPath => Path.Combine(Common.Utility.PluginsDirectory, "config.ini"); private static Regex sanitizeKeyRegex = new Regex("[^a-zA-Z0-9]+");