Decompiled source of RumbleDarkMode v2.3.7

Mods/RumbleDarkMode.dll

Decompiled 2 weeks ago
using System;
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.Preferences;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using RumbleDarkMode;
using RumbleModdingAPI.RMAPI;
using UIFramework;
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.3.7", "ERROR", null)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: MelonInfo(typeof(Main), "Rumble Dark Mode", "2.2.7", "ERROR", null)]
[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+df8504f51e2270496933d787207db911aa3ad0b4")]
[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 static class BuildInfo
	{
		public const string Name = "Rumble Dark Mode";

		public const string Author = "ERROR";

		public const string Version = "2.3.7";
	}
	public class SceneSettings
	{
		public MelonPreferences_Entry<bool> enabled;

		public MelonPreferences_Entry<string> skyboxName;

		public MelonPreferences_Entry<string> skyboxTint;

		public MelonPreferences_Entry<float> skyboxExposure;

		public MelonPreferences_Entry<string> lightingColor;

		public MelonPreferences_Entry<string> treeColor;

		public MelonPreferences_Entry<string> treeShadowColor;

		public MelonPreferences_Entry<bool> fogEnabled;

		public MelonPreferences_Entry<string> fogColor;

		public MelonPreferences_Entry<float> fogDensity;

		public static (SceneSettings settings, MelonPreferences_Category category) CreateSettings(string id, string name)
		{
			MelonPreferences_Category val = MelonPreferences.CreateCategory(id, name);
			return (new SceneSettings
			{
				enabled = val.CreateEntry<bool>("Enabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null),
				skyboxName = val.CreateEntry<string>("SkyboxName", "NightTime", (string)null, (string)null, false, false, (ValueValidator)null, (string)null),
				skyboxTint = val.CreateEntry<string>("SkyboxTint", "404052", (string)null, (string)null, false, false, (ValueValidator)null, (string)null),
				skyboxExposure = val.CreateEntry<float>("SkyboxExposure", 0.5f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null),
				lightingColor = val.CreateEntry<string>("LightingColor", "3d385c", (string)null, (string)null, false, false, (ValueValidator)null, (string)null),
				treeColor = val.CreateEntry<string>("TreeColor", "#3e452d", (string)null, (string)null, false, false, (ValueValidator)null, (string)null),
				treeShadowColor = val.CreateEntry<string>("TreeShadowColor", "#1f2418", (string)null, (string)null, false, false, (ValueValidator)null, (string)null)
			}, val);
		}
	}
	public class Main : MelonMod
	{
		public string currentScene = "Loader";

		public SceneSettings globalSettings;

		public Dictionary<string, SceneSettings> sceneSettings;

		public Cubemap cubemap;

		public override void OnLateInitializeMelon()
		{
			Actions.onMapInitialized += OnMapInitialized;
			InitializeUI();
		}

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

		private void InitializeUI()
		{
			(SceneSettings, MelonPreferences_Category) tuple = SceneSettings.CreateSettings("Global_Settings", "Global Settings");
			globalSettings = tuple.Item1;
			(SceneSettings, MelonPreferences_Category) tuple2 = SceneSettings.CreateSettings("Gym_Settings", "Gym");
			(SceneSettings, MelonPreferences_Category) tuple3 = SceneSettings.CreateSettings("Park_Settings", "Park");
			(SceneSettings, MelonPreferences_Category) tuple4 = SceneSettings.CreateSettings("Ring_Settings", "Ring");
			(SceneSettings, MelonPreferences_Category) tuple5 = SceneSettings.CreateSettings("Pit_Settings", "Pit");
			sceneSettings = new Dictionary<string, SceneSettings>
			{
				["Gym"] = tuple2.Item1,
				["Park"] = tuple3.Item1,
				["Map0"] = tuple4.Item1,
				["Map1"] = tuple5.Item1
			};
			ModelMod val = UI.Register((MelonBase)(object)this, (MelonPreferences_Category[])(object)new MelonPreferences_Category[5] { tuple.Item2, tuple2.Item2, tuple3.Item2, tuple4.Item2, tuple5.Item2 });
			((ModelModItem)val).OnModSaved += delegate
			{
				ApplyDarkMode(currentScene);
			};
		}

		private void OnMapInitialized(string sceneName)
		{
			ApplyDarkMode(sceneName);
		}

		private void ApplyDarkMode(string sceneName)
		{
			if (!(sceneName == "Loader") && this.sceneSettings.TryGetValue(sceneName, out var value))
			{
				SceneSettings sceneSettings = (value.enabled.Value ? value : globalSettings);
				if (sceneSettings.enabled.Value)
				{
					ApplySkybox(sceneSettings);
					ApplyLighting(sceneSettings);
					ApplyMaterials(sceneSettings);
				}
			}
		}

		private void ApplySkybox(SceneSettings settings)
		{
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Expected O, but got Unknown
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Expected O, but got Unknown
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = LoadFace("Right", settings);
			Texture2D val2 = LoadFace("Left", settings);
			Texture2D val3 = LoadFace("Top", settings);
			Texture2D val4 = LoadFace("Bottom", settings);
			Texture2D val5 = LoadFace("Front", settings);
			Texture2D val6 = LoadFace("Back", settings);
			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))
			{
				cubemap = new Cubemap(((Texture)val).width, (TextureFormat)4, false);
				Graphics.CopyTexture((Texture)(object)val, 0, 0, (Texture)(object)cubemap, 0, 0);
				Graphics.CopyTexture((Texture)(object)val2, 0, 0, (Texture)(object)cubemap, 1, 0);
				Graphics.CopyTexture((Texture)(object)val3, 0, 0, (Texture)(object)cubemap, 2, 0);
				Graphics.CopyTexture((Texture)(object)val4, 0, 0, (Texture)(object)cubemap, 3, 0);
				Graphics.CopyTexture((Texture)(object)val5, 0, 0, (Texture)(object)cubemap, 4, 0);
				Graphics.CopyTexture((Texture)(object)val6, 0, 0, (Texture)(object)cubemap, 5, 0);
				Shader val7 = Shader.Find("Skybox/Cubemap");
				if (!((Object)(object)val7 == (Object)null))
				{
					Material val8 = new Material(val7);
					val8.SetTexture("_Tex", (Texture)(object)cubemap);
					val8.SetColor("_Tint", HexToColor(settings.skyboxTint.Value));
					val8.SetFloat("_Exposure", settings.skyboxExposure.Value);
					RenderSettings.skybox = val8;
				}
			}
		}

		private Texture2D LoadFace(string face, SceneSettings settings)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			string path = Path.Combine(MelonEnvironment.UserDataDirectory, "RumbleDarkMode", "Skybox");
			string path2 = Path.Combine(path, settings.skyboxName.Value + "_" + face + ".png");
			if (!File.Exists(path2))
			{
				return null;
			}
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			ImageConversion.LoadImage(val, Il2CppStructArray<byte>.op_Implicit(File.ReadAllBytes(path2)));
			return val;
		}

		private void ApplyLighting(SceneSettings settings)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Invalid comparison between Unknown and I4
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			foreach (Light item in Object.FindObjectsOfType<Light>())
			{
				if ((int)item.type == 1)
				{
					item.color = HexToColor(settings.lightingColor.Value);
					item.intensity = 0.5f;
				}
				item.cullingMask = -1;
			}
		}

		private void ApplyMaterials(SceneSettings settings)
		{
			//IL_005e: 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_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Expected O, but got Unknown
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			foreach (Renderer item in Object.FindObjectsOfType<Renderer>())
			{
				Material sharedMaterial = item.sharedMaterial;
				if ((Object)(object)sharedMaterial == (Object)null)
				{
					continue;
				}
				if (((Object)sharedMaterial.shader).name == "Shader Graphs/Leaves")
				{
					sharedMaterial.SetColor("_Main_color", HexToColor(settings.treeColor.Value));
					sharedMaterial.SetColor("_Shadow_color", HexToColor(settings.treeShadowColor.Value));
				}
				if (((Object)sharedMaterial.shader).name == "Shader Graphs/MobileEnvironmentUV0")
				{
					Shader val = Shader.Find("Shader Graphs/RUMBLE_Move_Toon");
					if ((Object)(object)item.sharedMaterial.shader != (Object)(object)val)
					{
						Material val2 = new Material(val);
						Texture texture = sharedMaterial.GetTexture("_TEXTURE");
						val2.SetTexture("Texture2D_2058E65A", texture);
						val2.SetTexture("Texture2D_3812B1EC", texture);
						val2.SetColor("Color_D943764B", Color.white);
						item.sharedMaterial = val2;
					}
				}
				item.lightmapIndex = -1;
				item.lightProbeUsage = (LightProbeUsage)0;
				item.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));
		}
	}
}