Переглянути джерело

Upgrade patcher to point to BepInEx folder

Bepis 5 роки тому
батько
коміт
066e171dbd

+ 39 - 0
BepInEx.Bootstrap/BepInEx.Bootstrap.csproj

@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{6E6BC1E5-5BE8-4566-B3AE-52C4CB218AEB}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>BepInEx.Bootstrap</RootNamespace>
+    <AssemblyName>BepInEx.Bootstrap</AssemblyName>
+    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Entrypoint.cs" />
+    <Compile Include="Linker.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\BepInEx\BepInEx.csproj">
+      <Project>{4ffba620-f5ed-47f9-b90c-dad1316fd9b9}</Project>
+      <Name>BepInEx</Name>
+    </ProjectReference>
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+</Project>

+ 36 - 0
BepInEx.Bootstrap/Entrypoint.cs

@@ -0,0 +1,36 @@
+using System;
+using System.Diagnostics;
+using System.IO;
+using System.Reflection;
+
+namespace BepInEx.Bootstrap
+{
+    public static class Entrypoint
+    {
+	    public static void Init()
+	    {
+		    AppDomain.CurrentDomain.AssemblyResolve += ResolveBepInEx;
+
+			Linker.StartBepInEx();
+	    }
+
+	    private static readonly string LocalDirectory = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
+
+	    private static Assembly ResolveBepInEx(object sender, ResolveEventArgs args)
+	    {
+		    string path = Path.Combine(LocalDirectory, $@"BepInEx\core\{new AssemblyName(args.Name).Name}.dll");
+
+		    if (!File.Exists(path))
+			    return null;
+
+		    try
+		    {
+			    return Assembly.LoadFile(path);
+		    }
+		    catch (Exception)
+		    {
+			    return null;
+		    }
+	    }
+    }
+}

+ 19 - 0
BepInEx.Bootstrap/Linker.cs

@@ -0,0 +1,19 @@
+using System.Diagnostics;
+using System.Reflection;
+
+namespace BepInEx.Bootstrap
+{
+	public static class Linker
+	{
+		public static void StartBepInEx()
+		{
+			var property = typeof(Paths)
+				.GetProperty("ExecutablePath", BindingFlags.Static | BindingFlags.Public)
+				?.GetSetMethod(true);
+
+			property?.Invoke(null, new object[] {Process.GetCurrentProcess().MainModule.FileName});
+			
+			Chainloader.Initialize();
+		}
+	}
+}

+ 36 - 0
BepInEx.Bootstrap/Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("BepInEx.Bootstrap")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("BepInEx.Bootstrap")]
+[assembly: AssemblyCopyright("Copyright ©  2018")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components.  If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("6e6bc1e5-5be8-4566-b3ae-52c4cb218aeb")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 4 - 7
BepInEx.Patcher/BepInEx.Patcher.csproj

@@ -21,7 +21,7 @@
     <DebugSymbols>true</DebugSymbols>
     <DebugType>full</DebugType>
     <Optimize>false</Optimize>
-    <OutputPath>..\bin\</OutputPath>
+    <OutputPath>..\bin\patcher\</OutputPath>
     <DefineConstants>DEBUG;TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
@@ -32,7 +32,7 @@
     <PlatformTarget>AnyCPU</PlatformTarget>
     <DebugType>embedded</DebugType>
     <Optimize>true</Optimize>
-    <OutputPath>..\bin\</OutputPath>
+    <OutputPath>..\bin\patcher\</OutputPath>
     <DefineConstants>TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
@@ -64,9 +64,7 @@
   </ItemGroup>
   <ItemGroup />
   <ItemGroup>
-    <EmbeddedResource Include="..\bin\0Harmony.dll" />
-    <EmbeddedResource Include="..\bin\BepInEx.dll" />
-    <EmbeddedResource Include="..\bin\Mono.Cecil.dll" />
+    <EmbeddedResource Include="..\bin\patcher\BepInEx.Bootstrap.dll" />
   </ItemGroup>
   <Import Project="..\BepInEx.Common\BepInEx.Common.projitems" Label="Shared" />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
@@ -86,8 +84,7 @@
     </ItemGroup>
     <ILRepack Parallel="true" Internalize="true" DebugInfo="true" PrimaryAssemblyFile="$(OutputPath)\$(AssemblyName)1.exe" InputAssemblies="@(InputAssemblies)" TargetKind="Exe" TargetPlatformVersion="v2" OutputFile="$(OutputPath)\$(AssemblyName).exe" />
     <Delete Files="@(InputAssemblies)" />
-    <Delete Files="$(OutputPath)\0Harmony.dll" />
-    <Delete Files="$(OutputPath)\BepInEx.dll" />
+    <Delete Files="$(OutputPath)\BepInEx.Bootstrap.dll" />
   </Target>
   <!-- /ILRepack -->
   <Import Project="..\packages\ILRepack.MSBuild.Task.1.0.9\build\ILRepack.MSBuild.Task.targets" Condition="Exists('..\packages\ILRepack.MSBuild.Task.1.0.9\build\ILRepack.MSBuild.Task.targets')" />

+ 1 - 5
BepInEx.Patcher/EmbeddedResource.cs

@@ -1,9 +1,5 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
+using System.IO;
 using System.Reflection;
-using System.Text;
 
 namespace BepInEx.Patcher
 {

+ 8 - 13
BepInEx.Patcher/Program.cs

@@ -85,11 +85,8 @@ namespace BepInEx.Patcher
 
             try
             {
-                string harmony = Path.GetFullPath($"{managedDir}\\0Harmony.dll");
-                File.WriteAllBytes(harmony, EmbeddedResource.Get("BepInEx.Patcher.0Harmony.dll"));
-
-                string injectedDLL = Path.GetFullPath($"{managedDir}\\BepInEx.dll");
-                File.WriteAllBytes(injectedDLL, EmbeddedResource.Get("BepInEx.Patcher.BepInEx.dll"));
+                string injectedDLL = Path.GetFullPath($"{managedDir}\\BepInEx.Bootstrap.dll");
+                File.WriteAllBytes(injectedDLL, EmbeddedResource.Get("BepInEx.Patcher.BepInEx.Bootstrap.dll"));
 
                 var defaultResolver = new DefaultAssemblyResolver();
                 defaultResolver.AddSearchDirectory(managedDir);
@@ -156,8 +153,8 @@ 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 == "Entrypoint")
+                .Methods.First(x => x.Name == "Init");
 
             var injectMethod = unity.MainModule.ImportReference(originalInjectMethod);
 
@@ -185,17 +182,15 @@ namespace BepInEx.Patcher
             message = "";
 
             //check if already patched
-            var sceneManager = unity.MainModule.Types.First(x => x.Name == "Application");
-
-            if (sceneManager.Methods.Any(x => x.Name == ".cctor"))
+            if (unity.MainModule.AssemblyReferences.Any(x => x.Name == "BepInEx"))
             {
-                //already patched by bepin
                 canPatch = false;
 
-                message += "This assembly has already been patched by BepInEx.";
+                message += "This assembly has already been patched by BepInEx.\r\n";
             }
 
+	        message = message.Trim();
             return canPatch;
         }
     }
-}
+}

+ 2 - 2
BepInEx.Patcher/Properties/AssemblyInfo.cs

@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
 // You can specify all the values or you can default the Build and Revision Numbers
 // by using the '*' as shown below:
 // [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("3.2.0.0")]
-[assembly: AssemblyFileVersion("3.2.0.0")]
+[assembly: AssemblyVersion("4.1.0.0")]
+[assembly: AssemblyFileVersion("4.1.0.0")]

+ 10 - 1
BepInEx.sln

@@ -12,11 +12,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BepInEx.Patcher", "BepInEx.
 EndProject
 Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "BepInEx.Common", "BepInEx.Common\BepInEx.Common.shproj", "{D8DEEEF7-28F5-4F13-A004-C581CE051CDC}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BepInEx.Bootstrap", "BepInEx.Bootstrap\BepInEx.Bootstrap.csproj", "{6E6BC1E5-5BE8-4566-B3AE-52C4CB218AEB}"
+EndProject
 Global
 	GlobalSection(SharedMSBuildProjectFiles) = preSolution
 		BepInEx.Common\BepInEx.Common.projitems*{4ffba620-f5ed-47f9-b90c-dad1316fd9b9}*SharedItemsImports = 4
 		BepInEx.Common\BepInEx.Common.projitems*{d8deeef7-28f5-4f13-a004-c581ce051cdc}*SharedItemsImports = 13
-		BepInEx.Common\BepInEx.Common.projitems*{dc89f18b-235b-4c01-ab31-af40dce5c4c7}*SharedItemsImports = 4
 	EndGlobalSection
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|v2017 = Debug|v2017
@@ -45,6 +46,14 @@ Global
 		{DC89F18B-235B-4C01-AB31-AF40DCE5C4C7}.Release|v2017.ActiveCfg = Release|Any CPU
 		{DC89F18B-235B-4C01-AB31-AF40DCE5C4C7}.Release|v4.ActiveCfg = Release|Any CPU
 		{DC89F18B-235B-4C01-AB31-AF40DCE5C4C7}.Release|v5.ActiveCfg = Release|Any CPU
+		{6E6BC1E5-5BE8-4566-B3AE-52C4CB218AEB}.Debug|v2017.ActiveCfg = Release|Any CPU
+		{6E6BC1E5-5BE8-4566-B3AE-52C4CB218AEB}.Debug|v4.ActiveCfg = Release|Any CPU
+		{6E6BC1E5-5BE8-4566-B3AE-52C4CB218AEB}.Debug|v4.Build.0 = Release|Any CPU
+		{6E6BC1E5-5BE8-4566-B3AE-52C4CB218AEB}.Debug|v5.ActiveCfg = Release|Any CPU
+		{6E6BC1E5-5BE8-4566-B3AE-52C4CB218AEB}.Debug|v5.Build.0 = Release|Any CPU
+		{6E6BC1E5-5BE8-4566-B3AE-52C4CB218AEB}.Release|v2017.ActiveCfg = Release|Any CPU
+		{6E6BC1E5-5BE8-4566-B3AE-52C4CB218AEB}.Release|v4.ActiveCfg = Release|Any CPU
+		{6E6BC1E5-5BE8-4566-B3AE-52C4CB218AEB}.Release|v5.ActiveCfg = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 1 - 1
BepInEx/Bootstrap/AssemblyPatcher.cs

@@ -149,4 +149,4 @@ namespace BepInEx.Bootstrap
 		    }
 	    }
     }
-}
+}