@@ -106,6 +106,7 @@ type private GameControllerExtension() =
106
106
[<HarmonyPatch>]
107
107
type GameControllerPatch () =
108
108
static let freeplay_f = AccessTools.Field( typeof< GameController>, " freeplay" )
109
+ static let file_exists_m = AccessTools.Method( typeof< System.IO.File>, " Exists" )
109
110
110
111
[<HarmonyTranspiler>]
111
112
[<HarmonyPatch( typeof< GameController>, " Start" ) >]
@@ -154,13 +155,28 @@ type GameControllerPatch() =
154
155
[<HarmonyTranspiler>]
155
156
[<HarmonyPatch( typeof< GameController>, " tryToLoadLevel" ) >]
156
157
static member LoadChartTranspiler ( instructions : CodeInstruction seq ): CodeInstruction seq =
157
- let matcher =
158
- CodeMatcher( instructions)
158
+ let matcher = CodeMatcher( instructions)
159
+
160
+ let existsLabels =
161
+ matcher
159
162
.MatchForward( false , [|
160
- CodeMatch OpCodes.Ldarg_ 2
161
- CodeMatch OpCodes.Brtrue
163
+ CodeMatch OpCodes.Ldloc_ 0
164
+ CodeMatch ( fun ins -> ins.Calls( file_ exists_ m))
165
+ CodeMatch OpCodes.Brfalse
162
166
|])
163
- .ThrowIfInvalid( " Could not find start of injection point in GameController#tryToLoadLevel" )
167
+ .ThrowIfInvalid( " Could not find File.Exists call in GameController#tryToLoadLevel" )
168
+ .Labels
169
+ matcher
170
+ .RemoveInstructions( 3 )
171
+ .AddLabels( existsLabels)
172
+
173
+ // Find the start of the injection point
174
+ .MatchForward( false , [|
175
+ CodeMatch OpCodes.Ldarg_ 2
176
+ CodeMatch OpCodes.Brtrue
177
+ |])
178
+ .ThrowIfInvalid( " Could not find start of injection point in GameController#tryToLoadLevel" )
179
+ |> ignore
164
180
165
181
let startPos = matcher.Pos
166
182
let startLabels = matcher.Labels
0 commit comments