@@ -185,91 +185,86 @@ public void Restart(
185
185
186
186
public void CallSaveStateEvent ( string name )
187
187
{
188
- using ( GuiAPI . ThisIsTheLuaAutoUnlockHack ( ) )
188
+ using var luaAutoUnlockHack = GuiAPI . ThisIsTheLuaAutoUnlockHack ( ) ;
189
+
190
+ try
189
191
{
190
- try
191
- {
192
- foreach ( var lf in RegisteredFunctions . Where ( static l => l . Event == NamedLuaFunction . EVENT_TYPE_SAVESTATE ) . ToList ( ) )
193
- {
194
- lf . Call ( name ) ;
195
- }
196
- }
197
- catch ( Exception e )
192
+ foreach ( var lf in RegisteredFunctions . Where ( static l => l . Event == NamedLuaFunction . EVENT_TYPE_SAVESTATE ) . ToList ( ) )
198
193
{
199
- LogToLuaConsole ( $ "error running function attached by lua function event.onsavestate \n Error message: { e . Message } " ) ;
194
+ lf . Call ( name ) ;
200
195
}
201
196
}
197
+ catch ( Exception e )
198
+ {
199
+ LogToLuaConsole ( $ "error running function attached by lua function event.onsavestate\n Error message: { e . Message } ") ;
200
+ }
202
201
}
203
202
204
203
public void CallLoadStateEvent ( string name )
205
204
{
206
- using ( GuiAPI . ThisIsTheLuaAutoUnlockHack ( ) )
205
+ using var luaAutoUnlockHack = GuiAPI . ThisIsTheLuaAutoUnlockHack ( ) ;
206
+
207
+ try
207
208
{
208
- try
209
+ foreach ( var lf in RegisteredFunctions . Where ( static l => l . Event == NamedLuaFunction . EVENT_TYPE_LOADSTATE ) . ToList ( ) )
209
210
{
210
- foreach ( var lf in RegisteredFunctions . Where ( static l => l . Event == NamedLuaFunction . EVENT_TYPE_LOADSTATE ) . ToList ( ) )
211
- {
212
- lf . Call ( name ) ;
213
- }
214
- }
215
- catch ( Exception e )
216
- {
217
- LogToLuaConsole ( $ "error running function attached by lua function event.onloadstate\n Error message: { e . Message } ") ;
211
+ lf . Call ( name ) ;
218
212
}
219
213
}
214
+ catch ( Exception e )
215
+ {
216
+ LogToLuaConsole ( $ "error running function attached by lua function event.onloadstate\n Error message: { e . Message } ") ;
217
+ }
220
218
}
221
219
222
220
public void CallFrameBeforeEvent ( )
223
221
{
224
222
if ( IsUpdateSupressed ) return ;
225
223
226
- using ( GuiAPI . ThisIsTheLuaAutoUnlockHack ( ) )
224
+ using var luaAutoUnlockHack = GuiAPI . ThisIsTheLuaAutoUnlockHack ( ) ;
225
+
226
+ try
227
227
{
228
- try
229
- {
230
- foreach ( var lf in RegisteredFunctions . Where ( static l => l . Event == NamedLuaFunction . EVENT_TYPE_PREFRAME ) . ToList ( ) )
231
- {
232
- lf . Call ( ) ;
233
- }
234
- }
235
- catch ( Exception e )
228
+ foreach ( var lf in RegisteredFunctions . Where ( static l => l . Event == NamedLuaFunction . EVENT_TYPE_PREFRAME ) . ToList ( ) )
236
229
{
237
- LogToLuaConsole ( $ "error running function attached by lua function event.onframestart \n Error message: { e . Message } " ) ;
230
+ lf . Call ( ) ;
238
231
}
239
232
}
233
+ catch ( Exception e )
234
+ {
235
+ LogToLuaConsole ( $ "error running function attached by lua function event.onframestart\n Error message: { e . Message } ") ;
236
+ }
240
237
}
241
238
242
239
public void CallFrameAfterEvent ( )
243
240
{
244
241
if ( IsUpdateSupressed ) return ;
245
242
246
- using ( GuiAPI . ThisIsTheLuaAutoUnlockHack ( ) )
243
+ using var luaAutoUnlockHack = GuiAPI . ThisIsTheLuaAutoUnlockHack ( ) ;
244
+
245
+ try
247
246
{
248
- try
249
- {
250
- foreach ( var lf in RegisteredFunctions . Where ( static l => l . Event == NamedLuaFunction . EVENT_TYPE_POSTFRAME ) . ToList ( ) )
251
- {
252
- lf . Call ( ) ;
253
- }
254
- }
255
- catch ( Exception e )
247
+ foreach ( var lf in RegisteredFunctions . Where ( static l => l . Event == NamedLuaFunction . EVENT_TYPE_POSTFRAME ) . ToList ( ) )
256
248
{
257
- LogToLuaConsole ( $ "error running function attached by lua function event.onframeend \n Error message: { e . Message } " ) ;
249
+ lf . Call ( ) ;
258
250
}
259
251
}
252
+ catch ( Exception e )
253
+ {
254
+ LogToLuaConsole ( $ "error running function attached by lua function event.onframeend\n Error message: { e . Message } ") ;
255
+ }
260
256
}
261
257
262
258
public void CallExitEvent ( LuaFile lf )
263
259
{
264
- using ( GuiAPI . ThisIsTheLuaAutoUnlockHack ( ) )
260
+ using var luaAutoUnlockHack = GuiAPI . ThisIsTheLuaAutoUnlockHack ( ) ;
261
+
262
+ foreach ( var exitCallback in RegisteredFunctions
263
+ . Where ( l => l . Event == NamedLuaFunction . EVENT_TYPE_ENGINESTOP
264
+ && ( l . LuaFile . Path == lf . Path || ReferenceEquals ( l . LuaFile . Thread , lf . Thread ) ) )
265
+ . ToList ( ) )
265
266
{
266
- foreach ( var exitCallback in RegisteredFunctions
267
- . Where ( l => l . Event == NamedLuaFunction . EVENT_TYPE_ENGINESTOP
268
- && ( l . LuaFile . Path == lf . Path || ReferenceEquals ( l . LuaFile . Thread , lf . Thread ) ) )
269
- . ToList ( ) )
270
- {
271
- exitCallback . Call ( ) ;
272
- }
267
+ exitCallback . Call ( ) ;
273
268
}
274
269
}
275
270
@@ -327,31 +322,29 @@ public void ExecuteString(string command)
327
322
328
323
public ( bool WaitForFrame , bool Terminated ) ResumeScript ( LuaFile lf )
329
324
{
330
- using ( GuiAPI . ThisIsTheLuaAutoUnlockHack ( ) )
331
- {
332
- _currThread = lf . Thread ;
333
-
334
- try
335
- {
336
- LuaLibraryBase . SetCurrentThread ( lf ) ;
325
+ _currThread = lf . Thread ;
326
+ using var luaAutoUnlockHack = GuiAPI . ThisIsTheLuaAutoUnlockHack ( ) ;
337
327
338
- var execResult = _currThread . Resume ( ) ;
328
+ try
329
+ {
330
+ LuaLibraryBase . SetCurrentThread ( lf ) ;
339
331
340
- _currThread = null ;
341
- var result = execResult switch
342
- {
343
- KeraLua . LuaStatus . OK => ( WaitForFrame : false , Terminated : true ) ,
344
- KeraLua . LuaStatus . Yield => ( WaitForFrame : FrameAdvanceRequested , Terminated : false ) ,
345
- _ => throw new InvalidOperationException ( $ "{ nameof ( _currThread . Resume ) } () returned { execResult } ?")
346
- } ;
332
+ var execResult = _currThread . Resume ( ) ;
347
333
348
- FrameAdvanceRequested = false ;
349
- return result ;
350
- }
351
- finally
334
+ _currThread = null ;
335
+ var result = execResult switch
352
336
{
353
- LuaLibraryBase . ClearCurrentThread ( ) ;
354
- }
337
+ KeraLua . LuaStatus . OK => ( WaitForFrame : false , Terminated : true ) ,
338
+ KeraLua . LuaStatus . Yield => ( WaitForFrame : FrameAdvanceRequested , Terminated : false ) ,
339
+ _ => throw new InvalidOperationException ( $ "{ nameof ( _currThread . Resume ) } () returned { execResult } ?")
340
+ } ;
341
+
342
+ FrameAdvanceRequested = false ;
343
+ return result ;
344
+ }
345
+ finally
346
+ {
347
+ LuaLibraryBase . ClearCurrentThread ( ) ;
355
348
}
356
349
}
357
350
0 commit comments