mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-04-22 04:24:44 +00:00
Added an option to enable/disable RPC, added rpc to emulator.cpp making it work on nonqt builds
This commit is contained in:
parent
05c98bc4f3
commit
660af35eb4
11 changed files with 78 additions and 25 deletions
|
@ -361,6 +361,8 @@ set(COMMON src/common/logging/backend.cpp
|
|||
src/common/debug.h
|
||||
src/common/decoder.cpp
|
||||
src/common/decoder.h
|
||||
src/common/discord_rpc_handler.cpp
|
||||
src/common/discord_rpc_handler.h
|
||||
src/common/elf_info.h
|
||||
src/common/endian.h
|
||||
src/common/enum.h
|
||||
|
@ -659,8 +661,6 @@ set(QT_GUI src/qt_gui/about_dialog.cpp
|
|||
src/qt_gui/cheats_patches.h
|
||||
src/qt_gui/check_update.cpp
|
||||
src/qt_gui/check_update.h
|
||||
src/qt_gui/discord_rpc_handler.cpp
|
||||
src/qt_gui/discord_rpc_handler.h
|
||||
src/qt_gui/main_window_ui.h
|
||||
src/qt_gui/main_window.cpp
|
||||
src/qt_gui/main_window.h
|
||||
|
@ -843,6 +843,4 @@ if (UNIX AND NOT APPLE)
|
|||
endif()
|
||||
|
||||
#Discord RPC
|
||||
if(ENABLE_QT_GUI)
|
||||
target_link_libraries(shadps4 PRIVATE discord-rpc)
|
||||
endif()
|
||||
target_link_libraries(shadps4 PRIVATE discord-rpc)
|
||||
|
|
4
externals/CMakeLists.txt
vendored
4
externals/CMakeLists.txt
vendored
|
@ -185,8 +185,6 @@ if (NOT TARGET pugixml::pugixml)
|
|||
endif()
|
||||
|
||||
#Discord RPC
|
||||
if(ENABLE_QT_GUI)
|
||||
set(BUILD_EXAMPLES OFF)
|
||||
add_subdirectory(discord-rpc/)
|
||||
target_include_directories(discord-rpc INTERFACE discord-rpc/include)
|
||||
endif()
|
||||
target_include_directories(discord-rpc INTERFACE discord-rpc/include)
|
|
@ -33,6 +33,7 @@ static bool isNeo = false;
|
|||
static bool isFullscreen = false;
|
||||
static bool playBGM = false;
|
||||
static int BGMvolume = 50;
|
||||
static bool enableDiscordRPC = false;
|
||||
static u32 screenWidth = 1280;
|
||||
static u32 screenHeight = 720;
|
||||
static s32 gpuId = -1; // Vulkan physical device index. Set to negative for auto select
|
||||
|
@ -94,6 +95,10 @@ int getBGMvolume() {
|
|||
return BGMvolume;
|
||||
}
|
||||
|
||||
bool getEnableDiscordRPC() {
|
||||
return enableDiscordRPC;
|
||||
}
|
||||
|
||||
u32 getScreenWidth() {
|
||||
return screenWidth;
|
||||
}
|
||||
|
@ -258,6 +263,10 @@ void setBGMvolume(int volume) {
|
|||
BGMvolume = volume;
|
||||
}
|
||||
|
||||
void setEnableDiscordRPC(bool enable) {
|
||||
enableDiscordRPC = enable;
|
||||
}
|
||||
|
||||
void setLanguage(u32 language) {
|
||||
m_language = language;
|
||||
}
|
||||
|
@ -422,6 +431,7 @@ void load(const std::filesystem::path& path) {
|
|||
isFullscreen = toml::find_or<bool>(general, "Fullscreen", false);
|
||||
playBGM = toml::find_or<bool>(general, "playBGM", false);
|
||||
BGMvolume = toml::find_or<int>(general, "BGMvolume", 50);
|
||||
enableDiscordRPC = toml::find_or<bool>(general, "enableDiscordRPC", false);
|
||||
logFilter = toml::find_or<std::string>(general, "logFilter", "");
|
||||
logType = toml::find_or<std::string>(general, "logType", "sync");
|
||||
userName = toml::find_or<std::string>(general, "userName", "shadPS4");
|
||||
|
@ -524,6 +534,7 @@ void save(const std::filesystem::path& path) {
|
|||
data["General"]["Fullscreen"] = isFullscreen;
|
||||
data["General"]["playBGM"] = playBGM;
|
||||
data["General"]["BGMvolume"] = BGMvolume;
|
||||
data["General"]["enableDiscordRPC"] = enableDiscordRPC;
|
||||
data["General"]["logFilter"] = logFilter;
|
||||
data["General"]["logType"] = logType;
|
||||
data["General"]["userName"] = userName;
|
||||
|
@ -577,6 +588,7 @@ void setDefaultValues() {
|
|||
isFullscreen = false;
|
||||
playBGM = false;
|
||||
BGMvolume = 50;
|
||||
enableDiscordRPC = true;
|
||||
screenWidth = 1280;
|
||||
screenHeight = 720;
|
||||
logFilter = "";
|
||||
|
|
|
@ -15,6 +15,7 @@ bool isNeoMode();
|
|||
bool isFullscreenMode();
|
||||
bool getPlayBGM();
|
||||
int getBGMvolume();
|
||||
bool getEnableDiscordRPC();
|
||||
|
||||
std::string getLogFilter();
|
||||
std::string getLogType();
|
||||
|
@ -52,6 +53,7 @@ void setScreenHeight(u32 height);
|
|||
void setFullscreenMode(bool enable);
|
||||
void setPlayBGM(bool enable);
|
||||
void setBGMvolume(int volume);
|
||||
void setEnableDiscordRPC(bool enable);
|
||||
void setLanguage(u32 language);
|
||||
void setNeoMode(bool enable);
|
||||
void setUserName(const std::string& type);
|
||||
|
|
|
@ -3,16 +3,16 @@
|
|||
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include "src/qt_gui/discord_rpc_handler.h"
|
||||
#include "src/common/discord_rpc_handler.h"
|
||||
|
||||
namespace DiscordRPCHandler {
|
||||
|
||||
void RPC::init(const std::string& appId) {
|
||||
void RPC::init() {
|
||||
DiscordEventHandlers handlers{};
|
||||
|
||||
Discord_Initialize(appId.c_str(), &handlers, 1, nullptr);
|
||||
Discord_Initialize("1290207945476280360", &handlers, 1, nullptr);
|
||||
startTimestamp = time(nullptr);
|
||||
enabled = true;
|
||||
rpcEnabled = true;
|
||||
}
|
||||
|
||||
void RPC::setStatusIdling() {
|
||||
|
@ -22,6 +22,7 @@ void RPC::setStatusIdling() {
|
|||
rpc.startTimestamp = startTimestamp;
|
||||
rpc.details = "Idle";
|
||||
|
||||
status = RPCStatus::Idling;
|
||||
Discord_UpdatePresence(&rpc);
|
||||
}
|
||||
|
||||
|
@ -37,7 +38,20 @@ void RPC::setStatusPlaying(const std::string& game_name, const std::string& game
|
|||
rpc.largeImageText = game_name.c_str();
|
||||
rpc.startTimestamp = startTimestamp;
|
||||
|
||||
status = RPCStatus::Playing;
|
||||
Discord_UpdatePresence(&rpc);
|
||||
}
|
||||
|
||||
void RPC::shutdown() {
|
||||
if (rpcEnabled) {
|
||||
rpcEnabled = false;
|
||||
Discord_ClearPresence();
|
||||
Discord_Shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
bool RPC::getRPCEnabled() {
|
||||
return rpcEnabled;
|
||||
}
|
||||
|
||||
} // namespace DiscordRPCHandler
|
|
@ -16,12 +16,20 @@ enum class RPCStatus {
|
|||
|
||||
class RPC {
|
||||
std::uint64_t startTimestamp;
|
||||
bool enabled = false;
|
||||
bool rpcEnabled = false;
|
||||
RPCStatus status;
|
||||
|
||||
public:
|
||||
void init(const std::string& appId);
|
||||
static RPC& getInstance() {
|
||||
static RPC instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void init();
|
||||
void setStatusIdling();
|
||||
void setStatusPlaying(const std::string& game_name, const std::string& game_id);
|
||||
void shutdown();
|
||||
bool getRPCEnabled();
|
||||
};
|
||||
|
||||
} // namespace DiscordRPCHandler
|
|
@ -11,6 +11,7 @@
|
|||
#include "common/memory_patcher.h"
|
||||
#endif
|
||||
#include "common/assert.h"
|
||||
#include "common/discord_rpc_handler.h"
|
||||
#include "common/elf_info.h"
|
||||
#include "common/ntapi.h"
|
||||
#include "common/path_util.h"
|
||||
|
@ -210,6 +211,14 @@ void Emulator::Run(const std::filesystem::path& file) {
|
|||
}
|
||||
}
|
||||
|
||||
// Discord RPC
|
||||
if (Config::getEnableDiscordRPC()) {
|
||||
if (DiscordRPCHandler::RPC::getInstance().getRPCEnabled() == false) {
|
||||
DiscordRPCHandler::RPC::getInstance().init();
|
||||
}
|
||||
DiscordRPCHandler::RPC::getInstance().setStatusPlaying(game_info.title, id);
|
||||
}
|
||||
|
||||
// start execution
|
||||
std::jthread mainthread =
|
||||
std::jthread([this](std::stop_token stop_token) { linker->Execute(); });
|
||||
|
|
|
@ -71,8 +71,10 @@ bool MainWindow::Init() {
|
|||
statusBar->showMessage(statusMessage);
|
||||
|
||||
// Initialize Discord RPC
|
||||
discordRPC.init("1290207945476280360");
|
||||
discordRPC.setStatusIdling();
|
||||
if (Config::getEnableDiscordRPC()) {
|
||||
DiscordRPCHandler::RPC::getInstance().init();
|
||||
DiscordRPCHandler::RPC::getInstance().setStatusIdling();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -532,23 +534,17 @@ void MainWindow::StartGame() {
|
|||
if (table_mode == 0) {
|
||||
if (m_game_list_frame->currentItem()) {
|
||||
int itemID = m_game_list_frame->currentItem()->row();
|
||||
discordRPC.setStatusPlaying(m_game_info->m_games[itemID].name,
|
||||
m_game_info->m_games[itemID].serial);
|
||||
Common::FS::PathToQString(gamePath, m_game_info->m_games[itemID].path / "eboot.bin");
|
||||
}
|
||||
} else if (table_mode == 1) {
|
||||
if (m_game_grid_frame->cellClicked) {
|
||||
int itemID = (m_game_grid_frame->crtRow * m_game_grid_frame->columnCnt) +
|
||||
m_game_grid_frame->crtColumn;
|
||||
discordRPC.setStatusPlaying(m_game_info->m_games[itemID].name,
|
||||
m_game_info->m_games[itemID].serial);
|
||||
Common::FS::PathToQString(gamePath, m_game_info->m_games[itemID].path / "eboot.bin");
|
||||
}
|
||||
} else {
|
||||
if (m_elf_viewer->currentItem()) {
|
||||
int itemID = m_elf_viewer->currentItem()->row();
|
||||
discordRPC.setStatusPlaying(m_game_info->m_games[itemID].name,
|
||||
m_game_info->m_games[itemID].serial);
|
||||
gamePath = m_elf_viewer->m_elf_list[itemID];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include "background_music_player.h"
|
||||
#include "common/config.h"
|
||||
#include "common/discord_rpc_handler.h"
|
||||
#include "common/path_util.h"
|
||||
#include "core/file_format/psf.h"
|
||||
#include "core/file_sys/fs.h"
|
||||
|
@ -21,7 +22,6 @@
|
|||
#include "main_window_themes.h"
|
||||
#include "main_window_ui.h"
|
||||
#include "pkg_viewer.h"
|
||||
#include "qt_gui/discord_rpc_handler.h"
|
||||
|
||||
class GameListFrame;
|
||||
|
||||
|
@ -94,8 +94,6 @@ private:
|
|||
|
||||
QTranslator* translator;
|
||||
|
||||
DiscordRPCHandler::RPC discordRPC;
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject* obj, QEvent* event) override;
|
||||
|
||||
|
|
|
@ -151,6 +151,16 @@ SettingsDialog::SettingsDialog(std::span<const QString> physical_devices, QWidge
|
|||
Config::setBGMvolume(val);
|
||||
BackgroundMusicPlayer::getInstance().setVolume(val);
|
||||
});
|
||||
|
||||
connect(ui->discordRPCCheckbox, &QCheckBox::stateChanged, this, [](int val) {
|
||||
Config::setEnableDiscordRPC(val);
|
||||
if (val) {
|
||||
DiscordRPCHandler::RPC::getInstance().init();
|
||||
DiscordRPCHandler::RPC::getInstance().setStatusIdling();
|
||||
} else {
|
||||
DiscordRPCHandler::RPC::getInstance().shutdown();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// GPU TAB
|
||||
|
@ -241,6 +251,7 @@ void SettingsDialog::LoadValuesFromConfig() {
|
|||
ui->dumpPM4CheckBox->setChecked(Config::dumpPM4());
|
||||
ui->playBGMCheckBox->setChecked(Config::getPlayBGM());
|
||||
ui->BGMVolumeSlider->setValue((Config::getBGMvolume()));
|
||||
ui->discordRPCCheckbox->setChecked(Config::getEnableDiscordRPC());
|
||||
ui->fullscreenCheckBox->setChecked(Config::isFullscreenMode());
|
||||
ui->showSplashCheckBox->setChecked(Config::showSplash());
|
||||
ui->ps4proCheckBox->setChecked(Config::isNeoMode());
|
||||
|
|
|
@ -139,6 +139,13 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="discordRPCCheckbox">
|
||||
<property name="text">
|
||||
<string>Enable Discord Rich Presence</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
|
|
Loading…
Add table
Reference in a new issue