Exemplo n.º 1
0
        public void Abort()
        {
            int count;

            string[] message = new string[] { "Stopping ", count.ToString(), " script(s) ..." };
            count = this._runningScripts.Count;
            GTA.Log("[INFO]", message);
            List <Script> .Enumerator enumerator = this._runningScripts.GetEnumerator();
            if (enumerator.MoveNext())
            {
                do
                {
                    Script current = enumerator.Current;
                    current.Abort();
                    IDisposable disposable = current as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }while (enumerator.MoveNext());
            }
            this._scriptTypes.Clear();
            this._runningScripts.Clear();
            GC.Collect();
        }
Exemplo n.º 2
0
        private bool LoadAssembly(string filename, Assembly assembly)
        {
            uint num3;

            uint num2 = 0;

            try
            {
                foreach (System.Type type in assembly.GetTypes())
                {
                    if (type.IsSubclassOf(typeof(Script)))
                    {
                        num2++;
                        this._scriptTypes.Add(new Tuple <string, System.Type>(filename, type));
                    }
                }
            }
            catch (ReflectionTypeLoadException exception1)
            {
                string[] strArray2 = new string[] { "Failed to load assembly '", Path.GetFileName(filename), "':", Environment.NewLine, exception1.ToString() };
                GTA.Log("[ERROR]", strArray2);
                return(false);
            }
            string[] message = new string[] { "Found ", num3.ToString(), " script(s) in '", Path.GetFileName(filename), "'." };
            num3 = num2;
            GTA.Log("[INFO]", message);
            return((num2 != 0) ? ((bool)((byte)1)) : ((bool)((byte)0)));
        }
Exemplo n.º 3
0
 private Script InstantiateScript(System.Type scripttype)
 {
     if (scripttype.IsSubclassOf(typeof(Script)))
     {
         string[] message = new string[] { "Instantiating script '", scripttype.FullName, "' in script domain '", this.Name, "' ..." };
         GTA.Log("[INFO]", message);
         try
         {
             return((Script)Activator.CreateInstance(scripttype));
         }
         catch (MissingMethodException)
         {
             string[] strArray4 = new string[] { "Failed to instantiate script '", scripttype.FullName, "' because no public default constructor was found." };
             GTA.Log("[ERROR]", strArray4);
         }
         catch (TargetInvocationException exception1)
         {
             string[] strArray2 = new string[] { "Failed to instantiate script '", scripttype.FullName, "' because constructor threw an exception:", Environment.NewLine, exception1.InnerException.ToString() };
             GTA.Log("[ERROR]", strArray2);
         }
         catch (Exception exception3)
         {
             string[] strArray = new string[] { "Failed to instantiate script '", scripttype.FullName, "':", Environment.NewLine, exception3.ToString() };
             GTA.Log("[ERROR]", strArray);
         }
     }
     return(null);
 }
Exemplo n.º 4
0
 public ScriptDomain()
 {
     sCurrentDomain = this;
     this._appdomain.AssemblyResolve    += new ResolveEventHandler(< Module >.GTA.HandleResolve);
     this._appdomain.UnhandledException += new UnhandledExceptionEventHandler(< Module >.GTA.HandleUnhandledException);
     string[] message = new string[] { "Created new script domain with v", typeof(ScriptDomain).Assembly.GetName().Version.ToString(3), "." };
     GTA.Log("[INFO]", message);
 }
Exemplo n.º 5
0
 public static void AbortScript(Script script)
 {
     if (!ReferenceEquals(script._thread, null))
     {
         script._running = false;
         script._thread.Abort();
         script._thread = null;
         string[] message = new string[] { "Aborted script '", script.Name, "'." };
         GTA.Log("[INFO]", message);
     }
 }
Exemplo n.º 6
0
 public void DoTick()
 {
     List <Script> .Enumerator enumerator = this._runningScripts.GetEnumerator();
     if (enumerator.MoveNext())
     {
         do
         {
             Script current = enumerator.Current;
             if (current._running)
             {
                 this._executingScript = current;
                 AutoResetEvent event2 = current._waitEvent;
                 current._continueEvent.Set();
                 byte num = (byte)event2.WaitOne(0x7530);
                 current._running = (bool)num;
                 if (num != 0)
                 {
                     while (this._taskQueue.Count > 0)
                     {
                         this._taskQueue.Dequeue().Run();
                         event2 = current._waitEvent;
                         current._continueEvent.Set();
                         num = (byte)event2.WaitOne(0x7530);
                         current._running = (bool)num;
                         if (num == 0)
                         {
                             break;
                         }
                     }
                 }
                 this._executingScript = null;
                 if (!current._running)
                 {
                     string[] message = new string[] { "Script '", current.Name, "' is not responding! Aborting ..." };
                     GTA.Log("[ERROR]", message);
                     AbortScript(current);
                 }
             }
         }while (enumerator.MoveNext());
     }
     this.CleanupStrings();
 }
Exemplo n.º 7
0
        private bool LoadAssembly(string filename)
        {
            Assembly assembly = null;

            try
            {
                assembly = Assembly.LoadFrom(filename);
            }
            catch (BadImageFormatException)
            {
                return(false);
            }
            catch (Exception exception1)
            {
                string[] message = new string[] { "Failed to load assembly '", Path.GetFileName(filename), "':", Environment.NewLine, exception1.ToString() };
                GTA.Log("[ERROR]", message);
                return(false);
            }
            return(this.LoadAssembly(filename, assembly));
        }
Exemplo n.º 8
0
        private bool LoadScript(string filename)
        {
            CodeDomProvider provider;

            CompilerParameters options = new CompilerParameters {
                CompilerOptions         = "/optimize",
                GenerateInMemory        = true,
                IncludeDebugInformation = true,
                ReferencedAssemblies    =
                {
                    "System.dll",
                    "System.Core.dll",
                    "System.Drawing.dll",
                    "System.Windows.Forms.dll",
                    "System.XML.dll",
                    "System.XML.Linq.dll",
                    typeof(Script).Assembly.Location
                }
            };
            string extension = Path.GetExtension(filename);

            if (extension.Equals(".cs", StringComparison.InvariantCultureIgnoreCase))
            {
                provider = new CSharpCodeProvider();
                options.CompilerOptions = options.CompilerOptions + " /unsafe";
            }
            else
            {
                if (!extension.Equals(".vb", StringComparison.InvariantCultureIgnoreCase))
                {
                    return(false);
                }
                provider = new VBCodeProvider();
            }
            CompilerResults results = provider.CompileAssemblyFromFile(options, new string[] { filename });

            if (!results.Errors.HasErrors)
            {
                string[] message = new string[] { "Successfully compiled '", Path.GetFileName(filename), "'." };
                GTA.Log("[INFO]", message);
                return(this.LoadAssembly(filename, results.CompiledAssembly));
            }
            StringBuilder builder    = new StringBuilder();
            IEnumerator   enumerator = results.Errors.GetEnumerator();

            while (true)
            {
                try
                {
                    while (true)
                    {
                        if (!enumerator.MoveNext())
                        {
                            int      count;
                            string[] message = new string[] { "Failed to compile '", Path.GetFileName(filename), "' with ", count.ToString(), " error(s):", Environment.NewLine, builder.ToString() };
                            count = results.Errors.Count;
                            GTA.Log("[ERROR]", message);
                            return(false);
                        }
                        else
                        {
                            CompilerError current = (CompilerError)enumerator.Current;
                            builder.Append("   at line ");
                            builder.Append(current.Line);
                            builder.Append(": ");
                            builder.Append(current.ErrorText);
                            builder.AppendLine();
                        }
                        break;
                    }
                }
                finally
                {
                    IDisposable disposable = enumerator as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }
            }
        }
Exemplo n.º 9
0
        public static ScriptDomain Load(string path)
        {
            int num;

            List <string> list;
            List <string> list2;

            path = Path.GetFullPath(path);
            AppDomainSetup info = new AppDomainSetup {
                ApplicationBase       = path,
                ShadowCopyFiles       = "true",
                ShadowCopyDirectories = path
            };

            StrongName[]     fullTrustAssemblies = new StrongName[0];
            System.AppDomain domain = System.AppDomain.CreateDomain("ScriptDomain_" + (path.GetHashCode() * Environment.TickCount).ToString("X"), null, info, new PermissionSet(PermissionState.Unrestricted), fullTrustAssemblies);
            domain.InitializeLifetimeService();
            ScriptDomain domain2 = null;

            try
            {
                domain2 = (ScriptDomain)domain.CreateInstanceFromAndUnwrap(typeof(ScriptDomain).Assembly.Location, typeof(ScriptDomain).FullName);
            }
            catch (Exception exception1)
            {
                string[] strArray2 = new string[] { "Failed to create script domain '", domain.FriendlyName, "':", Environment.NewLine, exception1.ToString() };
                GTA.Log("[ERROR]", strArray2);
                System.AppDomain.Unload(domain);
                return(null);
            }
            string[] message = new string[] { "Loading scripts from '", path, "' into script domain '", domain.FriendlyName, "' ..." };
            GTA.Log("[INFO]", message);
            if (!Directory.Exists(path))
            {
                string[] strArray7 = new string[] { "Failed to reload scripts because the directory is missing." };
                GTA.Log("[ERROR]", strArray7);
                return(domain2);
            }
            else
            {
                list2 = new List <string>();
                list  = new List <string>();
                try
                {
                    list2.AddRange(Directory.GetFiles(path, "*.vb", SearchOption.AllDirectories));
                    list2.AddRange(Directory.GetFiles(path, "*.cs", SearchOption.AllDirectories));
                    list.AddRange(Directory.GetFiles(path, "*.dll", SearchOption.AllDirectories));
                }
                catch (Exception exception5)
                {
                    string[] strArray6 = new string[] { "Failed to reload scripts:", Environment.NewLine, exception5.ToString() };
                    GTA.Log("[ERROR]", strArray6);
                    System.AppDomain.Unload(domain);
                    return(null);
                }
                num = 0;
            }
            while (true)
            {
                if (num >= list.Count)
                {
                    List <string> .Enumerator enumerator2 = list2.GetEnumerator();
                    if (enumerator2.MoveNext())
                    {
                        do
                        {
                            string current = enumerator2.Current;
                            domain2.LoadScript(current);
                        }while (enumerator2.MoveNext());
                    }
                    List <string> .Enumerator enumerator = list.GetEnumerator();
                    if (enumerator.MoveNext())
                    {
                        do
                        {
                            string current = enumerator.Current;
                            domain2.LoadAssembly(current);
                        }while (enumerator.MoveNext());
                    }
                    break;
                }
                try
                {
                    string assemblyFile = list[num];
                    if (AssemblyName.GetAssemblyName(assemblyFile).Name == "ScriptHookVDotNet")
                    {
                        string[] strArray5 = new string[] { "Removing assembly file '", Path.GetFileName(assemblyFile), "'." };
                        GTA.Log("[WARNING]", strArray5);
                        num += -1;
                        list.RemoveAt(num);
                        try
                        {
                            File.Delete(assemblyFile);
                        }
                        catch (Exception exception6)
                        {
                            string[] strArray4 = new string[] { "Failed to delete assembly file:", Environment.NewLine, exception6.ToString() };
                            GTA.Log("[ERROR]", strArray4);
                        }
                    }
                }
                catch (BadImageFormatException)
                {
                }
                catch (Exception exception7)
                {
                    string[] strArray3 = new string[] { "Failed to load assembly ", list[num], Environment.NewLine, exception7.ToString() };
                    GTA.Log("[ERROR]", strArray3);
                }
                num++;
            }
            return(domain2);
        }