Skip to content

Commit

Permalink
Fix invalid operation when setting bool convar with string value
Browse files Browse the repository at this point in the history
  • Loading branch information
Mooshua committed Jan 25, 2024
1 parent 0c13633 commit cb90915
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion mod/Jailbreak.Teams/Ratio/RatioBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>("mp_ignore_round_win_conditions", true))
{
var success = action.Type switch
{
Expand Down
12 changes: 6 additions & 6 deletions public/Jailbreak.Public/Utils/TemporaryConvar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@

namespace Jailbreak.Public.Utils;

public class TemporaryConvar : IDisposable
public class TemporaryConvar<T> : 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);

Check warning on line 11 in public/Jailbreak.Public/Utils/TemporaryConvar.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference assignment.
if (_handle == null)
throw new InvalidOperationException($"ConVar {name} does not exist!");

_previousValue = _handle.StringValue;
_handle.SetValue(value);
_previousValue = _handle.GetPrimitiveValue<T>();
_handle.SetValue<T>(value);
}

public void Dispose()
{
_handle.StringValue = _previousValue;
_handle.SetValue<T>(_previousValue);
}
}

0 comments on commit cb90915

Please sign in to comment.