mirror of
https://github.com/BepInEx/BepInEx.git
synced 2026-10-20 01:46:13 +00:00
Upgrade patcher to point to BepInEx folder
This commit is contained in:
1 parent
3eef163425
commit
066e171dbd
10 files changed
+156
-29
No files matched your search
@@ -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>
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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")]
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
<DebugType>full</DebugType>
|
<DebugType>full</DebugType>
|
||||||
<Optimize>false</Optimize>
|
<Optimize>false</Optimize>
|
||||||
<OutputPath>..\bin\</OutputPath>
|
<OutputPath>..\bin\patcher\</OutputPath>
|
||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
@@ -32,7 +32,7 @@
|
|||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
<DebugType>embedded</DebugType>
|
<DebugType>embedded</DebugType>
|
||||||
<Optimize>true</Optimize>
|
<Optimize>true</Optimize>
|
||||||
<OutputPath>..\bin\</OutputPath>
|
<OutputPath>..\bin\patcher\</OutputPath>
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
@@ -64,9 +64,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup />
|
<ItemGroup />
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Include="..\bin\0Harmony.dll" />
|
<EmbeddedResource Include="..\bin\patcher\BepInEx.Bootstrap.dll" />
|
||||||
<EmbeddedResource Include="..\bin\BepInEx.dll" />
|
|
||||||
<EmbeddedResource Include="..\bin\Mono.Cecil.dll" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="..\BepInEx.Common\BepInEx.Common.projitems" Label="Shared" />
|
<Import Project="..\BepInEx.Common\BepInEx.Common.projitems" Label="Shared" />
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
@@ -86,8 +84,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ILRepack Parallel="true" Internalize="true" DebugInfo="true" PrimaryAssemblyFile="$(OutputPath)\$(AssemblyName)1.exe" InputAssemblies="@(InputAssemblies)" TargetKind="Exe" TargetPlatformVersion="v2" OutputFile="$(OutputPath)\$(AssemblyName).exe" />
|
<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="@(InputAssemblies)" />
|
||||||
<Delete Files="$(OutputPath)\0Harmony.dll" />
|
<Delete Files="$(OutputPath)\BepInEx.Bootstrap.dll" />
|
||||||
<Delete Files="$(OutputPath)\BepInEx.dll" />
|
|
||||||
</Target>
|
</Target>
|
||||||
<!-- /ILRepack -->
|
<!-- /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')" />
|
<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,9 +1,5 @@
|
|||||||
using System;
|
using System.IO;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace BepInEx.Patcher
|
namespace BepInEx.Patcher
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -85,11 +85,8 @@ namespace BepInEx.Patcher
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string harmony = Path.GetFullPath($"{managedDir}\\0Harmony.dll");
|
string injectedDLL = Path.GetFullPath($"{managedDir}\\BepInEx.Bootstrap.dll");
|
||||||
File.WriteAllBytes(harmony, EmbeddedResource.Get("BepInEx.Patcher.0Harmony.dll"));
|
File.WriteAllBytes(injectedDLL, EmbeddedResource.Get("BepInEx.Patcher.BepInEx.Bootstrap.dll"));
|
||||||
|
|
||||||
string injectedDLL = Path.GetFullPath($"{managedDir}\\BepInEx.dll");
|
|
||||||
File.WriteAllBytes(injectedDLL, EmbeddedResource.Get("BepInEx.Patcher.BepInEx.dll"));
|
|
||||||
|
|
||||||
var defaultResolver = new DefaultAssemblyResolver();
|
var defaultResolver = new DefaultAssemblyResolver();
|
||||||
defaultResolver.AddSearchDirectory(managedDir);
|
defaultResolver.AddSearchDirectory(managedDir);
|
||||||
@@ -156,8 +153,8 @@ namespace BepInEx.Patcher
|
|||||||
static void InjectAssembly(AssemblyDefinition unity, AssemblyDefinition injected)
|
static void InjectAssembly(AssemblyDefinition unity, AssemblyDefinition injected)
|
||||||
{
|
{
|
||||||
//Entry point
|
//Entry point
|
||||||
var originalInjectMethod = injected.MainModule.Types.First(x => x.Name == "Chainloader")
|
var originalInjectMethod = injected.MainModule.Types.First(x => x.Name == "Entrypoint")
|
||||||
.Methods.First(x => x.Name == "Initialize");
|
.Methods.First(x => x.Name == "Init");
|
||||||
|
|
||||||
var injectMethod = unity.MainModule.ImportReference(originalInjectMethod);
|
var injectMethod = unity.MainModule.ImportReference(originalInjectMethod);
|
||||||
|
|
||||||
@@ -185,17 +182,15 @@ namespace BepInEx.Patcher
|
|||||||
message = "";
|
message = "";
|
||||||
|
|
||||||
//check if already patched
|
//check if already patched
|
||||||
var sceneManager = unity.MainModule.Types.First(x => x.Name == "Application");
|
if (unity.MainModule.AssemblyReferences.Any(x => x.Name == "BepInEx"))
|
||||||
|
|
||||||
if (sceneManager.Methods.Any(x => x.Name == ".cctor"))
|
|
||||||
{
|
{
|
||||||
//already patched by bepin
|
|
||||||
canPatch = false;
|
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;
|
return canPatch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("3.2.0.0")]
|
[assembly: AssemblyVersion("4.1.0.0")]
|
||||||
[assembly: AssemblyFileVersion("3.2.0.0")]
|
[assembly: AssemblyFileVersion("4.1.0.0")]
|
||||||
+10
-1
@@ -12,11 +12,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BepInEx.Patcher", "BepInEx.
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "BepInEx.Common", "BepInEx.Common\BepInEx.Common.shproj", "{D8DEEEF7-28F5-4F13-A004-C581CE051CDC}"
|
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "BepInEx.Common", "BepInEx.Common\BepInEx.Common.shproj", "{D8DEEEF7-28F5-4F13-A004-C581CE051CDC}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BepInEx.Bootstrap", "BepInEx.Bootstrap\BepInEx.Bootstrap.csproj", "{6E6BC1E5-5BE8-4566-B3AE-52C4CB218AEB}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SharedMSBuildProjectFiles) = preSolution
|
GlobalSection(SharedMSBuildProjectFiles) = preSolution
|
||||||
BepInEx.Common\BepInEx.Common.projitems*{4ffba620-f5ed-47f9-b90c-dad1316fd9b9}*SharedItemsImports = 4
|
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*{d8deeef7-28f5-4f13-a004-c581ce051cdc}*SharedItemsImports = 13
|
||||||
BepInEx.Common\BepInEx.Common.projitems*{dc89f18b-235b-4c01-ab31-af40dce5c4c7}*SharedItemsImports = 4
|
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|v2017 = Debug|v2017
|
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|v2017.ActiveCfg = Release|Any CPU
|
||||||
{DC89F18B-235B-4C01-AB31-AF40DCE5C4C7}.Release|v4.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
|
{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
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
@@ -149,4 +149,4 @@ namespace BepInEx.Bootstrap
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user