Skip to content

Commit

Permalink
fix: game crash caused by setting convars
Browse files Browse the repository at this point in the history
  • Loading branch information
lengran committed Apr 11, 2024
1 parent 1120655 commit 22d6ca6
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 27 deletions.
61 changes: 38 additions & 23 deletions OpenPrefirePrac.cs
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,6 @@ private void SaveConvars()
{
string[] boolConvarNames = [
"tv_enable",
"sv_cheats",
"bot_allow_grenades",
"bot_allow_snipers",
"bot_allow_shotguns",
Expand Down Expand Up @@ -925,6 +924,10 @@ private void SaveConvars()

try
{
// sv_cheats
var sv_cheats = ConVar.Find("sv_cheats");
_serverStatus.sv_cheats = sv_cheats!.GetPrimitiveValue<bool>();

// Bool convars
foreach (var convarName in boolConvarNames)
{
Expand Down Expand Up @@ -1000,15 +1003,16 @@ private void RestoreConvars()
// Bool convars
foreach (var convar in _serverStatus.BoolConvars)
{
var tmpConvar = ConVar.Find(convar.Key);
tmpConvar!.SetValue(convar.Value);
// var tmpConvar = ConVar.Find(convar.Key);
// tmpConvar!.SetValue(convar.Value);
Server.ExecuteCommand(convar.Key + " " + convar.Value.ToString());
}
_serverStatus.BoolConvars.Clear();

// Int convars
foreach (var convar in _serverStatus.IntConvars)
{
var tmpConvar = ConVar.Find(convar.Key);
// var tmpConvar = ConVar.Find(convar.Key);
// Somehow the following 2 methods don't work, just make up a command to implement this.
Server.ExecuteCommand(convar.Key + " " + convar.Value.ToString());
// tmpConvar!.GetPrimitiveValue<int>() = convar.Value;
Expand All @@ -1019,7 +1023,7 @@ private void RestoreConvars()
// Float convars
foreach (var convar in _serverStatus.FloatConvars)
{
var tmpConvar = ConVar.Find(convar.Key);
// var tmpConvar = ConVar.Find(convar.Key);
// Somehow the following 2 methods don't work, just make up a command to implement this.
Server.ExecuteCommand(convar.Key + " " + convar.Value.ToString());
// tmpConvar!.GetPrimitiveValue<float>() = convar.Value;
Expand All @@ -1030,11 +1034,17 @@ private void RestoreConvars()
// String convars
foreach (var convar in _serverStatus.StringConvars)
{
var tmpConvar = ConVar.Find(convar.Key);
tmpConvar!.StringValue = convar.Value;
// var tmpConvar = ConVar.Find(convar.Key);
// tmpConvar!.StringValue = convar.Value;
Server.ExecuteCommand(convar.Key + " " + convar.Value.ToString());
}
_serverStatus.StringConvars.Clear();

// Restore sv_cheats
// var sv_cheats = ConVar.Find("sv_cheats");
// sv_cheats!.SetValue(_serverStatus.sv_cheats);
Server.ExecuteCommand("sv_cheats " + _serverStatus.sv_cheats.ToString());

// Restore warmup status
if (!_serverStatus.WarmupStatus)
{
Expand All @@ -1046,35 +1056,40 @@ private void SetupConvars()
{
Server.ExecuteCommand("tv_enable 0");
Server.ExecuteCommand("sv_cheats 1");
Server.ExecuteCommand("mp_maxmoney 60000");
Server.ExecuteCommand("mp_startmoney 60000");
Server.ExecuteCommand("mp_buytime 9999");
Server.ExecuteCommand("mp_buy_anywhere 1");
Server.ExecuteCommand("bot_allow_grenades 0");
Server.ExecuteCommand("bot_allow_snipers 0");
Server.ExecuteCommand("bot_allow_shotguns 0");
// Server.ExecuteCommand("bot_autodifficulty_threshold_high 5");
// Server.ExecuteCommand("bot_autodifficulty_threshold_low 5");
Server.ExecuteCommand("bot_difficulty 5");
Server.ExecuteCommand("custom_bot_difficulty 5");
// Server.ExecuteCommand("sv_auto_adjust_bot_difficulty 0");
Server.ExecuteCommand("sv_infinite_ammo 1");
Server.ExecuteCommand("mp_limitteams 0");
Server.ExecuteCommand("mp_autoteambalance 0");
Server.ExecuteCommand("sv_alltalk 1");
Server.ExecuteCommand("sv_full_alltalk 1");

Server.ExecuteCommand("mp_buy_anywhere 1");
Server.ExecuteCommand("mp_warmup_pausetimer 1");
Server.ExecuteCommand("bot_quota_mode normal");
Server.ExecuteCommand("weapon_auto_cleanup_time 1");
Server.ExecuteCommand("mp_free_armor 2");
Server.ExecuteCommand("mp_limitteams 0");
Server.ExecuteCommand("sv_infinite_ammo 1");
Server.ExecuteCommand("mp_maxmoney 60000");
Server.ExecuteCommand("mp_startmoney 60000");
Server.ExecuteCommand("bot_difficulty 5");
Server.ExecuteCommand("custom_bot_difficulty 5");

Server.ExecuteCommand("mp_respawn_immunitytime -1");
Server.ExecuteCommand("mp_buytime 9999");

Server.ExecuteCommand("bot_quota_mode normal");

Server.ExecuteCommand("mp_warmup_start");

// Server.ExecuteCommand("bot_autodifficulty_threshold_high 5");
// Server.ExecuteCommand("bot_autodifficulty_threshold_low 5");
// Server.ExecuteCommand("sv_auto_adjust_bot_difficulty 0");
// Server.ExecuteCommand("weapon_auto_cleanup_time 1");
// Server.ExecuteCommand("mp_roundtime 60");
// Server.ExecuteCommand("mp_roundtime_defuse 60");
// Server.ExecuteCommand("mp_freezetime 0");
// Server.ExecuteCommand("mp_team_intro_time 0");
// Server.ExecuteCommand("mp_ignore_round_win_conditions 1");
// Server.ExecuteCommand("mp_respawn_on_death_ct 1");
// Server.ExecuteCommand("mp_respawn_on_death_t 1");
Server.ExecuteCommand("sv_alltalk 1");
Server.ExecuteCommand("sv_full_alltalk 1");
Server.ExecuteCommand("mp_warmup_start");
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Finished practices:
- Attack A site from A short (mid)
- de_anubis
- Attack B site from B main
- Attack B site from mid (b connector)
- Attack B site from mid (B connector)
- de_dust2
- Attack A site from A long
- Attack A site from A short
Expand Down
2 changes: 2 additions & 0 deletions ServerStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public class ServerStatus
public readonly Dictionary<string, string> StringConvars = new();

public bool WarmupStatus = false;

public bool sv_cheats = false;
}
2 changes: 1 addition & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"map.de_overpass.a_long": "Attack A site from A long",
"map.de_overpass.a_short": "Attack A site from A short (mid)",
"map.de_anubis.b_main": "Attack B site from B main",
"map.de_anubis.mid_to_b": "Attack B site from mid (b connector)",
"map.de_anubis.mid_to_b": "Attack B site from mid (B connector)",
"map.de_dust2.a_long": "Attack A site from A long",
"map.de_dust2.a_short": "Attack A site from A short"
}
4 changes: 2 additions & 2 deletions maps/de_anubis/b_main.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mid_to_b
8 0.7
8 0.75
-361.479248 -1548.610840 2.031250 1.825867 147.881363 0.000000
-1048.037964 -494.476929 1.8980260000000015 -4.575871 -87.976990 0.000000 False
-1016.033325 27.412306 0.5619429999999994 -2.419896 -89.451118 0.000000 False
Expand Down Expand Up @@ -28,12 +28,12 @@ mid_to_b
-596.031250 419.968781 -71.742668 -4.971682 -169.217773 0.000000 False
-1076.660889 1486.973145 -31.96875 -2.155705 -105.964729 0.000000 False
-1134.953247 1798.507568 47.03125 1.452296 -97.216751 0.000000 False
-1277.964844 1646.199951 47.03125 2.046000 -87.075897 0.000000 False
-581.441895 947.277161 38.117844000000005 2.134299 -140.072800 0.000000 False
-1332.967407 991.252136 -0.932738999999998 1.034275 -66.513023 0.000000 False
-1013.968201 1146.201782 34.03125 -0.373934 -81.486084 0.000000 False
-704.968750 496.902740 37.926734999999994 0.660274 107.542480 0.000000 False
-789.931152 52.031494 -94.958229 -5.807882 91.125908 0.000000 False
-704.968750 496.933624 37.223541 -0.285686 110.548195 0.000000 False
-885.053162 -1254.885132 44.079605
-938.764648 -1232.651123 74.42871099999999
-1087.173340 -1018.218018 73.03125
Expand Down

0 comments on commit 22d6ca6

Please sign in to comment.