Decompiled source of Arenas v1.0.0

CustomArenas.dll

Decompiled 4 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using CustomArenas;
using CustomArenas.Utils;
using MelonLoader;
using RumbleModdingFramework;
using UnhollowerBaseLib;
using UnhollowerBaseLib.Attributes;
using UnhollowerRuntimeLib;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(CAMain), "CustomArenas", "1.0.0", "Hazzy", null)]
[assembly: AssemblyTitle("CustomArenas")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CustomArenas")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("74C7F822-8761-4383-90AE-C98FF427DA77")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace CustomArenas
{
	public class CAMain : MelonMod
	{
		public string dropArenaPath;

		public string ovalArenaPath;

		public bool mapLoadingBuffer = false;

		public AssetBundle prevBundle;

		public override void OnUpdate()
		{
			if (Input.GetKeyDown((KeyCode)117))
			{
				dropArenaPath = MelonUtils.UserDataDirectory + "\\CustomArenas\\wuhuisland.arena";
			}
			if (Input.GetKeyDown((KeyCode)105))
			{
				ovalArenaPath = MelonUtils.UserDataDirectory + "\\CustomArenas\\whitebox.arena";
			}
		}

		public override void OnInitializeMelon()
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Expected O, but got Unknown
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Expected O, but got Unknown
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Expected O, but got Unknown
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Expected O, but got Unknown
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Expected O, but got Unknown
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Expected O, but got Unknown
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Expected O, but got Unknown
			Directory.CreateDirectory(MelonUtils.UserDataDirectory + "\\CustomArenas");
			string[] files = Directory.GetFiles($"{MelonUtils.UserDataDirectory}\\CustomArenas", "*.arena");
			VrMenuPageBuilder val = VrMenuPageBuilder.Builder();
			VrMenuPageBuilder val2 = VrMenuPageBuilder.Builder();
			VrMenuPageBuilder val3 = VrMenuPageBuilder.Builder();
			val2.AddButton(new VrMenuButton("Default", (Action)delegate
			{
				dropArenaPath = null;
			}, Color.gray));
			val3.AddButton(new VrMenuButton("Default", (Action)delegate
			{
				ovalArenaPath = null;
			}, Color.gray));
			int num = 0;
			string[] array = files;
			foreach (string arenaDir1 in array)
			{
				int num2 = num;
				val2.AddButton(new VrMenuButton(Path.GetFileNameWithoutExtension(files[num]), (Action)delegate
				{
					dropArenaPath = arenaDir1;
				}));
				num++;
			}
			int num3 = 0;
			string[] array2 = files;
			foreach (string arenaDir2 in array2)
			{
				int num4 = num3;
				val3.AddButton(new VrMenuButton(Path.GetFileNameWithoutExtension(files[num3]), (Action)delegate
				{
					ovalArenaPath = arenaDir2;
				}));
				num3++;
			}
			VrMenuPage dropPit = val2.Build();
			VrMenuPage customArenas = val.Build();
			VrMenuPage ovalStage = val3.Build();
			val.AddButton(new VrMenuButton("Drop Pit Arena", (Action)delegate
			{
				dropPit.Open();
			}, Color.blue));
			val.AddButton(new VrMenuButton("Oval Arena", (Action)delegate
			{
				ovalStage.Open();
			}, Color.blue));
			VrMenu.RegisterMainButton(new VrMenuButton("Arenas", (Action)delegate
			{
				customArenas.Open();
			}));
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			if (mapLoadingBuffer)
			{
				mapLoadingBuffer = false;
			}
			else if (sceneName == "Map0")
			{
				if ((Object)(object)prevBundle != (Object)null)
				{
					prevBundle.Unload(unloadAllLoadedObjects: true);
				}
				if (dropArenaPath != null)
				{
					AssetBundle assetBundle = AssetBundle.LoadFromFile(dropArenaPath);
					prevBundle = assetBundle;
					SceneManager.LoadScene("CustomArena0", (LoadSceneMode)1);
					GameObject val = GameObject.Find("Map0_production/Main static group");
					GameObject val2 = GameObject.Find("Map0_production/Mountain");
					val.SetActive(false);
					val2.SetActive(false);
					mapLoadingBuffer = true;
				}
			}
			else if (sceneName == "Map1")
			{
				if ((Object)(object)prevBundle != (Object)null)
				{
					prevBundle.Unload(unloadAllLoadedObjects: true);
				}
				if (ovalArenaPath != null)
				{
					AssetBundle assetBundle2 = AssetBundle.LoadFromFile(ovalArenaPath);
					prevBundle = assetBundle2;
					SceneManager.LoadScene("CustomArena1", (LoadSceneMode)1);
					GameObject val3 = GameObject.Find("Map1_production/Main static group");
					val3.SetActive(false);
					mapLoadingBuffer = true;
				}
			}
		}

		public void LeverPulled()
		{
		}
	}
}
namespace CustomArenas.Utils
{
	public class AssetBundle : Object
	{
		internal delegate IntPtr d_LoadFromFile(IntPtr path, uint crc, ulong offset);

		private delegate IntPtr d_LoadFromMemory(IntPtr binary, uint crc);

		public delegate IntPtr d_GetAllLoadedAssetBundles_Native();

		internal delegate IntPtr d_LoadAssetWithSubAssets_Internal(IntPtr _this, IntPtr name, IntPtr type);

		internal delegate IntPtr d_LoadAsset_Internal(IntPtr _this, IntPtr name, IntPtr type);

		internal delegate void d_Unload(IntPtr _this, bool unloadAllLoadedObjects);

		public readonly IntPtr m_bundlePtr = IntPtr.Zero;

		static AssetBundle()
		{
			ClassInjector.RegisterTypeInIl2Cpp<AssetBundle>();
		}

		[HideFromIl2Cpp]
		public static AssetBundle LoadFromFile(string path)
		{
			IntPtr intPtr = ICallManager.GetICallUnreliable<d_LoadFromFile>(new string[2] { "UnityEngine.AssetBundle::LoadFromFile_Internal", "UnityEngine.AssetBundle::LoadFromFile" })(IL2CPP.ManagedStringToIl2Cpp(path), 0u, 0uL);
			return (intPtr != IntPtr.Zero) ? new AssetBundle(intPtr) : null;
		}

		[HideFromIl2Cpp]
		public static AssetBundle LoadFromMemory(byte[] binary, uint crc = 0u)
		{
			IntPtr intPtr = ICallManager.GetICallUnreliable<d_LoadFromMemory>(new string[2] { "UnityEngine.AssetBundle::LoadFromMemory_Internal", "UnityEngine.AssetBundle::LoadFromMemory" })(((Il2CppObjectBase)Il2CppStructArray<byte>.op_Implicit(binary)).Pointer, crc);
			return (intPtr != IntPtr.Zero) ? new AssetBundle(intPtr) : null;
		}

		[HideFromIl2Cpp]
		public static AssetBundle[] GetAllLoadedAssetBundles()
		{
			IntPtr intPtr = ICallManager.GetICall<d_GetAllLoadedAssetBundles_Native>("UnityEngine.AssetBundle::GetAllLoadedAssetBundles_Native")();
			return (intPtr != IntPtr.Zero) ? Il2CppArrayBase<AssetBundle>.op_Implicit((Il2CppArrayBase<AssetBundle>)(object)new Il2CppReferenceArray<AssetBundle>(intPtr)) : null;
		}

		public AssetBundle(IntPtr ptr)
			: base(ptr)
		{
			m_bundlePtr = ptr;
		}

		[HideFromIl2Cpp]
		public Object[] LoadAllAssets()
		{
			IntPtr intPtr = ICallManager.GetICall<d_LoadAssetWithSubAssets_Internal>("UnityEngine.AssetBundle::LoadAssetWithSubAssets_Internal")(m_bundlePtr, IL2CPP.ManagedStringToIl2Cpp(""), ((Il2CppObjectBase)Il2CppType.Of<Object>()).Pointer);
			return (Object[])((intPtr != IntPtr.Zero) ? ((Array)Il2CppArrayBase<Object>.op_Implicit((Il2CppArrayBase<Object>)(object)new Il2CppReferenceArray<Object>(intPtr))) : ((Array)new Object[0]));
		}

		[HideFromIl2Cpp]
		public T LoadAsset<T>(string name) where T : Object
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			IntPtr intPtr = ICallManager.GetICall<d_LoadAsset_Internal>("UnityEngine.AssetBundle::LoadAsset_Internal")(m_bundlePtr, IL2CPP.ManagedStringToIl2Cpp(name), ((Il2CppObjectBase)Il2CppType.Of<T>()).Pointer);
			return (intPtr != IntPtr.Zero) ? ((Il2CppObjectBase)new Object(intPtr)).TryCast<T>() : default(T);
		}

		[HideFromIl2Cpp]
		public void Unload(bool unloadAllLoadedObjects)
		{
			ICallManager.GetICall<d_Unload>("UnityEngine.AssetBundle::Unload")(m_bundlePtr, unloadAllLoadedObjects);
		}
	}
	public static class ICallManager
	{
		private static readonly Dictionary<string, Delegate> iCallCache = new Dictionary<string, Delegate>();

		private static readonly Dictionary<string, Delegate> unreliableCache = new Dictionary<string, Delegate>();

		public static T GetICall<T>(string signature) where T : Delegate
		{
			if (iCallCache.ContainsKey(signature))
			{
				return (T)iCallCache[signature];
			}
			IntPtr intPtr = IL2CPP.il2cpp_resolve_icall(signature);
			if (intPtr == IntPtr.Zero)
			{
				throw new MissingMethodException("Could not find any iCall with the signature '" + signature + "'!");
			}
			Delegate delegateForFunctionPointer = Marshal.GetDelegateForFunctionPointer(intPtr, typeof(T));
			iCallCache.Add(signature, delegateForFunctionPointer);
			return (T)delegateForFunctionPointer;
		}

		public static T GetICallUnreliable<T>(params string[] possibleSignatures) where T : Delegate
		{
			string text = possibleSignatures.First();
			if (unreliableCache.ContainsKey(text))
			{
				return (T)unreliableCache[text];
			}
			foreach (string text2 in possibleSignatures)
			{
				IntPtr intPtr = IL2CPP.il2cpp_resolve_icall(text2);
				if (intPtr != IntPtr.Zero)
				{
					T val = (T)Marshal.GetDelegateForFunctionPointer(intPtr, typeof(T));
					unreliableCache.Add(text, val);
					return val;
				}
			}
			throw new MissingMethodException("Could not find any iCall from list of provided signatures starting with '" + text + "'!");
		}
	}
}