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 14, 2024
1 parent 8cf226d commit 31695c5
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 11 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 @@ -172,7 +172,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 All @@ -196,6 +195,7 @@ find_package(STDUUID CONFIG REQUIRED)
find_package(pugixml CONFIG REQUIRED)
find_package(ZLIB REQUIRED)
find_package(httplib CONFIG REQUIRED)
find_package(DiscordRPC QUIET)
if(APPLE)
# Required for Physfs
find_library(FOUNDATION Foundation REQUIRED)
Expand All @@ -210,6 +210,10 @@ endif(WIN32)
if(NOT OPENSSL_FOUND)
find_package(GMP REQUIRED)
endif()
if(DISCORDRPC_FOUND AND NOT ANDROID)
# Enable Discord Rich Presence if available, but don't require it
add_definitions(-DENABLE_DISCORD_RPC)
endif()
if(TOGGLE_DIRECTX)
find_package(DirectX REQUIRED)
endif()
Expand Down Expand Up @@ -586,6 +590,9 @@ else() # Linux
endif()

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

# *****************************************************************************
# Enable otclient console only for debug build
Expand Down
3 changes: 0 additions & 3 deletions src/framework/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@
#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
#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
#ifdef ENABLE_DISCORD_RPC
#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
#ifdef ENABLE_DISCORD_RPC
#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
#ifdef ENABLE_DISCORD_RPC
#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
#ifdef ENABLE_DISCORD_RPC
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 31695c5

Please sign in to comment.