private void Awake() { RealtimeSinceStartup = Time.realtimeSinceStartup; oxideMod = Interface.Oxide; EventInfo eventInfo = typeof(Application).GetEvent("logMessageReceived"); if (eventInfo == null) { // Unity 4 FieldInfo logCallbackField = typeof(Application).GetField("s_LogCallback", BindingFlags.Static | BindingFlags.NonPublic); Application.LogCallback logCallback = logCallbackField?.GetValue(null) as Application.LogCallback; if (logCallback == null) { Interface.Oxide.LogWarning("No Unity application log callback is registered"); } #pragma warning disable 0618 Application.RegisterLogCallback((message, stack_trace, type) => { logCallback?.Invoke(message, stack_trace, type); LogMessageReceived(message, stack_trace, type); }); } else { // Unity 5 Delegate handleException = Delegate.CreateDelegate(eventInfo.EventHandlerType, this, "LogMessageReceived"); eventInfo.GetAddMethod().Invoke(null, new object[] { handleException }); } }
void Awake() { oxideMod = Interface.Oxide; var eventInfo = typeof(Application).GetEvent("logMessageReceived"); if (eventInfo == null) { // Unity 4 var logCallbackField = typeof(Application).GetField("s_LogCallback", BindingFlags.Static | BindingFlags.NonPublic); var logCallback = logCallbackField?.GetValue(null) as Application.LogCallback; if (logCallback == null) Interface.Oxide.LogWarning("No Unity application log callback is registered"); #pragma warning disable 0618 Application.RegisterLogCallback((message, stack_trace, type) => { logCallback?.Invoke(message, stack_trace, type); LogMessageReceived(message, stack_trace, type); }); } else { // Unity 5 var handleException = Delegate.CreateDelegate(eventInfo.EventHandlerType, this, "LogMessageReceived"); eventInfo.GetAddMethod().Invoke(null, new object[] { handleException }); } }
private void Awake() { this.oxideMod = Interface.get_Oxide(); EventInfo @event = typeof(Application).GetEvent("logMessageReceived"); if (@event != null) { Delegate @delegate = Delegate.CreateDelegate(@event.EventHandlerType, this, "LogMessageReceived"); @event.GetAddMethod().Invoke(null, new object[] { @delegate }); return; } FieldInfo field = typeof(Application).GetField("s_LogCallback", BindingFlags.Static | BindingFlags.NonPublic); Application.LogCallback logCallback1 = (field != null ? field.GetValue(null) : null) as Application.LogCallback; if (logCallback1 == null) { Interface.get_Oxide().LogWarning("No Unity application log callback is registered", new object[0]); } Application.RegisterLogCallback((string message, string stack_trace, LogType type) => { Application.LogCallback logCallback = logCallback1; if (logCallback != null) { logCallback(message, stack_trace, type); } else { } this.LogMessageReceived(message, stack_trace, type); }); }
public void Initalize() { int?nullable; int?nullable1; int?nullable2; if (!this.config.Enabled || this.listener != null || this.server != null) { return; } if (string.IsNullOrEmpty(this.config.Password)) { Interface.Oxide.LogWarning("[Rcon] Remote console password is not set, disabling", Array.Empty <object>()); return; } try { this.server = new WebSocketServer(this.config.Port) { WaitTime = TimeSpan.FromSeconds(5), ReuseAddress = true }; this.server.AddWebSocketService <Oxide.Core.RemoteConsole.RemoteConsole.RconListener>(string.Concat("/", this.config.Password), () => { Oxide.Core.RemoteConsole.RemoteConsole.RconListener rconListener = new Oxide.Core.RemoteConsole.RemoteConsole.RconListener(this); Oxide.Core.RemoteConsole.RemoteConsole.RconListener rconListener1 = rconListener; this.listener = rconListener; return(rconListener1); }); this.server.Start(); Interface.Oxide.LogInfo(string.Format("[Rcon] Server started successfully on port {0}", this.server.Port), Array.Empty <object>()); } catch (Exception exception1) { Exception exception = exception1; OxideMod oxide = Interface.Oxide; WebSocketServer webSocketServer = this.server; if (webSocketServer != null) { nullable1 = new int?(webSocketServer.Port); } else { nullable = null; nullable1 = nullable; } oxide.LogException(string.Format("[Rcon] Failed to start server on port {0}", nullable1), exception); WebSocketServer webSocketServer1 = this.server; if (webSocketServer1 != null) { nullable2 = new int?(webSocketServer1.Port); } else { nullable = null; nullable2 = nullable; } RemoteLogger.Exception(string.Format("Failed to start RCON server on port {0}", nullable2), exception); } }
protected void Puts(string format, params object[] args) { OxideMod oxide = Interface.Oxide; object[] title = new object[] { base.Title, null }; title[1] = (args.Length != 0 ? string.Format(format, args) : format); oxide.LogInfo("[{0}] {1}", title); }
/// <summary> /// Initializes Oxide /// </summary> public static void Initialize() { // Create if not already created if (oxide == null) { oxide = new OxideMod(); oxide.Load(); } }
void Awake() { oxideMod = Interface.GetMod(); }
static Timer() { Timer.Lock = new object(); Timer.Oxide = Interface.Oxide; }
private void PatchAssembly(Action <byte[]> callback) { Action action1 = null; if (this.isPatching) { Interface.Oxide.LogWarning("Already patching plugin assembly: {0} (ignoring)", new object[] { this.PluginNames.ToSentence <string>() }); return; } float now = Interface.Oxide.Now; this.isPatching = true; ThreadPool.QueueUserWorkItem((object _) => { AssemblyDefinition assemblyDefinition; try { using (MemoryStream memoryStream = new MemoryStream(this.RawAssembly)) { assemblyDefinition = AssemblyDefinition.ReadAssembly(memoryStream); } ConstructorInfo constructor = typeof(UnauthorizedAccessException).GetConstructor(new Type[] { typeof(string) }); MethodReference methodReference1 = assemblyDefinition.MainModule.Import(constructor); Action <TypeDefinition> methods = null; methods = (TypeDefinition type) => { string fullName; string str; foreach (MethodDefinition method in type.Methods) { bool flag = false; if (method.Body != null) { bool flag1 = false; foreach (VariableDefinition variable in method.Body.Variables) { if (!CompiledAssembly.IsNamespaceBlacklisted(variable.VariableType.FullName)) { continue; } Mono.Cecil.Cil.MethodBody methodBody = new Mono.Cecil.Cil.MethodBody(method); methodBody.Instructions.Add(Instruction.Create(OpCodes.Ldstr, string.Concat("System access is restricted, you are not allowed to use ", variable.VariableType.FullName))); methodBody.Instructions.Add(Instruction.Create(OpCodes.Newobj, methodReference1)); methodBody.Instructions.Add(Instruction.Create(OpCodes.Throw)); method.Body = methodBody; flag1 = true; break; } if (flag1) { continue; } Collection <Instruction> instructions = method.Body.Instructions; ILProcessor lProcessor = method.Body.GetILProcessor(); Instruction instruction = instructions.First <Instruction>(); for (int i = 0; i < instructions.Count && !flag; i++) { Instruction item = instructions[i]; if (item.OpCode == OpCodes.Ldtoken) { IMetadataTokenProvider operand = item.Operand as IMetadataTokenProvider; str = (operand != null ? operand.ToString() : null); string str1 = str; if (CompiledAssembly.IsNamespaceBlacklisted(str1)) { lProcessor.InsertBefore(instruction, Instruction.Create(OpCodes.Ldstr, string.Concat("System access is restricted, you are not allowed to use ", str1))); lProcessor.InsertBefore(instruction, Instruction.Create(OpCodes.Newobj, methodReference1)); lProcessor.InsertBefore(instruction, Instruction.Create(OpCodes.Throw)); flag = true; } } else if (item.OpCode == OpCodes.Call || item.OpCode == OpCodes.Calli || item.OpCode == OpCodes.Callvirt || item.OpCode == OpCodes.Ldftn) { MethodReference methodReference = item.Operand as MethodReference; string str2 = (methodReference != null ? methodReference.DeclaringType.FullName : null); if (str2 == "System.Type" && methodReference.Name == "GetType" || CompiledAssembly.IsNamespaceBlacklisted(str2)) { lProcessor.InsertBefore(instruction, Instruction.Create(OpCodes.Ldstr, string.Concat("System access is restricted, you are not allowed to use ", str2))); lProcessor.InsertBefore(instruction, Instruction.Create(OpCodes.Newobj, methodReference1)); lProcessor.InsertBefore(instruction, Instruction.Create(OpCodes.Throw)); flag = true; } } else if (item.OpCode == OpCodes.Ldfld) { FieldReference fieldReference = item.Operand as FieldReference; fullName = (fieldReference != null ? fieldReference.FieldType.FullName : null); string str3 = fullName; if (CompiledAssembly.IsNamespaceBlacklisted(str3)) { lProcessor.InsertBefore(instruction, Instruction.Create(OpCodes.Ldstr, string.Concat("System access is restricted, you are not allowed to use ", str3))); lProcessor.InsertBefore(instruction, Instruction.Create(OpCodes.Newobj, methodReference1)); lProcessor.InsertBefore(instruction, Instruction.Create(OpCodes.Throw)); flag = true; } } } } else if (method.HasPInvokeInfo) { MethodDefinition attributes = method; attributes.Attributes = attributes.Attributes & (Mono.Cecil.MethodAttributes.MemberAccessMask | Mono.Cecil.MethodAttributes.Private | Mono.Cecil.MethodAttributes.FamANDAssem | Mono.Cecil.MethodAttributes.Assembly | Mono.Cecil.MethodAttributes.Family | Mono.Cecil.MethodAttributes.FamORAssem | Mono.Cecil.MethodAttributes.Public | Mono.Cecil.MethodAttributes.Static | Mono.Cecil.MethodAttributes.Final | Mono.Cecil.MethodAttributes.Virtual | Mono.Cecil.MethodAttributes.HideBySig | Mono.Cecil.MethodAttributes.VtableLayoutMask | Mono.Cecil.MethodAttributes.NewSlot | Mono.Cecil.MethodAttributes.CheckAccessOnOverride | Mono.Cecil.MethodAttributes.Abstract | Mono.Cecil.MethodAttributes.SpecialName | Mono.Cecil.MethodAttributes.UnmanagedExport | Mono.Cecil.MethodAttributes.RTSpecialName | Mono.Cecil.MethodAttributes.HasSecurity | Mono.Cecil.MethodAttributes.RequireSecObject); Mono.Cecil.Cil.MethodBody methodBody1 = new Mono.Cecil.Cil.MethodBody(method); methodBody1.Instructions.Add(Instruction.Create(OpCodes.Ldstr, "PInvoke access is restricted, you are not allowed to use PInvoke")); methodBody1.Instructions.Add(Instruction.Create(OpCodes.Newobj, methodReference1)); methodBody1.Instructions.Add(Instruction.Create(OpCodes.Throw)); method.Body = methodBody1; } if (!flag) { continue; } Mono.Cecil.Cil.MethodBody body = method.Body; if (body != null) { body.OptimizeMacros(); } else { } } foreach (TypeDefinition nestedType in type.NestedTypes) { methods(nestedType); } }; foreach (TypeDefinition typeDefinition in assemblyDefinition.MainModule.Types) { methods(typeDefinition); if (this.IsCompilerGenerated(typeDefinition)) { continue; } if (typeDefinition.Namespace != "Oxide.Plugins") { if (!(typeDefinition.FullName != "<Module>") || this.PluginNames.Any <string>((string plugin) => typeDefinition.FullName.StartsWith(string.Concat("Oxide.Plugins.", plugin)))) { continue; } Interface.Oxide.LogWarning(((int)this.PluginNames.Length == 1 ? string.Concat(this.PluginNames[0], " has polluted the global namespace by defining ", typeDefinition.FullName) : string.Concat("A plugin has polluted the global namespace by defining ", typeDefinition.FullName)), Array.Empty <object>()); } else if (!this.PluginNames.Contains <string>(typeDefinition.Name)) { Interface.Oxide.LogWarning(((int)this.PluginNames.Length == 1 ? string.Concat(this.PluginNames[0], " has polluted the global namespace by defining ", typeDefinition.Name) : string.Concat("A plugin has polluted the global namespace by defining ", typeDefinition.Name)), Array.Empty <object>()); } else { Collection <MethodDefinition> methodDefinitions = typeDefinition.Methods; Func <MethodDefinition, bool> u003cu003e9_204 = CompiledAssembly.< > c.< > 9__20_4; if (u003cu003e9_204 == null) { u003cu003e9_204 = (MethodDefinition m) => { if (m.IsStatic || !m.IsConstructor || m.HasParameters) { return(false); } return(!m.IsPublic); }; CompiledAssembly.< > c.< > 9__20_4 = u003cu003e9_204; } if (methodDefinitions.FirstOrDefault <MethodDefinition>(u003cu003e9_204) == null) { DirectCallMethod directCallMethod = new DirectCallMethod(assemblyDefinition.MainModule, typeDefinition); } else { CompilablePlugin compilablePlugin = this.CompilablePlugins.SingleOrDefault <CompilablePlugin>((CompilablePlugin p) => p.Name == typeDefinition.Name); if (compilablePlugin == null) { continue; } compilablePlugin.CompilerErrors = "Primary constructor in main class must be public"; } } } foreach (TypeDefinition typeDefinition1 in assemblyDefinition.MainModule.Types) { if (typeDefinition1.Namespace != "Oxide.Plugins" || !this.PluginNames.Contains <string>(typeDefinition1.Name)) { continue; } Collection <MethodDefinition> methods1 = typeDefinition1.Methods; Func <MethodDefinition, bool> u003cu003e9_206 = CompiledAssembly.< > c.< > 9__20_6; if (u003cu003e9_206 == null) { u003cu003e9_206 = (MethodDefinition m) => { if (m.IsStatic || m.HasGenericParameters || m.ReturnType.IsGenericParameter || m.IsSetter) { return(false); } return(!m.IsGetter); }; CompiledAssembly.< > c.< > 9__20_6 = u003cu003e9_206; } foreach (MethodDefinition methodDefinition in methods1.Where <MethodDefinition>(u003cu003e9_206)) { foreach (ParameterDefinition parameter in methodDefinition.Parameters) { foreach (CustomAttribute customAttribute in parameter.CustomAttributes) { } } } } using (MemoryStream memoryStream1 = new MemoryStream()) { assemblyDefinition.Write(memoryStream1); this.PatchedAssembly = memoryStream1.ToArray(); } OxideMod oxide = Interface.Oxide; Action u003cu003e9_2 = action1; if (u003cu003e9_2 == null) { Action u003cu003e4_this = () => { this.isPatching = false; callback(this.PatchedAssembly); }; Action action = u003cu003e4_this; action1 = u003cu003e4_this; u003cu003e9_2 = action; } oxide.NextTick(u003cu003e9_2); } catch (Exception exception1) { Exception exception = exception1; Interface.Oxide.NextTick(() => { this.isPatching = false; Interface.Oxide.LogException(string.Concat("Exception while patching: ", this.PluginNames.ToSentence <string>()), exception); callback(null); }); } }); }
private void OnRemovedFromManager(Plugin sender, PluginManager manager) { Event.Callback <Plugin, PluginManager> callback; bool state; object name; List <string> strs = new List <string>(); foreach (KeyValuePair <string, Connection> _connection in this._connections) { if ((object)_connection.Value.get_Plugin() != (object)sender) { continue; } DbConnection con = _connection.Value.get_Con(); if (con != null) { state = con.State != ConnectionState.Closed; } else { state = true; } if (state) { OxideMod oxide = Interface.get_Oxide(); object[] connectionString = new object[] { _connection.Value.get_ConnectionString(), null }; Plugin plugin = _connection.Value.get_Plugin(); if (plugin != null) { name = plugin.get_Name(); } else { name = null; } if (name == null) { name = "null"; } connectionString[1] = name; oxide.LogWarning("Unclosed sqlite connection ({0}), by plugin '{1}', closing...", connectionString); } DbConnection dbConnection = _connection.Value.get_Con(); if (dbConnection != null) { dbConnection.Close(); } else { } _connection.Value.set_Plugin(null); strs.Add(_connection.Key); } foreach (string str in strs) { this._connections.Remove(str); } if (this._pluginRemovedFromManager.TryGetValue(sender, out callback)) { callback.Remove(); this._pluginRemovedFromManager.Remove(sender); } }
public Connection OpenDb(string conStr, Plugin plugin, bool persistent = false) { Dictionary <string, Connection> strs; Connection connection; object name; object connectionString; object obj; Dictionary <string, Dictionary <string, Connection> > strs1 = this._connections; if (plugin != null) { name = plugin.get_Name(); } else { name = null; } if (name == null) { name = "null"; } if (!strs1.TryGetValue((string)name, out strs)) { Dictionary <string, Dictionary <string, Connection> > strs2 = this._connections; if (plugin != null) { obj = plugin.get_Name(); } else { obj = null; } if (obj == null) { obj = "null"; } Dictionary <string, Connection> strs3 = new Dictionary <string, Connection>(); strs = strs3; strs2[(string)obj] = strs3; } if (!strs.TryGetValue(conStr, out connection)) { Connection connection1 = new Connection(conStr, persistent); connection1.set_Plugin(plugin); connection1.set_Con(new MySqlConnection(conStr)); connection = connection1; strs[conStr] = connection; } else { OxideMod oxide = Interface.get_Oxide(); object[] objArray = new object[1]; DbConnection con = connection.get_Con(); if (con != null) { connectionString = con.ConnectionString; } else { connectionString = null; } objArray[0] = connectionString; oxide.LogWarning("Already open connection ({0}), using existing instead...", objArray); } if (plugin != null && !this._pluginRemovedFromManager.ContainsKey(plugin)) { this._pluginRemovedFromManager[plugin] = plugin.OnRemovedFromManager.Add(new Action <Plugin, PluginManager>(this.OnRemovedFromManager)); } return(connection); }
private void OnRemovedFromManager(Plugin sender, PluginManager manager) { Dictionary <string, Connection> strs; Event.Callback <Plugin, PluginManager> callback; bool state; object connectionString; object name; if (this._connections.TryGetValue(sender.get_Name(), out strs)) { foreach (KeyValuePair <string, Connection> keyValuePair in strs) { if ((object)keyValuePair.Value.get_Plugin() != (object)sender) { continue; } DbConnection con = keyValuePair.Value.get_Con(); if (con != null) { state = con.State != ConnectionState.Closed; } else { state = true; } if (state) { OxideMod oxide = Interface.get_Oxide(); object[] objArray = new object[2]; DbConnection dbConnection = keyValuePair.Value.get_Con(); if (dbConnection != null) { connectionString = dbConnection.ConnectionString; } else { connectionString = null; } objArray[0] = connectionString; Plugin plugin = keyValuePair.Value.get_Plugin(); if (plugin != null) { name = plugin.get_Name(); } else { name = null; } if (name == null) { name = "null"; } objArray[1] = name; oxide.LogWarning("Unclosed mysql connection ({0}), by plugin '{1}', closing...", objArray); } DbConnection con1 = keyValuePair.Value.get_Con(); if (con1 != null) { con1.Close(); } else { } keyValuePair.Value.set_Plugin(null); } this._connections.Remove(sender.get_Name()); } if (this._pluginRemovedFromManager.TryGetValue(sender, out callback)) { callback.Remove(); this._pluginRemovedFromManager.Remove(sender); } }