Decompiled source of FPSCounter v2.2.0

WhiteKnuckleFPSMod.dll

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

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("WhiteKnuckleFPSMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("WhiteKnuckleFPSMod")]
[assembly: AssemblyTitle("WhiteKnuckleFPSMod")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace WhiteKnuckleFPSMod;

public enum TextColorOptions
{
	White,
	Red,
	Green,
	Cyan,
	Yellow,
	Magenta
}
[BepInPlugin("wkfpscounter", "WK FPS Counter", "2.1.0")]
public class FPSCounterPlugin : BaseUnityPlugin
{
	private float deltaTime = 0f;

	private Text uiText;

	private int lastFontSize = -1;

	private ConfigEntry<bool> modEnabled;

	private ConfigEntry<int> fontSize;

	private ConfigEntry<float> posX;

	private ConfigEntry<float> posY;

	private ConfigEntry<TextColorOptions> textColor;

	private void Awake()
	{
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Expected O, but got Unknown
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Expected O, but got Unknown
		modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "Enabled", true, "Turn the FPS counter on or off");
		fontSize = ((BaseUnityPlugin)this).Config.Bind<int>("2 - Visuals", "FontSize", 14, "Size of the FPS text");
		posX = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Visuals", "PositionX", 10f, "X position (from left)");
		posY = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Visuals", "PositionY", -2f, "Y position (negative goes down)");
		textColor = ((BaseUnityPlugin)this).Config.Bind<TextColorOptions>("2 - Visuals", "Color", TextColorOptions.White, "Color of the text");
		((BaseUnityPlugin)this).Logger.LogInfo((object)"WK FPS Counter Mod Loaded!");
		Camera.onPreRender = (CameraCallback)Delegate.Combine((Delegate?)(object)Camera.onPreRender, (Delegate?)new CameraCallback(OnCameraRender));
	}

	private void OnCameraRender(Camera cam)
	{
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Expected O, but got Unknown
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Expected O, but got Unknown
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0250: Unknown result type (might be due to invalid IL or missing references)
		//IL_0263: Unknown result type (might be due to invalid IL or missing references)
		//IL_0276: Unknown result type (might be due to invalid IL or missing references)
		//IL_0289: Unknown result type (might be due to invalid IL or missing references)
		//IL_029c: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02af: Unknown result type (might be due to invalid IL or missing references)
		deltaTime += (Time.unscaledDeltaTime - deltaTime) * 0.1f;
		float num = 1f / deltaTime;
		if ((Object)(object)uiText == (Object)null)
		{
			GameObject val = new GameObject("WK_FPSCanvas");
			Canvas val2 = val.AddComponent<Canvas>();
			val2.renderMode = (RenderMode)0;
			val2.sortingOrder = 32767;
			val.AddComponent<CanvasScaler>();
			val.AddComponent<GraphicRaycaster>();
			GameObject val3 = new GameObject("WK_FPSText");
			val3.transform.SetParent(val.transform, false);
			uiText = val3.AddComponent<Text>();
			uiText.font = Font.CreateDynamicFontFromOSFont("Arial", 48);
			uiText.fontStyle = (FontStyle)0;
			uiText.alignment = (TextAnchor)0;
			RectTransform component = ((Component)uiText).GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0f, 1f);
			component.anchorMax = new Vector2(0f, 1f);
			component.pivot = new Vector2(0f, 1f);
			component.sizeDelta = new Vector2(500f, 500f);
			uiText.horizontalOverflow = (HorizontalWrapMode)1;
			uiText.verticalOverflow = (VerticalWrapMode)1;
		}
		if ((Object)(object)uiText != (Object)null)
		{
			((Behaviour)uiText).enabled = modEnabled.Value;
			uiText.text = $"FPS: {Mathf.CeilToInt(num)}";
			uiText.fontSize = fontSize.Value;
			if (lastFontSize != fontSize.Value)
			{
				lastFontSize = fontSize.Value;
				uiText.font.RequestCharactersInTexture("FPS: 0123456789", fontSize.Value, (FontStyle)0);
				((Graphic)uiText).SetAllDirty();
			}
			switch (textColor.Value)
			{
			case TextColorOptions.Red:
				((Graphic)uiText).color = Color.red;
				break;
			case TextColorOptions.Green:
				((Graphic)uiText).color = Color.green;
				break;
			case TextColorOptions.Cyan:
				((Graphic)uiText).color = Color.cyan;
				break;
			case TextColorOptions.Yellow:
				((Graphic)uiText).color = Color.yellow;
				break;
			case TextColorOptions.Magenta:
				((Graphic)uiText).color = Color.magenta;
				break;
			default:
				((Graphic)uiText).color = Color.white;
				break;
			}
			RectTransform component2 = ((Component)uiText).GetComponent<RectTransform>();
			component2.anchoredPosition = new Vector2(posX.Value, posY.Value);
		}
	}
}