Skip to content

Commit

Permalink
added VshCtrl for 1.50
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseAaronLopezGarcia committed Jan 1, 2025
1 parent b01f0a8 commit ae9cd45
Show file tree
Hide file tree
Showing 10 changed files with 443 additions and 10 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ SUBDIRS = libs \
extras/150kernel/rebootex150 \
extras/150kernel/reboot150 \
extras/150kernel/systemctrl150 \
extras/150kernel/vshctrl150 \
extras/150kernel/tmctrl150 \
extras/150kernel/installer

Expand Down
9 changes: 1 addition & 8 deletions core/vshctrl/vshpatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ typedef struct _HookUserFunctions {
} HookUserFunctions;

static STMOD_HANDLER previous;
//SEConfig conf;

static void patch_sysconf_plugin_module(SceModule2 *mod);
static void patch_game_plugin_module(SceModule2 *mod);
Expand All @@ -73,38 +72,32 @@ static int vshpatch_module_chain(SceModule2 *mod)

if(0 == strcmp(mod->modname, "sysconf_plugin_module")) {
patch_sysconf_plugin_module(mod);
sync_cache();
goto exit;
}

if(0 == strcmp(mod->modname, "game_plugin_module")) {
patch_game_plugin_module(mod);
sync_cache();
goto exit;
}

if(0 == strcmp(mod->modname, "vsh_module")) {
patch_vsh_module(mod);
patch_sceCtrlReadBufferPositive();
sync_cache();
goto exit;
}

if(0 == strcmp(mod->modname, "msvideo_main_plugin_module")) {
patch_msvideo_main_plugin_module(mod);
sync_cache();
goto exit;
}

if( 0 == strcmp(mod->modname, "update_plugin_module")) {
patch_update_plugin_module(mod);
sync_cache();
goto exit;
}

if(0 == strcmp(mod->modname, "SceUpdateDL_Library")) {
patch_SceUpdateDL_Library(mod);
sync_cache();
goto exit;
}

Expand All @@ -118,11 +111,11 @@ static int vshpatch_module_chain(SceModule2 *mod)
patch_hibblock(mod);
}

sync_cache();
goto exit;
}

exit:
sync_cache();
if (previous) previous(mod);
}

Expand Down
2 changes: 1 addition & 1 deletion extras/150kernel/btcnf/pspbtcnf.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
/kd/chkreg.prx
/kd/impose.prx
/kd/vshbridge.prx
/kd/ark_vshctrl.prx
/kd/ark_vshctrl150.prx

#for savedata
/vsh/module/chnnlsv.prx
Expand Down
1 change: 1 addition & 0 deletions extras/150kernel/systemctrl150/exports.exp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ PSP_EXPORT_FUNC(sctrlHENFindFunction)
PSP_EXPORT_FUNC(sctrlHENSetLoadRebootOverrideHandler)
PSP_EXPORT_FUNC(sctrlHENSetRebootexOverride)
PSP_EXPORT_FUNC(sctrlHENSetStartModuleHandler)
PSP_EXPORT_FUNC(sctrlHENPatchSyscall)
PSP_EXPORT_END


Expand Down
27 changes: 27 additions & 0 deletions extras/150kernel/systemctrl150/src/sctrl_hen.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,31 @@ unsigned int sctrlHENFindFunction(char * szMod, char * szLib, unsigned int nid)

// Function not found
return 0;
}

// Replace Function in Syscall Table
void sctrlHENPatchSyscall(void * addr, void * newaddr)
{
// Syscall Table
unsigned int * syscalls = NULL;

// Get Syscall Table Pointer from Coprocessor
__asm__ volatile("cfc0 %0, $12\n" : "=r"(syscalls));

// Invalid Syscall Table
if(syscalls == NULL) return;

// Skip Table Header
syscalls += 4; // 4 * 4 = 16

// Iterate Syscalls
for(int i = 0; i < 0xFF4; ++i)
{
// Found Matching Function
if((syscalls[i] & 0x0FFFFFFF) == (((unsigned int)addr) & 0x0FFFFFFF))
{
// Replace Syscall Function
syscalls[i] = (unsigned int)newaddr;
}
}
}
32 changes: 32 additions & 0 deletions extras/150kernel/vshctrl150/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
TARGET = vshctrl150

OBJS = \
main.o \
vshmenu.o \
$(ARKROOT)/libs/ansi-c/strcasecmp.o

all: $(TARGET).prx
INCDIR = $(ARKROOT)/common/include/ $(ARKROOT)/libs/graphics/ $(ARKROOT)
CFLAGS = -std=c99 -Os -G0 -Wall -fno-pic $(addprefix -I, $(INCDIR))

CFLAGS += -I include

CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)

BUILD_PRX = 1
PRX_EXPORTS = exports.exp

USE_KERNEL_LIBC=1
USE_KERNEL_LIBS=1

LIBDIR = $(ARKROOT)/libs lib
LDFLAGS = -nostartfiles
LIBS = -lpspsystemctrl_kernel

PSP_FW_VERSION = 150

include $(ARKROOT)/common/make/global.mak
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
include $(ARKROOT)/common/make/beauty.mak
14 changes: 14 additions & 0 deletions extras/150kernel/vshctrl150/exports.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Define the exports for the prx
PSP_BEGIN_EXPORTS

PSP_EXPORT_START(syslib, 0, 0x8000)
PSP_EXPORT_FUNC_HASH(module_start)
PSP_EXPORT_VAR_HASH(module_info)
PSP_EXPORT_END

PSP_EXPORT_START(VshCtrlLib, 0, 0x4001)
PSP_EXPORT_FUNC(vctrlVSHRegisterVshMenu)
PSP_EXPORT_FUNC(vctrlVSHExitVSHMenu)
PSP_EXPORT_END

PSP_END_EXPORTS
154 changes: 154 additions & 0 deletions extras/150kernel/vshctrl150/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
#include <pspsdk.h>
#include <pspsysmem_kernel.h>
#include <pspkernel.h>
#include <psputilsforkernel.h>
#include <pspsysevent.h>
#include <pspiofilemgr.h>
#include <stdio.h>
#include <string.h>
#include <pspumd.h>
#include <systemctrl.h>
#include <systemctrl_se.h>
#include "macros.h"
#include <ark.h>
#include "functions.h"

PSP_MODULE_INFO("VshCtrl", 0x1007, 1, 2);

#define GAME150_PATCH "__150"

static STMOD_HANDLER previous;

extern int _sceCtrlReadBufferPositive(SceCtrlData *ctrl, int count);
extern int (*g_sceCtrlReadBufferPositive) (SceCtrlData *, int);

// Flush Instruction and Data Cache
void sync_cache()
{
// Flush Instruction Cache
sceKernelIcacheInvalidateAll();

// Flush Data Cache
sceKernelDcacheWritebackInvalidateAll();
}

static void patch_vsh_module(SceModule2* vshmain)
{
SceModule* mod;

mod = sceKernelFindModuleByName("sceVshBridge_Driver");
hookImportByNID(mod, "sceCtrl_driver", 0x1F803938, _sceCtrlReadBufferPositive);
g_sceCtrlReadBufferPositive = (void *) sctrlHENFindFunction("sceController_Service", "sceCtrl", 0x1F803938);
sctrlHENPatchSyscall(g_sceCtrlReadBufferPositive, _sceCtrlReadBufferPositive);
}


void Fix150Path(const char *file)
{
char str[256];

if (strstr(file, "ms0:/PSP/GAME/") == file) {
strcpy(str, (char *)file);

char *p = strstr(str, GAME150_PATCH);

if (p) {
strcpy((char *)file+13, "150/");
strncpy((char *)file+17, str+14, p-(str+14));
strcpy((char *)file+17+(p-(str+14)), p+5);
}
}
}

static inline int is_game_dir(const char *dirname)
{
const char *p;
char path[256];
SceIoStat stat;

p = strchr(dirname, '/');

if (p == NULL) {
return 0;
}

if (0 != strnicmp(p, "/PSP/GAME", sizeof("/PSP/GAME")-1)) {
return 0;
}

if (0 == strnicmp(p, "/PSP/GAME/_DEL_", sizeof("/PSP/GAME/_DEL_")-1)) {
return 0;
}

strcpy(path, dirname);
strcat(path, "/EBOOT.PBP");

if(0 == sceIoGetstat(path, &stat)) {
return 0;
}

strcpy(path, dirname);
strcat(path, "/PARAM.PBP");

if(0 == sceIoGetstat(path, &stat)) {
return 0;
}

return 1;
}

SceUID gamedopen(const char * dirname)
{
SceUID result;
u32 k1;

Fix150Path(dirname);

result = sceIoDopen(dirname);

if (result >= 0){
if(is_game_dir(dirname)) {

if (strcmp(dirname, "ms0:/PSP/GAME") == 0) {
k1 = pspSdkSetK1(0);
sceIoDclose(result);
result = sceIoDopen("ms0:/PSP/GAME150");
pspSdkSetK1(k1);
}

}
}

return result;
}

static void hook_directory_io(){
void *fp = (void*)sctrlHENFindFunction("sceIOFileManager", "IoFileMgrForUser", 0xB29DDF9C);
if(fp != NULL) {
sctrlHENPatchSyscall(fp, gamedopen);
}
}

static int vshpatch_module_chain(SceModule2 *mod)
{
u32 text_addr = mod->text_addr;

if(0 == strcmp(mod->modname, "vsh_module")) {
patch_vsh_module(mod);
goto exit;
}

exit:
sync_cache();
if (previous) previous(mod);
}


int module_start(SceSize args, void* argp)
{

previous = sctrlHENSetStartModuleHandler(&vshpatch_module_chain);
hook_directory_io();

return 0;
}
Loading

0 comments on commit ae9cd45

Please sign in to comment.