diff --git a/CMakeLists.txt b/CMakeLists.txt index a0c37f3..5418b05 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,13 +31,18 @@ FetchContent_Declare(tomlplusplus GIT_SHALLOW ON GIT_TAG master) -FetchContent_MakeAvailable(ztd.text wil tomlplusplus) +# Disable DiscordRPC from running clang-format to work around issue with +# its .clang-format file. +set(CLANG_FORMAT_CMD "") -add_subdirectory(external/subproject/lua544) +FetchContent_Declare(DiscordRPC + GIT_REPOSITORY https://github.com/discord/discord-rpc.git + GIT_SHALLOW ON + GIT_TAG master) -if(NOT MSVC) - message(FATAL_ERROR "LuaBackendHook must be built using MSVC.") -endif() +FetchContent_MakeAvailable(ztd.text wil tomlplusplus DiscordRPC) + +add_subdirectory(external/subproject/lua544) set(SOURCE src/main_dll.cpp @@ -75,21 +80,33 @@ add_custom_target(build-info add_library(DBGHELP SHARED ${SOURCE}) add_dependencies(DBGHELP build-info) -target_compile_options(DBGHELP PRIVATE /W4) +if(MSVC) + target_compile_options(DBGHELP PRIVATE /W4) +else() + target_compile_options(DBGHELP PRIVATE + -g + -Wall + -Werror + -Wextra + -Wpedantic + -Wno-language-extension-token + -Wno-gnu-zero-variadic-macro-arguments + ) +endif() + target_compile_definitions(DBGHELP PRIVATE -DUNICODE -D_UNICODE) target_include_directories(DBGHELP PRIVATE external/include external/subproject/lua544 - external/include/discord + ${DiscordRPC_SOURCE_DIR}/include ${CMAKE_CURRENT_BINARY_DIR} ) -target_link_directories(DBGHELP PRIVATE external/lib) target_link_libraries(DBGHELP PRIVATE ztd::text WIL tomlplusplus::tomlplusplus lua54 - discord-rpc.lib + discord-rpc ) unset(PROGRAM_VERSION CACHE) diff --git a/external/include/discord/discord_register.h b/external/include/discord/discord_register.h deleted file mode 100644 index 16fb42f..0000000 --- a/external/include/discord/discord_register.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#if defined(DISCORD_DYNAMIC_LIB) -#if defined(_WIN32) -#if defined(DISCORD_BUILDING_SDK) -#define DISCORD_EXPORT __declspec(dllexport) -#else -#define DISCORD_EXPORT __declspec(dllimport) -#endif -#else -#define DISCORD_EXPORT __attribute__((visibility("default"))) -#endif -#else -#define DISCORD_EXPORT -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -DISCORD_EXPORT void Discord_Register(const char* applicationId, const char* command); -DISCORD_EXPORT void Discord_RegisterSteamGame(const char* applicationId, const char* steamId); - -#ifdef __cplusplus -} -#endif diff --git a/external/include/discord/discord_rpc.h b/external/include/discord/discord_rpc.h deleted file mode 100644 index 3e1441e..0000000 --- a/external/include/discord/discord_rpc.h +++ /dev/null @@ -1,87 +0,0 @@ -#pragma once -#include - -// clang-format off - -#if defined(DISCORD_DYNAMIC_LIB) -# if defined(_WIN32) -# if defined(DISCORD_BUILDING_SDK) -# define DISCORD_EXPORT __declspec(dllexport) -# else -# define DISCORD_EXPORT __declspec(dllimport) -# endif -# else -# define DISCORD_EXPORT __attribute__((visibility("default"))) -# endif -#else -# define DISCORD_EXPORT -#endif - -// clang-format on - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct DiscordRichPresence { - const char* state; /* max 128 bytes */ - const char* details; /* max 128 bytes */ - int64_t startTimestamp; - int64_t endTimestamp; - const char* largeImageKey; /* max 32 bytes */ - const char* largeImageText; /* max 128 bytes */ - const char* smallImageKey; /* max 32 bytes */ - const char* smallImageText; /* max 128 bytes */ - const char* partyId; /* max 128 bytes */ - int partySize; - int partyMax; - const char* matchSecret; /* max 128 bytes */ - const char* joinSecret; /* max 128 bytes */ - const char* spectateSecret; /* max 128 bytes */ - int8_t instance; -} DiscordRichPresence; - -typedef struct DiscordUser { - const char* userId; - const char* username; - const char* discriminator; - const char* avatar; -} DiscordUser; - -typedef struct DiscordEventHandlers { - void (*ready)(const DiscordUser* request); - void (*disconnected)(int errorCode, const char* message); - void (*errored)(int errorCode, const char* message); - void (*joinGame)(const char* joinSecret); - void (*spectateGame)(const char* spectateSecret); - void (*joinRequest)(const DiscordUser* request); -} DiscordEventHandlers; - -#define DISCORD_REPLY_NO 0 -#define DISCORD_REPLY_YES 1 -#define DISCORD_REPLY_IGNORE 2 - -DISCORD_EXPORT void Discord_Initialize(const char* applicationId, - DiscordEventHandlers* handlers, - int autoRegister, - const char* optionalSteamId); -DISCORD_EXPORT void Discord_Shutdown(void); - -/* checks for incoming messages, dispatches callbacks */ -DISCORD_EXPORT void Discord_RunCallbacks(void); - -/* If you disable the lib starting its own io thread, you'll need to call this from your own */ -#ifdef DISCORD_DISABLE_IO_THREAD -DISCORD_EXPORT void Discord_UpdateConnection(void); -#endif - -DISCORD_EXPORT void Discord_UpdatePresence(const DiscordRichPresence* presence); -DISCORD_EXPORT void Discord_ClearPresence(void); - -DISCORD_EXPORT void Discord_Respond(const char* userid, /* DISCORD_REPLY_ */ int reply); - -DISCORD_EXPORT void Discord_UpdateHandlers(DiscordEventHandlers* handlers); - -#ifdef __cplusplus -} /* extern "C" */ -#endif diff --git a/external/lib/discord-rpc.lib b/external/lib/discord-rpc.lib deleted file mode 100644 index 1f3e825..0000000 Binary files a/external/lib/discord-rpc.lib and /dev/null differ diff --git a/src/LuaBackend.cpp b/src/LuaBackend.cpp index 7e812c4..082c855 100644 --- a/src/LuaBackend.cpp +++ b/src/LuaBackend.cpp @@ -2,6 +2,7 @@ #include +#include #include namespace fs = std::filesystem; @@ -18,7 +19,7 @@ int LuaBackend::ExceptionHandle( (void)description; const std::exception _ex = *thrownException; - ConsoleLib::MessageOutput(_ex.what() + '\n', 3); + ConsoleLib::MessageOutput(std::string{_ex.what()} + "\n", 3); return sol::stack::push(luaState, _ex.what()); } @@ -122,7 +123,7 @@ void LuaBackend::LoadScripts(const std::vector& ScriptPaths, loadedScripts.push_back(std::move(_script)); } else { sol::error err = _result; - ConsoleLib::MessageOutput(err.what() + '\n', 3); + ConsoleLib::MessageOutput(std::string{err.what()} + "\n", 3); ConsoleLib::MessageOutput( "Initialization of this script was aborted.\n", 3); } diff --git a/src/lua_exec.cpp b/src/lua_exec.cpp index 640c3b3..969c9a4 100644 --- a/src/lua_exec.cpp +++ b/src/lua_exec.cpp @@ -151,7 +151,7 @@ void ExecuteLUA() { _sClock = std::chrono::high_resolution_clock::now(); } - for (int i = 0; i < _backend->loadedScripts.size(); i++) { + for (std::size_t i = 0; i < _backend->loadedScripts.size(); i++) { auto& _script = _backend->loadedScripts[i]; if (_script->frameFunction) { diff --git a/src/main_dll.cpp b/src/main_dll.cpp index 043fdb1..067964b 100644 --- a/src/main_dll.cpp +++ b/src/main_dll.cpp @@ -102,8 +102,6 @@ bool hookGame() { constexpr static auto frameProcOffsets = std::to_array({0x3E8, 0x0, 0x20}); - constexpr static auto graphicsProcOffsets = - std::to_array({0x2D8}); std::uintptr_t pointerStruct = moduleAddress + gameInfo->pointerStructOffset; @@ -129,9 +127,7 @@ bool hookGame() { return true; } -DWORD WINAPI entry(LPVOID lpParameter) { - (void)lpParameter; - +DWORD WINAPI entry([[maybe_unused]] LPVOID lpParameter) { std::wstring modulePathStr; wil::GetModuleFileNameW(nullptr, modulePathStr); @@ -205,9 +201,8 @@ DWORD WINAPI entry(LPVOID lpParameter) { return 0; } -BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) { - (void)hinstDLL; - (void)lpReserved; +BOOL WINAPI DllMain([[maybe_unused]] HINSTANCE hinstDLL, DWORD fdwReason, + [[maybe_unused]] LPVOID lpReserved) { static HMODULE dbgHelp = nullptr; static HMODULE dinput8 = nullptr;