Decompiled source of Clearwater ToolbarTweaks v0.6.2

BepInEx/Atlyss-UiTweaks/Clearwater-ToolbarTweaks.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Mirror;
using Nessie.ATLYSS.EasySettings;
using Nessie.ATLYSS.EasySettings.UIElements;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
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: AssemblyTitle("ATLYSS_Template")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ATLYSS_Template")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("A4FDB1E9-D3B5-4F4C-AC3F-532ED2D1FBC6")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ATLYSS_UiTweaks
{
	public static class CommonFunctions
	{
		[CompilerGenerated]
		private sealed class <WaitforSeconds>d__2 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public float seconds;

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

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

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

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

			private bool MoveNext()
			{
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_0031: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(seconds);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					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 static string getSceneName()
		{
			//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)
			Scene activeScene = SceneManager.GetActiveScene();
			return ((Scene)(ref activeScene)).name;
		}

		public static GameObject GetInactiveRootObject(string objectName)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			List<GameObject> list = new List<GameObject>();
			Scene activeScene = SceneManager.GetActiveScene();
			((Scene)(ref activeScene)).GetRootGameObjects(list);
			foreach (GameObject item in list)
			{
				if (((Object)item).name == objectName)
				{
					return item;
				}
			}
			return null;
		}

		[IteratorStateMachine(typeof(<WaitforSeconds>d__2))]
		public static IEnumerator WaitforSeconds(float seconds)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <WaitforSeconds>d__2(0)
			{
				seconds = seconds
			};
		}

		public static GameObject GetGameObjectChild(GameObject parentObject, string childToFind)
		{
			if ((Object)(object)parentObject.transform.Find(childToFind) != (Object)null)
			{
				return ((Component)parentObject.transform.Find(childToFind)).gameObject;
			}
			return null;
		}

		public static Text GetTextfromGameObject(GameObject objectToUse)
		{
			return objectToUse.GetComponent<Text>();
		}
	}
	public static class Fields
	{
		public static int previousExp;
	}
	public static class Logging
	{
		public static ManualLogSource PluginLogger = Logger.CreateLogSource("Atlyss Toolbar Tweaks");

		public static void Debug(string text)
		{
			PluginLogger.LogDebug((object)text);
		}

		public static void Message(string text)
		{
			PluginLogger.LogMessage((object)text);
		}

		public static void Warn(string text)
		{
			PluginLogger.LogWarning((object)text);
		}

		public static void Error(string text)
		{
			PluginLogger.LogError((object)text);
		}

		public static void Fatal(string text)
		{
			PluginLogger.LogFatal((object)text);
		}

		public static void Info(string text)
		{
			PluginLogger.LogInfo((object)text);
		}
	}
	[BepInPlugin("clearwater.atlyss.uitweaks", "Atlyss Toolbar Tweaks", "1.1.0")]
	public class Main : BaseUnityPlugin
	{
		public const string pluginId = "clearwater.atlyss.uitweaks";

		public const string pluginName = "Atlyss Toolbar Tweaks";

		public const string pluginVersion = "1.1.0";

		public ConfigFile ModSettingsFile = new ConfigFile(Path.Combine("BepInEx", "config", "clearwaterTweaks.cfg"), true);

		private void Awake()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			Logging.Message("-- LOADING Atlyss Toolbar Tweaks--");
			Harmony val = new Harmony("clearwater.atlyss.uitweaks");
			val.PatchAll();
			Settings.OnInitialized.AddListener(new UnityAction(InitModSettings));
			Settings.OnApplySettings.AddListener((UnityAction)delegate
			{
				ApplySettings();
			});
		}

		public void ApplySettings()
		{
			Logging.Message("Saving mod settings");
			ModSettings.toggleXPToLevelDisplay = ModSettings.toggleXPToLevelDisplayToggle.Toggle.isOn;
			ModSettings.toggleEnemyHP = ModSettings.toggleEnemyHPToggle.Toggle.isOn;
			ModSettings.toggleEnemyHPCritical = ModSettings.toggleEnemyHPCriticalToggle.Toggle.isOn;
			ModSettings.toggleActionCooldown = ModSettings.toggleActionCooldownToggle.Toggle.isOn;
			SaveToConfigFile();
		}

		public void SaveToConfigFile()
		{
			((BaseUnityPlugin)this).Config.Bind<bool>("CTT", "toggleXPToLevelDisplay", true, (ConfigDescription)null).Value = ModSettings.toggleXPToLevelDisplayToggle.Toggle.isOn;
			((BaseUnityPlugin)this).Config.Bind<bool>("CTT", "toggleEnemyHP", true, (ConfigDescription)null).Value = ModSettings.toggleEnemyHPToggle.Toggle.isOn;
			((BaseUnityPlugin)this).Config.Bind<bool>("CTT", "toggleEnemyHPCritical", true, (ConfigDescription)null).Value = ModSettings.toggleEnemyHPCriticalToggle.Toggle.isOn;
			((BaseUnityPlugin)this).Config.Bind<bool>("CTT", "toggleActionCooldown", true, (ConfigDescription)null).Value = ModSettings.toggleActionCooldownToggle.Toggle.isOn;
			((BaseUnityPlugin)this).Config.Save();
		}

		public void InitModSettings()
		{
			ModSettings.toggleXPToLevelDisplay = ((BaseUnityPlugin)this).Config.Bind<bool>("CTT", "toggleXPToLevelDisplay", true, (ConfigDescription)null).Value;
			ModSettings.toggleEnemyHP = ((BaseUnityPlugin)this).Config.Bind<bool>("CTT", "toggleEnemyHP", true, (ConfigDescription)null).Value;
			ModSettings.toggleEnemyHPCritical = ((BaseUnityPlugin)this).Config.Bind<bool>("CTT", "toggleEnemyHPCritical", true, (ConfigDescription)null).Value;
			ModSettings.toggleActionCooldown = ((BaseUnityPlugin)this).Config.Bind<bool>("CTT", "toggleActionCooldown", true, (ConfigDescription)null).Value;
			ModSettings.toggleConsumableCooldown = ((BaseUnityPlugin)this).Config.Bind<bool>("CTT", "toggleConsumableCooldown", true, (ConfigDescription)null).Value;
			AddTweakSettings();
		}

		public void AddTweakSettings()
		{
			SettingsTab modTab = Settings.ModTab;
			modTab.AddHeader("Clearwater's Toolbar Tweaks");
			ModSettings.toggleXPToLevelDisplayToggle = modTab.AddToggle("Show XP to level up on toolbar", ModSettings.toggleXPToLevelDisplay);
			ModSettings.toggleEnemyHPToggle = modTab.AddToggle("Enemy HP numbers", ModSettings.toggleEnemyHP);
			ModSettings.toggleEnemyHPCriticalToggle = modTab.AddToggle("Enemy critical HP colors (requires Enemy HP numbers)", ModSettings.toggleEnemyHPCritical);
			ModSettings.toggleActionCooldownToggle = modTab.AddToggle("Action slot cooldown display", ModSettings.toggleActionCooldown);
		}
	}
	public static class ModSettings
	{
		public static bool toggleXPToLevelDisplay = true;

		public static bool toggleEnemyHP = true;

		public static bool toggleEnemyHPCritical = true;

		public static bool toggleActionCooldown = true;

		public static bool toggleConsumableCooldown = true;

		public static AtlyssToggle toggleXPToLevelDisplayToggle;

		public static AtlyssToggle toggleEnemyHPToggle;

		public static AtlyssToggle toggleEnemyHPCriticalToggle;

		public static AtlyssToggle toggleActionCooldownToggle;
	}
}
namespace ATLYSS_UiTweaks.Harmony_Patches
{
	[HarmonyPatch(typeof(Player), "Player_OnDeath")]
	public static class resetCooldownOnDeathPatch
	{
		[HarmonyPostfix]
		public static void resetSkillCooldownOnDeath(ref Player __instance)
		{
			if (!((NetworkBehaviour)__instance).isLocalPlayer)
			{
				return;
			}
			for (int i = 0; i < ActionBarManager._current._actionSlots.Length; i++)
			{
				GameObject gameObject = ((Component)ActionBarManager._current._actionSlots[i]).gameObject;
				GameObject gameObjectChild = CommonFunctions.GetGameObjectChild(gameObject, "CooldownText");
				if ((Object)(object)gameObjectChild != (Object)null)
				{
					gameObjectChild.GetComponent<Text>().text = "0.0";
					gameObjectChild.SetActive(false);
				}
			}
		}
	}
	[HarmonyPatch(typeof(QuickItemSlot), "Update")]
	public static class DisplayConsumableCoolDownInSecondsPatch
	{
		[HarmonyPostfix]
		public static void patchShowSecondsCooldown(ref QuickItemSlot __instance)
		{
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)Player._mainPlayer != (Object)null))
			{
				return;
			}
			GameObject gameObject = ((Component)__instance).gameObject;
			PlayerInventory pInventory = Player._mainPlayer._pInventory;
			GameObject gameObjectChild = CommonFunctions.GetGameObjectChild(gameObject, "CooldownText");
			if ((Object)(object)gameObject != (Object)null && (Object)(object)pInventory != (Object)null && (Object)(object)gameObjectChild != (Object)null)
			{
				for (int i = 0; i < pInventory._consumableBuffers.Count; i++)
				{
					if (((ScriptableItem)pInventory._consumableBuffers[i]._scriptableConsumable)._itemName == __instance._setItemName)
					{
						float bufferTimer = pInventory._consumableBuffers[i]._bufferTimer;
						if (bufferTimer > 0f && ModSettings.toggleConsumableCooldown)
						{
							gameObjectChild.GetComponent<Text>().text = bufferTimer.ToString("F1");
							gameObjectChild.SetActive(true);
						}
						else
						{
							gameObjectChild.SetActive(false);
						}
					}
					else
					{
						gameObjectChild.SetActive(false);
					}
				}
			}
			else
			{
				GameObject val = Object.Instantiate<GameObject>(CommonFunctions.GetGameObjectChild(gameObject, "_quickItemSlot_quantityCounter"), gameObject.transform);
				val.transform.localPosition = new Vector3(10f, 0f, 0f);
				((Graphic)val.GetComponent<Text>()).color = Color.white;
				((Object)val).name = "CooldownText";
				val.SetActive(false);
			}
		}
	}
	[HarmonyPatch(typeof(StatusEntityGUI), "Update")]
	public static class DisplayEnemyHPPatch
	{
		[HarmonyPostfix]
		public static void displayEnemyHPInBar(ref StatusEntityGUI __instance, ref Creep ____isCreep)
		{
			if (ModSettings.toggleEnemyHP && (Object)(object)____isCreep != (Object)null)
			{
				int maxHealth = ____isCreep._statStruct._maxHealth;
				int currentHealth = ____isCreep._statusEntity._currentHealth;
				bool flag = (float)currentHealth < (float)maxHealth * 0.3f;
				string text = (((Object)(object)____isCreep._scriptStatModifier != (Object)null) ? (____isCreep._scriptStatModifier._modifierTag + " ") : "");
				string text2 = "";
				if (ModSettings.toggleEnemyHPCritical)
				{
					text2 = (flag ? "<color=orange>" : "") + text + ____isCreep._scriptCreep._creepName + (flag ? "</color>" : "") + " (" + (flag ? "<color=orange>" : "") + currentHealth + (flag ? "</color>" : "") + "/" + maxHealth + ")";
				}
				else
				{
					string[] obj = new string[7]
					{
						text,
						____isCreep._scriptCreep._creepName,
						" (",
						null,
						null,
						null,
						null
					};
					int num = currentHealth;
					obj[3] = num.ToString();
					obj[4] = "/";
					obj[5] = maxHealth.ToString();
					obj[6] = ")";
					text2 = string.Concat(obj);
				}
				____isCreep._creepDisplayName = text2;
			}
		}
	}
	[HarmonyPatch(typeof(InGameUI), "Update")]
	public static class DisplayXPToNextLevelPatch
	{
		[HarmonyPostfix]
		public static void patchExpBar(ref InGameUI __instance, PlayerStats ____pStats, ref Text ____text_experienceCounter)
		{
			if (ModSettings.toggleXPToLevelDisplay && (Object)(object)__instance != (Object)null && (Object)(object)____pStats != (Object)null && (Object)(object)____text_experienceCounter != (Object)null)
			{
				StatsMenuCell val = Object.FindObjectOfType<StatsMenuCell>();
				if ((Object)(object)val != (Object)null && ____text_experienceCounter.text != "MAX")
				{
					int currentExp = ____pStats._currentExp;
					float num = ((TabMenuCell)val)._mainPlayer._pStats._statStruct._experience;
					float num2 = (float)currentExp / num * 100f;
					string text = string.Format("{0} ({1}%) | {2} to next level", currentExp, num2.ToString("F2"), (num - (float)currentExp).ToString());
					____text_experienceCounter.text = text;
					____text_experienceCounter.horizontalOverflow = (HorizontalWrapMode)1;
				}
			}
		}
	}
	[HarmonyPatch(typeof(ActionBarManager), "Update")]
	public static class DisplaySkillCooldownInSecondsPatch
	{
		[HarmonyPostfix]
		public static void patchShowSecondsCooldown(ref ActionBarManager __instance, ref ActionSlot[] ____actionSlots, PlayerCasting ____pCast)
		{
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			if (____actionSlots == null || !((Object)(object)____pCast != (Object)null) || !((Object)(object)__instance != (Object)null) || !ModSettings.toggleActionCooldown)
			{
				return;
			}
			for (int i = 0; i < ____actionSlots.Length; i++)
			{
				for (int j = 0; j < ____pCast._skillCoolDownSlots.Count; j++)
				{
					GameObject gameObject = ((Component)____actionSlots[i]).gameObject;
					GameObject gameObjectChild = CommonFunctions.GetGameObjectChild(gameObject, "CooldownText");
					if ((Object)(object)gameObjectChild != (Object)null)
					{
						List<ScriptableSkill> list = ____pCast._skillCoolDownSlots.Select((SkillCooldownSlot slot) => slot._scriptSkill).ToList();
						if (list.Contains(____actionSlots[i]._scriptSkill))
						{
							if ((Object)(object)____actionSlots[i]._scriptSkill == (Object)(object)____pCast._skillCoolDownSlots[j]._scriptSkill)
							{
								Text component = gameObjectChild.GetComponent<Text>();
								component.text = ____pCast._skillCoolDownSlots[j]._currentCooldown.ToString("F1");
								gameObjectChild.transform.position = gameObject.transform.position;
								gameObjectChild.transform.localPosition = new Vector3(40f, 0f, 0f);
								gameObjectChild.SetActive(____pCast._skillCoolDownSlots[j]._currentCooldown > 0.1f);
								if (____pCast._skillCoolDownSlots[j]._currentCooldown < 10f && gameObjectChild.transform.localPosition.x == 40f)
								{
									gameObjectChild.transform.localPosition = new Vector3(45f, 0f, 0f);
								}
							}
						}
						else
						{
							gameObjectChild.SetActive(false);
						}
					}
					else
					{
						GameObject val = Object.Instantiate<GameObject>(CommonFunctions.GetGameObjectChild(gameObject, "_actionSlot_hotKey"), gameObject.transform);
						((Object)val).name = "CooldownText";
						val.transform.position = gameObject.transform.position;
						val.transform.localPosition = new Vector3(40f, 0f, 0f);
						val.SetActive(false);
					}
				}
			}
		}
	}
	public static class UsernamePersistence
	{
		public static Dictionary<string, string> PersistentUsernames = new Dictionary<string, string>();
	}
}