diff --git a/include/hooks.h b/include/hooks.h index e719d15..2da66ed 100644 --- a/include/hooks.h +++ b/include/hooks.h @@ -25,13 +25,14 @@ #include "../include/pib.h" #include -#define NUM_HOOKS 19 +#define NUM_HOOKS 20 extern tai_hook_ref_t hookRef[NUM_HOOKS]; extern SceUID hook[NUM_HOOKS]; extern int customResolutionMode; extern tai_module_info_t modInfo; extern int systemMode; +extern int isCreatingSurface; void loadHooks(PibOptions options); void releaseHooks(void); diff --git a/include/patches.h b/include/patches.h index b3ccc55..c4a57d3 100644 --- a/include/patches.h +++ b/include/patches.h @@ -47,4 +47,11 @@ SceGxmErrorCode sceGxmDepthStencilSurfaceInit_msaaPatch(SceGxmDepthStencilSurfac uint32_t strideInSamples, void *depthData, void *stencilData); +SceGxmErrorCode sceGxmShaderPatcherCreateFragmentProgram_msaaPatch(SceGxmShaderPatcher *shaderPatcher, + SceGxmShaderPatcherId programId, + SceGxmOutputRegisterFormat outputFormat, + SceGxmMultisampleMode multisampleMode, + const SceGxmBlendInfo *blendInfo, + const SceGxmProgram *vertexProgram, + SceGxmFragmentProgram **fragmentProgram); #endif /* PATCHES_H_ */ diff --git a/src/hooks.c b/src/hooks.c index 274fc5f..f0994b1 100644 --- a/src/hooks.c +++ b/src/hooks.c @@ -56,9 +56,10 @@ void loadHooks(PibOptions options) hook[6] = taiHookFunctionOffset(&hookRef[6], modInfo.modid, 0, 0x158F8, 1, pglDisplaySetSwapInterval_intervalPatch); hook[7] = taiHookFunctionImport(&hookRef[7], modInfo.name, 0x5ED8F994, 0x5795E898, sceDisplayWaitVblankStart_intervalPatch); LOG("Swap interval Patch: 0x%08x\nWaitVblankStart Patch: 0x%08X\n", hook[5], hook[6]); - if ((options & PIB_SYSTEM_MODE) || (options & PIB_ENABLE_MSAA)) + if ((options & PIB_SYSTEM_MODE) || (options & PIB_ENABLE_MSAA)) { hook[8] = taiHookFunctionOffset(&hookRef[8], modInfo.modid, 0, 0x17d24, 1, pglMemoryAllocAlign_patch); - LOG("pglMemoryAllocAlign Patch: 0x%08x\n", hook[8]); + hook[10] = taiHookFunctionOffset(&hookRef[10], modInfo.modid, 0, 0x33074, 1, pglPlatformSurfaceCreateWindow_detect); + } if (options & PIB_SYSTEM_MODE) { systemMode = 1; uint8_t cbnz_opcode = 0xB9; @@ -67,7 +68,6 @@ void loadHooks(PibOptions options) taiInjectData(modInfo.modid, 0, 0x2D2C0, &mem_mode_two, sizeof(mem_mode_two)); // Patch pglVitaMemoryAlloc to always use MAIN memblock taiInjectData(modInfo.modid, 0, 0x2D1DC, &mem_mode_two, sizeof(mem_mode_two)); // hook[9] = taiHookFunctionImport(&hookRef[9], modInfo.name, 0xF76B66BD, 0xB0F1E4EC, sceGxmInitialize_patch); - hook[10] = taiHookFunctionOffset(&hookRef[10], modInfo.modid, 0, 0x33074, 1, pglPlatformSurfaceCreateWindow_detect); hook[11] = taiHookFunctionImport(&hookRef[11], modInfo.name, 0xF76B66BD, 0x6A6013E1, sceGxmSyncObjectCreate_patch); hook[12] = taiHookFunctionOffset(&hookRef[12], modInfo.modid, 0, 0x2A85A, 1, pglPlatformContextBeginFrame_patch); hook[13] = taiHookFunctionOffset(&hookRef[13], modInfo.modid, 0, 0x33902, 1, pglPlatformSurfaceSwap_patch); @@ -77,7 +77,8 @@ void loadHooks(PibOptions options) if (options & PIB_ENABLE_MSAA) { hook[16] = taiHookFunctionImport(&hookRef[16], modInfo.name, 0xF76B66BD, 0xED0F6E25, sceGxmColorSurfaceInit_msaaPatch); hook[17] = taiHookFunctionImport(&hookRef[17], modInfo.name, 0xF76B66BD, 0x207AF96B, sceGxmCreateRenderTarget_msaaPatch); - hook[18] = taiHookFunctionImport(&hookRef[18], modInfo.name, 0xF76B66BD, 0xCA9D41D1, sceGxmCreateRenderTarget_msaaPatch); + hook[18] = taiHookFunctionImport(&hookRef[18], modInfo.name, 0xF76B66BD, 0xCA9D41D1, sceGxmDepthStencilSurfaceInit_msaaPatch); + hook[19] = taiHookFunctionImport(&hookRef[19], modInfo.name, 0xF76B66BD, 0x4ED2E49D, sceGxmShaderPatcherCreateFragmentProgram_msaaPatch); LOG("MSAA ENABLED!\n"); } } diff --git a/src/patches.c b/src/patches.c index 0f507ab..0fb776b 100644 --- a/src/patches.c +++ b/src/patches.c @@ -179,7 +179,7 @@ SceGxmErrorCode sceGxmCreateRenderTarget_msaaPatch(const SceGxmRenderTargetParam renderTargetParams.flags = 0; renderTargetParams.width = params->width; renderTargetParams.height = params->height; - renderTargetParams.multisampleMode = SCE_GXM_MULTISAMPLE_4X; + renderTargetParams.multisampleMode = isCreatingSurface ? SCE_GXM_MULTISAMPLE_4X : SCE_GXM_MULTISAMPLE_NONE; renderTargetParams.scenesPerFrame = 1; renderTargetParams.multisampleLocations = 0; renderTargetParams.driverMemBlock = -1; @@ -193,6 +193,19 @@ SceGxmErrorCode sceGxmDepthStencilSurfaceInit_msaaPatch(SceGxmDepthStencilSurfac void *depthData, void *stencilData) { - strideInSamples *= 2; + if (isCreatingSurface) + strideInSamples *= 2; return TAI_CONTINUE(SceGxmErrorCode, hookRef[18], surface, depthStencilFormat, surfaceType, strideInSamples, depthData, stencilData); -} \ No newline at end of file +} + +SceGxmErrorCode sceGxmShaderPatcherCreateFragmentProgram_msaaPatch(SceGxmShaderPatcher *shaderPatcher, + SceGxmShaderPatcherId programId, + SceGxmOutputRegisterFormat outputFormat, + SceGxmMultisampleMode multisampleMode, + const SceGxmBlendInfo *blendInfo, + const SceGxmProgram *vertexProgram, + SceGxmFragmentProgram **fragmentProgram) +{ + multisampleMode = SCE_GXM_MULTISAMPLE_4X; + return TAI_CONTINUE(SceGxmErrorCode, hookRef[19], shaderPatcher, programId, outputFormat, multisampleMode, blendInfo, vertexProgram, fragmentProgram); +} diff --git a/src/sysmodepatch.c b/src/sysmodepatch.c index 19460c1..8148901 100644 --- a/src/sysmodepatch.c +++ b/src/sysmodepatch.c @@ -55,8 +55,9 @@ typedef struct SceSharedFbInfo { // size is 0x58 static SceSharedFbInfo info; static SceUID shfb_id; static void *displayBufferData[2]; -static int isCreatingSurface, isDestroyingSurface, currentContext, framebegun = 0; +static int isDestroyingSurface, currentContext, framebegun = 0; static unsigned int bufferDataIndex; +int isCreatingSurface; SceGxmErrorCode sceGxmInitialize_patch(const SceGxmInitializeParams *params) { @@ -96,7 +97,7 @@ unsigned int pglMemoryAllocAlign_patch(int memoryType, int size, int unused, int memory[0] = displayBufferData[bufferDataIndex]; return 0; } - if (!systemMode && memoryType == 5) + if (!systemMode && memoryType == 5 && isCreatingSurface) { size *= 4; // For MSAA }