using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using TMPro;
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(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("FPSDisplay")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FPSDisplay")]
[assembly: AssemblyTitle("FPSDisplay")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.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;
}
}
}
[BepInPlugin("com.zizzy.fpsdisplay", "FPS Display", "1.0.0")]
public class FPSDisplayPlugin : BaseUnityPlugin
{
private GameObject canvasGO;
private TextMeshProUGUI fpsText;
private RectTransform textRect;
private ConfigEntry<string> cornerConfig;
private ConfigEntry<int> fontSizeConfig;
private ConfigEntry<float> marginTopConfig;
private ConfigEntry<float> marginBottomConfig;
private ConfigEntry<float> marginLeftConfig;
private ConfigEntry<float> marginRightConfig;
private ConfigEntry<float> updateIntervalConfig;
private float updateInterval = 0.5f;
private readonly string fontName = "DarumaDropOne-Regular SDF";
private void Awake()
{
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Expected O, but got Unknown
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Expected O, but got Unknown
updateIntervalConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Display", "UpdateInterval", 0.3f, new ConfigDescription("Time between FPS updates in seconds (0-1)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
updateIntervalConfig.SettingChanged += delegate
{
updateInterval = Mathf.Clamp(updateIntervalConfig.Value, 0f, 1f);
};
updateInterval = Mathf.Clamp(updateIntervalConfig.Value, 0f, 1f);
cornerConfig = ((BaseUnityPlugin)this).Config.Bind<string>("Display", "Corner", "TopLeft", new ConfigDescription("Corner", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[4] { "TopLeft", "TopRight", "BottomLeft", "BottomRight" }), Array.Empty<object>()));
fontSizeConfig = ((BaseUnityPlugin)this).Config.Bind<int>("Display", "FontSize", 20, (ConfigDescription)null);
marginTopConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Display", "MarginTop", 15f, (ConfigDescription)null);
marginBottomConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Display", "MarginBottom", 15f, (ConfigDescription)null);
marginLeftConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Display", "MarginLeft", 5f, (ConfigDescription)null);
marginRightConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Display", "MarginRight", 5f, (ConfigDescription)null);
cornerConfig.SettingChanged += delegate
{
UpdatePosition();
};
fontSizeConfig.SettingChanged += delegate
{
UpdateFontSize();
};
marginTopConfig.SettingChanged += delegate
{
UpdatePosition();
};
marginBottomConfig.SettingChanged += delegate
{
UpdatePosition();
};
marginLeftConfig.SettingChanged += delegate
{
UpdatePosition();
};
marginRightConfig.SettingChanged += delegate
{
UpdatePosition();
};
((MonoBehaviour)this).StartCoroutine(InitGUI());
}
private IEnumerator InitGUI()
{
yield return null;
canvasGO = new GameObject("FPSCanvas");
Canvas canvas = canvasGO.AddComponent<Canvas>();
canvas.renderMode = (RenderMode)0;
canvas.sortingOrder = 1000;
CanvasScaler scaler = canvasGO.AddComponent<CanvasScaler>();
scaler.uiScaleMode = (ScaleMode)1;
scaler.referenceResolution = new Vector2(1920f, 1080f);
canvasGO.AddComponent<GraphicRaycaster>();
GameObject textGO = new GameObject("FPSText");
textGO.transform.SetParent(canvasGO.transform, false);
fpsText = textGO.AddComponent<TextMeshProUGUI>();
TMP_FontAsset foundFont = null;
TMP_FontAsset[] fonts = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
for (int i = 0; i < fonts.Length; i++)
{
if (((Object)fonts[i]).name == fontName)
{
foundFont = fonts[i];
break;
}
}
((TMP_Text)fpsText).font = foundFont ?? Resources.GetBuiltinResource<TMP_FontAsset>("LiberationSans SDF.asset");
((TMP_Text)fpsText).fontSize = fontSizeConfig.Value;
((Graphic)fpsText).color = Color.white;
((TMP_Text)fpsText).enableWordWrapping = false;
((TMP_Text)fpsText).overflowMode = (TextOverflowModes)0;
textRect = textGO.GetComponent<RectTransform>();
UpdatePosition();
Object.DontDestroyOnLoad((Object)(object)canvasGO);
((MonoBehaviour)this).StartCoroutine(UpdateFPSLoop());
}
private void UpdateFontSize()
{
if ((Object)(object)fpsText != (Object)null)
{
((TMP_Text)fpsText).fontSize = fontSizeConfig.Value;
}
}
private void UpdatePosition()
{
//IL_0016: 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_001c: Unknown result type (might be due to invalid IL or missing references)
//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_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0157: Unknown result type (might be due to invalid IL or missing references)
//IL_0158: Unknown result type (might be due to invalid IL or missing references)
//IL_0159: Unknown result type (might be due to invalid IL or missing references)
//IL_0161: Unknown result type (might be due to invalid IL or missing references)
//IL_016f: Unknown result type (might be due to invalid IL or missing references)
//IL_017c: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: 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_00f8: 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_012a: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)textRect == (Object)null))
{
Vector2 val = Vector2.zero;
Vector2 zero = Vector2.zero;
Vector2 zero2 = Vector2.zero;
switch (cornerConfig.Value)
{
case "TopLeft":
((Vector2)(ref zero))..ctor(0f, 1f);
val = zero;
((Vector2)(ref zero2))..ctor(marginLeftConfig.Value, 0f - marginTopConfig.Value);
break;
case "TopRight":
((Vector2)(ref zero))..ctor(1f, 1f);
val = zero;
((Vector2)(ref zero2))..ctor(0f - marginRightConfig.Value, 0f - marginTopConfig.Value);
break;
case "BottomLeft":
((Vector2)(ref zero))..ctor(0f, 0f);
val = zero;
((Vector2)(ref zero2))..ctor(marginLeftConfig.Value, marginBottomConfig.Value);
break;
case "BottomRight":
((Vector2)(ref zero))..ctor(1f, 0f);
val = zero;
((Vector2)(ref zero2))..ctor(0f - marginRightConfig.Value, marginBottomConfig.Value);
break;
}
RectTransform obj = textRect;
Vector2 anchorMin = (textRect.anchorMax = val);
obj.anchorMin = anchorMin;
textRect.pivot = zero;
textRect.anchoredPosition = zero2;
}
}
private IEnumerator UpdateFPSLoop()
{
while (true)
{
if ((Object)(object)fpsText != (Object)null)
{
((TMP_Text)fpsText).text = $"FPS: {Mathf.RoundToInt(1f / Mathf.Max(Time.unscaledDeltaTime, 0.0001f))}";
}
yield return (object)new WaitForSeconds(updateInterval);
}
}
}