Decompiled source of Clearwater ToolbarTweaks v0.5.0

BepInEx/Atlyss-UiTweaks/Clearwater-ToolbarTweaks.dll

Decompiled 2 weeks ago
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Threading.Tasks;
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
	{
		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;
		}

		public static IEnumerator WaitforSeconds(float seconds)
		{
			yield return (object)new WaitForSeconds(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.0.0")]
	public class Main : BaseUnityPlugin
	{
		public const string pluginId = "clearwater.atlyss.uitweaks";

		public const string pluginName = "Atlyss Toolbar Tweaks";

		public const string pluginVersion = "1.0.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.Warn("-- 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.Warn("Saving mod settings");
			ModSettings.toggleCharMemory = ModSettings.toggleCharMemoryToggle.Toggle.isOn;
			ModSettings.toggleXPToLevelDisplay = ModSettings.toggleXPToLevelDisplayToggle.Toggle.isOn;
			ModSettings.toggleEnemyHP = ModSettings.toggleEnemyHPToggle.Toggle.isOn;
			ModSettings.toggleEnemyHPCritical = ModSettings.toggleEnemyHPCriticalToggle.Toggle.isOn;
			ModSettings.toggleActionCooldown = ModSettings.toggleActionCooldownToggle.Toggle.isOn;
			ModSettings.toggleConsumableCooldown = ModSettings.toggleConsumableCooldownToggle.Toggle.isOn;
			SaveToConfigFile();
		}

		public void SaveToConfigFile()
		{
			((BaseUnityPlugin)this).Config.Bind<bool>("CTT", "toggleCharMemory", true, (ConfigDescription)null).Value = ModSettings.toggleCharMemoryToggle.Toggle.isOn;
			((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.Bind<bool>("CTT", "toggleConsumableCooldown", true, (ConfigDescription)null).Value = ModSettings.toggleConsumableCooldownToggle.Toggle.isOn;
			((BaseUnityPlugin)this).Config.Save();
		}

		public void InitModSettings()
		{
			ModSettings.toggleCharMemory = ((BaseUnityPlugin)this).Config.Bind<bool>("CTT", "toggleCharMemory", true, (ConfigDescription)null).Value;
			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.toggleCharMemoryToggle = modTab.AddToggle("Online character name memory", ModSettings.toggleCharMemory);
			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);
			ModSettings.toggleConsumableCooldownToggle = modTab.AddToggle("Consumable cooldown display", ModSettings.toggleConsumableCooldown);
		}

		public void onSceneLoaded(Scene scene, LoadSceneMode mode)
		{
		}
	}
	public static class ModSettings
	{
		public static bool toggleCharMemory = true;

		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 toggleCharMemoryToggle;

		public static AtlyssToggle toggleXPToLevelDisplayToggle;

		public static AtlyssToggle toggleEnemyHPToggle;

		public static AtlyssToggle toggleEnemyHPCriticalToggle;

		public static AtlyssToggle toggleActionCooldownToggle;

		public static AtlyssToggle toggleConsumableCooldownToggle;
	}
}
namespace ATLYSS_UiTweaks.Harmony_Patches
{
	[HarmonyPatch(typeof(Player), "Start")]
	public static class HandleNewPlayerConnectionPatch
	{
		[HarmonyPostfix]
		public static async void showNewPlayerConnection(Player __instance)
		{
			if (!ModSettings.toggleCharMemory)
			{
				return;
			}
			await Task.Delay(5000);
			if (((NetworkBehaviour)__instance).isLocalPlayer)
			{
				return;
			}
			string steamID = __instance._steamID;
			if (steamID.Length > 0 && UsernamePersistence.PersistentUsernames.ContainsKey(steamID))
			{
				if (UsernamePersistence.PersistentUsernames.TryGetValue(steamID, out var previousName) && __instance._nickname != previousName)
				{
					ChatBehaviour._current.New_ChatMessage(__instance._nickname + " connected (Previous character was " + previousName + ")");
				}
			}
			else
			{
				UsernamePersistence.PersistentUsernames.Add(steamID, __instance._nickname);
			}
		}
	}
	[HarmonyPatch(typeof(QuickItemSlot), "Iterate_ItemHandleInfo")]
	public static class DisplayConsumableCoolDownInSecondsPatch
	{
		[HarmonyPostfix]
		public static void patchShowSecondsCooldown(ref QuickItemSlot __instance, ref PlayerInventory ____pInventory)
		{
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			GameObject gameObject = ((Component)__instance).gameObject;
			GameObject gameObjectChild = CommonFunctions.GetGameObjectChild(gameObject, "CooldownText");
			if ((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
			{
				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 = "";
				if (ModSettings.toggleEnemyHPCritical)
				{
					text = (flag ? "<color=orange>" : "") + ____isCreep._scriptCreep._creepName + (flag ? "</color>" : "") + " (" + (flag ? "<color=orange>" : "") + currentHealth + (flag ? "</color>" : "") + "/" + maxHealth + ")";
				}
				else
				{
					string[] obj = new string[6]
					{
						____isCreep._scriptCreep._creepName,
						" (",
						null,
						null,
						null,
						null
					};
					int num = currentHealth;
					obj[2] = num.ToString();
					obj[3] = "/";
					obj[4] = maxHealth.ToString();
					obj[5] = ")";
					text = string.Concat(obj);
				}
				____isCreep._creepDisplayName = text;
			}
		}
	}
	[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)
			{
				StatsMenuCell val = Object.FindObjectOfType<StatsMenuCell>();
				if ((Object)(object)____pStats != (Object)null && (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), "LateUpdate")]
	public static class DisplaySkillCooldownInSecondsPatch
	{
		[HarmonyPostfix]
		public static void patchShowSecondsCooldown(ref ActionBarManager __instance, ref ActionSlot[] ____actionSlots, PlayerCasting ____pCast)
		{
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: 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))
			{
				return;
			}
			for (int i = 0; i < 6; i++)
			{
				if (!((Object)(object)____actionSlots[i] != (Object)null))
				{
					continue;
				}
				GameObject gameObject = ((Component)____actionSlots[i]).gameObject;
				if (!((Object)(object)gameObject != (Object)null))
				{
					continue;
				}
				GameObject gameObjectChild = CommonFunctions.GetGameObjectChild(gameObject, "CooldownText");
				if ((Object)(object)gameObjectChild != (Object)null)
				{
					_ = ____pCast._skillCoolDowns[i];
					if (____pCast._skillCoolDowns[i] > 0f && ModSettings.toggleActionCooldown)
					{
						gameObjectChild.SetActive(true);
						gameObjectChild.GetComponent<Text>().text = ____pCast._skillCoolDowns[i].ToString("F1");
						if (____pCast._skillCoolDowns[i] < 10f && gameObjectChild.transform.localPosition.x == 40f)
						{
							gameObjectChild.transform.localPosition = new Vector3(45f, 0f, 0f);
						}
					}
					else
					{
						gameObjectChild.transform.localPosition = new Vector3(40f, 0f, 0f);
						gameObjectChild.SetActive(false);
					}
				}
				else
				{
					GameObject val = Object.Instantiate<GameObject>(CommonFunctions.GetGameObjectChild(gameObject, "_actionSlot_hotKey"), gameObject.transform);
					((Object)val).name = "CooldownText";
					val.transform.localPosition = new Vector3(40f, 0f, 0f);
				}
			}
		}
	}
	public static class UsernamePersistence
	{
		public static Dictionary<string, string> PersistentUsernames = new Dictionary<string, string>();
	}
}