From e54e17d6b0ce4b824cfbf6c24a428b8051896e90 Mon Sep 17 00:00:00 2001 From: fed <58637860+fedddddd@users.noreply.github.com> Date: Fri, 27 Jan 2023 23:34:16 +0100 Subject: [PATCH] Add sv_disableCustomClasses --- data/cdata/scripts/mp/classes.gsc | 34 ++++++++++++++++++++++ data/cdata/ui_scripts/classes/__init__.lua | 13 +++++++++ src/client/component/weapon.cpp | 4 +++ 3 files changed, 51 insertions(+) create mode 100644 data/cdata/scripts/mp/classes.gsc create mode 100644 data/cdata/ui_scripts/classes/__init__.lua diff --git a/data/cdata/scripts/mp/classes.gsc b/data/cdata/scripts/mp/classes.gsc new file mode 100644 index 00000000..0286f8e7 --- /dev/null +++ b/data/cdata/scripts/mp/classes.gsc @@ -0,0 +1,34 @@ +main() +{ + replacefunc(maps\mp\gametypes\_menus::getclasschoice, ::getclasschoice); +} + +getclasschoice(choice) +{ + if (choice <= 100) + { + if (getdvar("sv_disableCustomClasses") == "1") + { + return "class0"; + } + + choice = "custom" + choice; + } + else if (choice <= 200) + { + choice -= 101; + choice = "class" + choice; + } + else if ( choice <= 206 ) + { + choice -= 200; + choice = "axis_recipe" + choice; + } + else + { + choice -= 206; + choice = "allies_recipe" + choice; + } + + return choice; +} diff --git a/data/cdata/ui_scripts/classes/__init__.lua b/data/cdata/ui_scripts/classes/__init__.lua new file mode 100644 index 00000000..b555a121 --- /dev/null +++ b/data/cdata/ui_scripts/classes/__init__.lua @@ -0,0 +1,13 @@ +if (Engine.InFrontend()) then + return +end + +local getclasscount = Cac.GetCustomClassCount +Cac.GetCustomClassCount = function(...) + local value = Engine.GetDvarBool("sv_disableCustomClasses") + if (value) then + return 0 + end + + return getclasscount(...) +end \ No newline at end of file diff --git a/src/client/component/weapon.cpp b/src/client/component/weapon.cpp index 7e1b278d..a31cd4cd 100644 --- a/src/client/component/weapon.cpp +++ b/src/client/component/weapon.cpp @@ -6,6 +6,7 @@ #include "fastfiles.hpp" #include "game/game.hpp" +#include "game/dvars.hpp" #include #include @@ -260,6 +261,9 @@ namespace weapon utils::hook::call(0x41C595_b, g_find_config_string_index_stub); utils::hook::call(0x36B4D4_b, load_ddl_asset_stub); + + dvars::register_bool("sv_disableCustomClasses", + false, game::DVAR_FLAG_REPLICATED, "Disable custom classes on server"); } #ifdef DEBUG