Decompiled source of ReloadTimer v1.2.0

Zose_ReloadTimer.dll

Decompiled an hour 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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using CellMenu;
using GameData;
using Gear;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Microsoft.CodeAnalysis;
using Player;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using Zose_ReloadTimer;

[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 = "")]
[assembly: AssemblyCompany("Zose_ReloadTimer")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Zose_ReloadTimer")]
[assembly: AssemblyTitle("Zose_ReloadTimer")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
public static class FieldDumper
{
	public static void Dump(object target, string name)
	{
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Expected O, but got Unknown
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Expected O, but got Unknown
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Expected O, but got Unknown
		if (target == null)
		{
			return;
		}
		Type type = target.GetType();
		FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		bool flag = default(bool);
		BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(16, 2, ref flag);
		if (flag)
		{
			((BepInExLogInterpolatedStringHandler)val).AppendLiteral("--- Dump ");
			((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(name);
			((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" (");
			((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(type.Name);
			((BepInExLogInterpolatedStringHandler)val).AppendLiteral(") ---");
		}
		Logger.Info(val);
		FieldInfo[] array = fields;
		foreach (FieldInfo fieldInfo in array)
		{
			try
			{
				val = new BepInExInfoLogInterpolatedStringHandler(2, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(fieldInfo.Name);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<object>(fieldInfo.GetValue(target));
				}
				Logger.Info(val);
			}
			catch
			{
				val = new BepInExInfoLogInterpolatedStringHandler(20, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(fieldInfo.Name);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": <cannot get value>");
				}
				Logger.Info(val);
			}
		}
	}
}
namespace Zose_ReloadTimer
{
	public static class PluginData
	{
		public const string GUID = "Zose_ReloadTimer";

		public const string Name = "Zose_ReloadTimer";

		public const string Version = "1.1.5";
	}
	[BepInPlugin("Zose_ReloadTimer", "Zose_ReloadTimer", "1.1.5")]
	public class EntryPoint : BasePlugin
	{
		public static EntryPoint? Instance;

		public static ConfigEntry<float>? ConfigOffset;

		public static ConfigEntry<string>? ConfigChargeColor;

		public static ConfigEntry<float>? ConfigLowAmmoThreshold;

		public static ConfigEntry<string>? ConfigLowAmmoColor;

		public static Color ParsedChargeColor = new Color(0f, 1f, 0f, 0.8f);

		public static Color ParsedLowAmmoColor = new Color(1f, 0f, 0f, 0.8f);

		public static bool NeedsConfigReload = false;

		private static Harmony? harmony;

		private static FileSystemWatcher? _configWatcher;

		public override void Load()
		{
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Expected O, but got Unknown
			Instance = this;
			ClassInjector.RegisterTypeInIl2Cpp<Zose_ReloadTimer>();
			ConfigOffset = ((BasePlugin)this).Config.Bind<float>("Settings", "TextOffset", 85f, "The vertical offset of the reload text from the crosshair.");
			ConfigOffset.SettingChanged += delegate
			{
				Zose_ReloadTimer.Instance?.UpdateUIPosition();
			};
			ConfigChargeColor = ((BasePlugin)this).Config.Bind<string>("Settings", "ChargeColor", "#00FF0080", "The color of the reload charge circle in Hex format (#RRGGBBAA).");
			ConfigLowAmmoThreshold = ((BasePlugin)this).Config.Bind<float>("AmmoWarning", "LowAmmoThreshold", 0.35f, "The ammo threshold (percentage 0.0-1.0) for large weapons (>20 clip size).");
			ConfigLowAmmoColor = ((BasePlugin)this).Config.Bind<string>("AmmoWarning", "LowAmmoColor", "#FF000080", "The color of the 'RELOAD' warning text when ammo is low in Hex format (#RRGGBBAA).");
			UpdateParsedColor();
			ConfigChargeColor.SettingChanged += delegate
			{
				UpdateParsedColor();
			};
			ConfigLowAmmoColor.SettingChanged += delegate
			{
				UpdateParsedColor();
			};
			SetupConfigWatcher();
			harmony = new Harmony("Zose_ReloadTimer");
			harmony.PatchAll();
			Logger.Info("Zose_ReloadTimer v1.1.5 Loaded with Hot-Reload Support");
		}

		public void ReloadConfig()
		{
			((BasePlugin)this).Config.Reload();
			UpdateParsedColor();
			Logger.Info("Config reloaded from disk.");
		}

		private void UpdateParsedColor()
		{
			//IL_0021: 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_0048: 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)
			Color parsedChargeColor = default(Color);
			if (ConfigChargeColor != null && ColorUtility.TryParseHtmlString(ConfigChargeColor.Value, ref parsedChargeColor))
			{
				ParsedChargeColor = parsedChargeColor;
			}
			Color parsedLowAmmoColor = default(Color);
			if (ConfigLowAmmoColor != null && ColorUtility.TryParseHtmlString(ConfigLowAmmoColor.Value, ref parsedLowAmmoColor))
			{
				ParsedLowAmmoColor = parsedLowAmmoColor;
			}
		}

		private void SetupConfigWatcher()
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Expected O, but got Unknown
			try
			{
				_configWatcher = new FileSystemWatcher(Path.GetDirectoryName(((BasePlugin)this).Config.ConfigFilePath), Path.GetFileName(((BasePlugin)this).Config.ConfigFilePath));
				_configWatcher.NotifyFilter = NotifyFilters.LastWrite;
				_configWatcher.Changed += delegate
				{
					NeedsConfigReload = true;
				};
				_configWatcher.EnableRaisingEvents = true;
			}
			catch (Exception ex)
			{
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(31, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Failed to setup ConfigWatcher: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				Logger.Error(val);
			}
		}
	}
	internal static class Logger
	{
		private static readonly ManualLogSource _Logger;

		static Logger()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			_Logger = new ManualLogSource("Zose_ReloadTimer");
			Logger.Sources.Add((ILogSource)(object)_Logger);
		}

		private static string Format(object msg)
		{
			return msg.ToString();
		}

		public static void Info(BepInExInfoLogInterpolatedStringHandler handler)
		{
			_Logger.LogInfo(handler);
		}

		public static void Info(string str)
		{
			_Logger.LogMessage((object)str);
		}

		public static void Info(object data)
		{
			_Logger.LogMessage((object)Format(data));
		}

		public static void Debug(BepInExDebugLogInterpolatedStringHandler handler)
		{
			_Logger.LogDebug(handler);
		}

		public static void Debug(string str)
		{
			_Logger.LogDebug((object)str);
		}

		public static void Debug(object data)
		{
			_Logger.LogDebug((object)Format(data));
		}

		public static void Error(BepInExErrorLogInterpolatedStringHandler handler)
		{
			_Logger.LogError(handler);
		}

		public static void Error(string str)
		{
			_Logger.LogError((object)str);
		}

		public static void Error(object data)
		{
			_Logger.LogError((object)Format(data));
		}

		public static void Fatal(BepInExFatalLogInterpolatedStringHandler handler)
		{
			_Logger.LogFatal(handler);
		}

		public static void Fatal(string str)
		{
			_Logger.LogFatal((object)str);
		}

		public static void Fatal(object data)
		{
			_Logger.LogFatal((object)Format(data));
		}

		public static void Warn(BepInExWarningLogInterpolatedStringHandler handler)
		{
			_Logger.LogWarning(handler);
		}

		public static void Warn(string str)
		{
			_Logger.LogWarning((object)str);
		}

		public static void Warn(object data)
		{
			_Logger.LogWarning((object)Format(data));
		}
	}
	public class Zose_ReloadTimer : MonoBehaviour
	{
		private TextMeshProUGUI _textMesh = null;

		private TextMeshProUGUI _glitchTextMesh = null;

		private TextMeshProUGUI _glitchTextMesh2 = null;

		private GameObject _uiRoot = null;

		public static Zose_ReloadTimer Instance;

		private bool _isReloading = false;

		private float _reloadStartTime = 0f;

		private float _lastReloadDuration = 0f;

		private string _currentWeaponName = "";

		private float _lastFireTime = -10f;

		private int _lastClipCount = -1;

		private static Dictionary<string, float> _refreshRatioMap = new Dictionary<string, float>();

		private bool _ammoFilledThisReload = false;

		private float _readyEffectStartTime = -1f;

		private bool _hasTriggeredReadyEffect = false;

		private bool _isAnimatingReady = false;

		private bool _waitingForNativeReloadToEnd = false;

		private float _lastGlitchTime = 0f;

		private string _currGlitchedText = "";

		private const string GLITCH_CHARS = "#@&!$%01X?";

		private bool _chargeShown = false;

		private static bool _reflectionChecked = false;

		private Color _originalChargeColor;

		private static MethodInfo? _setChargeUpVisibleAndProgressMethod;

		private static Il2CppObjectBase? _circleTarget;

		private static MethodInfo? _setChargeMethod;

		private static MethodInfo? _showChargeMethod;

		private static MethodInfo? _setChargeColorMethod;

		private static FieldInfo? _chargeUpColOrgField;

		private static FieldInfo? _ammoField;

		private static FieldInfo? _isAimingField;

		private static FieldInfo? _lookYawField;

		private static FieldInfo? _lookPitchField;

		private static FieldInfo? _mouseLookField;

		private static object? _cachedMouseLook;

		private static IntPtr _lastMouseLookPointer = IntPtr.Zero;

		private IntPtr _lastWieldPointer = IntPtr.Zero;

		private BulletWeapon? _cachedBulletWeapon;

		private static MethodInfo? _getIdentifierMethod;

		private PlayerAgent? _localPlayer;

		private const float MAX_SWAY_OFFSET = 12f;

		private const float SWAY_SENSITIVITY = 1.2f;

		private const float SWAY_SMOOTHING = 0.12f;

		private const float ADS_SWAY_MULTIPLIER = 0.25f;

		private float _lastLookYaw = 0f;

		private float _lastLookPitch = 0f;

		private Vector2 _currentSwayOffset = Vector2.zero;

		private Vector2 _swayVelocity = Vector2.zero;

		private bool _isFirstSwayFrame = true;

		public void Awake()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Expected O, but got Unknown
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Expected O, but got Unknown
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Expected O, but got Unknown
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			Logger.Info("Zose_ReloadTimer v1.1.5 INITIALIZED.");
			_uiRoot = new GameObject("ReloadTimer")
			{
				layer = 5
			};
			_uiRoot.transform.SetParent(((Component)GuiManager.CrosshairLayer.m_circleCrosshair).transform.parent, false);
			UpdateUIPosition();
			GameObject val = new GameObject("MainText")
			{
				layer = 5
			};
			val.transform.SetParent(_uiRoot.transform, false);
			_textMesh = SetupTextMesh(val, new Color(1f, 1f, 1f, 1f));
			GameObject val2 = new GameObject("GlitchR")
			{
				layer = 5
			};
			val2.transform.SetParent(_uiRoot.transform, false);
			GameObject val3 = new GameObject("GlitchC")
			{
				layer = 5
			};
			val3.transform.SetParent(_uiRoot.transform, false);
			_glitchTextMesh2 = SetupTextMesh(val3, new Color(1f, 1f, 1f, 0f));
		}

		private TextMeshProUGUI SetupTextMesh(GameObject go, Color col)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI val = go.AddComponent<TextMeshProUGUI>();
			((TMP_Text)val).alignment = (TextAlignmentOptions)514;
			((Component)val).GetComponent<RectTransform>().sizeDelta = new Vector2(400f, 100f);
			((TMP_Text)val).fontSize = 20f;
			((TMP_Text)val).font = ((TMP_Text)GuiManager.PlayerLayer.m_playerStatus.m_healthText).font;
			((Graphic)val).color = col;
			((TMP_Text)val).characterSpacing = 0f;
			((TMP_Text)val).richText = true;
			return val;
		}

		public void OnAmmoRefreshed()
		{
			if (!_isReloading || _ammoFilledThisReload)
			{
				return;
			}
			_ammoFilledThisReload = true;
			float num = Time.time - _reloadStartTime;
			if (_lastReloadDuration > 0f)
			{
				float value = num / _lastReloadDuration;
				if (!_refreshRatioMap.ContainsKey(_currentWeaponName))
				{
					_refreshRatioMap.Add(_currentWeaponName, value);
				}
				else
				{
					_refreshRatioMap[_currentWeaponName] = value;
				}
			}
			if (!_hasTriggeredReadyEffect)
			{
				_readyEffectStartTime = Time.time;
				_hasTriggeredReadyEffect = true;
				_isAnimatingReady = true;
			}
		}

		private void Update()
		{
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			if (EntryPoint.NeedsConfigReload)
			{
				EntryPoint.NeedsConfigReload = false;
				EntryPoint.Instance?.ReloadConfig();
				UpdateUIPosition();
			}
			if ((Object)(object)_localPlayer == (Object)null)
			{
				_localPlayer = PlayerManager.GetLocalPlayerAgent();
				if ((Object)(object)_localPlayer == (Object)null)
				{
					return;
				}
			}
			PlayerInventoryBase inventory = _localPlayer.Inventory;
			ItemEquippable val = ((inventory != null) ? inventory.WieldedItem : null);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			if (((Il2CppObjectBase)val).Pointer != _lastWieldPointer)
			{
				_lastWieldPointer = ((Il2CppObjectBase)val).Pointer;
				_cachedBulletWeapon = ((Il2CppObjectBase)val).TryCast<BulletWeapon>();
				ResetReloadState();
				if ((Object)(object)_cachedBulletWeapon != (Object)null)
				{
					_currentWeaponName = ((Item)_cachedBulletWeapon).PublicName;
					_lastReloadDuration = ((ItemEquippable)_cachedBulletWeapon).ArchetypeData.DefaultReloadTime * GetWeaponMultiplier(_cachedBulletWeapon);
				}
				UpdateUIPosition();
			}
			if ((Object)(object)_cachedBulletWeapon == (Object)null)
			{
				return;
			}
			if (!_reflectionChecked && GuiManager.CrosshairLayer != null)
			{
				InitializeReflection();
			}
			bool isReloading = ((ItemEquippable)_cachedBulletWeapon).IsReloading;
			if (isReloading && !_isReloading && !_waitingForNativeReloadToEnd)
			{
				_isReloading = true;
				_ammoFilledThisReload = false;
				_reloadStartTime = Time.time;
				_currGlitchedText = string.Empty;
				_lastReloadDuration = ((ItemEquippable)_cachedBulletWeapon).ArchetypeData.DefaultReloadTime * GetWeaponMultiplier(_cachedBulletWeapon);
				if (!_chargeShown && _circleTarget != null)
				{
					if (_chargeUpColOrgField != null)
					{
						_originalChargeColor = (Color)_chargeUpColOrgField.GetValue(_circleTarget);
					}
					_setChargeColorMethod?.Invoke(_circleTarget, new object[1] { EntryPoint.ParsedChargeColor });
					_chargeUpColOrgField?.SetValue(_circleTarget, EntryPoint.ParsedChargeColor);
					_setChargeUpVisibleAndProgressMethod?.Invoke(GuiManager.CrosshairLayer, new object[2] { true, 0f });
					_showChargeMethod?.Invoke(_circleTarget, new object[1] { true });
					_chargeShown = true;
				}
			}
			else if (!isReloading)
			{
				_waitingForNativeReloadToEnd = false;
				if (_isReloading)
				{
					if (!_isAnimatingReady)
					{
						ResetReloadState();
					}
					else
					{
						_isReloading = false;
					}
				}
			}
			if (_isAnimatingReady && Time.time - _readyEffectStartTime >= 0.4f)
			{
				ResetReloadState();
			}
			if (isReloading || _isAnimatingReady)
			{
				return;
			}
			int clip = _cachedBulletWeapon.m_clip;
			int clipSize = ((ItemEquippable)_cachedBulletWeapon).ClipSize;
			if (clip < _lastClipCount && clip >= 0)
			{
				_lastFireTime = Time.time;
			}
			_lastClipCount = clip;
			if (isReloading || _isAnimatingReady)
			{
				return;
			}
			float num = ((clipSize <= 20) ? 0.5f : (EntryPoint.ConfigLowAmmoThreshold?.Value ?? 0.35f));
			if ((float)clip <= (float)clipSize * num)
			{
				if (Time.time - _lastGlitchTime > 0.08f)
				{
					_lastGlitchTime = Time.time;
					bool flag = clip == 0;
					string original = "RELOAD";
					_currGlitchedText = GetGlitchedText(original, flag ? 0.4f : 0.25f);
				}
			}
			else
			{
				_currGlitchedText = string.Empty;
			}
		}

		private void LateUpdate()
		{
			//IL_0580: Unknown result type (might be due to invalid IL or missing references)
			//IL_0585: Unknown result type (might be due to invalid IL or missing references)
			//IL_059f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_041a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0515: Unknown result type (might be due to invalid IL or missing references)
			//IL_052b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0479: Unknown result type (might be due to invalid IL or missing references)
			//IL_047e: Unknown result type (might be due to invalid IL or missing references)
			//IL_048f: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_075f: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0783: Unknown result type (might be due to invalid IL or missing references)
			//IL_07a5: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_cachedBulletWeapon == (Object)null || (Object)(object)_localPlayer == (Object)null)
			{
				return;
			}
			ApplyHUDSway();
			bool isReloading = ((ItemEquippable)_cachedBulletWeapon).IsReloading;
			bool flag = _isAnimatingReady && Time.time - _readyEffectStartTime < 0.4f;
			bool flag2 = isReloading && !_ammoFilledThisReload;
			bool flag3 = false;
			if (flag2 || flag || !string.IsNullOrEmpty(_currGlitchedText))
			{
				int clip = _cachedBulletWeapon.m_clip;
				int clipSize = ((ItemEquippable)_cachedBulletWeapon).ClipSize;
				string text = ((flag2 || flag) ? "" : $"[{clip}/{clipSize}] ");
				string text2 = "";
				float num = 1f;
				if (flag)
				{
					text2 = "";
					if (_circleTarget != null)
					{
						float num2 = Mathf.Clamp01((Time.time - _readyEffectStartTime) / 0.4f);
						float num3 = Mathf.Lerp(1.25f, 1f, num2);
						GameObject gameObject = _circleTarget.Cast<Component>().gameObject;
						if ((Object)(object)gameObject != (Object)null)
						{
							gameObject.transform.localScale = new Vector3(num3, num3, 1f);
						}
						_showChargeMethod?.Invoke(_circleTarget, new object[1] { true });
						_setChargeMethod?.Invoke(_circleTarget, new object[1] { 1f });
						_setChargeUpVisibleAndProgressMethod?.Invoke(GuiManager.CrosshairLayer, new object[2] { true, 1f });
					}
				}
				else if (flag2)
				{
					float num4 = Time.time - _reloadStartTime;
					float num5 = 0.9f;
					if (_refreshRatioMap.ContainsKey(_currentWeaponName))
					{
						num5 = _refreshRatioMap[_currentWeaponName];
					}
					else if (((ItemEquippable)_cachedBulletWeapon).ArchetypeData.DefaultClipSize > 10)
					{
						num5 = 0.6f;
					}
					float num6 = _lastReloadDuration * num5;
					float num7 = Mathf.Clamp01(num4 / num6);
					float num8 = Mathf.Max(0f, num6 - num4);
					text2 = ((num8 > 0f) ? $"{num8:0.00}s" : "");
					if (_circleTarget != null)
					{
						_showChargeMethod?.Invoke(_circleTarget, new object[1] { true });
						_setChargeMethod?.Invoke(_circleTarget, new object[1] { num7 });
						_setChargeUpVisibleAndProgressMethod?.Invoke(GuiManager.CrosshairLayer, new object[2] { true, num7 });
						GameObject gameObject2 = _circleTarget.Cast<Component>().gameObject;
						if ((Object)(object)gameObject2 != (Object)null)
						{
							gameObject2.transform.localScale = Vector3.one;
						}
					}
				}
				else if (!string.IsNullOrEmpty(_currGlitchedText))
				{
					text2 = "RELOAD";
				}
				((TMP_Text)_textMesh).text = text + text2;
				if (flag)
				{
					((TMP_Text)_textMesh).text = string.Empty;
					((Graphic)_textMesh).color = new Color(0f, 0f, 0f, 0f);
					flag3 = false;
				}
				else if (!string.IsNullOrEmpty(_currGlitchedText) && !isReloading)
				{
					float a = ((Mathf.Floor(Time.time * 5f) % 2f == 0f) ? 0.85f : 0.75f) * num;
					Color parsedLowAmmoColor = EntryPoint.ParsedLowAmmoColor;
					parsedLowAmmoColor.a = a;
					((Graphic)_textMesh).color = parsedLowAmmoColor;
					float value = Random.value;
					float num9 = 0f;
					if (value < 0.04f)
					{
						num9 = Random.Range(-6f, 6f);
					}
					else if (value < 0.05f)
					{
						num9 = Random.Range(-12f, 12f);
					}
					((Transform)((TMP_Text)_textMesh).rectTransform).localPosition = new Vector3(num9, 0f, 0f);
					flag3 = false;
				}
				else
				{
					((Graphic)_textMesh).color = Color.white;
					((Transform)((TMP_Text)_textMesh).rectTransform).localPosition = Vector3.zero;
					flag3 = false;
				}
			}
			else
			{
				((TMP_Text)_textMesh).text = string.Empty;
			}
			if (!flag3)
			{
				ClearGlitchLayers();
			}
			if (_circleTarget == null)
			{
				return;
			}
			if (flag)
			{
				Color color = ((Graphic)_textMesh).color;
				_setChargeColorMethod?.Invoke(_circleTarget, new object[1] { color });
			}
			else if (flag2)
			{
				_setChargeColorMethod?.Invoke(_circleTarget, new object[1] { EntryPoint.ParsedChargeColor });
			}
			if (flag2 || flag)
			{
				return;
			}
			if (isReloading)
			{
				_setChargeUpVisibleAndProgressMethod?.Invoke(GuiManager.CrosshairLayer, new object[2] { false, 0f });
				_showChargeMethod?.Invoke(_circleTarget, new object[1] { false });
				_setChargeMethod?.Invoke(_circleTarget, new object[1] { 0f });
				GameObject gameObject3 = _circleTarget.Cast<Component>().gameObject;
				if ((Object)(object)gameObject3 != (Object)null)
				{
					gameObject3.transform.localScale = Vector3.one;
				}
				return;
			}
			_setChargeUpVisibleAndProgressMethod?.Invoke(GuiManager.CrosshairLayer, new object[2] { false, 0f });
			_showChargeMethod?.Invoke(_circleTarget, new object[1] { false });
			_setChargeMethod?.Invoke(_circleTarget, new object[1] { 0f });
			GameObject gameObject4 = _circleTarget.Cast<Component>().gameObject;
			if ((Object)(object)gameObject4 != (Object)null)
			{
				gameObject4.transform.localScale = Vector3.one;
			}
			_setChargeColorMethod?.Invoke(_circleTarget, new object[1] { _originalChargeColor });
			_chargeUpColOrgField?.SetValue(_circleTarget, _originalChargeColor);
		}

		private void ClearGlitchLayers()
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_glitchTextMesh != (Object)null)
			{
				((TMP_Text)_glitchTextMesh).text = "";
				((Graphic)_glitchTextMesh).color = new Color(0f, 0f, 0f, 0f);
			}
			if ((Object)(object)_glitchTextMesh2 != (Object)null)
			{
				((TMP_Text)_glitchTextMesh2).text = "";
				((Graphic)_glitchTextMesh2).color = new Color(0f, 0f, 0f, 0f);
			}
		}

		private void UpdateGlitchArt(Color baseColor)
		{
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: 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)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_glitchTextMesh == (Object)null) && !((Object)(object)_glitchTextMesh2 == (Object)null) && Time.frameCount % 4 == 0)
			{
				((TMP_Text)_glitchTextMesh).text = GetGlitchedText(((TMP_Text)_textMesh).text, 0.08f);
				((TMP_Text)_glitchTextMesh2).text = GetGlitchedText(((TMP_Text)_textMesh).text, 0.04f);
				float num = Time.time * 15f;
				float num2 = Mathf.Sin(num) * 0.4f;
				float num3 = Mathf.Cos(num * 0.8f) * 0.3f;
				float num4 = ((Random.value > 0.01f) ? 1f : 0.5f);
				float num5 = ((baseColor.r > 0.5f && baseColor.g < 0.5f) ? 0.35f : 0.12f);
				Color color = baseColor;
				color.a = num5 * num4;
				((Transform)((TMP_Text)_glitchTextMesh).rectTransform).localPosition = new Vector3(num2, num3, 0f);
				((Graphic)_glitchTextMesh).color = color;
				((Transform)((TMP_Text)_glitchTextMesh2).rectTransform).localPosition = new Vector3((0f - num2) * 0.4f, (0f - num3) * 0.4f, 0f);
				color.a = num5 * 0.7f * num4;
				((Graphic)_glitchTextMesh2).color = color;
			}
		}

		private string GetGlitchedText(string original, float intensity)
		{
			if (string.IsNullOrEmpty(original) || Random.value > intensity)
			{
				return original;
			}
			char[] array = original.ToCharArray();
			int num = Random.Range(0, array.Length);
			if (array[num] != ' ' && array[num] != '[' && array[num] != ']' && array[num] != '[' && array[num] != ']')
			{
				array[num] = "#@&!$%01X?"[Random.Range(0, "#@&!$%01X?".Length)];
			}
			return new string(array);
		}

		private void ResetReloadState()
		{
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			_isReloading = false;
			_isAnimatingReady = false;
			_hasTriggeredReadyEffect = false;
			_readyEffectStartTime = -1f;
			((TMP_Text)_textMesh).text = string.Empty;
			_currGlitchedText = string.Empty;
			_lastClipCount = -1;
			_waitingForNativeReloadToEnd = (Object)(object)_cachedBulletWeapon != (Object)null && ((ItemEquippable)_cachedBulletWeapon).IsReloading;
			if (_circleTarget != null)
			{
				_showChargeMethod?.Invoke(_circleTarget, new object[1] { false });
				_setChargeMethod?.Invoke(_circleTarget, new object[1] { 0f });
				_setChargeUpVisibleAndProgressMethod?.Invoke(GuiManager.CrosshairLayer, new object[2] { false, 0f });
				if (_chargeShown)
				{
					_setChargeColorMethod?.Invoke(_circleTarget, new object[1] { _originalChargeColor });
					_chargeUpColOrgField?.SetValue(_circleTarget, _originalChargeColor);
					_chargeShown = false;
				}
				GameObject gameObject = _circleTarget.Cast<Component>().gameObject;
				if ((Object)(object)gameObject != (Object)null)
				{
					gameObject.transform.localScale = Vector3.one;
				}
			}
			ClearGlitchLayers();
		}

		private void ApplyHUDSway()
		{
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: 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_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: 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)
			FPSCamera fPSCamera = _localPlayer.FPSCamera;
			if ((Object)(object)fPSCamera == (Object)null || _mouseLookField == null)
			{
				return;
			}
			object value = _mouseLookField.GetValue(fPSCamera);
			if (value == null || _lookYawField == null || _lookPitchField == null)
			{
				return;
			}
			float num = (float)_lookYawField.GetValue(value);
			float num2 = (float)_lookPitchField.GetValue(value);
			if (_isFirstSwayFrame)
			{
				_lastLookYaw = num;
				_lastLookPitch = num2;
				_isFirstSwayFrame = false;
				return;
			}
			float num3 = Mathf.DeltaAngle(_lastLookYaw, num);
			float num4 = Mathf.DeltaAngle(_lastLookPitch, num2);
			_lastLookYaw = num;
			_lastLookPitch = num2;
			float num5 = 1.2f;
			bool flag = false;
			if (_isAimingField != null)
			{
				flag = (bool)_isAimingField.GetValue(_cachedBulletWeapon);
			}
			if ((Object)(object)_cachedBulletWeapon != (Object)null && flag)
			{
				num5 *= 0.25f;
			}
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor((0f - num3) * num5, num4 * num5);
			if (((Vector2)(ref val)).magnitude > 12f)
			{
				val = ((Vector2)(ref val)).normalized * 12f;
			}
			_currentSwayOffset = Vector2.SmoothDamp(_currentSwayOffset, val, ref _swayVelocity, 0.12f);
			_currentSwayOffset.x = Mathf.Clamp(_currentSwayOffset.x, -12f, 12f);
			_currentSwayOffset.y = Mathf.Clamp(_currentSwayOffset.y, -12f, 12f);
			float num6 = EntryPoint.ConfigOffset?.Value ?? 85f;
			_uiRoot.transform.localPosition = new Vector3(_currentSwayOffset.x, 0f - num6 + _currentSwayOffset.y, 0f);
		}

		public void UpdateUIPosition()
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_uiRoot == (Object)null))
			{
				float num = EntryPoint.ConfigOffset?.Value ?? 85f;
				_uiRoot.transform.localPosition = new Vector3(0f, 0f - num, 0f);
			}
		}

		private float GetWeaponMultiplier(BulletWeapon weapon)
		{
			try
			{
				GearIDRange gearIDRange = ((ItemEquippable)weapon).GearIDRange;
				if (gearIDRange == null)
				{
					return 1f;
				}
				if (_getIdentifierMethod == null)
				{
					_getIdentifierMethod = ((object)gearIDRange).GetType().GetMethod("GetIdentifier");
				}
				if (_getIdentifierMethod == null)
				{
					return 1f;
				}
				for (int i = 0; i < 64; i++)
				{
					try
					{
						uint num = (uint)_getIdentifierMethod.Invoke(gearIDRange, new object[1] { (object)(InventorySlot)(byte)i });
						if (num != 0)
						{
							GearMagPartDataBlock block = GameDataBlockBase<GearMagPartDataBlock>.GetBlock(num);
							if (block != null)
							{
								return block.ReloadTimeMultiplier;
							}
						}
					}
					catch
					{
					}
				}
			}
			catch
			{
			}
			return 1f;
		}

		private void InitializeReflection()
		{
			_reflectionChecked = true;
			if (GuiManager.CrosshairLayer == null)
			{
				return;
			}
			Type type = ((object)GuiManager.CrosshairLayer).GetType();
			_setChargeUpVisibleAndProgressMethod = type.GetMethod("SetChargeUpVisibleAndProgress");
			CircleCrosshair circleCrosshair = GuiManager.CrosshairLayer.m_circleCrosshair;
			if ((Object)(object)circleCrosshair != (Object)null)
			{
				_circleTarget = (Il2CppObjectBase?)(object)circleCrosshair;
				Type type2 = ((object)circleCrosshair).GetType();
				_setChargeMethod = type2.GetMethod("SetCharge");
				_showChargeMethod = type2.GetMethod("ShowCharge");
				_setChargeColorMethod = type2.GetMethod("SetChargeUpColor");
				_chargeUpColOrgField = type2.GetField("m_chargeUpColOrg", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			}
			Type typeFromHandle = typeof(BulletWeapon);
			if ((object)_ammoField == null)
			{
				_ammoField = typeFromHandle.GetField("m_ammo", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			}
			Type typeFromHandle2 = typeof(ItemEquippable);
			if ((object)_isAimingField == null)
			{
				_isAimingField = typeFromHandle2.GetField("m_isAiming", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			}
			Type typeFromHandle3 = typeof(FPSCamera);
			if ((object)_mouseLookField == null)
			{
				_mouseLookField = typeFromHandle3.GetField("m_mouseLook", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			}
			if (_mouseLookField != null)
			{
				Type fieldType = _mouseLookField.FieldType;
				if ((object)_lookYawField == null)
				{
					_lookYawField = fieldType.GetField("m_lookYaw", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				}
				if ((object)_lookPitchField == null)
				{
					_lookPitchField = fieldType.GetField("m_lookPitch", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				}
			}
		}
	}
	[HarmonyPatch(typeof(PlayerInventoryLocal), "DoReload")]
	internal static class ReloadDonePatch
	{
		public static void Postfix()
		{
			if ((Object)(object)Zose_ReloadTimer.Instance != (Object)null)
			{
				Zose_ReloadTimer.Instance.OnAmmoRefreshed();
			}
		}
	}
}
namespace Zose_ReloadTimer.Patches
{
	[HarmonyPatch(typeof(CM_PageRundown_New), "PlaceRundown")]
	internal static class CM_PageRundown_New_PlaceRundown
	{
		private static bool InjectedFlag;

		private static void Postfix()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			if (!InjectedFlag)
			{
				InjectedFlag = true;
				GameObject val = new GameObject("RT_CompInject");
				val.AddComponent<Zose_ReloadTimer>();
				Object.DontDestroyOnLoad((Object)(object)val);
			}
		}
	}
}