diff --git a/.gitmodules b/.gitmodules index 532659db..0fc17065 100644 --- a/.gitmodules +++ b/.gitmodules @@ -26,3 +26,6 @@ path = third-party/winpthread url = https://github.com/shadps4/winpthread.git branch = main +[submodule "third-party/discord-rpc"] + path = third-party/discord-rpc + url = https://github.com/discord/discord-rpc diff --git a/CMakeLists.txt b/CMakeLists.txt index 2cdaf46c..cc084d30 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,7 @@ endif() project(shadps4) include_directories(third-party/) +include_directories(third-party/discord-rpc/include) include_directories(third-party/imgui/) include_directories(third-party/imgui/backends) include_directories(third-party/sdl/) @@ -43,6 +44,8 @@ add_executable(shadps4 src/Util/string_util.cpp src/Core/PS4/HLE/Graphics/video_out.cpp src/Core/PS4/HLE/Graphics/video_out.h + src/discord.h + src/discord.cpp "src/Util/Singleton.h" "src/Util/Disassembler.cpp" "src/Util/Disassembler.h" "src/Core/PS4/Util/aerolib.h" "src/Core/PS4/Loader/SymbolsResolver.h" "src/Core/PS4/Loader/SymbolsResolver.cpp" "src/Core/PS4/HLE/Libs.cpp" "src/Core/PS4/HLE/Libs.h" "src/Core/PS4/HLE/LibC.cpp" "src/Core/PS4/HLE/LibC.h" "src/Lib/Timer.cpp" "src/Lib/Timer.h" "src/Core/PS4/HLE/LibKernel.cpp" "src/Core/PS4/HLE/LibKernel.h" "src/Core/PS4/HLE/LibSceVideoOut.cpp" "src/Core/PS4/HLE/LibSceVideoOut.h" "src/Core/PS4/HLE/LibSceGnmDriver.cpp" "src/Core/PS4/HLE/LibSceGnmDriver.h" "src/Core/PS4/HLE/Kernel/ThreadManagement.cpp" "src/Core/PS4/HLE/Kernel/ThreadManagement.h" "src/Core/PS4/HLE/ErrorCodes.h" "src/debug.h" "src/Core/PS4/HLE/Kernel/memory_management.cpp" "src/Core/PS4/HLE/Kernel/memory_management.h" "src/Core/PS4/GPU/gpu_memory.cpp" "src/Core/PS4/GPU/gpu_memory.h" "src/emulator.cpp" "src/emulator.h") find_package(OpenGL REQUIRED) diff --git a/src/discord.cpp b/src/discord.cpp new file mode 100644 index 00000000..219becc7 --- /dev/null +++ b/src/discord.cpp @@ -0,0 +1,37 @@ +#include "discord.h" + +#include +#include + +void Discord::RPC::init() { + DiscordEventHandlers handlers{}; + Discord_Initialize("1138176975865909360", &handlers, 1, nullptr); + + startTimestamp = time(nullptr); + enabled = true; +} + +void Discord::RPC::update(Discord::RPCStatus status, const std::string& game) { + DiscordRichPresence rpc{}; + + if (status == Discord::RPCStatus::Playing) { + rpc.details = "Playing a game"; + rpc.state = game.c_str(); + } else { + rpc.details = "Idle"; + } + + rpc.largeImageKey = "pand"; + rpc.largeImageText = "ShadPS4 is a PS4 emulator"; + rpc.startTimestamp = startTimestamp; + + Discord_UpdatePresence(&rpc); +} + +void Discord::RPC::stop() { + if (enabled) { + enabled = false; + Discord_ClearPresence(); + Discord_Shutdown(); + } +} diff --git a/src/discord.h b/src/discord.h new file mode 100644 index 00000000..ca888018 --- /dev/null +++ b/src/discord.h @@ -0,0 +1,19 @@ +#pragma once + +#include +#include +#include + +namespace Discord { + enum class RPCStatus { Idling, Playing }; + + class RPC { + std::uint64_t startTimestamp; + bool enabled = false; + + public: + void init(); + void update(RPCStatus status, const std::string& title); + void stop(); + }; +} // namespace Discord \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 7ce1f129..db5a9043 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -31,6 +31,7 @@ #include "Core/PS4/HLE/Libs.h" #include "Lib/Threads.h" #include +#include "discord.h" // Main code int main(int argc, char* argv[]) @@ -59,6 +60,10 @@ int main(int argc, char* argv[]) Emulator::emuRun(); mainthread.JoinThread(); + Discord::RPC discordRPC; + discordRPC.init(); + discordRPC.update(Discord::RPCStatus::Idling, ""); + #if 0 // Setup SDL if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMEPAD) != 0) @@ -240,5 +245,6 @@ int main(int argc, char* argv[]) SDL_Quit(); #endif + discordRPC.stop(); return 0; } diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index 048fae86..7baa9562 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -29,6 +29,8 @@ add_subdirectory(${zydis_DIR}) #========== winpthreads ====================== add_subdirectory(winpthread) +#=================== discord-rpc =================== +add_subdirectory(discord-rpc) #=================== IMGUI =================== set(IMGUI_DIR ${CMAKE_CURRENT_SOURCE_DIR}/imgui) @@ -58,6 +60,6 @@ find_package(OpenGL REQUIRED) target_link_libraries(IMGUI PUBLIC ${OPENGL_LIBRARIES}) -target_link_libraries(IMGUI PUBLIC SDL3-shared ${CMAKE_DL_LIBS} Zydis winpthread) +target_link_libraries(IMGUI PUBLIC SDL3-shared ${CMAKE_DL_LIBS} Zydis winpthread discord-rpc) diff --git a/third-party/discord-rpc b/third-party/discord-rpc new file mode 160000 index 00000000..963aa9f3 --- /dev/null +++ b/third-party/discord-rpc @@ -0,0 +1 @@ +Subproject commit 963aa9f3e5ce81a4682c6ca3d136cddda614db33