Exemplo n.º 1
0
 public void ScriptProcess(string zMessage)
 {
     this.ScriptWrite("> " + zMessage);
     if (!IManager._bScript)
     {
         return;
     }
     Scripting.Execute(zMessage + ";");
 }
Exemplo n.º 2
0
        public static bool Event(eScripting eScripting)
        {
            if (Scripting._hLua_X64 != null || Scripting._hLua_X86 != null || Scripting._hCompiled != null)
            {
                if (!Scripting._bLoaded && (eScripting == eScripting.OnRun || eScripting == eScripting.OnFrame))
                {
                    Scripting._bLoaded = true;
                    Scripting.Event(eScripting.OnLoad);
                }
                try
                {
                    if (Scripting._hCompiled != null)
                    {
                        switch (eScripting)
                        {
                        case eScripting.OnClose:
                            Scripting._hCompiled.hInterface.OnClose();
                            break;

                        case eScripting.OnLoad:
                            Scripting._hCompiled.hInterface.OnLoad();
                            break;

                        case eScripting.OnRun:
                            Scripting._hCompiled.hInterface.OnRun();
                            break;
                        }
                    }
                    else if (Scripting._hLua_X64 != null)
                    {
                        LuaInterface_X64.LuaFunction function = Scripting._hLua_X64.LuaEngine.GetFunction(eScripting.ToString());
                        if (function == null)
                        {
                            return(false);
                        }
                        function.Call();
                    }
                    else
                    {
                        LuaInterface_X86.LuaFunction function = Scripting._hLua_X86.LuaEngine.GetFunction(eScripting.ToString());
                        if (function == null)
                        {
                            return(false);
                        }
                        function.Call();
                    }
                    return(true);
                }
                catch (Exception ex)
                {
                    int num = 1;
                    Program.Exception(ex, num != 0);
                    Scripting.Close();
                }
            }
            return(false);
        }
Exemplo n.º 3
0
 public static void Frame()
 {
     if (Program.Manager.InvokeRequired)
     {
         Program.Manager.Invoke((Delegate) new Action(Event.Frame));
     }
     else
     {
         Scripting.Event(eScripting.OnFrame);
     }
 }
Exemplo n.º 4
0
 public static void Player()
 {
     if (Program.Manager.InvokeRequired)
     {
         Program.Manager.Invoke((Delegate) new Action(Event.Player));
     }
     else
     {
         Scripting.Event(eScripting.OnRun);
     }
 }
Exemplo n.º 5
0
 public static bool Update()
 {
     if (Scripting._hLua_X64 != null)
     {
         return(Scripting.Update(Scripting._hLua_X64.LuaEngine));
     }
     if (Scripting._hLua_X86 != null)
     {
         return(Scripting.Update(Scripting._hLua_X86.LuaEngine));
     }
     return(false);
 }
Exemplo n.º 6
0
 public static void Initialize()
 {
     if (Program.Manager.InvokeRequired)
     {
         Program.Manager.Invoke((Delegate) new Action(Event.Initialize));
     }
     else
     {
         Game.PlayerInput.RegisterThread();
         Program.Overlay.Show();
         Scripting.Update();
     }
 }
Exemplo n.º 7
0
 public static object Include(string zFile)
 {
     if (!zFile.EndsWith(".lua") && !zFile.EndsWith(".cs") && !zFile.EndsWith(".vb"))
     {
         if (Scripting._hLua_X64 == null && Scripting._hLua_X86 == null)
         {
             return((object)null);
         }
         zFile += ".lua";
     }
     if (!File.Exists(zFile))
     {
         return((object)null);
     }
     return(Scripting.IncludeString(zFile, Scripting._Read(zFile)));
 }
Exemplo n.º 8
0
 public static object IncludeString(string zFile, string zString)
 {
     if (Scripting._hLua_X64 == null && Scripting._hLua_X86 == null && Scripting._hCompiled == null)
     {
         return((object)null);
     }
     try
     {
         if (zFile != null && !zFile.EndsWith(".lua"))
         {
             if (Scripting._hCompiled.hTypes != null)
             {
                 foreach (Type type in Scripting._hCompiled.hTypes)
                 {
                     if (type.IsClass && Path.GetFileNameWithoutExtension(zString).Equals(type.Name))
                     {
                         return(Activator.CreateInstance(type));
                     }
                 }
             }
             return((object)null);
         }
         if (Scripting._hLua_X64 != null)
         {
             if (Scripting._hCompiled != null)
             {
                 return((object)Scripting._Create_X64(zFile));
             }
             Scripting._hLua_X64.LuaEngine.DoString("AionScriptObject = {};\r\n" + Regex.Replace(zString, "function (.*?)\\(", "function AionScriptObject:$1("), Path.GetFileName(zFile));
             return(Scripting._hLua_X64.LuaEngine["AionScriptObject"]);
         }
         if (Scripting._hCompiled != null)
         {
             return((object)Scripting._Create_X86(zFile));
         }
         Scripting._hLua_X86.LuaEngine.DoString("AionScriptObject = {};\r\n" + Regex.Replace(zString, "function (.*?)\\(", "function AionScriptObject:$1("), Path.GetFileName(zFile));
         return(Scripting._hLua_X86.LuaEngine["AionScriptObject"]);
     }
     catch (Exception ex)
     {
         int num = 1;
         Program.Exception(ex, num != 0);
         Scripting.Close();
         return((object)null);
     }
 }
Exemplo n.º 9
0
 public void ScriptExit()
 {
     if (this.InvokeRequired)
     {
         this.BeginInvoke((Delegate) new Action(this.ScriptExit));
     }
     else
     {
         if (!IManager._bScript)
         {
             return;
         }
         Scripting.Close();
         this.ScriptList.Enabled = true;
         this.NodeList.Enabled   = true;
         this.ScriptToggle.Text  = "Enable";
         IManager._bScript       = false;
     }
 }
Exemplo n.º 10
0
        private static LuaDotNet_X86 _Create_X86(string zFile)
        {
            LuaInterface_X86.Lua hLua           = new LuaInterface_X86.Lua();
            ProgramCryptor       programCryptor = new ProgramCryptor();

            Scripting.Update(hLua);
            hLua.RegisterFunction("Close", (object)programCryptor, (MethodBase)programCryptor.GetType().GetMethod("Close"));
            hLua.RegisterFunction("Include", (object)programCryptor, (MethodBase)programCryptor.GetType().GetMethod("Include"));
            hLua.RegisterFunction("Time", (object)new Game(), (MethodBase) new Game().GetType().GetMethod("Time"));
            hLua.RegisterFunction("Travel", (object)programCryptor, (MethodBase)programCryptor.GetType().GetMethod("Travel"));
            hLua.RegisterFunction("Register", (object)programCryptor, (MethodBase)programCryptor.GetType().GetMethod("Register"));
            hLua.RegisterFunction("Unregister", (object)programCryptor, (MethodBase)programCryptor.GetType().GetMethod("Unregister"));
            hLua.RegisterFunction("Write", (object)programCryptor, (MethodBase)programCryptor.GetType().GetMethod("Write"));
            if (File.Exists(zFile))
            {
                hLua.DoString(File.ReadAllText(zFile), Path.GetFileName(zFile));
            }
            return(new LuaDotNet_X86(hLua));
        }
Exemplo n.º 11
0
 public static bool Close()
 {
     if (Scripting._hLua_X64 == null && Scripting._hLua_X86 == null && Scripting._hCompiled == null)
     {
         return(false);
     }
     foreach (KeyValuePair <string, ArrayList> keyValuePair in Scripting._hHotKey)
     {
         Game.PlayerInput.Unregister((Keys)keyValuePair.Value[0], (KeysModifier)keyValuePair.Value[1]);
     }
     foreach (KeyValuePair <AionEventKeyHandler, ArrayList> keyValuePair in Scripting._hHotKeyCompiled)
     {
         Game.PlayerInput.Unregister((Keys)keyValuePair.Value[0], (KeysModifier)keyValuePair.Value[1]);
     }
     Scripting._hHotKey.Clear();
     Scripting._hHotKeyCompiled.Clear();
     Scripting.Event(eScripting.OnClose);
     Scripting._hLua_X86  = (LuaDotNet_X86)null;
     Scripting._hLua_X64  = (LuaDotNet_X64)null;
     Scripting._hCompiled = (CompileResult)null;
     return(true);
 }
Exemplo n.º 12
0
 private void _OnClick(object sender, EventArgs e)
 {
     if (sender == this.InfoPicture)
     {
         if (!File.Exists(Program.CurrentDirectory + "AionScript.pdf"))
         {
             return;
         }
         Process.Start(Program.CurrentDirectory + "AionScript.pdf");
     }
     else if (sender == this.DialogPicture)
     {
         Program.Dialog.Show();
     }
     else
     {
         if (sender == this.OffsetsPicture)
         {
             return;
         }
         if (sender != this.NodeListContextCreate)
         {
             if (sender == this.NodeListContextClear)
             {
                 this.NodeList.SelectedIndex = -1;
             }
             else if (sender == this.NodeListContextDelete)
             {
                 if (MessageBox.Show("This file will be permanently deleted from the file system and cannot be restored later if you change your mind! Are you absolutely sure you wish to delete this node forever?", "Confirm Delete", MessageBoxButtons.YesNo) != DialogResult.Yes)
                 {
                     return;
                 }
                 string zName = (string)this.NodeList.SelectedItem;
                 this.NodeClose(zName);
                 File.Delete(this._zFolderNode + "\\" + zName);
                 this.NodeList.Items.Remove((object)zName);
                 this.NodeList.SelectedIndex = -1;
             }
             else if (sender == this.NodeListContextEdit)
             {
                 string key = (string)this.NodeList.SelectedItem;
                 if (this._hNodeList.ContainsKey(key) && !this._hNodeList[key].IsDisposed)
                 {
                     this._hNodeList[key].Show();
                     this._hNodeList[key].Activate();
                 }
                 else
                 {
                     this._hNodeList[key] = new ITravel(this._zFolderNode + "\\" + key);
                     this._hNodeList[key].Show();
                 }
             }
             else if (sender == this.NodeListContextReload)
             {
                 this.SetFolderNode(this._zFolderNode);
             }
             else if (sender != this.ScriptListContextCreate)
             {
                 if (sender == this.ScriptListContextClear)
                 {
                     this.ScriptList.SelectedIndex = -1;
                 }
                 else if (sender == this.ScriptListContextDelete)
                 {
                     if (MessageBox.Show("This file will be permanently deleted from the file system and cannot be restored later if you change your mind! Are you absolutely sure you wish to delete this script forever?", "Confirm Delete", MessageBoxButtons.YesNo) != DialogResult.Yes)
                     {
                         return;
                     }
                     string zName = (string)this.ScriptList.SelectedItem;
                     this.ScriptClose(zName);
                     File.Delete(this._zFolderScripting + "\\" + zName);
                     this.ScriptList.Items.Remove((object)zName);
                     this.ScriptList.SelectedIndex = -1;
                 }
                 else if (sender == this.ScriptListContextEdit)
                 {
                     string key = (string)this.ScriptList.SelectedItem;
                     if (IManager._hScriptingList.ContainsKey(key) && !IManager._hScriptingList[key].IsDisposed)
                     {
                         IManager._hScriptingList[key].Show();
                         IManager._hScriptingList[key].Activate();
                     }
                     else if (File.Exists(this._zFolderScripting + "\\" + key))
                     {
                         IManager._hScriptingList[key] = new IScripting(this._zFolderScripting + "\\" + key);
                         IManager._hScriptingList[key].Show();
                     }
                     else
                     {
                         int num = (int)MessageBox.Show("This file does not exist. Perhaps this is a project?");
                     }
                 }
                 else if (sender == this.ScriptListContextReload)
                 {
                     this.SetFolderScripting(this._zFolderScripting);
                 }
                 else if (sender == this.ScriptOutputContextClear)
                 {
                     this.ScriptOutput.Text = "Clearing the console window...";
                 }
                 else
                 {
                     if (sender != this.ScriptToggle)
                     {
                         return;
                     }
                     if (IManager._bScript)
                     {
                         this.ScriptExit();
                     }
                     else if (Scripting.Load(this._zFolderScripting + "\\" + (string)this.ScriptList.SelectedItem))
                     {
                         this.ScriptList.Enabled = false;
                         this.NodeList.Enabled   = false;
                         this.ScriptToggle.Text  = "Disable";
                         IManager._bScript       = true;
                     }
                     else
                     {
                         this.InfoLabel.Focus();
                     }
                 }
             }
             else
             {
                 string str = Interaction.InputBox("Please provide the name of the new script file.", string.Empty, string.Empty, -1, -1);
                 if (str == null || str.Length == 0)
                 {
                     return;
                 }
                 if (!str.EndsWith(".lua") && !str.EndsWith(".cs") && !str.EndsWith(".vb"))
                 {
                     str += ".lua";
                 }
                 if (!this.ScriptList.Items.Contains((object)str))
                 {
                     this.ScriptList.Items.Add((object)str);
                 }
                 for (int index = 0; index < this.ScriptList.Items.Count; ++index)
                 {
                     if ((string)this.ScriptList.Items[index] == str)
                     {
                         this.ScriptList.SelectedIndex = index;
                         break;
                     }
                 }
                 if (!File.Exists(this._zFolderScripting + "\\" + str))
                 {
                     File.Create(this._zFolderScripting + "\\" + str).Close();
                 }
                 this.ScriptListContextEdit.PerformClick();
             }
         }
         else
         {
             string str = Interaction.InputBox("Please provide the name of the new node path.", string.Empty, string.Empty, -1, -1);
             if (str == null || str.Length == 0)
             {
                 return;
             }
             if (!str.ToLower().EndsWith(".xml"))
             {
                 str += ".xml";
             }
             if (!this.NodeList.Items.Contains((object)str))
             {
                 this.NodeList.Items.Add((object)str);
             }
             for (int index = 0; index < this.NodeList.Items.Count; ++index)
             {
                 if ((string)this.NodeList.Items[index] == str)
                 {
                     this.NodeList.SelectedIndex = index;
                     break;
                 }
             }
             if (!File.Exists(this._zFolderNode + "\\" + str))
             {
                 File.Create(this._zFolderNode + "\\" + str).Close();
             }
             this.NodeListContextEdit.PerformClick();
         }
     }
 }
Exemplo n.º 13
0
 public object ScriptInclude(string zFile)
 {
     return(Scripting.Include(this._zFolderScripting + "\\" + zFile));
 }
Exemplo n.º 14
0
 public static bool Load(string zFile)
 {
     try
     {
         bool bIsVisualBasic = false;
         Scripting._bLoaded = false;
         if (Game.PlayerInput == null)
         {
             throw new Exception("Please start the game before starting a script.");
         }
         Program.Manager.SetTravel((string)null);
         string path = zFile + Path.DirectorySeparatorChar.ToString() + Path.GetFileNameWithoutExtension(zFile) + ".csproj";
         if (File.Exists(path))
         {
             Assembly assembly = ProjectCompile.CompileToAssembly(new Uri(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar.ToString() + path));
             // ISSUE: variable of the null type
             Assembly local = null;
             if (assembly == (Assembly)local)
             {
                 throw new Exception("Unable to compile project; does it work in Visual Studio?");
             }
             foreach (Type type in assembly.GetTypes())
             {
                 try
                 {
                     if (!type.IsAbstract)
                     {
                         if (type.IsClass)
                         {
                             if (type.GetInterface(typeof(IAionInterface).Name) != (Type)null)
                             {
                                 Scripting._hCompiled = new CompileResult()
                                 {
                                     hInterface = (IAionInterface)Activator.CreateInstance(type),
                                     hTypes     = (Type[])null
                                 };
                                 return(true);
                             }
                         }
                     }
                 }
                 catch (Exception ex)
                 {
                     throw new Exception("Unable to instantiate project entry point!");
                 }
             }
             throw new Exception("Unable to find project entry point!");
         }
         if (!zFile.EndsWith(".cs") && !(bIsVisualBasic = zFile.EndsWith(".vb")))
         {
             if (zFile.EndsWith(".lua"))
             {
                 if (UIntPtr.Size == 4)
                 {
                     Scripting._hLua_X86 = Scripting._Create_X86(zFile);
                     if (Scripting._hLua_X86 == null)
                     {
                         return(false);
                     }
                 }
                 else
                 {
                     Scripting._hLua_X64 = Scripting._Create_X64(zFile);
                     if (Scripting._hLua_X64 == null)
                     {
                         return(false);
                     }
                 }
                 if (File.Exists("AionScript.lua"))
                 {
                     if (Scripting._hLua_X64 != null)
                     {
                         Scripting._hLua_X64.LuaEngine.DoFile("AionScript.lua");
                     }
                     else if (Scripting._hLua_X86 != null)
                     {
                         Scripting._hLua_X86.LuaEngine.DoFile("AionScript.lua");
                     }
                 }
                 foreach (string index in new List <string>()
                 {
                     "AsCircularMagic",
                     "AsTest"
                 })
                 {
                     string zString = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("AionScript.Resources.Library." + index + ".lua")).ReadToEnd();
                     if (Scripting._hLua_X64 != null)
                     {
                         Scripting._hLua_X64.LuaEngine[index] = Scripting.IncludeString((string)null, zString);
                     }
                     else
                     {
                         Scripting._hLua_X86.LuaEngine[index] = Scripting.IncludeString((string)null, zString);
                     }
                 }
                 return(true);
             }
         }
         else
         {
             Scripting._hCompiled = Compiler.Compile(zFile, bIsVisualBasic);
             return(Scripting._hCompiled != null);
         }
     }
     catch (Exception ex)
     {
         int num = 1;
         Program.Exception(ex, num != 0);
         Scripting.Close();
     }
     return(false);
 }