Decompiled source of PPP INSC UI OVERHAUL v1.1.14

plugins/PPP_INSC_UI_MOD.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using DiskCardGame;
using GBC;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("PPP_INSC_UI_MOD")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PPP_INSC_UI_MOD")]
[assembly: AssemblyTitle("PPP_INSC_UI_MOD")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace PPP_INSC_UI_MOD;

[BepInPlugin("PPP.INSC.Overhaul", "PPP UI Overhaul", "1.1.14")]
public class MyPlugin : BaseUnityPlugin
{
	public static Color ThemeColor = new Color(0f, 0.6f, 0.3f);

	public static Color BrightThemeColor = new Color(0f, 0.9f, 0.5f);

	public static Color NeonHighlight = new Color(0f, 1f, 0.8f);

	public static string ReplacementName = "CLOVER";

	public static string PreviousName = "KAYCEE";

	public static string ConfigPath => Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "config.txt");

	private void Awake()
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		LoadCustomConfig();
		new Harmony("com.ppp.inscryption.uitheme").PatchAll();
	}

	private void Update()
	{
		if (Input.GetMouseButtonDown(1))
		{
			PreviousName = ReplacementName;
			LoadCustomConfig();
			AscensionMenuScreens val = Object.FindObjectOfType<AscensionMenuScreens>();
			if ((Object)(object)val != (Object)null)
			{
				((MonoBehaviour)val).StartCoroutine(CoreSystemPatches.DeepRefresh(((Component)val).gameObject));
			}
		}
	}

	public static void LoadCustomConfig()
	{
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		if (!File.Exists(ConfigPath))
		{
			return;
		}
		try
		{
			string[] array = File.ReadAllLines(ConfigPath);
			if (array.Length >= 4)
			{
				Color themeColor = default(Color);
				if (ColorUtility.TryParseHtmlString(array[0].Trim(), ref themeColor))
				{
					ThemeColor = themeColor;
				}
				Color brightThemeColor = default(Color);
				if (ColorUtility.TryParseHtmlString(array[1].Trim(), ref brightThemeColor))
				{
					BrightThemeColor = brightThemeColor;
				}
				Color neonHighlight = default(Color);
				if (ColorUtility.TryParseHtmlString(array[2].Trim(), ref neonHighlight))
				{
					NeonHighlight = neonHighlight;
				}
				string text = array[3].Trim();
				if (!string.IsNullOrEmpty(text))
				{
					ReplacementName = text;
				}
			}
		}
		catch (Exception)
		{
		}
	}
}
[HarmonyPatch]
public class CoreSystemPatches
{
	[CompilerGenerated]
	private sealed class <DeepRefresh>d__7 : IEnumerator<object>, IEnumerator, IDisposable
	{
		private int <>1__state;

		private object <>2__current;

		public GameObject root;

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

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

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

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

		private bool MoveNext()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<>2__current = (object)new WaitForEndOfFrame();
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				if ((Object)(object)root != (Object)null)
				{
					ForceThemeRecursive(root.transform);
				}
				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();
		}
	}

	[HarmonyPatch(typeof(GameColors), "get_Instance")]
	[HarmonyPostfix]
	private static void GlobalPalette(ref GameColors __result)
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: 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_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)__result == (Object)null))
		{
			__result.red = MyPlugin.ThemeColor;
			__result.darkRed = MyPlugin.ThemeColor;
			__result.brightRed = MyPlugin.ThemeColor;
			__result.glowRed = MyPlugin.ThemeColor;
			__result.orange = MyPlugin.ThemeColor;
		}
	}

	[HarmonyPatch(typeof(PixelText), "SetText", new Type[]
	{
		typeof(string),
		typeof(bool)
	})]
	[HarmonyPrefix]
	private static void PixelTextContent(ref string text)
	{
		if (text != null)
		{
			if (text.Contains("KAYCEE"))
			{
				text = text.Replace("KAYCEE", MyPlugin.ReplacementName);
			}
			if (text.Contains(MyPlugin.PreviousName))
			{
				text = text.Replace(MyPlugin.PreviousName, MyPlugin.ReplacementName);
			}
		}
	}

	[HarmonyPatch(typeof(PixelText), "SetColor")]
	[HarmonyPrefix]
	private static void PixelTextColor(ref Color c)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		c = MyPlugin.ThemeColor;
	}

	[HarmonyPatch(typeof(AscensionMenuBlinkEffect), "SetBlinkingEnabled")]
	[HarmonyPrefix]
	private static void KillFlicker(AscensionMenuBlinkEffect __instance)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: 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)
		__instance.blinkOnColor = MyPlugin.BrightThemeColor;
		__instance.blinkOffColor = MyPlugin.ThemeColor;
		FieldInfo field = ((object)__instance).GetType().GetField("lightColor", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		if (field != null)
		{
			field.SetValue(__instance, MyPlugin.ThemeColor);
		}
		object? obj = AccessTools.Field(typeof(AscensionMenuBlinkEffect), "backRenderer")?.GetValue(__instance);
		SpriteRenderer val = (SpriteRenderer)((obj is SpriteRenderer) ? obj : null);
		if ((Object)(object)val != (Object)null)
		{
			val.color = MyPlugin.ThemeColor;
		}
	}

	[HarmonyPatch(typeof(AscensionStarterDeckIcon), "AssignInfo")]
	[HarmonyPostfix]
	private static void DeckIconVisuals(AscensionStarterDeckIcon __instance)
	{
		//IL_001c: 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)
		AccessTools.Field(typeof(AscensionStarterDeckIcon), "defaultColor")?.SetValue(__instance, MyPlugin.BrightThemeColor);
		object? obj = AccessTools.Field(typeof(AscensionStarterDeckIcon), "conqueredRenderer")?.GetValue(__instance);
		SpriteRenderer val = (SpriteRenderer)((obj is SpriteRenderer) ? obj : null);
		if ((Object)(object)val != (Object)null)
		{
			val.color = MyPlugin.NeonHighlight;
		}
	}

	[HarmonyPatch(typeof(AscensionMenuScreens), "SwitchToScreen")]
	[HarmonyPostfix]
	private static void RefreshOnSwitch(AscensionMenuScreens __instance)
	{
		((MonoBehaviour)__instance).StartCoroutine(DeepRefresh(((Component)__instance).gameObject));
	}

	[HarmonyPatch(typeof(AscensionMenuScreens), "Start")]
	[HarmonyPostfix]
	private static void RefreshOnStart(AscensionMenuScreens __instance)
	{
		((MonoBehaviour)__instance).StartCoroutine(DeepRefresh(((Component)__instance).gameObject));
	}

	[IteratorStateMachine(typeof(<DeepRefresh>d__7))]
	public static IEnumerator DeepRefresh(GameObject root)
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <DeepRefresh>d__7(0)
		{
			root = root
		};
	}

	private static void ForceThemeRecursive(Transform parent)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Expected O, but got Unknown
		//IL_00c7: 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_00f2: Unknown result type (might be due to invalid IL or missing references)
		TextMeshProUGUI val2 = default(TextMeshProUGUI);
		PixelText val3 = default(PixelText);
		SpriteRenderer val4 = default(SpriteRenderer);
		foreach (Transform item in parent)
		{
			Transform val = item;
			if (((Component)val).TryGetComponent<TextMeshProUGUI>(ref val2))
			{
				if (((TMP_Text)val2).text != null)
				{
					if (((TMP_Text)val2).text.Contains("KAYCEE"))
					{
						((TMP_Text)val2).text = ((TMP_Text)val2).text.Replace("KAYCEE", MyPlugin.ReplacementName);
					}
					if (((TMP_Text)val2).text.Contains(MyPlugin.PreviousName))
					{
						((TMP_Text)val2).text = ((TMP_Text)val2).text.Replace(MyPlugin.PreviousName, MyPlugin.ReplacementName);
					}
				}
				((Graphic)val2).color = MyPlugin.ThemeColor;
				((TMP_Text)val2).overrideColorTags = true;
			}
			if (((Component)val).TryGetComponent<PixelText>(ref val3))
			{
				val3.SetColor(MyPlugin.ThemeColor);
				val3.SetText(val3.Text, false);
			}
			if (((Component)val).TryGetComponent<SpriteRenderer>(ref val4))
			{
				val4.color = MyPlugin.BrightThemeColor;
			}
			if (val.childCount > 0)
			{
				ForceThemeRecursive(val);
			}
		}
	}
}