Decompiled source of UltraSandbox v0.1.1

doomahreal.ultrakill.UltraSandbox/UtraSandbox.dll

Decompiled 10 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using Configgy;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Sandbox;
using Sandbox.Arm;
using ULTRAKILL.Cheats;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("UtraSandbox")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("UtraSandbox")]
[assembly: AssemblyTitle("UtraSandbox")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
public static class ExperimentalArmRotationPatch
{
	[HarmonyPatch(typeof(MoveMode), "Update")]
	public class MoveMode_Update_Patch
	{
		private static void Postfix(MoveMode __instance)
		{
			ExperimentalArmRotation.Enabled = true;
		}
	}
}
namespace Assetbundleloader
{
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "UtraSandbox";

		public const string PLUGIN_NAME = "UtraSandbox";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace Secondultrakillmod
{
	[BepInPlugin("doomahreal.ultrakill.Assetbundleloader", "Assetbundleloader", "0.1.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Assetbundleloader : BaseUnityPlugin
	{
		private Dictionary<string, List<GameObject>> loadedObjectsDict = new Dictionary<string, List<GameObject>>();

		private List<GameObject> placedObjects = new List<GameObject>();

		private int currentObjectIndex = 0;

		private string currentAssetBundleName;

		public GameObject[] loadedObjects;

		private List<string> assetBundleNames = new List<string>();

		[Configgable("", "Build button", 0, null)]
		private static ConfigKeybind Keybind = new ConfigKeybind((KeyCode)120);

		[Configgable("", "Switch asset bundle", 0, null)]
		private static ConfigKeybind Keybind1 = new ConfigKeybind((KeyCode)110);

		[Configgable("", "Scroll through object list", 0, null)]
		private static ConfigKeybind Keybind3 = new ConfigKeybind((KeyCode)99);

		public static ConfigBuilder ConfigBuilder { get; private set; }

		private void Awake()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			ConfigBuilder = new ConfigBuilder("doomahreal.ultrakill.Assetbundleloader", "Assetbundleloader");
			ConfigBuilder.BuildAll();
			((MonoBehaviour)this).StartCoroutine(LoadAllAssetBundles());
			Harmony val = new Harmony("doomahreal.ultrakill.Assetbundleloader");
			val.PatchAll(typeof(ExperimentalArmRotationPatch));
		}

		private IEnumerator LoadAllAssetBundles()
		{
			string bundlesDirectory = GetBundlesDirectory();
			if (bundlesDirectory == null)
			{
				yield break;
			}
			string[] files = Directory.GetFiles(bundlesDirectory, "*.bundle");
			foreach (string bundlePath in files)
			{
				yield return LoadAssetBundle(bundlePath);
			}
			if (loadedObjectsDict.Count > 0)
			{
				currentAssetBundleName = loadedObjectsDict.Keys.OrderBy((string k) => k).First();
				currentObjectIndex = 0;
				LoadObjectsFromAssetBundle(currentAssetBundleName);
			}
			else
			{
				Debug.Log((object)"No asset bundles found in the directory where the DLL is located.");
			}
		}

		private IEnumerator LoadAssetBundle(string bundlePath)
		{
			AssetBundleCreateRequest assetBundleRequest = AssetBundle.LoadFromFileAsync(bundlePath);
			yield return assetBundleRequest;
			AssetBundle assetBundle = assetBundleRequest.assetBundle;
			string bundleName = Path.GetFileNameWithoutExtension(bundlePath);
			List<GameObject> prefabList = new List<GameObject>();
			string[] allAssetNames = assetBundle.GetAllAssetNames();
			foreach (string name in allAssetNames)
			{
				if (name.EndsWith(".prefab"))
				{
					AssetBundleRequest assetLoadRequest = assetBundle.LoadAssetAsync<GameObject>(name);
					yield return assetLoadRequest;
					Object asset = assetLoadRequest.asset;
					prefabList.Add((GameObject)(object)((asset is GameObject) ? asset : null));
				}
			}
			loadedObjectsDict.Add(bundleName, prefabList);
			assetBundleNames.Add(bundleName);
			assetBundle.Unload(false);
		}

		private string GetBundlesDirectory()
		{
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			string[] files = Directory.GetFiles(directoryName, "*.bundle");
			if (files.Length == 0)
			{
				Debug.Log((object)"No .bundle files found in the directory where the DLL is located.");
				return null;
			}
			return directoryName;
		}

		private void LoadObjectsFromAssetBundle(string bundleName)
		{
			if (loadedObjectsDict.TryGetValue(bundleName, out var value))
			{
				loadedObjects = value.ToArray();
				InstantiateCurrentObject();
			}
			else
			{
				Debug.Log((object)("Asset bundle not found: " + bundleName));
			}
		}

		private void Update()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			if (Input.GetKeyDown(((ConfigValueElement<KeyCode>)(object)Keybind).Value) && CheckForMissingBundle())
			{
				ShootRaycast();
			}
			if (Input.GetKeyDown(((ConfigValueElement<KeyCode>)(object)Keybind1).Value))
			{
				SwitchAssetBundle();
			}
			if (Input.GetKeyDown(((ConfigValueElement<KeyCode>)(object)Keybind3).Value) && CheckForMissingBundle())
			{
				ScrollObjectList(1);
			}
			ShootRaycastWithRotation();
		}

		private bool CheckForMissingBundle()
		{
			if (loadedObjects == null || loadedObjects.Length == 0)
			{
				MonoSingleton<HudMessageReceiver>.Instance.SendHudMessage("<color=red>Error:You dont either have a assetbundle in HotLoadedBundles or you dont even have assetbundles, stupid.</color>", "", "", 0, false);
				return false;
			}
			return true;
		}

		private void ShootRaycast()
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			if (loadedObjects != null && loadedObjects.Length != 0 && currentObjectIndex >= 0 && currentObjectIndex < loadedObjects.Length)
			{
				Ray val = default(Ray);
				((Ray)(ref val))..ctor(((Component)Camera.main).transform.position, ((Component)Camera.main).transform.forward);
				RaycastHit val2 = default(RaycastHit);
				if (Physics.Raycast(val, ref val2, float.MaxValue, LayerMask.op_Implicit(LayerMaskDefaults.Get((LMD)1))))
				{
					Debug.Log((object)("Raycast hit object: " + ((Object)((Component)((RaycastHit)(ref val2)).collider).gameObject).name));
					Bounds bounds = loadedObjects[currentObjectIndex].GetComponent<Renderer>().bounds;
					Vector3 val3 = ((RaycastHit)(ref val2)).point + ((RaycastHit)(ref val2)).normal * ((Bounds)(ref bounds)).extents.y;
					GameObject val4 = Object.Instantiate<GameObject>(loadedObjects[currentObjectIndex], val3, Quaternion.identity);
					val4.layer = 8;
					val4.AddComponent<SandboxProp>();
					Rigidbody val5 = val4.AddComponent<Rigidbody>();
					val5.useGravity = true;
					placedObjects.Add(val4);
				}
				else
				{
					Debug.Log((object)"Raycast didn't hit anything.");
				}
			}
		}

		private void ScrollObjectList(int direction)
		{
			currentObjectIndex += direction;
			if (currentObjectIndex < 0)
			{
				currentObjectIndex = loadedObjects.Length - 1;
			}
			if (currentObjectIndex >= loadedObjects.Length)
			{
				currentObjectIndex = 0;
			}
			InstantiateCurrentObject();
		}

		private void InstantiateCurrentObject()
		{
			if (loadedObjects != null && loadedObjects.Length != 0 && currentObjectIndex >= 0 && currentObjectIndex < loadedObjects.Length)
			{
				MonoSingleton<HudMessageReceiver>.Instance.SendHudMessage("<color=green>Currently Selected Object: </color>" + ((Object)loadedObjects[currentObjectIndex]).name, "", "", 0, false);
			}
		}

		private void SwitchAssetBundle()
		{
			if (assetBundleNames.Count > 0)
			{
				int num = assetBundleNames.IndexOf(currentAssetBundleName);
				num = (num + 1) % assetBundleNames.Count;
				currentAssetBundleName = assetBundleNames[num];
				currentObjectIndex = 0;
				LoadObjectsFromAssetBundle(currentAssetBundleName);
			}
		}

		private void ShootRaycastWithRotation()
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.Find("Player/Main Camera/Guns/Spawner Arm(Clone) - MoveHand");
			if ((Object)(object)val != (Object)null && Input.GetMouseButton(0) && Input.GetKey((KeyCode)114))
			{
				Ray val2 = default(Ray);
				((Ray)(ref val2))..ctor(((Component)Camera.main).transform.position, ((Component)Camera.main).transform.forward);
				RaycastHit val3 = default(RaycastHit);
				if (Physics.Raycast(val2, ref val3, float.MaxValue, LayerMask.op_Implicit(LayerMaskDefaults.Get((LMD)1))) && (Object)(object)((Component)((RaycastHit)(ref val3)).collider).gameObject.GetComponent<SandboxProp>() != (Object)null)
				{
					((MonoBehaviour)this).StartCoroutine(RotateObject(((Component)((RaycastHit)(ref val3)).collider).gameObject));
				}
			}
		}

		private IEnumerator RotateObject(GameObject objToRotate)
		{
			Vector3 initialMousePosition = Input.mousePosition;
			while (true)
			{
				Vector3 mouseDelta = (Input.mousePosition - initialMousePosition) * 0.1f;
				objToRotate.transform.Rotate(Vector3.up, mouseDelta.x, (Space)0);
				objToRotate.transform.Rotate(Vector3.right, 0f - mouseDelta.y, (Space)0);
				initialMousePosition = Input.mousePosition;
				if (!Input.GetKey((KeyCode)114) || !Input.GetMouseButton(0) || (Object)(object)GameObject.Find("Player/Main Camera/Guns/Spawner Arm(Clone) - MoveHand") == (Object)null)
				{
					break;
				}
				yield return null;
			}
		}
	}
}