示例#1
0
 private static CompilerResults _Compile(Uri hFilePath, bool bGenerateInMemory, string zGlobalUniqueIdenitifer = null)
 {
     try
     {
         CodeDomProvider    codeDomProvider = (CodeDomProvider) new CSharpCodeProvider();
         CompilerParameters options         = new CompilerParameters();
         XDocument          xdocument       = XDocument.Load(hFilePath.LocalPath);
         List <string>      hResultingFiles = new List <string>();
         options.GenerateExecutable = false;
         options.GenerateInMemory   = bGenerateInMemory;
         if (!ProjectCompile._CompilePropertyGroup(hFilePath, xdocument.Root, zGlobalUniqueIdenitifer) || !ProjectCompile._CompileItemGroup(hFilePath, xdocument.Root, hResultingFiles, options.ReferencedAssemblies, options.EmbeddedResources))
         {
             return((CompilerResults)null);
         }
         options.ReferencedAssemblies.Add("System.dll");
         options.ReferencedAssemblies.Add("System.Core.dll");
         CompilerResults compilerResults = codeDomProvider.CompileAssemblyFromFile(options, hResultingFiles.ToArray());
         if (compilerResults == null || compilerResults.Errors.HasErrors)
         {
             return((CompilerResults)null);
         }
         return(compilerResults);
     }
     catch (Exception ex)
     {
         return((CompilerResults)null);
     }
 }
示例#2
0
        public static Assembly CompileToAssembly(Uri hFilePath)
        {
            CompilerResults compilerResults = ProjectCompile._Compile(hFilePath, true, (string)null);

            if (compilerResults == null)
            {
                return((Assembly)null);
            }
            return(compilerResults.CompiledAssembly);
        }
示例#3
0
        public static Uri CompileToFile(Uri hFilePath)
        {
            CompilerResults compilerResults = ProjectCompile._Compile(hFilePath, false, (string)null);

            if (compilerResults == null)
            {
                return((Uri)null);
            }
            return(new Uri(compilerResults.PathToAssembly));
        }
示例#4
0
 private static bool _CompileItemGroup(Uri hFilePath, XElement hDocumentRoot, List <string> hResultingFiles, StringCollection hResultingReferences, StringCollection hResultingResources)
 {
     foreach (XElement xelement1 in Enumerable.Where <XElement>(hDocumentRoot.Elements(), (Func <XElement, bool>)(xelement_0 =>
     {
         if (xelement_0.HasElements)
         {
             return(xelement_0.Name.LocalName.Equals("ItemGroup"));
         }
         return(false);
     })))
     {
         IEnumerable <XElement> enumerable1 = Enumerable.Where <XElement>(xelement1.Elements(), (Func <XElement, bool>)(xelement_0 =>
         {
             if (xelement_0.HasAttributes && xelement_0.Name.LocalName.Equals("Compile"))
             {
                 return(xelement_0.Attribute((XName)"Include") != null);
             }
             return(false);
         }));
         IEnumerable <XElement> enumerable2 = Enumerable.Where <XElement>(xelement1.Elements(), (Func <XElement, bool>)(xelement_0 =>
         {
             if (xelement_0.HasAttributes && xelement_0.Name.LocalName.Equals("EmbeddedResource"))
             {
                 return(xelement_0.Attribute((XName)"Include") != null);
             }
             return(false);
         }));
         IEnumerable <XElement> enumerable3 = Enumerable.Where <XElement>(xelement1.Elements(), (Func <XElement, bool>)(xelement_0 =>
         {
             if (xelement_0.HasAttributes && xelement_0.Name.LocalName.Equals("ProjectReference"))
             {
                 return(xelement_0.Attribute((XName)"Include") != null);
             }
             return(false);
         }));
         IEnumerable <XElement> enumerable4 = Enumerable.Where <XElement>(xelement1.Elements(), (Func <XElement, bool>)(xelement_0 =>
         {
             if (xelement_0.HasAttributes && xelement_0.Name.LocalName.Equals("Reference"))
             {
                 return(xelement_0.Attribute((XName)"Include") != null);
             }
             return(false);
         }));
         foreach (XElement xelement2 in enumerable1)
         {
             Uri uri = new Uri(hFilePath, xelement2.Attribute((XName)"Include").Value);
             if (!File.Exists(uri.LocalPath))
             {
                 return(false);
             }
             hResultingFiles.Add(uri.LocalPath);
         }
         foreach (XElement xelement2 in enumerable2)
         {
             Uri uri = new Uri(hFilePath, xelement2.Attribute((XName)"Include").Value);
             if (!File.Exists(uri.LocalPath))
             {
                 return(false);
             }
             hResultingResources.Add(uri.LocalPath);
         }
         foreach (XElement xelement2 in enumerable3)
         {
             XElement        xelement3       = Enumerable.SingleOrDefault <XElement>(xelement2.Elements(), (Func <XElement, bool>)(xelement_0 => xelement_0.Name.LocalName.Equals("Project")));
             CompilerResults compilerResults = ProjectCompile._Compile(new Uri(hFilePath, xelement2.Attribute((XName)"Include").Value), false, xelement3 == null ? (string)null : xelement3.Value);
             if (compilerResults == null)
             {
                 return(false);
             }
             hResultingReferences.Add(compilerResults.PathToAssembly);
         }
         foreach (XElement xelement2 in enumerable4)
         {
             if (xelement2.HasElements)
             {
                 bool flag = false;
                 foreach (XElement xelement3 in xelement2.Elements())
                 {
                     if (xelement3.Name.LocalName.Equals("SpecificVersion"))
                     {
                         flag = xelement3.Value.Equals("True", StringComparison.CurrentCultureIgnoreCase);
                     }
                 }
                 foreach (XElement xelement3 in xelement2.Elements())
                 {
                     if (xelement3.Name.LocalName.Equals("HintPath"))
                     {
                         Uri uri = new Uri(hFilePath, xelement3.Value);
                         if (!File.Exists(uri.LocalPath))
                         {
                             return(false);
                         }
                         if (flag)
                         {
                             Assembly assembly = Assembly.ReflectionOnlyLoadFrom(uri.LocalPath);
                             if (!xelement2.Attribute((XName)"Include").Value.Equals(string.Format("{0}, processorArchitecture={1}", (object)Regex.Replace(assembly.FullName, "(.*), PublicKeyToken=(.*)", "$1"), (object)assembly.GetName().ProcessorArchitecture)))
                             {
                                 return(false);
                             }
                         }
                         hResultingReferences.Add(uri.LocalPath);
                         break;
                     }
                 }
             }
             else
             {
                 hResultingReferences.Add(string.Format("{0}.dll", (object)xelement2.Attribute((XName)"Include").Value));
             }
         }
     }
     return(true);
 }
示例#5
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);
 }