From c205719686e72e3787dc5aa146d4a939c13c3a18 Mon Sep 17 00:00:00 2001 From: JoseAaronLopezGarcia Date: Tue, 3 Dec 2024 19:20:07 +0100 Subject: [PATCH] added usbcam patches by isage --- Makefile | 4 +- core/compat/pentazemin/Makefile | 7 +- core/compat/pentazemin/imports.S | 12 +- core/compat/pentazemin/syspatch.c | 5 + core/compat/pentazemin/usbcam.c | 274 ++++++++++++++++++++++++++++++ 5 files changed, 296 insertions(+), 6 deletions(-) create mode 100644 core/compat/pentazemin/usbcam.c diff --git a/Makefile b/Makefile index fa76e413..e7b629f2 100644 --- a/Makefile +++ b/Makefile @@ -342,11 +342,11 @@ clean: $(Q)$(MAKE) $@ -C loader/perma/cipl/new/ipl_stage2_payload $(Q)$(MAKE) $@ K=sceUID -C loader/live/kernel/kxploit $(Q)$(MAKE) $@ K=sceSdGetLastIndex -C loader/live/kernel/kxploit + $(Q)$(PYTHON) contrib/PC/scripts/cleandeps.py + $(Q)find -name 'THEME.ARK' -exec rm {} \; $(Q)rm -f extras/apps/updater/ARK_01234.PKG | true $(Q)rm -f extras/apps/updater/EBOOT_PSP.PBP | true $(Q)rm -f extras/apps/updater/EBOOT_GO.PBP | true - $(Q)$(PYTHON) contrib/PC/scripts/cleandeps.py - $(Q)find -name 'THEME.ARK' -exec rm {} \; $(Q)rm -f extras/menus/arkMenu/LANG.ARK $(Q)rm -rf loader/vpk/bin/save/ARK_01234 $(Q)rm -f loader/vpk/bin/psx/ps1cfw_enabler.suprx diff --git a/core/compat/pentazemin/Makefile b/core/compat/pentazemin/Makefile index 1111e278..bbec8b9b 100644 --- a/core/compat/pentazemin/Makefile +++ b/core/compat/pentazemin/Makefile @@ -1,8 +1,9 @@ TARGET = pentazemin -C_OBJS = \ - main.o \ - funcs.o \ +C_OBJS = \ + main.o \ + funcs.o \ + usbcam.o \ vitamem.o \ syspatch.o \ io_patch.o \ diff --git a/core/compat/pentazemin/imports.S b/core/compat/pentazemin/imports.S index 6c615f63..214d4b9e 100644 --- a/core/compat/pentazemin/imports.S +++ b/core/compat/pentazemin/imports.S @@ -4,4 +4,14 @@ IMPORT_START "SystemCtrlPrivate",0x00090000 IMPORT_FUNC "SystemCtrlPrivate",0x5D7817CF,msstorCacheInit - IMPORT_FUNC "SystemCtrlPrivate",0x272984FD,isSystemBooted \ No newline at end of file + IMPORT_FUNC "SystemCtrlPrivate",0x272984FD,isSystemBooted + + IMPORT_START "sceUsbCam",0x40090000 + IMPORT_FUNC "sceUsbCam",0x3F0CF289,sceUsbCamSetupStill + IMPORT_FUNC "sceUsbCam",0x17F7B2FB,sceUsbCamSetupVideo + IMPORT_FUNC "sceUsbCam",0x03ED7A82,sceUsbCamSetupMic + IMPORT_FUNC "sceUsbCam",0x3DC0088E,sceUsbCamReadMic + + IMPORT_START "sceUsb_driver",0x00090011 + IMPORT_FUNC "sceUsb_driver",0x63E55EBE,sceUsb_driver_0x63E55EBE + IMPORT_FUNC "sceUsb_driver",0xED8C8695,sceUsb_driver_0xED8C8695 \ No newline at end of file diff --git a/core/compat/pentazemin/syspatch.c b/core/compat/pentazemin/syspatch.c index 1f7e425e..bd113dca 100644 --- a/core/compat/pentazemin/syspatch.c +++ b/core/compat/pentazemin/syspatch.c @@ -380,6 +380,11 @@ void AdrenalineOnModuleStart(SceModule2 * mod){ goto flush; } + if (strcmp(mod->modname, "sceUSBCam_Driver") == 0) { + patchUsbCam(mod); + goto flush; + } + if (strcmp(mod->modname, "sceImpose_Driver") == 0) { PatchImposeDriver(mod->text_addr); // perfect time to apply extra memory patch diff --git a/core/compat/pentazemin/usbcam.c b/core/compat/pentazemin/usbcam.c new file mode 100644 index 00000000..90efa9ac --- /dev/null +++ b/core/compat/pentazemin/usbcam.c @@ -0,0 +1,274 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "functions.h" +#include "macros.h" + +typedef struct PspUsbCamSetupMicParam { + int size; + int alc; + int gain; + int noize; + int freq; +} PspUsbCamSetupMicParam; + +typedef struct PspUsbCamSetupMicExParam { + int size; + int alc; + int gain; + u32 unk2[4]; // noize/hold/decay/attack? + int freq; + int unk3; +} PspUsbCamSetupMicExParam; + +void sceUsb_driver_0xED8C8695(); +void sceUsb_driver_0x63E55EBE(); +int sceUsbCamSetupMic(void *param, void *workarea, int wasize); + +int (* _sceUsbCamSetEvLevel)(int level); +int (* _sceUsbCamStillInput)(u8 *buf, SceSize size); +int (* _sceUsbCamReadMic)(void *buf, SceSize size); +int (* _sceUsbCamWaitReadMicEnd)(void); +int (* _sceUsbCamSetupMic)(void *param, void *workarea, int wasize); +int (* _sceUsbCamReadVideoFrame)(u8 *buf, SceSize size); +int (* _sceUsbCamWaitReadVideoFrameEnd)(void); + +static int dummy_read_cam = 0; +static int mute_mic = 0; +static void* mic_buf = NULL; +static SceSize mic_size = 0; + +int sceUsbCamStillInput_Patched(u8 *buf, SceSize size) { + int k1 = pspSdkSetK1(0); + int ret = _sceUsbCamStillInput(buf, size); + sceUsb_driver_0xED8C8695(); // force camera stop + + pspSdkSetK1(k1); + + return ret; +} + +int sceUsbCamSetupStillEx_Patched(PspUsbCamSetupStillExParam *exparam) { + int res = 0; + + int k1 = pspSdkSetK1(0); + + PspUsbCamSetupStillParam param = {0}; + param.size = sizeof(PspUsbCamSetupStillParam); + switch(exparam->resolution) + { + case 0: + param.resolution = 0; + break; + case 1: + param.resolution = 1; + break; + case 2: + param.resolution = 2; + break; + case 3: + param.resolution = 3; + break; + case 4: + param.resolution = 8; + break; + case 5: + param.resolution = 7; + break; + case 6: + param.resolution = 4; + break; + case 7: + param.resolution = 5; + break; + case 8: + // Vita camera doesn't support 1280x960 + param.resolution = 7; + //param.resolution = 6; + break; + } + + param.jpegsize = exparam->jpegsize; + param.complevel = exparam->complevel; + param.delay = exparam->delay; + param.reverseflags = 0x101; + + res = sceUsbCamSetupStill(¶m); + + sceUsb_driver_0x63E55EBE(); // force camera start + + pspSdkSetK1(k1); + + return res; +} + +int sceUsbCamSetupVideoEx_Patched(PspUsbCamSetupVideoExParam *exparam, void *workarea, int wasize) { + int res = 0; + + int k1 = pspSdkSetK1(0); + + PspUsbCamSetupVideoParam param = {0}; + param.size = sizeof(PspUsbCamSetupVideoParam); + switch(exparam->resolution) + { + case 0: + param.resolution = 0; + break; + case 1: + param.resolution = 1; + break; + case 2: + param.resolution = 2; + break; + case 3: + param.resolution = 3; + break; + case 4: + param.resolution = 8; + break; + case 5: + param.resolution = 7; + break; + case 6: + param.resolution = 4; + break; + case 7: + param.resolution = 5; + break; + case 8: + // Vita camera doesn't support 1280x960 + param.resolution = 7; +// param.resolution = 6; + break; + } + + param.framerate = exparam->framerate; + param.wb = exparam->wb; + param.saturation = exparam->saturation; + param.brightness = exparam->brightness; + param.contrast = exparam->contrast; + param.sharpness = exparam->sharpness; + param.effectmode = exparam->effectmode; + param.framesize = exparam->framesize; + param.evlevel = exparam->evlevel; + + res = sceUsbCamSetupVideo(¶m, workarea, wasize); + + pspSdkSetK1(k1); + + return res; +} + +int sceUsbCamReadMic_Patched(void *buf, SceSize size) { + int k1 = pspSdkSetK1(0); + int res = _sceUsbCamReadMic(buf, size); + mic_buf = buf; + mic_size = size; + pspSdkSetK1(k1); + return res; +} + +int sceUsbCamWaitReadMicEnd_Patched() { + int k1 = pspSdkSetK1(0); + int res = _sceUsbCamWaitReadMicEnd(); + if (mute_mic && mic_buf) + { + memset(mic_buf, 0, mic_size); + } + pspSdkSetK1(k1); + return res; +} + +int sceUsbCamSetupMic_Patched(void *param, void *workarea, int wasize) +{ + int res = 0; + int k1 = pspSdkSetK1(0); + res = _sceUsbCamSetupMic(param, workarea, wasize); + pspSdkSetK1(k1); + mute_mic = 0; + return res; + +} + +int sceUsbCamSetupMicEx_Patched(PspUsbCamSetupMicExParam *exparam, void *workarea, int wasize) { + int res = 0; + + // TODO: xmb wants 22050, but it causes crash for some reason + // TODO: pspemu resampler looks broken (see invizimals voice chat, for example) + int k1 = pspSdkSetK1(0); + PspUsbCamSetupMicParam param = {0}; + param.size = sizeof(PspUsbCamSetupMicParam); + param.alc = exparam->alc; + param.gain = exparam->gain; + param.freq = 11025;//exparam->freq; + + res = _sceUsbCamSetupMic(¶m, workarea, wasize); + + pspSdkSetK1(k1); + + mute_mic = 1; + + return res; +} + +int sceUsbCamSetEvLevel_Patched(int level) +{ + int res = 0; + int k1 = pspSdkSetK1(0); + dummy_read_cam = 1; + sceKernelDelayThread(100000); + res = _sceUsbCamSetEvLevel(level); + sceKernelDelayThread(100000); + dummy_read_cam = 0; + sceKernelDelayThread(100000); + pspSdkSetK1(k1); + return res; +} + +int sceUsbCamReadVideoFrame_Patched(u8 *buf, SceSize size) +{ + int k1 = pspSdkSetK1(0); + + if (dummy_read_cam) + { + sceKernelDelayThread(300000); + pspSdkSetK1(k1); + return 0; + } + int res = _sceUsbCamReadVideoFrame(buf, size); + pspSdkSetK1(k1); + return res; +} + +int sceUsbCamWaitReadVideoFrameEnd_Patched() +{ + int k1 = pspSdkSetK1(0); + if (dummy_read_cam) + { + sceKernelDelayThread(300000); + pspSdkSetK1(k1); + return 0x8000; + } + int res = _sceUsbCamWaitReadVideoFrameEnd(); + pspSdkSetK1(k1); + return res; +} + +void patchUsbCam(SceModule2* mod){ + REDIRECT_FUNCTION(sctrlHENFindFunction(mod->modname, "sceUsbCam", 0x0A41A298), sceUsbCamSetupStillEx_Patched); + REDIRECT_FUNCTION(sctrlHENFindFunction(mod->modname, "sceUsbCam", 0xCFE9E999), sceUsbCamSetupVideoEx_Patched); + REDIRECT_FUNCTION(sctrlHENFindFunction(mod->modname, "sceUsbCam", 0x2E930264), sceUsbCamSetupMicEx_Patched); + HIJACK_FUNCTION(sctrlHENFindFunction(mod->modname, "sceUsbCam", 0xFB0A6C5D), sceUsbCamStillInput_Patched, _sceUsbCamStillInput); + HIJACK_FUNCTION(sctrlHENFindFunction(mod->modname, "sceUsbCam", 0x1D686870), sceUsbCamSetEvLevel_Patched, _sceUsbCamSetEvLevel); + HIJACK_FUNCTION(sctrlHENFindFunction(mod->modname, "sceUsbCam", 0x99D86281), sceUsbCamReadVideoFrame_Patched, _sceUsbCamReadVideoFrame); + HIJACK_FUNCTION(sctrlHENFindFunction(mod->modname, "sceUsbCam", 0xF90B2293), sceUsbCamWaitReadVideoFrameEnd_Patched, _sceUsbCamWaitReadVideoFrameEnd); + HIJACK_FUNCTION(sctrlHENFindFunction(mod->modname, "sceUsbCam", 0x3DC0088E), sceUsbCamReadMic_Patched, _sceUsbCamReadMic); + HIJACK_FUNCTION(sctrlHENFindFunction(mod->modname, "sceUsbCam", 0x03ED7A82), sceUsbCamSetupMic_Patched, _sceUsbCamSetupMic); + HIJACK_FUNCTION(sctrlHENFindFunction(mod->modname, "sceUsbCam", 0xB048A67D), sceUsbCamWaitReadMicEnd_Patched, _sceUsbCamWaitReadMicEnd); +} \ No newline at end of file