using System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using BepInEx.Configuration; using Microsoft.CodeAnalysis; using RoR2; using RoR2.UI; 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: AssemblyVersion("0.0.0.0")] [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; } } } [BepInPlugin("LocalMods.ClientFPS", "Client FPS", "1.0.1")] public sealed class ClientFPS : BaseUnityPlugin { private ConfigEntry visible; private ConfigEntry size; private ConfigEntry margin; private ConfigEntry interval; private ConfigEntry toggle; private ConfigEntry right; private readonly Stopwatch clock = Stopwatch.StartNew(); private double lastSample; private double nextProbe; private int frames; private int lastState = int.MinValue; private uint previousCount; private bool haveCount; private bool warned; private FieldInfo stateField; private FieldInfo countField; private static readonly FieldInfo hudCanvasField = typeof(HUD).GetField("canvas", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); private GameObject overlay; private TextMeshProUGUI text; private string label = "Game: measuring..."; private void Awake() { //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Expected O, but got Unknown //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Expected O, but got Unknown //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Expected O, but got Unknown //IL_0108: Unknown result type (might be due to invalid IL or missing references) visible = ((BaseUnityPlugin)this).Config.Bind("Display", "Enabled", true, "Show the FPS overlay."); right = ((BaseUnityPlugin)this).Config.Bind("Display", "TopRight", false, "Anchor to the top right; false uses top left."); size = ((BaseUnityPlugin)this).Config.Bind("Display", "FontSize", 20, new ConfigDescription("Text size at 1080p; scales with the screen.", (AcceptableValueBase)(object)new AcceptableValueRange(12, 48), Array.Empty())); margin = ((BaseUnityPlugin)this).Config.Bind("Display", "Margin", 12, new ConfigDescription("Distance from screen edges.", (AcceptableValueBase)(object)new AcceptableValueRange(0, 200), Array.Empty())); interval = ((BaseUnityPlugin)this).Config.Bind("Display", "RefreshSeconds", 0.5f, new ConfigDescription("Measurement window; lower values fluctuate more.", (AcceptableValueBase)(object)new AcceptableValueRange(0.25f, 2f), Array.Empty())); toggle = ((BaseUnityPlugin)this).Config.Bind("Display", "ToggleKey", new KeyboardShortcut((KeyCode)290, Array.Empty()), "Toggle this counter."); lastSample = clock.Elapsed.TotalSeconds; ((BaseUnityPlugin)this).Logger.LogInfo((object)"Client FPS ready. Game FPS uses real time; FG output uses SDK presentation counts, never an estimated multiplier. F9 toggles."); } private void Probe(double now) { if (now < nextProbe) { return; } nextProbe = now + 5.0; Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly in assemblies) { Type type = assembly.GetType("RiskOfRainUpscaling.NativeApi", throwOnError: false); if (!(type == null)) { stateField = type.GetField("FrameGenerationState", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); countField = type.GetField("FrameGenerationPresentedFrames", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); break; } } } private void Update() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) KeyboardShortcut value = toggle.Value; if (((KeyboardShortcut)(ref value)).IsDown()) { visible.Value = !visible.Value; } double totalSeconds = clock.Elapsed.TotalSeconds; frames++; double num = totalSeconds - lastSample; if (num < (double)interval.Value) { return; } double num2 = (double)frames / num; string text = "FG: unavailable"; try { if (stateField == null || countField == null) { Probe(totalSeconds); } Delegate obj = ((stateField == null) ? null : (stateField.GetValue(null) as Delegate)); Delegate obj2 = ((countField == null) ? null : (countField.GetValue(null) as Delegate)); if ((object)obj != null && (object)obj2 != null) { int num3 = (int)obj.DynamicInvoke(); uint current = (uint)(int)obj2.DynamicInvoke(); if (num3 == 3) { double num4 = PresentationRate.Measure(previousCount, current, num, haveCount && lastState == 3); text = ((!double.IsNaN(num4)) ? ("Output: " + Math.Round(num4).ToString("0") + " FPS (FG)") : "Output: measuring... (FG)"); } else { text = ((num3 == 2) ? "FG: waiting for gameplay" : ((num3 == 1) ? "FG: restart/startup pending" : ((num3 < 0) ? "FG: error" : "FG: off"))); } previousCount = current; lastState = num3; haveCount = true; } else { haveCount = false; lastState = int.MinValue; } } catch (Exception ex) { haveCount = false; lastState = int.MinValue; text = "FG: unavailable"; if (!warned) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Optional upscaler telemetry unavailable: " + ex.GetType().Name)); warned = true; } } label = "Game: " + Math.Round(num2).ToString("0") + " FPS | " + (1000.0 / num2).ToString("0.0") + " ms\n" + text; lastSample = totalSeconds; frames = 0; Draw(); } private void Draw() { //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Expected O, but got Unknown //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Expected O, but got Unknown //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_0190: Unknown result type (might be due to invalid IL or missing references) //IL_0322: Unknown result type (might be due to invalid IL or missing references) //IL_032a: Unknown result type (might be due to invalid IL or missing references) //IL_032c: Unknown result type (might be due to invalid IL or missing references) //IL_032d: Unknown result type (might be due to invalid IL or missing references) //IL_0335: Unknown result type (might be due to invalid IL or missing references) //IL_0372: Unknown result type (might be due to invalid IL or missing references) //IL_0391: Unknown result type (might be due to invalid IL or missing references) TMP_FontAsset defaultLanguageFont = HGTextMeshProUGUI.defaultLanguageFont; if (!Object.op_Implicit((Object)(object)defaultLanguageFont)) { return; } if (!Object.op_Implicit((Object)(object)overlay)) { overlay = new GameObject("Client FPS Overlay", new Type[3] { typeof(RectTransform), typeof(Canvas), typeof(CanvasScaler) }); Object.DontDestroyOnLoad((Object)(object)overlay); Canvas component = overlay.GetComponent(); component.renderMode = (RenderMode)0; component.sortingOrder = 32760; CanvasScaler component2 = overlay.GetComponent(); component2.uiScaleMode = (ScaleMode)1; component2.referenceResolution = new Vector2(1920f, 1080f); component2.matchWidthOrHeight = 1f; GameObject val = new GameObject("FPS", new Type[2] { typeof(RectTransform), typeof(TextMeshProUGUI) }); val.transform.SetParent(overlay.transform, false); text = val.GetComponent(); ((Graphic)text).raycastTarget = false; ((TMP_Text)text).richText = false; ((TMP_Text)text).enableWordWrapping = false; ((Graphic)text).color = new Color(0.9f, 0.9f, 0.87f); ((TMP_Text)text).font = defaultLanguageFont; ((TMP_Text)text).outlineColor = new Color32((byte)15, (byte)18, (byte)23, byte.MaxValue); ((TMP_Text)text).outlineWidth = 0.18f; } overlay.SetActive(visible.Value); Camera val2 = null; foreach (HUD readOnlyInstance in HUD.readOnlyInstanceList) { Canvas val3 = (Canvas)((Object.op_Implicit((Object)(object)readOnlyInstance) && hudCanvasField != null) ? /*isinst with value type is only supported in some contexts*/: null); if (Object.op_Implicit((Object)(object)val3) && Object.op_Implicit((Object)(object)val3.worldCamera) && ((Behaviour)val3.worldCamera).isActiveAndEnabled) { val2 = val3.worldCamera; break; } } Canvas component3 = overlay.GetComponent(); if (Object.op_Implicit((Object)(object)val2)) { overlay.layer = 5; ((Component)text).gameObject.layer = 5; component3.renderMode = (RenderMode)1; component3.worldCamera = val2; component3.planeDistance = val2.nearClipPlane + 0.1f; component3.targetDisplay = val2.targetDisplay; } else { component3.renderMode = (RenderMode)0; component3.worldCamera = null; if (Object.op_Implicit((Object)(object)Run.instance)) { overlay.SetActive(false); } } RectTransform rectTransform = ((TMP_Text)text).rectTransform; Vector2 val4 = default(Vector2); ((Vector2)(ref val4))..ctor((float)(right.Value ? 1 : 0), 1f); rectTransform.pivot = val4; Vector2 anchorMin = (rectTransform.anchorMax = val4); rectTransform.anchorMin = anchorMin; rectTransform.anchoredPosition = new Vector2((float)(right.Value ? (-margin.Value) : margin.Value), (float)(-margin.Value)); rectTransform.sizeDelta = new Vector2(700f, (float)(size.Value * 3)); ((TMP_Text)text).fontSize = size.Value; ((TMP_Text)text).alignment = (TextAlignmentOptions)(right.Value ? 260 : 257); ((TMP_Text)text).text = label; } private void OnDestroy() { if (Object.op_Implicit((Object)(object)overlay)) { Object.Destroy((Object)(object)overlay); } } } public static class PresentationRate { public static double Measure(uint previous, uint current, double seconds, bool continuous) { if (!continuous || seconds <= 0.0 || double.IsNaN(seconds) || double.IsInfinity(seconds)) { return double.NaN; } uint num = current - previous; double num2 = (double)num / seconds; return (num != 0 && num2 < 10000.0) ? num2 : double.NaN; } }