@@ -156,6 +156,7 @@ public LuaConsole()
156156 }
157157
158158 private LuaLibraries LuaImp ;
159+ private List < LuaFile > _scriptsToRestart = new ( ) ;
159160
160161 private IEnumerable < LuaFile > SelectedItems => LuaListView . SelectedRows . Select ( index => LuaImp . ScriptList [ index ] ) ;
161162
@@ -186,10 +187,22 @@ private void BranchesMarkersSplit_SplitterMoved(object sender, SplitterEventArgs
186187 Settings . SplitDistance = splitContainer1 . SplitterDistance ;
187188 }
188189
189- public override void Restart ( )
190+ public override void Stop ( )
190191 {
191- List < LuaFile > runningScripts = new ( ) ;
192+ if ( LuaImp is not null && ! LuaImp . IsRebootingCore )
193+ {
194+ _scriptsToRestart = LuaImp . ScriptList . Where ( lf => lf . Enabled ) . ToList ( ) ;
192195
196+ // we don't use _scriptsToRestart here as the other scripts need to be stopped too
197+ foreach ( var file in LuaImp . ScriptList )
198+ {
199+ DisableLuaScript ( file ) ;
200+ }
201+ }
202+ }
203+
204+ public override void Restart ( )
205+ {
193206 ApiContainer apiContainer = ApiManager . RestartLua (
194207 Emulator . ServiceProvider ,
195208 WriteToOutputWindow ,
@@ -203,23 +216,11 @@ public override void Restart()
203216 Game ,
204217 DialogController ) ;
205218
206- // Things we need to do with the existing LuaImp before we can make a new one
207- if ( LuaImp is not null )
219+ if ( LuaImp is not null && LuaImp . IsRebootingCore )
208220 {
209- if ( LuaImp . IsRebootingCore )
210- {
211- // Even if the lua console is self-rebooting from client.reboot_core() we still want to re-inject dependencies
212- LuaImp . Restart ( Emulator . ServiceProvider , Config , apiContainer ) ;
213- return ;
214- }
215-
216- runningScripts = LuaImp . ScriptList . Where ( lf => lf . Enabled ) . ToList ( ) ;
217-
218- // we don't use runningScripts here as the other scripts need to be stopped too
219- foreach ( var file in LuaImp . ScriptList )
220- {
221- DisableLuaScript ( file ) ;
222- }
221+ // Even if the lua console is self-rebooting from client.reboot_core() we still want to re-inject dependencies
222+ LuaImp . Restart ( Emulator . ServiceProvider , Config , apiContainer ) ;
223+ return ;
223224 }
224225
225226 LuaFileList newScripts = new ( LuaImp ? . ScriptList , onChanged : SessionChangedCallback ) ;
@@ -240,7 +241,7 @@ public override void Restart()
240241 . Select ( static f => $ "{ f . Library } .{ f . Name } ")
241242 . ToArray ( ) ) ;
242243
243- foreach ( var file in runningScripts )
244+ foreach ( var file in _scriptsToRestart )
244245 {
245246 try
246247 {
0 commit comments