Decompiled source of ShiftedStones v1.2.0

Mods/ShiftedStones.dll

Decompiled 6 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppRUMBLE.Combat.ShiftStones;
using MelonLoader;
using Microsoft.CodeAnalysis;
using RumbleModUI;
using RumbleModdingAPI.RMAPI;
using ShiftedStones;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Core), "ShiftedStones", "1.2.0", "Orangenal", null)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("ShiftedStones")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+23c4ee409ba42f782deda60cd8792f5c856b46ec")]
[assembly: AssemblyProduct("ShiftedStones")]
[assembly: AssemblyTitle("ShiftedStones")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 ShiftedStones
{
	public class Validation : ValidationParameters
	{
		public override bool DoValidation(string Input)
		{
			string pattern = "^(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)\\s(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)\\s(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)$";
			string pattern2 = "^#?[0-9A-Fa-f]{6}$";
			if (Regex.IsMatch(Input, pattern) || Regex.IsMatch(Input, pattern2) || Input.ToLower() == "vanilla")
			{
				return true;
			}
			return false;
		}
	}
	public class Core : MelonMod
	{
		internal static Mod mod = new Mod();

		public static Material[] originalMaterials = (Material[])(object)new Material[8];

		public static Material[] clonedMaterials = (Material[])(object)new Material[8];

		internal static string[] shiftstoneOrder = new string[8] { "Flow Stone", "Vigor Stone", "Guard Stone", "Stubborn Stone", "Charge Stone", "Volatile Stone", "Surge Stone", "Adamant Stone" };

		internal static List<ShiftStone> loadedStones = new List<ShiftStone>();

		internal static List<MeshRenderer> customStones = new List<MeshRenderer>();

		internal static GameObject materialStorage;

		internal static Instance Logger;

		internal static List<ShiftStone> randomiserStones = new List<ShiftStone>();

		private bool hasRandomiser;

		public override void OnInitializeMelon()
		{
			//IL_004d: 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_005e: Expected O, but got Unknown
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Expected O, but got Unknown
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Expected O, but got Unknown
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Expected O, but got Unknown
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Expected O, but got Unknown
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Expected O, but got Unknown
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Expected O, but got Unknown
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Expected O, but got Unknown
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Expected O, but got Unknown
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Expected O, but got Unknown
			mod.ModName = ((MelonBase)this).Info.Name;
			mod.ModVersion = ((MelonBase)this).Info.Version;
			mod.SetFolder("ShiftedStones");
			mod.AddDescription("Description", "", "A mod that lets you recolour shiftstones!", new Tags
			{
				IsSummary = true
			});
			mod.AddToList("Flow", "Vanilla", "Colour of the flow stone\n\nAccepts colours formatted as hex codes (e.g. #FF00CC) or 3 RGB values (e.g. 255 165 0)", new Tags());
			mod.AddToList("Vigor", "Vanilla", "Colour of the vigor stone\n\nAccepts colours formatted as hex codes (e.g. #FF00CC) or 3 RGB values (e.g. 255 165 0)", new Tags());
			mod.AddToList("Guard", "Vanilla", "Colour of the guard stone\n\nAccepts colours formatted as hex codes (e.g. #FF00CC) or 3 RGB values (e.g. 255 165 0)", new Tags());
			mod.AddToList("Stubborn", "Vanilla", "Colour of the stubborn stone\n\nAccepts colours formatted as hex codes (e.g. #FF00CC) or 3 RGB values (e.g. 255 165 0)", new Tags());
			mod.AddToList("Charge", "Vanilla", "Colour of the charge stone\n\nAccepts colours formatted as hex codes (e.g. #FF00CC) or 3 RGB values (e.g. 255 165 0)", new Tags());
			mod.AddToList("Volatile", "Vanilla", "Colour of the volatile stone\n\nAccepts colours formatted as hex codes (e.g. #FF00CC) or 3 RGB values (e.g. 255 165 0)", new Tags());
			mod.AddToList("Surge", "Vanilla", "Colour of the surge stone\n\nAccepts colours formatted as hex codes (e.g. #FF00CC) or 3 RGB values (e.g. 255 165 0)", new Tags());
			mod.AddToList("Adamant", "Vanilla", "Colour of the adamant stone\n\nAccepts colours formatted as hex codes (e.g. #FF00CC) or 3 RGB values (e.g. 255 165 0)", new Tags());
			foreach (ModSetting setting in mod.Settings)
			{
				if (!setting.Tags.IsSummary)
				{
					setting.SavedValueChanged += OnSave;
					mod.AddValidation(setting.Name, (ValidationParameters)(object)new Validation());
				}
			}
			mod.GetFromFile();
			UI.instance.UI_Initialized += OnUIInit;
			materialStorage = new GameObject();
			((Object)materialStorage).name = "Shiftstone material storage";
			Object.DontDestroyOnLoad((Object)(object)materialStorage);
			Logger = ((MelonBase)this).LoggerInstance;
			((MelonBase)this).LoggerInstance.Msg("Initialised.");
		}

		public override void OnLateInitializeMelon()
		{
			hasRandomiser = Mods.findOwnMod("ShiftStoneRandomizer", "0.0.0", false);
		}

		private void OnUIInit()
		{
			UI.instance.AddMod(mod);
		}

		public static string GetPath(GameObject obj)
		{
			string text = ((Object)obj).name;
			Transform parent = obj.transform.parent;
			while ((Object)(object)parent != (Object)null)
			{
				text = ((Object)parent).name + "/" + text;
				parent = parent.parent;
			}
			return text;
		}

		private void OnSave(object sender = null, EventArgs e = null)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			if (loadedStones.Count == 0 || !mod.GetUIStatus())
			{
				return;
			}
			string name = ((ModSetting)sender).Name;
			ShiftStone[] array = loadedStones.Where((ShiftStone s) => s.StoneName == name + " Stone").ToArray();
			string value = ((ValueChange<string>)(object)e).Value;
			if (hasRandomiser)
			{
				customStones.RemoveAll((MeshRenderer r) => (Object)(object)((Component)r).GetComponentInParent<ShiftStone>() == (Object)null);
				Il2CppArrayBase<ShiftStone> val = null;
				switch (Scene.GetSceneName())
				{
				case "Gym":
					val = ShiftstoneQuickswapper.GetGameObject().GetComponentsInChildren<ShiftStone>(true);
					break;
				case "Park":
					val = ShiftstoneQuickswapper.GetGameObject().GetComponentsInChildren<ShiftStone>(true);
					break;
				case "Map0":
					if (Players.GetAllPlayers().Count > 1)
					{
						val = ShiftstoneQuickswapper.GetGameObject().GetComponentsInChildren<ShiftStone>(true);
						((IEnumerable<ShiftStone>)val).Concat((IEnumerable<ShiftStone>)ShiftstoneQuickswapper.GetGameObject().GetComponentsInChildren<ShiftStone>(true));
					}
					break;
				case "Map1":
					if (Players.GetAllPlayers().Count > 1)
					{
						val = ShiftstoneQuickswapper.GetGameObject().GetComponentsInChildren<ShiftStone>(true);
						((IEnumerable<ShiftStone>)val).Concat((IEnumerable<ShiftStone>)ShiftstoneQuickswapper.GetGameObject().GetComponentsInChildren<ShiftStone>(true));
					}
					break;
				}
				foreach (ShiftStone item in val)
				{
					foreach (MeshRenderer componentsInChild in ((Component)item).GetComponentsInChildren<MeshRenderer>())
					{
						if (((Object)((Component)componentsInChild).gameObject).name.Contains("%") && !customStones.Contains(componentsInChild))
						{
							customStones.Add(componentsInChild);
						}
					}
					if (item.StoneName == name + " Stone")
					{
						array = CollectionExtensions.AddItem<ShiftStone>((IEnumerable<ShiftStone>)array, item).ToArray();
					}
				}
			}
			customStones.RemoveAll((MeshRenderer r) => (Object)(object)((Component)r).GetComponentInParent<ShiftStone>() == (Object)null);
			foreach (MeshRenderer item2 in customStones.Where((MeshRenderer r) => ((Object)((Component)((Component)r).GetComponentInParent<ShiftStone>()).gameObject).name.Replace("(Clone)", "") == name + "Stone"))
			{
				if (value.ToLower() == "vanilla" && customStones.Count > 0)
				{
					((Renderer)item2).material = originalMaterials[((ReadOnlySpan<string>)shiftstoneOrder).IndexOf(name + " Stone")];
					continue;
				}
				((Renderer)item2).material = clonedMaterials[((ReadOnlySpan<string>)shiftstoneOrder).IndexOf(name + " Stone")];
				Material material = ((Renderer)item2).material;
				ShiftstonePatch.setColours(value, ref material);
			}
			for (int i = 0; i < array.Count(); i++)
			{
				if (!((Object)(object)array[i] == (Object)null) && array.Contains(array[i]))
				{
					MeshRenderer component = ((Component)((Component)array[i]).transform.GetChild(0)).GetComponent<MeshRenderer>();
					Material material2 = ((Renderer)component).material;
					if (value.ToLower() == "vanilla")
					{
						((Renderer)component).material = originalMaterials[((ReadOnlySpan<string>)shiftstoneOrder).IndexOf(name + " Stone")];
					}
					else
					{
						ShiftstonePatch.setColours(value, ref material2);
					}
				}
			}
		}

		public override void OnSceneWasUnloaded(int buildIndex, string sceneName)
		{
			loadedStones = new List<ShiftStone>();
			customStones = new List<MeshRenderer>();
			randomiserStones = new List<ShiftStone>();
		}
	}
	[HarmonyPatch(typeof(ShiftStone), "OnFetchFromPool")]
	internal static class ShiftstonePatch
	{
		internal static void setColours(string colourStr, ref Material material)
		{
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: 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)
			colourStr = colourStr.Replace("#", "");
			colourStr = colourStr.Replace("0x", "");
			Color val = default(Color);
			if (colourStr.Contains(" "))
			{
				string[] array = colourStr.Split(' ');
				if (array.Length != 3 || !byte.TryParse(array[0], out var result) || !byte.TryParse(array[1], out var result2) || !byte.TryParse(array[2], out var result3))
				{
					Core.Logger.Error("Somehow not a valid colour");
					throw new Exception("Provided string is not in a valid format.");
				}
				((Color)(ref val))..ctor((float)(int)result / 255f, (float)(int)result2 / 255f, (float)(int)result3 / 255f);
			}
			else
			{
				if (colourStr.Length != 6 || !int.TryParse(colourStr, NumberStyles.HexNumber, null, out var result4))
				{
					Core.Logger.Error("Somehow not a valid colour");
					throw new Exception("Provided string is not in a valid format.");
				}
				float num = (float)((result4 >> 16) & 0xFF) / 255f;
				float num2 = (float)((result4 >> 8) & 0xFF) / 255f;
				float num3 = (float)(result4 & 0xFF) / 255f;
				((Color)(ref val))..ctor(num, num2, num3);
			}
			material.SetColor("_Core_Color", val);
			material.SetColor("_Edge_Color", val);
			float num4 = default(float);
			float num5 = default(float);
			float num6 = default(float);
			Color.RGBToHSV(val, ref num4, ref num5, ref num6);
			material.SetColor("_Base_Color", Color.HSVToRGB(num4, num5 * 3f / 4f, num6 * 3f / 4f));
			material.SetColor("_Shadow_Color", Color.HSVToRGB(num4, num5 * 1f / 2f, num6 * 1f / 2f));
		}

		[HarmonyBefore(new string[] { "ShifstoneModels, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null:Custom Shiftstone Models" })]
		private static void Postfix(ref ShiftStone __instance)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Expected O, but got Unknown
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			int num = ((ReadOnlySpan<string>)Core.shiftstoneOrder).IndexOf(__instance.StoneName);
			MeshRenderer component = ((Component)((Component)__instance).transform.GetChild(0)).GetComponent<MeshRenderer>();
			if ((Object)(object)Core.originalMaterials[num] == (Object)null)
			{
				Core.originalMaterials[num] = new Material(((Renderer)component).material);
				GameObject obj = GameObject.CreatePrimitive((PrimitiveType)0);
				((Renderer)obj.GetComponent<MeshRenderer>()).material = Core.originalMaterials[num];
				((Object)obj).name = "Material Copy";
				obj.transform.parent = Core.materialStorage.transform;
				obj.transform.position = new Vector3(10000f, 10000f, 10000f);
			}
			if ((Object)(object)Core.clonedMaterials[num] == (Object)null)
			{
				Core.clonedMaterials[num] = new Material(((Renderer)component).material);
				GameObject obj2 = GameObject.CreatePrimitive((PrimitiveType)0);
				((Renderer)obj2.GetComponent<MeshRenderer>()).material = Core.clonedMaterials[num];
				((Object)obj2).name = "Material Copy";
				obj2.transform.parent = Core.materialStorage.transform;
				obj2.transform.position = new Vector3(10000f, 10000f, 10000f);
				if (((string)Core.mod.Settings[num + 1].SavedValue).ToLower() != "vanilla")
				{
					setColours((string)Core.mod.Settings[num + 1].SavedValue, ref Core.clonedMaterials[num]);
				}
			}
			((Renderer)component).material = ((((string)Core.mod.Settings[num + 1].SavedValue).ToLower() != "vanilla") ? Core.clonedMaterials : Core.originalMaterials)[num];
			if (!Core.loadedStones.Contains(__instance))
			{
				Core.loadedStones.Add(__instance);
			}
		}

		[HarmonyAfter(new string[] { "ShifstoneModels, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null:Custom Shiftstone Models" })]
		[HarmonyPostfix]
		private static void AddCustomModelRenderers(ref ShiftStone __instance)
		{
			if (((Component)__instance).transform.childCount <= 2)
			{
				return;
			}
			foreach (MeshRenderer componentsInChild in ((Component)__instance).GetComponentsInChildren<MeshRenderer>())
			{
				if (((Object)((Component)componentsInChild).gameObject).name.Contains("%"))
				{
					Core.customStones.Add(componentsInChild);
				}
			}
		}
	}
}