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 <noreply@anthropic.com>
This commit is contained in:
@@ -80,14 +80,38 @@ namespace BurglinGnomes.UltraWideFix
|
|||||||
private void Start() => Apply();
|
private void Start() => Apply();
|
||||||
|
|
||||||
// Canvases are created lazily (menus, popups), so re-apply periodically.
|
// 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()
|
private void Update()
|
||||||
{
|
{
|
||||||
_timer += Time.unscaledDeltaTime;
|
_timer += Time.unscaledDeltaTime;
|
||||||
if (_timer < 2f) return;
|
if (_timer < 2f) return;
|
||||||
_timer = 0f;
|
_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();
|
Apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private System.DateTime _configStamp;
|
||||||
|
|
||||||
private void Apply()
|
private void Apply()
|
||||||
{
|
{
|
||||||
if (!_enabled.Value) return;
|
if (!_enabled.Value) return;
|
||||||
@@ -132,9 +156,11 @@ namespace BurglinGnomes.UltraWideFix
|
|||||||
if (cs.referenceResolution != targetRef)
|
if (cs.referenceResolution != targetRef)
|
||||||
{
|
{
|
||||||
cs.referenceResolution = targetRef;
|
cs.referenceResolution = targetRef;
|
||||||
if (_verbose.Value)
|
// expected scale now; Canvas.scaleFactor lags a frame
|
||||||
Logger.LogInfo($"HUD '{cs.name}' ref {baseRef} -> {targetRef} " +
|
float exp = Mathf.Pow(Screen.width / targetRef.x, 1f - _match.Value) *
|
||||||
$"match={_match.Value}");
|
Mathf.Pow(Screen.height / targetRef.y, _match.Value);
|
||||||
|
Logger.LogInfo($"HUD '{cs.name}' ref {baseRef} -> {targetRef} " +
|
||||||
|
$"match={_match.Value} => scale={exp:F3}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user