[App] Add support for Discord rich presence.
This commit is contained in:
parent
e466687f11
commit
ce38e7b0b1
|
@ -40,6 +40,12 @@
|
||||||
[submodule "third_party/volk"]
|
[submodule "third_party/volk"]
|
||||||
path = third_party/volk
|
path = third_party/volk
|
||||||
url = https://github.com/zeux/volk.git
|
url = https://github.com/zeux/volk.git
|
||||||
|
[submodule "third_party/discord-rpc"]
|
||||||
|
path = third_party/discord-rpc
|
||||||
|
url = https://github.com/discordapp/discord-rpc
|
||||||
|
[submodule "third_party/rapidjson"]
|
||||||
|
path = third_party/rapidjson
|
||||||
|
url = https://github.com/Tencent/rapidjson.git
|
||||||
[submodule "third_party/aes_128"]
|
[submodule "third_party/aes_128"]
|
||||||
path = third_party/aes_128
|
path = third_party/aes_128
|
||||||
url = https://github.com/openluopworld/aes_128.git
|
url = https://github.com/openluopworld/aes_128.git
|
||||||
|
|
|
@ -232,6 +232,7 @@ solution("xenia")
|
||||||
-- Include third party files first so they don't have to deal with gflags.
|
-- Include third party files first so they don't have to deal with gflags.
|
||||||
include("third_party/aes_128.lua")
|
include("third_party/aes_128.lua")
|
||||||
include("third_party/capstone.lua")
|
include("third_party/capstone.lua")
|
||||||
|
include("third_party/discord-rpc.lua")
|
||||||
include("third_party/gflags.lua")
|
include("third_party/gflags.lua")
|
||||||
include("third_party/glew.lua")
|
include("third_party/glew.lua")
|
||||||
include("third_party/glslang-spirv.lua")
|
include("third_party/glslang-spirv.lua")
|
||||||
|
@ -246,6 +247,7 @@ solution("xenia")
|
||||||
|
|
||||||
include("src/xenia")
|
include("src/xenia")
|
||||||
include("src/xenia/app")
|
include("src/xenia/app")
|
||||||
|
include("src/xenia/app/discord")
|
||||||
include("src/xenia/apu")
|
include("src/xenia/apu")
|
||||||
include("src/xenia/apu/nop")
|
include("src/xenia/apu/nop")
|
||||||
include("src/xenia/base")
|
include("src/xenia/base")
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* Xenia : Xbox 360 Emulator Research Project *
|
||||||
|
******************************************************************************
|
||||||
|
* Copyright 2015 Ben Vanik. All rights reserved. *
|
||||||
|
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "discord_presence.h"
|
||||||
|
#include "third_party/discord-rpc/include/discord_rpc.h"
|
||||||
|
#include "xenia/base/string.h"
|
||||||
|
|
||||||
|
namespace xe {
|
||||||
|
namespace discord {
|
||||||
|
|
||||||
|
void HandleDiscordReady(const DiscordUser* request) {}
|
||||||
|
void HandleDiscordError(int errorCode, const char* message) {}
|
||||||
|
void HandleDiscordJoinGame(const char* joinSecret) {}
|
||||||
|
void HandleDiscordJoinRequest(const DiscordUser* request) {}
|
||||||
|
void HandleDiscordSpectateGame(const char* spectateSecret) {}
|
||||||
|
|
||||||
|
void DiscordPresence::InitializeDiscord() {
|
||||||
|
DiscordEventHandlers handlers = {};
|
||||||
|
handlers.ready = &HandleDiscordReady;
|
||||||
|
handlers.errored = &HandleDiscordError;
|
||||||
|
handlers.joinGame = &HandleDiscordJoinGame;
|
||||||
|
handlers.joinRequest = &HandleDiscordJoinRequest;
|
||||||
|
handlers.spectateGame = &HandleDiscordSpectateGame;
|
||||||
|
Discord_Initialize("606840046649081857", &handlers, 0, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiscordPresence::NotPlaying() {
|
||||||
|
DiscordRichPresence discordPresence = {};
|
||||||
|
discordPresence.state = "Idle";
|
||||||
|
discordPresence.details = "Standby";
|
||||||
|
discordPresence.largeImageKey = "default";
|
||||||
|
discordPresence.instance = 1;
|
||||||
|
Discord_UpdatePresence(&discordPresence);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiscordPresence::PlayingTitle(std::wstring game_title) {
|
||||||
|
auto discord_game_title = xe::to_string(game_title);
|
||||||
|
DiscordRichPresence discordPresence = {};
|
||||||
|
discordPresence.state = "In Game";
|
||||||
|
discordPresence.details = discord_game_title.c_str();
|
||||||
|
discordPresence.smallImageKey = "default";
|
||||||
|
discordPresence.largeImageKey = "defaultgame";
|
||||||
|
discordPresence.instance = 1;
|
||||||
|
Discord_UpdatePresence(&discordPresence);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiscordPresence::ShutdownDiscord() { Discord_Shutdown(); }
|
||||||
|
|
||||||
|
} // namespace discord
|
||||||
|
} // namespace xe
|
|
@ -0,0 +1,29 @@
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* Xenia : Xbox 360 Emulator Research Project *
|
||||||
|
******************************************************************************
|
||||||
|
* Copyright 2015 Ben Vanik. All rights reserved. *
|
||||||
|
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef XENIA_DISCORD_DISCORD_PRESENCE_H_
|
||||||
|
#define XENIA_DISCORD_DISCORD_PRESENCE_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace xe {
|
||||||
|
namespace discord {
|
||||||
|
|
||||||
|
class DiscordPresence {
|
||||||
|
public:
|
||||||
|
static void InitializeDiscord();
|
||||||
|
static void NotPlaying();
|
||||||
|
static void PlayingTitle(std::wstring game_title);
|
||||||
|
static void ShutdownDiscord();
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace discord
|
||||||
|
} // namespace xe
|
||||||
|
|
||||||
|
#endif // XENIA_DISCORD_DISCORD_PRESENCE_H_
|
|
@ -0,0 +1,20 @@
|
||||||
|
project_root = "../../../.."
|
||||||
|
include(project_root.."/tools/build")
|
||||||
|
|
||||||
|
group("src")
|
||||||
|
project("xenia-app-discord")
|
||||||
|
uuid("d14c0885-22d2-40de-ab28-7b234ef2b949")
|
||||||
|
kind("StaticLib")
|
||||||
|
language("C++")
|
||||||
|
links({
|
||||||
|
"discord-rpc"
|
||||||
|
})
|
||||||
|
defines({
|
||||||
|
})
|
||||||
|
includedirs({
|
||||||
|
project_root.."/third_party/discord-rpc/src"
|
||||||
|
})
|
||||||
|
files({
|
||||||
|
"discord_presence.cc",
|
||||||
|
"discord_presence.h"
|
||||||
|
})
|
|
@ -7,12 +7,15 @@
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <gflags/gflags.h>
|
||||||
|
|
||||||
#include "xenia/app/emulator_window.h"
|
#include "xenia/app/emulator_window.h"
|
||||||
|
|
||||||
// Autogenerated by `xb premake`.
|
// Autogenerated by `xb premake`.
|
||||||
#include "build/version.h"
|
#include "build/version.h"
|
||||||
|
|
||||||
#include "third_party/imgui/imgui.h"
|
#include "third_party/imgui/imgui.h"
|
||||||
|
#include "xenia/app/discord/discord_presence.h"
|
||||||
#include "xenia/base/clock.h"
|
#include "xenia/base/clock.h"
|
||||||
#include "xenia/base/debugging.h"
|
#include "xenia/base/debugging.h"
|
||||||
#include "xenia/base/logging.h"
|
#include "xenia/base/logging.h"
|
||||||
|
@ -26,6 +29,8 @@
|
||||||
#include "xenia/ui/imgui_dialog.h"
|
#include "xenia/ui/imgui_dialog.h"
|
||||||
#include "xenia/ui/imgui_drawer.h"
|
#include "xenia/ui/imgui_drawer.h"
|
||||||
|
|
||||||
|
DEFINE_bool(discord, false, "Enable Discord rich presence");
|
||||||
|
|
||||||
namespace xe {
|
namespace xe {
|
||||||
namespace app {
|
namespace app {
|
||||||
|
|
||||||
|
@ -80,6 +85,11 @@ bool EmulatorWindow::Initialize() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (FLAGS_discord) {
|
||||||
|
discord::DiscordPresence::InitializeDiscord();
|
||||||
|
discord::DiscordPresence::NotPlaying();
|
||||||
|
}
|
||||||
|
|
||||||
UpdateTitle();
|
UpdateTitle();
|
||||||
|
|
||||||
window_->on_closed.AddListener([this](UIEvent* e) { loop_->Quit(); });
|
window_->on_closed.AddListener([this](UIEvent* e) { loop_->Quit(); });
|
||||||
|
@ -334,6 +344,9 @@ void EmulatorWindow::FileOpen() {
|
||||||
void EmulatorWindow::FileClose() {
|
void EmulatorWindow::FileClose() {
|
||||||
if (emulator_->is_title_open()) {
|
if (emulator_->is_title_open()) {
|
||||||
emulator_->TerminateTitle();
|
emulator_->TerminateTitle();
|
||||||
|
if (FLAGS_discord) {
|
||||||
|
discord::DiscordPresence::NotPlaying();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -431,6 +444,9 @@ void EmulatorWindow::UpdateTitle() {
|
||||||
auto game_title = emulator()->game_title();
|
auto game_title = emulator()->game_title();
|
||||||
title += xe::format_string(L" | [%.8X] %s", emulator()->title_id(),
|
title += xe::format_string(L" | [%.8X] %s", emulator()->title_id(),
|
||||||
game_title.c_str());
|
game_title.c_str());
|
||||||
|
if (FLAGS_discord) {
|
||||||
|
discord::DiscordPresence::PlayingTitle(game_title);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto graphics_system = emulator()->graphics_system();
|
auto graphics_system = emulator()->graphics_system();
|
||||||
|
|
|
@ -10,6 +10,7 @@ project("xenia-app")
|
||||||
links({
|
links({
|
||||||
"aes_128",
|
"aes_128",
|
||||||
"capstone",
|
"capstone",
|
||||||
|
"discord-rpc",
|
||||||
"gflags",
|
"gflags",
|
||||||
"glew",
|
"glew",
|
||||||
"glslang-spirv",
|
"glslang-spirv",
|
||||||
|
@ -20,6 +21,7 @@ project("xenia-app")
|
||||||
"snappy",
|
"snappy",
|
||||||
"spirv-tools",
|
"spirv-tools",
|
||||||
"volk",
|
"volk",
|
||||||
|
"xenia-app-discord",
|
||||||
"xenia-apu",
|
"xenia-apu",
|
||||||
"xenia-apu-nop",
|
"xenia-apu-nop",
|
||||||
"xenia-base",
|
"xenia-base",
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit ba9fe00c4de1d680cdc56605d9c0d2b4cf8e7a07
|
|
@ -0,0 +1,37 @@
|
||||||
|
group("third_party")
|
||||||
|
project("discord-rpc")
|
||||||
|
uuid("012f6131-efc0-4abd-852d-a33640732d4c")
|
||||||
|
kind("StaticLib")
|
||||||
|
language("C++")
|
||||||
|
links({
|
||||||
|
})
|
||||||
|
defines({
|
||||||
|
"_LIB",
|
||||||
|
})
|
||||||
|
includedirs({
|
||||||
|
"discord-rpc/include",
|
||||||
|
"rapidjson/include"
|
||||||
|
})
|
||||||
|
files({
|
||||||
|
"discord-rpc/src/connection.h",
|
||||||
|
"discord-rpc/src/discord_rpc.cpp",
|
||||||
|
"discord-rpc/src/msg_queue.h",
|
||||||
|
"discord-rpc/src/rpc_connection.cpp",
|
||||||
|
"discord-rpc/src/rpc_connection.h",
|
||||||
|
"discord-rpc/src/serialization.cpp",
|
||||||
|
"discord-rpc/src/serialization.h"
|
||||||
|
})
|
||||||
|
filter("platforms:Linux")
|
||||||
|
files({
|
||||||
|
"discord-rpc/src/connection_unix.cpp",
|
||||||
|
"discord-rpc/src/discord_register_linux.cpp"
|
||||||
|
})
|
||||||
|
filter("platforms:Mac")
|
||||||
|
files({
|
||||||
|
"discord-rpc/src/discord_register_osx.m"
|
||||||
|
})
|
||||||
|
filter("platforms:Windows")
|
||||||
|
files({
|
||||||
|
"discord-rpc/src/connection_win.cpp",
|
||||||
|
"discord-rpc/src/discord_register_win.cpp"
|
||||||
|
})
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit af223d44f4e8d3772cb1ac0ce8bc2a132b51717f
|
Loading…
Reference in New Issue