Decompiled source of AutoBioPing v1.0.4

AutoBioPing.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using Agents;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Enemies;
using GameData;
using Gear;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using Player;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("AutoBioPing")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("AutoBioPing")]
[assembly: AssemblyTitle("AutoBioPing")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 AutoBioPing
{
	[BepInPlugin("com.scarlet.autobioping", "AutoBioPing", "1.0.3")]
	public class Plugin : BasePlugin
	{
		public static ConfigEntry<KeyCode> ToggleKey;

		public static Fixed<float> CostPercentPerSecond;

		public static Fixed<float> PingInterval;

		public static Fixed<float> ToolAmmoMax;

		public static Fixed<bool> OnlyAggressive;

		public static Fixed<bool> PingScouts;

		public static Fixed<float> ActivationCostPercent;

		public static Fixed<bool> EnableToolAmmoUse;

		public static Fixed<bool> ShowAutoLabel;

		public static ConfigEntry<bool> DebugLog;

		public static Fixed<string> AutoLabelText;

		public static Fixed<bool> AutoScreenEffect;

		public static Fixed<string> AutoScreenColor;

		public static Fixed<bool> PingMovingEnemies;

		public static Fixed<float> LabelOffsetX;

		public static Fixed<float> LabelOffsetY;

		public static Fixed<float> LabelSizeFactor;

		private static ManualLogSource _log;

		public static void Instance_Log(string msg)
		{
			ManualLogSource log = _log;
			if (log != null)
			{
				log.LogInfo((object)msg);
			}
		}

		public static void Debug(string msg)
		{
			if (DebugLog != null && DebugLog.Value)
			{
				ManualLogSource log = _log;
				if (log != null)
				{
					log.LogInfo((object)msg);
				}
			}
		}

		public override void Load()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			_log = ((BasePlugin)this).Log;
			ConfigFile val = new ConfigFile(Path.Combine(Paths.ConfigPath, "AutoBioPing.cfg"), true);
			ToggleKey = val.Bind<KeyCode>("AutoPing", "ToggleKey", (KeyCode)118, "자동 바이오핑 토글 키");
			CostPercentPerSecond = new Fixed<float>(1f);
			PingInterval = new Fixed<float>(1f);
			ShowAutoLabel = new Fixed<bool>(v: false);
			DebugLog = val.Bind<bool>("AutoPing", "DebugLog", false, "true면 자동 핑/탄약 상태를 로그에 자세히 출력 (문제 확인용)");
			EnableToolAmmoUse = new Fixed<bool>(v: true);
			AutoScreenEffect = new Fixed<bool>(v: true);
			AutoScreenColor = new Fixed<string>("#B8A0FF");
			PingMovingEnemies = new Fixed<bool>(v: true);
			AutoLabelText = new Fixed<string>("AUTO MODE");
			LabelOffsetX = new Fixed<float>(0f);
			LabelOffsetY = new Fixed<float>(-1.5f);
			LabelSizeFactor = new Fixed<float>(0.6f);
			ActivationCostPercent = new Fixed<float>(3f);
			PingScouts = new Fixed<bool>(v: true);
			OnlyAggressive = new Fixed<bool>(v: true);
			ToolAmmoMax = new Fixed<float>(100f);
			new Harmony("com.scarlet.autobioping").PatchAll();
			((BasePlugin)this).Log.LogInfo((object)"AutoBioPing loaded (build: multiplayer-tag test)");
		}
	}
	public class Fixed<T>
	{
		public T Value;

		public Fixed(T v)
		{
			Value = v;
		}
	}
	public static class AutoPingState
	{
		public static bool Enabled;

		public static float PingTimer;

		public static bool DrainStarted;

		public static IntPtr OwnerPtr;
	}
	[HarmonyPatch(typeof(EnemyScanner), "Update")]
	public static class EnemyScannerUpdatePatch
	{
		public static void Postfix(EnemyScanner __instance)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			if (!IsLocalPlayersScanner(__instance))
			{
				return;
			}
			if (AutoPingState.OwnerPtr != ((Il2CppObjectBase)__instance).Pointer)
			{
				AutoPingState.Enabled = false;
				AutoPingState.PingTimer = 0f;
				AutoPingState.OwnerPtr = ((Il2CppObjectBase)__instance).Pointer;
				EnemyMotion.Reset();
				NetTag.Reset();
			}
			ToolAmmo.EnsureReady();
			ToolAmmo.Watch();
			if (Input.GetKeyDown(Plugin.ToggleKey.Value))
			{
				if (AutoPingState.Enabled)
				{
					AutoPingState.Enabled = false;
					AutoPingState.PingTimer = 0f;
					Plugin.Instance_Log("AutoPing OFF");
				}
				else if (__instance.m_recharging)
				{
					Plugin.Instance_Log("Cannot start AutoPing while scanner is recharging");
				}
				else if (ToolAmmo.TryConsume(Plugin.ActivationCostPercent.Value * 0.01f, exact: true))
				{
					AutoPingState.Enabled = true;
					AutoPingState.PingTimer = 0f;
					AutoPingState.DrainStarted = false;
					NetTag.Reset();
					Plugin.Instance_Log("AutoPing ON");
				}
				else
				{
					Plugin.Instance_Log("Not enough tool ammo to start AutoPing");
				}
			}
			if (AutoPingState.Enabled && __instance.m_recharging)
			{
				AutoPingState.Enabled = false;
				AutoPingState.PingTimer = 0f;
				Plugin.Instance_Log("AutoPing OFF (manual scan completed)");
			}
			AutoLabel.Apply(__instance, AutoPingState.Enabled);
			AutoScreen.Apply(__instance, AutoPingState.Enabled);
			if (!AutoPingState.Enabled || __instance.m_tagging || __instance.m_recharging)
			{
				return;
			}
			float deltaTime = Time.deltaTime;
			AutoPingState.PingTimer += deltaTime;
			if (!AutoPingState.DrainStarted)
			{
				if (AutoPingState.PingTimer >= Plugin.PingInterval.Value)
				{
					AutoPingState.PingTimer = 0f;
					AutoPingState.DrainStarted = true;
					DoPing(__instance);
				}
			}
			else if (!ToolAmmo.TryConsume(Plugin.CostPercentPerSecond.Value * 0.01f * deltaTime))
			{
				AutoPingState.Enabled = false;
				Plugin.Instance_Log("Tool ammo empty - AutoPing OFF");
			}
			else if (AutoPingState.PingTimer >= Plugin.PingInterval.Value)
			{
				AutoPingState.PingTimer = 0f;
				DoPing(__instance);
			}
		}

		private static bool IsLocalPlayersScanner(EnemyScanner scanner)
		{
			PlayerAgent localPlayerAgent = PlayerManager.GetLocalPlayerAgent();
			if ((Object)(object)localPlayerAgent == (Object)null || !((Agent)localPlayerAgent).IsLocallyOwned)
			{
				return false;
			}
			if (!((Agent)localPlayerAgent).Alive)
			{
				AutoPingState.Enabled = false;
				return false;
			}
			if ((Object)(object)localPlayerAgent.Inventory == (Object)null)
			{
				return false;
			}
			ItemEquippable wieldedItem = localPlayerAgent.Inventory.WieldedItem;
			return (Object)(object)wieldedItem != (Object)null && ((Il2CppObjectBase)wieldedItem).Pointer == ((Il2CppObjectBase)scanner).Pointer;
		}

		private unsafe static void DoPing(EnemyScanner scanner)
		{
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Invalid comparison between Unknown and I4
			List<EnemyAgent> enemiesDetected = scanner.m_enemiesDetected;
			if (enemiesDetected == null || enemiesDetected.Count == 0)
			{
				return;
			}
			int num = 0;
			string text = "";
			for (int i = 0; i < enemiesDetected.Count; i++)
			{
				EnemyAgent val = enemiesDetected[i];
				if ((Object)(object)val == (Object)null || !((Agent)val).Alive)
				{
					continue;
				}
				EnemyAI aI = val.AI;
				if ((Object)(object)aI == (Object)null)
				{
					continue;
				}
				AgentMode mode = ((AgentAI)aI).Mode;
				string text2 = ((object)(*(AgentMode*)(&mode))/*cast due to .constrained prefix*/).ToString();
				bool flag = Plugin.PingScouts.Value && (text2 == "Scout" || val.IsScout);
				bool flag2 = Plugin.PingMovingEnemies.Value && EnemyMotion.IsMoving(val);
				text = text + text2 + (val.IsScout ? "(scout)" : "") + (flag2 ? "(moving)" : "") + ",";
				EnemyMotion.LogOnce(val, text2, flag2);
				if (Plugin.OnlyAggressive.Value)
				{
					if (text2 != "Agressive" && !flag && !flag2)
					{
						continue;
					}
				}
				else if ((int)mode == 4 && !flag && !flag2)
				{
					continue;
				}
				if (flag || flag2 || !val.IsHibernationDetecting)
				{
					if (NetTag.Due(val))
					{
						NetTag.Tag(val);
					}
					num++;
				}
			}
			Plugin.Debug($"AutoPing: tagged {num}/{enemiesDetected.Count} modes=[{text}]");
		}
	}
	public static class EnemyMotion
	{
		private class Rec
		{
			public Vector3 Pos;

			public float LastMoved = -999f;
		}

		private static readonly Dictionary<int, Rec> _recs = new Dictionary<int, Rec>();

		private static readonly HashSet<int> _logged = new HashSet<int>();

		public static void Reset()
		{
			_recs.Clear();
			_logged.Clear();
		}

		public static bool IsMoving(EnemyAgent enemy)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			int instanceID = ((Object)enemy).GetInstanceID();
			Vector3 position = enemy.Position;
			float time = Clock.Time;
			if (!_recs.TryGetValue(instanceID, out var value))
			{
				_recs[instanceID] = new Rec
				{
					Pos = position
				};
				return false;
			}
			Vector3 val = position - value.Pos;
			if (((Vector3)(ref val)).sqrMagnitude > 0.09f)
			{
				value.Pos = position;
				value.LastMoved = time;
			}
			return time - value.LastMoved < 5f;
		}

		public static void LogOnce(EnemyAgent enemy, string modeName, bool moving)
		{
			if (Plugin.DebugLog.Value)
			{
				int instanceID = ((Object)enemy).GetInstanceID();
				if (_logged.Add(instanceID))
				{
					Plugin.Debug($"Enemy#{instanceID}: dataId={enemy.EnemyDataID} scout={enemy.IsScout} mode={modeName} moving={moving} hibDetect={enemy.IsHibernationDetecting}");
				}
			}
		}
	}
	public static class AutoScreen
	{
		private static bool _active;

		private static float _nextApply;

		private static string _savedCharge;

		private static string _savedTarget;

		private static Color _color = new Color(0.72f, 0.63f, 1f, 1f);

		private static bool _errLogged;

		private static bool _logged;

		public static void Apply(EnemyScanner scanner, bool enabled)
		{
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				EnemyScannerScreen screen = scanner.m_screen;
				if ((Object)(object)screen == (Object)null)
				{
					return;
				}
				if (!enabled || !Plugin.AutoScreenEffect.Value)
				{
					if (_active)
					{
						Restore(screen);
					}
				}
				else
				{
					if (scanner.m_tagging || scanner.m_recharging || Time.time < _nextApply)
					{
						return;
					}
					_nextApply = Time.time + 0.25f;
					if (!_active)
					{
						_active = true;
						_savedCharge = (((Object)(object)screen.m_statusTextCharge != (Object)null) ? ((TMP_Text)screen.m_statusTextCharge).text : null);
						_savedTarget = (((Object)(object)screen.m_statusTextTarget != (Object)null) ? ((TMP_Text)screen.m_statusTextTarget).text : null);
						Color color = default(Color);
						if (ColorUtility.TryParseHtmlString(Plugin.AutoScreenColor.Value, ref color))
						{
							_color = color;
						}
					}
					screen.SetGuixColor(_color);
					screen.SetStatusText(Plugin.AutoLabelText.Value);
					if ((Object)(object)screen.m_statusTextCharge != (Object)null)
					{
						((TMP_Text)screen.m_statusTextCharge).text = Plugin.AutoLabelText.Value;
					}
					if ((Object)(object)screen.m_statusTextTarget != (Object)null)
					{
						((TMP_Text)screen.m_statusTextTarget).text = Plugin.AutoLabelText.Value;
					}
					if (!_logged)
					{
						_logged = true;
						Plugin.Instance_Log("AutoScreen applied: charge=" + ((Object)(object)screen.m_statusTextCharge != (Object)null) + " target=" + ((Object)(object)screen.m_statusTextTarget != (Object)null));
					}
				}
			}
			catch (Exception ex)
			{
				if (!_errLogged)
				{
					_errLogged = true;
					Plugin.Instance_Log("AutoScreen error: " + ex.Message);
				}
			}
		}

		private static void Restore(EnemyScannerScreen screen)
		{
			_active = false;
			screen.ResetGuixColor();
			if ((Object)(object)screen.m_statusTextCharge != (Object)null && _savedCharge != null)
			{
				((TMP_Text)screen.m_statusTextCharge).text = _savedCharge;
			}
			if ((Object)(object)screen.m_statusTextTarget != (Object)null && _savedTarget != null)
			{
				((TMP_Text)screen.m_statusTextTarget).text = _savedTarget;
			}
		}
	}
	public static class NetTag
	{
		private static bool _resolved;

		private static bool _loggedRoute;

		private static MethodInfo _tagMethod;

		private static readonly Dictionary<int, float> _last = new Dictionary<int, float>();

		public static void Reset()
		{
			_last.Clear();
		}

		public static bool Due(EnemyAgent enemy)
		{
			float time = Clock.Time;
			float num = Mathf.Max(0.5f, EnemyScanner.TagDuration - Plugin.PingInterval.Value);
			if (_last.TryGetValue(((Object)enemy).GetInstanceID(), out var value) && time - value < num && enemy.IsTagged)
			{
				return false;
			}
			return true;
		}

		public static void Tag(EnemyAgent enemy)
		{
			Resolve();
			bool flag = false;
			if (_tagMethod != null)
			{
				try
				{
					_tagMethod.Invoke(null, new object[1] { enemy });
					flag = true;
				}
				catch (Exception ex)
				{
					Exception ex2 = ((ex.InnerException != null) ? ex.InnerException : ex);
					Plugin.Instance_Log("Network tag call failed, using local fallback: " + ex2.Message);
					_tagMethod = null;
				}
			}
			if (!flag)
			{
				enemy.EnemyTaggedTimer = Clock.Time + EnemyScanner.TagDuration;
				enemy.SyncPlaceNavMarkerTag();
			}
			_last[((Object)enemy).GetInstanceID()] = Clock.Time;
			if (!_loggedRoute)
			{
				_loggedRoute = true;
				Plugin.Instance_Log("AutoPing tag route: " + (flag ? "ToolSyncManager (network)" : "local fallback"));
			}
		}

		private static void Resolve()
		{
			if (_resolved)
			{
				return;
			}
			_resolved = true;
			try
			{
				Type type = FindType("ToolSyncManager", onlyAsmDlls: true) ?? FindType("ToolSyncManager", onlyAsmDlls: false);
				if (type == null)
				{
					Plugin.Instance_Log("ToolSyncManager type not found");
					return;
				}
				BindingFlags bindingAttr = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
				MethodInfo[] methods = type.GetMethods(bindingAttr);
				foreach (MethodInfo methodInfo in methods)
				{
					if (methodInfo.Name.IndexOf("Tag", StringComparison.OrdinalIgnoreCase) >= 0)
					{
						string text = "";
						ParameterInfo[] parameters = methodInfo.GetParameters();
						foreach (ParameterInfo parameterInfo in parameters)
						{
							text = text + parameterInfo.ParameterType.Name + " " + parameterInfo.Name + ", ";
						}
						Plugin.Instance_Log($"ToolSyncManager.{methodInfo.Name}({text}) static={methodInfo.IsStatic}");
						ParameterInfo[] parameters2 = methodInfo.GetParameters();
						if (_tagMethod == null && methodInfo.IsStatic && parameters2.Length == 1 && parameters2[0].ParameterType.IsAssignableFrom(typeof(EnemyAgent)) && methodInfo.Name.IndexOf("TagEnemy", StringComparison.OrdinalIgnoreCase) >= 0)
						{
							_tagMethod = methodInfo;
						}
					}
				}
				Plugin.Instance_Log("Network tag method: " + ((_tagMethod != null) ? _tagMethod.Name : "none found"));
			}
			catch (Exception ex)
			{
				Plugin.Instance_Log("NetTag resolve failed: " + ex.Message);
			}
		}

		private static Type FindType(string name, bool onlyAsmDlls)
		{
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly in assemblies)
			{
				if (onlyAsmDlls && !assembly.GetName().Name.EndsWith("-ASM"))
				{
					continue;
				}
				Type[] types;
				try
				{
					types = assembly.GetTypes();
				}
				catch (ReflectionTypeLoadException ex)
				{
					types = ex.Types;
				}
				catch
				{
					continue;
				}
				Type[] array = types;
				foreach (Type type in array)
				{
					if (type != null && type.Name == name)
					{
						return type;
					}
				}
			}
			return null;
		}
	}
	[HarmonyPatch(typeof(EnemyScanner), "OnUnWield")]
	public static class EnemyScannerUnwieldPatch
	{
		public static void Postfix(EnemyScanner __instance)
		{
			try
			{
				if (AutoPingState.Enabled && ((Il2CppObjectBase)__instance).Pointer == AutoPingState.OwnerPtr)
				{
					AutoPingState.Enabled = false;
					AutoPingState.PingTimer = 0f;
					Plugin.Instance_Log("AutoPing OFF (tool unwielded)");
					AutoLabel.Apply(__instance, enabled: false);
					AutoScreen.Apply(__instance, enabled: false);
				}
			}
			catch
			{
			}
		}
	}
	[HarmonyPatch(typeof(EnemyScanner), "Setup")]
	public static class EnemyScannerSetupPatch
	{
		public static void Postfix(ItemDataBlock data)
		{
			if (data == null)
			{
				return;
			}
			try
			{
				if (Plugin.EnableToolAmmoUse.Value)
				{
					SetFlag(data, "BlockToolAmmoRefill", value: false);
					SetFlag(data, "GUIShowAmmoInfinite", value: false);
					SetFlag(data, "GUIShowAmmoTotalRel", value: true);
				}
				Plugin.Instance_Log($"ItemData flags: BlockToolAmmoRefill={GetFlag(data, "BlockToolAmmoRefill")}, GUIShowAmmoInfinite={GetFlag(data, "GUIShowAmmoInfinite")}, GUIShowAmmoTotalRel={GetFlag(data, "GUIShowAmmoTotalRel")}");
			}
			catch (Exception ex)
			{
				Plugin.Instance_Log("ItemData patch failed: " + ex.Message);
			}
		}

		private static void SetFlag(ItemDataBlock data, string name, bool value)
		{
			Type type = ((object)data).GetType();
			PropertyInfo property = type.GetProperty("_" + name + "_k__BackingField");
			if (property != null && property.CanWrite)
			{
				property.SetValue(data, value);
				return;
			}
			MethodInfo methodInfo = type.GetProperty(name)?.GetSetMethod(nonPublic: true);
			if (methodInfo != null)
			{
				methodInfo.Invoke(data, new object[1] { value });
			}
			else
			{
				Plugin.Instance_Log("SetFlag failed: " + name);
			}
		}

		private static object GetFlag(ItemDataBlock data, string name)
		{
			return ((object)data).GetType().GetProperty(name)?.GetValue(data);
		}
	}
	public static class AutoLabel
	{
		private static TextMeshPro _label;

		private static IntPtr _owner;

		private static bool _init;

		private static bool _adjust;

		private static bool _errLogged;

		private static float _ox;

		private static float _oy;

		private static float _factor;

		public static void Apply(EnemyScanner scanner, bool enabled)
		{
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: 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_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!Plugin.ShowAutoLabel.Value)
				{
					if ((Object)(object)_label != (Object)null)
					{
						((Component)_label).gameObject.SetActive(false);
					}
					return;
				}
				EnemyScannerScreen screen = scanner.m_screen;
				if ((Object)(object)screen == (Object)null)
				{
					return;
				}
				TextMeshPro statusTextTarget = screen.m_statusTextTarget;
				if ((Object)(object)statusTextTarget == (Object)null)
				{
					return;
				}
				if (!_init)
				{
					_init = true;
					_ox = Plugin.LabelOffsetX.Value;
					_oy = Plugin.LabelOffsetY.Value;
					_factor = Plugin.LabelSizeFactor.Value;
				}
				Rect rect;
				if ((Object)(object)_label == (Object)null || _owner != ((Il2CppObjectBase)screen).Pointer)
				{
					_owner = ((Il2CppObjectBase)screen).Pointer;
					Transform val = (((Object)(object)statusTextTarget.transform.parent != (Object)null) ? statusTextTarget.transform.parent : statusTextTarget.transform);
					GameObject val2 = Object.Instantiate<GameObject>(((Component)statusTextTarget).gameObject, val);
					((Object)val2).name = "AutoBioPingLabel";
					_label = val2.GetComponent<TextMeshPro>();
					if ((Object)(object)_label == (Object)null)
					{
						return;
					}
					((TMP_Text)_label).text = Plugin.AutoLabelText.Value;
					((TMP_Text)_label).enableAutoSizing = false;
					DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(57, 3);
					defaultInterpolatedStringHandler.AppendLiteral("AutoLabel created. src.localPos=");
					defaultInterpolatedStringHandler.AppendFormatted<Vector3>(statusTextTarget.transform.localPosition);
					defaultInterpolatedStringHandler.AppendLiteral(" src.fontSize=");
					defaultInterpolatedStringHandler.AppendFormatted(((TMP_Text)statusTextTarget).fontSize);
					defaultInterpolatedStringHandler.AppendLiteral(" src.rectH=");
					rect = ((TMP_Text)statusTextTarget).rectTransform.rect;
					defaultInterpolatedStringHandler.AppendFormatted(((Rect)(ref rect)).height);
					Plugin.Instance_Log(defaultInterpolatedStringHandler.ToStringAndClear());
				}
				rect = ((TMP_Text)statusTextTarget).rectTransform.rect;
				float num = ((Rect)(ref rect)).height;
				if (num <= 0f)
				{
					num = 0.01f;
				}
				Vector3 localPosition = statusTextTarget.transform.localPosition;
				((TMP_Text)_label).fontSize = ((TMP_Text)statusTextTarget).fontSize * _factor;
				_label.transform.localPosition = new Vector3(localPosition.x + _ox * num, localPosition.y + _oy * num, localPosition.z);
				((Component)_label).gameObject.SetActive(enabled);
				HandleAdjustKeys();
			}
			catch (Exception ex)
			{
				if (!_errLogged)
				{
					_errLogged = true;
					Plugin.Instance_Log("AutoLabel error: " + ex.Message);
				}
			}
		}

		private static void HandleAdjustKeys()
		{
			if (Input.GetKeyDown((KeyCode)256))
			{
				_adjust = !_adjust;
				Plugin.Instance_Log("AutoLabel adjust mode " + (_adjust ? "ON (Keypad 4/6/8/2 = move, Keypad +/- = size)" : "OFF"));
			}
			if (_adjust)
			{
				bool flag = false;
				if (Input.GetKeyDown((KeyCode)260))
				{
					_ox -= 0.25f;
					flag = true;
				}
				if (Input.GetKeyDown((KeyCode)262))
				{
					_ox += 0.25f;
					flag = true;
				}
				if (Input.GetKeyDown((KeyCode)264))
				{
					_oy += 0.25f;
					flag = true;
				}
				if (Input.GetKeyDown((KeyCode)258))
				{
					_oy -= 0.25f;
					flag = true;
				}
				if (Input.GetKeyDown((KeyCode)270))
				{
					_factor += 0.1f;
					flag = true;
				}
				if (Input.GetKeyDown((KeyCode)269))
				{
					_factor = Mathf.Max(0.1f, _factor - 0.1f);
					flag = true;
				}
				if (flag)
				{
					Plugin.Instance_Log($"AutoLabel: LabelOffsetX={_ox:F2} LabelOffsetY={_oy:F2} LabelSizeFactor={_factor:F2}");
				}
			}
		}
	}
	public static class ToolAmmo
	{
		private static bool _logged;

		private static bool _failed;

		private static float _lastDbg;

		private static float _prev = -1f;

		private static PlayerAmmoStorage GetStorage()
		{
			PlayerBackpack localBackpack = PlayerBackpackManager.LocalBackpack;
			return (localBackpack != null) ? localBackpack.AmmoStorage : null;
		}

		public static void EnsureReady()
		{
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			if (_failed)
			{
				return;
			}
			try
			{
				PlayerAmmoStorage storage = GetStorage();
				if (storage == null)
				{
					return;
				}
				InventorySlotAmmo classAmmo = storage.ClassAmmo;
				if (classAmmo != null)
				{
					if (!_logged)
					{
						_logged = true;
						Plugin.Debug($"ClassAmmo: inPack={classAmmo.AmmoInPack} max={classAmmo.AmmoMaxCap} cost={classAmmo.CostOfBullet} type={classAmmo.AmmoType}");
					}
					if (!(classAmmo.AmmoMaxCap > 0f))
					{
						float value = Plugin.ToolAmmoMax.Value;
						storage.SetupAmmoType((AmmoType)2, 1f, 1, value);
						storage.SetAmmo((AmmoType)2, value);
						storage.UpdateSlotAmmoUI(storage.ClassAmmo, 0);
						storage.NeedsSync = true;
						Plugin.Instance_Log($"Bio tracker tool ammo initialised: max={value}");
					}
				}
			}
			catch (Exception ex)
			{
				_failed = true;
				Plugin.Instance_Log("ToolAmmo.EnsureReady failed: " + ex.Message);
			}
		}

		public static void Watch()
		{
			if (_failed)
			{
				return;
			}
			try
			{
				PlayerAmmoStorage storage = GetStorage();
				if (storage == null)
				{
					return;
				}
				InventorySlotAmmo classAmmo = storage.ClassAmmo;
				if (classAmmo != null)
				{
					float ammoInPack = classAmmo.AmmoInPack;
					if (_prev >= 0f && ammoInPack > _prev + 0.01f)
					{
						Plugin.Debug($"Ammo increased: {_prev:F2} -> {ammoInPack:F2} (refill/pickup)");
					}
					_prev = ammoInPack;
				}
			}
			catch
			{
			}
		}

		public static bool TryConsume(float fraction, bool exact = false)
		{
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			if (_failed)
			{
				return false;
			}
			try
			{
				PlayerAmmoStorage storage = GetStorage();
				if (storage == null)
				{
					return false;
				}
				InventorySlotAmmo classAmmo = storage.ClassAmmo;
				if (classAmmo == null || classAmmo.AmmoMaxCap <= 0f)
				{
					return false;
				}
				float ammoInPack = classAmmo.AmmoInPack;
				if (ammoInPack <= 0.0001f)
				{
					return false;
				}
				float num = classAmmo.AmmoMaxCap * fraction;
				if (exact && ammoInPack < num)
				{
					return false;
				}
				float num2 = Mathf.Min(num, ammoInPack);
				storage.UpdateAmmoInPack(classAmmo.AmmoType, 0f - num2);
				storage.UpdateSlotAmmoUI(classAmmo, 0);
				storage.NeedsSync = true;
				if (Time.time - _lastDbg > 3f)
				{
					_lastDbg = Time.time;
					Plugin.Debug($"Ammo: inPack={classAmmo.AmmoInPack:F2}/{classAmmo.AmmoMaxCap:F2} rel={classAmmo.RelInPack:F2} NeedClassAmmo={storage.NeedClassAmmo()}");
				}
				return true;
			}
			catch (Exception ex)
			{
				_failed = true;
				Plugin.Instance_Log("ToolAmmo.TryConsume failed: " + ex.Message);
				return false;
			}
		}
	}
}