Decompiled source of VargheimZoneMeter v1.0.1

VargheimZoneMeter.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace VargheimZoneMeter
{
	[BepInPlugin("digi.vargheim.zonemeter", "VargheimZoneMeter", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "digi.vargheim.zonemeter";

		public const string Version = "1.0.0";

		private const string Rpc = "VZM_Zone";

		internal static ConfigEntry<bool> Show;

		internal static ConfigEntry<float> Scale;

		internal static ConfigEntry<float> SendInterval;

		internal static ConfigEntry<int> OffsetY;

		private static int s_level = -1;

		private static int s_kills;

		private static int s_per;

		private static int s_ring;

		private static float s_stamp = -100f;

		private static bool s_lookedUp;

		private static MethodInfo s_getZone;

		private static PropertyInfo s_zoneLevel;

		private static PropertyInfo s_zoneKills;

		private static ConfigEntry<int> s_perCfg;

		private static ConfigEntry<bool> s_enabledCfg;

		private static ConfigEntry<bool> s_distCfg;

		private static FieldInfo s_bandsField;

		private float m_next;

		private static Texture2D s_round;

		private static bool s_registered;

		internal static ManualLogSource Log;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Show = ((BaseUnityPlugin)this).Config.Bind<bool>("Meter", "Show", true, "Draw the zone meter under the minimap.");
			Scale = ((BaseUnityPlugin)this).Config.Bind<float>("Meter", "Scale", 1f, "Size of the meter.");
			OffsetY = ((BaseUnityPlugin)this).Config.Bind<int>("Meter", "OffsetY", 6, "Pixels below the minimap.");
			SendInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Server", "SendInterval", 4f, "Server: seconds between zone updates sent to each player.");
		}

		private void Update()
		{
			ZNet instance = ZNet.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			if (instance.IsServer())
			{
				if (!(Time.time < m_next))
				{
					m_next = Time.time + Mathf.Max(1f, SendInterval.Value);
					ServerTick();
				}
			}
			else if (!s_registered && ZRoutedRpc.instance != null)
			{
				s_registered = true;
				ZRoutedRpc.instance.Register<ZPackage>("VZM_Zone", (Action<long, ZPackage>)OnZone);
			}
		}

		private static void LookUp()
		{
			if (s_lookedUp)
			{
				return;
			}
			s_lookedUp = true;
			try
			{
				Assembly assembly = null;
				Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
				foreach (Assembly assembly2 in assemblies)
				{
					if (assembly2.GetName().Name == "StarLevelSystem")
					{
						assembly = assembly2;
						break;
					}
				}
				if (assembly == null)
				{
					Log.LogInfo((object)"StarLevelSystem not present; zone meter idle.");
					return;
				}
				Type type = assembly.GetType("StarLevelSystem.Data.ZoneScaleSystemData");
				Type type2 = assembly.GetType("StarLevelSystem.common.DataObjects+ZoneData");
				Type type3 = assembly.GetType("StarLevelSystem.common.ValConfig");
				if (type == null || type2 == null || type3 == null)
				{
					Log.LogWarning((object)"StarLevelSystem types not found; zone meter idle.");
					return;
				}
				s_getZone = type.GetMethod("GetZoneForPosition", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(Vector3) }, null);
				s_zoneLevel = type2.GetProperty("ZoneLevel");
				s_zoneKills = type2.GetProperty("TotalKills");
				FieldInfo field = type3.GetField("ZoneKillsPerLevelUp", BindingFlags.Static | BindingFlags.Public);
				s_perCfg = ((field != null) ? (field.GetValue(null) as ConfigEntry<int>) : null);
				field = type3.GetField("EnableZoneScalingBonus", BindingFlags.Static | BindingFlags.Public);
				s_enabledCfg = ((field != null) ? (field.GetValue(null) as ConfigEntry<bool>) : null);
				if (s_getZone == null || s_zoneLevel == null || s_zoneKills == null || s_perCfg == null)
				{
					Log.LogWarning((object)"StarLevelSystem zone members not found; zone meter idle.");
					s_getZone = null;
				}
				else
				{
					Log.LogInfo((object)("Zone meter: StarLevelSystem zone data hooked (kills per level " + s_perCfg.Value + ")."));
				}
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Zone meter lookup failed: " + ex.Message));
				s_getZone = null;
			}
		}

		private void ServerTick()
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Expected O, but got Unknown
			LookUp();
			if (s_getZone == null || ZRoutedRpc.instance == null || (s_enabledCfg != null && !s_enabledCfg.Value))
			{
				return;
			}
			int num = Mathf.Max(1, s_perCfg.Value);
			foreach (ZNetPeer peer in ZNet.instance.GetPeers())
			{
				if (peer == null || !peer.IsReady())
				{
					continue;
				}
				int num2 = 0;
				int num3 = 0;
				try
				{
					object obj = s_getZone.Invoke(null, new object[1] { peer.m_refPos });
					if (obj != null)
					{
						num2 = (int)s_zoneLevel.GetValue(obj, null);
						num3 = (int)s_zoneKills.GetValue(obj, null);
					}
				}
				catch (Exception ex)
				{
					Log.LogWarning((object)("Zone meter: " + ex.Message));
					break;
				}
				ZPackage val = new ZPackage();
				val.Write(num2);
				val.Write(num3);
				val.Write(num);
				ZRoutedRpc.instance.InvokeRoutedRPC(peer.m_uid, "VZM_Zone", new object[1] { val });
			}
		}

		private static void OnZone(long sender, ZPackage pkg)
		{
			s_level = pkg.ReadInt();
			s_kills = pkg.ReadInt();
			s_per = Mathf.Max(1, pkg.ReadInt());
			s_stamp = Time.time;
		}

		private static GUIStyle Style(float size, TextAnchor anchor, Color c)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: 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_0016: 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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			GUIStyle val = new GUIStyle(GUI.skin.label)
			{
				alignment = anchor,
				fontSize = Mathf.RoundToInt(size),
				fontStyle = (FontStyle)1,
				richText = false
			};
			val.normal.textColor = c;
			return val;
		}

		private void OnGUI()
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Invalid comparison between Unknown and I4
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Expected O, but got Unknown
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0303: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: Unknown result type (might be due to invalid IL or missing references)
			//IL_0343: Unknown result type (might be due to invalid IL or missing references)
			//IL_0357: Unknown result type (might be due to invalid IL or missing references)
			//IL_035e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0373: Unknown result type (might be due to invalid IL or missing references)
			//IL_0384: Unknown result type (might be due to invalid IL or missing references)
			if (!Show.Value || s_level < 0 || Time.time - s_stamp > 30f || (Object)(object)Player.m_localPlayer == (Object)null || (Object)(object)Hud.instance == (Object)null || Hud.IsUserHidden() || (Object)(object)Minimap.instance == (Object)null || (int)Minimap.instance.m_mode != 1)
			{
				return;
			}
			RawImage mapImageSmall = Minimap.instance.m_mapImageSmall;
			if (!((Object)(object)mapImageSmall == (Object)null))
			{
				if ((Object)(object)s_round == (Object)null)
				{
					s_round = new Texture2D(1, 1, (TextureFormat)4, false);
					s_round.SetPixel(0, 0, Color.white);
					s_round.Apply();
				}
				Vector3[] array = (Vector3[])(object)new Vector3[4];
				((Graphic)mapImageSmall).rectTransform.GetWorldCorners(array);
				Vector2 val = default(Vector2);
				((Vector2)(ref val))..ctor(array[0].x, array[0].y);
				Vector2 val2 = default(Vector2);
				((Vector2)(ref val2))..ctor(array[2].x, array[2].y);
				float num = Scale.Value * Mathf.Clamp((float)Screen.height / 1080f, 0.6f, 2f);
				float num2 = Mathf.Max(120f * num, (val2.x - val.x) * 0.9f);
				float num3 = 8f * num;
				float num4 = (val.x + val2.x) * 0.5f - num2 * 0.5f;
				float num5 = (float)Screen.height - val.y + (float)OffsetY.Value * num + 16f * num;
				int num6 = s_kills % s_per;
				float num7 = ((s_per > 0) ? ((float)num6 / (float)s_per) : 0f);
				string text = "Zone " + s_level + "  ·  " + num6 + " / " + s_per;
				Color color = GUI.color;
				GUI.Label(new Rect(num4 - 20f * num, num5 - 17f * num, num2 + 40f * num, 18f * num), text, Style(12f * num, (TextAnchor)4, new Color(0.93f, 0.84f, 0.55f, 0.95f)));
				GUI.color = new Color(0.05f, 0.04f, 0.03f, 0.75f);
				GUI.DrawTexture(new Rect(num4 - 1.5f * num, num5 - 1.5f * num, num2 + 3f * num, num3 + 3f * num), (Texture)(object)s_round, (ScaleMode)0, true, 0f, GUI.color, 0f, 4f * num);
				GUI.color = new Color(0.25f, 0.2f, 0.14f, 0.9f);
				GUI.DrawTexture(new Rect(num4, num5, num2, num3), (Texture)(object)s_round, (ScaleMode)0, true, 0f, GUI.color, 0f, 3f * num);
				if (num7 > 0f)
				{
					GUI.color = Color.Lerp(new Color(0.55f, 0.75f, 0.35f), new Color(0.95f, 0.45f, 0.25f), num7);
					GUI.DrawTexture(new Rect(num4, num5, num2 * num7, num3), (Texture)(object)s_round, (ScaleMode)0, true, 0f, GUI.color, 0f, 3f * num);
				}
				GUI.color = color;
			}
		}
	}
}