Skip to content

Commit

Permalink
fixed per-game settings/plugins with physical UMDs
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseAaronLopezGarcia committed Jul 7, 2023
1 parent e8d6bbf commit 50fa2a6
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 72 deletions.
2 changes: 1 addition & 1 deletion common/include/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
#define ARK_MAJOR_VERSION 4
#define ARK_MINOR_VERSION 20
#define ARK_MICRO_VERSION 60
#define ARK_REVISION 4
#define ARK_REVISION 5
#define MAX_FLASH0_SIZE 0x32000

/*
Expand Down
1 change: 1 addition & 0 deletions common/include/rebootconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ typedef struct RebootConfigARK {
u32 size;
u32 flags;
} rtm_mod;
char game_id[10];
} RebootConfigARK;

#define IS_ARK_CONFIG(config) (*((u32*)config) == ARK_CONFIG_MAGIC)
Expand Down
1 change: 0 additions & 1 deletion core/compat/pentazemin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ C_OBJS = \
$(ARKROOT)/core/compat/vita/vlf.o \
$(ARKROOT)/common/utils/patches.o \
$(ARKROOT)/core/systemctrl/src/dummy.o \
$(ARKROOT)/core/systemctrl/src/gameinfo.o \

OBJS = \
$(C_OBJS) imports.o
Expand Down
1 change: 0 additions & 1 deletion core/compat/psp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ C_OBJS = \
libertas.o \
usb_charge.o \
region_free.o \
$(ARKROOT)/core/systemctrl/src/gameinfo.o \

OBJS = \
$(C_OBJS) imports.o
Expand Down
2 changes: 1 addition & 1 deletion core/systemctrl/exports.exp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ PSP_EXPORT_FUNC_NID(strncasecmp, 0xAC7554DF)
PSP_EXPORT_FUNC_NID(sctrlHENSetArkConfig, 0x6EAFC03D)
PSP_EXPORT_FUNC(sctrlHENSetPluginHandler)
PSP_EXPORT_FUNC(sctrlHENSetRebootexConfig)
PSP_EXPORT_FUNC(readGameIdFromDisc)
PSP_EXPORT_FUNC(getGameId)
PSP_EXPORT_END

PSP_EXPORT_START(ARKdebug, 0, 0x4001)
Expand Down
118 changes: 57 additions & 61 deletions core/systemctrl/src/gameinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <pspinit.h>
#include <pspiofilemgr.h>
#include <pspsysmem_kernel.h>
#include <rebootconfig.h>

#include "globals.h"
#include "macros.h"
Expand All @@ -20,11 +21,9 @@ struct LbaParams {
};

static const char* HOME_ID = "HOME00000";
extern RebootConfigARK rebootex_config;

/*
int readGameIdFromUmd(char* gameid){
int (*UmdActivate)(int, char*) = sctrlHENFindFunction("sceUmd_driver", "sceUmd", 0xC6183D47);
if (UmdActivate) UmdActivate(1, "disc0:");
int readGameIdFromDisc(char* gameid){
// Open Disc Identifier
int disc = sceIoOpen("disc0:/UMD_DATA.BIN", PSP_O_RDONLY, 0777);
// Opened Disc Identifier
Expand All @@ -45,77 +44,74 @@ int readGameIdFromUmd(char* gameid){
}
return 0;
}
*/

int readGameIdFromDisc(char* gameid){
static char game_id[10] = {0};
int apitype = sceKernelInitApitype();
int readGameIdFromPBP(char* gameid){
int n = 9;
int res = sctrlGetInitPARAM("DISC_ID", NULL, &n, rebootex_config.game_id);
if (res < 0) return 0;
return 1;
}

if (game_id[0] == 0){
if (apitype == 0x144 || apitype == 0x155){ // PS1: read from PBP
int n = 9;
int res = sctrlGetInitPARAM("DISC_ID", NULL, &n, game_id);
if (res < 0) return 0;
}
else { //if (sceKernelFindModuleByName("PRO_Inferno_Driver")){ // Inferno Driver: use IoDevctl
struct LbaParams param;
memset(&param, 0, sizeof(param));

param.cmd = 0x01E380C0;
param.lba_top = 16;
param.byte_size_total = 10;
param.byte_size_start = 883;

int res = sceIoDevctl("umd:", 0x01E380C0, &param, sizeof(param), game_id, sizeof(game_id));

if (res < 0) return 0;

// remove the dash in the middle: ULUS-01234 -> ULUS01234
game_id[4] = game_id[5];
game_id[5] = game_id[6];
game_id[6] = game_id[7];
game_id[7] = game_id[8];
game_id[8] = game_id[9];
game_id[9] = 0;
}
/*
else { // UMD: use regular IO
readGameIdFromUmd(game_id);
int fd = sceIoOpen("ms0:/gameid.bin", PSP_O_WRONLY|PSP_O_CREAT|PSP_O_TRUNC, 0777);
sceIoWrite(fd, game_id, strlen(game_id));
sceIoClose(fd);
}
*/
}
int readGameIdFromUmd(char* gameid){
struct LbaParams param;
memset(&param, 0, sizeof(param));

param.cmd = 0x01E380C0;
param.lba_top = 16;
param.byte_size_total = 10;
param.byte_size_start = 883;

int res = sceIoDevctl("umd:", 0x01E380C0, &param, sizeof(param), rebootex_config.game_id, sizeof(rebootex_config.game_id));

if (res < 0) return 0;

// remove the dash in the middle: ULUS-01234 -> ULUS01234
rebootex_config.game_id[4] = rebootex_config.game_id[5];
rebootex_config.game_id[5] = rebootex_config.game_id[6];
rebootex_config.game_id[6] = rebootex_config.game_id[7];
rebootex_config.game_id[7] = rebootex_config.game_id[8];
rebootex_config.game_id[8] = rebootex_config.game_id[9];
rebootex_config.game_id[9] = 0;

if (gameid) memcpy(gameid, game_id, 9);
return 1;
}

int getGameId(char* gameid){

int res = 1;

int apitype = sceKernelInitApitype();
if (apitype == 0x141 || apitype == 0x152 || apitype >= 0x200){
strcpy(gameid, HOME_ID);
return;
return res;
}

// Find Function
void * (* SysMemForKernel_EF29061C)(void) = (void *)sctrlHENFindFunction("sceSystemMemoryManager", "SysMemForKernel", 0xEF29061C);

// Function unavailable (how?!)
if(SysMemForKernel_EF29061C == NULL) return 0;

// Get Game Info Structure
void * gameinfo = SysMemForKernel_EF29061C();

// Structure unavailable
if(gameinfo == NULL) return 0;
memcpy(gameid, gameinfo+0x44, 9);
if (rebootex_config.game_id[0] == 0){

if (gameid[0] == 0 || strncmp(gameid, HOME_ID, 9) == 0){
return readGameIdFromDisc(gameid);
// Find Function
void * (* SysMemForKernel_EF29061C)(void) = (void *)sctrlHENFindFunction("sceSystemMemoryManager", "SysMemForKernel", 0xEF29061C);

// Function unavailable (how?!)
if(SysMemForKernel_EF29061C == NULL) return 0;

// Get Game Info Structure
void * gameinfo = SysMemForKernel_EF29061C();

// Structure unavailable
if(gameinfo == NULL) return 0;
memcpy(gameid, gameinfo+0x44, 9);

if (rebootex_config.game_id[0] == 0 || strncmp(rebootex_config.game_id, HOME_ID, 9) == 0){
if (apitype == 0x144 || apitype == 0x155){ // PS1: read from PBP
res = readGameIdFromPBP(rebootex_config.game_id);
}
else {
res = readGameIdFromUmd(rebootex_config.game_id);
}
}
}

return 1;
if (gameid) memcpy(gameid, rebootex_config.game_id, 9);

return res;
}
3 changes: 2 additions & 1 deletion core/systemctrl/src/loadercore.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,13 @@ static void checkArkPath(){
else{
sceIoDclose(res);
}
extern RebootConfigARK rebootex_config;
if (sceKernelInitApitype() > PSP_INIT_APITYPE_DISC) rebootex_config.game_id[0] = 0;
}

// Init Start Module Hook
int InitKernelStartModule(int modid, SceSize argsize, void * argp, int * modstatus, SceKernelSMOption * opt)
{
extern u8 rebootex_config[];
SceModule2* mod = (SceModule2*) sceKernelFindModuleByUID(modid);

int result = -1;
Expand Down
3 changes: 2 additions & 1 deletion core/systemctrl/src/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ static int matchingRunlevel(char * runlevel)
}
else { // check if plugin loads on specific game
char gameid[10]; memset(gameid, 0, sizeof(gameid));
return (getGameId(gameid) && strstr(runlevel, gameid) != NULL);
getGameId(gameid);
return (gameid[0] && strstr(runlevel, gameid) != NULL);
}

// Unsupported Runlevel (we don't touch those to keep stability up)
Expand Down
3 changes: 3 additions & 0 deletions core/systemctrl/src/sctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ int sctrlKernelLoadExecVSHMs4(const char *file, struct SceKernelLoadExecVSHParam
}

int sctrlKernelLoadExecVSHDisc(const char *file, struct SceKernelLoadExecVSHParam *param) {
int k1 = pspSdkSetK1(0);
readGameIdFromDisc(rebootex_config.game_id);
pspSdkSetK1(k1);
return sctrlKernelLoadExecVSHWithApitype(PSP_INIT_APITYPE_DISC, file, param);
}

Expand Down
2 changes: 1 addition & 1 deletion core/vshctrl/vshpatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ int umdLoadExec(char * file, struct SceKernelLoadExecVSHParam * param)
} else {
sctrlSESetBootConfFileIndex(MODE_UMD);
sctrlSESetUmdFile("");
ret = sceKernelLoadExecVSHDisc(file, param);
ret = sctrlKernelLoadExecVSHDisc(file, param);
}

return ret;
Expand Down
2 changes: 1 addition & 1 deletion libs/SystemCtrlForKernel/SystemCtrlForKernel.S
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
IMPORT_FUNC "SystemCtrlForKernel",0xDCDC3891,sctrlHENSetRebootexOverride
#endif
#ifdef F_SystemCtrlForKernel_0067
IMPORT_FUNC "SystemCtrlForUser",0x577AF198,sctrlKernelLoadExecVSHDisc
IMPORT_FUNC "SystemCtrlForKernel",0x577AF198,sctrlKernelLoadExecVSHDisc
#endif
#ifdef F_SystemCtrlForKernel_0068
IMPORT_FUNC "SystemCtrlForKernel",0x94FE5E4B,sctrlKernelLoadExecVSHDiscUpdater
Expand Down
3 changes: 0 additions & 3 deletions loader/live/kernel/kernel_loader/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,6 @@ void kernelContentFunction(void){
g_tbl->prtstr = KERNELIFY(g_tbl->prtstr);
kxf->repairInstruction = KERNELIFY(kxf->repairInstruction);

PRTSTR("Testing Priviledges");
u32 test = *(u32*)SYSMEM_TEXT;

PRTSTR("Scanning kernel functions");
// get kernel functions
scanKernelFunctions(k_tbl);
Expand Down

0 comments on commit 50fa2a6

Please sign in to comment.