private void RunLuaScripts() { foreach (var file in LuaImp.ScriptList.Where(s => !s.IsSeparator)) { if (!file.Enabled && file.Thread == null) { try { LuaSandbox.Sandbox(null, () => { string pathToLoad = ProcessPath(file.Path); LuaImp.SpawnAndSetFileThread(file.Path, file); LuaSandbox.CreateSandbox(file.Thread, Path.GetDirectoryName(pathToLoad)); }, () => { file.State = LuaFile.RunState.Disabled; }); } catch (Exception e) { MessageBox.Show(e.ToString()); } } else { file.Stop(); } } }
public void RunLuaScripts() { foreach (var file in _luaList) { if (file.Enabled && file.Thread == null) { try { LuaSandbox.Sandbox(() => { file.Thread = LuaImp.SpawnCoroutine(file.Path); }, () => { file.Enabled = false; }); } catch (Exception e) { MessageBox.Show(e.ToString()); } } else { file.Stop(); } } }
public void RunLuaScripts() { foreach (var file in _luaList) { if (!file.Enabled && file.Thread == null) { try { LuaSandbox.Sandbox(null, () => { string pathToLoad = Path.IsPathRooted(file.Path) ? file.Path : PathManager.MakeProgramRelativePath(file.Path); //JUNIPIER SQUATCHBOX COMPLEX file.Thread = LuaImp.SpawnCoroutine(file.Path); LuaSandbox.CreateSandbox(file.Thread, Path.GetDirectoryName(pathToLoad)); }, () => { file.State = LuaFile.RunState.Disabled; }); } catch (Exception e) { MessageBox.Show(e.ToString()); } } else { file.Stop(); } } }
private void RunLuaScripts() { foreach (var file in _luaList) { if (!file.Enabled && file.Thread == null) { try { LuaSandbox.Sandbox(null, () => { string pathToLoad = ProcessPath(file.Path); file.Thread = LuaImp.SpawnCoroutine(file.Path); LuaSandbox.CreateSandbox(file.Thread, Path.GetDirectoryName(pathToLoad)); }, () => { file.State = LuaFile.RunState.Disabled; }); } catch (Exception e) { MessageBox.Show(e.ToString()); } } else { file.Stop(); } } }
private void EnableLuaFile(LuaFile item) { try { LuaSandbox.Sandbox(null, () => { string pathToLoad = Path.IsPathRooted(item.Path) ? item.Path : PathManager.MakeProgramRelativePath(item.Path); LuaImp.SpawnAndSetFileThread(pathToLoad, item); LuaSandbox.CreateSandbox(item.Thread, Path.GetDirectoryName(pathToLoad)); }, () => { item.State = LuaFile.RunState.Disabled; }); // Shenanigans // We want any gui.text messages from a script to immediately update even when paused GlobalWin.OSD.ClearGUIText(); GlobalWin.Tools.UpdateToolsAfter(); LuaImp.EndLuaDrawing(); LuaImp.StartLuaDrawing(); } catch (IOException) { ConsoleLog($"Unable to access file {item.Path}"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public void Restart() { // Even if the lua console is self-rebooting from client.reboot_core() we still want to re-inject dependencies if (IsRebootingCore) { LuaImp.Restart(Emulator.ServiceProvider); return; } if (LuaImp?.GuiLibrary != null && LuaImp.GuiLibrary.HasLuaSurface) { LuaImp.GuiLibrary.DrawFinish(); } var runningScripts = _luaList.Where(f => f.Enabled).ToList(); foreach (var file in runningScripts) { LuaImp.CallExitEvent(file.Thread); var functions = LuaImp.RegisteredFunctions.Where(lf => lf.Lua == file.Thread).ToList(); foreach (var function in functions) { LuaImp.RegisteredFunctions.Remove(function); } UpdateRegisteredFunctionsDialog(); file.Stop(); } LuaImp = new EmuLuaLibrary(Emulator.ServiceProvider); InputBox.AutoCompleteCustomSource.AddRange(LuaImp.Docs.Select(a => a.Library + "." + a.Name).ToArray()); foreach (var file in runningScripts) { string pathToLoad = ProcessPath(file.Path); try { LuaSandbox.Sandbox(file.Thread, () => { file.Thread = LuaImp.SpawnCoroutine(pathToLoad); LuaSandbox.CreateSandbox(file.Thread, Path.GetDirectoryName(pathToLoad)); file.State = LuaFile.RunState.Running; }, () => { file.State = LuaFile.RunState.Disabled; }); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } UpdateDialog(); }
public void LoadLuaFile(string path) { var processedPath = PathManager.TryMakeRelative(path); string pathToLoad = Path.IsPathRooted(processedPath) ? processedPath : PathManager.MakeProgramRelativePath(processedPath); //JUNIPIER SQUATCHBOX COMPLEX if (LuaAlreadyInSession(processedPath) == false) { var luaFile = new LuaFile(string.Empty, processedPath); _luaList.Add(luaFile); LuaListView.ItemCount = _luaList.Count; Global.Config.RecentLua.Add(processedPath); if (!Global.Config.DisableLuaScriptsOnLoad) { try { LuaSandbox.Sandbox(null, () => { luaFile.Thread = LuaImp.SpawnCoroutine(pathToLoad); LuaSandbox.CreateSandbox(luaFile.Thread, Path.GetDirectoryName(pathToLoad)); luaFile.State = LuaFile.RunState.Running; }, () => { luaFile.State = LuaFile.RunState.Disabled; }); } catch (Exception e) { MessageBox.Show(e.ToString()); } } else { luaFile.State = LuaFile.RunState.Disabled; } if (Global.Config.LuaReloadOnScriptFileChange) { CreateFileWatcher(processedPath); } //luaFile.Paused = false; } else { foreach (var file in _luaList.Where(file => processedPath == file.Path && file.Enabled == false && !Global.Config.DisableLuaScriptsOnLoad)) { file.Toggle(); break; } RunLuaScripts(); } UpdateDialog(); }
private void ToggleScriptMenuItem_Click(object sender, EventArgs e) { var files = !SelectedFiles.Any() && Global.Config.ToggleAllIfNoneSelected ? _luaList : SelectedFiles; foreach (var item in files) { item.Toggle(); if (item.Enabled && item.Thread == null) { try { LuaSandbox.Sandbox(() => { item.Thread = LuaImp.SpawnCoroutine(item.Path); }, () => { item.State = LuaFile.RunState.Disabled; }); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } else if (!item.Enabled && item.Thread != null) { LuaImp.CallExitEvent(item.Thread); var items = SelectedItems.ToList(); foreach (var sitem in items) { var temp = sitem; var functions = LuaImp.RegisteredFunctions.Where(x => x.Lua == temp.Thread).ToList(); foreach (var function in functions) { LuaImp.RegisteredFunctions.Remove(function); } UpdateRegisteredFunctionsDialog(); } LuaImp.CallExitEvent(item.Thread); item.Stop(); if (Global.Config.RemoveRegisteredFunctionsOnToggle) { GlobalWin.Tools.LuaConsole.LuaImp.RegisteredFunctions.ClearAll(); } } } UpdateDialog(); UpdateNumberOfScripts(); LuaListView.Refresh(); }
/// <summary> /// resumes suspended Co-routines /// </summary> /// <param name="includeFrameWaiters">should frame waiters be waken up? only use this immediately before a frame of emulation</param> public void ResumeScripts(bool includeFrameWaiters) { if (!_luaList.Any()) { return; } if (LuaImp.GuiLibrary.SurfaceIsNull) { LuaImp.GuiLibrary.DrawNew("emu"); } foreach (var lf in _luaList) { try { LuaSandbox.Sandbox(() => { if (lf.Enabled && lf.Thread != null && !lf.Paused) { var prohibit = lf.FrameWaiting && !includeFrameWaiters; if (!prohibit) { // Restore this lua thread's preferred current directory if (lf.CurrentDirectory != null) { Environment.CurrentDirectory = PathManager.MakeAbsolutePath(lf.CurrentDirectory, null); } var result = LuaImp.ResumeScript(lf.Thread); if (result.Terminated) { LuaImp.CallExitEvent(lf.Thread); lf.Stop(); } lf.FrameWaiting = result.WaitForFrame; // If the lua thread changed its current directory, capture that here lf.CurrentDirectory = Environment.CurrentDirectory; } } }, () => { lf.Enabled = false; lf.Thread = null; }); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } }
public void LoadLuaFile(string path) { var processedPath = PathManager.TryMakeRelative(path); if (LuaAlreadyInSession(processedPath) == false) { var luaFile = new LuaFile(string.Empty, processedPath); _luaList.Add(luaFile); LuaListView.ItemCount = _luaList.Count; Global.Config.RecentLua.Add(processedPath); if (!Global.Config.DisableLuaScriptsOnLoad) { try { LuaSandbox.Sandbox(() => { luaFile.Thread = LuaImp.SpawnCoroutine(processedPath); luaFile.Enabled = true; }, () => { luaFile.Enabled = false; }); } catch (Exception e) { MessageBox.Show(e.ToString()); } } else { luaFile.Enabled = false; } luaFile.Paused = false; } else { foreach (var file in _luaList.Where(file => processedPath == file.Path && file.Enabled == false && !Global.Config.DisableLuaScriptsOnLoad)) { file.Toggle(); break; } RunLuaScripts(); } UpdateDialog(); }
public void Restart() { if (LuaImp != null && LuaImp.GuiLibrary != null && LuaImp.GuiLibrary.HasLuaSurface) { LuaImp.GuiLibrary.DrawFinish(); } var runningScripts = _luaList.Where(f => f.Enabled).ToList(); foreach (var file in runningScripts) { LuaImp.CallExitEvent(file.Thread); var functions = LuaImp.RegisteredFunctions.Where(x => x.Lua == file.Thread).ToList(); foreach (var function in functions) { LuaImp.RegisteredFunctions.Remove(function); } UpdateRegisteredFunctionsDialog(); file.Stop(); } LuaImp = new EmuLuaLibrary(this); InputBox.AutoCompleteCustomSource.AddRange(LuaImp.Docs.Select(a => a.Library + "." + a.Name).ToArray()); foreach (var file in runningScripts) { string pathToLoad = Path.IsPathRooted(file.Path) ? file.Path : PathManager.MakeProgramRelativePath(file.Path); //JUNIPIER SQUATCHBOX COMPLEX try { LuaSandbox.Sandbox(file.Thread, () => { file.Thread = LuaImp.SpawnCoroutine(pathToLoad); LuaSandbox.CreateSandbox(file.Thread, Path.GetDirectoryName(pathToLoad)); file.State = LuaFile.RunState.Running; }, () => { file.State = LuaFile.RunState.Disabled; }); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } UpdateDialog(); }
public void DoLuaEvent(IntPtr handle) { LuaSandbox.Sandbox(_ownerFile.Thread, () => { Environment.CurrentDirectory = _currentDirectory; foreach (LuaEvent luaEvent in ControlEvents) { if (luaEvent.Control == handle) { luaEvent.Event.Call(); } } }); }
public void DoLuaEvent(IntPtr handle) { LuaSandbox.Sandbox(() => { Environment.CurrentDirectory = CurrentDirectory; foreach (LuaEvent l_event in ControlEvents) { if (l_event.Control == handle) { l_event.Event.Call(); } } }); }
public void Restart() { if (LuaImp != null && LuaImp.GuiLibrary != null && LuaImp.GuiLibrary.HasLuaSurface) { LuaImp.GuiLibrary.DrawFinish(); } var runningScripts = _luaList.Where(f => f.Enabled).ToList(); foreach (var file in runningScripts) { LuaImp.CallExitEvent(file.Thread); var functions = LuaImp.RegisteredFunctions.Where(x => x.Lua == file.Thread).ToList(); foreach (var function in functions) { LuaImp.RegisteredFunctions.Remove(function); } UpdateRegisteredFunctionsDialog(); file.Stop(); } LuaImp = new EmuLuaLibrary(this); InputBox.AutoCompleteCustomSource.AddRange(LuaImp.Docs.Select(a => a.Library + "." + a.Name).ToArray()); foreach (var file in runningScripts) { try { LuaSandbox.Sandbox(() => { file.Thread = LuaImp.SpawnCoroutine(file.Path); file.Enabled = true; }, () => { file.Enabled = false; }); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } UpdateDialog(); }
public void DoLuaEvent(IntPtr handle) { // #1957 - ownerFile can be full, if the script that generated the form ended which will happen if the script does not have a while true loop LuaSandbox.Sandbox(_ownerFile?.Thread, () => { Environment.CurrentDirectory = _currentDirectory; foreach (LuaEvent luaEvent in ControlEvents) { if (luaEvent.Control == handle) { luaEvent.Event.Call(); } } }); }
private void ToggleScriptMenuItem_Click(object sender, EventArgs e) { foreach (var item in SelectedFiles) { item.Toggle(); if (item.Enabled && item.Thread == null) { try { LuaSandbox.Sandbox(() => { item.Thread = LuaImp.SpawnCoroutine(item.Path); }, () => { item.Enabled = false; }); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } else if (!item.Enabled && item.Thread != null) { LuaImp.CallExitEvent(item.Thread); var items = SelectedItems.ToList(); foreach (var sitem in items) { var temp = sitem; var functions = LuaImp.RegisteredFunctions.Where(x => x.Lua == temp.Thread).ToList(); foreach (var function in functions) { LuaImp.RegisteredFunctions.Remove(function); } UpdateRegisteredFunctionsDialog(); } LuaImp.CallExitEvent(item.Thread); item.Stop(); } } UpdateDialog(); }
/// <summary> /// resumes suspended Co-routines /// </summary> /// <param name="includeFrameWaiters">should frame waiters be waken up? only use this immediately before a frame of emulation</param> public void ResumeScripts(bool includeFrameWaiters) { if (!_luaList.Any()) { return; } if (LuaImp.GuiLibrary.SurfaceIsNull) { LuaImp.GuiLibrary.DrawNew("emu"); } foreach (var lf in _luaList.Where(l => l.Enabled && l.Thread != null && !l.Paused)) { try { LuaSandbox.Sandbox(lf.Thread, () => { var prohibit = lf.FrameWaiting && !includeFrameWaiters; if (!prohibit) { var result = LuaImp.ResumeScript(lf.Thread); if (result.Terminated) { LuaImp.CallExitEvent(lf.Thread); lf.Stop(); UpdateDialog(); } lf.FrameWaiting = result.WaitForFrame; } }, () => { lf.State = LuaFile.RunState.Disabled; lf.Thread = null; }); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } }
private void InputBox_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { string consoleBeforeCall = OutputBox.Text; // TODO: Maybe make these try-catches more general if (InputBox.Text != "") { LuaSandbox.Sandbox(null, () => { LuaImp.ExecuteString(string.Format("console.log({0})", InputBox.Text)); }, () => { LuaSandbox.Sandbox(null, () => { LuaImp.ExecuteString(InputBox.Text); if (OutputBox.Text == consoleBeforeCall) { ConsoleLog("Command successfully executed"); } }); }); _consoleCommandHistory.Insert(0, InputBox.Text); _consoleCommandHistoryIndex = -1; InputBox.Clear(); } } else if (e.KeyCode == Keys.Up) { if (_consoleCommandHistoryIndex < _consoleCommandHistory.Count - 1) { _consoleCommandHistoryIndex++; InputBox.Text = _consoleCommandHistory[_consoleCommandHistoryIndex]; InputBox.Select(InputBox.Text.Length, 0); } e.Handled = true; } else if (e.KeyCode == Keys.Down) { if (_consoleCommandHistoryIndex == 0) { _consoleCommandHistoryIndex--; InputBox.Text = ""; } else if (_consoleCommandHistoryIndex > 0) { _consoleCommandHistoryIndex--; InputBox.Text = _consoleCommandHistory[_consoleCommandHistoryIndex]; InputBox.Select(InputBox.Text.Length, 0); } e.Handled = true; } else if (e.KeyCode == Keys.Tab) { this.ProcessTabKey(false); e.Handled = true; } }
private void ToggleScriptMenuItem_Click(object sender, EventArgs e) { var files = !SelectedFiles.Any() && Global.Config.ToggleAllIfNoneSelected ? LuaImp.ScriptList : SelectedFiles; foreach (var item in files) { item.Toggle(); if (item.Enabled && item.Thread == null) { try { LuaSandbox.Sandbox(null, () => { string pathToLoad = Path.IsPathRooted(item.Path) ? item.Path : PathManager.MakeProgramRelativePath(item.Path); item.Thread = LuaImp.SpawnCoroutine(pathToLoad); LuaSandbox.CreateSandbox(item.Thread, Path.GetDirectoryName(pathToLoad)); }, () => { item.State = LuaFile.RunState.Disabled; }); // Shenanigans // We want any gui.text messages from a script to immediately update even when paused GlobalWin.OSD.ClearGUIText(); GlobalWin.Tools.UpdateToolsAfter(); LuaImp.EndLuaDrawing(); LuaImp.StartLuaDrawing(); } catch (IOException) { ConsoleLog("Unable to access file " + item.Path); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } else if (!item.Enabled && item.Thread != null) { LuaImp.CallExitEvent(item.Thread); var items = SelectedItems.ToList(); foreach (var sitem in items) { var temp = sitem; var functions = LuaImp.RegisteredFunctions.Where(lf => lf.Lua == temp.Thread).ToList(); foreach (var function in functions) { LuaImp.RegisteredFunctions.Remove(function); } UpdateRegisteredFunctionsDialog(); } LuaImp.CallExitEvent(item.Thread); item.Stop(); if (Global.Config.RemoveRegisteredFunctionsOnToggle) { LuaImp.RegisteredFunctions.ClearAll(); } } } UpdateDialog(); UpdateNumberOfScripts(); LuaListView.Refresh(); }
public void Restart() { var runningScripts = new List <LuaFile>(); if (LuaImp != null) // Things we need to do with the existing LuaImp before we can make a new one { if (LuaImp.IsRebootingCore) { // Even if the lua console is self-rebooting from client.reboot_core() we still want to re-inject dependencies LuaImp.Restart(Emulator.ServiceProvider); return; } if (LuaImp.GuiLibrary != null && LuaImp.GuiLibrary.HasLuaSurface) { LuaImp.GuiLibrary.DrawFinish(); } runningScripts = LuaImp.RunningScripts.ToList(); foreach (var file in runningScripts) { LuaImp.CallExitEvent(file); LuaImp.GetRegisteredFunctions().RemoveAll(lf => lf.Lua == file.Thread); UpdateRegisteredFunctionsDialog(); file.Stop(); } } var currentScripts = LuaImp?.ScriptList; // Temp fix for now LuaImp = OSTailoredCode.IsWindows() ? (PlatformEmuLuaLibrary) new EmuLuaLibrary(Emulator.ServiceProvider) : (PlatformEmuLuaLibrary) new NotReallyLuaLibrary(); if (currentScripts != null) { LuaImp.ScriptList.AddRange(currentScripts); } InputBox.AutoCompleteCustomSource.AddRange(LuaImp.Docs.Select(a => $"{a.Library}.{a.Name}").ToArray()); foreach (var file in runningScripts) { string pathToLoad = ProcessPath(file.Path); try { LuaSandbox.Sandbox(file.Thread, () => { LuaImp.SpawnAndSetFileThread(pathToLoad, file); LuaSandbox.CreateSandbox(file.Thread, Path.GetDirectoryName(pathToLoad)); file.State = LuaFile.RunState.Running; }, () => { file.State = LuaFile.RunState.Disabled; }); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } UpdateDialog(); }
private void InputBox_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { string consoleBeforeCall = OutputBox.Text; // TODO: Maybe make these try-catches more general if (!string.IsNullOrWhiteSpace(InputBox.Text)) { if (InputBox.Text.Contains("emu.frameadvance(")) { ConsoleLog("emu.frameadvance() can not be called from the console"); return; } LuaSandbox.Sandbox(null, () => { LuaImp.ExecuteString($"console.log({InputBox.Text})"); }, () => { LuaSandbox.Sandbox(null, () => { LuaImp.ExecuteString(InputBox.Text); if (OutputBox.Text == consoleBeforeCall) { ConsoleLog("Command successfully executed"); } }); }); _consoleCommandHistory.Insert(0, InputBox.Text); _consoleCommandHistoryIndex = -1; InputBox.Clear(); } } else if (e.KeyCode == Keys.Up) { if (_consoleCommandHistoryIndex < _consoleCommandHistory.Count - 1) { _consoleCommandHistoryIndex++; InputBox.Text = _consoleCommandHistory[_consoleCommandHistoryIndex]; InputBox.Select(InputBox.Text.Length, 0); } e.Handled = true; } else if (e.KeyCode == Keys.Down) { if (_consoleCommandHistoryIndex == 0) { _consoleCommandHistoryIndex--; InputBox.Text = ""; } else if (_consoleCommandHistoryIndex > 0) { _consoleCommandHistoryIndex--; InputBox.Text = _consoleCommandHistory[_consoleCommandHistoryIndex]; InputBox.Select(InputBox.Text.Length, 0); } e.Handled = true; } else if (e.KeyCode == Keys.Tab) { ProcessTabKey(false); e.Handled = true; } }
private void ToggleScriptMenuItem_Click(object sender, EventArgs e) { var files = !SelectedFiles.Any() && Global.Config.ToggleAllIfNoneSelected ? _luaList : SelectedFiles; foreach (var item in files) { item.Toggle(); if (item.Enabled && item.Thread == null) { try { LuaSandbox.Sandbox(null, () => { string pathToLoad = Path.IsPathRooted(item.Path) ? item.Path : PathManager.MakeProgramRelativePath(item.Path); //JUNIPIER SQUATCHBOX COMPLEX item.Thread = LuaImp.SpawnCoroutine(pathToLoad); LuaSandbox.CreateSandbox(item.Thread, Path.GetDirectoryName(pathToLoad)); }, () => { item.State = LuaFile.RunState.Disabled; }); } catch (IOException) { ConsoleLog("Unable to access file " + item.Path); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } else if (!item.Enabled && item.Thread != null) { LuaImp.CallExitEvent(item.Thread); var items = SelectedItems.ToList(); foreach (var sitem in items) { var temp = sitem; var functions = LuaImp.RegisteredFunctions.Where(x => x.Lua == temp.Thread).ToList(); foreach (var function in functions) { LuaImp.RegisteredFunctions.Remove(function); } UpdateRegisteredFunctionsDialog(); } LuaImp.CallExitEvent(item.Thread); item.Stop(); if (Global.Config.RemoveRegisteredFunctionsOnToggle) { GlobalWin.Tools.LuaConsole.LuaImp.RegisteredFunctions.ClearAll(); } } } UpdateDialog(); UpdateNumberOfScripts(); LuaListView.Refresh(); }