Skip to content

Commit

Permalink
Fixed game crashing when running vanilla game (without jk+) due to .n…
Browse files Browse the repository at this point in the history
…et runtime optimisation causing harmony patch to sometimes not work properly on methods returning structs
  • Loading branch information
Skippeh committed Mar 20, 2022
1 parent 0b995ff commit b582f70
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions JKMP.Core/Patches/InputPatches.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Reflection;
using HarmonyLib;
using JKMP.Core.Input;
using JumpKing.Controller;
Expand All @@ -7,22 +8,17 @@

namespace JKMP.Core.Patches
{
[HarmonyPatch(typeof(PadInstance), nameof(PadInstance.GetState))]
internal static class PadInstanceGetStatePatch
[HarmonyPatch(typeof(PadInstance), nameof(PadInstance.Update))]
internal static class PadInstanceUpdatePatch
{
private static bool Prefix(ref PadState __result)
{
__result = VanillaKeyBindRouter.GetState();
return false;
}
}
private static readonly FieldInfo LastStateField = AccessTools.Field(typeof(PadInstance), "last_state");
private static readonly FieldInfo CurrentStateField = AccessTools.Field(typeof(PadInstance), "current_state");

[HarmonyPatch(typeof(PadInstance), nameof(PadInstance.GetPressed))]
internal static class PadInstanceGetPressedPatch
{
private static bool Prefix(ref PadState __result)
private static bool Prefix(PadInstance __instance)
{
__result = VanillaKeyBindRouter.GetPressedState();
LastStateField.SetValue(__instance, CurrentStateField.GetValue(__instance));
CurrentStateField.SetValue(__instance, VanillaKeyBindRouter.GetState());

return false;
}
}
Expand Down

0 comments on commit b582f70

Please sign in to comment.