Decompiled source of RumblePrecipitation v1.0.2

Mods/RumblePrecipitation.dll

Decompiled 2 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.InteropServices;
using System.Runtime.Versioning;
using AssetBundleLoader;
using ErrorUtils;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.Attributes;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppRUMBLE.Players;
using Il2CppSystem;
using MelonLoader;
using Microsoft.CodeAnalysis;
using RumbleModUI;
using RumbleModdingAPI;
using RumblePrecipitation;
using UnityEngine;
using UniverseLib.Runtime.Il2Cpp;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Main), "RumblePrecipitation", "1.0.2", "ERROR", null)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: MelonColor(255, 255, 0, 0)]
[assembly: MelonAuthorColor(255, 255, 0, 0)]
[assembly: AssemblyDescription("")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: VerifyLoaderVersion(0, 6, 2, true)]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b10c94a1-8a40-4701-bc5b-98eabb44dfea")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("RumblePrecipitation")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+858e0976c3de6a25d51de2d1df9a31226a2214ba")]
[assembly: AssemblyProduct("RumblePrecipitation")]
[assembly: AssemblyTitle("RumblePrecipitation")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace ErrorUtils
{
	internal static class Utilities
	{
		public static PlayerController playerController { get; private set; }

		public static void Init()
		{
			playerController = Players.GetPlayerController();
		}

		public static AssetBundle LoadBundle(string resourceName)
		{
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			using Stream stream = executingAssembly.GetManifestResourceStream(resourceName);
			if (stream != null)
			{
				byte[] array = new byte[stream.Length];
				stream.Read(array, 0, array.Length);
				return AssetBundle.LoadFromMemory(array);
			}
			Debug.LogError(Object.op_Implicit("Resource not found: " + resourceName));
			return null;
		}
	}
}
namespace RumblePrecipitation
{
	public static class BuildInfo
	{
		public const string ModName = "RumblePrecipitation";

		public const string ModVersion = "1.0.2";

		public const string Description = "Adds rain and snow to rumble!";

		public const string Author = "ERROR";

		public const string Company = "";
	}
	public class Main : MelonMod
	{
		private bool isInitialized;

		private string currentScene = "Loader";

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

		private ModSetting<int> WeatherType;

		private int weatherType = 0;

		private ModSetting<bool> EnabledInMatches;

		private bool enabledInMatches = false;

		private ModSetting<bool> FogBreath;

		private bool fogBreath = true;

		private UI UI = UI.instance;

		private Mod Precipitation = new Mod();

		private AudioSource audioSource;

		private AudioClip audioClip;

		public override void OnLateInitializeMelon()
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Expected O, but got Unknown
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Expected O, but got Unknown
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Expected O, but got Unknown
			Calls.onMapInitialized += OnMapInitialized;
			MelonLogger.Msg("RumblePrecipitation Initiated");
			Precipitation.ModName = "RumblePrecipitation";
			Precipitation.ModVersion = "1.0.2";
			Precipitation.SetFolder("RumblePrecipitation");
			Precipitation.AddDescription("Description", "", "Adds rain and snow to rumble!", new Tags
			{
				IsSummary = true
			});
			WeatherType = Precipitation.AddToList("Weather Type", 1, "An integer value (whole number) that determines what type of weather you want. \n 0 = Snow \n 1 = Rain \n >2 = Clear", new Tags());
			EnabledInMatches = Precipitation.AddToList("Enabled In Matches", true, 0, "Determines weather or not weather is activated in matches.", new Tags());
			FogBreath = Precipitation.AddToList("Fog Breath", true, 0, "Toggles weather or not you want fog breath when weather is active. (Breathes every 3 seconds)", new Tags());
			Precipitation.GetFromFile();
			Precipitation.ModSaved += Save;
			UI.instance.UI_Initialized += OnUIInit;
			Save();
		}

		public void OnUIInit()
		{
			UI.AddMod(Precipitation);
		}

		public void Save()
		{
			MelonLogger.Msg("Saved settings for weather");
			enabledInMatches = (bool)((ModSetting)EnabledInMatches).Value;
			weatherType = (int)((ModSetting)WeatherType).Value;
			fogBreath = (bool)((ModSetting)FogBreath).Value;
			if (isInitialized)
			{
				if ((currentScene == "Map0" || currentScene == "Map1") && !enabledInMatches)
				{
					ChangeWeather(2);
				}
				else
				{
					ChangeWeather(weatherType);
				}
			}
		}

		public void OnMapInitialized()
		{
			if (currentScene != "Loader")
			{
				MelonCoroutines.Start(InitializeWithPause());
			}
		}

		private IEnumerator InitializeWithPause()
		{
			yield return (object)new WaitForSeconds(3f);
			Initialize();
		}

		private void ChangeWeather(int weather)
		{
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0330: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_03be: Unknown result type (might be due to invalid IL or missing references)
			//IL_039b: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d6: Unknown result type (might be due to invalid IL or missing references)
			if (needDestroy != null || needDestroy.Count > 0)
			{
				foreach (GameObject item in needDestroy)
				{
					Object.Destroy((Object)(object)item);
				}
			}
			if (weather <= 0)
			{
				AssetBundle assetBundle = Utilities.LoadBundle("RumblePrecipitation.snow");
				if ((Object)(object)assetBundle != (Object)null)
				{
					GameObject val = assetBundle.LoadAsset<GameObject>("Particle");
					GameObject val2 = Object.Instantiate<GameObject>(val);
					val2.transform.position = new Vector3(-2.48f, 11.74f, -6.33f);
					val2.transform.localScale = new Vector3(5f, 1f, 5f);
					needDestroy.Add(val2);
					assetBundle.Unload(unloadAllLoadedObjects: false);
					AssetBundle assetBundle2 = Utilities.LoadBundle("RumblePrecipitation.snowsound");
					if ((Object)(object)assetBundle2 != (Object)null)
					{
						audioClip = assetBundle2.LoadAsset<AudioClip>("Snow");
						if ((Object)(object)audioClip != (Object)null)
						{
							audioSource.clip = audioClip;
							audioSource.loop = true;
							audioSource.spatialBlend = 0f;
							audioSource.volume = 1f;
							audioSource.Play();
							assetBundle2.Unload(unloadAllLoadedObjects: false);
						}
						else
						{
							MelonLogger.Msg("Failed to load the audio clip.");
						}
					}
				}
				RenderSettings.fog = true;
				RenderSettings.fogColor = Color.white;
				RenderSettings.fogMode = (FogMode)1;
				RenderSettings.fogStartDistance = 5f;
				RenderSettings.fogEndDistance = 100f;
				RenderSettings.fogDensity = 0.1f;
			}
			else if (weather == 1)
			{
				AssetBundle assetBundle3 = Utilities.LoadBundle("RumblePrecipitation.rain");
				if ((Object)(object)assetBundle3 != (Object)null)
				{
					GameObject val3 = assetBundle3.LoadAsset<GameObject>("Rain");
					GameObject val4 = Object.Instantiate<GameObject>(val3);
					val4.transform.position = new Vector3(-11.28f, 11.74f, -0.87f);
					val4.transform.localScale = new Vector3(5f, 1f, 5f);
					needDestroy.Add(val4);
					assetBundle3.Unload(unloadAllLoadedObjects: false);
					AssetBundle assetBundle4 = Utilities.LoadBundle("RumblePrecipitation.lightrain");
					if ((Object)(object)assetBundle4 != (Object)null)
					{
						audioClip = assetBundle4.LoadAsset<AudioClip>("LightRain");
						if ((Object)(object)audioClip != (Object)null)
						{
							audioSource.clip = audioClip;
							audioSource.loop = true;
							audioSource.spatialBlend = 0f;
							audioSource.volume = 1f;
							audioSource.Play();
							assetBundle4.Unload(unloadAllLoadedObjects: false);
						}
						else
						{
							MelonLogger.Msg("Failed to load the audio clip.");
						}
					}
				}
				RenderSettings.fog = true;
				RenderSettings.fogColor = Color.gray;
				RenderSettings.fogMode = (FogMode)1;
				RenderSettings.fogStartDistance = 5f;
				RenderSettings.fogEndDistance = 100f;
				RenderSettings.fogDensity = 0.1f;
				MelonLogger.Msg("Set weather to rain.");
			}
			else if (weather >= 2)
			{
				if (Mods.getMyModString().Contains("Rumble Dark Mode"))
				{
					RenderSettings.fogColor = Color.black;
				}
				else
				{
					RenderSettings.fogColor = new Color(0f, 0f, 0f, 1f);
				}
				audioSource.Stop();
				audioSource.clip = null;
				RenderSettings.fog = true;
				RenderSettings.fogMode = (FogMode)1;
				RenderSettings.fogStartDistance = 20f;
				RenderSettings.fogEndDistance = 1000f;
				RenderSettings.fogDensity = 0.01f;
			}
			if (!fogBreath || weather >= 2)
			{
				return;
			}
			AssetBundle assetBundle5 = Utilities.LoadBundle("RumblePrecipitation.breath");
			if ((Object)(object)assetBundle5 != (Object)null)
			{
				GameObject val5 = assetBundle5.LoadAsset<GameObject>("Breath");
				if ((Object)(object)val5 == (Object)null)
				{
					MelonLogger.Error("Breath Object is null");
					return;
				}
				GameObject val6 = Object.Instantiate<GameObject>(val5);
				val6.transform.SetParent(((Component)Players.GetLocalPlayer().Controller).transform.GetChild(1).GetChild(0).GetChild(0));
				val6.transform.localPosition = new Vector3(0f, -0.07f, 0f);
				val6.transform.localRotation = Quaternion.identity;
				needDestroy.Add(val6);
				assetBundle5.Unload(unloadAllLoadedObjects: false);
			}
		}

		public void Initialize()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			if (!isInitialized)
			{
				GameObject val = new GameObject("SoundObject");
				audioSource = val.AddComponent<AudioSource>();
				if ((currentScene == "Map0" || currentScene == "Map1") && !enabledInMatches)
				{
					ChangeWeather(2);
				}
				else
				{
					ChangeWeather(weatherType);
				}
				isInitialized = true;
			}
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			currentScene = sceneName;
			isInitialized = false;
		}
	}
}
namespace UniverseLib.Runtime.Il2Cpp
{
	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 + "'!");
		}
	}
}
namespace AssetBundleLoader
{
	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);
		}
	}
}