Repository navigation
Expand file tree
/
Copy pathmain.c
More file actions
executable file
Β·208 lines (178 loc) Β· 8.04 KB
/
Copy pathmain.c
File metadata and controls
executable file
Β·208 lines (178 loc) Β· 8.04 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*
* this file is part of Game Categories Lite
*
* Copyright (C) 2011 Bubbletune
* Copyright (C) 2011 Codestation
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <pspsdk.h>
#include <pspkernel.h>
#include <string.h>
#include "categories_lite.h"
#include "psppaf.h"
#include "gcpatches.h"
#include "pspdefs.h"
#include "config.h"
#include "logger.h"
#include "vshitem.h"
// change the module name back to GCLite once PRO stops doing weird things with plugins
PSP_MODULE_INFO("Game_Categories_Light", 0x0807, 1, 5);
PSP_NO_CREATE_MAIN_THREAD();
/* Global variables */
int patch_index;
int model;
int game_plug = 0;
int sysconf_plug = 0;
/* Set when the XMB Item Hider plugin (module name "XMBIH") starts. GC Lite is
required to be first in vsh.txt, so our start-module handler sees XMBIH load
(when it's enabled) before the XMB builds its columns. vshitem.c's
xmbih_is_active() reads this flag instead of probing a fixed vsh address or
walking the module list -- both of which fault on Adrenaline/Epinephrine <=7
(out-of-bounds vsh read / module-walk race during boot). Value 0 = XMBIH not
loaded (or not enabled) -> XMBIH-compat shift disabled, no unsafe probe. */
int g_xmbih_present = 0;
/* Adrenaline (PSP-emu on PS Vita) detection, via Epinephrine's EPI-XmbControl
module. Adrenaline's "System Storage" (ef0:) is opened with the normal Memory
Stick game action, not the PSP-Go internal-storage action -- so the ef0
handling in vshitem.c/gcread.c is gated on this to leave real PSP-Go hardware
untouched. Detected LAZILY on first use (gc_adrenaline()) rather than at
vsh_module load: walking the module list during the vsh_module start handler
(GC Lite must be first in vsh.txt, so it runs at a delicate point) crashed the
XMB before it built. -1 = not yet detected. */
int g_adrenaline = -1;
int gc_adrenaline(void) {
if (g_adrenaline < 0) {
/* kuKernelFindModuleByName fills the kernel's OWN SceModule, which on
6.61 is larger than our (or the SDK's) truncated SceModule2 typedef.
Copying it into a right-sized struct overflowed the buffer -- harmless
on hidexmb's stack copy, but here (static BSS) it smashed adjacent
globals and corrupted later ef0/EPI operations. Give it generous
slack so the copy can never overflow. */
static char epi[1024];
g_adrenaline = (kuKernelFindModuleByName("EPI-XmbControl", (SceModule2 *)epi) >= 0);
kprintf("adrenaline (EPI-XmbControl) present: %i\n", g_adrenaline);
}
return g_adrenaline;
}
char currfw[5];
//TODO: remove it from here
u32 text_addr_game;
u32 text_size_game;
/* Captured in OnModuleStart's vsh_module branch; used by vshitem.c's
load_xmbih_shift to probe vshmain for XMBIH's patch signature. */
u32 vsh_text_addr = 0;
/* vsh_module's text size, so the XMBIH probe can bounds-check its read instead
of trusting a fixed offset to be inside whatever vshmain is mapped. */
u32 vsh_text_size = 0;
static STMOD_HANDLER previous;
int OnModuleStart(SceModule2 *mod) {
//kprintf(">> %s: loading %s, text_addr: %08X\n", __func__, mod->modname, mod->text_addr);
/* Note XMBIH's presence the moment it loads -- cheap strcmp, no module walk
or vsh read (both unsafe on EPI <=7). */
if (sce_paf_private_strcmp(mod->modname, "XMBIH") == 0) {
g_xmbih_present = 1;
kprintf("EPI7-DIAG: XMBIH module detected at load\n");
}
if (sce_paf_private_strcmp(mod->modname, "game_plugin_module") == 0) {
kprintf("loading %s, text_addr: %08X\n", mod->modname, mod->text_addr);
game_plug = 1;
//TODO: remove it from here
text_addr_game = mod->text_addr;
text_size_game = mod->text_size;
PatchGamePluginForGCread(mod->text_addr);
if(config.mode == MODE_FOLDER) {
PatchSelection(mod->text_addr);
}
ClearCaches();
} else if (sce_paf_private_strcmp(mod->modname, "vsh_module") == 0) {
kprintf("loading %s, text_addr: %08X\n", mod->modname, mod->text_addr);
vsh_text_addr = mod->text_addr;
vsh_text_size = mod->text_size; /* bounds-check for xmbih_is_active() */
PatchVshmain(mod->text_addr);
PatchVshmainForSysconf(mod->text_addr);
PatchVshmainForContext(mod->text_addr);
/* Make sceKernelGetCompiledSdkVersion clear the caches,
so that we don't have to create a kernel module just
to be able to clear the caches from user mode.*/
//6.20: 0xFC114573 [0x00009B0C] - SysMemUserForUser_FC114573
//6.35: 0xFC114573 [0x000099EC] - SysMemUserForUser_FC114573
//6.60: 0xFC114573 [0x000098B0] - SysMemUserForUser_FC114573
kprintf("Patching sceKernelGetCompiledSdkVersion, index: %i\n", patch_index);
MAKE_JUMP(patches.get_compiled_sdk_version[patch_index], ClearCaches);
ClearCaches();
} else if (sce_paf_private_strcmp(mod->modname, "sysconf_plugin_module") == 0) {
kprintf("loading %s, text_addr: %08X\n", mod->modname, mod->text_addr);
sysconf_plug = 1;
PatchSysconf(mod->text_addr);
ClearCaches();
} else if (sce_paf_private_strcmp(mod->modname, "scePaf_Module") == 0) {
kprintf("loading %s, text_addr: %08X\n", mod->modname, mod->text_addr);
PatchPaf(mod->text_addr);
PatchPafForSysconf(mod->text_addr);
ClearCaches();
} else if (sce_paf_private_strcmp(mod->modname, "sceVshCommonGui_Module") == 0) {
kprintf("loading %s, text_addr: %08X\n", mod->modname, mod->text_addr);
PatchVshCommonGui(mod->text_addr);
ClearCaches();
}
return previous ? previous(mod) : 0;
}
int module_start(SceSize args UNUSED, void *argp UNUSED) {
#if defined(DEBUG) && GCLITE_LOGGING
const char *src = "xx0:/category_lite.log";
static const char build_id[] =
"Game Categories Lite FOLDER-JAL-FIX-14-NOLOG starting\n";
char *dest = filebuf;
#endif
model = kuKernelGetModel();
#if defined(DEBUG) && GCLITE_LOGGING
while((*dest++ = *src++)) {
/* copy */
}
SET_DEVICENAME(filebuf, model == 4 ? INTERNAL_STORAGE : MEMORY_STICK);
// paf isn't loaded yet
kwrite(filebuf, build_id, sizeof(build_id) - 1);
#endif
// Determine fw group
u32 devkit = sceKernelDevkitVersion();
if (devkit == 0x06020010) {
patch_index = FW_620;
ResolveNIDs(FW_620);
} else if (devkit >= 0x06030010 && devkit < 0x06040010) {
patch_index = FW_630;
} else if (devkit >= 0x06060010 && devkit < 0x06070010) {
patch_index = FW_660;
ResolveNIDs(FW_660);
} else {
return 1;
}
currfw[0] = ((devkit >> 24) & 0xF) + '0';
currfw[1] = '.';
currfw[2] = ((devkit >> 16) & 0xF) + '0';
currfw[3] = ((devkit >> 8) & 0xF) + '0';
currfw[4] = 0;
/* Resolve the fake VSH region NOW, from the safe early context this helper
was written for -- it was defined but never actually called, which went
unnoticed while xmbih.state short-circuited load_xmbih_shift() before it
could reach extras_hidden_by_fake_region(). With the state file gone the
ini-derivation path always runs, so the first sctrlHENFindFunction /
GetSEConfigEx call would otherwise land inside the vsh item build, where
it faults on Adrenaline/Epinephrine <=7 (hardware: CL enabled crashed
Adrenaline 7, 2026-08-29). The result is cached, so the later call is just
a flag read. Safe no-op on firmwares where it already worked. */
gc_prime_xmbih_detection();
previous = sctrlHENSetStartModuleHandler(OnModuleStart);
return 0;
}