Skip to content

Commit

Permalink
Added support for cwcheat in pops mode
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOfficialFloW committed Apr 17, 2017
1 parent 9cadca8 commit 6fd9286
Show file tree
Hide file tree
Showing 15 changed files with 1,869 additions and 1,853 deletions.
8 changes: 5 additions & 3 deletions adrenaline_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@
#ifndef __ADRENALINE_COMPAT_H__
#define __ADRENALINE_COMPAT_H__

#define ADRENALINE_VERSION_MAJOR 3
#define ADRENALINE_VERSION_MINOR 1
#define ADRENALINE_VERSION (ADRENALINE_VERSION_MAJOR << 16) | ADRENALINE_VERSION_MINOR

#define SCE_PSPEMU_FLASH0_PACKAGE_SIZE 0x920000
#define SCE_PSPEMU_EXTRA_MEMORY 0x8B000000
#define SCE_PSPEMU_SCRATCHPAD 0x8BD00000
#define SCE_PSPEMU_VRAM 0x8BE00000

#define SCE_PSPEMU_FRAMEBUFFER 0x74000000
#define SCE_PSPEMU_FRAMEBUFFER 0x74000000
#define SCE_PSPEMU_FRAMEBUFFER_SIZE 0x88000

#define PSP_RAM_SIZE (64 * 1024 * 1024)
Expand Down Expand Up @@ -150,8 +154,6 @@ typedef struct {
char titleid[12];
char filename[256];

int open_homescreen;

int psp_cmd;
int vita_cmd;
int psp_response;
Expand Down
Binary file modified cef/flash0/kd/systemctrl.prx
Binary file not shown.
3 changes: 0 additions & 3 deletions cef/include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@

#include "../../adrenaline_compat.h"

#define ADRENALINE_VERSION_MAJOR 3
#define ADRENALINE_VERSION_MINOR 1

#define PBP_MAGIC 0x50425000
#define ELF_MAGIC 0x464C457F
#define PSP_MAGIC 0x5053507E
Expand Down
4 changes: 2 additions & 2 deletions cef/systemctrl/binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ static unsigned char binary[] __attribute__((aligned(16))) = {
0x00, 0x00, 0xb0, 0xaf, 0x01, 0x00, 0x10, 0x3c, 0x50, 0x02, 0x06, 0x8e, 0x01, 0x00, 0x02, 0x24,
0x04, 0x00, 0xbf, 0xaf, 0x08, 0x00, 0xc4, 0xac, 0x0c, 0x00, 0xc5, 0xac, 0x00, 0x00, 0xc3, 0x8c,
0x0a, 0x00, 0x62, 0x14, 0x0f, 0x00, 0x04, 0x24, 0x37, 0x40, 0x00, 0x0c, 0x01, 0x00, 0x05, 0x24,
0x50, 0x02, 0x03, 0x8e, 0x01, 0x00, 0x04, 0x24, 0xb0, 0x01, 0x62, 0x8c, 0xfe, 0xff, 0x44, 0x14,
0x50, 0x02, 0x03, 0x8e, 0x01, 0x00, 0x04, 0x24, 0xac, 0x01, 0x62, 0x8c, 0xfe, 0xff, 0x44, 0x14,
0x00, 0x00, 0x00, 0x00, 0x73, 0x40, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0x8c,
0x02, 0x00, 0x02, 0x24, 0x0a, 0x00, 0x62, 0x14, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x04, 0x24,
0x37, 0x40, 0x00, 0x0c, 0x02, 0x00, 0x05, 0x24, 0x50, 0x02, 0x03, 0x8e, 0x02, 0x00, 0x04, 0x24,
0xb0, 0x01, 0x62, 0x8c, 0xfe, 0xff, 0x44, 0x14, 0x00, 0x00, 0x00, 0x00, 0xb0, 0x01, 0x60, 0xac,
0xac, 0x01, 0x62, 0x8c, 0xfe, 0xff, 0x44, 0x14, 0x00, 0x00, 0x00, 0x00, 0xac, 0x01, 0x60, 0xac,
0x00, 0x80, 0x08, 0x40, 0x00, 0x10, 0x09, 0x24, 0x40, 0x12, 0x08, 0x7d, 0x04, 0x48, 0x09, 0x01,
0x00, 0xe0, 0x80, 0x40, 0x00, 0xe8, 0x80, 0x40, 0x21, 0x40, 0x00, 0x00, 0x00, 0x00, 0x01, 0xbd,
0x00, 0x00, 0x03, 0xbd, 0x40, 0x00, 0x08, 0x25, 0xfc, 0xff, 0x09, 0x15, 0x00, 0x00, 0x00, 0x00,
Expand Down
3 changes: 3 additions & 0 deletions cef/systemctrl/imports.S
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
IMPORT_FUNC "ModuleMgrForKernel",0x939E4270,sceKernelLoadModule661
IMPORT_FUNC "ModuleMgrForKernel",0x3FF74DF1,sceKernelStartModule661

IMPORT_START "sceDisplay_driver",0x00090011
IMPORT_FUNC "sceDisplay_driver",0xA38B3F89,sceDisplaySetFrameBuf661

IMPORT_START "LoadExecForKernel",0x00090011
IMPORT_FUNC "LoadExecForKernel",0x08F7166C,sceKernelExitVSHVSH661

Expand Down
18 changes: 6 additions & 12 deletions cef/systemctrl/io_patch.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ int (* _sceIoDelDrv)(const char *drv_name);
int (* _sceIoUnassign)(const char *dev);
int (* _sceIoAssign)(const char *dev1, const char *dev2, const char *dev3, int mode, void* unk1, long unk2);

int (* MsfsSysEventHandler)(int ev_id, char *ev_name, void *param, int *result);

char *stristr(const char *str1, const char *str2) {
#define MAXLEN 256

Expand Down Expand Up @@ -105,6 +103,12 @@ int _msIoIoctl(u32 *args) {
}

int IoDevctlReinsertMs() {
SceModule2 *mod = sceKernelFindModuleByName661("sceKermitMsfs_driver");
if (!mod)
return -1;

int (* MsfsSysEventHandler)(int ev_id, char *ev_name, void *param, int *result) = mod->text_addr + 0x150;

// Perform a MS reinsertion
static int ev_ids[] = { 0x102, 0x400, 0x10000, 0x100000 };

Expand Down Expand Up @@ -612,14 +616,4 @@ void PatchIoFileMgr() {
// This fixes popsman flash2 assign
HIJACK_FUNCTION(K_EXTRACT_IMPORT(&sceIoUnassign), sceIoUnassignPatched, _sceIoUnassign);
HIJACK_FUNCTION(K_EXTRACT_IMPORT(&sceIoAssign), sceIoAssignPatched, _sceIoAssign);
}

int sceKernelRegisterSysEventHandlerPatched(PspSysEventHandler *handler) {
MsfsSysEventHandler = handler->handler;
return sceKernelRegisterSysEventHandler(handler);
}

void PatchMsfsDriver(SceModule2 *mod) {
MAKE_JUMP(sctrlHENFindImport(mod->modname, "sceSysEventForKernel", 0xCD9E4BB5), sceKernelRegisterSysEventHandlerPatched);
ClearCaches();
}
1 change: 0 additions & 1 deletion cef/systemctrl/io_patch.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@
#define __IO_PATCH_H__

void PatchIoFileMgr();
void PatchMsfsDriver(SceModule2 *mod);

#endif
28 changes: 2 additions & 26 deletions cef/systemctrl/libraries_patch.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ u32 sctrlHENFindImport(const char *szMod, const char *szLib, u32 nid) {
if (!mod)
return 0;
}

/*
u32 new_nid = ResolveOldNIDs(szLib, nid);
if (new_nid)
nid = new_nid;

*/
int i = 0;
while (i < mod->stub_size) {
SceLibraryStubTable *stub = (SceLibraryStubTable *)(mod->stub_top + i);
Expand All @@ -149,31 +149,7 @@ u32 sctrlHENFindImport(const char *szMod, const char *szLib, u32 nid) {

return 0;
}
/*
int hookImportByNID(SceModule2 *mod, const char *library, u32 nid, void *func) {
u32 function = sctrlHENFindImport(mod->modname, library, nid);
if ((u32)func >= 0 && (u32)func <= 0xFFFF) {
MAKE_DUMMY_FUNCTION(function, (u32)func);
} else
{
if ((function & 0x08800000) == 0x08800000 && ((u32)func & 0x88000000) == 0x88000000) {
int (* sceKernelQuerySystemCall660)(void *function) = (void *)FindProc("sceInterruptManager", "InterruptManagerForKernel", 0x8B61808B);
int syscall = sceKernelQuerySystemCall661(func);
if (syscall < 0) return -1;
MAKE_SYSCALL_JUMP(function, syscall);
} else
{
REDIRECT_FUNCTION(function, func);
}
}
sceKernelDcacheWritebackInvalidateRange((void *)function, 8);
sceKernelIcacheInvalidateRange((void *)function, 8);

return 0;
}
*/
int aLinkLibEntriesPatched(void *lib) {
char *libname = (char *)((u32 *)lib)[8/4];

Expand Down
42 changes: 39 additions & 3 deletions cef/systemctrl/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,13 @@ void OnSystemStatusIdle() {
if (sceKernelBootFrom() == PSP_BOOT_DISC) {
SetSpeed(cpu_list[config.umdisocpuspeed % N_CPU], bus_list[config.umdisocpuspeed % N_CPU]);
}

// Set fake framebuffer so that cwcheat can be displayed
SceAdrenaline *adrenaline = (SceAdrenaline *)ADRENALINE_ADDRESS;
if (adrenaline->pops_mode) {
sceDisplaySetFrameBuf661((void *)0x0A000000, 512, PSP_DISPLAY_PIXEL_FORMAT_8888, PSP_DISPLAY_SETBUF_NEXTFRAME);
memset(0xAA000000, 0, 16 * 1024 * 1024);
}
}

int (* sceMeAudio_driver_C300D466)(int codec, int unk, void *info);
Expand All @@ -256,6 +263,31 @@ int sceMeAudio_driver_C300D466_Patched(int codec, int unk, void *info) {
return res;
}

int sceKernelSuspendThreadPatched(SceUID thid) {
SceKernelThreadInfo info;
info.size = sizeof(SceKernelThreadInfo);
if (sceKernelReferThreadStatus(thid, &info) == 0) {
if (strcmp(info.name, "popsmain") == 0) {
SendAdrenalineCmd(ADRENALINE_VITA_CMD_PAUSE_POPS);
SendAdrenalineCmd(ADRENALINE_VITA_CMD_SET_FRAMEBUF);
}
}

return sceKernelSuspendThread(thid);
}

int sceKernelResumeThreadPatched(SceUID thid) {
SceKernelThreadInfo info;
info.size = sizeof(SceKernelThreadInfo);
if (sceKernelReferThreadStatus(thid, &info) == 0) {
if (strcmp(info.name, "popsmain") == 0) {
SendAdrenalineCmd(ADRENALINE_VITA_CMD_RESUME_POPS);
}
}

return sceKernelResumeThread(thid);
}

int OnModuleStart(SceModule2 *mod) {
char *modname = mod->modname;
u32 text_addr = mod->text_addr;
Expand All @@ -277,8 +309,6 @@ int OnModuleStart(SceModule2 *mod) {
PatchLowIODriver2(text_addr);
} else if (strcmp(modname, "sceLoadExec") == 0) {
PatchLoadExec(text_addr);
} else if (strcmp(modname, "sceKermitMsfs_driver") == 0) {
PatchMsfsDriver(mod);
} else if (strcmp(modname, "scePower_Service") == 0) {
log("Built: %s %s\n", __DATE__, __TIME__);
log("Boot From: 0x%X\n", sceKernelBootFrom());
Expand All @@ -288,7 +318,7 @@ int OnModuleStart(SceModule2 *mod) {

sctrlSEGetConfig(&config);

if (config.forcehighmemory) {
if (sceKernelInitKeyConfig() != PSP_INIT_KEYCONFIG_POPS && config.forcehighmemory) {
sctrlHENSetMemory(52, 0);
ApplyMemory();
}
Expand Down Expand Up @@ -333,6 +363,12 @@ int OnModuleStart(SceModule2 *mod) {
}

ClearCaches();
} else if (strcmp(mod->modname, "CWCHEATPRX") == 0) {
if (sceKernelInitKeyConfig() == PSP_INIT_KEYCONFIG_POPS) {
MAKE_JUMP(sctrlHENFindImport(mod->modname, "ThreadManForKernel", 0x9944F31F), sceKernelSuspendThreadPatched);
MAKE_JUMP(sctrlHENFindImport(mod->modname, "ThreadManForKernel", 0x75156E8F), sceKernelResumeThreadPatched);
ClearCaches();
}
}

if (!idle) {
Expand Down
48 changes: 21 additions & 27 deletions cef/systemctrl/sysmodpatches.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,22 @@ int SetIdleCallbackPatched(int flags) {
return 0;
}

int RestoreSound() {
SceModule2 *mod = sceKernelFindModuleByName661("sceAudio_Driver");
if (!mod)
return -1;

int (* AudioSysEventHandler)(int ev_id, char *ev_name, void *param, int *result) = mod->text_addr + 0x179C;
AudioSysEventHandler(0x200, NULL, NULL, NULL);
AudioSysEventHandler(0x100000, NULL, NULL, NULL);

return 0;
}

int exit_callback(int arg1, int arg2, void *common) {
sceKernelSuspendAllUserThreads();

SendAdrenalineCmd(ADRENALINE_VITA_CMD_RESUME_POPS);
RestoreSound();

static u32 vshmain_args[0x100];
memset(vshmain_args, 0, sizeof(vshmain_args));
Expand Down Expand Up @@ -260,32 +272,17 @@ SceUID SetupCallbacks() {
return thid;
}

int (* _sceDisplaySetFrameBufferInternal)(int pri, void *topaddr, int bufferwidth, int pixelformat, int sync);

int sceDisplaySetFrameBufferInternalPatched(int pri, void *topaddr, int bufferwidth, int pixelformat, int sync) {
// Enable interrupts now
asm __volatile__ (
"mfc0 $v0, $12\n"
"ori $v0, $v0, 1\n"
"mtc0 $v0, $12\n"
"nop\n"
);

if (topaddr) {
int sceKernelWaitEventFlagPatched(int evid, u32 bits, u32 wait, u32 *outBits, SceUInt *timeout) {
int res = sceKernelWaitEventFlag(evid, bits, wait, outBits, timeout);

if (*outBits & 0x1) {
SendAdrenalineCmd(ADRENALINE_VITA_CMD_PAUSE_POPS);
SendAdrenalineCmd(ADRENALINE_VITA_CMD_SET_FRAMEBUF);
} else {
} else if (*outBits & 0x2) {
SendAdrenalineCmd(ADRENALINE_VITA_CMD_RESUME_POPS);
}

// Disable interrupts now
asm __volatile__ (
"mtic $0, $0\n"
"nop\n"
"nop\n"
);

return _sceDisplaySetFrameBufferInternal(pri, topaddr, bufferwidth, pixelformat, sync);
return res;
}

void PatchImposeDriver(u32 text_addr) {
Expand All @@ -295,12 +292,9 @@ void PatchImposeDriver(u32 text_addr) {
HIJACK_FUNCTION(text_addr + 0x381C, SetIdleCallbackPatched, SetIdleCallback);

if (sceKernelInitKeyConfig() == PSP_INIT_KEYCONFIG_POPS) {
MAKE_DUMMY_FUNCTION(text_addr + 0x91C8, PSP_INIT_KEYCONFIG_GAME);

_sceDisplaySetFrameBufferInternal = (void *)K_EXTRACT_IMPORT(text_addr + 0x9380);
REDIRECT_FUNCTION(text_addr + 0x9380, sceDisplaySetFrameBufferInternalPatched);

SetupCallbacks();
MAKE_DUMMY_FUNCTION(text_addr + 0x91C8, PSP_INIT_KEYCONFIG_GAME);
REDIRECT_FUNCTION(text_addr + 0x92B0, sceKernelWaitEventFlagPatched);
}

ClearCaches();
Expand Down
2 changes: 1 addition & 1 deletion cef/systemctrl/systemctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ int sctrlHENGetVersion() {
}

int sctrlSEGetVersion() {
return (ADRENALINE_VERSION_MAJOR << 16) | ADRENALINE_VERSION_MINOR;
return ADRENALINE_VERSION;
}

PspIoDrv *sctrlHENFindDriver(char *drvname) {
Expand Down
3 changes: 2 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
For 6.61 Adrenaline-2 or higher, you must put Adrenaline files to 'ux0:adrenaline' instead of 'ux0:pspemu/adrenaline'.

- Changelog v3.1 -
- Fixed 'Please wait...' bug in some games.
- Added support for cwcheat in PS1 games.
- Fixed sound problems after exiting a PS1 game.
- Fixed 'Please wait...' bug in some games.
- Fixed problem where mounting ur0: as USB device would cause problems in livearea.

- Changelog v3 fix -
Expand Down
Loading

0 comments on commit 6fd9286

Please sign in to comment.