forked from LavaGang/MelonLoader
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added more Comprehensive Exception Message when attempting to use an …
…Instance Patch Method LavaGang#138
- Loading branch information
1 parent
55ec8cf
commit a2cdb8e
Showing
4 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Reflection; | ||
using HarmonyLib; | ||
using MonoMod.RuntimeDetour; | ||
|
||
namespace MelonLoader.Fixes | ||
{ | ||
internal static class InstancePatchFix | ||
{ | ||
internal static void Install() | ||
{ | ||
Type instancePatchFixType = typeof(InstancePatchFix); | ||
HarmonyMethod patchMethod = AccessTools.Method(instancePatchFixType, "PatchMethod").ToNewHarmonyMethod(); | ||
|
||
try | ||
{ | ||
Core.HarmonyInstance.Patch(AccessTools.Method("HarmonyLib.PatchFunctions:ReversePatch"), patchMethod); | ||
Core.HarmonyInstance.Patch(AccessTools.Method("HarmonyLib.HarmonyMethod:ImportMethod"), patchMethod); | ||
} | ||
catch (Exception ex) { MelonLogger.Warning($"PatchFix Exception: {ex}"); } | ||
|
||
Hook.OnDetour += (detour, originalMethod, patchMethod, delegateTarget) => PatchMethod(patchMethod); | ||
Detour.OnDetour += (detour, originalMethod, patchMethod) => PatchMethod(patchMethod); | ||
} | ||
|
||
private static bool PatchMethod(MethodBase __0) | ||
{ | ||
if (__0 == null) | ||
throw new NullReferenceException("Patch Method"); | ||
if ((__0 != null) && !__0.IsStatic) | ||
throw new Exception("Patch Method can't be an Instance Method!"); | ||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters