Skip to content

Commit

Permalink
Fetch discord-rpc from repository and compile on clang
Browse files Browse the repository at this point in the history
  • Loading branch information
Sirius902 committed Oct 23, 2023
1 parent 3dc9e1f commit 9bc3b77
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 133 deletions.
35 changes: 26 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
26 changes: 0 additions & 26 deletions external/include/discord/discord_register.h

This file was deleted.

87 changes: 0 additions & 87 deletions external/include/discord/discord_rpc.h

This file was deleted.

Binary file removed external/lib/discord-rpc.lib
Binary file not shown.
5 changes: 3 additions & 2 deletions src/LuaBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <crcpp/CRC.h>

#include <string>
#include <utility>

namespace fs = std::filesystem;
Expand All @@ -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());
}
Expand Down Expand Up @@ -122,7 +123,7 @@ void LuaBackend::LoadScripts(const std::vector<fs::path>& 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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/lua_exec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 3 additions & 8 deletions src/main_dll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ bool hookGame() {

constexpr static auto frameProcOffsets =
std::to_array<std::uintptr_t>({0x3E8, 0x0, 0x20});
constexpr static auto graphicsProcOffsets =
std::to_array<std::uintptr_t>({0x2D8});

std::uintptr_t pointerStruct = moduleAddress + gameInfo->pointerStructOffset;

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

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 9bc3b77

Please sign in to comment.