private static void UpdateCheck() { try { string str = Path.Combine(Interface.Oxide.RootDirectory, PluginCompiler.FileName); HttpWebResponse response = (HttpWebResponse)((HttpWebRequest)WebRequest.Create(string.Concat("https://umod-01.nyc3.digitaloceanspaces.com/", PluginCompiler.FileName))).GetResponse(); int statusCode = (int)response.StatusCode; if (statusCode != 200) { Interface.Oxide.LogWarning(string.Format("Status code from download location was not okay (code {0})", statusCode), Array.Empty <object>()); } string str1 = response.Headers[HttpResponseHeader.ETag].Trim(new char[] { '\"' }); string str2 = (File.Exists(str) ? PluginCompiler.GetHash(str, PluginCompiler.Algorithms.MD5) : "0"); Interface.Oxide.LogInfo(string.Concat("Latest compiler MD5: ", str1), Array.Empty <object>()); Interface.Oxide.LogInfo(string.Concat("Local compiler MD5: ", str2), Array.Empty <object>()); if (str1 != str2) { Interface.Oxide.LogInfo("Compiler hashes did not match, downloading latest", Array.Empty <object>()); PluginCompiler.DownloadCompiler(response, str1); } } catch (Exception exception1) { Exception exception = exception1; Interface.Oxide.LogError(string.Concat("Couldn't check for update to ", PluginCompiler.FileName), Array.Empty <object>()); Interface.Oxide.LogError(exception.Message, Array.Empty <object>()); } }
public CSharpPluginLoader(CSharpExtension extension) { Instance = this; CSharpPluginLoader.extension = extension; PluginCompiler.CheckCompilerBinary(); compiler = new PluginCompiler(); }
public void Compile(Action <bool> callback) { CheckLastModificationTime(); if (LastCompiledAt == LastModifiedAt) { //Interface.GetMod().LogInfo("Plugin is already compiled: {0}", Name); callback(true); return; } if (compiler != null) { Interface.GetMod().LogInfo("Plugin compilation is already in progress: {0}", ScriptName); return; } compiler = new PluginCompiler(this); compiler.Compile(compiled => { if (compiled) { Interface.GetMod().LogInfo("{0} plugin was compiled successfully in {1}ms", ScriptName, Math.Round(compiler.Duration * 1000f)); } else { Interface.GetMod().LogInfo("{0} plugin failed to compile! Exit code: {1}", ScriptName, compiler.ExitCode); Interface.GetMod().LogInfo(compiler.StdOutput.ToString()); if (compiler.ErrOutput.Length > 0) { Interface.GetMod().LogInfo(compiler.ErrOutput.ToString()); } } compiler = null; callback(compiled); }); }
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); } } } }
private static void DownloadCompiler(WebResponse response, string remoteHash) { try { Interface.Oxide.LogInfo(string.Concat("Downloading ", PluginCompiler.FileName, " for .cs (C#) plugin compilation"), Array.Empty <object>()); Stream responseStream = response.GetResponseStream(); FileStream fileStream = new FileStream(PluginCompiler.FileName, FileMode.Create, FileAccess.Write, FileShare.None); int num = 10000; byte[] numArray = new byte[num]; while (true) { int num1 = responseStream.Read(numArray, 0, num); if (num1 == -1 || num1 == 0) { break; } fileStream.Write(numArray, 0, num1); } fileStream.Flush(); fileStream.Close(); responseStream.Close(); response.Close(); if (PluginCompiler.downloadRetries >= 3) { Interface.Oxide.LogInfo(string.Concat("Couldn't download ", PluginCompiler.FileName, "! Please download manually from: https://github.com/OxideMod/Compiler/releases/download/latest/", PluginCompiler.FileName), Array.Empty <object>()); } else if (remoteHash == (File.Exists(PluginCompiler.BinaryPath) ? PluginCompiler.GetHash(PluginCompiler.BinaryPath, PluginCompiler.Algorithms.MD5) : "0")) { Interface.Oxide.LogInfo(string.Concat("Download of ", PluginCompiler.FileName, " completed successfully"), Array.Empty <object>()); } else { Interface.Oxide.LogInfo(string.Concat("Local hash did not match remote hash for ", PluginCompiler.FileName, ", attempting download again"), Array.Empty <object>()); PluginCompiler.UpdateCheck(); PluginCompiler.downloadRetries++; } } catch (Exception exception1) { Exception exception = exception1; Interface.Oxide.LogError(string.Concat("Couldn't download ", PluginCompiler.FileName, "! Please download manually from: https://github.com/OxideMod/Compiler/releases/download/latest/", PluginCompiler.FileName), Array.Empty <object>()); Interface.Oxide.LogError(exception.Message, Array.Empty <object>()); } }
public void OnCompilationStarted(PluginCompiler compiler) { //Interface.Oxide.LogDebug("Compiling plugin: {0}", Name); LastCompiledAt = LastModifiedAt; }
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); }
public static void CheckCompilerBinary() { PluginCompiler.BinaryPath = null; string rootDirectory = Interface.Oxide.RootDirectory; string str = Path.Combine(rootDirectory, PluginCompiler.FileName); if (File.Exists(str)) { PluginCompiler.BinaryPath = str; return; } switch (Environment.OSVersion.Platform) { case PlatformID.Win32S: case PlatformID.Win32Windows: case PlatformID.Win32NT: { PluginCompiler.FileName = "Compiler.exe"; str = Path.Combine(rootDirectory, PluginCompiler.FileName); PluginCompiler.UpdateCheck(); PluginCompiler.BinaryPath = str; return; } case PlatformID.WinCE: case PlatformID.Xbox: { PluginCompiler.BinaryPath = str; return; } case PlatformID.Unix: case PlatformID.MacOSX: { PluginCompiler.FileName = string.Concat("Compiler.", (IntPtr.Size != 8 ? "x86" : "x86_x64")); str = Path.Combine(rootDirectory, PluginCompiler.FileName); PluginCompiler.UpdateCheck(); try { if (Syscall.access(str, AccessModes.X_OK) == 0) { PluginCompiler.BinaryPath = str; return; } } catch (Exception exception1) { Exception exception = exception1; Interface.Oxide.LogError(string.Concat("Unable to check ", PluginCompiler.FileName, " for executable permission"), Array.Empty <object>()); Interface.Oxide.LogError(exception.Message, Array.Empty <object>()); Interface.Oxide.LogError(exception.StackTrace, Array.Empty <object>()); } try { Syscall.chmod(str, FilePermissions.S_IRWXU); PluginCompiler.BinaryPath = str; return; } catch (Exception exception3) { Exception exception2 = exception3; Interface.Oxide.LogError(string.Concat("Could not set ", PluginCompiler.FileName, " as executable, please set manually"), Array.Empty <object>()); Interface.Oxide.LogError(exception2.Message, Array.Empty <object>()); Interface.Oxide.LogError(exception2.StackTrace, Array.Empty <object>()); PluginCompiler.BinaryPath = str; return; } break; } default: { PluginCompiler.BinaryPath = str; return; } } }