Skip to content

Commit

Permalink
fix: discord-rpc in cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
surfaceflinger committed Oct 16, 2024
1 parent 8cf226d commit 968d52d
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,11 @@ Beyond of it's flexibility with scripts, otclient comes with tons of other featu


- <details>
<summary>Support Discord RPC by @SkullzOTS (Doesn't work with CMAKE)</summary>
<summary>Support Discord RPC by @SkullzOTS</summary>

- by [@SkullzOTS](https://github.com/SkullzOTS)

- To enable just go to [config.h](https://github.com/mehah/otclient/blob/main/src/framework/config.h#L43), set 1 in ENABLE_DISCORD_RPC and configure the others definitions
- To enable just make discord-rpc available and go to [config.h](https://github.com/mehah/otclient/blob/main/src/framework/config.h#L43) to optionally configure the other definitions

- You can see the step by step in [YouTube](https://www.youtube.com/watch?v=zCHYtRlD58g)

Expand Down
16 changes: 16 additions & 0 deletions cmake/FindDiscordRPC.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Try to find the DISCORDRPC library
# DISCORDRPC_FOUND - system has DISCORDRPC
# DISCORDRPC_INCLUDE_DIR - the DISCORDRPC include directory
# DISCORDRPC_LIBRARY - the DISCORDRPC library

FIND_PATH(DISCORDRPC_INCLUDE_DIR NAMES discord_rpc.h)
SET(_DISCORDRPC_STATIC_LIBS discord-rpc.lib libdiscord-rpc.a)
SET(_DISCORDRPC_SHARED_LIBS discord-rpc.lib libdiscord-rpc.dylib libdiscord-rpc.so)
IF(USE_STATIC_LIBS)
FIND_LIBRARY(DISCORDRPC_LIBRARY NAMES ${_DISCORDRPC_STATIC_LIBS} ${_DISCORDRPC_SHARED_LIBS})
ELSE()
FIND_LIBRARY(DISCORDRPC_LIBRARY NAMES ${_DISCORDRPC_SHARED_LIBS} ${_DISCORDRPC_STATIC_LIBS})
ENDIF()
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(DiscordRPC DEFAULT_MSG DISCORDRPC_LIBRARY DISCORDRPC_INCLUDE_DIR)
MARK_AS_ADVANCED(DISCORDRPC_LIBRARY DISCORDRPC_INCLUDE_DIR)
9 changes: 8 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ option(TOGGLE_FRAMEWORK_XML "Use XML " ON)
option(TOGGLE_FRAMEWORK_NET "Use NET " ON)
option(TOGGLE_FRAMEWORK_EDITOR "Use Editor " OFF)
option(TOGGLE_DIRECTX "Use DX9 support" OFF)
option(TOGGLE_DISCORD_RPC "Use Discord Rich Presence" OFF)
option(TOGGLE_BIN_FOLDER "Use build/bin folder for generate compilation files" OFF)
option(TOGGLE_BOT_PROTECTION "Use bot protection" ON)
option(DEBUG_LOG "Enable Debug Log" OFF)
Expand Down Expand Up @@ -172,7 +173,6 @@ endif(TOGGLE_BOT_PROTECTION)
add_definitions(-D_WIN32_WINNT=0x0501)
add_definitions(${FRAMEWORK_DEFINITIONS})
add_definitions(-D"VERSION=${VERSION}")

# === Build options ===
message(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
add_definitions(-D"BUILD_TYPE=\\\"${CMAKE_BUILD_TYPE}\\\"")
Expand Down Expand Up @@ -210,6 +210,10 @@ endif(WIN32)
if(NOT OPENSSL_FOUND)
find_package(GMP REQUIRED)
endif()
if(TOGGLE_DISCORD_RPC AND NOT ANDROID)
find_package(DiscordRPC REQUIRED)
add_compile_definitions(-DTOGGLE_DISCORD_RPC=1)
endif()
if(TOGGLE_DIRECTX)
find_package(DirectX REQUIRED)
endif()
Expand Down Expand Up @@ -586,6 +590,9 @@ else() # Linux
endif()

endif()
if(TOGGLE_DISCORD_RPC AND NOT ANDROID)
target_link_libraries(${PROJECT_NAME} PRIVATE ${DISCORDRPC_LIBRARY})
endif()

# *****************************************************************************
# Enable otclient console only for debug build
Expand Down
5 changes: 3 additions & 2 deletions src/framework/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@
#define ENCRYPTION_HEADER "SET_YOUR_HEADER_HERE"

// DISCORD RPC (https://discord.com/developers/applications)
// Note: Only for VSSolution, doesn't work with CMAKE
// Enable Discord Rich Presence
#define ENABLE_DISCORD_RPC 0 // 1 to enable | 0 to disable
#ifndef TOGGLE_DISCORD_RPC
#define TOGGLE_DISCORD_RPC 0 // 1 to enable | 0 to disable
#endif
#define RPC_API_KEY "1060650448522051664" // Your API Key
// RPC Configs (https://youtu.be/zCHYtRlD58g) step by step to config your rich presence
#define SHOW_CHARACTER_NAME_RPC 1 // 1 to enable | 0 to disable
Expand Down
2 changes: 1 addition & 1 deletion src/framework/discord/discord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "discord.h"

#ifndef ANDROID
#if ENABLE_DISCORD_RPC == 1
#if TOGGLE_DISCORD_RPC == 1
#include <framework/core/eventdispatcher.h>
#include <time.h>

Expand Down
2 changes: 1 addition & 1 deletion src/framework/discord/discord.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <string>

#ifndef ANDROID
#if ENABLE_DISCORD_RPC == 1
#if TOGGLE_DISCORD_RPC == 1
#include <discord_register.h>
#include <discord_rpc.h>

Expand Down
6 changes: 3 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <framework/luaengine/luainterface.h>

#ifndef ANDROID
#if ENABLE_DISCORD_RPC == 1
#if TOGGLE_DISCORD_RPC == 1
#include <framework/discord/discord.h>
#endif
#endif
Expand Down Expand Up @@ -79,7 +79,7 @@ extern "C" {
g_logger.fatal("Unable to find work directory, the application cannot be initialized.");

#ifndef ANDROID
#if ENABLE_DISCORD_RPC == 1
#if TOGGLE_DISCORD_RPC == 1
std::function<bool()> canUpdate = []() -> bool { return g_game.isOnline(); };
std::function<void(std::string&)> onUpdate = [](std::string& info) {
#if SHOW_CHARACTER_NAME_RPC == 1
Expand Down Expand Up @@ -124,4 +124,4 @@ extern "C" {
}
#ifdef ANDROID
}
#endif
#endif

0 comments on commit 968d52d

Please sign in to comment.