fix discord rpc

This commit is contained in:
delledev 2024-09-30 14:30:55 +03:00
commit 39b98fcfda
10 changed files with 54 additions and 16 deletions

View file

@ -361,6 +361,8 @@ set(COMMON src/common/logging/backend.cpp
src/common/debug.h src/common/debug.h
src/common/decoder.cpp src/common/decoder.cpp
src/common/decoder.h src/common/decoder.h
src/common/discord.h
src/common/discord.cpp
src/common/elf_info.h src/common/elf_info.h
src/common/endian.h src/common/endian.h
src/common/enum.h src/common/enum.h
@ -839,3 +841,8 @@ if (UNIX AND NOT APPLE)
target_link_libraries(shadps4 PRIVATE ${OPENSSL_LIBRARIES}) target_link_libraries(shadps4 PRIVATE ${OPENSSL_LIBRARIES})
endif() endif()
endif() endif()
#Discord Lib
add_subdirectory(externals/discord-rpc)
target_link_libraries(shadps4 PRIVATE discord-rpc)
include_directories(externals/discord-rpc/include)

View file

@ -6,7 +6,7 @@
"configurationType": "Release", "configurationType": "Release",
"buildRoot": "${projectDir}\\Build\\${name}", "buildRoot": "${projectDir}\\Build\\${name}",
"installRoot": "${projectDir}\\Install\\${name}", "installRoot": "${projectDir}\\Install\\${name}",
"cmakeCommandArgs": "", "cmakeCommandArgs": "-DENABLE_QT_GUI=ON -DCMAKE_PREFIX_PATH=C:\\Qt\\6.7.3\\msvc2019_64",
"buildCommandArgs": "", "buildCommandArgs": "",
"ctestCommandArgs": "", "ctestCommandArgs": "",
"inheritEnvironments": [ "clang_cl_x64_x64" ], "inheritEnvironments": [ "clang_cl_x64_x64" ],

View file

@ -183,3 +183,4 @@ add_subdirectory(tracy)
if (NOT TARGET pugixml::pugixml) if (NOT TARGET pugixml::pugixml)
add_subdirectory(pugixml) add_subdirectory(pugixml)
endif() endif()

1
externals/discord-rpc vendored Submodule

@ -0,0 +1 @@
Subproject commit 963aa9f3e5ce81a4682c6ca3d136cddda614db33

View file

@ -4,30 +4,43 @@
#include <cstring> #include <cstring>
#include <ctime> #include <ctime>
#include "common/discord.h" #include "common/discord.h"
#include "logging/log.h"
#include "common/debug.h"
namespace Discord { namespace Discord {
void RPC::init() { void RPC::init() {
DiscordEventHandlers handlers{}; DiscordEventHandlers handlers{};
Discord_Initialize("1139939140494971051", &handlers, 1, nullptr); std::string discordAppId = "1290207945476280360";
Discord_Initialize(discordAppId.c_str(), &handlers, 1, nullptr);
LOG_INFO(Loader, "Discord RPC Initalized with App Id: {}", discordAppId);
startTimestamp = time(nullptr); startTimestamp = time(nullptr);
enabled = true; enabled = true;
} }
void RPC::update(Discord::RPCStatus status, const std::string& game) { void RPC::updatePlaying(const std::string& game, const std::string& game_id) {
DiscordRichPresence rpc{}; DiscordRichPresence rpc{};
if (status == Discord::RPCStatus::Playing) {
rpc.details = "Playing a game"; rpc.details = "Playing a game";
rpc.state = game.c_str(); rpc.state = game.c_str();
} else { std::string largeImageUrl =
rpc.details = "Idle"; "https://store.playstation.com/store/api/chihiro/00_09_000/titlecontainer/US/en/999/" +
game_id + "_00/image";
rpc.largeImageKey = largeImageUrl.c_str();
rpc.largeImageText = game.c_str();
rpc.startTimestamp = startTimestamp;
LOG_INFO(Loader, "Found game. Name: {}, Id: {}", game.c_str(), game_id.c_str());
Discord_UpdatePresence(&rpc);
} }
void RPC::updateIdle() {
DiscordRichPresence rpc{};
rpc.largeImageKey = "shadps4"; rpc.largeImageKey = "shadps4";
rpc.largeImageText = "ShadPS4 is a PS4 emulator"; rpc.largeImageText = "ShadPS4 is a PS4 emulator";
rpc.startTimestamp = startTimestamp; rpc.startTimestamp = startTimestamp;
rpc.details = "Idle";
Discord_UpdatePresence(&rpc); Discord_UpdatePresence(&rpc);
} }

View file

@ -20,7 +20,8 @@ class RPC {
public: public:
void init(); void init();
void update(RPCStatus status, const std::string& title); void updatePlaying(const std::string& title, const std::string& game_id);
void updateIdle();
void stop(); void stop();
}; };

View file

@ -34,6 +34,7 @@
#include "core/memory.h" #include "core/memory.h"
#include "emulator.h" #include "emulator.h"
#include "video_core/renderdoc.h" #include "video_core/renderdoc.h"
#include "common/discord.h"
Frontend::WindowSDL* g_window = nullptr; Frontend::WindowSDL* g_window = nullptr;
@ -210,6 +211,11 @@ void Emulator::Run(const std::filesystem::path& file) {
} }
} }
//Discord RPC
Discord::RPC rpc;
/*rpc.init();*/
rpc.updatePlaying(game_info.title, id);
// start execution // start execution
std::jthread mainthread = std::jthread mainthread =
std::jthread([this](std::stop_token stop_token) { linker->Execute(); }); std::jthread([this](std::stop_token stop_token) { linker->Execute(); });

View file

@ -7,6 +7,7 @@
#include "emulator.h" #include "emulator.h"
#include "game_install_dialog.h" #include "game_install_dialog.h"
#include "main_window.h" #include "main_window.h"
#include "common/discord.h"
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
@ -55,6 +56,11 @@ int main(int argc, char* argv[]) {
emulator.Run(argv[1]); emulator.Run(argv[1]);
} }
//Initialize Discord RPC
Discord::RPC rpc;
rpc.init();
rpc.updateIdle();
// Run the Qt application // Run the Qt application
return a.exec(); return a.exec();
} }

View file

@ -13,6 +13,7 @@
#include "input/controller.h" #include "input/controller.h"
#include "sdl_window.h" #include "sdl_window.h"
#include "video_core/renderdoc.h" #include "video_core/renderdoc.h"
#include "common/discord.h"
#ifdef __APPLE__ #ifdef __APPLE__
#include <SDL3/SDL_metal.h> #include <SDL3/SDL_metal.h>
@ -73,7 +74,7 @@ WindowSDL::WindowSDL(s32 width_, s32 height_, Input::GameController* controller_
} }
WindowSDL::~WindowSDL() = default; WindowSDL::~WindowSDL() = default;
Discord::RPC rpc;
void WindowSDL::waitEvent() { void WindowSDL::waitEvent() {
// Called on main thread // Called on main thread
SDL_Event event; SDL_Event event;
@ -112,6 +113,8 @@ void WindowSDL::waitEvent() {
onGamepadEvent(&event); onGamepadEvent(&event);
break; break;
case SDL_EVENT_QUIT: case SDL_EVENT_QUIT:
rpc.init();
rpc.updateIdle();
is_open = false; is_open = false;
break; break;
default: default: