Decompiled source of EverythingSandboxable v1.0.0

EverythingSandboxable.dll

Decompiled 7 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Sandbox;
using Sandbox.Arm;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("EverythingSandboxable")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("EverythingSandboxable")]
[assembly: AssemblyTitle("EverythingSandboxable")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace whataboutsandboxineverylevel;

[HarmonyPatch(typeof(EnemyIdentifier), "Start")]
public class EnemySandbox
{
	public static void Postfix(ref EnemyIdentifier __instance)
	{
		((Component)__instance).gameObject.AddComponent<SandboxEnemy>();
	}
}
[HarmonyPatch(typeof(UnlockBestiary), "Start")]
public class Benajmin
{
	public static void Postfix(ref UnlockBestiary __instance)
	{
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		if (Plugin.Instance.Enabled.Value && !(((Object)((Component)__instance).gameObject).name != "Main"))
		{
			GameObject val = GameObject.CreatePrimitive((PrimitiveType)3);
			val.transform.position = new Vector3(1.0744f, 19.3423f, 351.7555f);
			val.transform.localScale = new Vector3(2f, 2f, 2f);
			val.GetComponent<Renderer>().material.color = Color.blue;
			val.AddComponent<MeshCollider>();
			val.AddComponent<SandboxProp>();
			val.AddComponent<SandboxSpawnableInstance>();
			val.layer = 8;
			((Component)__instance).gameObject.transform.parent = val.transform;
		}
	}
}
[HarmonyPatch(typeof(SandboxAlterMenu), "Show")]
public class Dupe
{
	public static void Postfix(ref AlterMenuElements ___elementManager, SandboxSpawnableInstance prop)
	{
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		___elementManager.CreateTitle("Custom");
		___elementManager.CreateBoolRow("Clone", false, (Action<bool>)delegate
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			GameObject val2 = Object.Instantiate<GameObject>(((Component)prop).gameObject, ((Component)prop).transform.position, ((Component)prop).transform.rotation);
			SandboxSpawnableInstance component = val2.GetComponent<SandboxSpawnableInstance>();
			if ((Object)(object)component.attachedParticles != (Object)null)
			{
				Object.Destroy((Object)(object)component.attachedParticles);
			}
			if (!prop.frozen)
			{
				prop.Resume();
			}
		}, (string)null);
		bool flag = (Object.op_Implicit((Object)(object)((Component)prop).gameObject.GetComponent<Rigidbody>()) ? true : false);
		___elementManager.CreateBoolRow("Physics", flag, (Action<bool>)delegate
		{
			if ((Object)(object)((Component)prop).gameObject.GetComponent<Rigidbody>() == (Object)null)
			{
				((Component)prop).gameObject.AddComponent<Rigidbody>();
				if ((Object)(object)((Component)prop).GetComponent<Collider>() == (Object)null && (Object)(object)((Component)prop).GetComponentInChildren<Collider>() == (Object)null)
				{
					((Component)prop).gameObject.AddComponent<Collider>();
				}
				Collider collider = prop.collider;
				MeshCollider val = (MeshCollider)(object)((collider is MeshCollider) ? collider : null);
				if (val != null)
				{
					val.convex = true;
				}
			}
			else
			{
				Object.Destroy((Object)(object)((Component)prop).gameObject.GetComponent<Rigidbody>());
			}
		}, (string)null);
		List<Material> children = Resources.FindObjectsOfTypeAll<Material>().ToList();
		Plugin.Instance.Coolio("material", 0, delegate(int thing)
		{
			((Component)prop).gameObject.GetComponent<Renderer>().material = children[thing];
		}, children, ___elementManager);
		List<Mesh> Meshes = Resources.FindObjectsOfTypeAll<Mesh>().ToList();
		Meshes.RemoveAll((Mesh x) => ((Object)x).name.ToLower().Contains("unity"));
		Plugin.Instance.Coolio("mesh", 0, delegate(int thing)
		{
			((Component)prop).gameObject.GetComponent<MeshFilter>().mesh = Meshes[thing];
			((Component)prop).gameObject.GetComponent<MeshFilter>().sharedMesh = Meshes[thing];
		}, Meshes, ___elementManager);
		___elementManager.CreateVector3Row("Position", ((Component)prop).gameObject.transform.position, (Action<Vector3>)delegate(Vector3 pos)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			((Component)prop).gameObject.transform.position = pos;
		}, (string)null);
	}
}
[HarmonyPatch(typeof(SandboxArm), "Update")]
public class customDistance
{
	public static bool Prefix(ref SandboxArm __instance, ref ISandboxArmMode ___currentMode)
	{
		//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_020c: Unknown result type (might be due to invalid IL or missing references)
		if (Plugin.Instance.Distance.Value == 75f)
		{
			return true;
		}
		if (Time.timeScale == 0f)
		{
			return false;
		}
		if ((Object)(object)__instance.menu != (Object)null && MonoSingleton<InputManager>.Instance.InputSource.Fire2.WasPerformedThisFrame && (___currentMode == null || ___currentMode.CanOpenMenu))
		{
			((Component)__instance.menu).gameObject.SetActive(true);
			MonoSingleton<OptionsManager>.Instance.Freeze();
			return false;
		}
		if ((Object)(object)__instance.menu == (Object)null || !((Component)__instance.menu).gameObject.activeSelf)
		{
			if (!MonoSingleton<InputManager>.Instance.PerformingCheatMenuCombo() && MonoSingleton<InputManager>.Instance.InputSource.Fire1.WasPerformedThisFrame)
			{
				ISandboxArmMode val = ___currentMode;
				if (val != null)
				{
					val.OnPrimaryDown();
				}
			}
			if (MonoSingleton<InputManager>.Instance.InputSource.Fire1.WasCanceledThisFrame)
			{
				ISandboxArmMode val2 = ___currentMode;
				if (val2 != null)
				{
					val2.OnPrimaryUp();
				}
			}
			if (!MonoSingleton<InputManager>.Instance.PerformingCheatMenuCombo() && MonoSingleton<InputManager>.Instance.InputSource.Fire2.WasPerformedThisFrame)
			{
				ISandboxArmMode val3 = ___currentMode;
				if (val3 != null)
				{
					val3.OnSecondaryDown();
				}
			}
			if (MonoSingleton<InputManager>.Instance.InputSource.Fire2.WasCanceledThisFrame)
			{
				ISandboxArmMode val4 = ___currentMode;
				if (val4 != null)
				{
					val4.OnSecondaryUp();
				}
			}
		}
		if (___currentMode != null && ___currentMode.Raycast)
		{
			__instance.hitSomething = Physics.Raycast(((Component)MonoSingleton<CameraController>.Instance).transform.position, ((Component)MonoSingleton<CameraController>.Instance).transform.forward, ref __instance.hit, Plugin.Instance.Distance.Value, LayerMask.op_Implicit(__instance.raycastLayers));
		}
		ISandboxArmMode val5 = ___currentMode;
		if (val5 == null)
		{
			return false;
		}
		val5.Update();
		return false;
	}
}
[BepInPlugin("somethingsomethingsomething", "CoolName", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	public static Plugin Instance;

	public Harmony Harmony;

	public ConfigEntry<float> Distance;

	public ConfigEntry<bool> Enabled;

	public ConfigEntry<KeyCode> KeyToApply;

	public List<Material> materialsList;

	public void Coolio<T>(string name, int initialState, Action<int> callback, List<T> items, object elementManager, string tooltipMessage = null)
	{
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Expected O, but got Unknown
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Expected O, but got Unknown
		Type type = elementManager.GetType();
		FieldInfo field = type.GetField("createdRows", BindingFlags.Instance | BindingFlags.NonPublic);
		FieldInfo field2 = type.GetField("CreateTooltip", BindingFlags.Instance | BindingFlags.NonPublic);
		FieldInfo field3 = type.GetField("dropdownRowTemplate", BindingFlags.Instance | BindingFlags.NonPublic);
		FieldInfo field4 = type.GetField("container", BindingFlags.Instance | BindingFlags.NonPublic);
		MethodInfo method = type.GetMethod("CreateTooltip", BindingFlags.Instance | BindingFlags.NonPublic);
		GameObject val = (GameObject)field3.GetValue(elementManager);
		Transform val2 = (Transform)field4.GetValue(elementManager);
		List<int> list = (List<int>)field.GetValue(elementManager);
		GameObject val3 = Object.Instantiate<GameObject>(val, val2, false);
		val3.SetActive(true);
		val3.GetComponentInChildren<TMP_Text>().text = name;
		Dropdown componentInChildren = val3.GetComponentInChildren<Dropdown>();
		componentInChildren.ClearOptions();
		List<string> list2 = new List<string>();
		foreach (T item in items)
		{
			list2.Add(item.ToString());
		}
		componentInChildren.AddOptions(list2);
		componentInChildren.SetValueWithoutNotify(initialState);
		((Selectable)componentInChildren).interactable = callback != null;
		if (callback != null)
		{
			((UnityEvent<int>)(object)componentInChildren.onValueChanged).AddListener((UnityAction<int>)delegate(int value)
			{
				callback(value);
			});
		}
		if (tooltipMessage != null)
		{
			object[] parameters = new object[2] { val3, tooltipMessage };
			method.Invoke(elementManager, parameters);
		}
		list.Add(((Object)val3).GetInstanceID());
		field.SetValue(elementManager, list);
	}

	private void Awake()
	{
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Expected O, but got Unknown
		materialsList = Resources.FindObjectsOfTypeAll<Material>().ToList();
		Distance = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "Arm Distance", 75f, "how far you can reach with the arm");
		Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Enabled", false, (ConfigDescription)null);
		KeyToApply = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Settings", "Make Everything sandbox prop key", (KeyCode)57, "when this key is pressed it will turn everything into a sandboxProp");
		Instance = this;
		Harmony = new Harmony("somethingsomethingsomething");
		Harmony.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin somethingsomethingsomething is loaded!");
		SceneManager.sceneLoaded += SceneManager_sceneLoaded;
	}

	private void Update()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		if (!Input.GetKeyDown(KeyToApply.Value))
		{
			return;
		}
		GameObject[] array = Resources.FindObjectsOfTypeAll<GameObject>();
		GameObject[] array2 = array;
		foreach (GameObject val in array2)
		{
			if (!(val.scene != SceneManager.GetActiveScene()) && !Object.op_Implicit((Object)(object)val.GetComponent<SandboxProp>()))
			{
				PlaceRightSandbox(val);
			}
		}
	}

	private void PlaceRightSandbox(GameObject theObject)
	{
		if ((Object)(object)theObject == (Object)null || theObject.tag == "Player" || IsDescendantOf(((Component)MonoSingleton<NewMovement>.Instance).gameObject.transform, theObject.transform) || (Object)(object)theObject.GetComponent<SandboxProp>() != (Object)null || (Object)(object)theObject.GetComponent<SandboxPropPart>() != (Object)null || (Object)(object)theObject.GetComponent<SandboxSpawnableInstance>() != (Object)null || (Object)(object)theObject.GetComponent<EnemyIdentifier>() != (Object)null || (Object)(object)theObject.GetComponentInParent<EnemyIdentifier>() != (Object)null)
		{
			return;
		}
		Collider component = theObject.GetComponent<Collider>();
		if (!((Object)(object)component != (Object)null))
		{
			return;
		}
		Renderer component2 = theObject.GetComponent<Renderer>();
		if ((Object)(object)component2 != (Object)null)
		{
			if ((Object)(object)theObject.GetComponent<SandboxProp>() == (Object)null)
			{
				theObject.AddComponent<SandboxSpawnableInstance>();
				theObject.AddComponent<SandboxProp>();
			}
			Collider componentInChildren = theObject.GetComponentInChildren<Collider>();
			if ((Object)(object)componentInChildren != (Object)null)
			{
				SandboxPropPart val = ((Component)componentInChildren).gameObject.AddComponent<SandboxPropPart>();
				val.parent = theObject.AddComponent<SandboxSpawnableInstance>();
			}
			return;
		}
		if ((Object)(object)theObject.transform.parent == (Object)null)
		{
			theObject.AddComponent<SandboxProp>();
			return;
		}
		Renderer componentInParent = theObject.GetComponentInParent<Renderer>();
		if ((Object)(object)componentInParent != (Object)null)
		{
			SandboxPropPart val2 = theObject.AddComponent<SandboxPropPart>();
			val2.parent = ((Component)theObject.transform.parent).gameObject.AddComponent<SandboxSpawnableInstance>();
			return;
		}
		Renderer componentInChildren2 = ((Component)theObject.transform.parent).gameObject.GetComponentInChildren<Renderer>();
		if ((Object)(object)componentInChildren2 != (Object)null)
		{
			SandboxPropPart val3 = theObject.AddComponent<SandboxPropPart>();
			val3.parent = ((Component)componentInChildren2).gameObject.AddComponent<SandboxSpawnableInstance>();
			return;
		}
		Renderer[] componentsInChildren = ((Component)theObject.transform).GetComponentsInChildren<Renderer>();
		if (componentsInChildren.Length != 0)
		{
			SandboxSpawnableInstance parent = theObject.AddComponent<SandboxSpawnableInstance>();
			Renderer[] array = componentsInChildren;
			foreach (Renderer val4 in array)
			{
				((Component)val4).gameObject.AddComponent<SandboxPropPart>().parent = parent;
			}
		}
	}

	private void SceneManager_sceneLoaded(Scene arg0, LoadSceneMode arg1)
	{
		if (Enabled.Value)
		{
			if ((Object)(object)MapInfo.Instance != (Object)null)
			{
				((MapInfoBase)MapInfo.Instance).sandboxTools = true;
			}
			else if ((Object)(object)StockMapInfo.Instance != (Object)null)
			{
				((MapInfoBase)StockMapInfo.Instance).sandboxTools = true;
			}
		}
	}

	private bool IsDescendantOf(Transform parent, Transform child)
	{
		if ((Object)(object)child == (Object)null)
		{
			return false;
		}
		Transform parent2 = child.parent;
		while ((Object)(object)parent2 != (Object)null)
		{
			if ((Object)(object)parent2 == (Object)(object)parent)
			{
				return true;
			}
			parent2 = parent2.parent;
		}
		return false;
	}
}