diff --git a/src/client/component/steam_proxy.cpp b/src/client/component/steam_proxy.cpp index c1f91f59..458db7bc 100644 --- a/src/client/component/steam_proxy.cpp +++ b/src/client/component/steam_proxy.cpp @@ -153,7 +153,7 @@ namespace steam_proxy const auto self = utils::nt::library::get_by_address(start_mod_unsafe); const auto path = self.get_path(); - const std::string cmdline = utils::string::va("\"%s\" -proc %d", path.data(), GetCurrentProcessId()); + const auto* cmdline = utils::string::va("\"%s\" -proc %d", path.generic_string().data(), GetCurrentProcessId()); steam::game_id game_id; game_id.raw.type = 1; // k_EGameIDTypeGameMod @@ -162,7 +162,7 @@ namespace steam_proxy const auto* mod_id = "bo3"; game_id.raw.mod_id = *reinterpret_cast(mod_id) | 0x80000000; - client_user.invoke("SpawnProcess", path.data(), cmdline.data(), our_directory, + client_user.invoke("SpawnProcess", path.generic_string().data(), cmdline, our_directory, &game_id.bits, title.data(), 0, 0, 0); return ownership_state::success; diff --git a/src/client/component/updater.cpp b/src/client/component/updater.cpp index dc54ae01..8c0d7eec 100644 --- a/src/client/component/updater.cpp +++ b/src/client/component/updater.cpp @@ -42,7 +42,7 @@ namespace updater std::string get_self_file() { const auto self = utils::nt::library::get_by_address(get_self_file); - return self.get_path(); + return self.get_path().generic_string(); } std::string get_leftover_file() diff --git a/src/client/main.cpp b/src/client/main.cpp index 531a50cc..7714b974 100644 --- a/src/client/main.cpp +++ b/src/client/main.cpp @@ -83,7 +83,7 @@ namespace auto game_path = std::filesystem::path(game_file); game_path.replace_extension(".start"); - utils::io::remove_file(game_path.generic_string()); + utils::io::remove_file(game_path); } PIMAGE_TLS_CALLBACK* get_tls_callbacks() diff --git a/src/common/utils/info_string.cpp b/src/common/utils/info_string.cpp index 7b857926..cd3d6637 100644 --- a/src/common/utils/info_string.cpp +++ b/src/common/utils/info_string.cpp @@ -32,7 +32,7 @@ namespace utils return value->second; } - return ""; + return {}; } void info_string::parse(std::string buffer) diff --git a/src/common/utils/io.cpp b/src/common/utils/io.cpp index a03d1bb2..45f2ab91 100644 --- a/src/common/utils/io.cpp +++ b/src/common/utils/io.cpp @@ -4,9 +4,9 @@ namespace utils::io { - bool remove_file(const std::string& file) + bool remove_file(const std::filesystem::path& file) { - if(DeleteFileA(file.data()) != FALSE) + if(DeleteFileW(file.wstring().data()) != FALSE) { return true; } @@ -14,9 +14,9 @@ namespace utils::io return GetLastError() == ERROR_FILE_NOT_FOUND; } - bool move_file(const std::string& src, const std::string& target) + bool move_file(const std::filesystem::path& src, const std::filesystem::path& target) { - return MoveFileA(src.data(), target.data()) == TRUE; + return MoveFileW(src.wstring().data(), target.wstring().data()) == TRUE; } bool file_exists(const std::string& file) @@ -37,7 +37,7 @@ namespace utils::io if (stream.is_open()) { - stream.write(data.data(), data.size()); + stream.write(data.data(), static_cast(data.size())); stream.close(); return true; } @@ -68,8 +68,8 @@ namespace utils::io if (size > -1) { - data->resize(static_cast(size)); - stream.read(const_cast(data->data()), size); + data->resize(static_cast(size)); + stream.read(data->data(), size); stream.close(); return true; } @@ -78,7 +78,7 @@ namespace utils::io return false; } - size_t file_size(const std::string& file) + std::size_t file_size(const std::string& file) { if (file_exists(file)) { @@ -87,29 +87,29 @@ namespace utils::io if (stream.good()) { stream.seekg(0, std::ios::end); - return static_cast(stream.tellg()); + return static_cast(stream.tellg()); } } return 0; } - bool create_directory(const std::string& directory) + bool create_directory(const std::filesystem::path& directory) { return std::filesystem::create_directories(directory); } - bool directory_exists(const std::string& directory) + bool directory_exists(const std::filesystem::path& directory) { return std::filesystem::is_directory(directory); } - bool directory_is_empty(const std::string& directory) + bool directory_is_empty(const std::filesystem::path& directory) { return std::filesystem::is_empty(directory); } - std::vector list_files(const std::string& directory) + std::vector list_files(const std::filesystem::path& directory) { std::vector files; diff --git a/src/common/utils/io.hpp b/src/common/utils/io.hpp index ab4ebaa4..52476834 100644 --- a/src/common/utils/io.hpp +++ b/src/common/utils/io.hpp @@ -6,16 +6,16 @@ namespace utils::io { - bool remove_file(const std::string& file); - bool move_file(const std::string& src, const std::string& target); + bool remove_file(const std::filesystem::path& file); + bool move_file(const std::filesystem::path& src, const std::filesystem::path& target); bool file_exists(const std::string& file); bool write_file(const std::string& file, const std::string& data, bool append = false); bool read_file(const std::string& file, std::string* data); std::string read_file(const std::string& file); size_t file_size(const std::string& file); - bool create_directory(const std::string& directory); - bool directory_exists(const std::string& directory); - bool directory_is_empty(const std::string& directory); - std::vector list_files(const std::string& directory); + bool create_directory(const std::filesystem::path& directory); + bool directory_exists(const std::filesystem::path& directory); + bool directory_is_empty(const std::filesystem::path& directory); + std::vector list_files(const std::filesystem::path& directory); void copy_folder(const std::filesystem::path& src, const std::filesystem::path& target); } diff --git a/src/common/utils/nt.cpp b/src/common/utils/nt.cpp index 671de23a..fa890e52 100644 --- a/src/common/utils/nt.cpp +++ b/src/common/utils/nt.cpp @@ -121,28 +121,28 @@ namespace utils::nt std::string library::get_name() const { - if (!this->is_valid()) return ""; + if (!this->is_valid()) return {}; - auto path = this->get_path(); - const auto pos = path.find_last_of("/\\"); - if (pos == std::string::npos) return path; + const auto path = this->get_path(); + const auto pos = path.generic_string().find_last_of("/\\"); + if (pos == std::string::npos) return path.generic_string(); - return path.substr(pos + 1); + return path.generic_string().substr(pos + 1); } - std::string library::get_path() const + std::filesystem::path library::get_path() const { - if (!this->is_valid()) return ""; + if (!this->is_valid()) return {}; - char name[MAX_PATH] = {0}; - GetModuleFileNameA(this->module_, name, sizeof name); + wchar_t name[MAX_PATH] = {0}; + GetModuleFileNameW(this->module_, name, MAX_PATH); - return name; + return {name}; } - std::string library::get_folder() const + std::filesystem::path library::get_folder() const { - if (!this->is_valid()) return ""; + if (!this->is_valid()) return {}; const auto path = std::filesystem::path(this->get_path()); return path.parent_path().generic_string(); @@ -265,7 +265,7 @@ namespace utils::nt GetCurrentDirectoryA(sizeof(current_dir), current_dir); auto* const command_line = GetCommandLineA(); - CreateProcessA(self.get_path().data(), command_line, nullptr, nullptr, false, NULL, nullptr, current_dir, + CreateProcessA(self.get_path().generic_string().data(), command_line, nullptr, nullptr, false, NULL, nullptr, current_dir, &startup_info, &process_info); if (process_info.hThread && process_info.hThread != INVALID_HANDLE_VALUE) CloseHandle(process_info.hThread); diff --git a/src/common/utils/nt.hpp b/src/common/utils/nt.hpp index 27b7df8d..71222007 100644 --- a/src/common/utils/nt.hpp +++ b/src/common/utils/nt.hpp @@ -41,27 +41,27 @@ namespace utils::nt operator HMODULE() const; void unprotect() const; - void* get_entry_point() const; - size_t get_relative_entry_point() const; + [[nodiscard]] void* get_entry_point() const; + [[nodiscard]] 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]] bool is_valid() const; + [[nodiscard]] std::string get_name() const; + [[nodiscard]] std::filesystem::path get_path() const; + [[nodiscard]] std::filesystem::path 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 + [[nodiscard]] T get_proc(const std::string& process) const { if (!this->is_valid()) T{}; return reinterpret_cast(GetProcAddress(this->module_, process.data())); } template - std::function get(const std::string& process) const + [[nodiscard]] std::function get(const std::string& process) const { if (!this->is_valid()) return std::function(); return static_cast(this->get_proc(process)); @@ -91,13 +91,13 @@ namespace utils::nt 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 653ecff2..3313eca9 100644 --- a/src/common/utils/string.cpp +++ b/src/common/utils/string.cpp @@ -36,9 +36,9 @@ namespace utils::string std::string to_lower(std::string text) { - std::transform(text.begin(), text.end(), text.begin(), [](const char input) + std::transform(text.begin(), text.end(), text.begin(), [](const unsigned char input) { - return static_cast(tolower(input)); + return static_cast(std::tolower(input)); }); return text; @@ -46,9 +46,9 @@ namespace utils::string std::string to_upper(std::string text) { - std::transform(text.begin(), text.end(), text.begin(), [](const char input) + std::transform(text.begin(), text.end(), text.begin(), [](const unsigned char input) { - return static_cast(toupper(input)); + return static_cast(std::toupper(input)); }); return text; @@ -105,12 +105,12 @@ namespace utils::string 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); @@ -128,11 +128,10 @@ namespace utils::string ++in; } + *out = '\0'; } -#pragma warning(push) -#pragma warning(disable: 4100) std::string convert(const std::wstring& wstr) { std::string result; @@ -158,7 +157,6 @@ namespace utils::string return result; } -#pragma warning(pop) std::string replace(std::string str, const std::string& from, const std::string& to) { diff --git a/src/common/utils/string.hpp b/src/common/utils/string.hpp index 04042cb9..8bdfe5c9 100644 --- a/src/common/utils/string.hpp +++ b/src/common/utils/string.hpp @@ -91,7 +91,7 @@ namespace utils::string 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);