Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dependencies/SupportModules/Il2Cpp/Il2Cpp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
<PackageReference Include="Il2CppInterop.Runtime" Version="$(Il2CppInteropVersion)" ExcludeAssets="Runtime" />
<PackageReference Include="Il2CppInterop.HarmonySupport" Version="$(Il2CppInteropVersion)" ExcludeAssets="Runtime" />
<PackageReference Include="Mono.Cecil" Version="$(MonoCecilVersion)" ExcludeAssets="Runtime" />
<PackageReference Include="MonoMod.RuntimeDetour" Version="$(MonoModVersion)" ExcludeAssets="Runtime" />
<PackageReference Include="MonoMod.Utils" Version="$(MonoModVersion)" ExcludeAssets="Runtime" />
<PackageReference Include="MonoMod.RuntimeDetour" Version="$(MonoModRuntimeDetourVersion)" ExcludeAssets="Runtime" />
<PackageReference Include="MonoMod.Utils" Version="$(MonoModUtilsVersion)" ExcludeAssets="Runtime" />
<PackageReference Include="Samboy063.Tomlet" Version="$(TomletVersion)" ExcludeAssets="Runtime" />
</ItemGroup>
</Project>
4 changes: 3 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@
<TomletVersion>6.2.0</TomletVersion>
<PastelVersion>7.0.1</PastelVersion>
<MonoModVersion>22.7.31.1</MonoModVersion>
<MonoModUtilsVersion>25.0.11</MonoModUtilsVersion>
<MonoModRuntimeDetourVersion>25.3.3</MonoModRuntimeDetourVersion>
<MonoCecilVersion>0.11.6</MonoCecilVersion>
<HarmonyXVersion>2.10.2</HarmonyXVersion>
<HarmonyXVersion>2.16.0</HarmonyXVersion>
<AssetToolsVersion>3.0.4</AssetToolsVersion>
<AssetRipperVersion>3.2.0</AssetRipperVersion>
<AsmResolverVersion>6.0.0-beta.5</AsmResolverVersion>
Expand Down
13 changes: 10 additions & 3 deletions MelonLoader/Attributes/PatchShield.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,20 @@ internal static void Install()
}
catch (Exception ex) { LogException(ex); }

Hook.OnDetour += (detour, originalMethod, patchMethod, delegateTarget) => MethodCheck(originalMethod);
ILHook.OnDetour += (detour, originalMethod, ilmanipulator) => MethodCheck(originalMethod);
Detour.OnDetour += (detour, originalMethod, patchMethod) => MethodCheck(originalMethod);
try
{
Core.HarmonyInstance.Patch(AccessTools.Method(typeof(Hook), "Apply"),
AccessTools.Method(patchShieldType, "PatchMethod_Hook_Apply").ToNewHarmonyMethod());
Core.HarmonyInstance.Patch(AccessTools.Method(typeof(ILHook), "Apply"),
AccessTools.Method(patchShieldType, "PatchMethod_ILHook_Apply").ToNewHarmonyMethod());
}
catch (Exception ex) { LogException(ex); }
}

private static bool PatchMethod_PatchFunctions_ReversePatch(MethodBase __1) => MethodCheck(__1);
private static bool PatchMethod_PatchProcessor_Patch(PatchProcessor __instance) => MethodCheck(PatchProcessor_OriginalRef(__instance));
private static bool PatchMethod_PatchProcessor_Unpatch(PatchProcessor __instance) => MethodCheck(PatchProcessor_OriginalRef(__instance));
private static bool PatchMethod_Hook_Apply(Hook __instance) => MethodCheck(__instance.Source);
private static bool PatchMethod_ILHook_Apply(ILHook __instance) => MethodCheck(__instance.Method);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
[assembly: TypeForwardedTo(typeof(HarmonyLib.HarmonyGlobalSettings))]
[assembly: TypeForwardedTo(typeof(HarmonyLib.HarmonyMethod))]
[assembly: TypeForwardedTo(typeof(HarmonyLib.HarmonyMethodExtensions))]
[assembly: TypeForwardedTo(typeof(HarmonyLib.InlineSignature))]
[assembly: TypeForwardedTo(typeof(HarmonyLib.PatchInfo))]
[assembly: TypeForwardedTo(typeof(HarmonyLib.Patch))]
[assembly: TypeForwardedTo(typeof(HarmonyLib.PatchClassProcessor))]
Expand Down

This file was deleted.

This file was deleted.

13 changes: 0 additions & 13 deletions MelonLoader/Core.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
using System;
using System.Diagnostics;
using System.Reflection;
using System.IO;
using bHapticsLib;
using System.Threading;
using HarmonyLib;
using MelonLoader.Resolver;
using MelonLoader.Utils;
using MelonLoader.InternalUtils;
using MelonLoader.Melons;
using MonoMod.RuntimeDetour;
using MonoMod.RuntimeDetour.Platforms;

[assembly: MelonLoader.PatchShield]

Expand Down Expand Up @@ -54,14 +49,6 @@ internal static int Initialize()
Assertions.LemonAssertMapping.Setup();
HarmonyLogger.Setup();

#if !WINDOWS && !NET6_0_OR_GREATER
// Using Process.Start can run Console..cctor
// Since MonoMod's PlatformHelper (used by DetourHelper.Native) runs Process.Start to determine ARM/x86
// platform, this causes the unpatched TermInfoReader to kick in before it can be patched and fixed when
// installing the XTermFix below. To work around this, we can force the platform directly
DetourHelper.Native = new DetourNativeMonoPosixPlatform(new DetourNativeX86Platform());
#endif

HarmonyInstance = new HarmonyLib.Harmony(Properties.BuildInfo.Name);

#if !WINDOWS && !NET6_0_OR_GREATER
Expand Down
10 changes: 8 additions & 2 deletions MelonLoader/Fixes/Harmony/InstancePatchFix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ internal static void Install()
}
catch (Exception ex) { MelonLogger.Warning(ex); }

Hook.OnDetour += (detour, originalMethod, patchMethod, delegateTarget) => PatchMethod(patchMethod);
Detour.OnDetour += (detour, originalMethod, patchMethod) => PatchMethod(patchMethod);
try
{
Core.HarmonyInstance.Patch(AccessTools.Method(typeof(Hook), "Apply"),
AccessTools.Method(instancePatchFixType, "PatchHookApply").ToNewHarmonyMethod());
}
catch (Exception ex) { MelonLogger.Warning(ex); }
}

private static bool PatchMethod(MethodBase __0)
Expand All @@ -31,5 +35,7 @@ private static bool PatchMethod(MethodBase __0)
throw new Exception("Patch Method must be a Static Method!");
return true;
}

private static bool PatchHookApply(Hook __instance) => PatchMethod(__instance.Target);
}
}
8 changes: 5 additions & 3 deletions MelonLoader/Fixes/Il2CppInterop/Il2CppICallInjector.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#if NET6_0_OR_GREATER

using MelonLoader.NativeUtils;
using MonoMod.RuntimeDetour;
using MonoMod.Core.Platforms;
using MonoMod.Utils;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -272,8 +272,10 @@ private static (object, DynamicMethodDefinition, MethodInfo, IntPtr) GenerateTra
return (null, null, null, IntPtr.Zero);

// Return the New Method
MethodInfo newMethod = trampoline.Generate().Pin();
return (patcher, trampoline, newMethod, newMethod.GetNativeStart());
var triple = PlatformTriple.Current;
MethodInfo newMethod = trampoline.Generate();
triple.PinMethodIfNeeded(newMethod);
return (patcher, trampoline, newMethod, triple.Runtime.GetMethodEntryPoint(newMethod));
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions MelonLoader/Fixes/Il2CppInterop/Il2CppInteropFixes.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#if NET6_0_OR_GREATER
extern alias Iced;

using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -12,14 +14,13 @@
using Il2CppInterop.Runtime.Runtime;
using Il2CppInterop.Runtime.Runtime.VersionSpecific.Class;
using Il2CppInterop.Runtime.Runtime.VersionSpecific.MethodInfo;
using Il2CppInterop.Runtime.Runtime.VersionSpecific.Type;
using HarmonyLib;
using Il2CppInterop.Generator.Contexts;
using AsmResolver.DotNet;
using Il2CppInterop.HarmonySupport;
using Iced.Intel;
using Il2CppInterop.Common.XrefScans;
using FlowControl = Iced.Intel.FlowControl;
using Iced::Iced.Intel;
using FlowControl = Iced::Iced.Intel.FlowControl;

#pragma warning disable CS8632

Expand Down
6 changes: 3 additions & 3 deletions MelonLoader/MelonLoader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
<PackageReference Include="HarmonyX" Version="$(HarmonyXVersion)" />
<PackageReference Include="Mono.Cecil" Version="$(MonoCecilVersion)" />
<PackageReference Include="MonoMod" Version="$(MonoModVersion)" />
<PackageReference Include="MonoMod.RuntimeDetour" Version="$(MonoModVersion)" />
<PackageReference Include="MonoMod.Utils" Version="$(MonoModVersion)" />
<PackageReference Include="MonoMod.RuntimeDetour" Version="$(MonoModRuntimeDetourVersion)" />
<PackageReference Include="MonoMod.Utils" Version="$(MonoModUtilsVersion)" />
<PackageReference Include="Samboy063.Tomlet" Version="$(TomletVersion)" />
<PackageReference Include="AsmResolver.DotNet" Version="$(AsmResolverVersion)" />

Expand All @@ -56,7 +56,7 @@
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" />
<PackageReference Include="System.Security.Permissions" Version="10.0.3" />

<PackageReference Include="Iced" Version="$(IcedVersion)" />
<PackageReference Include="Iced" Version="$(IcedVersion)" Aliases="Iced" />
<PackageReference Include="Il2CppInterop.Common" Version="$(Il2CppInteropVersion)" />
<PackageReference Include="Il2CppInterop.Runtime" Version="$(Il2CppInteropVersion)" />
<PackageReference Include="Il2CppInterop.Generator" Version="$(Il2CppInteropVersion)" />
Expand Down