From cb90915b44edb2ebe0243a058b724d606d387bcb Mon Sep 17 00:00:00 2001 From: Mooshua <43320783+mooshua@users.noreply.github.com> Date: Wed, 24 Jan 2024 17:27:21 -0800 Subject: [PATCH] Fix invalid operation when setting bool convar with string value --- mod/Jailbreak.Teams/Ratio/RatioBehavior.cs | 2 +- public/Jailbreak.Public/Utils/TemporaryConvar.cs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/mod/Jailbreak.Teams/Ratio/RatioBehavior.cs b/mod/Jailbreak.Teams/Ratio/RatioBehavior.cs index 6d132b7d..1d399f79 100644 --- a/mod/Jailbreak.Teams/Ratio/RatioBehavior.cs +++ b/mod/Jailbreak.Teams/Ratio/RatioBehavior.cs @@ -97,7 +97,7 @@ public HookResult OnRoundStart(EventRoundStart ev, GameEventInfo info) var action = Evaluate(counterTerrorists, terrorists); // Prevent the round from ending while we make ratio adjustments - using (var _ = new TemporaryConvar("mp_ignore_round_win_conditions", "true")) + using (var _ = new TemporaryConvar("mp_ignore_round_win_conditions", true)) { var success = action.Type switch { diff --git a/public/Jailbreak.Public/Utils/TemporaryConvar.cs b/public/Jailbreak.Public/Utils/TemporaryConvar.cs index bed6f467..5ddb543d 100644 --- a/public/Jailbreak.Public/Utils/TemporaryConvar.cs +++ b/public/Jailbreak.Public/Utils/TemporaryConvar.cs @@ -2,22 +2,22 @@ namespace Jailbreak.Public.Utils; -public class TemporaryConvar : IDisposable +public class TemporaryConvar : IDisposable { - private string _previousValue; + private T _previousValue; private ConVar _handle; - public TemporaryConvar(string name, string value) + public TemporaryConvar(string name, T value) { _handle = ConVar.Find(name); if (_handle == null) throw new InvalidOperationException($"ConVar {name} does not exist!"); - _previousValue = _handle.StringValue; - _handle.SetValue(value); + _previousValue = _handle.GetPrimitiveValue(); + _handle.SetValue(value); } public void Dispose() { - _handle.StringValue = _previousValue; + _handle.SetValue(_previousValue); } }