Skip to content

Commit

Permalink
main: Hook user getters and report correct clocks
Browse files Browse the repository at this point in the history
e.g. in homebrew like VITAident
  • Loading branch information
Electry committed Nov 15, 2019
1 parent b5d84c4 commit 9adb460
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ int module_get_offset(SceUID pid, SceUID modid, int segidx, size_t offset, uintp
int module_get_export_func(SceUID pid, const char *modname, uint32_t libnid, uint32_t funcnid, uintptr_t *func);
bool ksceAppMgrIsExclusiveProcessRunning();

#define PSVS_MAX_HOOKS 14
#define PSVS_MAX_HOOKS 18
static tai_hook_ref_t g_hookrefs[PSVS_MAX_HOOKS];
static SceUID g_hooks[PSVS_MAX_HOOKS];
static SceUID g_injects[1];
Expand Down Expand Up @@ -130,6 +130,11 @@ int kscePowerSetGpuXbarClockFrequency_patched(int freq) {
return TAI_CONTINUE(int, g_hookrefs[12], psvs_oc_get_target_freq(PSVS_OC_DEVICE_GPU_XBAR, freq));
}

DECL_FUNC_HOOK_PATCH_FREQ_GETTER(14, scePowerGetArmClockFrequency, PSVS_OC_DEVICE_CPU)
DECL_FUNC_HOOK_PATCH_FREQ_GETTER(15, scePowerGetBusClockFrequency, PSVS_OC_DEVICE_BUS)
DECL_FUNC_HOOK_PATCH_FREQ_GETTER(16, scePowerGetGpuClockFrequency, PSVS_OC_DEVICE_GPU_ES4)
DECL_FUNC_HOOK_PATCH_FREQ_GETTER(17, scePowerGetGpuXbarClockFrequency, PSVS_OC_DEVICE_GPU_XBAR)

int ksceKernelInvokeProcEventHandler_patched(int pid, int ev, int a3, int a4, int *a5, int a6) {
char titleid[sizeof(g_titleid)];
int ret = ksceKernelLockMutex(g_mutex_procevent_uid, 1, NULL);
Expand Down Expand Up @@ -315,6 +320,15 @@ int module_start(SceSize argc, const void *args) {
g_hooks[13] = taiHookFunctionImportForKernel(KERNEL_PID, &g_hookrefs[13],
"SceProcessmgr", 0x887F19D0, 0x414CC813, ksceKernelInvokeProcEventHandler_patched);

g_hooks[14] = taiHookFunctionExportForKernel(KERNEL_PID, &g_hookrefs[14],
"ScePower", 0x1082DA7F, 0xABC6F88F, scePowerGetArmClockFrequency_patched);
g_hooks[15] = taiHookFunctionExportForKernel(KERNEL_PID, &g_hookrefs[15],
"ScePower", 0x1082DA7F, 0x478FE6F5, scePowerGetBusClockFrequency_patched);
g_hooks[16] = taiHookFunctionExportForKernel(KERNEL_PID, &g_hookrefs[16],
"ScePower", 0x1082DA7F, 0x1B04A1D6, scePowerGetGpuClockFrequency_patched);
g_hooks[17] = taiHookFunctionExportForKernel(KERNEL_PID, &g_hookrefs[17],
"ScePower", 0x1082DA7F, 0x0A750DEE, scePowerGetGpuXbarClockFrequency_patched);

ret = module_get_export_func(KERNEL_PID,
"SceKernelModulemgr", 0xC445FA63, 0x20A27FA9, (uintptr_t *)&_ksceKernelGetProcessMainModule); // 3.60
if (ret < 0) {
Expand Down
10 changes: 10 additions & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@
return ret; \
}

#define DECL_FUNC_HOOK_PATCH_FREQ_GETTER(index, name, device) \
static int name##_patched() { \
uint32_t state; \
ENTER_SYSCALL(state); \
TAI_CONTINUE(int, g_hookrefs[(index)]); \
int freq = psvs_oc_get_freq((device)); \
EXIT_SYSCALL(state); \
return freq; \
}

extern char g_titleid[32];
extern bool g_is_in_pspemu;

Expand Down

0 comments on commit 9adb460

Please sign in to comment.