Пример #1
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);
 }
Пример #2
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);
 }