コード例 #1
0
 public CSharpPluginLoader(CSharpExtension extension)
 {
     Instance = this;
     CSharpPluginLoader.extension = extension;
     PluginCompiler.CheckCompilerBinary();
     compiler = new PluginCompiler();
 }
コード例 #2
0
        public void OnModLoaded()
        {
            PluginCompiler.CheckCompilerBinary();

            // Include references to all loaded game extensions and any assemblies they reference
            foreach (Core.Extensions.Extension extension in Interface.Oxide.GetAllExtensions())
            {
                if (extension == null || !extension.IsCoreExtension && !extension.IsGameExtension)
                {
                    continue;
                }

                System.Reflection.Assembly assembly = extension.GetType().Assembly;
                string assemblyName = assembly.GetName().Name;

                if (AssemblyBlacklist.Contains(assemblyName))
                {
                    continue;
                }

                PluginReferences.Add(assemblyName);
                foreach (System.Reflection.AssemblyName reference in assembly.GetReferencedAssemblies())
                {
                    if (reference != null)
                    {
                        PluginReferences.Add(reference.Name);
                    }
                }
            }
        }
コード例 #3
0
        private bool CheckCompiler()
        {
            PluginCompiler.CheckCompilerBinary();
            Oxide.Core.Libraries.Timer.TimerInstance timerInstance = this.idleTimer;
            if (timerInstance != null)
            {
                timerInstance.Destroy();
            }
            else
            {
            }
            if (PluginCompiler.BinaryPath == null)
            {
                return(false);
            }
            if (this.process != null && this.process.Handle != IntPtr.Zero && !this.process.HasExited)
            {
                return(true);
            }
            PluginCompiler.SetCompilerVersion();
            PluginCompiler.PurgeOldLogs();
            this.Shutdown();
            string[] strArrays = new string[] { "/service", string.Concat("/logPath:", PluginCompiler.EscapePath(Interface.Oxide.LogDirectory)) };
            try
            {
                Process process = new Process();
                process.StartInfo.FileName               = PluginCompiler.BinaryPath;
                process.StartInfo.Arguments              = string.Join(" ", strArrays);
                process.StartInfo.CreateNoWindow         = true;
                process.StartInfo.UseShellExecute        = false;
                process.StartInfo.RedirectStandardInput  = true;
                process.StartInfo.RedirectStandardOutput = true;
                process.EnableRaisingEvents              = true;
                this.process = process;
                switch (Environment.OSVersion.Platform)
                {
                case PlatformID.Win32S:
                case PlatformID.Win32Windows:
                case PlatformID.Win32NT:
                {
                    string environmentVariable = Environment.GetEnvironmentVariable("PATH");
                    Environment.SetEnvironmentVariable("PATH", string.Concat(environmentVariable, ";", Path.Combine(Interface.Oxide.ExtensionDirectory, "x86")));
                    goto case PlatformID.Xbox;
                }

                case PlatformID.WinCE:
                case PlatformID.Xbox:
                {
                    this.process.Exited += new EventHandler(this.OnProcessExited);
                    this.process.Start();
                    break;
                }

                case PlatformID.Unix:
                case PlatformID.MacOSX:
                {
                    string str = Environment.GetEnvironmentVariable("LD_LIBRARY_PATH");
                    this.process.StartInfo.EnvironmentVariables["LD_LIBRARY_PATH"] = Path.Combine(Interface.Oxide.ExtensionDirectory, (IntPtr.Size == 8 ? "x64" : "x86"));
                    Environment.SetEnvironmentVariable("LD_LIBRARY_PATH", string.Concat(str, ":", Path.Combine(Interface.Oxide.ExtensionDirectory, (IntPtr.Size == 8 ? "x64" : "x86"))));
                    goto case PlatformID.Xbox;
                }

                default:
                {
                    goto case PlatformID.Xbox;
                }
                }
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                Process   process1  = this.process;
                if (process1 != null)
                {
                    process1.Dispose();
                }
                else
                {
                }
                this.process = null;
                Interface.Oxide.LogException(string.Concat("Exception while starting compiler version ", PluginCompiler.CompilerVersion, ": "), exception);
                if (PluginCompiler.BinaryPath.Contains("'"))
                {
                    Interface.Oxide.LogWarning("Server directory path contains an apostrophe, compiler will not work until path is renamed", Array.Empty <object>());
                }
                else if (Environment.OSVersion.Platform == PlatformID.Unix)
                {
                    Interface.Oxide.LogWarning("Compiler may not be set as executable; chmod +x or 0744/0755 required", Array.Empty <object>());
                }
                if (exception.GetBaseException() != exception)
                {
                    Interface.Oxide.LogException("BaseException: ", exception.GetBaseException());
                }
                Win32Exception win32Exception = exception as Win32Exception;
                if (win32Exception != null)
                {
                    Interface.Oxide.LogError("Win32 NativeErrorCode: {0} ErrorCode: {1} HelpLink: {2}", new object[] { win32Exception.NativeErrorCode, win32Exception.ErrorCode, win32Exception.HelpLink });
                }
            }
            if (this.process == null)
            {
                return(false);
            }
            this.client          = new ObjectStreamClient <CompilerMessage>(this.process.StandardOutput.BaseStream, this.process.StandardInput.BaseStream);
            this.client.Message += new ConnectionMessageEventHandler <CompilerMessage, CompilerMessage>(this.OnMessage);
            this.client.Error   += new StreamExceptionEventHandler(PluginCompiler.OnError);
            this.client.Start();
            return(true);
        }