From 40d057ac6e27b8d29bc9c27f164b880822023ade Mon Sep 17 00:00:00 2001 From: ckoch Date: Tue, 21 Jul 2026 16:18:05 -0400 Subject: [PATCH] Plugin: reload config live and always log HUD changes BepInEx does not pick up external edits to a plugin's .cfg, so tuning values while the game ran silently did nothing - the plugin kept the values loaded at startup. Now watches the config file's mtime and calls Config.Reload() when it changes, so edits apply within ~2s with no restart. Reload is wrapped in try/catch so a malformed .cfg warns instead of spamming exceptions. HUD adjustments now always log (not just under Verbose) with the resulting scale, so it is obvious whether a value took effect. Co-Authored-By: Claude Opus 4.8 --- games/BurglinGnomes/plugin/UltraWideFix.cs | 32 ++++++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/games/BurglinGnomes/plugin/UltraWideFix.cs b/games/BurglinGnomes/plugin/UltraWideFix.cs index 6f1100a..fc260e7 100644 --- a/games/BurglinGnomes/plugin/UltraWideFix.cs +++ b/games/BurglinGnomes/plugin/UltraWideFix.cs @@ -80,14 +80,38 @@ namespace BurglinGnomes.UltraWideFix private void Start() => Apply(); // Canvases are created lazily (menus, popups), so re-apply periodically. + // We also re-read the config file each tick: BepInEx does NOT pick up + // external edits on its own, so without this you'd have to restart the + // game after every tweak. private void Update() { _timer += Time.unscaledDeltaTime; if (_timer < 2f) return; _timer = 0f; + + try + { + var stamp = System.IO.File.GetLastWriteTimeUtc(Config.ConfigFilePath); + if (stamp != _configStamp) + { + _configStamp = stamp; + Config.Reload(); + Logger.LogInfo($"Config reloaded: HudScale={_hudScale.Value} " + + $"WorldLabelScale={_worldScale.Value} " + + $"Match={_match.Value} Enabled={_enabled.Value}"); + // values changed -> re-derive from baselines on this pass + } + } + catch (System.Exception e) + { + Logger.LogWarning($"Config reload failed (check the .cfg syntax): {e.Message}"); + } + Apply(); } + private System.DateTime _configStamp; + private void Apply() { if (!_enabled.Value) return; @@ -132,9 +156,11 @@ namespace BurglinGnomes.UltraWideFix if (cs.referenceResolution != targetRef) { cs.referenceResolution = targetRef; - if (_verbose.Value) - Logger.LogInfo($"HUD '{cs.name}' ref {baseRef} -> {targetRef} " + - $"match={_match.Value}"); + // expected scale now; Canvas.scaleFactor lags a frame + float exp = Mathf.Pow(Screen.width / targetRef.x, 1f - _match.Value) * + Mathf.Pow(Screen.height / targetRef.y, _match.Value); + Logger.LogInfo($"HUD '{cs.name}' ref {baseRef} -> {targetRef} " + + $"match={_match.Value} => scale={exp:F3}"); } } }