Decompiled source of RumbleDarkMode v2.2.7

Mods/RumbleDarkMode.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using MelonLoader;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using RumbleDarkMode;
using RumbleModUI;
using UnityEngine;
using UnityEngine.Rendering;

[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), "Rumble Dark Mode", "2.2.7", "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("RumbleDarkMode")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RumbleDarkMode")]
[assembly: AssemblyTitle("RumbleDarkMode")]
[assembly: AssemblyVersion("1.0.0.0")]
[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;
		}
	}
}
namespace RumbleDarkMode
{
	public class Main : MelonMod
	{
		[CompilerGenerated]
		private sealed class <DelayedApply>d__15 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public Main <>4__this;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <DelayedApply>d__15(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(3f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<>4__this.ApplyDarkMode();
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		public Mod mod = new Mod();

		private ModSetting<bool> gymToggle;

		private ModSetting<bool> parkToggle;

		private ModSetting<bool> ringToggle;

		private ModSetting<bool> pitToggle;

		private ModSetting<string> skyboxName;

		private ModSetting<string> skyboxTint;

		private ModSetting<float> skyboxExposure;

		private ModSetting<string> lightingColor;

		private ModSetting<string> treeColor;

		private ModSetting<string> treeShadowColor;

		public string currentScene = "Loader";

		public override void OnLateInitializeMelon()
		{
			UI.instance.UI_Initialized += OnUIInit;
		}

		public void OnUIInit()
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Expected O, but got Unknown
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Expected O, but got Unknown
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Expected O, but got Unknown
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Expected O, but got Unknown
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Expected O, but got Unknown
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Expected O, but got Unknown
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Expected O, but got Unknown
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Expected O, but got Unknown
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Expected O, but got Unknown
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Expected O, but got Unknown
			mod.ModName = "Rumble Dark Mode";
			mod.ModVersion = "2.2.7";
			mod.SetFolder("RumbleDarkMode");
			mod.AddDescription("Description", "", "Adds a dark mode option to Gym, Park, and Ring!", new Tags
			{
				IsSummary = true
			});
			mod.ModSaved += ApplyDarkMode;
			gymToggle = mod.AddToList("Toggle In Gym", true, 0, "Toggles Dark Mode in Gym", new Tags());
			parkToggle = mod.AddToList("Toggle In Parks", true, 0, "Toggles Dark Mode in Parks", new Tags());
			ringToggle = mod.AddToList("Toggle In Ring", true, 0, "Toggles Dark Mode in Ring", new Tags());
			pitToggle = mod.AddToList("Toggle In Pit", false, 0, "Toggles Dark Mode in Pit", new Tags());
			skyboxName = mod.AddToList("Skybox Name", "NightTime", "Name prefix for the skybox texture set. Stored in UserData/RumbleDarkMode/Skybox/", new Tags());
			skyboxTint = mod.AddToList("Skybox Tint", "404052", "The hex value that represents the skybox tint.\nDefault: 404052 (slate blue)", new Tags());
			skyboxExposure = mod.AddToList("Skybox Exposure", 0.5f, "The value that represents the exposure of the skybox.\nDefault: 0.5", new Tags());
			lightingColor = mod.AddToList("Lighting Color", "3d385c", "The hex value that represents what color the scene is lit as.", new Tags());
			treeColor = mod.AddToList("Tree Color", "#3e452d", "The hex value that represents what the tree/moss color is.", new Tags());
			treeShadowColor = mod.AddToList("Tree Shadow Color", "#1f2418", "The hex value that represents that shadow color of the trees/moss.", new Tags());
			mod.GetFromFile();
			UI.instance.AddMod(mod);
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			currentScene = sceneName;
			MelonCoroutines.Start(DelayedApply());
		}

		[IteratorStateMachine(typeof(<DelayedApply>d__15))]
		private IEnumerator DelayedApply()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <DelayedApply>d__15(0)
			{
				<>4__this = this
			};
		}

		private Texture2D LoadSkyboxFace(string face)
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Expected O, but got Unknown
			string path = Path.Combine(MelonEnvironment.UserDataDirectory, "RumbleDarkMode", "Skybox");
			string path2 = (string)((ModSetting)skyboxName).SavedValue + "_" + face + ".png";
			string text = Path.Combine(path, path2);
			if (!File.Exists(text))
			{
				MelonLogger.Msg("Skybox face missing: " + text);
				return null;
			}
			byte[] array = File.ReadAllBytes(text);
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			ImageConversion.LoadImage(val, Il2CppStructArray<byte>.op_Implicit(array));
			return val;
		}

		private void SetCustomSkybox()
		{
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Expected O, but got Unknown
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Expected O, but got Unknown
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = LoadSkyboxFace("Right");
			Texture2D val2 = LoadSkyboxFace("Left");
			Texture2D val3 = LoadSkyboxFace("Top");
			Texture2D val4 = LoadSkyboxFace("Bottom");
			Texture2D val5 = LoadSkyboxFace("Front");
			Texture2D val6 = LoadSkyboxFace("Back");
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null || (Object)(object)val4 == (Object)null || (Object)(object)val5 == (Object)null || (Object)(object)val6 == (Object)null)
			{
				MelonLogger.Msg("One or more skybox faces missing.");
				return;
			}
			int width = ((Texture)val).width;
			Cubemap val7 = new Cubemap(width, (TextureFormat)4, false);
			Graphics.CopyTexture((Texture)(object)val, 0, 0, (Texture)(object)val7, 0, 0);
			Graphics.CopyTexture((Texture)(object)val2, 0, 0, (Texture)(object)val7, 1, 0);
			Graphics.CopyTexture((Texture)(object)val3, 0, 0, (Texture)(object)val7, 2, 0);
			Graphics.CopyTexture((Texture)(object)val4, 0, 0, (Texture)(object)val7, 3, 0);
			Graphics.CopyTexture((Texture)(object)val5, 0, 0, (Texture)(object)val7, 4, 0);
			Graphics.CopyTexture((Texture)(object)val6, 0, 0, (Texture)(object)val7, 5, 0);
			Shader val8 = Shader.Find("Skybox/Cubemap");
			if ((Object)(object)val8 == (Object)null)
			{
				MelonLogger.Msg("Skybox/Cubemap shader not found.");
				return;
			}
			Material val9 = new Material(val8);
			val9.SetTexture("_Tex", (Texture)(object)val7);
			val9.SetColor("_Tint", HexToColor((string)((ModSetting)skyboxTint).SavedValue));
			val9.SetFloat("_Exposure", (float)((ModSetting)skyboxExposure).SavedValue);
			RenderSettings.skybox = val9;
		}

		private void ApplyDarkMode()
		{
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Invalid comparison between Unknown and I4
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Expected O, but got Unknown
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			if (currentScene == "Loader" || (currentScene == "Gym" && !(bool)((ModSetting)gymToggle).SavedValue) || (currentScene == "Park" && !(bool)((ModSetting)parkToggle).SavedValue) || (currentScene == "Map0" && !(bool)((ModSetting)ringToggle).SavedValue) || (currentScene == "Map1" && !(bool)((ModSetting)pitToggle).SavedValue))
			{
				return;
			}
			SetCustomSkybox();
			foreach (Light item in Object.FindObjectsOfType<Light>())
			{
				if ((int)item.type == 1)
				{
					item.color = HexToColor((string)((ModSetting)lightingColor).SavedValue);
					item.intensity = 0.5f;
				}
				item.cullingMask = -1;
			}
			foreach (Renderer item2 in Object.FindObjectsOfType<Renderer>())
			{
				Material sharedMaterial = item2.sharedMaterial;
				if (!((Object)(object)sharedMaterial == (Object)null))
				{
					if (((Object)sharedMaterial.shader).name == "Shader Graphs/MobileEnvironmentUV0")
					{
						Texture texture = sharedMaterial.GetTexture("_TEXTURE");
						Material val = new Material(Shader.Find("Shader Graphs/RUMBLE_Move_Toon"));
						val.SetTexture("Texture2D_2058E65A", texture);
						val.SetTexture("Texture2D_3812B1EC", texture);
						val.SetColor("Color_D943764B", Color.white);
						item2.material = val;
					}
					if (((Object)sharedMaterial.shader).name == "Shader Graphs/Leaves")
					{
						sharedMaterial.SetColor("_Main_color", HexToColor((string)((ModSetting)treeColor).SavedValue));
						sharedMaterial.SetColor("_Shadow_color", HexToColor((string)((ModSetting)treeShadowColor).SavedValue));
					}
					item2.lightmapIndex = -1;
					item2.lightmapScaleOffset = Vector4.zero;
					item2.lightProbeUsage = (LightProbeUsage)0;
					item2.reflectionProbeUsage = (ReflectionProbeUsage)0;
				}
			}
		}

		private static Color HexToColor(string hex)
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: 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)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			if (hex.StartsWith("#"))
			{
				hex = hex.Substring(1);
			}
			if (hex.Length != 6)
			{
				return Color.black;
			}
			byte b = byte.Parse(hex.Substring(0, 2), NumberStyles.HexNumber);
			byte b2 = byte.Parse(hex.Substring(2, 2), NumberStyles.HexNumber);
			byte b3 = byte.Parse(hex.Substring(4, 2), NumberStyles.HexNumber);
			return Color32.op_Implicit(new Color32(b, b2, b3, byte.MaxValue));
		}
	}
}