diff --git a/src/client/component/arxan.cpp b/src/client/component/arxan.cpp index e6b80737..34ef481e 100644 --- a/src/client/component/arxan.cpp +++ b/src/client/component/arxan.cpp @@ -1,9 +1,10 @@ #include #include "loader/component_loader.hpp" -#include "scheduler.hpp" -#include "game/game.hpp" #include "arxan.hpp" +#include "scheduler.hpp" + +#include "game/game.hpp" #include diff --git a/src/client/component/auth.cpp b/src/client/component/auth.cpp index 3ba4a4cd..ba38b3bd 100644 --- a/src/client/component/auth.cpp +++ b/src/client/component/auth.cpp @@ -2,18 +2,19 @@ #include "loader/component_loader.hpp" #include "auth.hpp" -#include "component/command.hpp" +#include "command.hpp" +#include "console.hpp" #include "network.hpp" +#include "game/game.hpp" +#include "steam/steam.hpp" + #include #include #include #include #include -#include "game/game.hpp" -#include "steam/steam.hpp" - namespace auth { namespace @@ -249,9 +250,9 @@ namespace auth utils::hook::set(0x12D93C_b, 0xC3); } - command::add("guid", []() + command::add("guid", [] { - printf("Your guid: %llX\n", steam::SteamUser()->GetSteamID().bits); + console::info("Your guid: %llX\n", steam::SteamUser()->GetSteamID().bits); }); } }; diff --git a/src/client/component/binding.cpp b/src/client/component/binding.cpp index 5ef5bf66..821ec3f7 100644 --- a/src/client/component/binding.cpp +++ b/src/client/component/binding.cpp @@ -1,5 +1,6 @@ #include #include "loader/component_loader.hpp" + #include "game/game.hpp" #include diff --git a/src/client/component/bots.cpp b/src/client/component/bots.cpp index 4c82cd4e..1dc3bfc1 100644 --- a/src/client/component/bots.cpp +++ b/src/client/component/bots.cpp @@ -29,10 +29,10 @@ namespace bots void bot_team_join(const int entity_num) { const game::scr_entref_t entref{static_cast(entity_num), 0}; - scheduler::once([entref]() + scheduler::once([entref] { scripting::notify(entref, "luinotifyserver", {"team_select", 2}); - scheduler::once([entref]() + scheduler::once([entref] { auto* _class = utils::string::va("class%d", utils::cryptography::random::get_integer() % 5); scripting::notify(entref, "luinotifyserver", {"class_select", _class}); @@ -65,7 +65,7 @@ namespace bots } else { - scheduler::once([]() + scheduler::once([] { add_bot(); }, scheduler::pipeline::server, 100ms); diff --git a/src/client/component/branding.cpp b/src/client/component/branding.cpp index cbbcb0eb..f304b07f 100644 --- a/src/client/component/branding.cpp +++ b/src/client/component/branding.cpp @@ -1,13 +1,13 @@ #include #include "loader/component_loader.hpp" +#include "command.hpp" +#include "dvars.hpp" #include "localized_strings.hpp" #include "scheduler.hpp" -#include "command.hpp" #include "version.hpp" #include "game/game.hpp" -#include "dvars.hpp" #include #include diff --git a/src/client/component/bullet.cpp b/src/client/component/bullet.cpp index 72f6f4ff..58431474 100644 --- a/src/client/component/bullet.cpp +++ b/src/client/component/bullet.cpp @@ -34,9 +34,8 @@ namespace bullet return; } - bg_surface_penetration = dvars::register_float("bg_surfacePenetration", 0.0f, - 0.0f, std::numeric_limits::max(), 0, - "Set to a value greater than 0 to override the surface penetration depth"); + bg_surface_penetration = dvars::register_float("bg_surfacePenetration", 0.0f, 0.0f, std::numeric_limits::max(), 0, + "Set to a value greater than 0 to override the bullet surface penetration depth"); bg_get_surface_penetration_depth_hook.create(0x2E1110_b, &bg_get_surface_penetration_depth_stub); } diff --git a/src/client/component/command.cpp b/src/client/component/command.cpp index 5b7c6d84..7a8588d5 100644 --- a/src/client/component/command.cpp +++ b/src/client/component/command.cpp @@ -1,18 +1,18 @@ #include #include "loader/component_loader.hpp" -#include "game/game.hpp" -#include "game/dvars.hpp" -#include "game/scripting/execution.hpp" - #include "command.hpp" #include "console.hpp" +#include "dvars.hpp" #include "game_console.hpp" #include "fastfiles.hpp" #include "filesystem.hpp" #include "scheduler.hpp" #include "logfile.hpp" -#include "dvars.hpp" + +#include "game/game.hpp" +#include "game/dvars.hpp" +#include "game/scripting/execution.hpp" #include #include diff --git a/src/client/component/console.cpp b/src/client/component/console.cpp index 7daaa3f7..f6c769b8 100644 --- a/src/client/component/console.cpp +++ b/src/client/component/console.cpp @@ -1,10 +1,10 @@ #include -#include "console.hpp" #include "loader/component_loader.hpp" #include "game/game.hpp" #include "command.hpp" +#include "console.hpp" #include "rcon.hpp" #include "version.hpp" @@ -62,7 +62,7 @@ namespace console { static thread_local char buffer[0x1000]; - const auto count = _vsnprintf_s(buffer, sizeof(buffer), sizeof(buffer), message, *ap); + const auto count = vsnprintf_s(buffer, _TRUNCATE, message, *ap); if (count < 0) { return {}; diff --git a/src/client/component/dedicated.cpp b/src/client/component/dedicated.cpp index deb63fb5..dae3124c 100644 --- a/src/client/component/dedicated.cpp +++ b/src/client/component/dedicated.cpp @@ -138,7 +138,7 @@ namespace dedicated va_end(ap); - scheduler::once([]() + scheduler::once([] { command::execute("map_rotate"); }, scheduler::main, 3s); @@ -313,7 +313,7 @@ namespace dedicated { if (game::Live_SyncOnlineDataFlags(0) == 32 && game::Sys_IsDatabaseReady2()) { - scheduler::once([]() + scheduler::once([] { command::execute("xstartprivateparty", true); command::execute("disconnect", true); // 32 -> 0 @@ -324,7 +324,7 @@ namespace dedicated return scheduler::cond_continue; }, scheduler::pipeline::main, 1s); - scheduler::on_game_initialized([]() + scheduler::on_game_initialized([] { initialize(); diff --git a/src/client/component/dedicated_info.cpp b/src/client/component/dedicated_info.cpp index fa5c9a34..8164345b 100644 --- a/src/client/component/dedicated_info.cpp +++ b/src/client/component/dedicated_info.cpp @@ -1,8 +1,11 @@ #include #include "loader/component_loader.hpp" -#include "game/game.hpp" + #include "scheduler.hpp" -#include + +#include "game/game.hpp" + +#include namespace dedicated_info { @@ -16,7 +19,7 @@ namespace dedicated_info return; } - scheduler::loop([]() + scheduler::loop([] { auto* sv_running = game::Dvar_FindVar("sv_running"); if (!sv_running || !sv_running->current.enabled || (*game::mp::svs_clients) == nullptr) @@ -25,9 +28,9 @@ namespace dedicated_info return; } - auto* const sv_hostname = game::Dvar_FindVar("sv_hostname"); - auto* const sv_maxclients = game::Dvar_FindVar("sv_maxclients"); - auto* const mapname = game::Dvar_FindVar("mapname"); + const auto sv_hostname = game::Dvar_FindVar("sv_hostname"); + const auto sv_maxclients = game::Dvar_FindVar("sv_maxclients"); + const auto mapname = game::Dvar_FindVar("mapname"); auto bot_count = 0; auto client_count = 0; diff --git a/src/client/component/demonware.cpp b/src/client/component/demonware.cpp index c09f4b03..c1451299 100644 --- a/src/client/component/demonware.cpp +++ b/src/client/component/demonware.cpp @@ -1,16 +1,16 @@ #include #include "loader/component_loader.hpp" -#include -#include - #include "game/game.hpp" #include "game/demonware/servers/lobby_server.hpp" #include "game/demonware/servers/auth3_server.hpp" #include "game/demonware/servers/stun_server.hpp" #include "game/demonware/servers/umbrella_server.hpp" #include "game/demonware/server_registry.hpp" -#include +#include "game/dvars.hpp" + +#include +#include #define TCP_BLOCKING true #define UDP_BLOCKING false diff --git a/src/client/component/discord.cpp b/src/client/component/discord.cpp index 0274e0ce..b8587789 100644 --- a/src/client/component/discord.cpp +++ b/src/client/component/discord.cpp @@ -1,15 +1,15 @@ #include #include "loader/component_loader.hpp" -#include "scheduler.hpp" -#include "game/game.hpp" #include "console.hpp" #include "command.hpp" +#include "discord.hpp" +#include "materials.hpp" #include "network.hpp" #include "party.hpp" -#include "materials.hpp" -#include "discord.hpp" +#include "scheduler.hpp" +#include "game/game.hpp" #include "game/ui_scripting/execution.hpp" #include @@ -58,16 +58,12 @@ namespace discord static char details[0x80] = {0}; const auto map = game::Dvar_FindVar("mapname")->current.string; const auto key = utils::string::va("PRESENCE_%s%s", SELECT_VALUE("SP_", ""), map); - const char* mapname = nullptr; + const char* mapname = map; if (game::DB_XAssetExists(game::ASSET_TYPE_LOCALIZE, key) && !game::DB_IsXAssetDefault(game::ASSET_TYPE_LOCALIZE, key)) { mapname = game::UI_SafeTranslateString(key); } - else - { - mapname = map; - } if (game::environment::is_mp()) { @@ -80,7 +76,6 @@ namespace discord clean_hostname, sizeof(clean_hostname)); auto max_clients = party::server_client_count(); - // When true, we are in Private Match if (game::SV_Loaded()) { strcpy_s(clean_hostname, "Private Match"); @@ -227,12 +222,17 @@ namespace discord handlers.joinGame = join_game; handlers.joinRequest = join_request; } + else + { + handlers.joinGame = nullptr; + handlers.joinRequest = nullptr; + } Discord_Initialize("947125042930667530", &handlers, 1, nullptr); scheduler::once(download_default_avatar, scheduler::pipeline::async); - scheduler::once([]() + scheduler::once([] { scheduler::once(update_discord, scheduler::pipeline::async); scheduler::loop(update_discord, scheduler::pipeline::async, 5s); @@ -270,15 +270,12 @@ namespace discord static void join_game(const char* join_secret) { - console::info("Discord: Join game called with join secret: %s\n", join_secret); - - std::string secret = join_secret; - scheduler::once([=]() + scheduler::once([=] { game::netadr_s target{}; - if (game::NET_StringToAdr(secret.data(), &target)) + if (game::NET_StringToAdr(join_secret, &target)) { - console::info("Discord: Connecting to server: %s\n", secret.data()); + console::info("Discord: Connecting to server: %s\n", join_secret); party::connect(target); } }, scheduler::pipeline::main); @@ -286,7 +283,7 @@ namespace discord static void join_request(const DiscordUser* request) { - console::info("Discord: join_request from %s (%s)\n", request->username, request->userId); + console::info("Discord: Join request from %s (%s)\n", request->username, request->userId); if (game::Com_InFrontend() || !ui_scripting::lui_running()) { @@ -299,7 +296,7 @@ namespace discord std::string discriminator = request->discriminator; std::string username = request->username; - scheduler::once([=]() + scheduler::once([=] { const ui_scripting::table request_table{}; request_table.set("avatar", avatar); diff --git a/src/client/component/download.cpp b/src/client/component/download.cpp index 4b65d0ed..6914555c 100644 --- a/src/client/component/download.cpp +++ b/src/client/component/download.cpp @@ -71,7 +71,7 @@ namespace download static_cast(total)); } - scheduler::once([=]() + scheduler::once([=] { ui_scripting::notify("mod_download_progress", { @@ -91,7 +91,7 @@ namespace download void menu_error(const std::string& error) { - scheduler::once([=]() + scheduler::once([=] { party::menu_error(error); }, scheduler::pipeline::lui); @@ -102,7 +102,7 @@ namespace download { if (download_active()) { - scheduler::schedule([=]() + scheduler::schedule([=] { if (!download_active()) { @@ -128,14 +128,12 @@ namespace download return; } - scheduler::once([=]() + scheduler::once([] { - const ui_scripting::table mod_data_table{}; - ui_scripting::notify("mod_download_start", {}); }, scheduler::pipeline::lui); - scheduler::once([=]() + scheduler::once([=] { { const auto _0 = gsl::finally(&mark_unactive); @@ -148,7 +146,7 @@ namespace download for (const auto& file : files) { - scheduler::once([=]() + scheduler::once([=] { const ui_scripting::table data_table{}; data_table.set("name", file.name.data()); @@ -192,12 +190,12 @@ namespace download } } - scheduler::once([]() + scheduler::once([] { ui_scripting::notify("mod_download_done", {}); }, scheduler::pipeline::lui); - scheduler::once([=]() + scheduler::once([target] { party::connect(target); }, scheduler::pipeline::main); @@ -216,11 +214,10 @@ namespace download globals_.abort = true; }); - scheduler::once([]() + scheduler::once([] { ui_scripting::notify("mod_download_done", {}); party::menu_error("Download for server mod has been cancelled."); }, scheduler::pipeline::lui); } } - diff --git a/src/client/component/download.hpp b/src/client/component/download.hpp index 131a0f06..ddd95790 100644 --- a/src/client/component/download.hpp +++ b/src/client/component/download.hpp @@ -1,6 +1,7 @@ #pragma once #include "game/game.hpp" + #include namespace download diff --git a/src/client/component/dvar_cheats.cpp b/src/client/component/dvar_cheats.cpp index 66c49e6c..edb209a9 100644 --- a/src/client/component/dvar_cheats.cpp +++ b/src/client/component/dvar_cheats.cpp @@ -135,7 +135,7 @@ namespace dvar_cheats utils::hook::nop(0x1861D4_b, 8); // let our stub handle zero-source sets utils::hook::jump(0x1861DF_b, get_dvar_flag_checks_stub(), true); // check extra dvar flags when setting values - scheduler::once([]() + scheduler::once([] { dvars::register_bool("sv_cheats", false, game::DvarFlags::DVAR_FLAG_REPLICATED, "Allow cheat commands and dvars on this server"); diff --git a/src/client/component/dvars.cpp b/src/client/component/dvars.cpp index a1e4a4ee..3fec1fd4 100644 --- a/src/client/component/dvars.cpp +++ b/src/client/component/dvars.cpp @@ -1,5 +1,6 @@ #include #include "loader/component_loader.hpp" + #include "dvars.hpp" #include "game/game.hpp" diff --git a/src/client/component/exception.cpp b/src/client/component/exception.cpp index 0cba305a..86190fa1 100644 --- a/src/client/component/exception.cpp +++ b/src/client/component/exception.cpp @@ -1,8 +1,11 @@ #include #include "loader/component_loader.hpp" -#include "system_check.hpp" -#include "scheduler.hpp" +#include "scheduler.hpp" +#include "system_check.hpp" +#include "version.hpp" + +#include "game/dvars.hpp" #include "game/game.hpp" #include @@ -13,10 +16,6 @@ #include -#include - -#include "game/dvars.hpp" - namespace exception { namespace @@ -246,7 +245,7 @@ namespace exception SetUnhandledExceptionFilter(exception_filter); utils::hook::jump(SetUnhandledExceptionFilter, set_unhandled_exception_filter_stub, true); - scheduler::on_game_initialized([]() + scheduler::on_game_initialized([] { is_initialized() = true; }); @@ -255,7 +254,7 @@ namespace exception void post_unpack() override { dvars::cg_legacyCrashHandling = dvars::register_bool("cg_legacyCrashHandling", - false, game::DVAR_FLAG_SAVED, "Disable new crash handling"); + false, game::DVAR_FLAG_SAVED, "Toggle new crash handling"); } }; } diff --git a/src/client/component/fastfiles.cpp b/src/client/component/fastfiles.cpp index 64e6af6b..0dcbf4aa 100644 --- a/src/client/component/fastfiles.cpp +++ b/src/client/component/fastfiles.cpp @@ -1,13 +1,13 @@ #include #include "loader/component_loader.hpp" -#include "game/dvars.hpp" - -#include "fastfiles.hpp" #include "command.hpp" #include "console.hpp" +#include "fastfiles.hpp" #include "filesystem.hpp" +#include "game/dvars.hpp" + #include #include #include diff --git a/src/client/component/fonts.cpp b/src/client/component/fonts.cpp index 07f447ca..e38c2ff6 100644 --- a/src/client/component/fonts.cpp +++ b/src/client/component/fonts.cpp @@ -1,8 +1,8 @@ #include #include "loader/component_loader.hpp" -#include "fonts.hpp" #include "console.hpp" +#include "fonts.hpp" #include "filesystem.hpp" #include "game/game.hpp" diff --git a/src/client/component/fps.cpp b/src/client/component/fps.cpp index dc721c3b..056398cf 100644 --- a/src/client/component/fps.cpp +++ b/src/client/component/fps.cpp @@ -1,15 +1,15 @@ #include #include "loader/component_loader.hpp" +#include "dvars.hpp" #include "fps.hpp" +#include "scheduler.hpp" #include "game/game.hpp" #include "game/dvars.hpp" -#include "dvars.hpp" #include #include -#include namespace fps { diff --git a/src/client/component/gsc/script_loading.cpp b/src/client/component/gsc/script_loading.cpp index e5232396..510c4f03 100644 --- a/src/client/component/gsc/script_loading.cpp +++ b/src/client/component/gsc/script_loading.cpp @@ -89,8 +89,7 @@ namespace gsc } std::string source_buffer; - const auto rawfile_gsc_exists = read_script_file(real_name + ".gsc", &source_buffer); - if (!rawfile_gsc_exists || source_buffer.empty()) + if (!read_script_file(real_name + ".gsc", &source_buffer) || source_buffer.empty()) { return nullptr; } @@ -98,17 +97,12 @@ namespace gsc if (game::DB_XAssetExists(game::ASSET_TYPE_SCRIPTFILE, file_name) && !game::DB_IsXAssetDefault(game::ASSET_TYPE_SCRIPTFILE, file_name)) { - // filter out developer rawfiles that won't compile + // filter out gsc rawfiles that contain developer code (has ScriptFile counterparts for ship, won't compile either) if ((real_name.starts_with("maps/createfx") || real_name.starts_with("maps/createart") || real_name.starts_with("maps/mp")) && (real_name.ends_with("_fx") || real_name.ends_with("_fog") || real_name.ends_with("_hdr"))) { return game::DB_FindXAssetHeader(game::ASSET_TYPE_SCRIPTFILE, file_name, false).scriptfile; } - - if (!rawfile_gsc_exists) - { - return game::DB_FindXAssetHeader(game::ASSET_TYPE_SCRIPTFILE, file_name, false).scriptfile; - } } std::vector data; diff --git a/src/client/component/map_rotation.cpp b/src/client/component/map_rotation.cpp index 6f749304..7b80bebf 100644 --- a/src/client/component/map_rotation.cpp +++ b/src/client/component/map_rotation.cpp @@ -1,11 +1,15 @@ #include #include "loader/component_loader.hpp" + #include "command.hpp" +#include "console.hpp" #include "scheduler.hpp" + +#include "game/game.hpp" +#include "game/dvars.hpp" + #include #include -#include "game/game.hpp" -#include namespace map_rotation { @@ -82,14 +86,12 @@ namespace map_rotation auto* const dvar = game::Dvar_FindVar("sv_autoPriority"); if (dvar && dvar->current.enabled) { - scheduler::on_game_initialized([]() + scheduler::on_game_initialized([] { - //printf("=======================setting OLD priority=======================\n"); SetPriorityClass(GetCurrentProcess(), previous_priority); }, scheduler::pipeline::main, 1s); previous_priority = GetPriorityClass(GetCurrentProcess()); - //printf("=======================setting NEW priority=======================\n"); SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS); } } @@ -119,7 +121,7 @@ namespace map_rotation change_process_priority(); if (!game::SV_MapExists(value.data())) { - printf("map_rotation: '%s' map doesn't exist!\n", value.data()); + console::info("map_rotation: '%s' map doesn't exist!\n", value.data()); launch_default_map(); return; } @@ -128,7 +130,7 @@ namespace map_rotation } else { - printf("Invalid map rotation key: %s\n", key.data()); + console::info("Invalid map rotation key: %s\n", key.data()); } } @@ -137,7 +139,7 @@ namespace map_rotation void trigger_map_rotation() { - scheduler::schedule([]() + scheduler::schedule([] { if (game::CL_IsCgameInitialized()) { @@ -160,7 +162,7 @@ namespace map_rotation return; } - scheduler::once([]() + scheduler::once([] { dvars::register_string("sv_mapRotation", "", game::DVAR_FLAG_NONE, ""); dvars::register_string("sv_mapRotationCurrent", "", game::DVAR_FLAG_NONE, ""); diff --git a/src/client/component/network.cpp b/src/client/component/network.cpp index e3069751..b9ad6039 100644 --- a/src/client/component/network.cpp +++ b/src/client/component/network.cpp @@ -7,6 +7,7 @@ #include "dvars.hpp" #include "game/dvars.hpp" +#include "game/game.hpp" #include #include @@ -33,7 +34,7 @@ namespace network return false; } - const std::string_view data(message->data + offset, message->cursize - offset); + const std::string data(message->data + offset, message->cursize - offset); handler->second(*address, data); #ifdef DEBUG @@ -302,11 +303,10 @@ namespace network utils::hook::set(0x4F1E25_b, max_packet_size); // ignore built in "print" oob command and add in our own - utils::hook::set(0x12F817_b, 0xEB); - on("print", [](const game::netadr_s&, const std::string_view& data) + utils::hook::set(0x12F817_b, 0xEB); + on("print", [](const game::netadr_s&, const std::string& data) { - const std::string message{data}; - console::info("%s\n", message.data()); + console::info("%s\n", data.data()); }); // Use our own socket since the game's socket doesn't work with non localhost addresses diff --git a/src/client/component/network.hpp b/src/client/component/network.hpp index c8c9d7fc..a412b691 100644 --- a/src/client/component/network.hpp +++ b/src/client/component/network.hpp @@ -3,7 +3,7 @@ namespace network { - using callback = std::function; + using callback = std::function; void on(const std::string& command, const callback& callback); void send(const game::netadr_s& address, const std::string& command, const std::string& data = {}, char separator = ' '); diff --git a/src/client/component/party.cpp b/src/client/component/party.cpp index 6e9e67b4..c685deb7 100644 --- a/src/client/component/party.cpp +++ b/src/client/component/party.cpp @@ -486,11 +486,6 @@ namespace party return connect_state.host; } - std::string get_state_challenge() - { - return connect_state.challenge; - } - void start_map(const std::string& mapname, bool dev) { if (game::Live_SyncOnlineDataFlags(0) > 32) @@ -770,7 +765,7 @@ namespace party game::SV_GameSendServerCommand(client_num, game::SV_CMD_CAN_IGNORE, utils::string::va("%c \"%s: %s\"", 84, name, message.data())); - printf("%s -> %i: %s\n", name, client_num, message.data()); + console::info("%s -> %i: %s\n", name, client_num, message.data()); }); command::add("tellraw", [](const command::params& params) @@ -785,7 +780,7 @@ namespace party game::SV_GameSendServerCommand(client_num, game::SV_CMD_CAN_IGNORE, utils::string::va("%c \"%s\"", 84, message.data())); - printf("%i: %s\n", client_num, message.data()); + console::info("%i: %s\n", client_num, message.data()); }); command::add("say", [](const command::params& params) @@ -800,7 +795,7 @@ namespace party game::SV_GameSendServerCommand( -1, game::SV_CMD_CAN_IGNORE, utils::string::va("%c \"%s: %s\"", 84, name, message.data())); - printf("%s: %s\n", name, message.data()); + console::info("%s: %s\n", name, message.data()); }); command::add("sayraw", [](const command::params& params) @@ -814,15 +809,15 @@ namespace party game::SV_GameSendServerCommand(-1, game::SV_CMD_CAN_IGNORE, utils::string::va("%c \"%s\"", 84, message.data())); - printf("%s\n", message.data()); + console::info("%s\n", message.data()); }); - network::on("getInfo", [](const game::netadr_s& target, const std::string_view& data) + network::on("getInfo", [](const game::netadr_s& target, const std::string& data) { const auto mapname = get_dvar_string("mapname"); - utils::info_string info{}; - info.set("challenge", std::string{data}); + utils::info_string info; + info.set("challenge", data); info.set("gamename", "H1"); info.set("hostname", get_dvar_string("sv_hostname")); info.set("gametype", get_dvar_string("g_gametype")); @@ -871,9 +866,9 @@ namespace party network::send(target, "infoResponse", info.build(), '\n'); }); - network::on("infoResponse", [](const game::netadr_s& target, const std::string_view& data) + network::on("infoResponse", [](const game::netadr_s& target, const std::string& data) { - const utils::info_string info{data}; + const utils::info_string info(data); server_list::handle_info_response(target, info); if (connect_state.host != target) diff --git a/src/client/component/party.hpp b/src/client/component/party.hpp index e770a426..69590895 100644 --- a/src/client/component/party.hpp +++ b/src/client/component/party.hpp @@ -12,7 +12,6 @@ namespace party void clear_sv_motd(); game::netadr_s get_state_host(); - std::string get_state_challenge(); int server_client_count(); int get_client_num_by_name(const std::string& name); diff --git a/src/client/component/server_list.cpp b/src/client/component/server_list.cpp index 9eb7fded..d9b2d668 100644 --- a/src/client/component/server_list.cpp +++ b/src/client/component/server_list.cpp @@ -491,7 +491,7 @@ namespace server_list scheduler::loop(do_frame_work, scheduler::pipeline::main); scheduler::loop(check_refresh, scheduler::pipeline::lui, 10ms); - network::on("getServersResponse", [](const game::netadr_s& target, const std::string_view& data) + network::on("getServersResponse", [](const game::netadr_s& target, const std::string& data) { { std::lock_guard _(mutex); @@ -503,7 +503,7 @@ namespace server_list master_state.requesting = false; std::optional start{}; - for (size_t i = 0; i + 6 < data.size(); ++i) + for (std::size_t i = 0; i + 6 < data.size(); ++i) { if (data[i + 6] == '\\') { @@ -527,8 +527,8 @@ namespace server_list game::netadr_s address{}; address.type = game::NA_IP; address.localNetID = game::NS_CLIENT1; - memcpy(&address.ip[0], data.data() + i + 0, 4); - memcpy(&address.port, data.data() + i + 4, 2); + std::memcpy(&address.ip[0], data.data() + i + 0, 4); + std::memcpy(&address.port, data.data() + i + 4, 2); master_state.queued_servers[address] = 0; } diff --git a/src/client/component/slowmotion.cpp b/src/client/component/slowmotion.cpp index 1ae9cb98..e70911fb 100644 --- a/src/client/component/slowmotion.cpp +++ b/src/client/component/slowmotion.cpp @@ -1,5 +1,8 @@ #include #include "loader/component_loader.hpp" + +#include "gsc/script_extension.hpp" + #include "game/game.hpp" #include @@ -7,34 +10,6 @@ namespace slowmotion { - namespace - { - void scr_cmd_set_slow_motion() - { - if (game::Scr_GetNumParam() < 1) - { - return; - } - - int duration = 1000; - float end = 1.0f; - const float start = game::Scr_GetFloat(0); - - if (game::Scr_GetNumParam() >= 2) - { - end = game::Scr_GetFloat(1); - } - - if (game::Scr_GetNumParam() >= 3) - { - duration = static_cast(game::Scr_GetFloat(2) * 1000.0f); - } - - game::SV_SetConfigstring(10, utils::string::va("%i %i %g %g", *game::mp::gameTime, duration, start, end)); - game::Com_SetSlowMotion(start, end, duration); - } - } - class component final : public component_interface { public: @@ -45,7 +20,22 @@ namespace slowmotion return; } - utils::hook::jump(0x43D2E0_b, scr_cmd_set_slow_motion); + gsc::function::add("setslowmotion", [](const gsc::function_args& args) + { + if (args.size() == 0) + { + return scripting::script_value{}; + } + + const auto start = args[0].as(); + const auto end = (args.size() > 0 ? args[1].as() : 1.0f); + const auto duration = (args.size() > 1 ? args[2].as() : 1) * 1000; + + game::SV_SetConfigstring(10, utils::string::va("%i %i %g %g", *game::mp::gameTime, duration, start, end)); + game::Com_SetSlowMotion(start, end, duration); + + return scripting::script_value{}; + }); } }; } diff --git a/src/client/component/steam_proxy.cpp b/src/client/component/steam_proxy.cpp index fa3f2f24..1c840647 100644 --- a/src/client/component/steam_proxy.cpp +++ b/src/client/component/steam_proxy.cpp @@ -5,16 +5,16 @@ #include "arxan.hpp" -#include -#include -#include -#include - #include "game/game.hpp" #include "steam/interface.hpp" #include "steam/steam.hpp" +#include +#include +#include +#include + namespace steam_proxy { namespace diff --git a/src/client/component/system_check.cpp b/src/client/component/system_check.cpp index 452f4df2..10002dde 100644 --- a/src/client/component/system_check.cpp +++ b/src/client/component/system_check.cpp @@ -1,7 +1,8 @@ #include #include "loader/component_loader.hpp" -#include "system_check.hpp" + #include "arxan.hpp" +#include "system_check.hpp" #include "game/game.hpp" diff --git a/src/client/component/updater.cpp b/src/client/component/updater.cpp index d19cdc8a..dcb44584 100644 --- a/src/client/component/updater.cpp +++ b/src/client/component/updater.cpp @@ -2,16 +2,15 @@ #include "loader/component_loader.hpp" #include "console.hpp" -#include "scheduler.hpp" -#include "dvars.hpp" -#include "updater.hpp" #include "fastfiles.hpp" -#include "game/ui_scripting/execution.hpp" - -#include "version.h" +#include "dvars.hpp" +#include "scheduler.hpp" +#include "updater.hpp" +#include "version.hpp" #include "game/game.hpp" #include "game/dvars.hpp" +#include "game/ui_scripting/execution.hpp" #include #include diff --git a/src/client/component/videos.cpp b/src/client/component/videos.cpp index 04b9d2c5..e380ab16 100644 --- a/src/client/component/videos.cpp +++ b/src/client/component/videos.cpp @@ -10,6 +10,7 @@ namespace videos namespace { utils::hook::detour playvid_hook; + std::unordered_map video_replaces; void playvid(const char* name, const int a2, const int a3) diff --git a/src/client/component/virtuallobby.cpp b/src/client/component/virtuallobby.cpp index 57db01e4..9eda8e65 100644 --- a/src/client/component/virtuallobby.cpp +++ b/src/client/component/virtuallobby.cpp @@ -12,37 +12,34 @@ namespace virtuallobby { game::dvar_t* virtual_lobby_fovscale; - void* get_get_fovscale_stub() + void get_get_fovscale_stub(utils::hook::assembler& a) { - return utils::hook::assemble([](utils::hook::assembler& a) - { - const auto ret = a.newLabel(); - const auto original = a.newLabel(); + const auto ret = a.newLabel(); + const auto original = a.newLabel(); - a.pushad64(); - a.mov(rax, qword_ptr(0x2999CE8_b)); // virtualLobbyInFiringRange - a.cmp(byte_ptr(rax, 0x10), 1); - a.je(original); - a.call_aligned(game::VirtualLobby_Loaded); - a.cmp(al, 0); - a.je(original); + a.pushad64(); + a.mov(rax, qword_ptr(0x2999CE8_b)); // virtualLobbyInFiringRange + a.cmp(byte_ptr(rax, 0x10), 1); + a.je(original); + a.call_aligned(game::VirtualLobby_Loaded); + a.cmp(al, 0); + a.je(original); - // virtuallobby - a.popad64(); - a.mov(rax, ptr(reinterpret_cast(&virtual_lobby_fovscale))); - a.jmp(ret); + // virtuallobby + a.popad64(); + a.mov(rax, ptr(reinterpret_cast(&virtual_lobby_fovscale))); + a.jmp(ret); - // original - a.bind(original); - a.popad64(); - a.mov(rax, qword_ptr(0x14C4EC8_b)); - a.jmp(ret); + // original + a.bind(original); + a.popad64(); + a.mov(rax, qword_ptr(0x14C4EC8_b)); + a.jmp(ret); - a.bind(ret); - a.mov(rdi, rax); - a.mov(ecx, 8); - a.jmp(0x104545_b); - }); + a.bind(ret); + a.mov(rdi, rax); + a.mov(ecx, 8); + a.jmp(0x104545_b); } } @@ -59,7 +56,7 @@ namespace virtuallobby virtual_lobby_fovscale = dvars::register_float_hashed("virtualLobby_fovScale", 0.7f, 0.0f, 2.0f, game::DVAR_FLAG_SAVED, "Field of view scaled for the virtual lobby"); - utils::hook::jump(0x104539_b, get_get_fovscale_stub(), true); + utils::hook::jump(0x104539_b, utils::hook::assemble(get_get_fovscale_stub), true); } }; } diff --git a/src/client/component/weapon.cpp b/src/client/component/weapon.cpp index 86ed93cd..ad88234b 100644 --- a/src/client/component/weapon.cpp +++ b/src/client/component/weapon.cpp @@ -1,13 +1,13 @@ #include #include "loader/component_loader.hpp" -#include "game/game.hpp" - -#include "console.hpp" #include "command.hpp" +#include "console.hpp" #include "fastfiles.hpp" -#include "utils/hook.hpp" +#include "game/game.hpp" + +#include namespace weapon {