From 940752950eb0fb18c99a2670912618007288d28f Mon Sep 17 00:00:00 2001 From: Diavolo Date: Mon, 30 Oct 2023 09:59:20 +0100 Subject: [PATCH] maint: cleanup --- .github/workflows/build.yml | 4 +- premake5.lua | 2 - src/client/component/command_additions.cpp | 4 +- src/common/utils/cryptography.cpp | 4 +- src/common/utils/info_string.hpp | 4 +- src/common/utils/io.cpp | 2 +- src/common/utils/nt.cpp | 12 +++--- src/common/utils/nt.hpp | 34 ++++++++-------- src/common/utils/string.cpp | 45 ---------------------- src/common/utils/string.hpp | 5 --- 10 files changed, 32 insertions(+), 84 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0a30727..ccd1a27 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,7 +24,7 @@ jobs: - Release steps: - name: Check out files - uses: actions/checkout@v3.5.2 + uses: actions/checkout@v4 with: submodules: true fetch-depth: 0 @@ -44,7 +44,7 @@ jobs: run: msbuild /m /v:minimal /p:Configuration=${{matrix.configuration}} /p:Platform=Win32 build/black-ops-plugin.sln - name: Upload ${{matrix.configuration}} binaries - uses: actions/upload-artifact@v3.1.2 + uses: actions/upload-artifact@v3.1.3 with: name: ${{matrix.configuration}} binaries path: | diff --git a/premake5.lua b/premake5.lua index 7130cdf..3745dc4 100644 --- a/premake5.lua +++ b/premake5.lua @@ -92,8 +92,6 @@ targetname "black-ops-plugin" 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"} diff --git a/src/client/component/command_additions.cpp b/src/client/component/command_additions.cpp index ba49bd4..195f140 100644 --- a/src/client/component/command_additions.cpp +++ b/src/client/component/command_additions.cpp @@ -44,10 +44,10 @@ class component final : public component_interface { game::select(0x355E69C, 0x243FB1C)); cmd_vstr_f_var->function = cmd_vstr_f; - if (game::environment::is_sp()) { + if (game::environment::is_sp()) { // Fix (client) crash from SV_DropClient (server side) utils::hook::set(0x634C1D, 0xEB); - } + } } }; } // namespace command_additions diff --git a/src/common/utils/cryptography.cpp b/src/common/utils/cryptography.cpp index bfdf040..435035f 100644 --- a/src/common/utils/cryptography.cpp +++ b/src/common/utils/cryptography.cpp @@ -2,11 +2,11 @@ #include "cryptography.hpp" namespace jenkins_one_at_a_time { -unsigned int jenkins_one_at_a_time::compute(const std::string& data) { +unsigned int compute(const std::string& data) { return compute(data.data(), data.size()); } -unsigned int jenkins_one_at_a_time::compute(const char* key, const size_t len) { +unsigned int compute(const char* key, const size_t len) { unsigned int hash, i; for (hash = i = 0; i < len; ++i) { hash += key[i]; diff --git a/src/common/utils/info_string.hpp b/src/common/utils/info_string.hpp index 9a2027c..a26f023 100644 --- a/src/common/utils/info_string.hpp +++ b/src/common/utils/info_string.hpp @@ -11,8 +11,8 @@ class info_string { info_string(const std::string_view& buffer); void set(const std::string& key, const std::string& value); - std::string get(const std::string& key) const; - std::string build() const; + [[nodiscard]] std::string get(const std::string& key) const; + [[nodiscard]] std::string build() const; private: std::unordered_map key_value_pairs_{}; diff --git a/src/common/utils/io.cpp b/src/common/utils/io.cpp index 5e017f9..afa6e68 100644 --- a/src/common/utils/io.cpp +++ b/src/common/utils/io.cpp @@ -55,7 +55,7 @@ bool read_file(const std::string& file, std::string* data) { stream.seekg(0, std::ios::beg); if (size > -1) { - data->resize(static_cast(size)); + data->resize(static_cast(size)); stream.read(data->data(), size); stream.close(); return true; diff --git a/src/common/utils/nt.cpp b/src/common/utils/nt.cpp index da93ba8..6bd1d74 100644 --- a/src/common/utils/nt.cpp +++ b/src/common/utils/nt.cpp @@ -6,7 +6,7 @@ library library::load(const std::string& name) { } library library::load(const std::filesystem::path& path) { - return library::load(path.generic_string()); + return load(path.generic_string()); } library library::get_by_address(void* address) { @@ -98,7 +98,7 @@ bool library::is_valid() const { std::string library::get_name() const { if (!this->is_valid()) - return ""; + return {}; auto path = this->get_path(); const auto pos = path.find_last_of("/\\"); @@ -110,9 +110,9 @@ std::string library::get_name() const { std::string library::get_path() const { if (!this->is_valid()) - return ""; + return {}; - char name[MAX_PATH] = {0}; + char name[MAX_PATH]{}; GetModuleFileNameA(this->module_, name, sizeof name); return name; @@ -120,7 +120,7 @@ std::string library::get_path() const { std::string library::get_folder() const { if (!this->is_valid()) - return ""; + return {}; const auto path = std::filesystem::path(this->get_path()); return path.parent_path().generic_string(); @@ -221,7 +221,7 @@ void relaunch_self() { ZeroMemory(&process_info, sizeof(process_info)); startup_info.cb = sizeof(startup_info); - char current_dir[MAX_PATH]; + char current_dir[MAX_PATH]{}; GetCurrentDirectoryA(sizeof(current_dir), current_dir); auto* const command_line = GetCommandLineA(); diff --git a/src/common/utils/nt.hpp b/src/common/utils/nt.hpp index 5cfd331..cbb071d 100644 --- a/src/common/utils/nt.hpp +++ b/src/common/utils/nt.hpp @@ -32,21 +32,21 @@ class library final { bool operator!=(const library& obj) const { return !(*this == obj); }; bool operator==(const library& obj) const; - operator bool() const; - operator HMODULE() const; + [[nodiscard]] operator bool() const; + [[nodiscard]] operator HMODULE() const; void unprotect() const; - void* get_entry_point() const; - size_t get_relative_entry_point() const; - - bool is_valid() const; - std::string get_name() const; - std::string get_path() const; - std::string get_folder() const; - std::uint8_t* get_ptr() const; + [[nodiscard]] void* get_entry_point() const; + [[nodiscard]] size_t get_relative_entry_point() const; + + [[nodiscard]] bool is_valid() const; + [[nodiscard]] std::string get_name() const; + [[nodiscard]] std::string get_path() const; + [[nodiscard]] std::string get_folder() const; + [[nodiscard]] std::uint8_t* get_ptr() const; void free(); - HMODULE get_handle() const; + [[nodiscard]] HMODULE get_handle() const; template T get_proc(const std::string& process) const { if (!this->is_valid()) @@ -85,14 +85,14 @@ class library final { return T(); } - std::vector get_section_headers() const; + [[nodiscard]] std::vector get_section_headers() const; - PIMAGE_NT_HEADERS get_nt_headers() const; - PIMAGE_DOS_HEADER get_dos_header() const; - PIMAGE_OPTIONAL_HEADER get_optional_header() const; + [[nodiscard]] PIMAGE_NT_HEADERS get_nt_headers() const; + [[nodiscard]] PIMAGE_DOS_HEADER get_dos_header() const; + [[nodiscard]] PIMAGE_OPTIONAL_HEADER get_optional_header() const; - void** get_iat_entry(const std::string& module_name, - const std::string& proc_name) const; + [[nodiscard]] void** get_iat_entry(const std::string& module_name, + const std::string& proc_name) const; private: HMODULE module_; diff --git a/src/common/utils/string.cpp b/src/common/utils/string.cpp index d6b9b4f..bad3cac 100644 --- a/src/common/utils/string.cpp +++ b/src/common/utils/string.cpp @@ -93,51 +93,6 @@ std::string get_clipboard_data() { return {}; } -void strip(const char* in, char* out, size_t max) { - if (!in || !out) - return; - - max--; - size_t current = 0; - while (*in != 0 && current < max) { - const auto color_index = (*(in + 1) - 48) >= 0xC ? 7 : (*(in + 1) - 48); - - if (*in == '^' && (color_index != 7 || *(in + 1) == '7')) { - ++in; - } else { - *out = *in; - ++out; - ++current; - } - - ++in; - } - - *out = '\0'; -} - -std::string convert(const std::wstring& wstr) { - std::string result; - result.reserve(wstr.size()); - - for (const auto& chr : wstr) { - result.push_back(static_cast(chr)); - } - - return result; -} - -std::wstring convert(const std::string& str) { - std::wstring result; - result.reserve(str.size()); - - for (const auto& chr : str) { - result.push_back(static_cast(chr)); - } - - return result; -} - std::string replace(std::string str, const std::string& from, const std::string& to) { if (from.empty()) { diff --git a/src/common/utils/string.hpp b/src/common/utils/string.hpp index e4bdf2e..c8772b5 100644 --- a/src/common/utils/string.hpp +++ b/src/common/utils/string.hpp @@ -87,11 +87,6 @@ std::string dump_hex(const std::string& data, std::string get_clipboard_data(); -void strip(const char* in, char* out, size_t max); - -std::string convert(const std::wstring& wstr); -std::wstring convert(const std::string& str); - std::string replace(std::string str, const std::string& from, const std::string& to); } // namespace utils::string