Merge pull request #81 from diamante0018/main

refactor(cmd): add support for cmds + cleanup
This commit is contained in:
Maurice Heumann 2022-11-21 19:44:37 +01:00 committed by GitHub
commit 2dad3b4851
25 changed files with 94 additions and 88 deletions

View File

@ -39,7 +39,7 @@ jobs:
uses: microsoft/setup-msbuild@v1.1.3
- name: Generate project files
run: tools/premake5 vs2022 --ci-build
run: tools/premake5 vs2022
- name: Set up problem matching
uses: ammaraskar/msvc-problem-matcher@master

View File

@ -77,11 +77,6 @@ newoption {
description = "Enable development builds of the client."
}
newoption {
trigger = "ci-build",
description = "Enable CI builds of the client."
}
newaction {
trigger = "version",
description = "Returns the version string for the current commit of the source code.",
@ -249,7 +244,7 @@ workspace "boiii"
defines {"DEV_BUILD"}
end
if _OPTIONS["ci-build"] then
if os.getenv("CI") then
defines {"CI"}
end
@ -262,7 +257,7 @@ workspace "boiii"
filter "configurations:Release"
optimize "Size"
buildoptions {"/GL"}
linkoptions { "/IGNORE:4702", "/LTCG" }
linkoptions {"/IGNORE:4702", "/LTCG"}
defines {"NDEBUG"}
flags {"FatalCompileWarnings"}
filter {}

View File

@ -77,7 +77,7 @@ namespace branding
std::string str = "BOIII: " VERSION;
//str += "\n\n" + get_connectivity_info();
game::R_AddCmdDrawText(str.data(), 0x7FFFFFFF, font, static_cast<float>(x),
game::R_AddCmdDrawText(str.data(), std::numeric_limits<int>::max(), font, static_cast<float>(x),
y + static_cast<float>(font[2]) * scale,
scale, scale, 0.0f, color, game::ITEM_TEXTSTYLE_NORMAL);
}

View File

@ -1,5 +1,4 @@
#include <std_include.hpp>
#include "network.hpp"
#include "loader/component_loader.hpp"
#include "scheduler.hpp"
@ -9,6 +8,8 @@
#include <utils/string.hpp>
#include <utils/finally.hpp>
#include "network.hpp"
namespace network
{
namespace

View File

@ -1,5 +1,4 @@
#pragma once
#include "game/game.hpp"
namespace network
{

View File

@ -1,11 +1,11 @@
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"
#include "steam/steam.hpp"
#include "party.hpp"
#include "network.hpp"
#include "scheduler.hpp"
#include "game/game.hpp"
#include "steam/steam.hpp"
#include <utils/hook.hpp>
#include <utils/string.hpp>

View File

@ -1,6 +1,4 @@
#pragma once
#include <game/game.hpp>
#include <utils/info_string.hpp>
namespace party

View File

@ -5,7 +5,6 @@
#include "game/game.hpp"
#include <cassert>
#include <utils/hook.hpp>
#include <utils/concurrency.hpp>
#include <utils/thread.hpp>

View File

@ -1,5 +1,6 @@
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "splash.hpp"
#include "resource.hpp"

View File

@ -1,7 +1,5 @@
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "steam_proxy.hpp"
#include "scheduler.hpp"
#include <utils/nt.hpp>
#include <utils/flags.hpp>
@ -12,6 +10,9 @@
#include "steam/interface.hpp"
#include "steam/steam.hpp"
#include "steam_proxy.hpp"
#include "scheduler.hpp"
namespace steam_proxy
{
namespace
@ -152,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
@ -161,7 +162,7 @@ namespace steam_proxy
const auto* mod_id = "bo3";
game_id.raw.mod_id = *reinterpret_cast<const unsigned int*>(mod_id) | 0x80000000;
client_user.invoke<bool>("SpawnProcess", path.data(), cmdline.data(), our_directory,
client_user.invoke<bool>("SpawnProcess", path.generic_string().data(), cmdline, our_directory,
&game_id.bits, title.data(), 0, 0, 0);
return ownership_state::success;

View File

@ -1,5 +1,4 @@
#pragma once
#include <utils/nt.hpp>
namespace steam_proxy
{

View File

@ -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()

View File

@ -6,8 +6,7 @@
namespace game
{
#define Com_Error(code, fmt, ...) \
Com_Error_(__FILE__, __LINE__, code, fmt, ##__VA_ARGS__)
#define Com_Error(code, fmt, ...) Com_Error_(__FILE__, __LINE__, code, fmt, ##__VA_ARGS__)
// CL
WEAK symbol<void(int controllerIndex, XSESSION_INFO* hostInfo, const netadr_t* addr, int numPublicSlots,
@ -85,6 +84,14 @@ namespace game
// Global game definitions
constexpr auto CMD_MAX_NESTING = 8;
// Reimplementations
struct cmd_args_t
{
CmdArgs* operator->() const
{
return Sys_GetTLS()->cmdArgs;
}
};
// Re-implementations
eModes Com_SessionMode_GetMode();
}

View File

@ -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()

View File

@ -85,7 +85,7 @@
#include <asmjit/x86/x86assembler.h>
#define RAPIDJSON_NOEXCEPT
#define RAPIDJSON_ASSERT(cond) if(cond); else throw std::runtime_error("rapidjson assert fail");
#define RAPIDJSON_ASSERT(cond) if (cond); else throw std::runtime_error("rapidjson assert fail");
#include <rapidjson/document.h>
#include <rapidjson/prettywriter.h>

View File

@ -1,8 +1,9 @@
#include <std_include.hpp>
#include "../steam.hpp"
#include "component/steam_proxy.hpp"
//#include <game/game.hpp>
#include <utils/nt.hpp>
#include "component/steam_proxy.hpp"
namespace steam
{

View File

@ -1,8 +1,12 @@
#include <std_include.hpp>
#include "../steam.hpp"
#include "game/game.hpp"
#include "component/party.hpp"
#include "component/network.hpp"
#include "utils/string.hpp"
#include <utils/string.hpp>
namespace steam
{

View File

@ -1,5 +1,8 @@
#include <std_include.hpp>
#include "../steam.hpp"
#include <utils/nt.hpp>
#include "component/steam_proxy.hpp"
namespace steam

View File

@ -32,7 +32,7 @@ namespace utils
return value->second;
}
return "";
return {};
}
void info_string::parse(std::string buffer)

View File

@ -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<std::streamsize>(data.size()));
stream.close();
return true;
}
@ -68,8 +68,8 @@ namespace utils::io
if (size > -1)
{
data->resize(static_cast<uint32_t>(size));
stream.read(const_cast<char*>(data->data()), size);
data->resize(static_cast<std::uint32_t>(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<size_t>(stream.tellg());
return static_cast<std::size_t>(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<std::string> list_files(const std::string& directory)
std::vector<std::string> list_files(const std::filesystem::path& directory)
{
std::vector<std::string> files;

View File

@ -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<std::string> 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<std::string> list_files(const std::filesystem::path& directory);
void copy_folder(const std::filesystem::path& src, const std::filesystem::path& target);
}

View File

@ -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);

View File

@ -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 <typename T>
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<T>(GetProcAddress(this->module_, process.data()));
}
template <typename T>
std::function<T> get(const std::string& process) const
[[nodiscard]] std::function<T> get(const std::string& process) const
{
if (!this->is_valid()) return std::function<T>();
return static_cast<T*>(this->get_proc<void*>(process));
@ -91,13 +91,13 @@ namespace utils::nt
return T();
}
std::vector<PIMAGE_SECTION_HEADER> get_section_headers() const;
[[nodiscard]] std::vector<PIMAGE_SECTION_HEADER> 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_;

View File

@ -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<char>(tolower(input));
return static_cast<char>(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<char>(toupper(input));
return static_cast<char>(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)
{

View File

@ -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);