diff --git a/BepInEx.Bootstrap/BepInEx.Bootstrap.csproj b/BepInEx.Bootstrap/BepInEx.Bootstrap.csproj
new file mode 100644
index 0000000..59c67e3
--- /dev/null
+++ b/BepInEx.Bootstrap/BepInEx.Bootstrap.csproj
@@ -0,0 +1,39 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {6E6BC1E5-5BE8-4566-B3AE-52C4CB218AEB}
+ Library
+ Properties
+ BepInEx.Bootstrap
+ BepInEx.Bootstrap
+ v3.5
+ 512
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+
+
+
+
+
+
+
+
+
+ {4ffba620-f5ed-47f9-b90c-dad1316fd9b9}
+ BepInEx
+
+
+
+
\ No newline at end of file
diff --git a/BepInEx.Bootstrap/Entrypoint.cs b/BepInEx.Bootstrap/Entrypoint.cs
new file mode 100644
index 0000000..50b22a2
--- /dev/null
+++ b/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;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/BepInEx.Bootstrap/Linker.cs b/BepInEx.Bootstrap/Linker.cs
new file mode 100644
index 0000000..3cd0e2c
--- /dev/null
+++ b/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();
+ }
+ }
+}
\ No newline at end of file
diff --git a/BepInEx.Bootstrap/Properties/AssemblyInfo.cs b/BepInEx.Bootstrap/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..d3a383d
--- /dev/null
+++ b/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")]
diff --git a/BepInEx.Patcher/BepInEx.Patcher.csproj b/BepInEx.Patcher/BepInEx.Patcher.csproj
index 5b095fd..a1bd7e4 100644
--- a/BepInEx.Patcher/BepInEx.Patcher.csproj
+++ b/BepInEx.Patcher/BepInEx.Patcher.csproj
@@ -21,7 +21,7 @@
true
full
false
- ..\bin\
+ ..\bin\patcher\
DEBUG;TRACE
prompt
4
@@ -32,7 +32,7 @@
AnyCPU
embedded
true
- ..\bin\
+ ..\bin\patcher\
TRACE
prompt
4
@@ -64,9 +64,7 @@
-
-
-
+
@@ -86,8 +84,7 @@
-
-
+
diff --git a/BepInEx.Patcher/EmbeddedResource.cs b/BepInEx.Patcher/EmbeddedResource.cs
index c736928..b87f284 100644
--- a/BepInEx.Patcher/EmbeddedResource.cs
+++ b/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
{
diff --git a/BepInEx.Patcher/Program.cs b/BepInEx.Patcher/Program.cs
index 7edf286..d12ecfb 100644
--- a/BepInEx.Patcher/Program.cs
+++ b/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;
}
}
-}
+}
\ No newline at end of file
diff --git a/BepInEx.Patcher/Properties/AssemblyInfo.cs b/BepInEx.Patcher/Properties/AssemblyInfo.cs
index ca3a802..9275ad9 100644
--- a/BepInEx.Patcher/Properties/AssemblyInfo.cs
+++ b/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")]
diff --git a/BepInEx.sln b/BepInEx.sln
index 67f35f4..9e9f3fe 100644
--- a/BepInEx.sln
+++ b/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
diff --git a/BepInEx/Bootstrap/AssemblyPatcher.cs b/BepInEx/Bootstrap/AssemblyPatcher.cs
index 663a3a9..aba07a3 100644
--- a/BepInEx/Bootstrap/AssemblyPatcher.cs
+++ b/BepInEx/Bootstrap/AssemblyPatcher.cs
@@ -149,4 +149,4 @@ namespace BepInEx.Bootstrap
}
}
}
-}
+}
\ No newline at end of file