using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using UnityEngine; namespace Oxide.Plugins { [Info("DisableSandbox", "Vice", "1.0.0")] public class DisableSandbox : RustPlugin { void Init() { if (true)//CSharpExtension.SandboxEnabled) { Debug.Log("Sandbox is enabled, disabling it via reflection and creating oxide.disable-sandbox in the game's root directory."); // grab SandboxEnabled field and turn it off var field = typeof(CSharpExtension).GetField("k__BackingField", BindingFlags.Static | BindingFlags.NonPublic); field?.SetValue(null, false); MethodInfo writeAllText = GetMethod("mscorlib", "File", "WriteAllText", new Type[] { typeof(string), typeof(string) }); // create sandbox toggle file writeAllText.Invoke(null, new object[] { "./RustDedicated_Data/Managed/oxide.disable-sandbox", "" }); if (!CSharpExtension.SandboxEnabled) Debug.Log("Sandbox sucessfully disabled."); else Debug.Log("Sandbox was not disabled."); } Debug.Log("Sandbox is enabled."); } private MethodInfo GetMethod(string definingLib, string declaringType, string methodName, Type[] args) { // box assembly reference to avoid tripping the sandbox Box assemblies = new Box(AppDomain.CurrentDomain.GetAssemblies()); Box target = null; for (var index = 0; index < assemblies.Value.Length; index++) { // access property safely string name = AccessProperty(assemblies.Value[index], "FullName"); if (name.StartsWith(definingLib)) target = new Box(assemblies.Value[index]); } // grab typeof(declaringType) from definingLib without tripping the sandbox TypeInfo fileType = AccessProperty>(target.Value, "DefinedTypes").FirstOrDefault(x => x.Name == declaringType); var writeAllText = fileType.GetMethod(methodName, args); return writeAllText; } private T AccessProperty(object obj, string property) { var info = obj.GetType().GetProperty(property, BindingFlags.NonPublic| BindingFlags.Public | BindingFlags.Instance); return (T) info?.GetValue(obj); } private class Box { public readonly T Value; public Box(T Value) { this.Value = Value; } } } }