From d20cdfbb41b771fd07c857f80d479a5881e2fa3a Mon Sep 17 00:00:00 2001 From: Diavolo Date: Mon, 18 Apr 2022 12:32:56 +0200 Subject: [PATCH] Fix crash --- .gitmodules | 3 + README.md | 2 +- deps/asmjit | 1 + deps/premake/asmjit.lua | 34 +++++++++ premake5.lua | 33 +++++++-- src/{ => client}/component/ban.cpp | 7 +- src/{ => client}/component/bots.cpp | 10 +-- src/{ => client}/component/chat.cpp | 22 +++--- src/{ => client}/component/command.cpp | 70 ++++++++++++------- src/{ => client}/component/command.hpp | 4 -- src/client/component/gameplay.cpp | 30 ++++++++ src/{main.cpp => client/dllmain.cpp} | 2 +- src/{ => client}/game/game.cpp | 2 +- src/{ => client}/game/game.hpp | 1 + src/{ => client}/game/structs.hpp | 3 +- src/{ => client}/game/symbols.hpp | 2 +- .../loader/component_interface.hpp | 0 src/{ => client}/loader/component_loader.cpp | 2 +- src/{ => client}/loader/component_loader.hpp | 0 src/client/std_include.cpp | 1 + src/{stdinc.hpp => client/std_include.hpp} | 2 +- src/{ => common}/utils/concurrency.hpp | 0 src/{ => common}/utils/cryptography.cpp | 0 src/{ => common}/utils/cryptography.hpp | 0 src/{ => common}/utils/hook.cpp | 24 +++++++ src/{ => common}/utils/hook.hpp | 19 ++++- src/{ => common}/utils/info_string.cpp | 0 src/{ => common}/utils/info_string.hpp | 0 src/{ => common}/utils/io.cpp | 6 +- src/{ => common}/utils/io.hpp | 0 src/{ => common}/utils/memory.cpp | 2 +- src/{ => common}/utils/memory.hpp | 13 ++-- src/{ => common}/utils/nt.cpp | 0 src/{ => common}/utils/nt.hpp | 0 src/{ => common}/utils/signature.cpp | 0 src/{ => common}/utils/signature.hpp | 0 src/{ => common}/utils/string.cpp | 8 +-- src/{ => common}/utils/string.hpp | 3 +- src/component/gameplay.cpp | 31 -------- src/stdinc.cpp | 1 - 40 files changed, 224 insertions(+), 114 deletions(-) create mode 160000 deps/asmjit create mode 100644 deps/premake/asmjit.lua rename src/{ => client}/component/ban.cpp (92%) rename src/{ => client}/component/bots.cpp (92%) rename src/{ => client}/component/chat.cpp (87%) rename src/{ => client}/component/command.cpp (62%) rename src/{ => client}/component/command.hpp (75%) create mode 100644 src/client/component/gameplay.cpp rename src/{main.cpp => client/dllmain.cpp} (92%) rename src/{ => client}/game/game.cpp (93%) rename src/{ => client}/game/game.hpp (99%) rename src/{ => client}/game/structs.hpp (99%) rename src/{ => client}/game/symbols.hpp (98%) rename src/{ => client}/loader/component_interface.hpp (100%) rename src/{ => client}/loader/component_loader.cpp (98%) rename src/{ => client}/loader/component_loader.hpp (100%) create mode 100644 src/client/std_include.cpp rename src/{stdinc.hpp => client/std_include.hpp} (96%) rename src/{ => common}/utils/concurrency.hpp (100%) rename src/{ => common}/utils/cryptography.cpp (100%) rename src/{ => common}/utils/cryptography.hpp (100%) rename src/{ => common}/utils/hook.cpp (90%) rename src/{ => common}/utils/hook.hpp (86%) rename src/{ => common}/utils/info_string.cpp (100%) rename src/{ => common}/utils/info_string.hpp (100%) rename src/{ => common}/utils/io.cpp (94%) rename src/{ => common}/utils/io.hpp (100%) rename src/{ => common}/utils/memory.cpp (98%) rename src/{ => common}/utils/memory.hpp (74%) rename src/{ => common}/utils/nt.cpp (100%) rename src/{ => common}/utils/nt.hpp (100%) rename src/{ => common}/utils/signature.cpp (100%) rename src/{ => common}/utils/signature.hpp (100%) rename src/{ => common}/utils/string.cpp (95%) rename src/{ => common}/utils/string.hpp (97%) delete mode 100644 src/component/gameplay.cpp delete mode 100644 src/stdinc.cpp diff --git a/.gitmodules b/.gitmodules index d5a267d..592affd 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "deps/rapidjson"] path = deps/rapidjson url = https://github.com/Tencent/rapidjson.git +[submodule "deps/asmjit"] + path = deps/asmjit + url = https://github.com/asmjit/asmjit.git diff --git a/README.md b/README.md index 905aa7e..f0584c5 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ [![build](https://github.com/diamante0018/BlackOpsPlugin/workflows/Build/badge.svg)](https://github.com/diamante0018/BlackOpsPlugin/actions) # Black-Ops-Plugin -I have no clue as to what this does. I use this program to test experimental features. +I use this program to test experimental features. Some may end up in the plutonium client. Some may not. ## Thanks to * [momo5502](https://github.com/momo5502) - Core component loader & utils diff --git a/deps/asmjit b/deps/asmjit new file mode 160000 index 0000000..a4cb51b --- /dev/null +++ b/deps/asmjit @@ -0,0 +1 @@ +Subproject commit a4cb51b532af0f8137c4182914244c3b05d7745f diff --git a/deps/premake/asmjit.lua b/deps/premake/asmjit.lua new file mode 100644 index 0000000..ee93259 --- /dev/null +++ b/deps/premake/asmjit.lua @@ -0,0 +1,34 @@ +asmjit = { + source = path.join(dependencies.basePath, "asmjit"), +} + +function asmjit.import() + links { "asmjit" } + asmjit.includes() +end + +function asmjit.includes() + includedirs { + path.join(asmjit.source, "src") + } + + defines { + "ASMJIT_STATIC" + } +end + +function asmjit.project() + project "asmjit" + language "C++" + + asmjit.includes() + + files { + path.join(asmjit.source, "src/**.cpp"), + } + + warnings "Off" + kind "StaticLib" +end + +table.insert(dependencies, asmjit) diff --git a/premake5.lua b/premake5.lua index 4bfa58b..ddf9215 100644 --- a/premake5.lua +++ b/premake5.lua @@ -51,7 +51,7 @@ editandcontinue "Off" warnings "Extra" characterset "ASCII" -flags { "NoIncrementalLink", "NoMinimalRebuild", "MultiProcessorCompile", "No64BitChecks" } +flags {"NoIncrementalLink", "NoMinimalRebuild", "MultiProcessorCompile", "No64BitChecks"} filter "platforms:Win*" defines {"_WINDOWS", "WIN32"} @@ -60,7 +60,7 @@ filter {} filter "configurations:Release" optimize "Size" buildoptions {"/GL"} - linkoptions { "/IGNORE:4702", "/LTCG" } + linkoptions {"/IGNORE:4702", "/LTCG"} defines {"NDEBUG"} flags {"FatalCompileWarnings"} filter {} @@ -70,13 +70,36 @@ filter "configurations:Debug" defines {"DEBUG", "_DEBUG"} filter {} -project "black-ops-plugin" +project "common" +kind "StaticLib" +language "C++" + +files {"./src/common/**.hpp", "./src/common/**.cpp"} + +includedirs {"./src/common", "%{prj.location}/src"} + +resincludedirs {"$(ProjectDir)src"} + +dependencies.imports() + +project "client" kind "SharedLib" language "C++" -files {"./src/**.hpp", "./src/**.cpp"} +targetname "black-ops-plugin" -includedirs {"src"} +pchheader "std_include.hpp" +pchsource "src/client/std_include.cpp" + +linkoptions {"/IGNORE:4254", "/PDBCompress"} + +files {"./src/client/**.hpp", "./src/client/**.cpp"} + +includedirs {"./src/client", "./src/common", "%{prj.location}/src"} + +resincludedirs {"$(ProjectDir)src"} + +links {"common"} dependencies.imports() diff --git a/src/component/ban.cpp b/src/client/component/ban.cpp similarity index 92% rename from src/component/ban.cpp rename to src/client/component/ban.cpp index fae00ba..a4ea238 100644 --- a/src/component/ban.cpp +++ b/src/client/component/ban.cpp @@ -1,7 +1,8 @@ -#include +#include -#include "loader/component_loader.hpp" -#include "utils/hook.hpp" +#include "../loader/component_loader.hpp" + +#include namespace ban { namespace { diff --git a/src/component/bots.cpp b/src/client/component/bots.cpp similarity index 92% rename from src/component/bots.cpp rename to src/client/component/bots.cpp index 00c4c7a..9a6ce3e 100644 --- a/src/component/bots.cpp +++ b/src/client/component/bots.cpp @@ -1,9 +1,9 @@ -#include +#include -#include "loader/component_loader.hpp" +#include "../loader/component_loader.hpp" -#include "utils/hook.hpp" -#include "utils/io.hpp" +#include +#include namespace bots { namespace { @@ -14,7 +14,7 @@ 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; + const auto* path = game::Dvar_FindVar("fs_homepath")->current.string; std::filesystem::current_path(path); if (!utils::io::file_exists("bots/bots.json")) { diff --git a/src/component/chat.cpp b/src/client/component/chat.cpp similarity index 87% rename from src/component/chat.cpp rename to src/client/component/chat.cpp index 03210a6..0e66a72 100644 --- a/src/component/chat.cpp +++ b/src/client/component/chat.cpp @@ -1,8 +1,8 @@ -#include +#include -#include "loader/component_loader.hpp" -#include "utils/hook.hpp" -#include "utils/string.hpp" +#include "../loader/component_loader.hpp" +#include +#include #include "command.hpp" @@ -11,26 +11,26 @@ namespace { std::mutex chat_mutex; std::unordered_set mute_list{}; -void mute_player(const game::client_s* cl) { +void mute_player(const game::client_s* client) { std::unique_lock _(chat_mutex); - if (mute_list.contains(cl->xuid)) { + if (mute_list.contains(client->xuid)) { game::SV_GameSendServerCommand( -1, game::SV_CMD_CAN_IGNORE, - utils::string::va("%c \"%s is already muted\"", 0x65, cl->name)); + utils::string::va("%c \"%s is already muted\"", 0x65, client->name)); return; } - mute_list.insert(cl->xuid); + mute_list.insert(client->xuid); } -void unmute_player(const game::client_s* cl) { +void unmute_player(const game::client_s* client) { std::unique_lock _(chat_mutex); - mute_list.erase(cl->xuid); + mute_list.erase(client->xuid); game::SV_GameSendServerCommand( - cl->gentity->entnum, game::SV_CMD_CAN_IGNORE, + client->gentity->entnum, game::SV_CMD_CAN_IGNORE, utils::string::va("%c \"You were unmuted\"", 0x65)); } diff --git a/src/component/command.cpp b/src/client/component/command.cpp similarity index 62% rename from src/component/command.cpp rename to src/client/component/command.cpp index 5f1014f..e52792d 100644 --- a/src/component/command.cpp +++ b/src/client/component/command.cpp @@ -1,9 +1,9 @@ -#include +#include -#include "loader/component_loader.hpp" -#include "utils/string.hpp" -#include "utils/nt.hpp" -#include "utils/io.hpp" +#include "../loader/component_loader.hpp" + +#include +#include #include "command.hpp" @@ -12,6 +12,33 @@ constexpr auto CMD_MAX_NESTING = 8; namespace command { std::unordered_map> handlers; +namespace { +void cmd_vstr_f(const params& params) { + if (params.size() < 2) { + game::Com_Printf(game::CON_CHANNEL_DONT_FILTER, + "vstr : execute a variable command\n"); + return; + } + + const auto* dvar_name = params.get(1); + const auto* dvar = game::Dvar_FindVar(dvar_name); + + if (dvar == nullptr) { + game::Com_Printf(game::CON_CHANNEL_DONT_FILTER, "%s doesn't exist\n", + dvar_name); + return; + } + + if (dvar->type == game::DVAR_TYPE_STRING || + dvar->type == game::DVAR_TYPE_ENUM) { + execute(dvar->current.string); + } else { + game::Com_Printf(game::CON_CHANNEL_DONT_FILTER, + "%s is not a string-based dvar\n", dvar->name); + } +} +} // namespace + void main_handler() { params params = {}; @@ -63,26 +90,6 @@ void add(const char* name, const std::function& callback) { handlers[command] = callback; } -std::vector script_commands; -utils::memory::allocator allocator; - -void add_script_command(const std::string& name, - const std::function& callback) { - script_commands.push_back(name); - const auto _name = allocator.duplicate_string(name); - add(_name, callback); -} - -void clear_script_commands() { - for (const auto& name : script_commands) { - handlers.erase(name); - game::Cmd_RemoveCommand(name.data()); - } - - allocator.clear(); - script_commands.clear(); -} - void execute(std::string command, const bool sync) { command += "\n"; @@ -97,11 +104,20 @@ class component final : public component_interface { public: void post_unpack() override { add_commands_generic(); } - void pre_destroy() override { clear_script_commands(); } - private: static void add_commands_generic() { add("properQuit", [](const params&) { utils::nt::raise_hard_exception(); }); + + add("echo", [](const params& params) { + for (auto i = 1; i < params.size(); i++) { + game::Com_Printf(game::CON_CHANNEL_DONT_FILTER, "%s ", params.get(i)); + } + + game::Com_Printf(game::CON_CHANNEL_DONT_FILTER, "\n"); + }); + + game::Cmd_RemoveCommand("vstr"); + add("vstr", cmd_vstr_f); } }; } // namespace command diff --git a/src/component/command.hpp b/src/client/component/command.hpp similarity index 75% rename from src/component/command.hpp rename to src/client/component/command.hpp index fde7f96..5aa2f92 100644 --- a/src/component/command.hpp +++ b/src/client/component/command.hpp @@ -18,9 +18,5 @@ private: void add_raw(const char* name, void (*callback)()); void add(const char* name, const std::function& callback); -void add_script_command(const std::string& name, - const std::function& callback); -void clear_script_commands(); - void execute(std::string command, bool sync = false); } // namespace command diff --git a/src/client/component/gameplay.cpp b/src/client/component/gameplay.cpp new file mode 100644 index 0000000..611c431 --- /dev/null +++ b/src/client/component/gameplay.cpp @@ -0,0 +1,30 @@ +#include + +#include "../loader/component_loader.hpp" +#include + +namespace gameplay { +namespace { +game::dvar_s** player_sustainAmmo = nullptr; + +utils::hook::detour pm_weapon_use_ammo_hook; + +void pm_weapon_use_ammo_stub(void* ps, int wp, int amount) { + if (!(*player_sustainAmmo)->current.enabled) { + pm_weapon_use_ammo_hook.invoke(ps, wp, amount); + } +} +} // namespace + +class component final : public component_interface { +public: + void post_unpack() override { + if (game::environment::t5zm()) { + player_sustainAmmo = reinterpret_cast(0xBCD250); + pm_weapon_use_ammo_hook.create(0x6979B0, &pm_weapon_use_ammo_stub); + } + } +}; +} // namespace gameplay + +REGISTER_COMPONENT(gameplay::component) diff --git a/src/main.cpp b/src/client/dllmain.cpp similarity index 92% rename from src/main.cpp rename to src/client/dllmain.cpp index 2a94104..b4cecb5 100644 --- a/src/main.cpp +++ b/src/client/dllmain.cpp @@ -1,4 +1,4 @@ -#include +#include "std_include.hpp" #include "loader/component_loader.hpp" BOOL APIENTRY DllMain(HMODULE /*module_*/, DWORD ul_reason_for_call, diff --git a/src/game/game.cpp b/src/client/game/game.cpp similarity index 93% rename from src/game/game.cpp rename to src/client/game/game.cpp index 4ebdc63..3b9f6d4 100644 --- a/src/game/game.cpp +++ b/src/client/game/game.cpp @@ -1,4 +1,4 @@ -#include +#include namespace game { gamemode current = reinterpret_cast(0xA6840C) == "multiplayer"s diff --git a/src/game/game.hpp b/src/client/game/game.hpp similarity index 99% rename from src/game/game.hpp rename to src/client/game/game.hpp index d690d06..cdf009e 100644 --- a/src/game/game.hpp +++ b/src/client/game/game.hpp @@ -19,6 +19,7 @@ public: T* get() const { if (environment::t5mp()) { + return t5mp_; } diff --git a/src/game/structs.hpp b/src/client/game/structs.hpp similarity index 99% rename from src/game/structs.hpp rename to src/client/game/structs.hpp index ede1690..f0b5ca4 100644 --- a/src/game/structs.hpp +++ b/src/client/game/structs.hpp @@ -276,10 +276,9 @@ typedef struct dvar_s { DvarValue saved; DvarLimits domain; dvar_s* hashNext; - unsigned char pad0[8]; } dvar_t; -static_assert(sizeof(dvar_s) == 112); +static_assert(sizeof(dvar_s) == 104); enum playerFlag { PLAYER_FLAG_NOCLIP = 1 << 0, diff --git a/src/game/symbols.hpp b/src/client/game/symbols.hpp similarity index 98% rename from src/game/symbols.hpp rename to src/client/game/symbols.hpp index a3e24a8..81cc094 100644 --- a/src/game/symbols.hpp +++ b/src/client/game/symbols.hpp @@ -32,7 +32,7 @@ WEAK symbol NET_OutOfBandPrint{0x560BB0, 0x472850}; WEAK symbol NET_AdrToString{0x49F970, 0x40D790}; -WEAK symbol Dvar_FindVar{0x512F70, 0x5AE810}; +WEAK symbol Dvar_FindVar{0x512F70, 0x5AE810}; WEAK symbol Dvar_DisplayableValue{0x681DD0, 0x5B56F0}; WEAK symbol Dvar_DisplayableLatchedValue{0x4AE1A0, diff --git a/src/loader/component_interface.hpp b/src/client/loader/component_interface.hpp similarity index 100% rename from src/loader/component_interface.hpp rename to src/client/loader/component_interface.hpp diff --git a/src/loader/component_loader.cpp b/src/client/loader/component_loader.cpp similarity index 98% rename from src/loader/component_loader.cpp rename to src/client/loader/component_loader.cpp index c6e3f18..aed344c 100644 --- a/src/loader/component_loader.cpp +++ b/src/client/loader/component_loader.cpp @@ -1,4 +1,4 @@ -#include +#include #include "component_loader.hpp" void component_loader::register_component( diff --git a/src/loader/component_loader.hpp b/src/client/loader/component_loader.hpp similarity index 100% rename from src/loader/component_loader.hpp rename to src/client/loader/component_loader.hpp diff --git a/src/client/std_include.cpp b/src/client/std_include.cpp new file mode 100644 index 0000000..e912508 --- /dev/null +++ b/src/client/std_include.cpp @@ -0,0 +1 @@ +#include "std_include.hpp" diff --git a/src/stdinc.hpp b/src/client/std_include.hpp similarity index 96% rename from src/stdinc.hpp rename to src/client/std_include.hpp index 7907a24..5dff469 100644 --- a/src/stdinc.hpp +++ b/src/client/std_include.hpp @@ -7,7 +7,7 @@ #define WIN32_LEAN_AND_MEAN -#include +#include #include #include diff --git a/src/utils/concurrency.hpp b/src/common/utils/concurrency.hpp similarity index 100% rename from src/utils/concurrency.hpp rename to src/common/utils/concurrency.hpp diff --git a/src/utils/cryptography.cpp b/src/common/utils/cryptography.cpp similarity index 100% rename from src/utils/cryptography.cpp rename to src/common/utils/cryptography.cpp diff --git a/src/utils/cryptography.hpp b/src/common/utils/cryptography.hpp similarity index 100% rename from src/utils/cryptography.hpp rename to src/common/utils/cryptography.hpp diff --git a/src/utils/hook.cpp b/src/common/utils/hook.cpp similarity index 90% rename from src/utils/hook.cpp rename to src/common/utils/hook.cpp index 4cd9cf9..ab6e654 100644 --- a/src/utils/hook.cpp +++ b/src/common/utils/hook.cpp @@ -17,6 +17,14 @@ public: } __; } // namespace +asmjit::Error assembler::call(void* target) { + return Assembler::call(size_t(target)); +} + +asmjit::Error assembler::jmp(void* target) { + return Assembler::jmp(size_t(target)); +} + detour::detour(const size_t place, void* target) : detour(reinterpret_cast(place), target) {} @@ -153,4 +161,20 @@ void redirect_jump(void* pointer, void* data) { void redirect_jump(size_t pointer, void* data) { redirect_jump(reinterpret_cast(pointer), data); } + +void* assemble(const std::function& asm_function) { + static asmjit::JitRuntime runtime; + + asmjit::CodeHolder code; + code.init(runtime.environment()); + + assembler a(&code); + + asm_function(a); + + void* result = nullptr; + runtime.add(&result, &code); + + return result; +} } // namespace utils::hook diff --git a/src/utils/hook.hpp b/src/common/utils/hook.hpp similarity index 86% rename from src/utils/hook.hpp rename to src/common/utils/hook.hpp index 6cae5d3..7fcbcf3 100644 --- a/src/utils/hook.hpp +++ b/src/common/utils/hook.hpp @@ -2,9 +2,24 @@ #include "signature.hpp" #define CalculateRelativeJMPAddress(X, Y) \ - (((std::uintptr_t)Y - (std::uintptr_t)X) - 5) + (((std::uintptr_t)(Y) - (std::uintptr_t)(X)) - 5) + +#include +#include + +using namespace asmjit::x86; namespace utils::hook { +class assembler : public Assembler { +public: + using Assembler::Assembler; + using Assembler::call; + using Assembler::jmp; + + asmjit::Error call(void* target); + asmjit::Error jmp(void* target); +}; + class detour { public: detour() = default; @@ -70,6 +85,8 @@ void jump(std::uintptr_t address, void* destination); void redirect_jump(void* pointer, void* data); void redirect_jump(size_t pointer, void* data); +void* assemble(const std::function& asm_function); + template T extract(void* address) { const auto data = static_cast(address); const auto offset = *reinterpret_cast(data); diff --git a/src/utils/info_string.cpp b/src/common/utils/info_string.cpp similarity index 100% rename from src/utils/info_string.cpp rename to src/common/utils/info_string.cpp diff --git a/src/utils/info_string.hpp b/src/common/utils/info_string.hpp similarity index 100% rename from src/utils/info_string.hpp rename to src/common/utils/info_string.hpp diff --git a/src/utils/io.cpp b/src/common/utils/io.cpp similarity index 94% rename from src/utils/io.cpp rename to src/common/utils/io.cpp index 11049d3..5e017f9 100644 --- a/src/utils/io.cpp +++ b/src/common/utils/io.cpp @@ -11,7 +11,9 @@ bool move_file(const std::string& src, const std::string& target) { return MoveFileA(src.data(), target.data()) == TRUE; } -bool file_exists(const std::string& file) { return std::ifstream(file).good(); } +bool file_exists(const std::string& file) { + return std::filesystem::exists(file); +} bool write_file(const std::string& file, const std::string& data, const bool append) { @@ -54,7 +56,7 @@ bool read_file(const std::string& file, std::string* data) { if (size > -1) { data->resize(static_cast(size)); - stream.read(const_cast(data->data()), size); + stream.read(data->data(), size); stream.close(); return true; } diff --git a/src/utils/io.hpp b/src/common/utils/io.hpp similarity index 100% rename from src/utils/io.hpp rename to src/common/utils/io.hpp diff --git a/src/utils/memory.cpp b/src/common/utils/memory.cpp similarity index 98% rename from src/utils/memory.cpp rename to src/common/utils/memory.cpp index 89787b7..00d4d96 100644 --- a/src/utils/memory.cpp +++ b/src/common/utils/memory.cpp @@ -9,7 +9,7 @@ memory::allocator::~allocator() { this->clear(); } void memory::allocator::clear() { std::lock_guard _(this->mutex_); - for (auto& data : this->pool_) { + for (const auto& data : this->pool_) { memory::free(data); } diff --git a/src/utils/memory.hpp b/src/common/utils/memory.hpp similarity index 74% rename from src/utils/memory.hpp rename to src/common/utils/memory.hpp index b12f238..cacf25f 100644 --- a/src/utils/memory.hpp +++ b/src/common/utils/memory.hpp @@ -18,11 +18,9 @@ public: void* allocate(size_t length); - template inline T* allocate() { - return this->allocate_array(1); - } + template T* allocate() { return this->allocate_array(1); } - template inline T* allocate_array(const size_t count = 1) { + template T* allocate_array(const size_t count = 1) { return static_cast(this->allocate(count * sizeof(T))); } @@ -37,12 +35,9 @@ public: static void* allocate(size_t length); - template static inline T* allocate() { - return allocate_array(1); - } + template static T* allocate() { return allocate_array(1); } - template - static inline T* allocate_array(const size_t count = 1) { + template static T* allocate_array(const size_t count = 1) { return static_cast(allocate(count * sizeof(T))); } diff --git a/src/utils/nt.cpp b/src/common/utils/nt.cpp similarity index 100% rename from src/utils/nt.cpp rename to src/common/utils/nt.cpp diff --git a/src/utils/nt.hpp b/src/common/utils/nt.hpp similarity index 100% rename from src/utils/nt.hpp rename to src/common/utils/nt.hpp diff --git a/src/utils/signature.cpp b/src/common/utils/signature.cpp similarity index 100% rename from src/utils/signature.cpp rename to src/common/utils/signature.cpp diff --git a/src/utils/signature.hpp b/src/common/utils/signature.hpp similarity index 100% rename from src/utils/signature.hpp rename to src/common/utils/signature.hpp diff --git a/src/utils/string.cpp b/src/common/utils/string.cpp similarity index 95% rename from src/utils/string.cpp rename to src/common/utils/string.cpp index eb91606..b3d5119 100644 --- a/src/utils/string.cpp +++ b/src/common/utils/string.cpp @@ -24,8 +24,7 @@ std::vector split(const std::string& s, const char delim) { std::vector elems; while (std::getline(ss, item, delim)) { - elems.push_back(item); // elems.push_back(std::move(item)); // if C++11 - // (based on comment from @mchiasson) + elems.push_back(item); // elems.push_back(std::move(item)); if C++11 } return elems; @@ -92,12 +91,12 @@ std::string get_clipboard_data() { return {}; } -void strip(const char* in, char* out, int max) { +void strip(const char* in, char* out, size_t max) { if (!in || !out) return; max--; - auto current = 0; + size_t current = 0; while (*in != 0 && current < max) { const auto color_index = (*(in + 1) - 48) >= 0xC ? 7 : (*(in + 1) - 48); @@ -111,6 +110,7 @@ void strip(const char* in, char* out, int max) { ++in; } + *out = '\0'; } diff --git a/src/utils/string.hpp b/src/common/utils/string.hpp similarity index 97% rename from src/utils/string.hpp rename to src/common/utils/string.hpp index 1193fb5..eb78028 100644 --- a/src/utils/string.hpp +++ b/src/common/utils/string.hpp @@ -1,6 +1,5 @@ #pragma once #include "memory.hpp" -#include #ifndef ARRAYSIZE template size_t ARRAYSIZE(Type (&)[n]) { return n; } @@ -87,7 +86,7 @@ std::string dump_hex(const std::string& data, std::string get_clipboard_data(); -void strip(const char* in, char* out, int max); +void strip(const char* in, char* out, size_t max); std::string convert(const std::wstring& wstr); std::wstring convert(const std::string& str); diff --git a/src/component/gameplay.cpp b/src/component/gameplay.cpp deleted file mode 100644 index 8d96dfc..0000000 --- a/src/component/gameplay.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include - -#include "loader/component_loader.hpp" -#include "utils/hook.hpp" - -namespace gameplay { -namespace { -const game::dvar_s* player_meleeRange = nullptr; -utils::hook::detour fire_weapon_melee_hook; - -void fire_weapon_melee_stub(game::gentity_s* ent, int time) { - if (player_meleeRange->current.value == 0.0f) - return; - - fire_weapon_melee_hook.invoke(ent, time); -} -} // namespace - -class component final : public component_interface { -public: - void post_unpack() override { - player_meleeRange = - *reinterpret_cast(SELECT(0xC51990, 0xBCAFE4)); - - fire_weapon_melee_hook.create(SELECT(0x401E00, 0x465E40), - &fire_weapon_melee_stub); - } -}; -} // namespace gameplay - -REGISTER_COMPONENT(gameplay::component) diff --git a/src/stdinc.cpp b/src/stdinc.cpp deleted file mode 100644 index c4d450f..0000000 --- a/src/stdinc.cpp +++ /dev/null @@ -1 +0,0 @@ -#include