Decompiled source of Erenshor Mob Buddy v1.0.1

erenshor-mob-buddy.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using UnityEngine;
using UnityEngine.UI;
using erenshor_mob_buddy.Model;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("erenshor-mob-buddy")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("erenshor-mob-buddy")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4dcc0e65-7ada-4198-8e65-a667443b604c")]
[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 erenshor_mob_buddy
{
	internal class Metadata
	{
		public const string MOD_GUID = "dpower.mobbuddy";

		public const string MOD_NAME = "Erenshor Mob Buddy";

		public const string MOD_VERSION = "1.0.0";
	}
	[BepInPlugin("dpower.mobbuddy", "Erenshor Mob Buddy", "1.0.0")]
	public class Mod : BaseUnityPlugin
	{
		private static Mod Instance;

		private readonly Harmony harmony = new Harmony("dpower.mobbuddy");

		private static List<string> TrackedMobs = new List<string>();

		private const float ScanTime = 2f;

		private GameObject _madeUI;

		private float Timer = 2.1f;

		public static bool ToggleTracking(string MobName)
		{
			MobName = MobName.ToLower();
			if (TrackedMobs.Contains(MobName))
			{
				TrackedMobs.Remove(MobName);
				Instance.RefreshUI();
				return false;
			}
			TrackedMobs.Add(MobName);
			Instance.RefreshUI();
			return true;
		}

		public static void ClearTracking()
		{
			TrackedMobs.Clear();
		}

		public void Awake()
		{
			if ((Object)(object)Instance != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			harmony.PatchAll();
			Instance = this;
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			RefreshUI();
		}

		public void Update()
		{
			Timer += Time.deltaTime;
			if (Timer >= 2f)
			{
				Timer = 0f;
				RefreshUI();
			}
		}

		private void RefreshUI()
		{
			CleanUI();
			IEnumerable<ScanResult> source = Scan();
			BuildWindow(source.ToList());
		}

		private void CleanUI()
		{
			if (!((Object)(object)_madeUI == (Object)null))
			{
				Object.Destroy((Object)(object)_madeUI);
			}
		}

		private void BuildWindow(List<ScanResult> FoundMobs)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Expected O, but got Unknown
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Expected O, but got Unknown
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("MobBuddyCanvas", new Type[3]
			{
				typeof(Canvas),
				typeof(CanvasScaler),
				typeof(GraphicRaycaster)
			});
			Canvas component = val.GetComponent<Canvas>();
			component.renderMode = (RenderMode)0;
			component.overrideSorting = true;
			component.sortingOrder = 0;
			CanvasGroup val2 = val.AddComponent<CanvasGroup>();
			val2.blocksRaycasts = false;
			val2.interactable = true;
			GameObject val3 = new GameObject("MobBuddyPanel", new Type[3]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer),
				typeof(RawImage)
			});
			val3.transform.SetParent(val.transform, false);
			RectTransform component2 = val3.GetComponent<RectTransform>();
			float num = 200f;
			float num2 = 300f;
			component2.sizeDelta = new Vector2(num, num2);
			component2.anchorMin = new Vector2(1f, 0.5f);
			component2.anchorMax = new Vector2(1f, 0.5f);
			component2.anchoredPosition = new Vector2((0f - num) / 2f, 0f);
			((Graphic)val3.GetComponent<RawImage>()).color = new Color(0.1f, 0.1f, 0.1f, 0.5f);
			VerticalLayoutGroup val4 = val3.AddComponent<VerticalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)val4).childForceExpandWidth = true;
			((HorizontalOrVerticalLayoutGroup)val4).childForceExpandHeight = false;
			((LayoutGroup)val4).childAlignment = (TextAnchor)1;
			((HorizontalOrVerticalLayoutGroup)val4).spacing = 1f;
			((LayoutGroup)val4).padding = new RectOffset(10, 10, 4, 4);
			foreach (ScanResult FoundMob in FoundMobs)
			{
				AddText(FoundMob.MobName, ((Component)val4).transform, FoundMob.Found ? Color.yellow : Color.grey);
			}
			_madeUI = val;
		}

		private void AddText(string Text, Transform Parent, Color TextColor)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("MobBuddyEntry", new Type[3]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer),
				typeof(Text)
			});
			val.transform.SetParent(Parent, false);
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchorMin = Vector2.zero;
			component.anchorMax = Vector2.one;
			component.offsetMin = Vector2.zero;
			component.offsetMax = Vector2.zero;
			Text component2 = val.GetComponent<Text>();
			component2.text = Text;
			component2.alignment = (TextAnchor)3;
			component2.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
			((Graphic)component2).color = TextColor;
			component2.fontSize = 12;
			Outline val2 = ((Component)component2).gameObject.AddComponent<Outline>();
			((Shadow)val2).effectColor = Color.black;
			((Shadow)val2).effectDistance = new Vector2(1f, 1f);
		}

		private IEnumerable<ScanResult> Scan()
		{
			IEnumerable<string> AllMobs = NPCTable.LiveNPCs.Select((NPC x) => x.NPCName.ToLower());
			return TrackedMobs.Select((string tracked) => new ScanResult(tracked, AllMobs.Contains(tracked)));
		}
	}
}
namespace erenshor_mob_buddy.Patches
{
	[HarmonyPatch(typeof(TypeText))]
	[HarmonyPatch("CheckCommands")]
	internal class CommandText
	{
		private static bool Prefix()
		{
			string text = GameData.TextInput.typed.text;
			if (text.Length >= 6)
			{
				string text2 = text.Substring(0, 6).ToLower();
				if (text2 == "/track")
				{
					try
					{
						string text3 = text.Replace("/track ", "");
						if (text3 == "clear")
						{
							Mod.ClearTracking();
							UpdateSocialLog.LogAdd("<color=#ffba66>MobBuddy: </color><color=#66a1ff>Cleared all tracked mobs.</color>");
							return false;
						}
						if (Mod.ToggleTracking(text3))
						{
							UpdateSocialLog.LogAdd("<color=#ffba66>MobBuddy: </color><color=#66a1ff>Now tracking <b>" + text3 + "</b></color>");
						}
						else
						{
							UpdateSocialLog.LogAdd("<color=#ffba66>MobBuddy: </color><color=#66a1ff>No longer tracking <b>" + text3 + "</b></color>");
						}
					}
					catch
					{
						return true;
					}
					return false;
				}
			}
			return true;
		}
	}
}
namespace erenshor_mob_buddy.Model
{
	internal class ScanResult
	{
		public string MobName { get; private set; }

		public bool Found { get; private set; }

		public ScanResult(string MobName, bool Found)
		{
			this.MobName = MobName;
			this.Found = Found;
		}
	}
}