aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c89
1 files changed, 83 insertions, 6 deletions
diff --git a/main.c b/main.c
index aa41cb2..acdb1de 100644
--- a/main.c
+++ b/main.c
@@ -19,6 +19,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <stdbool.h>
#include <string.h>
#include <psp2/display.h>
+#include <psp2/gxm.h>
#include <psp2/kernel/clib.h>
#include <psp2/kernel/modulemgr.h>
#include <psp2/kernel/processmgr.h>
@@ -38,6 +39,7 @@ extern int font_sfn_len;
#define MODE_720 0
#define MODE_1080 1
+#define MODE_544 2
#if PATCH_MODE == MODE_720
#pragma message "Compiling 1280x720"
@@ -49,6 +51,11 @@ extern int font_sfn_len;
#define FB_PITCH 1920
#define FB_WIDTH 1920
#define FB_HEIGHT 1080
+#elif PATCH_MODE == MODE_544
+ #pragma message "Compiling 960x544 MSAA 4x"
+ #define FB_PITCH 1024
+ #define FB_WIDTH 960
+ #define FB_HEIGHT 544
#else
#pragma GCC error "Invalid PATCH_MODE"
#endif
@@ -82,7 +89,7 @@ static struct {
#define N_INJECT 8
static SceUID inject_id[N_INJECT];
-#define N_HOOK 5
+#define N_HOOK 8
static SceUID hook_id[N_HOOK];
static tai_hook_ref_t hook_ref[N_HOOK];
@@ -100,6 +107,18 @@ static SceUID hook_import(int idx, char *mod, int libnid, int funcnid, void *fun
#define HOOK_IMPORT(idx, mod, libnid, funcnid, func)\
hook_import(idx, mod, libnid, funcnid, func##_hook)
+#if PATCH_MODE == MODE_544
+
+static SceUID hook_offset(int idx, int mod, int ofs, void *func) {
+ hook_id[idx] = taiHookFunctionOffset(hook_ref+idx, mod, 0, ofs, 1, func);
+ LOG("Hooked %d UID %08X\n", idx, hook_id[idx]);
+ return hook_id[idx];
+}
+#define HOOK_OFFSET(idx, mod, ofs, func)\
+ hook_offset(idx, mod, ofs, func##_hook)
+
+#endif
+
static int UNINJECT(int idx) {
int ret = 0;
if (inject_id[idx] >= 0) {
@@ -133,6 +152,8 @@ static int sceDisplaySetFrameBuf_hook(SceDisplayFrameBuf *fb, int mode) {
fb->height = FB_HEIGHT;
fnblit_set_fb(fb->base, fb->pitch, fb->width, fb->height);
+
+#if PATCH_MODE != MODE_544
if (failed) {
fb->width = 960;
fb->height = 544;
@@ -141,18 +162,22 @@ static int sceDisplaySetFrameBuf_hook(SceDisplayFrameBuf *fb, int mode) {
} else if (sceKernelGetProcessTimeLow() - start_time < 15 * 1000 * 1000) {
fnblit_printf(0, 0, "Persona 4 Golden HD Patch success: %dx%d", FB_WIDTH, FB_HEIGHT);
}
+#else
+ if (sceKernelGetProcessTimeLow() - start_time < 15 * 1000 * 1000) {
+ fnblit_printf(0, 0, "Persona 4 Golden HD Patch success: 960x544 MSAA 4x");
+ }
+#endif
+
}
int ret = TAI_NEXT(sceDisplaySetFrameBuf_hook, hook_ref[0], fb, mode);
-
- if (!failed && fb && fb->base && fb->pitch == FB_PITCH
- && fb->width == FB_WIDTH && fb->height == FB_HEIGHT) {
- failed = ret < 0;
- }
+ failed = failed || ret < 0;
return ret;
}
+#if PATCH_MODE != MODE_544
+
static int sceGxmSetUniformDataF_hook(
void *uniformBuffer,
void *parameter,
@@ -177,6 +202,46 @@ static int sceGxmSetUniformDataF_hook(
uniformBuffer, parameter, componentOffset, componentCount, sourceData);
}
+#else
+
+static int color_surface_init_1_hook(void *color_surface_ctx,
+ int color_format, int width, int height, int msaa,
+ int pitch, int pitch2, int scenes_per_frame) {
+
+ if (width == FB_WIDTH && height == FB_HEIGHT) {
+ msaa = SCE_GXM_MULTISAMPLE_4X;
+ }
+
+ return TAI_NEXT(color_surface_init_1_hook, hook_ref[5], color_surface_ctx,
+ color_format, width, height, msaa,
+ pitch, pitch2, scenes_per_frame);
+}
+
+static int color_surface_init_2_hook(void *color_surface_ctx,
+ int color_format, int width, int height, int msaa, int pitch,
+ int tex_height, int scenes_per_frame, void *color_data) {
+
+ if (width == FB_WIDTH && height == FB_HEIGHT) {
+ msaa = SCE_GXM_MULTISAMPLE_4X;
+ }
+
+ return TAI_NEXT(color_surface_init_2_hook, hook_ref[6], color_surface_ctx,
+ color_format, width, height, msaa, pitch,
+ tex_height, scenes_per_frame, color_data);
+}
+
+static int depth_surface_init_hook(void *depth_surface_ctx,
+ int format, int pitch, int height, int flags) {
+
+ pitch *= 2;
+ height *= 2;
+
+ return TAI_NEXT(depth_surface_init_hook, hook_ref[7], depth_surface_ctx,
+ format, pitch, height, flags);
+}
+
+#endif
+
#if PATCH_MODE == MODE_1080
static SceUID sceKernelAllocMemBlock_hook(char *name, int type, int size, void *opt) {
@@ -273,6 +338,8 @@ int module_start(SceSize argc, const void *argv) { (void)argc; (void)argv;
GLZ(INJECT_DATA(1, p4g_modid, 1, ofs_3dbuf + 4, (float[]){(float)FB_HEIGHT}, 4));
GLZ(INJECT_DATA(2, p4g_modid, 1, ofs_3dbuf + 8, (float[]){(float)FB_PITCH}, 4));
+#if PATCH_MODE != MODE_544
+
// main/UI buffer
uint16_t nop_nop[2] = {0xBF00, 0xBF00};
@@ -290,6 +357,16 @@ int module_start(SceSize argc, const void *argv) { (void)argc; (void)argv;
// fix scaling
GLZ(HOOK_IMPORT(1, P4G_MOD_NAME, 0xF76B66BD, 0x65DD0C84, sceGxmSetUniformDataF));
+#else
+
+ // multisample anti-aliasing
+
+ GLZ(HOOK_OFFSET(5, p4g_modid, ofs_instr + 0x270C, color_surface_init_1));
+ GLZ(HOOK_OFFSET(6, p4g_modid, ofs_instr + 0x25C0, color_surface_init_2));
+ GLZ(HOOK_OFFSET(7, p4g_modid, ofs_instr + 0x28A2, depth_surface_init));
+
+#endif
+
// memory management
#if PATCH_MODE == MODE_1080