#include <pspkernel.h>
#include <pspctrl.h>
#include <pspinit.h>
PSP_MODULE_INFO("ctrl_hook", 0x1000, 1, 1);
int (* GetCtrlsReal) (SceCtrlData *pad_data, int count) = NULL;
int GetCtrlsPatch(SceCtrlData* pad_data, int count)
{
int ret = GetCtrlsReal(pad_data, count);
int interrupts = pspSdkDisableInterrupts();
if(!sceKernelFindModuleByName("htmlviewer_plugin_module"))
{
sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
if(pad_data->Lx == 0)
pad_data->Buttons |= PSP_CTRL_LEFT;
if(pad_data->Lx == 255)
pad_data->Buttons |= PSP_CTRL_RIGHT;
if(pad_data->Ly == 0)
pad_data->Buttons |= PSP_CTRL_UP;
if(pad_data->Ly == 255)
pad_data->Buttons |= PSP_CTRL_DOWN;
};
pspSdkEnableInterrupts(interrupts);
return ret;
};
u32 PatchFunction(char *modname, char *libname, int nid, void *newFunc)
{
u32 addr = sctrlHENFindFunction(modname, libname, nid);
sctrlHENPatchSyscall(addr, newFunc);
return addr;
};
int main_thread(SceSize args, void *argp)
{
sceKernelDelayThread(3000000);
int keyConf = sceKernelInitKeyConfig();
if(keyConf == PSP_INIT_KEYCONFIG_VSH)
{
GetCtrlsReal = (void *)PatchFunction("sceVshBridge_Driver", "sceVshBridge", 0xC6395C03, GetCtrlsPatch);
}
else
{
GetCtrlsReal = (void *)PatchFunction("sceController_Service", "sceCtrl", 0x1F803938, GetCtrlsPatch);
PatchFunction("sceController_Service", "sceCtrl", 0x3A622550, GetCtrlsPatch);
};
sceKernelDcacheWritebackAll();
sceKernelIcacheClearAll();
return 0;
};
int module_start(SceSize args, void *argp)
{
int thid = 0;
thid = 0;
thid = sceKernelCreateThread("main_thread", main_thread, 25, 64 * 1024, 0, NULL);
if(thid >= 0)
sceKernelStartThread(thid, args, argp);
return 0;
};