Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of REPOPerformanceKit v0.1.3
REPOPerformance.dll
Decompiled a month agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using REPOPerformance.Config; using REPOPerformance.Features; using UnityEngine; using UnityEngine.SceneManagement; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyCompany("REPOPerformance")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.1.0.0")] [assembly: AssemblyInformationalVersion("0.1.0")] [assembly: AssemblyProduct("REPOPerformance")] [assembly: AssemblyTitle("REPOPerformance")] [assembly: AssemblyVersion("0.1.0.0")] namespace REPOPerformance { [BepInPlugin("com.mentalize.repoperformance", "REPOPerformance", "0.1.0")] public class Plugin : BaseUnityPlugin { internal static ManualLogSource Log; internal static PerformanceConfig PerfConfig; private void Awake() { Log = ((BaseUnityPlugin)this).Logger; PerfConfig = new PerformanceConfig(((BaseUnityPlugin)this).Config); Log.LogInfo((object)"REPOPerformance 0.1.0 loading…"); LogSuppressor.Apply(PerfConfig, Log); FrameRateTuner.Apply(PerfConfig, Log); GCTuner.Apply(PerfConfig, Log); TextureStreamingTuner.Apply(PerfConfig, Log); AdaptivePhysics.Apply(PerfConfig, Log); CullDistanceBoost.Apply(PerfConfig, Log); FPSCounter.Apply(PerfConfig, Log); Log.LogInfo((object)"REPOPerformance ready."); } } internal static class PluginInfo { public const string Guid = "com.mentalize.repoperformance"; public const string Name = "REPOPerformance"; public const string Version = "0.1.0"; } } namespace REPOPerformance.Features { internal static class AdaptivePhysics { private sealed class AdaptivePhysicsRunner : MonoBehaviour { private PerformanceConfig _cfg; private ManualLogSource _log; private float _smoothedFps = 60f; private float _sampleTimer; private bool _degraded; public void Configure(PerformanceConfig cfg, ManualLogSource log) { _cfg = cfg; _log = log; } private void Update() { if (_cfg == null) { return; } float num = 1f / Mathf.Max(Time.unscaledDeltaTime, 0.0001f); _smoothedFps = Mathf.Lerp(_smoothedFps, num, 0.05f); _sampleTimer += Time.unscaledDeltaTime; if (!(_sampleTimer < 1f)) { _sampleTimer = 0f; if (!_degraded && _smoothedFps < _cfg.DegradeBelowFps.Value) { Time.fixedDeltaTime = _cfg.DegradedFixedDeltaTime.Value; _degraded = true; _log.LogInfo((object)($"Adaptive physics: degraded -> fixedDeltaTime={Time.fixedDeltaTime:F4} " + $"(fps {_smoothedFps:F1}).")); } else if (_degraded && _smoothedFps > _cfg.RecoverAboveFps.Value) { Time.fixedDeltaTime = _cfg.BaselineFixedDeltaTime.Value; _degraded = false; _log.LogInfo((object)($"Adaptive physics: recovered -> fixedDeltaTime={Time.fixedDeltaTime:F4} " + $"(fps {_smoothedFps:F1}).")); } } } } private static GameObject _host; public static void Apply(PerformanceConfig cfg, ManualLogSource log) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Expected O, but got Unknown if (cfg.EnableAdaptivePhysics.Value) { Time.fixedDeltaTime = cfg.BaselineFixedDeltaTime.Value; _host = new GameObject("REPOPerformance_AdaptivePhysics"); Object.DontDestroyOnLoad((Object)(object)_host); ((Object)_host).hideFlags = (HideFlags)61; _host.AddComponent<AdaptivePhysicsRunner>().Configure(cfg, log); log.LogInfo((object)"Adaptive physics runner started."); } } } internal static class CullDistanceBoost { private static PerformanceConfig _cfg; private static ManualLogSource _log; private static bool _hooked; public static void Apply(PerformanceConfig cfg, ManualLogSource log) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) if (cfg.EnableCullDistanceBoost.Value) { _cfg = cfg; _log = log; TryApply(SceneManager.GetActiveScene(), (LoadSceneMode)0); if (!_hooked) { SceneManager.sceneLoaded += TryApply; _hooked = true; } } } private static void TryApply(Scene scene, LoadSceneMode mode) { Camera main = Camera.main; if (!((Object)(object)main == (Object)null)) { float farClipPlane = main.farClipPlane; float num = farClipPlane * Mathf.Clamp(_cfg.CullDistanceMultiplier.Value, 0.25f, 1f); float[] array = new float[32]; for (int i = 0; i < 32; i++) { array[i] = ((i >= 8) ? num : 0f); } main.layerCullDistances = array; main.layerCullSpherical = true; _log.LogInfo((object)("Cull distance boost applied to '" + ((Object)main).name + "' in scene '" + ((Scene)(ref scene)).name + "' " + $"(far={farClipPlane:F0}, detail={num:F0}).")); } } } internal static class FPSCounter { private sealed class FPSCounterBehaviour : MonoBehaviour { private float _smoothed = 60f; private GUIStyle _style; private void Update() { float num = 1f / Mathf.Max(Time.unscaledDeltaTime, 0.0001f); _smoothed = Mathf.Lerp(_smoothed, num, 0.1f); } private void OnGUI() { //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0086: 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_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0020: 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_002d: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Expected O, but got Unknown if (_style == null) { GUIStyle val = new GUIStyle(GUI.skin.label) { fontSize = 14, alignment = (TextAnchor)0 }; val.normal.textColor = Color.white; _style = val; } float num = Time.unscaledDeltaTime * 1000f; string text = $"FPS {_smoothed:F0} {num:F1}ms physTick {1f / Time.fixedDeltaTime:F0}Hz"; GUIStyle style = _style; Color textColor = style.normal.textColor; style.normal.textColor = Color.black; GUI.Label(new Rect(11f, 11f, 400f, 20f), text, style); style.normal.textColor = textColor; GUI.Label(new Rect(10f, 10f, 400f, 20f), text, _style); } } private static GameObject _host; public static void Apply(PerformanceConfig cfg, ManualLogSource log) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown if (cfg.ShowFpsOverlay.Value) { _host = new GameObject("REPOPerformance_FPSCounter"); Object.DontDestroyOnLoad((Object)(object)_host); ((Object)_host).hideFlags = (HideFlags)61; _host.AddComponent<FPSCounterBehaviour>(); log.LogInfo((object)"FPS overlay enabled."); } } } internal static class FrameRateTuner { public static void Apply(PerformanceConfig cfg, ManualLogSource log) { if (cfg.MaximumDeltaTime.Value > 0f) { Time.maximumDeltaTime = cfg.MaximumDeltaTime.Value; log.LogInfo((object)$"Time.maximumDeltaTime set to {cfg.MaximumDeltaTime.Value:F3}s."); } if (cfg.VSyncCount.Value >= 0) { QualitySettings.vSyncCount = cfg.VSyncCount.Value; log.LogInfo((object)$"QualitySettings.vSyncCount set to {cfg.VSyncCount.Value}."); } if (cfg.OverrideTargetFrameRate.Value) { Application.targetFrameRate = cfg.TargetFrameRate.Value; log.LogInfo((object)$"Application.targetFrameRate set to {cfg.TargetFrameRate.Value}."); } } } internal static class GCTuner { private static PerformanceConfig _cfg; private static ManualLogSource _log; private static bool _hooked; public static void Apply(PerformanceConfig cfg, ManualLogSource log) { _cfg = cfg; _log = log; if (cfg.EnableIncrementalGC.Value) { try { Type type = Type.GetType("UnityEngine.Scripting.GarbageCollector, UnityEngine.CoreModule"); if (type != null) { PropertyInfo property = type.GetProperty("GCMode", BindingFlags.Static | BindingFlags.Public); if (property != null && property.PropertyType.IsEnum) { object value = Enum.Parse(property.PropertyType, "Enabled"); property.SetValue(null, value, null); log.LogInfo((object)"Unity incremental GC enabled."); } } } catch (Exception ex) { log.LogWarning((object)("Could not enable incremental GC: " + ex.Message)); } } if (cfg.CollectGCOnSceneLoad.Value && !_hooked) { SceneManager.sceneLoaded += OnSceneLoaded; _hooked = true; log.LogInfo((object)"GC.Collect will run on scene load."); } } private static void OnSceneLoaded(Scene scene, LoadSceneMode mode) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) if ((int)mode == 0) { GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); _log.LogInfo((object)("GC pass after loading scene '" + ((Scene)(ref scene)).name + "'.")); } } } internal static class LogSuppressor { private sealed class FilteringListener : ILogListener, IDisposable { private readonly List<string> _substrings; private readonly bool _dedupe; private readonly List<ILogListener> _downstream = new List<ILogListener>(); private string _lastMessage; private int _lastRepeat; private readonly object _lock = new object(); public LogLevel LogLevelFilter => (LogLevel)63; public FilteringListener(List<string> substrings, bool dedupe) { _substrings = substrings; _dedupe = dedupe; foreach (ILogListener item in new List<ILogListener>(Logger.Listeners)) { if (item != this) { _downstream.Add(item); Logger.Listeners.Remove(item); } } } public void LogEvent(object sender, LogEventArgs e) { //IL_001c: 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_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Expected O, but got Unknown string text = ((e.Data == null) ? string.Empty : e.Data.ToString()); if ((e.Level & 7) == 0) { string text2 = text.ToLowerInvariant(); foreach (string substring in _substrings) { if (text2.Contains(substring)) { return; } } } lock (_lock) { if (_dedupe && text == _lastMessage) { _lastRepeat++; return; } if (_lastRepeat > 0) { LogEventArgs e2 = new LogEventArgs((object)$"(previous message repeated {_lastRepeat} more times)", (LogLevel)16, e.Source); ForwardAll(sender, e2); _lastRepeat = 0; } _lastMessage = text; ForwardAll(sender, e); } } private void ForwardAll(object sender, LogEventArgs e) { foreach (ILogListener item in _downstream) { try { item.LogEvent(sender, e); } catch { } } } public void Dispose() { foreach (ILogListener item in _downstream) { try { ((IDisposable)item).Dispose(); } catch { } } _downstream.Clear(); } } private static FilteringListener _listener; public static void Apply(PerformanceConfig cfg, ManualLogSource log) { if (cfg.DisableUnityStackTraces.Value) { try { Application.SetStackTraceLogType((LogType)3, (StackTraceLogType)0); Application.SetStackTraceLogType((LogType)2, (StackTraceLogType)0); Application.SetStackTraceLogType((LogType)0, (StackTraceLogType)1); Application.SetStackTraceLogType((LogType)4, (StackTraceLogType)1); Application.SetStackTraceLogType((LogType)1, (StackTraceLogType)1); log.LogInfo((object)"Unity stack-trace capture disabled for Log/Warning."); } catch (Exception ex) { log.LogWarning((object)("Failed to set Unity stack trace log type: " + ex.Message)); } } if (cfg.SuppressPluginLogSpam.Value || cfg.DedupeRepeatedLogs.Value) { List<string> list = ParseSubstrings(cfg.SuppressedSubstrings.Value); _listener = new FilteringListener(list, cfg.DedupeRepeatedLogs.Value); Logger.Listeners.Add((ILogListener)(object)_listener); log.LogInfo((object)($"Installed filtering log listener ({list.Count} substring filters, " + $"dedupe={cfg.DedupeRepeatedLogs.Value}).")); } } private static List<string> ParseSubstrings(string raw) { List<string> list = new List<string>(); if (string.IsNullOrWhiteSpace(raw)) { return list; } string[] array = raw.Split(new char[1] { ',' }); for (int i = 0; i < array.Length; i++) { string text = array[i].Trim(); if (text.Length > 0) { list.Add(text.ToLowerInvariant()); } } return list; } } internal static class TextureStreamingTuner { public static void Apply(PerformanceConfig cfg, ManualLogSource log) { if (!cfg.EnableTextureStreaming.Value) { return; } try { QualitySettings.streamingMipmapsActive = true; int num = Mathf.Clamp(cfg.StreamingMipmapsMemoryBudget.Value, 128, 8192); QualitySettings.streamingMipmapsMemoryBudget = num; QualitySettings.streamingMipmapsMaxLevelReduction = 2; QualitySettings.streamingMipmapsMaxFileIORequests = 256; QualitySettings.streamingMipmapsAddAllCameras = true; log.LogInfo((object)$"Texture streaming enabled (budget={num}MB)."); } catch (Exception ex) { log.LogWarning((object)("Could not enable texture streaming: " + ex.Message)); } } } } namespace REPOPerformance.Config { internal sealed class PerformanceConfig { public readonly ConfigEntry<bool> DisableUnityStackTraces; public readonly ConfigEntry<bool> SuppressPluginLogSpam; public readonly ConfigEntry<string> SuppressedSubstrings; public readonly ConfigEntry<bool> DedupeRepeatedLogs; public readonly ConfigEntry<bool> OverrideTargetFrameRate; public readonly ConfigEntry<int> TargetFrameRate; public readonly ConfigEntry<int> VSyncCount; public readonly ConfigEntry<float> MaximumDeltaTime; public readonly ConfigEntry<bool> EnableAdaptivePhysics; public readonly ConfigEntry<float> BaselineFixedDeltaTime; public readonly ConfigEntry<float> DegradedFixedDeltaTime; public readonly ConfigEntry<float> DegradeBelowFps; public readonly ConfigEntry<float> RecoverAboveFps; public readonly ConfigEntry<bool> EnableCullDistanceBoost; public readonly ConfigEntry<float> CullDistanceMultiplier; public readonly ConfigEntry<bool> EnableIncrementalGC; public readonly ConfigEntry<bool> CollectGCOnSceneLoad; public readonly ConfigEntry<bool> EnableTextureStreaming; public readonly ConfigEntry<int> StreamingMipmapsMemoryBudget; public readonly ConfigEntry<bool> ShowFpsOverlay; public PerformanceConfig(ConfigFile file) { DisableUnityStackTraces = file.Bind<bool>("Logging", "DisableUnityStackTraces", true, "Disables Unity's internal stack-trace capture for Debug.Log/Warning. Stack-trace capture is one of the biggest GC sources in Unity games. Errors still keep stack traces."); SuppressPluginLogSpam = file.Bind<bool>("Logging", "SuppressPluginLogSpam", true, "Filter the BepInEx log-listener chain so repetitive plugin log lines are dropped."); SuppressedSubstrings = file.Bind<string>("Logging", "SuppressedSubstrings", "Patched method,Applying patch,Harmony.PatchAll", "Comma-separated list of case-insensitive substrings. Any log line containing one of these is dropped. Leave empty to disable substring filtering."); DedupeRepeatedLogs = file.Bind<bool>("Logging", "DedupeRepeatedLogs", true, "Collapse identical consecutive log lines (prints '(previous message x N)' instead)."); OverrideTargetFrameRate = file.Bind<bool>("FrameRate", "OverrideTargetFrameRate", false, "Force Application.targetFrameRate. Leave OFF unless you know your display refresh rate."); TargetFrameRate = file.Bind<int>("FrameRate", "TargetFrameRate", 144, "Target frame rate when OverrideTargetFrameRate is true. -1 = uncapped."); VSyncCount = file.Bind<int>("FrameRate", "VSyncCount", -1, "QualitySettings.vSyncCount. 0 = off, 1 = every refresh, 2 = every second refresh. -1 = do not change."); MaximumDeltaTime = file.Bind<float>("FrameRate", "MaximumDeltaTime", 0.1f, "Time.maximumDeltaTime. Caps how much physics catch-up the game tries after a hitch. Prevents 'physics death spiral' where a stutter triggers more stutters."); EnableAdaptivePhysics = file.Bind<bool>("AdaptivePhysics", "Enable", true, "Dynamically lower physics tick rate when FPS drops, restoring it when performance recovers."); BaselineFixedDeltaTime = file.Bind<float>("AdaptivePhysics", "BaselineFixedDeltaTime", 0.02f, "Normal Time.fixedDeltaTime (0.02 = 50Hz, Unity default)."); DegradedFixedDeltaTime = file.Bind<float>("AdaptivePhysics", "DegradedFixedDeltaTime", 0.0333f, "Fallback fixedDeltaTime under load (0.0333 = 30Hz)."); DegradeBelowFps = file.Bind<float>("AdaptivePhysics", "DegradeBelowFps", 40f, "Drop to degraded fixedDeltaTime if smoothed FPS falls below this."); RecoverAboveFps = file.Bind<float>("AdaptivePhysics", "RecoverAboveFps", 55f, "Return to baseline fixedDeltaTime if smoothed FPS rises above this. Must be above DegradeBelowFps to create a hysteresis band."); EnableCullDistanceBoost = file.Bind<bool>("Culling", "Enable", true, "Apply per-layer cull distances to the main camera so tiny/detail objects stop rendering at their multiplied distance. Invisible at conservative multipliers."); CullDistanceMultiplier = file.Bind<float>("Culling", "Multiplier", 1f, "Multiplier applied to the main camera's far clip plane to derive a detail-cull distance. 1.0 = unchanged, 0.75 = more aggressive. Only affects layers > 7."); EnableIncrementalGC = file.Bind<bool>("GC", "EnableIncrementalGC", true, "Spread GC work across frames instead of one big stall (Unity incremental GC)."); CollectGCOnSceneLoad = file.Bind<bool>("GC", "CollectGCOnSceneLoad", true, "Run a full GC.Collect during scene loads (hidden by the loading screen)."); EnableTextureStreaming = file.Bind<bool>("TextureStreaming", "Enable", true, "Enable Unity mipmap streaming. Loads only the mip levels visible at the current camera distance, keeping VRAM bounded regardless of how many content mods are installed. Invisible at adequate memory budgets."); StreamingMipmapsMemoryBudget = file.Bind<int>("TextureStreaming", "MemoryBudgetMB", 1024, "VRAM budget for streamed textures in MB. Unity default is 512. Raise to 1024-2048 on GPUs with >= 6GB VRAM for better LOD retention. Clamped to [128, 8192]."); ShowFpsOverlay = file.Bind<bool>("Diagnostics", "ShowFpsOverlay", false, "Draw a small FPS / frametime counter in the top-left corner."); } } }