-
Notifications
You must be signed in to change notification settings - Fork 15
/
selection.c
320 lines (265 loc) · 10.8 KB
/
selection.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
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
/*
Game Categories Light v 1.3
Copyright (C) 2011, Bubbletune
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 <psprtc.h>
#include "psppaf.h"
#include <string.h>
#include "categories_lite.h"
#include "logger.h"
/* Global variables */
static int already_in_foldermode = 1;
extern int by_category_mode;
extern u32 text_addr_game;
static void *GetSelectionArg;
static u32 sound_call_addr;
static int defaulted;
int ToggleCategoryMode(int mode);
void HijackGameClass(int items);
/* Function pointers */
int (*AddGameContext)(void *unk, SceGameContext **item);
SceGameContext *(*GetSelection)(void *arg0, u32 arg1);
int (*SetMode)(void *arg0, void *arg1, void *arg2);
int (*OnPushFolderOptionListCascade)(void *arg0, u32 *arg1);
int (*OnPushOptionListCascade)(void *arg0, u32 *arg1);
int (*scePafSetSelection)(void *arg0, int selection);
int (*vsh_function)(void *arg);
/* Functions */
void ToggleSound(int toggle)
{
kprintf("called, toggle: %i\n", toggle);
if (toggle == 0) {
sound_call_addr = U_EXTRACT_CALL(text_addr_game + patches.play_sound_call[patch_index]);
_sw(NOP_OPCODE, text_addr_game + patches.play_sound_call[patch_index]);
}
else {
MAKE_CALL(text_addr_game+patches.play_sound_call[patch_index], sound_call_addr);
}
ClearCachesForUser();
}
int AddGameContextPatched(void *unk, SceGameContext **item)
{
/* Allocate buffer for "By Category" */
SceGameContext *newitem = sce_paf_private_malloc(sizeof(SceGameContext));
sce_paf_private_memcpy(newitem, *item, sizeof(SceGameContext));
kprintf("called\n");
/* Modify buffer for "By Category */
newitem->text = "msg_by_category";
newitem->option = patches.OPTION_BY_CATEGORY[patch_index];
/* Add the option */
AddGameContext(unk, &newitem);
/* Add the original */
return AddGameContext(unk, item);
}
#define MODE_ALL 0
#define OPTION_BY_EXPIRE_DATE 0
int SetModePatched(void *arg0, void *arg1, void *arg2, u32 *info)
{
/** Square-button cycling **/
kprintf("called\n");
/* What's the current mode? */
if (info[patches.array_index[patch_index]] == MODE_ALL) {
/* All */
/* Next stop: By Expire Date */
info[patches.array_index[patch_index]] = patches.MODE_BY_EXPIRE_DATE[patch_index];
already_in_foldermode = 1;
} else if (info[patches.array_index[patch_index]] == patches.MODE_BY_EXPIRE_DATE[patch_index]) {
if (!by_category_mode) {
/* By Expire Date */
/* Next stop: By Category */
ToggleCategoryMode(1);
} else {
/* By Category */
/* Next stop: All */
ToggleCategoryMode(0);
info[patches.array_index[patch_index]] = MODE_ALL;
already_in_foldermode = 0;
}
}
return SetMode(arg0, arg1, arg2);
}
void QuickSwitchToAll(SceGameContext *selection, void *arg0, u32 *arg1)
{
kprintf("called\n");
u32 backup = selection->option;
/* Switch to "All" */
selection->option = 1;
/* Disable the click sound */
ToggleSound(0);
/* Call the function */
OnPushFolderOptionListCascade(arg0, arg1);
/* Enable the click sound */
ToggleSound(1);
/* Restore the original option */
selection->option = backup;
}
int OnPushFolderOptionListCascadePatched(void *arg0, u32 *arg1)
{
kprintf("called\n");
SceGameContext *selection = GetSelection(GetSelectionArg, arg1[3]);
kprintf("GetSelection returned, selection: %08X\n", selection);
/* We're in one of the folder modes in case this function is being used... */
/* Where do we want to go? */
if (selection->option == OPTION_BY_EXPIRE_DATE) {
kprintf("OPTION_BY_EXPIRE_DATE\n");
/* Check if we're already in there */
if (by_category_mode) {
kprintf("toggle category to 0\n");
/* Toggle "By Category" off */
ToggleCategoryMode(0);
/* We're not... */
if (already_in_foldermode) {
kprintf("calling QuickSwitchToAll #1\n");
/* Switch to "All" for a brief second */
QuickSwitchToAll(selection, arg0, arg1);
} else {
/* We are now! */
already_in_foldermode = 1;
}
}
}
else if (selection->option == patches.OPTION_BY_CATEGORY[patch_index]) {
int res;
kprintf("OPTION_BY_CATEGORY\n");
/* Check if we're already in there */
if (!by_category_mode) {
/* We're not... */
if (already_in_foldermode) {
kprintf("calling QuickSwitchToAll #2\n");
/* Switch to "All" for a brief second */
QuickSwitchToAll(selection, arg0, arg1);
} else {
/* We are now! */
already_in_foldermode = 1;
}
kprintf("toggle category to 1\n");
/* Toggle "By Category" on */
ToggleCategoryMode(1);
/** HINT: This mode doesn't *really* exist, so we need to simulate "By Expire Date" */
/* Switch to "By Expire Date" */
selection->option = OPTION_BY_EXPIRE_DATE;
kprintf("calling OnPushOptionListCascade\n");
/* Call the function */
res = OnPushOptionListCascade(arg0, arg1);
/* Restore the original */
selection->option = patches.OPTION_BY_CATEGORY[patch_index];
} else {
/* We are... */
/* But darn, you user! You opened a lame context menu! ): */
/* Now we need to fake another item just to make it dissappear */
kprintf("faking item\n");
/* Switch to "By Expire Date" */
selection->option = OPTION_BY_EXPIRE_DATE;
kprintf("calling OnPushFolderOptionListCascade\n");
/* Call the function */
res = OnPushFolderOptionListCascade(arg0, arg1);
/* Restore the original */
selection->option = patches.OPTION_BY_CATEGORY[patch_index];
}
return res;
} else { // OPTION_ALL && OPTION_BY_FORMAT
already_in_foldermode = 0;
}
kprintf("going out\n");
return OnPushFolderOptionListCascade(arg0, arg1);
}
int OnPushOptionListCascadePatched(void *arg0, u32 *arg1)
{
kprintf("called\n");
SceGameContext *selection = GetSelection(GetSelectionArg, arg1[3]);
/* We're in the "All" mode in case this function is being used... */
/* Where do we want to go? */
if (selection->option == OPTION_BY_EXPIRE_DATE) {
already_in_foldermode = 1;
/* Toggle "By Category" off */
ToggleCategoryMode(0);
} else if (selection->option == patches.OPTION_BY_CATEGORY[patch_index]) {
already_in_foldermode = 1;
/* Toggle "By Category" on */
ToggleCategoryMode(1);
/** HINT: This mode doesn't *really* exist, so we need to simulate "By Expire Date" */
/* Switch to "By Expire Date" */
selection->option = OPTION_BY_EXPIRE_DATE;
kprintf("Calling OnPushOptionListCascade\n");
/* Call the function */
int res = OnPushOptionListCascade(arg0, arg1);
kprintf("Called OnPushOptionListCascade, res: %i\n", res);
/* Restore the original */
selection->option = patches.OPTION_BY_CATEGORY[patch_index];
return res;
} else {
already_in_foldermode = 0;
}
return OnPushOptionListCascade(arg0, arg1);
}
int scePafSetSelectionPatched(void *arg0, int selection)
{
kprintf("called\n");
/* "By Expire Date" */
if (selection == 1) {
/* Should it be "By Category"? */
if (by_category_mode) {
selection = 2; // yes
}
}
return scePafSetSelection(arg0, selection);
}
int vsh_function_patched(void *arg)
{
if (!defaulted) {
ToggleCategoryMode(1);
_sw(patches.MODE_BY_EXPIRE_DATE[patch_index], text_addr_game + patches.current_mode[patch_index] + 56);
ClearCachesForUser();
defaulted = 1;
}
return vsh_function(arg);
}
void PatchSelection(u32 text_addr)
{
/* Patch AddGameContext */
MAKE_CALL(text_addr+patches.add_game_context_call[patch_index][0], AddGameContextPatched);
MAKE_CALL(text_addr+patches.add_game_context_call[patch_index][1], AddGameContextPatched);
AddGameContext = (void *) (text_addr + patches.add_game_context[patch_index]);
/* Patch calls to SetMode */
MAKE_CALL(text_addr+patches.setmode_call_arg_1[patch_index][0], SetModePatched);
_sw(patches.setmode_arg_opcode[patch_index], text_addr + patches.setmode_call_arg_1[patch_index][1]);
if (patches.setmode_call_arg_2[patch_index][0]) {
kprintf("patching SetMode\n");
MAKE_CALL(text_addr+patches.setmode_call_arg_2[patch_index][0], SetModePatched);
_sw(patches.setmode_arg_opcode[patch_index], text_addr + patches.setmode_call_arg_2[patch_index][1]);
}
/* Patch OnPushFolderOptionListCascade */
_sw((u32) OnPushFolderOptionListCascadePatched, text_addr + patches.on_push_folder_options_call[patch_index]);
OnPushFolderOptionListCascade = (void *) (text_addr + patches.on_push_folder_options[patch_index]);
/* Patch OnPushOptionListCascade */
_sw((u32) OnPushOptionListCascadePatched, text_addr + patches.on_push_options_call[patch_index]);
OnPushOptionListCascade = (void *) (text_addr + patches.on_push_options[patch_index]);
/* Additional function pointers */
GetSelection = (void *) (text_addr + patches.get_selection[patch_index]);
SetMode = (void *) (text_addr + patches.setmode[patch_index]);
/* Argument required for GetSelection */
GetSelectionArg = (void *) (text_addr + patches.get_selection_arg[patch_index]);
if (patches.set_selection_call[patch_index][0]) {
/* Patch scePafSetSelection */
scePafSetSelection = (void *)U_EXTRACT_CALL(text_addr+patches.set_selection_call[patch_index][0]);
MAKE_CALL(text_addr+patches.set_selection_call[patch_index][0], scePafSetSelectionPatched);
MAKE_CALL(text_addr+patches.set_selection_call[patch_index][1], scePafSetSelectionPatched);
}
defaulted = 0;
by_category_mode = 0;
vsh_function = (void *)U_EXTRACT_CALL(text_addr+0x12E0);
MAKE_CALL(text_addr+0x12E0, vsh_function_patched);
HijackGameClass(32);
}