Decompiled source of FPSCounter v1.4.0

BepInEx/plugins/FPSCounter.dll

Decompiled 8 months ago
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using FPSCounter.Compatibility;
using FPSCounter.Config;
using FPSCounter.Patches;
using HarmonyLib;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("FPSCounter")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FPSCounter")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("68bc4741-12ed-4a19-80ea-9a379b167c12")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace FPSCounter
{
	internal class FPSCounterGUI : MonoBehaviour
	{
		public static GUIStyle style;

		[SerializeField]
		[Range(0f, 1f)]
		private static float _expSmoothingFactor = 0.1f;

		[SerializeField]
		public static float _refreshFrequency = General.refreshFrequency.Value;

		private static float _timeSinceUpdate = 0f;

		private static float _averageFps = 1f;

		private float count;

		public int XPosition = PersistantCounter.XPosition.Value;

		public int YPosition = PersistantCounter.YPosition.Value;

		private IEnumerator Start()
		{
			style = new GUIStyle();
			UpdateGUISize();
			UpdateGUIColor();
			GUI.depth = 2;
			while (true)
			{
				getAverageFPS();
				yield return (object)new WaitForSeconds(0.1f);
			}
		}

		private void getAverageFPS()
		{
			_averageFps = _expSmoothingFactor * _averageFps + (1f - _expSmoothingFactor) * 1f / Time.unscaledDeltaTime;
			if (_timeSinceUpdate < _refreshFrequency)
			{
				_timeSinceUpdate += Time.deltaTime;
			}
			else
			{
				count = Mathf.RoundToInt(_averageFps);
			}
		}

		public static void UpdateGUISize()
		{
			FPSCounterBase.debugLog("Updating GUI size to " + PersistantCounter.Size.Value);
			style.fontSize = PersistantCounter.Size.Value;
		}

		public static void UpdateGUIColor()
		{
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			FPSCounterBase.debugLog("Updating GUI color to: " + PersistantCounter.Color.Value);
			if (PersistantCounter.Color.Value != PersistantCounter.PersistentCounterColors.custom)
			{
				style.normal.textColor = (Color)typeof(Color).GetProperty(PersistantCounter.Color.Value.ToString()).GetValue(null, null);
				style.hover.textColor = (Color)typeof(Color).GetProperty(PersistantCounter.Color.Value.ToString()).GetValue(null, null);
			}
			else
			{
				Color textColor = default(Color);
				((Color)(ref textColor))..ctor(PersistantCounter.R.Value / 255f, PersistantCounter.G.Value / 255f, PersistantCounter.B.Value / 255f);
				style.normal.textColor = textColor;
				style.hover.textColor = textColor;
			}
		}

		private void OnGUI()
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			if (!General.disableFPS.Value && General.persistentCounter.Value)
			{
				GUI.Label(new Rect((float)PersistantCounter.XPosition.Value, (float)PersistantCounter.YPosition.Value, 100f, 25f), "FPS: " + Mathf.Round(count), style);
			}
		}
	}
	[BepInPlugin("bctix.FPSCounter", "FPS_Counter", "1.4.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class FPSCounterBase : BaseUnityPlugin
	{
		private const string modGUID = "bctix.FPSCounter";

		private const string modName = "FPS_Counter";

		private const string modVersion = "1.4.0";

		private readonly Harmony harmony = new Harmony("bctix.FPSCounter");

		private static FPSCounterBase Instance;

		public static ManualLogSource mls;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("bctix.FPSCounter");
			mls.LogInfo((object)"Hello World!");
			Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			FPSCounter.Config.Config.init(((BaseUnityPlugin)this).Config);
			if (Chainloader.PluginInfos.ContainsKey("ainavt.lc.lethalconfig"))
			{
				LethalConfig.init();
			}
			harmony.PatchAll(typeof(FPSCounterBase));
			harmony.PatchAll(typeof(HUDPatch));
		}

		public static void debugLog(object data)
		{
		}

		private void OnDestroy()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			Object.DontDestroyOnLoad((Object)(object)new GameObject("FPSCounterGUI").AddComponent<FPSCounterGUI>());
		}
	}
}
namespace FPSCounter.Patches
{
	[HarmonyPatch(typeof(HUDManager))]
	internal class HUDPatch
	{
		public static TextMeshProUGUI _textMesh;

		[SerializeField]
		[Range(0f, 1f)]
		private static float _expSmoothingFactor = 0.1f;

		[SerializeField]
		public static float _refreshFrequency = General.refreshFrequency.Value;

		private static float _timeSinceUpdate = 0f;

		private static float _averageFps = 1f;

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void Start(ref HUDManager __instance)
		{
			//IL_0005: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("HealthHUDDisplay");
			val.AddComponent<RectTransform>();
			_textMesh = val.AddComponent<TextMeshProUGUI>();
			RectTransform rectTransform = ((TMP_Text)_textMesh).rectTransform;
			((Transform)rectTransform).SetParent(((Component)__instance.PTTIcon).transform, false);
			rectTransform.anchoredPosition = new Vector2(0f, -20f);
			((TMP_Text)_textMesh).font = ((TMP_Text)__instance.controlTipLines[0]).font;
			((TMP_Text)_textMesh).fontSize = 10f;
			((Graphic)_textMesh).color = ((Graphic)HUDManager.Instance.weightCounter).color;
			((TMP_Text)_textMesh).overflowMode = (TextOverflowModes)0;
			if (General.persistentCounter.Value)
			{
				((Behaviour)_textMesh).enabled = false;
			}
			else
			{
				((Behaviour)_textMesh).enabled = !General.disableFPS.Value;
			}
		}

		[HarmonyPatch("Update")]
		[HarmonyPrefix]
		private static void updateFPS()
		{
			_averageFps = _expSmoothingFactor * _averageFps + (1f - _expSmoothingFactor) * 1f / Time.unscaledDeltaTime;
			if (_timeSinceUpdate < _refreshFrequency)
			{
				_timeSinceUpdate += Time.deltaTime;
				return;
			}
			int num = Mathf.RoundToInt(_averageFps);
			((TMP_Text)_textMesh).text = "FPS " + num;
			_timeSinceUpdate = 0f;
		}
	}
}
namespace FPSCounter.Config
{
	internal class Config
	{
		public static void init(ConfigFile Config)
		{
			General.init(Config);
			PersistantCounter.init(Config);
		}
	}
	internal class PersistantCounter
	{
		public enum PersistentCounterColors
		{
			green,
			blue,
			red,
			yellow,
			white,
			cyan,
			custom
		}

		public enum PersistentCounterFonts
		{
			arial,
			montserrat,
			impact,
			sans,
			papyrus,
			standard_galactic,
			braille
		}

		public static ConfigEntry<PersistentCounterColors> Color;

		public static ConfigEntry<int> Size;

		public static ConfigEntry<int> XPosition;

		public static ConfigEntry<int> YPosition;

		public static ConfigEntry<float> R;

		public static ConfigEntry<float> G;

		public static ConfigEntry<float> B;

		public static void init(ConfigFile Config)
		{
			Color = Config.Bind<PersistentCounterColors>("Persistant Counter", "PersistentCounterColor", PersistentCounterColors.green, "The color of the persistent counter.");
			Color.SettingChanged += delegate
			{
				FPSCounterGUI.UpdateGUIColor();
			};
			Size = Config.Bind<int>("Persistant Counter", "PersistentCounterSize", 24, "The Size of the persistent counter. The max is 500");
			Size.SettingChanged += delegate
			{
				if (Size.Value > 500)
				{
					Size.Value = 500;
					Config.Save();
				}
				if (Size.Value < 1)
				{
					Size.Value = 1;
					Config.Save();
				}
				FPSCounterGUI.UpdateGUISize();
			};
			XPosition = Config.Bind<int>("Persistant Counter", "PersistentCounterXPosition", 10, "The X Position of the persistent counter");
			YPosition = Config.Bind<int>("Persistant Counter", "PersistentCounterYPosition", 10, "The Y Position of the persistent counter");
			R = Config.Bind<float>("Persistant Counter Color", "PersistentCounterColorR", 255f, "The R Value of the persistent counter");
			G = Config.Bind<float>("Persistant Counter Color", "PersistentCounterColorG", 255f, "The G Value of the persistent counter");
			B = Config.Bind<float>("Persistant Counter Color", "PersistentCounterColorB", 255f, "The B Value of the persistent counter");
			ConfigEntry<float>[] array = new ConfigEntry<float>[3] { R, G, B };
			foreach (ConfigEntry<float> setting in array)
			{
				setting.SettingChanged += delegate
				{
					if (setting.Value > 255f)
					{
						setting.Value = 255f;
					}
					if (setting.Value < 0f)
					{
						setting.Value = 0f;
					}
					Config.Save();
					FPSCounterGUI.UpdateGUIColor();
				};
			}
		}
	}
	internal class General
	{
		public static ConfigEntry<bool> disableFPS;

		public static ConfigEntry<bool> persistentCounter;

		public static ConfigEntry<float> refreshFrequency;

		public static void init(ConfigFile Config)
		{
			disableFPS = Config.Bind<bool>("General", "HideCounter", false, "Hides the FPS counter.");
			disableFPS.SettingChanged += delegate
			{
				if (disableFPS.Value)
				{
					if (Object.op_Implicit((Object)(object)HUDPatch._textMesh))
					{
						((Behaviour)HUDPatch._textMesh).enabled = false;
					}
				}
				else if (Object.op_Implicit((Object)(object)HUDPatch._textMesh))
				{
					if (persistentCounter.Value)
					{
						((Behaviour)HUDPatch._textMesh).enabled = false;
					}
					else
					{
						((Behaviour)HUDPatch._textMesh).enabled = true;
					}
				}
			};
			persistentCounter = Config.Bind<bool>("General", "PersistentCounter", false, "The counter is always showed in the corner, although it can be a bit more intrusive like this.\n\n(may not work with all mods)");
			persistentCounter.SettingChanged += delegate
			{
				if (persistentCounter.Value)
				{
					if (Object.op_Implicit((Object)(object)HUDPatch._textMesh))
					{
						((Behaviour)HUDPatch._textMesh).enabled = false;
					}
				}
				else if (Object.op_Implicit((Object)(object)HUDPatch._textMesh) && !disableFPS.Value)
				{
					((Behaviour)HUDPatch._textMesh).enabled = true;
				}
			};
			refreshFrequency = Config.Bind<float>("General", "RefreshFrequency", 0.4f, "The frequency (seconds) that the fps counter updates");
			refreshFrequency.SettingChanged += delegate
			{
				HUDPatch._refreshFrequency = refreshFrequency.Value;
				FPSCounterGUI._refreshFrequency = refreshFrequency.Value;
			};
		}
	}
}
namespace FPSCounter.Compatibility
{
	internal class LethalConfig
	{
		public static void init()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: 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)
			//IL_0067: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Expected O, but got Unknown
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Expected O, but got Unknown
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Expected O, but got Unknown
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: 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_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Expected O, but got Unknown
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Expected O, but got Unknown
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Expected O, but got Unknown
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Expected O, but got Unknown
			//IL_0131: 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_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: 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_0163: Expected O, but got Unknown
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Expected O, but got Unknown
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Expected O, but got Unknown
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Expected O, but got Unknown
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Expected O, but got Unknown
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Expected O, but got Unknown
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Expected O, but got Unknown
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Expected O, but got Unknown
			FPSCounterBase.debugLog("Lethal Config spotted, loading LCManager stuff");
			LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(General.disableFPS, new BoolCheckBoxOptions
			{
				RequiresRestart = false,
				Name = "Disable Counter"
			}));
			LethalConfigManager.AddConfigItem((BaseConfigItem)new FloatInputFieldConfigItem(General.refreshFrequency, new FloatInputFieldOptions
			{
				RequiresRestart = false,
				Min = 0f,
				Max = float.PositiveInfinity,
				Name = "Refresh Frequency"
			}));
			LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(General.persistentCounter, new BoolCheckBoxOptions
			{
				RequiresRestart = false,
				Name = "Persistant Counter"
			}));
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)new EnumDropDownConfigItem<PersistantCounter.PersistentCounterColors>(PersistantCounter.Color, new EnumDropDownOptions
			{
				RequiresRestart = false,
				Name = "Color"
			}));
			LethalConfigManager.AddConfigItem((BaseConfigItem)new IntSliderConfigItem(PersistantCounter.Size, new IntSliderOptions
			{
				Min = 1,
				Max = 500,
				RequiresRestart = false,
				Name = "Font Size"
			}));
			LethalConfigManager.AddConfigItem((BaseConfigItem)new IntInputFieldConfigItem(PersistantCounter.XPosition, new IntInputFieldOptions
			{
				Min = -10000,
				Max = 10000,
				RequiresRestart = false,
				Name = "X Position"
			}));
			LethalConfigManager.AddConfigItem((BaseConfigItem)new IntInputFieldConfigItem(PersistantCounter.YPosition, new IntInputFieldOptions
			{
				Min = -10000,
				Max = 10000,
				RequiresRestart = false,
				Name = "Y Position"
			}));
			FloatSliderConfigItem val = new FloatSliderConfigItem(PersistantCounter.R, new FloatSliderOptions
			{
				Min = 1f,
				Max = 255f,
				RequiresRestart = false,
				Name = "R"
			});
			FloatSliderConfigItem val2 = new FloatSliderConfigItem(PersistantCounter.G, new FloatSliderOptions
			{
				Min = 1f,
				Max = 255f,
				RequiresRestart = false,
				Name = "G"
			});
			FloatSliderConfigItem val3 = new FloatSliderConfigItem(PersistantCounter.B, new FloatSliderOptions
			{
				Min = 1f,
				Max = 255f,
				RequiresRestart = false,
				Name = "B"
			});
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val);
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val2);
			LethalConfigManager.AddConfigItem((BaseConfigItem)val3);
		}
	}
}