Decompiled source of SeasonalLeaves v4.1.1

Mods/SeasonalLeaves.dll

Decompiled 5 months ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using MelonLoader;
using RumbleModUI;
using SeasonalLeaves;
using UnityEngine;
using UnityEngine.VFX;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(SeasonalLeavesClass), "SeasonalLeaves", "4.1.1", "Baumritter", null)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: VerifyLoaderVersion(0, 6, 2)]
[assembly: MelonColor(200, 0, 200, 0)]
[assembly: MelonAuthorColor(200, 0, 200, 0)]
[assembly: AssemblyTitle("SeasonalLeaves")]
[assembly: AssemblyDescription("Changes the color of all leaves based on season.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SeasonalLeaves")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("80d96e94-eda2-46b0-9b8b-23557ea773b5")]
[assembly: AssemblyFileVersion("4.1.1")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("4.1.1.0")]
namespace SeasonalLeaves;

public static class BuildInfo
{
	public const string ModName = "SeasonalLeaves";

	public const string ModVersion = "4.1.1";

	public const string Description = "Changes the color of all leaves based on season.";

	public const string Author = "Baumritter";

	public const string Company = "";
}
public class SeasonalLeavesClass : MelonMod
{
	private const double Delay = 6.0;

	private const int LCT1 = 1365;

	private const int LCB1 = 1366;

	private const int LCT2 = 1359;

	private const int LCB2 = 1361;

	private const int GC1 = 1340;

	private const int GC2 = 1342;

	private const int GC3 = 1347;

	private const int GC4 = 1349;

	private const int VFXGradientID = 977;

	private const string SettingsFolder = "Settings";

	private Color color_cust_cherry = new Color(0.8f, 0.52f, 0.57f, 1f);

	private Color color_sumr_lshgrn = new Color(0f, 0.15f, 0f, 1f);

	private Color color_sumr_drkgrn = new Color(0.05f, 0.04f, 0f, 1f);

	private Color color_fall_drkred = new Color(0.19f, 0.06f, 0f, 1f);

	private Color color_fall_orange = new Color(0.25f, 0.1f, 0f, 1f);

	private Color color_fall_yellow = new Color(0.25f, 0.16f, 0f, 1f);

	private Color color_wntr_lghblu = new Color(0.5f, 0.5f, 0.8f, 1f);

	private readonly bool debug = false;

	private string currentscene;

	private string[] ObjectStrings = new string[15]
	{
		"--------------SCENE--------------/Gym_Production/Main static group/Foliage/Root_leaves", "--------------SCENE--------------/Gym_Production/Main static group/Foliage/Root_leaves_001", "--------------SCENE--------------/Gym_Production/Main static group/Foliage/Root_leaves_002", "--------------SCENE--------------/Gym_Production/Main static group/Foliage/Root_leaves_003", "--------------SCENE--------------/Gym_Production/Main static group/Gymarena/Leave_sphere__23_", "--------------SCENE--------------/Gym_Production/Main static group/Gymarena/Leave_sphere__24_", "--------------SCENE--------------/Grass", "________________SCENE_________________/Park/Main static group/Leaves/Leave_sphere_park", "________________SCENE_________________/Park/Main static group/Leaves/Leave_sphere_park_001", "________________SCENE_________________/Park/Main static group/Leaves/Leave_sphere_park_002",
		"________________SCENE_________________/Park/Main static group/Leaves/Leave_sphere_park_003", "Lighting and effects/Visual Effects/Falling Leaf VFXs", "Map0_production/Main static group/leave", "Map1_production/Main static group/Leaves_Map2", "Lighting & Effects/Visual Effects/Falling Leaf VFXs"
	};

	private List<Material> Mat_Trees = new List<Material>();

	private List<Material> Mat_Grass = new List<Material>();

	private GameObject GO_VFX;

	private VisualEffect VFX_VFX;

	private Mod Mod = new Mod();

	private Delay LoadDelay = new Delay
	{
		DelayName = "SeasonalLeavesLoadDelay"
	};

	public override void OnLateInitializeMelon()
	{
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		((MelonBase)this).OnLateInitializeMelon();
		UI.instance.UI_Initialized += OnUIInit;
		LoadHandler.PlayerLoaded += WaitAfterInit;
		Shading.shades[0] = Color.HSVToRGB(0f, 1f, 1f);
		Shading.shades[1] = Color.HSVToRGB(0f, 0.66f, 0.66f);
		Shading.shades[2] = Color.HSVToRGB(0f, 0.33f, 0.33f);
	}

	private void OnUIInit()
	{
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Expected O, but got Unknown
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Expected O, but got Unknown
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Expected O, but got Unknown
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Expected O, but got Unknown
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Expected O, but got Unknown
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Expected O, but got Unknown
		Mod.ModName = "SeasonalLeaves";
		Mod.ModVersion = "4.1.1";
		Mod.SetFolder("SeasonalLeaves");
		Mod.SetSubFolder("Settings");
		Mod.AddDescription("Description", "", "Changes the color of all leaves based on season.", new Tags
		{
			IsSummary = true
		});
		Mod.AddToList("Grass", false, 0, "Enables continuous Shading of Grass. This is horrendous on performance.", new Tags());
		Mod.AddToList("RGB", false, 1, "Turns the RGB theme on/off.", new Tags());
		Mod.AddToList("Cursed", false, 1, "Turns the Cursed theme on/off." + Environment.NewLine + "Epilepsy Warning!", new Tags());
		Mod.AddToList("Season", true, 1, "Turns the Seasonal theme on/off.", new Tags());
		Mod.AddToList("Cherry", false, 1, "Turns the Cherry theme on/off.", new Tags());
		Mod.SetLinkGroup(1, "Themes");
		Mod.GetFromFile();
		Mod.ModSaved += OnSaveOrInit;
		UI.instance.AddMod(Mod);
		MelonLoggerExtension.Log("Added Mod.");
	}

	private void WaitAfterInit()
	{
		LoadDelay.Start(6.0, false, (Action)delegate
		{
			OnSaveOrInit();
		});
	}

	private void OnSaveOrInit()
	{
		//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
		if (Shading.Coroutine != null)
		{
			MelonCoroutines.Stop(Shading.Coroutine);
		}
		ApplySettings();
		switch (currentscene)
		{
		case "Gym":
			if (!(bool)Mod.Settings.Find((ModSetting x) => x.Name == "Grass").Value & Shading.Continuous)
			{
				GetObjects(ShrinkArray(ObjectStrings, 0, 5), ObjectStrings[11]);
			}
			else
			{
				GetObjects(ShrinkArray(ObjectStrings, 0, 5), ObjectStrings[11], ObjectStrings[6]);
			}
			break;
		case "Park":
			GetObjects(ShrinkArray(ObjectStrings, 7, 10), ObjectStrings[11]);
			break;
		case "Map0":
			GetObjects(ShrinkArray(ObjectStrings, 12, 12), ObjectStrings[14]);
			break;
		case "Map1":
			GetObjects(ShrinkArray(ObjectStrings, 13, 13), ObjectStrings[14]);
			break;
		}
		if (Shading.Continuous)
		{
			Shading.Coroutine = MelonCoroutines.Start(ContinuousShading());
			return;
		}
		Shading.ApplyShadingbyColor(Shading.Static_Color);
		ChangeProperties();
	}

	private IEnumerator ContinuousShading()
	{
		WaitForFixedUpdate waitForFixedUpdate = new WaitForFixedUpdate();
		int FrameCounter = Shading.FrameDelay;
		while (true)
		{
			if (FrameCounter >= Shading.FrameDelay)
			{
				Shading.ContinuousShading();
				ChangeProperties();
				FrameCounter = 0;
			}
			FrameCounter++;
			yield return waitForFixedUpdate;
		}
	}

	private void ApplySettings()
	{
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_018c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: Unknown result type (might be due to invalid IL or missing references)
		//IL_0199: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_017e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: Unknown result type (might be due to invalid IL or missing references)
		string text = "";
		foreach (ModSetting setting in Mod.Settings)
		{
			if (setting.LinkGroup == 1 && (bool)setting.Value)
			{
				text = setting.Name;
				break;
			}
		}
		switch (text)
		{
		case "RGB":
			Shading.Continuous = true;
			Shading.ContinuousType = text;
			Shading.FrameDelay = 10;
			break;
		case "Cursed":
			Shading.Continuous = true;
			Shading.ContinuousType = text;
			Shading.FrameDelay = 5;
			break;
		case "Cherry":
			Shading.Continuous = false;
			Shading.Static_Color = color_cust_cherry;
			break;
		case "Season":
			Shading.Continuous = false;
			switch (DateTime.Now.Month)
			{
			case 1:
			case 2:
			case 3:
			case 12:
				Shading.Static_Color = color_wntr_lghblu;
				break;
			case 4:
				if (DateTime.Now.Day == 1)
				{
					Shading.Static_Color = new Color(1f, 0f, 1f, 1f);
				}
				break;
			case 5:
			case 6:
				Shading.Static_Color = color_sumr_lshgrn;
				break;
			case 7:
			case 8:
				Shading.Static_Color = color_sumr_drkgrn;
				break;
			case 9:
				Shading.Static_Color = color_fall_yellow;
				break;
			case 10:
				Shading.Static_Color = color_fall_orange;
				break;
			case 11:
				Shading.Static_Color = color_fall_drkred;
				break;
			}
			break;
		default:
			Application.Quit();
			break;
		}
	}

	private void GetObjects(string[] Trees, string VFX = "", string Grass = "")
	{
		Mat_Trees.Clear();
		Mat_Grass.Clear();
		GO_VFX = null;
		VFX_VFX = null;
		foreach (string text in Trees)
		{
			Mat_Trees.Add(((Renderer)GameObject.Find(text).GetComponent<MeshRenderer>()).material);
		}
		if (debug)
		{
			MelonLogger.Msg("Mat_Tree get");
		}
		if (VFX != "")
		{
			GO_VFX = GameObject.Find(VFX);
			VFX_VFX = ((Component)GO_VFX.transform.GetChild(0)).gameObject.GetComponent<VisualEffect>();
			Shading.gradient = VFX_VFX.GetGradient(977);
		}
		if (debug)
		{
			MelonLogger.Msg("GO_VFX get");
		}
		if (Grass != "")
		{
			for (int j = 0; j < GameObject.Find(Grass).transform.GetChildCount(); j++)
			{
				Mat_Grass.Add(((Renderer)((Component)GameObject.Find(Grass).transform.GetChild(j)).GetComponent<MeshRenderer>()).material);
				Mat_Grass.Add(((Renderer)((Component)GameObject.Find(Grass).transform.GetChild(j).GetChild(0)).GetComponent<MeshRenderer>()).material);
			}
			if (debug)
			{
				MelonLogger.Msg("Mat_Grass get");
			}
		}
	}

	private void ChangeProperties()
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
		Enumerator<Material> enumerator = Mat_Trees.GetEnumerator();
		while (enumerator.MoveNext())
		{
			Material current = enumerator.Current;
			current.SetColor(1365, Shading.shades[2]);
			current.SetColor(1366, Shading.shades[0]);
			current.SetColor(1359, Shading.shades[2]);
			current.SetColor(1361, Shading.shades[0]);
		}
		if (debug)
		{
			MelonLogger.Msg("Applied Shading - Tree");
		}
		if ((Object)(object)GO_VFX != (Object)null)
		{
			Shading.keys[0].color = Shading.shades[1];
			Shading.keys[1].color = Shading.shades[1];
			Shading.gradient.colorKeys = Il2CppStructArray<GradientColorKey>.op_Implicit(Shading.keys);
			for (int i = 0; i < GO_VFX.transform.GetChildCount(); i++)
			{
				VFX_VFX = ((Component)GO_VFX.transform.GetChild(i)).gameObject.GetComponent<VisualEffect>();
				VFX_VFX.SetGradient(977, Shading.gradient);
			}
			if (debug)
			{
				MelonLogger.Msg("Applied Shading - VFX");
			}
		}
		if (Mat_Grass.Count > 0)
		{
			Enumerator<Material> enumerator2 = Mat_Grass.GetEnumerator();
			while (enumerator2.MoveNext())
			{
				Material current2 = enumerator2.Current;
				current2.SetColor(1340, Shading.shades[1]);
				current2.SetColor(1342, Shading.shades[0]);
				current2.SetColor(1347, Shading.shades[1]);
				current2.SetColor(1349, Shading.shades[0]);
			}
		}
	}

	private string[] ShrinkArray(string[] Input, int From, int To)
	{
		string[] array = new string[To - From + 1];
		for (int i = From; i <= To; i++)
		{
			array[i - From] = Input[i];
		}
		return array;
	}

	public override void OnSceneWasUnloaded(int buildIndex, string sceneName)
	{
		((MelonMod)this).OnSceneWasUnloaded(buildIndex, sceneName);
		if (Shading.Coroutine != null)
		{
			MelonCoroutines.Stop(Shading.Coroutine);
		}
	}

	public override void OnSceneWasLoaded(int buildIndex, string sceneName)
	{
		((MelonMod)this).OnSceneWasLoaded(buildIndex, sceneName);
		currentscene = sceneName;
	}
}
internal static class Shading
{
	internal static int LoopVar;

	internal static bool Continuous;

	internal static int FrameDelay;

	internal static string ContinuousType;

	internal static object Coroutine;

	internal static Random Random = new Random();

	internal static Color Static_Color = new Color(1f, 1f, 1f, 1f);

	internal static Gradient gradient;

	internal static GradientColorKey[] keys = (GradientColorKey[])(object)new GradientColorKey[2];

	internal static Color[] shades = (Color[])(object)new Color[3];

	internal static void ApplyShadingbyColor(Color Base)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		float num = default(float);
		float num2 = default(float);
		float num3 = default(float);
		Color.RGBToHSV(Base, ref num, ref num2, ref num3);
		if (num2 > 0.9f)
		{
			num2 = 0.9f;
		}
		if (num2 < 0.1f)
		{
			num2 = 0.1f;
		}
		if (num3 > 0.9f)
		{
			num3 = 0.9f;
		}
		if (num3 < 0.1f)
		{
			num3 = 0.1f;
		}
		shades[0] = Color.HSVToRGB(num, num2 - 0.1f, num3 - 0.1f);
		shades[1] = Color.HSVToRGB(num, num2, num3);
		shades[2] = Color.HSVToRGB(num, num2 + 0.1f, num3 + 0.1f);
	}

	internal static void ContinuousShading()
	{
		string continuousType = ContinuousType;
		string text = continuousType;
		if (!(text == "RGB"))
		{
			if (text == "Cursed")
			{
				ApplyShadingbyHue(Random.Next(0, 360));
			}
			return;
		}
		if (LoopVar >= 360)
		{
			LoopVar = 0;
		}
		ApplyShadingbyHue(LoopVar);
		LoopVar++;
	}

	private static void ApplyShadingbyHue(float Hue)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: 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)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		shades[0] = Color.HSVToRGB(Hue / 360f, 1f, 1f);
		shades[1] = Color.HSVToRGB(Hue / 360f, 0.66f, 0.66f);
		shades[2] = Color.HSVToRGB(Hue / 360f, 0.33f, 0.33f);
	}
}