From 40159196ab307eb28727253b9e425d48be2afdd4 Mon Sep 17 00:00:00 2001 From: FutureRave Date: Wed, 9 Feb 2022 00:08:28 +0000 Subject: [PATCH] Fix stuff --- premake5.lua | 38 +++++--------- src/component/ban.cpp | 5 +- src/component/bots.cpp | 101 +++++++++++++++++++++++++++++++++++++ src/component/chat.cpp | 11 ++-- src/component/command.cpp | 6 +-- src/component/gameplay.cpp | 2 +- src/game/game.cpp | 4 +- src/game/symbols.hpp | 2 +- src/stdinc.hpp | 1 - 9 files changed, 131 insertions(+), 39 deletions(-) create mode 100644 src/component/bots.cpp diff --git a/premake5.lua b/premake5.lua index 959e07c..d634da0 100644 --- a/premake5.lua +++ b/premake5.lua @@ -28,12 +28,6 @@ function dependencies.projects() end end -newoption { - trigger = "copy-to", - description = "Optional, copy the EXE to a custom folder after build, define the path here if wanted.", - value = "PATH" -} - dependencies.load() workspace "black-ops-plugin" @@ -45,6 +39,7 @@ targetname "%{prj.name}" configurations {"Debug", "Release"} language "C++" +cppdialect "C++20" architecture "x86" platforms "x86" @@ -58,23 +53,21 @@ characterset "ASCII" flags { "NoIncrementalLink", "NoMinimalRebuild", "MultiProcessorCompile", "No64BitChecks" } -filter "windows" -defines {"_WINDOWS", "WIN32"} +filter "platforms:x86" + defines {"_WINDOWS", "WIN32"} +filter {} -filter "Release" -optimize "Size" -buildoptions {"/GL"} -linkoptions { "/IGNORE:4702", "/LTCG" } - -defines {"NDEBUG"} - -flags {"FatalCompileWarnings"} - -filter "Debug" -optimize "Debug" - -defines {"DEBUG", "_DEBUG"} +filter "configurations:Release" + optimize "Size" + buildoptions {"/GL"} + linkoptions { "/IGNORE:4702", "/LTCG" } + defines {"NDEBUG"} + flags {"FatalCompileWarnings"} +filter {} +filter "configurations:Debug" + optimize "Debug" + defines {"DEBUG", "_DEBUG"} filter {} project "black-ops-plugin" @@ -89,6 +82,3 @@ dependencies.imports() group "Dependencies" dependencies.projects() - -workspace "*" - cppdialect "C++20" diff --git a/src/component/ban.cpp b/src/component/ban.cpp index d1dc84f..cdce783 100644 --- a/src/component/ban.cpp +++ b/src/component/ban.cpp @@ -12,6 +12,7 @@ namespace ban bool out_of_band_print_hk(game::netsrc_t src, game::netadr_s to, const char* msg) { + // Proof of concept patch. Please ignore if (msg != "error\nPATCH_BANNED_FROM_SERVER"s) { return game::NET_OutOfBandPrint(src, to, msg); @@ -29,10 +30,12 @@ namespace ban public: void post_unpack() override { + if (game::current == game::gamemode::zombies) return; + sv_discord = game::Dvar_RegisterString("sv_discord", "https://www.discord.gg/", game::DVAR_FLAG_SAVED, "Discord invitation link"); sv_clanWebsite = game::Dvar_RegisterString("sv_clanWebsite", "https://www.google.com/", game::DVAR_FLAG_SAVED, "Website link"); - utils::hook::call(SELECT(0x48B7E2, 0x0), out_of_band_print_hk); + utils::hook::call(0x48B7E2, out_of_band_print_hk); } }; } diff --git a/src/component/bots.cpp b/src/component/bots.cpp new file mode 100644 index 0000000..07581eb --- /dev/null +++ b/src/component/bots.cpp @@ -0,0 +1,101 @@ +#include + +#include "loader/component_loader.hpp" + +#include "utils/hook.hpp" +#include "utils/io.hpp" + +namespace bots +{ + namespace + { + typedef std::pair bot_entry; + + std::vector bot_names; + utils::hook::detour sv_bot_name_random_hook; + + // Json file is expected to contain a key for the bot's name. Value should be a string for the clantag + void load_bot_data() + { + const auto path = game::Dvar_FindVar("fs_homepath")->current.string; + std::filesystem::current_path(path); + + if (!utils::io::file_exists("bots/bots.json")) + { + game::Com_Printf(game::CON_CHANNEL_SERVER, "bots.json was not found\n"); + return; + } + + rapidjson::Document obj; + rapidjson::ParseResult result = obj.Parse(utils::io::read_file("bots/bots.json").data()); + + if (!result || !obj.IsObject()) + { + game::Com_Printf(game::CON_CHANNEL_SERVER, "Failed to parse ban file. Empty?\n"); + return; + } + + for (rapidjson::Value::ConstMemberIterator itr = obj.MemberBegin(); + itr != obj.MemberEnd(); ++itr) + { + if (itr->value.GetType() == rapidjson::Type::kStringType) + { + bot_names.emplace_back(std::make_pair(itr->name.GetString(), itr->value.GetString())); + } + } + } + + const char* sv_bot_name_random_stub() + { + if (bot_names.empty()) + { + load_bot_data(); + } + + static auto bot_id = 0; + if (!bot_names.empty()) + { + bot_id %= bot_names.size(); + const auto& entry = bot_names.at(bot_id++); + return entry.first.data(); + } + + return sv_bot_name_random_hook.invoke(); + } + + int build_connect_string(char* buf, const char* connect_string, const char* name, const char* xuid, + int protocol,int port) + { + // Default + auto clan_tag = "3arc"s; + for (const auto& entry : bot_names) + { + if (entry.first == name) + { + clan_tag = entry.second; + break; + } + } + + return _snprintf_s(buf, 0x400, _TRUNCATE, connect_string, name, + clan_tag.data(), xuid, protocol, port); + } + } + + class component final : public component_interface + { + public: + void post_unpack() override + { + if (game::current == game::gamemode::zombies) return; + + utils::hook::set(0x6B6294, "connect \"\\cg_predictItems\\1\\cl_punkbuster\\0\\cl_anonymous\\0\\color\\4\\head\\" + "default\\model\\multi\\snaps\\20\\rate\\5000\\name\\%s\\clanAbbrev\\%s\\bdOnlineUserID\\%s\\protocol\\%d\\qport\\%d\""); + + sv_bot_name_random_hook.create(0x49ED80, &sv_bot_name_random_stub); + utils::hook::call(0x6B6299, build_connect_string); + } + }; +} + +REGISTER_COMPONENT(bots::component) diff --git a/src/component/chat.cpp b/src/component/chat.cpp index 0b1ea5d..d18ff73 100644 --- a/src/component/chat.cpp +++ b/src/component/chat.cpp @@ -10,10 +10,12 @@ namespace chat { namespace { + std::mutex chat_mutex; std::unordered_set mute_list{}; void mute_player(const game::client_s* cl) { + std::unique_lock _(chat_mutex); if (mute_list.contains(cl->xuid)) { game::SV_GameSendServerCommand(-1, game::SV_CMD_CAN_IGNORE, @@ -26,6 +28,7 @@ namespace chat void unmute_player(const game::client_s* cl) { + std::unique_lock _(chat_mutex); mute_list.erase(cl->xuid); game::SV_GameSendServerCommand(cl->gentity->entnum, game::SV_CMD_CAN_IGNORE, @@ -44,6 +47,7 @@ namespace chat game::SV_Cmd_ArgvBuffer(0, buf, sizeof(buf)); + std::unique_lock _(chat_mutex); if (utils::string::starts_with(buf, "say") && mute_list.contains(game::svs_clients[clientNumber].xuid)) { @@ -66,11 +70,6 @@ namespace chat add_chat_commands(); } - void pre_destroy() override - { - mute_list.clear(); - } - private: static void add_chat_commands() { @@ -79,7 +78,7 @@ namespace chat if (params.size() < 3) { game::Com_Printf(game::CON_CHANNEL_DONT_FILTER, - "Usage: sayAs \n"); + "Usage: sayAs \n"); return; } diff --git a/src/component/command.cpp b/src/component/command.cpp index 35254ff..b7c0940 100644 --- a/src/component/command.cpp +++ b/src/component/command.cpp @@ -23,13 +23,13 @@ namespace command } params::params() - : nesting_(game::cmd_args->nesting) + : nesting_(game::sv_cmd_args->nesting) { } int params::size() const { - return game::cmd_args->argc[this->nesting_]; + return game::sv_cmd_args->argc[this->nesting_]; } const char* params::get(const int index) const @@ -39,7 +39,7 @@ namespace command return ""; } - return game::cmd_args->argv[this->nesting_][index]; + return game::sv_cmd_args->argv[this->nesting_][index]; } std::string params::join(const int index) const diff --git a/src/component/gameplay.cpp b/src/component/gameplay.cpp index eb6ccc5..ddbea54 100644 --- a/src/component/gameplay.cpp +++ b/src/component/gameplay.cpp @@ -24,7 +24,7 @@ namespace gameplay public: void post_unpack() override { - player_meleeRange = reinterpret_cast(SELECT(0xC51990, 0xBCAFE4)); + player_meleeRange = *reinterpret_cast(SELECT(0xC51990, 0xBCAFE4)); fire_weapon_melee_hook.create(SELECT(0x401E00, 0x465E40), &fire_weapon_melee_stub); } diff --git a/src/game/game.cpp b/src/game/game.cpp index b33e3fd..00a8071 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -8,12 +8,12 @@ namespace game namespace environment { - bool t6mp() + bool t5mp() { return current == gamemode::multiplayer; } - bool t6zm() + bool t5zm() { return current == gamemode::zombies; } diff --git a/src/game/symbols.hpp b/src/game/symbols.hpp index b5cbbfd..55791f6 100644 --- a/src/game/symbols.hpp +++ b/src/game/symbols.hpp @@ -51,7 +51,7 @@ namespace game WEAK symbol PM_GetEffectiveStance{0x659590, 0x0}; - WEAK symbol cmd_args{0x355BD88, 0x243D208}; + WEAK symbol sv_cmd_args{0x355BD88, 0x243D208}; WEAK symbol dvarCount{0x385BE74, 0x261CBD4}; WEAK symbol sortedDvars{0x385BE88, 0x261CBE8}; WEAK symbol svs_clients{0x372D11C, 0x286D01C}; diff --git a/src/stdinc.hpp b/src/stdinc.hpp index e622602..3360ac5 100644 --- a/src/stdinc.hpp +++ b/src/stdinc.hpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include