Decompiled source of Threat Bars v0.0.2

BepInEx/Plugins/corang-ThreatBars/ThreatBars.dll

Decompiled 2 days ago
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 BepInEx.Configuration;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ThreatBars")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ThreatBars")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("faf5e26f-c89d-44ee-b801-ec5be6c8f01c")]
[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 ThreatBars;

[BepInPlugin("com.corang.ThreatBars", "Threat Bars", "0.0.2")]
public class Mod : BaseUnityPlugin
{
	internal static ConfigEntry<float> WindowX;

	internal static ConfigEntry<float> WindowY;

	internal static ConfigEntry<float> WindowWidth;

	internal static ConfigEntry<float> WindowHeight;

	internal static ConfigEntry<bool> WindowLocked;

	public void Awake()
	{
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Expected O, but got Unknown
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Threat Bars loaded!");
		WindowX = ((BaseUnityPlugin)this).Config.Bind<float>("Window", "X", 10f, "Threat window X position");
		WindowY = ((BaseUnityPlugin)this).Config.Bind<float>("Window", "Y", 50f, "Threat window Y position");
		WindowWidth = ((BaseUnityPlugin)this).Config.Bind<float>("Window", "Width", 300f, "Threat window width");
		WindowHeight = ((BaseUnityPlugin)this).Config.Bind<float>("Window", "Height", 60f, "Threat window height");
		WindowLocked = ((BaseUnityPlugin)this).Config.Bind<bool>("Window", "Locked", false, "Lock the threat window in place");
		GameObject val = new GameObject("ThreatWindow");
		val.AddComponent<ThreatWindow>();
		Object.DontDestroyOnLoad((Object)val);
	}
}
internal class ThreatWindow : MonoBehaviour
{
	private Rect boxRect;

	private bool isDragging;

	private Vector2 dragOffset;

	private bool isResizing;

	private Vector2 resizeOffset;

	private const float resizeHandleSize = 20f;

	private static readonly Color defaultColor = new Color(0.2f, 0.6f, 1f, 0.6f);

	private static readonly Color PaladinColor = new Color(0.95f, 0.75f, 0.42f, 0.6f);

	private static readonly Color ArcanistColor = new Color(0.566f, 0.177f, 0.81f, 0.6f);

	private static readonly Color DuelistColor = new Color(0.82f, 0.02f, 0.01f, 0.6f);

	private static readonly Color DruidColor = new Color(0.26f, 0.44f, 0.19f, 0.6f);

	private static readonly Dictionary<Color, Texture2D> colorTextures = new Dictionary<Color, Texture2D>();

	private GUIStyle customStyle;

	private void Awake()
	{
		//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)
		boxRect = new Rect(Mod.WindowX.Value, Mod.WindowY.Value, Mod.WindowWidth.Value, Mod.WindowHeight.Value);
	}

	private Texture2D GetTextureForColor(Color color)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Expected O, but got Unknown
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		if (!colorTextures.TryGetValue(color, out var value))
		{
			value = new Texture2D(1, 1);
			value.SetPixel(0, 0, color);
			value.Apply();
			colorTextures[color] = value;
		}
		return value;
	}

	private Color GetClassColor(string className)
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: 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_004e: Unknown result type (might be due to invalid IL or missing references)
		return (Color)(className switch
		{
			"Paladin" => PaladinColor, 
			"Arcanist" => ArcanistColor, 
			"Duelist" => DuelistColor, 
			"Druid" => DruidColor, 
			_ => defaultColor, 
		});
	}

	private void SaveRectToConfig()
	{
		Mod.WindowX.Value = ((Rect)(ref boxRect)).x;
		Mod.WindowY.Value = ((Rect)(ref boxRect)).y;
		Mod.WindowWidth.Value = ((Rect)(ref boxRect)).width;
		Mod.WindowHeight.Value = ((Rect)(ref boxRect)).height;
	}

	private Texture2D GetTriangleTexture(int size, Color color)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Expected O, but got Unknown
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = new Texture2D(size, size);
		Color val2 = default(Color);
		((Color)(ref val2))..ctor(0f, 0f, 0f, 0f);
		for (int i = 0; i < size; i++)
		{
			for (int j = 0; j < size; j++)
			{
				if (j >= i)
				{
					val.SetPixel(j, i, color);
				}
				else
				{
					val.SetPixel(j, i, val2);
				}
			}
		}
		val.Apply();
		return val;
	}

	private Texture2D GetLineTexture(Color color)
	{
		//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_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Expected O, but got Unknown
		Texture2D val = new Texture2D(1, 1);
		val.SetPixel(0, 0, color);
		val.Apply();
		return val;
	}

	public void OnGUI()
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: 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_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Expected O, but got Unknown
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		//IL_0205: Unknown result type (might be due to invalid IL or missing references)
		//IL_0246: Unknown result type (might be due to invalid IL or missing references)
		//IL_024c: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0536: Unknown result type (might be due to invalid IL or missing references)
		//IL_053c: Invalid comparison between Unknown and I4
		//IL_04bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_059c: Unknown result type (might be due to invalid IL or missing references)
		//IL_057e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0584: Invalid comparison between Unknown and I4
		//IL_0546: Unknown result type (might be due to invalid IL or missing references)
		//IL_054c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0551: Unknown result type (might be due to invalid IL or missing references)
		//IL_04cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_0313: Unknown result type (might be due to invalid IL or missing references)
		//IL_0318: Unknown result type (might be due to invalid IL or missing references)
		//IL_031b: Unknown result type (might be due to invalid IL or missing references)
		//IL_04df: Unknown result type (might be due to invalid IL or missing references)
		//IL_062a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0630: Invalid comparison between Unknown and I4
		//IL_05b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_04fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0516: Unknown result type (might be due to invalid IL or missing references)
		//IL_051b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0520: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03de: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e8: Expected O, but got Unknown
		//IL_03e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03fc: Expected O, but got Unknown
		//IL_03f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0403: Unknown result type (might be due to invalid IL or missing references)
		//IL_040c: Unknown result type (might be due to invalid IL or missing references)
		//IL_042d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0443: Unknown result type (might be due to invalid IL or missing references)
		//IL_044c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0460: Unknown result type (might be due to invalid IL or missing references)
		//IL_0469: Unknown result type (might be due to invalid IL or missing references)
		//IL_06b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_06bb: Invalid comparison between Unknown and I4
		//IL_0634: Unknown result type (might be due to invalid IL or missing references)
		//IL_064f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0654: Unknown result type (might be due to invalid IL or missing references)
		//IL_065a: Unknown result type (might be due to invalid IL or missing references)
		//IL_065f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0664: Unknown result type (might be due to invalid IL or missing references)
		//IL_0671: Unknown result type (might be due to invalid IL or missing references)
		//IL_068d: Unknown result type (might be due to invalid IL or missing references)
		//IL_05e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_05e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0602: Unknown result type (might be due to invalid IL or missing references)
		//IL_0607: Unknown result type (might be due to invalid IL or missing references)
		//IL_060c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0611: Unknown result type (might be due to invalid IL or missing references)
		GUI.depth = 1005;
		GUIStyle val = new GUIStyle(GUI.skin.label)
		{
			fontSize = 24
		};
		val.normal.textColor = Color.white;
		customStyle = val;
		Scene activeScene = SceneManager.GetActiveScene();
		switch (((Scene)(ref activeScene)).name)
		{
		case "LoadScene":
			return;
		case "Hidden":
			return;
		case "Tutorial":
			return;
		}
		GUI.Box(boxRect, "");
		Rect val2 = default(Rect);
		((Rect)(ref val2))..ctor(((Rect)(ref boxRect)).xMax - 108f, ((Rect)(ref boxRect)).y + 4f, 100f, 36f);
		string text = (Mod.WindowLocked.Value ? "Locked" : "Unlocked");
		if (GUI.Button(val2, text, customStyle))
		{
			Mod.WindowLocked.Value = !Mod.WindowLocked.Value;
			isDragging = false;
			isResizing = false;
		}
		string text2 = "Threat: No Target";
		Rect val3 = default(Rect);
		((Rect)(ref val3))..ctor(((Rect)(ref boxRect)).xMax - 20f, ((Rect)(ref boxRect)).yMax - 20f, 20f, 20f);
		Texture2D triangleTexture = GetTriangleTexture(20, Color.white);
		GUI.DrawTexture(val3, (Texture)(object)triangleTexture, (ScaleMode)0, true, 0f);
		GameObject val4 = GameObject.Find("Player");
		List<AggroSlot> list = null;
		if ((Object)(object)val4 != (Object)null)
		{
			Character currentTarget = val4.GetComponent<PlayerControl>().CurrentTarget;
			if ((Object)(object)currentTarget != (Object)null && (Object)(object)((Component)currentTarget).gameObject.GetComponent<NPC>() != (Object)null)
			{
				list = ((Component)currentTarget).gameObject.GetComponent<NPC>().AggroTable;
				text2 = "Threat: " + ((Object)currentTarget).name;
			}
		}
		GUI.Label(new Rect(((Rect)(ref boxRect)).x + 8f, ((Rect)(ref boxRect)).y + 4f, ((Rect)(ref boxRect)).width - 16f, 36f), text2, customStyle);
		float num = ((Rect)(ref boxRect)).y + 40f;
		GUI.DrawTexture(new Rect(((Rect)(ref boxRect)).x, num, ((Rect)(ref boxRect)).width, 2f), (Texture)(object)GetLineTexture(Color.white));
		if (list != null)
		{
			List<AggroSlot> list2 = list.OrderByDescending((AggroSlot slot) => slot.Hate).ToList();
			float num2 = 36f;
			float num3 = 4f;
			float num4 = ((Rect)(ref boxRect)).y + 46f;
			int num5 = list2.Sum((AggroSlot slot) => slot.Hate);
			for (int i = 0; i < list2.Count; i++)
			{
				AggroSlot val5 = list2[i];
				Stats component = ((Component)val5.Player).gameObject.GetComponent<Stats>();
				string className = component.CharacterClass.ClassName;
				string myName = component.MyName;
				Color classColor = GetClassColor(className);
				Texture2D textureForColor = GetTextureForColor(classColor);
				string text3 = val5.Hate.ToString();
				int num6 = ((num5 > 0) ? ((int)((float)val5.Hate * 100f / (float)num5)) : 0);
				string text4 = $"({num6}%)";
				float num7 = (((Rect)(ref boxRect)).width - 8f) * (float)num6 / 100f;
				float num8 = num4 + (float)i * (num2 + num3);
				GUI.DrawTexture(new Rect(((Rect)(ref boxRect)).x + 4f, num8, num7, num2), (Texture)(object)textureForColor);
				float num9 = ((Rect)(ref boxRect)).x + 8f;
				float num10 = ((Rect)(ref boxRect)).width - 16f;
				Vector2 val6 = customStyle.CalcSize(new GUIContent(text4));
				Vector2 val7 = customStyle.CalcSize(new GUIContent(text3));
				float num11 = num9 + num10 - val6.x;
				float num12 = num11 - val7.x - 8f;
				GUI.Label(new Rect(num9, num8, num12 - num9 - 8f, num2), myName, customStyle);
				GUI.Label(new Rect(num12, num8, val7.x, num2), text3, customStyle);
				GUI.Label(new Rect(num11, num8, val6.x, num2), text4, customStyle);
			}
		}
		Event current = Event.current;
		if (!Mod.WindowLocked.Value)
		{
			if ((int)current.type == 0 && current.button == 0 && ((Rect)(ref boxRect)).Contains(current.mousePosition) && !((Rect)(ref val2)).Contains(current.mousePosition) && !((Rect)(ref val3)).Contains(current.mousePosition))
			{
				isDragging = true;
				GameData.DraggingUIElement = true;
				dragOffset = current.mousePosition - new Vector2(((Rect)(ref boxRect)).x, ((Rect)(ref boxRect)).y);
				current.Use();
			}
			if (isDragging && (int)current.type == 3)
			{
				((Rect)(ref boxRect)).position = current.mousePosition - dragOffset;
				SaveRectToConfig();
				Cursor.visible = true;
				Cursor.lockState = (CursorLockMode)0;
				current.Use();
			}
			if (isDragging && (int)current.type == 1)
			{
				isDragging = false;
				GameData.DraggingUIElement = false;
				current.Use();
			}
			if ((int)current.type == 0 && current.button == 0 && ((Rect)(ref val3)).Contains(current.mousePosition))
			{
				isResizing = true;
				GameData.DraggingUIElement = true;
				resizeOffset = new Vector2(((Rect)(ref boxRect)).width, ((Rect)(ref boxRect)).height) - (current.mousePosition - new Vector2(((Rect)(ref boxRect)).x, ((Rect)(ref boxRect)).y));
				current.Use();
			}
			if (isResizing && (int)current.type == 3)
			{
				Vector2 val8 = current.mousePosition - new Vector2(((Rect)(ref boxRect)).x, ((Rect)(ref boxRect)).y) + resizeOffset;
				((Rect)(ref boxRect)).width = Mathf.Max(200f, val8.x);
				((Rect)(ref boxRect)).height = Mathf.Max(80f, val8.y);
				SaveRectToConfig();
				current.Use();
			}
			if (isResizing && (int)current.type == 1)
			{
				isResizing = false;
				GameData.DraggingUIElement = false;
				current.Use();
			}
		}
	}
}