mirror of
https://github.com/BepInEx/BepInEx.git
synced 2026-11-19 13:17:07 +00:00
Add alternate build configuration for Mono.Cecil 0.9.6
This commit is contained in:
1 parent
561b823f19
commit
fe1559bf9c
7 files changed
+68
-43
No files matched your search
@@ -19,14 +19,18 @@ Global
|
||||
BepInEx.Common\BepInEx.Common.projitems*{dc89f18b-235b-4c01-ab31-af40dce5c4c7}*SharedItemsImports = 4
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Cecil 0.9.6_Release|Any CPU = Cecil 0.9.6_Release|Any CPU
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{4FFBA620-F5ED-47F9-B90C-DAD1316FD9B9}.Cecil 0.9.6_Release|Any CPU.ActiveCfg = Cecil 0.9.6_Release|Any CPU
|
||||
{4FFBA620-F5ED-47F9-B90C-DAD1316FD9B9}.Cecil 0.9.6_Release|Any CPU.Build.0 = Cecil 0.9.6_Release|Any CPU
|
||||
{4FFBA620-F5ED-47F9-B90C-DAD1316FD9B9}.Debug|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4FFBA620-F5ED-47F9-B90C-DAD1316FD9B9}.Debug|Any CPU.Build.0 = Release|Any CPU
|
||||
{4FFBA620-F5ED-47F9-B90C-DAD1316FD9B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4FFBA620-F5ED-47F9-B90C-DAD1316FD9B9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{DC89F18B-235B-4C01-AB31-AF40DCE5C4C7}.Cecil 0.9.6_Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{DC89F18B-235B-4C01-AB31-AF40DCE5C4C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{DC89F18B-235B-4C01-AB31-AF40DCE5C4C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
EndGlobalSection
|
||||
|
||||
+14
-6
@@ -18,19 +18,30 @@
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\bin\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<DefineConstants>TRACE;CECIL_10</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<StartupObject />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Cecil 0.9.6_Release|AnyCPU'">
|
||||
<OutputPath>..\bin\</OutputPath>
|
||||
<DefineConstants>TRACE;CECIL_9</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="0Harmony">
|
||||
<HintPath>..\lib\0Harmony.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Mono.Cecil, Version=0.10.0.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Mono.Cecil.0.10.0\lib\net35\Mono.Cecil.dll</HintPath>
|
||||
<Reference Include="Mono.Cecil" Condition="$(DefineConstants.Contains('CECIL_9'))">
|
||||
<HintPath>..\lib\Cecil 9\Mono.Cecil.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Mono.Cecil" Condition="$(DefineConstants.Contains('CECIL_10'))">
|
||||
<HintPath>..\lib\Cecil 10\Mono.Cecil.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Xml" />
|
||||
@@ -59,9 +70,6 @@
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Bootstrap\TypeLoader.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="..\BepInEx.Common\BepInEx.Common.projitems" Label="Shared" />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -28,7 +28,9 @@ namespace BepInEx.Bootstrap
|
||||
if (assembly.Name.Name == "System"
|
||||
|| assembly.Name.Name == "mscorlib") //mscorlib is already loaded into the appdomain so it can't be patched
|
||||
{
|
||||
#if CECIL_10
|
||||
assembly.Dispose();
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -68,7 +70,9 @@ namespace BepInEx.Bootstrap
|
||||
|
||||
public static void Patch(AssemblyDefinition assembly, IEnumerable<AssemblyPatcherDelegate> patcherMethods)
|
||||
{
|
||||
#if CECIL_10
|
||||
using (assembly)
|
||||
#endif
|
||||
using (MemoryStream assemblyStream = new MemoryStream())
|
||||
{
|
||||
foreach (AssemblyPatcherDelegate method in patcherMethods)
|
||||
|
||||
@@ -27,6 +27,8 @@ namespace BepInEx.Bootstrap
|
||||
|
||||
public static string ManagedPath => Utility.CombinePaths(GameRootPath, $"{GameName}_Data", "Managed");
|
||||
|
||||
public static string PluginPath => Utility.CombinePaths(GameRootPath, "BepInEx");
|
||||
|
||||
public static string PatcherPluginPath => Utility.CombinePaths(GameRootPath, "BepInEx", "patchers");
|
||||
|
||||
#endregion
|
||||
@@ -87,43 +89,50 @@ namespace BepInEx.Bootstrap
|
||||
|
||||
foreach (var type in assembly.GetExportedTypes())
|
||||
{
|
||||
if (type.IsInterface)
|
||||
continue;
|
||||
|
||||
PropertyInfo targetsProperty = type.GetProperty(
|
||||
"TargetDLLs",
|
||||
BindingFlags.Public | BindingFlags.Static | BindingFlags.IgnoreCase,
|
||||
null,
|
||||
typeof(IEnumerable<string>),
|
||||
Type.EmptyTypes,
|
||||
null);
|
||||
|
||||
MethodInfo patcher = type.GetMethod(
|
||||
"Patch",
|
||||
BindingFlags.Public | BindingFlags.Static | BindingFlags.IgnoreCase,
|
||||
null,
|
||||
CallingConventions.Any,
|
||||
new[] { typeof(AssemblyDefinition) },
|
||||
null);
|
||||
|
||||
if (targetsProperty == null || !targetsProperty.CanRead || patcher == null)
|
||||
continue;
|
||||
|
||||
AssemblyPatcherDelegate patchDelegate = (ass) => { patcher.Invoke(null, new object[] {ass}); };
|
||||
|
||||
IEnumerable<string> targets = (IEnumerable<string>)targetsProperty.GetValue(null, null);
|
||||
|
||||
foreach (string target in targets)
|
||||
try
|
||||
{
|
||||
if (patcherMethods.TryGetValue(target, out IList<AssemblyPatcherDelegate> patchers))
|
||||
patchers.Add(patchDelegate);
|
||||
else
|
||||
{
|
||||
patchers = new List<AssemblyPatcherDelegate>{ patchDelegate };
|
||||
if (type.IsInterface)
|
||||
continue;
|
||||
|
||||
patcherMethods[target] = patchers;
|
||||
PropertyInfo targetsProperty = type.GetProperty(
|
||||
"TargetDLLs",
|
||||
BindingFlags.Public | BindingFlags.Static | BindingFlags.IgnoreCase,
|
||||
null,
|
||||
typeof(IEnumerable<string>),
|
||||
Type.EmptyTypes,
|
||||
null);
|
||||
|
||||
MethodInfo patcher = type.GetMethod(
|
||||
"Patch",
|
||||
BindingFlags.Public | BindingFlags.Static | BindingFlags.IgnoreCase,
|
||||
null,
|
||||
CallingConventions.Any,
|
||||
new[] { typeof(AssemblyDefinition) },
|
||||
null);
|
||||
|
||||
if (targetsProperty == null || !targetsProperty.CanRead || patcher == null)
|
||||
continue;
|
||||
|
||||
AssemblyPatcherDelegate patchDelegate = (ass) => { patcher.Invoke(null, new object[] {ass}); };
|
||||
|
||||
IEnumerable<string> targets = (IEnumerable<string>)targetsProperty.GetValue(null, null);
|
||||
|
||||
foreach (string target in targets)
|
||||
{
|
||||
if (patcherMethods.TryGetValue(target, out IList<AssemblyPatcherDelegate> patchers))
|
||||
patchers.Add(patchDelegate);
|
||||
else
|
||||
{
|
||||
patchers = new List<AssemblyPatcherDelegate>{ patchDelegate };
|
||||
|
||||
patcherMethods[target] = patchers;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//TODO: add logging of exceptions
|
||||
}
|
||||
}
|
||||
|
||||
return patcherMethods;
|
||||
@@ -133,7 +142,11 @@ namespace BepInEx.Bootstrap
|
||||
{
|
||||
if (assembly.Name.Name == "UnityEngine")
|
||||
{
|
||||
#if CECIL_10
|
||||
using (AssemblyDefinition injected = AssemblyDefinition.ReadAssembly(CurrentExecutingAssemblyPath))
|
||||
#elif CECIL_9
|
||||
AssemblyDefinition injected = AssemblyDefinition.ReadAssembly(CurrentExecutingAssemblyPath);
|
||||
#endif
|
||||
{
|
||||
var originalInjectMethod = injected.MainModule.Types.First(x => x.Name == "Chainloader")
|
||||
.Methods.First(x => x.Name == "Initialize");
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Mono.Cecil" version="0.10.0" targetFramework="net35" />
|
||||
</packages>
|
||||
Binary file not shown.
Binary file not shown.
Reference in new issue
Block a user