From 6ca944319b29d8b0133d08b3edbf3d8a75845201 Mon Sep 17 00:00:00 2001 From: quaK Date: Tue, 9 Jan 2024 01:27:29 +0200 Subject: [PATCH] small stuff --- src/client/component/command.cpp | 154 ++++++++++++++++++---- src/client/component/console/terminal.cpp | 3 +- src/client/component/dvar_cheats.cpp | 3 +- src/client/component/fastfiles.cpp | 16 ++- src/client/game/game.cpp | 35 +++++ src/client/game/game.hpp | 6 + 6 files changed, 186 insertions(+), 31 deletions(-) diff --git a/src/client/component/command.cpp b/src/client/component/command.cpp index 04676927..42385642 100644 --- a/src/client/component/command.cpp +++ b/src/client/component/command.cpp @@ -4,6 +4,7 @@ #include "game/game.hpp" #include "game/dvars.hpp" +#include "game/scripting/execution.hpp" #include "console/console.hpp" #include "game_console.hpp" @@ -194,34 +195,105 @@ namespace command return 0; } - void client_println(int client_num, const std::string& text) + void cmd_give(const int client_num, const std::vector& params) { - if (game::Com_GameMode_GetActiveGameMode() == game::GAME_MODE_SP) + if (params.size() < 2) { - game::CG_Utils_GameMessage(client_num, text.data(), 0); // why is nothing printed? + game::shared::client_println(client_num, "You did not specify a weapon name"); + return; } - else + + try + { + const auto& arg = params[1]; + const auto player = scripting::entity({ static_cast(client_num), 0 }); + + if (arg == "ammo") + { + const auto weapon = player.call("getcurrentweapon").as(); + player.call("givemaxammo", { weapon }); + } + else if (arg == "allammo") + { + const auto weapons = player.call("getweaponslistall").as(); + for (auto i = 0; i < weapons.size(); i++) + { + player.call("givemaxammo", { weapons[i] }); + } + } + else if (arg == "health") + { + if (params.size() > 2) + { + const auto amount = atoi(params[2].data()); + const auto health = player.get("health").as(); + player.set("health", { health + amount }); + } + else + { + const auto amount = atoi(game::Dvar_FindVar("scr_player_maxhealth")->current.string); + player.set("health", { amount }); + } + } + else if (arg == "all") + { + const auto type = game::XAssetType::ASSET_TYPE_WEAPON; + game::DB_EnumXAssets(type, [&player, type](const game::XAssetHeader header) + { + const auto asset = game::XAsset{ type, header }; + const auto asset_name = game::DB_GetXAssetName(&asset); + + player.call("giveweapon", { asset_name }); + }); + } + else + { + player.call("giveweapon", { arg }); + } + } + catch (...) { - game::SV_GameSendServerCommand(client_num, game::SV_CMD_RELIABLE, - utils::string::va("f \"%s\"", text.data())); } } - bool cheats_ok(int client_num) + void cmd_drop_weapon(int client_num) { - if (game::Com_GameMode_GetActiveGameMode() == game::GAME_MODE_SP) + try { - return true; + const auto player = scripting::entity({ static_cast(client_num), 0 }); + const auto weapon = player.call("getcurrentweapon"); + player.call("dropitem", { weapon }); + } + catch (...) + { + } + } + + void cmd_take(int client_num, const std::vector& params) + { + if (params.size() < 2) + { + game::shared::client_println(client_num, "You did not specify a weapon name"); + return; } - const auto sv_cheats = game::Dvar_FindVar("sv_cheats"); - if (!sv_cheats || !sv_cheats->current.enabled) - { - client_println(client_num, "GAME_CHEATSNOTENABLED"); - return false; - } + const auto& weapon = params[1]; - return true; + try + { + const auto player = scripting::entity({ static_cast(client_num), 0 }); + if (weapon == "all"s) + { + player.call("takeallweapons"); + } + else + { + player.call("takeweapon", { weapon }); + } + } + catch (...) + { + } } } @@ -416,13 +488,13 @@ namespace command add_sv("god", [](const int client_num, const params_sv&) { - if (!cheats_ok(client_num)) + if (!game::shared::cheats_ok(client_num, true)) { return; } game::g_entities[client_num].flags ^= 1; - client_println(client_num, + game::shared::client_println(client_num, game::g_entities[client_num].flags & 1 ? "GAME_GODMODE_ON" : "GAME_GODMODE_OFF"); @@ -430,13 +502,13 @@ namespace command add_sv("demigod", [](const int client_num, const params_sv&) { - if (!cheats_ok(client_num)) + if (!game::shared::cheats_ok(client_num, true)) { return; } game::g_entities[client_num].flags ^= 2; - client_println(client_num, + game::shared::client_println(client_num, game::g_entities[client_num].flags & 2 ? "GAME_DEMI_GODMODE_ON" : "GAME_DEMI_GODMODE_OFF"); @@ -444,13 +516,13 @@ namespace command add_sv("notarget", [](const int client_num, const params_sv&) { - if (!cheats_ok(client_num)) + if (!game::shared::cheats_ok(client_num, true)) { return; } game::g_entities[client_num].flags ^= 4; - client_println(client_num, + game::shared::client_println(client_num, game::g_entities[client_num].flags & 4 ? "GAME_NOTARGETON" : "GAME_NOTARGETOFF"); @@ -458,13 +530,13 @@ namespace command add_sv("noclip", [](const int client_num, const params_sv&) { - if (!cheats_ok(client_num)) + if (!game::shared::cheats_ok(client_num, true)) { return; } game::g_entities[client_num].client->flags ^= 1; - client_println(client_num, + game::shared::client_println(client_num, game::g_entities[client_num].client->flags & 1 ? "GAME_NOCLIPON" : "GAME_NOCLIPOFF"); @@ -472,17 +544,47 @@ namespace command add_sv("ufo", [](const int client_num, const params_sv&) { - if (!cheats_ok(client_num)) + if (!game::shared::cheats_ok(client_num, true)) { return; } game::g_entities[client_num].client->flags ^= 2; - client_println(client_num, + game::shared::client_println(client_num, game::g_entities[client_num].client->flags & 2 ? "GAME_UFOON" : "GAME_UFOOFF"); }); + + add_sv("give", [](const int client_num, const params_sv& params) + { + if (!game::shared::cheats_ok(client_num, true)) + { + return; + } + + cmd_give(client_num, params.get_all()); + }); + + add_sv("dropweapon", [](const int client_num, const params_sv& params) + { + if (!game::shared::cheats_ok(client_num, true)) + { + return; + } + + cmd_drop_weapon(client_num); + }); + + add_sv("take", [](const int client_num, const params_sv& params) + { + if (!game::shared::cheats_ok(client_num, true)) + { + return; + } + + cmd_take(client_num, params.get_all()); + }); } }; } diff --git a/src/client/component/console/terminal.cpp b/src/client/component/console/terminal.cpp index df64bc2f..ec0d1ed3 100644 --- a/src/client/component/console/terminal.cpp +++ b/src/client/component/console/terminal.cpp @@ -341,7 +341,8 @@ namespace terminal public: component() { - ShowWindow(GetConsoleWindow(), SW_HIDE); + if(!game::environment::is_dedi()) + ShowWindow(GetConsoleWindow(), SW_HIDE); } void post_unpack() override diff --git a/src/client/component/dvar_cheats.cpp b/src/client/component/dvar_cheats.cpp index 384d7667..0f5f8d8c 100644 --- a/src/client/component/dvar_cheats.cpp +++ b/src/client/component/dvar_cheats.cpp @@ -69,8 +69,7 @@ namespace dvar_cheats return false; } - const auto sv_cheats = game::Dvar_FindVar("sv_cheats"); - if ((dvar->flags & game::DvarFlags::DVAR_FLAG_CHEAT) && ((sv_cheats && !sv_cheats->current.enabled) && *game::isCheatOverride)) + if ((dvar->flags & game::DvarFlags::DVAR_FLAG_CHEAT) && (!game::shared::cheats_ok() && *game::isCheatOverride)) { //#ifdef DEBUG console::error("%s is cheat protected\n", dvars::dvar_get_name(dvar).data()); diff --git a/src/client/component/fastfiles.cpp b/src/client/component/fastfiles.cpp index a69c5bc6..59d97b7a 100644 --- a/src/client/component/fastfiles.cpp +++ b/src/client/component/fastfiles.cpp @@ -34,6 +34,7 @@ namespace fastfiles utils::hook::detour db_init_load_x_file_hook; utils::hook::detour db_load_x_zone_hook; utils::hook::detour db_find_xasset_header_hook; + utils::hook::detour db_add_xasset_hook; void db_try_load_x_file_internal_stub(const char* zone_name, const unsigned int zone_flags, const bool is_base_map, const bool was_paused, const int failure_mode) @@ -88,10 +89,20 @@ namespace fastfiles game::g_assetNames[static_cast(type)], name); } - if (type == game::ASSET_TYPE_SCRIPTFILE && result.scriptfile) + + return result; + } + + game::XAssetHeader db_add_xasset_stub(game::XAssetType type, game::XAssetHeader* header_ptr) + { + auto header = *header_ptr; + + if (type == game::ASSET_TYPE_SCRIPTFILE && header.scriptfile) { - dump_gsc_script(name, result); + dump_gsc_script(header.scriptfile->name ? header.scriptfile->name : "__unnamed__", header); } + + auto result = db_add_xasset_hook.invoke(type, header_ptr); return result; } } @@ -124,6 +135,7 @@ namespace fastfiles #endif db_find_xasset_header_hook.create(game::DB_FindXAssetHeader, db_find_xasset_header_stub); + db_add_xasset_hook.create(0xA76520_b, db_add_xasset_stub); g_dump_scripts = game::Dvar_RegisterBool("g_dumpScripts", false, game::DVAR_FLAG_NONE, "Dump GSC scripts"); diff --git a/src/client/game/game.cpp b/src/client/game/game.cpp index 1bd22453..8d0fba30 100644 --- a/src/client/game/game.cpp +++ b/src/client/game/game.cpp @@ -2,6 +2,7 @@ #include "game.hpp" #include +#include namespace game { @@ -22,6 +23,40 @@ namespace game } } + namespace shared + { + void client_println(int client_num, const std::string& text) + { + if (game::Com_GameMode_GetActiveGameMode() == game::GAME_MODE_SP) + { + game::CG_Utils_GameMessage(client_num, text.data(), 0); // why is nothing printed? + } + else + { + game::SV_GameSendServerCommand(client_num, game::SV_CMD_RELIABLE, + utils::string::va("f \"%s\"", text.data())); + } + } + + bool cheats_ok(int client_num, bool print) + { + if (game::Com_GameMode_GetActiveGameMode() == game::GAME_MODE_SP) + { + return true; + } + + const auto sv_cheats = game::Dvar_FindVar("sv_cheats"); + if (!sv_cheats || !sv_cheats->current.enabled) + { + if(print) + client_println(client_num, "GAME_CHEATSNOTENABLED"); + return false; + } + + return true; + } + } + int Cmd_Argc() { return cmd_args->argc[cmd_args->nesting]; diff --git a/src/client/game/game.hpp b/src/client/game/game.hpp index 0aa4840a..7a01efbd 100644 --- a/src/client/game/game.hpp +++ b/src/client/game/game.hpp @@ -40,6 +40,12 @@ namespace game bool is_dedi(); } + namespace shared + { + void client_println(int client_num, const std::string& text); + bool cheats_ok(int client_num = 0, bool print = false); + } + int Cmd_Argc(); const char* Cmd_Argv(int index);