Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
        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();
        }
Ejemplo n.º 3
0
        /// <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());
                }
            }
        }
Ejemplo n.º 4
0
        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();
        }
Ejemplo n.º 5
0
        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
                {
                    file.Thread  = LuaImp.SpawnCoroutine(file.Path);
                    file.Enabled = true;
                }
                catch (Exception ex)
                {
                    if (ex is LuaScriptException)
                    {
                        file.Enabled = false;
                        ConsoleLog(ex.Message);
                    }
                    else
                    {
                        MessageBox.Show(ex.ToString());
                    }
                }
            }

            UpdateDialog();
        }
Ejemplo n.º 6
0
        private void ToggleScriptMenuItem_Click(object sender, EventArgs e)
        {
            foreach (var item in SelectedFiles)
            {
                item.Toggle();

                if (item.Enabled && item.Thread == null)
                {
                    try
                    {
                        item.Thread = LuaImp.SpawnCoroutine(item.Path);
                    }
                    catch (Exception ex)
                    {
                        if (ex.ToString().Substring(0, 32) == "LuaInterface.LuaScriptException:")
                        {
                            item.Enabled = false;
                            ConsoleLog(ex.Message);
                        }
                        else
                        {
                            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();
        }
Ejemplo n.º 7
0
        private void ToggleScriptMenuItem_Click(object sender, EventArgs e)
        {
            var files = !SelectedFiles.Any() && Global.Config.ToggleAllIfNoneSelected ? LuaImp.ScriptList : SelectedFiles;

            foreach (var file in files)
            {
                file.Toggle();

                if (file.Enabled && file.Thread == null)
                {
                    EnableLuaFile(file);
                }

                else if (!file.Enabled && file.Thread != null)
                {
                    LuaImp.CallExitEvent(file);

                    var items = SelectedItems.ToList();
                    foreach (var sitem in items)
                    {
                        var temp      = sitem;
                        var functions = LuaImp.GetRegisteredFunctions().Where(lf => lf.Lua == temp.Thread).ToList();
                        foreach (var function in functions)
                        {
                            LuaImp.GetRegisteredFunctions().Remove(function);
                        }

                        UpdateRegisteredFunctionsDialog();
                    }

                    LuaImp.CallExitEvent(file);
                    file.Stop();
                    if (Global.Config.RemoveRegisteredFunctionsOnToggle)
                    {
                        LuaImp.GetRegisteredFunctions().ClearAll();
                    }
                }
            }

            UpdateDialog();
            UpdateNumberOfScripts();
            LuaListView.Refresh();
        }
Ejemplo n.º 8
0
        /// <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());
                }
            }
        }
Ejemplo n.º 9
0
        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();
        }
Ejemplo n.º 10
0
        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();
        }
Ejemplo n.º 11
0
        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();
        }
Ejemplo n.º 12
0
        /// <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())
            {
                if (LuaImp.GuiLibrary.SurfaceIsNull)
                {
                    LuaImp.GuiLibrary.DrawNew("emu");
                }

                foreach (var lf in _luaList)
                {
                    var oldcd = Environment.CurrentDirectory;                     // Save old current directory before this lua thread clobbers it for the .net thread

                    try
                    {
                        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;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ex is LuaScriptException || ex is LuaException)
                        {
                            lf.Enabled = false;
                            lf.Thread  = null;
                            ConsoleLog(ex.ToString());
                        }
                        else
                        {
                            MessageBox.Show(ex.ToString());
                        }
                    }
                    finally
                    {
                        // Restore the current directory
                        Environment.CurrentDirectory = oldcd;
                    }
                }
            }
        }