mirror of
https://github.com/SirHumza/orbisRPC.git
synced 2026-10-07 16:00:41 +02:00
/data/GoldHEN/payloads/ is not an auto-load folder (PPPwn only loads goldhen.bin; folder auto-load is unimplemented GoldHEN feature #296), so the ELF payload never ran regardless of reboots. Replace that route with the GoldHEN plugin loader, which auto-starts into the game process at every boot via plugins.ini [default] with no PC involvement. - daemon.c/h: extract the payload main() loop into a shared daemon_run() usable from both the ELF entry (main.c thin wrapper) and the plugin - detect.c/h: add detect_name_for_title() for the known-titleid plugin mode - plugin/plugin.c: plugin_load() reads procInfo.titleid via sys_sdk_proc_info, skips non-game (NPXS/system) titles, starts daemon thread; plugin_unload() stops it cleanly - plugin/Makefile: builds orbisrpc_plugin.prx against the GoldHEN SDK (libGoldHEN_Hook.a + crtprx.o) - deploy/SETUP.md: rewrite for the plugin route; add plugins.ini [default] (plugin/plugins.ini.ps4) - scripts/build.sh: include daemon.c
92 lines
3.3 KiB
C
92 lines
3.3 KiB
C
/* plugin.c - orbisRPC as a GoldHEN plugin (.prx loaded into the game process).
|
|
*
|
|
* GoldHEN loads plugins per game title via /data/GoldHEN/plugins.ini. A
|
|
* plugin runs inside the game's process, so:
|
|
* - we KNOW which game is running: sys_sdk_proc_info() -> procInfo.titleid
|
|
* - the game has full network access (this is the whole point)
|
|
* - it auto-starts at every boot/jailbreak with zero PC involvement
|
|
*
|
|
* plugin_load() resolves the titleid to a display name and starts the shared
|
|
* daemon thread (daemon.c) which handles token refresh, the Discord gateway
|
|
* and presence. plugin_unload() stops it cleanly.
|
|
*/
|
|
#include <stdio.h>
|
|
#include <stdint.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <orbis/libkernel.h>
|
|
#include "Common.h"
|
|
#include "daemon.h"
|
|
#include "detect.h"
|
|
|
|
/* Only post presence for real game titles (CUSA/PPSA/etc). System apps
|
|
* (NPXS..., shell) launching would otherwise post bogus "playing" state. */
|
|
static int is_game_titleid(const char *t){
|
|
static const char *pfx[] = { "CUSA", "PPSA", "PCSE", "PCJS", "EPSA", "PCSB", NULL };
|
|
for(int i=0; pfx[i]; i++) if(strncmp(t, pfx[i], 4)==0) return 1;
|
|
return 0;
|
|
}
|
|
|
|
#define attr_public __attribute__((visibility("default")))
|
|
#define attr_module_hidden __attribute__((weak)) __attribute__((visibility("hidden")))
|
|
|
|
attr_public const char *g_pluginName = "orbisrpc";
|
|
attr_public const char *g_pluginDesc = "Discord Rich Presence for PS4";
|
|
attr_public const char *g_pluginAuth = "orbisRPC";
|
|
attr_public uint32_t g_pluginVersion = 0x00000100; /* 1.00 */
|
|
|
|
struct proc_info procInfo;
|
|
|
|
static void *daemon_thread(void *args){
|
|
/* args = display name of the game we are loaded into */
|
|
char name[128];
|
|
strncpy(name, (const char *)args, sizeof name - 1);
|
|
name[sizeof name - 1] = 0;
|
|
daemon_clear_stop();
|
|
daemon_run(name);
|
|
return NULL;
|
|
}
|
|
|
|
int32_t attr_public plugin_load(int32_t argc, const char *argv[]){
|
|
(void)argc; (void)argv;
|
|
klog("[orbisrpc] <%s\\Ver.0x%08x> %s\n", g_pluginName, g_pluginVersion, __func__);
|
|
klog("[orbisrpc] Plugin Author(s): %s\n", g_pluginAuth);
|
|
|
|
if(sys_sdk_proc_info(&procInfo) != 0){
|
|
klog("[orbisrpc] sys_sdk_proc_info failed; not starting\n");
|
|
return 0;
|
|
}
|
|
klog("[orbisrpc] loaded into process: pid=%d name=%s titleid=%s\n",
|
|
procInfo.pid, procInfo.name, procInfo.titleid);
|
|
|
|
if(!is_game_titleid(procInfo.titleid)){
|
|
klog("[orbisrpc] not a game title (system app?); not starting daemon\n");
|
|
return 0;
|
|
}
|
|
|
|
/* Resolve a display name for the title we are loaded into. */
|
|
static char game_name[128];
|
|
detect_name_for_title(procInfo.titleid, game_name, sizeof game_name);
|
|
klog("[orbisrpc] game: %s\n", game_name);
|
|
|
|
OrbisPthread thread;
|
|
scePthreadCreate(&thread, NULL, daemon_thread, game_name, "orbisrpc_daemon");
|
|
return 0;
|
|
}
|
|
|
|
int32_t attr_public plugin_unload(int32_t argc, const char *argv[]){
|
|
(void)argc; (void)argv;
|
|
klog("[orbisrpc] <%s\\Ver.0x%08x> %s\n", g_pluginName, g_pluginVersion, __func__);
|
|
daemon_request_stop();
|
|
return 0;
|
|
}
|
|
|
|
int32_t attr_module_hidden module_start(int64_t argc, const void *args){
|
|
(void)argc; (void)args;
|
|
return 0;
|
|
}
|
|
|
|
int32_t attr_module_hidden module_stop(int64_t argc, const void *args){
|
|
(void)argc; (void)args;
|
|
return 0;
|
|
} |