forked from Rinnegatamante/vitaRescale
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
104 lines (83 loc) · 3.12 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <libk/string.h>
#include <libk/stdio.h>
#include <libk/ctype.h>
#include <vitasdk.h>
#include <taihen.h>
#include "renderer.h"
#define HOOKS_NUM 1 // Hooked functions num
static uint8_t current_hook;
static SceUID hooks[HOOKS_NUM], fd;
static tai_hook_ref_t refs[HOOKS_NUM];
static int timer = 0;
static char buf[128], fname[128], titleid[16];
static uint16_t w3d, h3d, wfb, hfb;
tai_module_info_t info = {0};
// Simplified generic hooking function
void hookFunction(uint32_t nid, const void *func){
hooks[current_hook] = taiHookFunctionImport(&refs[current_hook],TAI_MAIN_MODULE,TAI_ANY_LIBRARY,nid,func);
current_hook++;
}
// Patch game resolution functions
void patchPlainResolution(int seg, uint32_t addr, uint16_t w, uint16_t h){ // Plain resolution value
if ((!w) || (!h)) return;
taiInjectData(info.modid, seg, addr, &w, sizeof(uint16_t));
taiInjectData(info.modid, seg, addr+4, &h, sizeof(uint16_t));
timer = 200;
}
int sceDisplaySetFrameBuf_patched(const SceDisplayFrameBuf *pParam, int sync) {
// Updating renderer status
updateFramebuf(pParam);
// Drawing info on screen
if (timer > 0){
setTextColor(0x00FFFFFF);
if (w3d) drawStringF(5, 5, "3D Rendering: %hux%hu.", w3d, h3d);
else drawStringF(5, 5, "3D Rendering: Native");
if (wfb) drawStringF(5, 25, "Base Rendering: %hux%hu.", wfb, hfb);
else drawStringF(5, 25, "Base Rendering: Native");
timer--;
}
return TAI_CONTINUE(int, refs[0], pParam, sync);
}
int sceDisplaySetFrameBuf_patched2(const SceDisplayFrameBuf *pParam, int sync) {
// Updating renderer status
updateFramebuf(pParam);
// Drawing info on screen
setTextColor(0x00FFFFFF);
drawStringF(5, 5, "ERROR: 0x%08X", fd);
return TAI_CONTINUE(int, refs[0], pParam, sync);
}
void _start() __attribute__ ((weak, alias ("module_start")));
int module_start(SceSize argc, const void *args) {
// Getting eboot.bin info
info.size = sizeof(tai_module_info_t);
taiGetModuleInfo(TAI_MAIN_MODULE, &info);
// Getting desired resolution from config file
sceAppMgrAppParamGetString(0, 12, titleid , 256);
sprintf(fname, "app0:/vitaRescale.txt");
fd = sceIoOpen(fname, SCE_O_RDONLY, 0777);
if (fd >= 0){
int nbytes = sceIoRead(fd, buf, 128);
buf[nbytes] = 0;
sceIoClose(fd);
sscanf(buf,"%hux%hu;%hux%hu", &wfb, &hfb, &w3d, &h3d);
// Checking if game is patchable
if (strncmp(titleid, "PCSB00048", 9) == 0){ // Ridge Racer (EU)
patchPlainResolution(1, 0x53E0, w3d, h3d); // 3D Rendering
patchPlainResolution(1, 0x54A8, wfb, hfb); // SetFrameBuf params
patchPlainResolution(0, 0x1E7538, wfb, hfb); // ? (960x544 on retail game)
}else if (strncmp(titleid, "PCSB00861", 9) == 0){ // Digimon Story: Cybersleuth (EU)
patchPlainResolution(1, 0x77CC, wfb, hfb); // Full Rendering
w3d = wfb;
h3d = hfb;
}
hookFunction(0x7A410B64, sceDisplaySetFrameBuf_patched);
}else hookFunction(0x7A410B64, sceDisplaySetFrameBuf_patched2);
return SCE_KERNEL_START_SUCCESS;
}
int module_stop(SceSize argc, const void *args) {
// Freeing hooks
while (current_hook-- > 0){
taiHookRelease(hooks[current_hook], refs[current_hook]);
}
return SCE_KERNEL_STOP_SUCCESS;
}