From 260ad45a88f3ddcb0ed329b786cb54001800dfd1 Mon Sep 17 00:00:00 2001 From: zeromus Date: Sat, 19 Dec 2015 21:14:00 -0600 Subject: [PATCH] fix lua's reboot_core function... maybe --- .../tools/Lua/Libraries/EmuLuaLibrary.Client.cs | 3 +++ BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.cs | 3 ++- BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs | 2 ++ BizHawk.Client.EmuHawk/tools/ToolManager.cs | 5 +++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Client.cs b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Client.cs index 4b7b7e52ae..97488bf4ac 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Client.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Client.cs @@ -312,7 +312,10 @@ namespace BizHawk.Client.EmuHawk )] public static void RebootCore() { + //pretty hacky.. we dont want a lua script to be able to restart itself by rebooting the core + ((LuaConsole)GlobalWin.Tools.Get()).IsRebootingCore = true; GlobalWin.MainForm.RebootCore(); + ((LuaConsole)GlobalWin.Tools.Get()).IsRebootingCore = false; } [LuaMethodAttributes( diff --git a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.cs b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.cs index ab48b62381..4bf4f196cd 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.cs @@ -144,7 +144,8 @@ namespace BizHawk.Client.EmuHawk public Lua SpawnCoroutine(string file) { var lua = _lua.NewThread(); - var main = lua.LoadString(File.ReadAllText(file), "main"); + var content = File.ReadAllText(file); + var main = lua.LoadString(content, "main"); lua.Push(main); // push main function on to stack for subsequent resuming return lua; } diff --git a/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs b/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs index f65226a2b7..aa355b3a16 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs @@ -27,6 +27,8 @@ namespace BizHawk.Client.EmuHawk private List _consoleCommandHistory = new List(); private int _consoleCommandHistoryIndex = -1; + public bool IsRebootingCore; + public LuaConsole() { _sortReverse = false; diff --git a/BizHawk.Client.EmuHawk/tools/ToolManager.cs b/BizHawk.Client.EmuHawk/tools/ToolManager.cs index 8687179ae5..195fe65b2e 100644 --- a/BizHawk.Client.EmuHawk/tools/ToolManager.cs +++ b/BizHawk.Client.EmuHawk/tools/ToolManager.cs @@ -441,7 +441,12 @@ namespace BizHawk.Client.EmuHawk if (ServiceInjector.IsAvailable(Global.Emulator.ServiceProvider, tool.GetType())) { ServiceInjector.UpdateServices(Global.Emulator.ServiceProvider, tool); + bool restartTool = false; if ((tool.IsHandleCreated && !tool.IsDisposed) || tool is RamWatch) // Hack for Ram Watch - in display watches mode it wants to keep running even closed, it will handle disposed logic + restartTool = true; + if (tool is LuaConsole && ((LuaConsole)tool).IsRebootingCore) + restartTool = false; + if(restartTool) { tool.Restart(); }