mirror of
https://github.com/BepInEx/BepInEx.git
synced 2026-10-20 01:46:13 +00:00
Delete hardpatcher
Hardpatcher is not supported anymore and should not be used
This commit is contained in:
1 parent
639dbb475c
commit
c85ece09fe
8 files changed
-385
No files matched your search
@@ -1,19 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net35</TargetFramework>
|
||||
<AssemblyTitle>BepInEx.Bootstrap</AssemblyTitle>
|
||||
<Product>BepInEx.Bootstrap</Product>
|
||||
<DebugType>none</DebugType>
|
||||
<OutputPath>..\bin\Patcher\</OutputPath>
|
||||
<LangVersion>9</LangVersion>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BepInEx.Core\BepInEx.Core.csproj"/>
|
||||
<ProjectReference Include="..\BepInEx.Unity\BepInEx.Unity.csproj"/>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" PrivateAssets="All"/>
|
||||
</ItemGroup>
|
||||
<Import Project="..\BepInEx.Shared\BepInEx.Shared.projitems" Label="Shared"/>
|
||||
</Project>
|
||||
@@ -1,37 +0,0 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
||||
namespace BepInEx.Bootstrap
|
||||
{
|
||||
public static class Entrypoint
|
||||
{
|
||||
private static readonly string LocalDirectory =
|
||||
Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
AppDomain.CurrentDomain.AssemblyResolve += ResolveBepInEx;
|
||||
|
||||
Linker.StartBepInEx();
|
||||
}
|
||||
|
||||
private static Assembly ResolveBepInEx(object sender, ResolveEventArgs args)
|
||||
{
|
||||
var 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
using System.Diagnostics;
|
||||
using BepInEx.Unity.Bootstrap;
|
||||
|
||||
namespace BepInEx.Bootstrap
|
||||
{
|
||||
public static class Linker
|
||||
{
|
||||
public static void StartBepInEx()
|
||||
{
|
||||
var chainloader = new UnityChainloader();
|
||||
|
||||
chainloader.Initialize(Process.GetCurrentProcess().MainModule.FileName);
|
||||
chainloader.Execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net35</TargetFramework>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<AssemblyTitle>BepInEx.Patcher</AssemblyTitle>
|
||||
<Product>BepInEx.Patcher</Product>
|
||||
<DebugType>embedded</DebugType>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>..\bin\Patcher\</OutputPath>
|
||||
<LangVersion>9</LangVersion>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<StartupObject>BepInEx.Patcher.Program</StartupObject>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ILRepack" Version="2.1.0-beta1"/>
|
||||
<PackageReference Include="ILRepack.Lib.MSBuild.Task" Version="2.0.18.2"/>
|
||||
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" PrivateAssets="All"/>
|
||||
<PackageReference Include="Mono.Cecil" Version="0.10.4"/>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="ILRepack.targets"/>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BepInEx.Unity\BepInEx.Unity.csproj"/>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="..\bin\patcher\BepInEx.Bootstrap.dll"/>
|
||||
</ItemGroup>
|
||||
<Import Project="..\BepInEx.Shared\BepInEx.Shared.projitems" Label="Shared"/>
|
||||
</Project>
|
||||
@@ -1,21 +0,0 @@
|
||||
using System.Reflection;
|
||||
|
||||
namespace BepInEx.Patcher
|
||||
{
|
||||
internal static class EmbeddedResource
|
||||
{
|
||||
public static byte[] Get(string resourceName)
|
||||
{
|
||||
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
|
||||
{
|
||||
var length = (int) stream.Length;
|
||||
|
||||
var buffer = new byte[length];
|
||||
|
||||
stream.Read(buffer, 0, length);
|
||||
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Target Name="ILRepacker" AfterTargets="Build" Condition="'$(Configuration)' == 'Release'">
|
||||
|
||||
<Copy SourceFiles="$(OutputPath)\$(AssemblyName).exe" DestinationFiles="$(OutputPath)\$(AssemblyName)1.exe"/>
|
||||
|
||||
<ItemGroup>
|
||||
<InputAssemblies Include="$(OutputPath)\$(AssemblyName)1.exe" />
|
||||
<InputAssemblies Include="$(OutputPath)\Mono.Cecil.dll" />
|
||||
</ItemGroup>
|
||||
|
||||
<ILRepack
|
||||
Parallel="false"
|
||||
Internalize="true"
|
||||
DebugInfo="true"
|
||||
InputAssemblies="@(InputAssemblies)"
|
||||
TargetKind="Exe"
|
||||
TargetPlatformVersion="v2"
|
||||
OutputFile="$(OutputPath)\$(AssemblyName).exe" />
|
||||
|
||||
<Delete Files="@(InputAssemblies)" />
|
||||
<Delete Files="$(OutputPath)\BepInEx.Bootstrap.dll" />
|
||||
|
||||
</Target>
|
||||
</Project>
|
||||
@@ -1,208 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using Mono.Cecil;
|
||||
using Mono.Cecil.Cil;
|
||||
using MethodAttributes = Mono.Cecil.MethodAttributes;
|
||||
|
||||
namespace BepInEx.Patcher
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
private static void WriteError(string message)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine("Failed");
|
||||
Console.ResetColor();
|
||||
Console.WriteLine(message);
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
private static void WriteSuccess()
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.WriteLine("Success");
|
||||
Console.ResetColor();
|
||||
}
|
||||
|
||||
private static string GetUnityEngineAssembly(string managedDir)
|
||||
{
|
||||
var path = Path.Combine(managedDir, "UnityEngine.CoreModule.dll");
|
||||
if (File.Exists(path))
|
||||
return path;
|
||||
return Path.Combine(managedDir, "UnityEngine.dll");
|
||||
}
|
||||
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine($"BepInEx Patcher v{Assembly.GetExecutingAssembly().GetName().Version}");
|
||||
|
||||
if (args.Length >= 1) //short circuit for specific dll patch
|
||||
Environment.Exit(PatchUnityExe(Path.GetDirectoryName(args[0]), args[0], out var message) ? 0 : 9999);
|
||||
|
||||
var hasFound = false;
|
||||
var hasFailure = false;
|
||||
var patchCount = 0;
|
||||
|
||||
foreach (var exePath in Directory.GetFiles(Directory.GetCurrentDirectory()))
|
||||
{
|
||||
var gameName = Path.GetFileNameWithoutExtension(exePath);
|
||||
|
||||
var managedDir = Environment.CurrentDirectory + $@"\{gameName}_Data\Managed";
|
||||
|
||||
var unityOutputDLL = GetUnityEngineAssembly(managedDir);
|
||||
|
||||
if (!Directory.Exists(managedDir) || !File.Exists(unityOutputDLL))
|
||||
continue;
|
||||
|
||||
hasFound = true;
|
||||
|
||||
Console.Write($"Patching {gameName}... ");
|
||||
|
||||
if (PatchUnityExe(managedDir, unityOutputDLL, out var message))
|
||||
{
|
||||
WriteSuccess();
|
||||
patchCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteError(message);
|
||||
hasFailure = true;
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine();
|
||||
|
||||
if (!hasFound)
|
||||
Console.WriteLine("Didn't find any games to patch! Exiting.");
|
||||
else
|
||||
Console.WriteLine($"Patched {patchCount} assemblies!");
|
||||
|
||||
if (hasFailure)
|
||||
{
|
||||
Console.WriteLine("Press any key to continue...");
|
||||
Console.ReadKey();
|
||||
}
|
||||
else
|
||||
{
|
||||
Thread.Sleep(3000);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool PatchUnityExe(string managedDir, string unityOutputDLL, out string message)
|
||||
{
|
||||
message = null;
|
||||
|
||||
try
|
||||
{
|
||||
var injectedDLL = Path.GetFullPath($"{managedDir}\\BepInEx.Bootstrap.dll");
|
||||
File.WriteAllBytes(injectedDLL, EmbeddedResource.Get("BepInEx.Patcher.BepInEx.Bootstrap.dll"));
|
||||
|
||||
var defaultResolver = new DefaultAssemblyResolver();
|
||||
defaultResolver.AddSearchDirectory(managedDir);
|
||||
var rp = new ReaderParameters
|
||||
{
|
||||
AssemblyResolver = defaultResolver
|
||||
};
|
||||
|
||||
var unityBackupDLL = $"{GetUnityEngineAssembly(managedDir)}.bak";
|
||||
|
||||
//determine which assembly to use as a base
|
||||
var unity = AssemblyDefinition.ReadAssembly(unityOutputDLL, rp);
|
||||
|
||||
if (!VerifyAssembly(unity, out message))
|
||||
{
|
||||
//try and fall back to .bak if exists
|
||||
if (File.Exists(unityBackupDLL))
|
||||
{
|
||||
unity.Dispose();
|
||||
unity = AssemblyDefinition.ReadAssembly(unityBackupDLL, rp);
|
||||
|
||||
if (!VerifyAssembly(unity, out message))
|
||||
{
|
||||
//can't use anything
|
||||
unity.Dispose();
|
||||
message += "\r\nThe backup is not usable.";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//can't use anything
|
||||
unity.Dispose();
|
||||
message += "\r\nNo backup exists.";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//make a backup of the assembly
|
||||
File.Copy(unityOutputDLL, unityBackupDLL, true);
|
||||
unity.Dispose();
|
||||
unity = AssemblyDefinition.ReadAssembly(unityBackupDLL, rp);
|
||||
}
|
||||
|
||||
//patch
|
||||
using (unity)
|
||||
using (var injected = AssemblyDefinition.ReadAssembly(injectedDLL, rp))
|
||||
{
|
||||
InjectAssembly(unity, injected);
|
||||
|
||||
unity.Write(unityOutputDLL);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
message = e.ToString();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void InjectAssembly(AssemblyDefinition unity, AssemblyDefinition injected)
|
||||
{
|
||||
//Entry point
|
||||
var originalInjectMethod = injected.MainModule.Types.First(x => x.Name == "Entrypoint")
|
||||
.Methods.First(x => x.Name == "Init");
|
||||
|
||||
var injectMethod = unity.MainModule.ImportReference(originalInjectMethod);
|
||||
|
||||
var sceneManager = unity.MainModule.Types.First(x => x.Name == "Application");
|
||||
|
||||
var voidType = unity.MainModule.ImportReference(typeof(void));
|
||||
var cctor = new MethodDefinition(".cctor",
|
||||
MethodAttributes.Static
|
||||
| MethodAttributes.Private
|
||||
| MethodAttributes.HideBySig
|
||||
| MethodAttributes.SpecialName
|
||||
| MethodAttributes.RTSpecialName,
|
||||
voidType);
|
||||
|
||||
var ilp = cctor.Body.GetILProcessor();
|
||||
ilp.Append(ilp.Create(OpCodes.Call, injectMethod));
|
||||
ilp.Append(ilp.Create(OpCodes.Ret));
|
||||
|
||||
sceneManager.Methods.Add(cctor);
|
||||
}
|
||||
|
||||
private static bool VerifyAssembly(AssemblyDefinition unity, out string message)
|
||||
{
|
||||
var canPatch = true;
|
||||
message = "";
|
||||
|
||||
//check if already patched
|
||||
if (unity.MainModule.AssemblyReferences.Any(x => x.Name.Contains("BepInEx")))
|
||||
{
|
||||
canPatch = false;
|
||||
|
||||
message += "This assembly has already been patched by BepInEx.\r\n";
|
||||
}
|
||||
|
||||
message = message.Trim();
|
||||
return canPatch;
|
||||
}
|
||||
}
|
||||
}
|
||||
-24
@@ -3,16 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.28922.388
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "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}
|
||||
{6E6BC1E5-5BE8-4566-B3AE-52C4CB218AEB} = {6E6BC1E5-5BE8-4566-B3AE-52C4CB218AEB}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BepInEx.Bootstrap", "BepInEx.Bootstrap\BepInEx.Bootstrap.csproj", "{6E6BC1E5-5BE8-4566-B3AE-52C4CB218AEB}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Patcher", "Patcher", "{A9071994-3533-4C1B-89DC-D817B676AB41}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BepInExTests", "BepInExTests\BepInExTests.csproj", "{E7CD429A-D057-48E3-8C51-E5C934E8E07B}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{4FFBA620-F5ED-47F9-B90C-DAD1316FD9B9} = {4FFBA620-F5ED-47F9-B90C-DAD1316FD9B9}
|
||||
@@ -61,18 +51,6 @@ Global
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{DC89F18B-235B-4C01-AB31-AF40DCE5C4C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{DC89F18B-235B-4C01-AB31-AF40DCE5C4C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DC89F18B-235B-4C01-AB31-AF40DCE5C4C7}.Release_NetFramework|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{DC89F18B-235B-4C01-AB31-AF40DCE5C4C7}.Release_Unity|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{DC89F18B-235B-4C01-AB31-AF40DCE5C4C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{DC89F18B-235B-4C01-AB31-AF40DCE5C4C7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{6E6BC1E5-5BE8-4566-B3AE-52C4CB218AEB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{6E6BC1E5-5BE8-4566-B3AE-52C4CB218AEB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6E6BC1E5-5BE8-4566-B3AE-52C4CB218AEB}.Release_NetFramework|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6E6BC1E5-5BE8-4566-B3AE-52C4CB218AEB}.Release_Unity|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6E6BC1E5-5BE8-4566-B3AE-52C4CB218AEB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6E6BC1E5-5BE8-4566-B3AE-52C4CB218AEB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E7CD429A-D057-48E3-8C51-E5C934E8E07B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E7CD429A-D057-48E3-8C51-E5C934E8E07B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E7CD429A-D057-48E3-8C51-E5C934E8E07B}.Release_NetFramework|Any CPU.ActiveCfg = Release|Any CPU
|
||||
@@ -128,8 +106,6 @@ Global
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{DC89F18B-235B-4C01-AB31-AF40DCE5C4C7} = {A9071994-3533-4C1B-89DC-D817B676AB41}
|
||||
{6E6BC1E5-5BE8-4566-B3AE-52C4CB218AEB} = {A9071994-3533-4C1B-89DC-D817B676AB41}
|
||||
{EAE9FAE6-8011-45A3-8B6E-0C7F14210533} = {6E2DD21E-0854-4F4A-B925-D90E0016D03D}
|
||||
{D404C973-441D-48ED-B266-C21320BA0D87} = {6E2DD21E-0854-4F4A-B925-D90E0016D03D}
|
||||
{490B052B-7F23-4052-AD04-613856618901} = {6EC98884-A3DC-4828-85EF-5F10F7519429}
|
||||
|
||||
Reference in new issue
Block a user