From 64a90a5573e7a008d6505b76db193652de8af390 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Fri, 17 Apr 2020 21:29:34 +0200 Subject: [PATCH] Some cleanup --- src/game/demonware/byte_buffer.cpp | 2 +- src/game/demonware/data_types.hpp | 8 ++++---- src/game/demonware/services/bdDediRSAAuth.cpp | 10 +++++----- src/game/demonware/services/bdStorage.cpp | 4 ++-- src/main.cpp | 12 ++++++------ src/module/game_launcher.cpp | 2 +- src/module/scheduler.cpp | 5 ++--- src/module/scripting.cpp | 6 +++--- src/steam/interface.hpp | 5 +++-- src/steam/interfaces/apps.hpp | 5 ++++- src/steam/interfaces/friends.hpp | 5 ++++- src/steam/interfaces/game_server.hpp | 5 ++++- src/steam/interfaces/master_server_updater.hpp | 5 ++++- src/steam/interfaces/matchmaking.hpp | 5 ++++- src/steam/interfaces/matchmaking_servers.hpp | 5 ++++- src/steam/interfaces/networking.hpp | 5 ++++- src/steam/interfaces/remote_storage.hpp | 5 ++++- src/steam/interfaces/user.hpp | 5 ++++- src/steam/interfaces/user_stats.hpp | 5 ++++- src/steam/interfaces/utils.hpp | 5 ++++- src/steam/steam.hpp | 2 ++ src/utils/hook.cpp | 2 +- src/utils/memory.cpp | 2 +- src/utils/memory.hpp | 6 +++--- src/utils/nt.cpp | 2 +- src/utils/nt.hpp | 2 +- 26 files changed, 80 insertions(+), 45 deletions(-) diff --git a/src/game/demonware/byte_buffer.cpp b/src/game/demonware/byte_buffer.cpp index 01de5ea..6334557 100644 --- a/src/game/demonware/byte_buffer.cpp +++ b/src/game/demonware/byte_buffer.cpp @@ -266,7 +266,7 @@ namespace demonware bool byte_buffer::write(const int bytes, const void* data) { - this->buffer_.append(reinterpret_cast(data), bytes); + this->buffer_.append(static_cast(data), bytes); this->current_byte_ += bytes; return true; } diff --git a/src/game/demonware/data_types.hpp b/src/game/demonware/data_types.hpp index 1537dbd..dc2bd78 100644 --- a/src/game/demonware/data_types.hpp +++ b/src/game/demonware/data_types.hpp @@ -9,7 +9,7 @@ namespace demonware public: std::string file_data; - explicit bdFileData(const std::string& buffer) : file_data(buffer) + explicit bdFileData(std::string buffer) : file_data(std::move(buffer)) { } @@ -165,11 +165,11 @@ namespace demonware void deserialize(byte_buffer* buffer) override { - int size; - char* data; + int size{}; + char* data{}; buffer->read_blob(&data, &size); - if (data && size >= sizeof this->session_id) + if (data && uint32_t(size) >= sizeof(this->session_id)) { this->session_id = *reinterpret_cast(data); } diff --git a/src/game/demonware/services/bdDediRSAAuth.cpp b/src/game/demonware/services/bdDediRSAAuth.cpp index 9511c34..e4a2523 100644 --- a/src/game/demonware/services/bdDediRSAAuth.cpp +++ b/src/game/demonware/services/bdDediRSAAuth.cpp @@ -19,8 +19,8 @@ namespace demonware buffer.read_uint32(&seed); buffer.read_uint32(&title_id); - unsigned char rsakey[140]; - buffer.read_bytes(sizeof(rsakey), rsakey); + unsigned char rsa_key[140]; + buffer.read_bytes(sizeof(rsa_key), rsa_key); uint8_t ticket[1024]; buffer.read_bytes(std::min(ticket_size, static_cast(sizeof(ticket))), ticket); @@ -52,9 +52,9 @@ namespace demonware register_hash(&sha1_desc); register_prng(&yarrow_desc); - std::string encrypted_key = utils::cryptography::rsa::encrypt(std::string(SERVER_CD_KEY, 24), - std::string("DW-RSAENC", 10), - std::string(PCHAR(rsakey), sizeof(rsakey))); + auto encrypted_key = utils::cryptography::rsa::encrypt(std::string(SERVER_CD_KEY, 24), + std::string("DW-RSAENC", 10), + std::string(PCHAR(rsa_key), sizeof(rsa_key))); bit_buffer response; response.set_use_data_types(false); diff --git a/src/game/demonware/services/bdStorage.cpp b/src/game/demonware/services/bdStorage.cpp index bb9a453..4fc8f33 100644 --- a/src/game/demonware/services/bdStorage.cpp +++ b/src/game/demonware/services/bdStorage.cpp @@ -264,7 +264,7 @@ namespace demonware const auto path = get_user_file_path(filename); utils::io::write_file(path, data); - auto info = new bdFileInfo; + auto* info = new bdFileInfo; info->file_id = *reinterpret_cast(utils::cryptography::sha1::compute(filename).data()); info->filename = filename; @@ -281,7 +281,7 @@ namespace demonware void bdStorage::get_user_file(i_server* server, byte_buffer* buffer) const { - uint64_t owner; + uint64_t owner{}; std::string game, filename, platform, data; buffer->read_string(&game); diff --git a/src/main.cpp b/src/main.cpp index 98e6539..081b6f6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,12 +3,15 @@ #include "loader/loader.hpp" #include "loader/module_loader.hpp" #include "game/game.hpp" -#include "loader/binary_loader.hpp" #include "utils/string.hpp" #include "utils/flags.hpp" //#define GENERATE_DIFFS +#ifdef GENERATE_DIFFS +#include "loader/binary_loader.hpp" +#endif + DECLSPEC_NORETURN void WINAPI exit_hook(const int code) { module_loader::pre_destroy(); @@ -18,11 +21,8 @@ DECLSPEC_NORETURN void WINAPI exit_hook(const int code) void verify_tls() { const utils::nt::module self; - const auto self_tls = reinterpret_cast(self.get_ptr() + self - .get_optional_header() - -> - DataDirectory - [IMAGE_DIRECTORY_ENTRY_TLS].VirtualAddress); + const auto self_tls = reinterpret_cast(self.get_ptr() + + self.get_optional_header()->DataDirectory[IMAGE_DIRECTORY_ENTRY_TLS].VirtualAddress); const auto ref = DWORD(&tls_data); const auto tls_index = *reinterpret_cast(self_tls->AddressOfIndex); diff --git a/src/module/game_launcher.cpp b/src/module/game_launcher.cpp index 3a901d4..7850fa5 100644 --- a/src/module/game_launcher.cpp +++ b/src/module/game_launcher.cpp @@ -36,7 +36,7 @@ private: static void launch_game(const bool singleplayer) { - utils::nt::module self; + const utils::nt::module self; STARTUPINFOA s_info; PROCESS_INFORMATION p_info; diff --git a/src/module/scheduler.cpp b/src/module/scheduler.cpp index 1c8db69..58e316b 100644 --- a/src/module/scheduler.cpp +++ b/src/module/scheduler.cpp @@ -1,7 +1,6 @@ #include #include "scheduler.hpp" #include "utils/string.hpp" -#include "game/structs.hpp" #include "game/game.hpp" #include "utils/hook.hpp" @@ -60,8 +59,8 @@ void scheduler::execute_safe() void scheduler::execute_error() { - const char* message; - int level; + const char* message = nullptr; + int level = 0; if (get_next_error(&message, &level) && message) { diff --git a/src/module/scripting.cpp b/src/module/scripting.cpp index 9500e49..05c78e0 100644 --- a/src/module/scripting.cpp +++ b/src/module/scripting.cpp @@ -120,13 +120,13 @@ private: static void start_execution_stub() { module_loader::get()->start_execution(); - reinterpret_cast(start_hook_.get_original())(); + static_cast(start_hook_.get_original())(); } static void stop_execution_stub() { module_loader::get()->stop_execution(); - reinterpret_cast(stop_hook_.get_original())(); + static_cast(stop_hook_.get_original())(); } static void vm_notify_stub(const unsigned int notify_id, const unsigned short type, @@ -142,7 +142,7 @@ private: //printf("%X: %s\n", e.entity_id, e.name.data()); - for (auto value = stack; value->type != game::native::SCRIPT_END; --value) + for (auto* value = stack; value->type != game::native::SCRIPT_END; --value) { e.arguments.emplace_back(*value); } diff --git a/src/steam/interface.hpp b/src/steam/interface.hpp index 1e1ab94..b9bfa08 100644 --- a/src/steam/interface.hpp +++ b/src/steam/interface.hpp @@ -12,8 +12,9 @@ namespace steam }; template - struct argument_size_calculator final : std::integral_constant< - size_t, X + ((argument_size_calculator::value + (sizeof(void*) - 1)) & ~(sizeof(void*) - 1))> + struct argument_size_calculator final + : std::integral_constant::value + + (sizeof(void*) - 1)) & ~(sizeof(void*) - 1))> { }; diff --git a/src/steam/interfaces/apps.hpp b/src/steam/interfaces/apps.hpp index 1400584..b15283d 100644 --- a/src/steam/interfaces/apps.hpp +++ b/src/steam/interfaces/apps.hpp @@ -2,8 +2,11 @@ namespace steam { - class apps final + class apps { + protected: + ~apps() = default; + public: virtual bool BIsSubscribed(); virtual bool BIsLowViolence(); diff --git a/src/steam/interfaces/friends.hpp b/src/steam/interfaces/friends.hpp index c120efc..a491dc3 100644 --- a/src/steam/interfaces/friends.hpp +++ b/src/steam/interfaces/friends.hpp @@ -2,8 +2,11 @@ namespace steam { - class friends final + class friends { + protected: + ~friends() = default; + public: virtual const char* GetPersonaName(); virtual void SetPersonaName(const char* pchPersonaName); diff --git a/src/steam/interfaces/game_server.hpp b/src/steam/interfaces/game_server.hpp index f72841c..9f3ac38 100644 --- a/src/steam/interfaces/game_server.hpp +++ b/src/steam/interfaces/game_server.hpp @@ -2,8 +2,11 @@ namespace steam { - class game_server final + class game_server { + protected: + ~game_server() = default; + public: virtual void LogOn(); virtual void LogOff(); diff --git a/src/steam/interfaces/master_server_updater.hpp b/src/steam/interfaces/master_server_updater.hpp index 7739dbd..c9920a2 100644 --- a/src/steam/interfaces/master_server_updater.hpp +++ b/src/steam/interfaces/master_server_updater.hpp @@ -2,8 +2,11 @@ namespace steam { - class master_server_updater final + class master_server_updater { + protected: + ~master_server_updater() = default; + public: virtual void SetActive(bool bActive); virtual void SetHeartbeatInterval(int iHeartbeatInterval); diff --git a/src/steam/interfaces/matchmaking.hpp b/src/steam/interfaces/matchmaking.hpp index ce67df3..0b8c519 100644 --- a/src/steam/interfaces/matchmaking.hpp +++ b/src/steam/interfaces/matchmaking.hpp @@ -21,8 +21,11 @@ namespace steam int m_e_chat_room_enter_response; }; - class matchmaking final + class matchmaking { + protected: + ~matchmaking() = default; + public: virtual int GetFavoriteGameCount(); virtual bool GetFavoriteGame(int iGame, unsigned int* pnAppID, unsigned int* pnIP, unsigned short* pnConnPort, diff --git a/src/steam/interfaces/matchmaking_servers.hpp b/src/steam/interfaces/matchmaking_servers.hpp index 79fb552..e51b7cf 100644 --- a/src/steam/interfaces/matchmaking_servers.hpp +++ b/src/steam/interfaces/matchmaking_servers.hpp @@ -2,8 +2,11 @@ namespace steam { - class matchmaking_servers final + class matchmaking_servers { + protected: + ~matchmaking_servers() = default; + public: virtual void* RequestInternetServerList(unsigned int iApp, void** ppchFilters, unsigned int nFilters, void* pRequestServersResponse); diff --git a/src/steam/interfaces/networking.hpp b/src/steam/interfaces/networking.hpp index 9787ca7..b7a631b 100644 --- a/src/steam/interfaces/networking.hpp +++ b/src/steam/interfaces/networking.hpp @@ -2,8 +2,11 @@ namespace steam { - class networking final + class networking { + protected: + ~networking() = default; + public: virtual bool SendP2PPacket(steam_id steamIDRemote, const void* pubData, unsigned int cubData, int eP2PSendType); virtual bool IsP2PPacketAvailable(unsigned int* pcubMsgSize, int idk); diff --git a/src/steam/interfaces/remote_storage.hpp b/src/steam/interfaces/remote_storage.hpp index fd3c239..20b7a9f 100644 --- a/src/steam/interfaces/remote_storage.hpp +++ b/src/steam/interfaces/remote_storage.hpp @@ -2,8 +2,11 @@ namespace steam { - class remote_storage final + class remote_storage { + protected: + ~remote_storage() = default; + public: virtual bool FileWrite(const char* pchFile, const void* pvData, int cubData); virtual int GetFileSize(const char* pchFile); diff --git a/src/steam/interfaces/user.hpp b/src/steam/interfaces/user.hpp index 4ee71e7..779d5d1 100644 --- a/src/steam/interfaces/user.hpp +++ b/src/steam/interfaces/user.hpp @@ -9,8 +9,11 @@ namespace steam int m_e_result; }; - class user final + class user { + protected: + ~user() = default; + public: virtual int GetHSteamUser(); virtual bool LoggedOn(); diff --git a/src/steam/interfaces/user_stats.hpp b/src/steam/interfaces/user_stats.hpp index 9039814..b87c96a 100644 --- a/src/steam/interfaces/user_stats.hpp +++ b/src/steam/interfaces/user_stats.hpp @@ -2,8 +2,11 @@ namespace steam { - class user_stats final + class user_stats { + protected: + ~user_stats() = default; + public: virtual bool RequestCurrentStats(); virtual bool GetStat(const char* pchName, int* pData); diff --git a/src/steam/interfaces/utils.hpp b/src/steam/interfaces/utils.hpp index f2942d4..49bf0c7 100644 --- a/src/steam/interfaces/utils.hpp +++ b/src/steam/interfaces/utils.hpp @@ -2,8 +2,11 @@ namespace steam { - class utils final + class utils { + protected: + ~utils() = default; + public: virtual unsigned int GetSecondsSinceAppActive(); virtual unsigned int GetSecondsSinceComputerActive(); diff --git a/src/steam/steam.hpp b/src/steam/steam.hpp index 3a1a248..688d21c 100644 --- a/src/steam/steam.hpp +++ b/src/steam/steam.hpp @@ -64,6 +64,8 @@ namespace steam void set_i_callback(const int i_callback) { callback_ = i_callback; } protected: + ~base() = default; + unsigned char flags_; int callback_; }; diff --git a/src/utils/hook.cpp b/src/utils/hook.cpp index b66d1a6..aaeaea6 100644 --- a/src/utils/hook.cpp +++ b/src/utils/hook.cpp @@ -7,7 +7,7 @@ namespace utils { if (this->signatures_.empty()) return; - const auto start = reinterpret_cast(this->start_); + const auto start = static_cast(this->start_); const unsigned int sig_count = this->signatures_.size(); const auto containers = this->signatures_.data(); diff --git a/src/utils/memory.cpp b/src/utils/memory.cpp index 419e666..d26243f 100644 --- a/src/utils/memory.cpp +++ b/src/utils/memory.cpp @@ -91,7 +91,7 @@ namespace utils bool memory::is_set(const void* mem, const char chr, const size_t length) { - const auto mem_arr = reinterpret_cast(mem); + const auto mem_arr = static_cast(mem); for (size_t i = 0; i < length; ++i) { diff --git a/src/utils/memory.hpp b/src/utils/memory.hpp index 06b35ed..5a9a3d2 100644 --- a/src/utils/memory.hpp +++ b/src/utils/memory.hpp @@ -16,16 +16,16 @@ namespace utils void free(const void* data); - void* allocate(const size_t length); + void* allocate(size_t length); template - inline T* allocate() + T* allocate() { return this->allocate_array(1); } template - inline T* allocate_array(const size_t count = 1) + T* allocate_array(const size_t count = 1) { return static_cast(this->allocate(count * sizeof(T))); } diff --git a/src/utils/nt.cpp b/src/utils/nt.cpp index a3a148e..be87d6c 100644 --- a/src/utils/nt.cpp +++ b/src/utils/nt.cpp @@ -11,7 +11,7 @@ namespace utils::nt module module::get_by_address(void* address) { HMODULE handle = nullptr; - GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, reinterpret_cast(address), &handle); + GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, static_cast(address), &handle); return module(handle); } diff --git a/src/utils/nt.hpp b/src/utils/nt.hpp index 4892a72..0f52ed2 100644 --- a/src/utils/nt.hpp +++ b/src/utils/nt.hpp @@ -45,7 +45,7 @@ namespace utils::nt std::function get(const std::string& process) const { if (!this->is_valid()) std::function(); - return reinterpret_cast(this->get_proc(process)); + return static_cast(this->get_proc(process)); } template