diff --git a/BaboonAPI/patch/GameControllerPatch.fs b/BaboonAPI/patch/GameControllerPatch.fs index 966be86..81f4044 100644 --- a/BaboonAPI/patch/GameControllerPatch.fs +++ b/BaboonAPI/patch/GameControllerPatch.fs @@ -106,6 +106,7 @@ type private GameControllerExtension() = [] type GameControllerPatch() = static let freeplay_f = AccessTools.Field(typeof, "freeplay") + static let file_exists_m = AccessTools.Method(typeof, "Exists") [] [, "Start")>] @@ -154,13 +155,28 @@ type GameControllerPatch() = [] [, "tryToLoadLevel")>] static member LoadChartTranspiler(instructions: CodeInstruction seq): CodeInstruction seq = - let matcher = - CodeMatcher(instructions) + let matcher = CodeMatcher(instructions) + + let existsLabels = + matcher .MatchForward(false, [| - CodeMatch OpCodes.Ldarg_2 - CodeMatch OpCodes.Brtrue + CodeMatch OpCodes.Ldloc_0 + CodeMatch (fun ins -> ins.Calls(file_exists_m)) + CodeMatch OpCodes.Brfalse |]) - .ThrowIfInvalid("Could not find start of injection point in GameController#tryToLoadLevel") + .ThrowIfInvalid("Could not find File.Exists call in GameController#tryToLoadLevel") + .Labels + matcher + .RemoveInstructions(3) + .AddLabels(existsLabels) + + // Find the start of the injection point + .MatchForward(false, [| + CodeMatch OpCodes.Ldarg_2 + CodeMatch OpCodes.Brtrue + |]) + .ThrowIfInvalid("Could not find start of injection point in GameController#tryToLoadLevel") + |> ignore let startPos = matcher.Pos let startLabels = matcher.Labels