mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2024-12-29 11:06:07 +00:00
Add discord RPC
This commit is contained in:
parent
16e2768df0
commit
f2b64e892b
|
@ -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)
|
||||
|
|
37
src/discord.cpp
Normal file
37
src/discord.cpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
#include "discord.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
19
src/discord.h
Normal file
19
src/discord.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
#pragma once
|
||||
|
||||
#include <discord_rpc.h>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
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
|
|
@ -31,6 +31,7 @@
|
|||
#include "Core/PS4/HLE/Libs.h"
|
||||
#include "Lib/Threads.h"
|
||||
#include <emulator.h>
|
||||
#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;
|
||||
}
|
||||
|
|
4
third-party/CMakeLists.txt
vendored
4
third-party/CMakeLists.txt
vendored
|
@ -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)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue