Пример #1
0
 public static void StopScript()
 {
     ScriptInterface.exit = true;
     CurrentScriptThread?.Join(1000);
     if (CurrentScriptThread?.IsAlive ?? false)
     {
         CurrentScriptThread.Abort();
         ScriptStopped?.Invoke(false);
     }
     CurrentScriptThread = null;
 }
Пример #2
0
        public static async Task <Exception> StartScriptAsync()
        {
            if (ScriptRunning)
            {
                ScriptInterface.Instance.Log("Script already running.");
                return(new Exception("Script already running."));
            }
            else
            {
                try
                {
                    ScriptInterface.exit = false;
                    object script = await Task.Run(() => Compile(File.ReadAllText(LoadedScript)));

                    LoadScriptConfig(script);
                    if (_configured.TryGetValue(ScriptInterface.Instance.Config.Storage, out bool b) && !b)
                    {
                        ScriptInterface.Instance.Config.Configure();
                    }
                    ScriptInterface.Instance.Handlers.Clear();
                    ScriptInterface.Instance.Runtime = new ScriptRuntimeVars();
                    CurrentScriptThread = new Thread(() =>
                    {
                        ScriptStarted?.Invoke();
                        try
                        {
                            script.GetType().GetMethod("ScriptMain").Invoke(script, new object[] { ScriptInterface.Instance });
                        }
                        catch (Exception e)
                        {
                            if (!(e is ThreadAbortException))
                            {
                                Debug.WriteLine($"Error while running script: {e.Message}");
                                ScriptError?.Invoke(e);
                            }
                        }
                        ScriptStopped?.Invoke(true);
                    });
                    CurrentScriptThread.Name = "Script Thread";
                    CurrentScriptThread.Start();
                    return(null);
                }
                catch (Exception e)
                {
                    return(e);
                }
            }
        }
Пример #3
0
        public static void StopScript()
        {
            ScriptInterface.exit = true;
            CurrentScriptThread?.Join(1000);
            if (CurrentScriptThread?.IsAlive ?? false)
            {
                CurrentScriptThread.Abort();
                ScriptStopped?.Invoke(false);
                Forms.Scripts.btnStartScript.CheckedInvoke(() => Forms.Scripts.btnStartScript.Text = "Start Script");
            }

            ScriptInterface.Instance.Options.AutoRelogin      = false;
            ScriptInterface.Instance.Options.LagKiller        = false;
            ScriptInterface.Instance.Options.LagKiller        = true;
            ScriptInterface.Instance.Options.LagKiller        = false;
            ScriptInterface.Instance.Options.AggroAllMonsters = false;
            ScriptInterface.Instance.Options.AggroMonsters    = false;
            ScriptInterface.Instance.Options.SkipCutscenes    = false;
            ScriptInterface.Instance.Skills.StopTimer();
            ScriptInterface.Instance.Drops.Stop();
            ScriptInterface.Instance.Events.ClearHandlers();
            CurrentScriptThread = null;
        }
Пример #4
0
 protected virtual void OnScriptStopped(ScriptStoppedEventArgs e)
 {
     ScriptStopped?.Invoke(this, e);
 }