Strange behavior when setting the `mp_backup_round_file` convar
Hey, we experience strange behavior when setting the mp_backup_round_file convar.
We tried to set it like:
string prefix = $"PugSharp_Match_{_Match.MatchInfo.Config.MatchId}";
_Logger.LogInformation("Create round backup files: {prefix}", prefix);
UpdateConvar("mp_backup_round_file", prefix);
After the update, the cvar content seems to not be the same, even if the prefix content stays exactly the same.
799,1: mp_backup_round_file = `��
1125,21: mp_backup_round_file = `��
1127,1: mp_backup_round_file = `��
1129,1: mp_backup_round_file = `��
1131,1: mp_backup_round_file = `��
1133,1: mp_backup_round_file = `��
2049,1: mp_backup_round_file = �X�M�~
2864,1: mp_backup_round_file = ����-V
7209,1: mp_backup_round_file = �X9��
The files are later named something like (not sure which filename belongs to which output above) :
'`'$'\372\256\b\365\177''_round00.txt'
'`'$'\372\256\b\365\177''_round01.txt'
'`'$'\372\256\b\365\177''_round02.txt'
'`'$'\372\256\b\365\177''_round03.txt'
'`'$'\372\360\t\r\177''_round00.txt'
'`'$'\372\360\t\r\177''_round01.txt'
'`'$'\372\360\t\r\177''_round02.txt'
'xJ'$'\212\232\364\177''_round00.txt'
'xJ'$'\212\232\364\177''_round01.txt'
'xJ'$'\212\232\364\177''_round02.txt'
''$'\320''Z'$'\325\n''W'$'\177''_round00.txt'
''$'\320''Z'$'\325\n''W'$'\177''_round01.txt'
''$'\320''Z'$'\325\n''W'$'\177''_round02.txt'
''$'\320''Z'$'\325\n''W'$'\177''_round03.txt'
''$'\320''Z'$'\325\n''W'$'\177''_round04.txt'
''$'\320\362\343\310''-V_round00.txt'
''$'\320\362\343\310''-V_round01.txt'
''$'\330''X9'$'\223\256\177''_round00.txt'
''$'\330''X9'$'\223\256\177''_round01.txt'
''$'\330''X9'$'\223\256\177''_round02.txt'
''$'\330''X9'$'\223\256\177''_round03.txt'
''$'\330''X9'$'\223\256\177''_round04.txt'
''$'\330''X9'$'\223\256\177''_round05.txt'
''$'\330''X'$'\373''M'$'\376''~_round00.txt'
''$'\330''X'$'\373''M'$'\376''~_round01.txt'
'طs'$'\025\006\177''_round00.txt'
'p'$'\226''Z'$'\222\275''U_round00.txt'
'p'$'\226''Z'$'\222\275''U_round01.txt'
'p'$'\226''Z'$'\222\275''U_round02.txt'
'p'$'\226''Z'$'\222\275''U_round03.txt'
'p'$'\226''Z'$'\222\275''U_round04.txt'
'p'$'\226''Z'$'\222\275''U_round05.txt'
We can use Server.ExecuteCommand($"mp_backup_round_file {prefix}"); as a workaround which sets mp_backup_round_file = PugSharp_Match_59 and creates PugSharp_Match_59_round01.txt just fine.
What is UpdateConvar?
UpdateConvar wraps setting a convar value.
In case of the string values following calls are made:
var convar = ConVar.Find(name);
convar.StringValue = stringValue;
To this issue I have some additional information.
I tested with the following convars to make sure of my theory:
- mp_t_default_secondary
- mp_ct_default_secondary
- mp_t_default_primary
- mp_ct_default_primary
You have to know that about these convars if you set it (with console) to an invalid value, the server crashes (atleast currently). This is an important thing here.
If you try to set these at midgame with ConVar.Find("mp_ct_default_primary"), then validate if null and then using StringValue. It is going to set it perfectly to a new value.
...BUT, if you set these with the exact same way on plugin start or at map change it is going to crash. This means that whenever ConVar string value is being set at these events, the problem happens. Otherwise, when using mid game it sets the value well.
I'm not sure, it it's helpful but I've encountered this problem and I fixed it with Server.ExecuteCommand("mp_t_default_secondary \"\"");, which means the convar can be set on mapchange and plugin start, but not from the ConVar methods of CSS.
I can confirm that there's an issue with ConVar.StringValue. The setter seems to sometimes not take the string you want to set but rather... something from somewhere in memory. It isn't fully deterministic though and for me it worked more reliably when strings where < 8 characters in length.
This only works as expected rarely:
public ConVar convar = ConVar.Find("mp_ct_default_primary")!;
[ConsoleCommand("css_write")]
public void OnW(CCSPlayerController? player, CommandInfo command)
{
convar.StringValue = "weapon_test";
}
[ConsoleCommand("css_read")]
public void OnR(CCSPlayerController? player, CommandInfo command)
{
var str = convar.StringValue;
command.ReplyToCommand($"Value: {str}");
}
I once had it set the ConVar to "System.Console". Often, it sets it to just "S".
CS2 version: 1.40.2.9/14029 10072 CSS version: v263 Metamod version: 2.0.0-dev+1313
Had same issue, changing any string convar ends with a broken encoding.
Example when doing backup round file override:
The only workaround for now, is to use Server.ExecuteCommand to set string cvars.