Skip to content

Commit c16a611

Browse files
author
codestation
committed
4th batch of code for folder category.
1 parent c128b14 commit c16a611

File tree

8 files changed

+103
-84
lines changed

8 files changed

+103
-84
lines changed

Diff for: categories_lite.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,12 @@ void PatchVshmainForContext(u32 text_addr);
190190
void PatchGamePluginForGCread(u32 text_addr);
191191

192192
// Functions in: category.c
193-
int CountCategories(int location);
194-
void ClearCategories(int location);
195-
void AddCategory(const char *category, u64 mtime, int location);
196-
Category *GetNextCategory(Category *prev, int location);
197-
Category *FindCategory(const char *category, int location);
198-
void IndexCategories(const char *path, int location);
193+
int CountCategories(Category *head[], int location);
194+
void ClearCategories(Category *head[], int location);
195+
void AddCategory(Category *head[], const char *category, u64 mtime, int location);
196+
Category *GetNextCategory(Category *head[], Category *prev, int location);
197+
Category *FindCategory(Category *head[], const char *category, int location);
198+
void IndexCategories(Category *head[], const char *path, int location);
199199

200200
// Functions in: gcpatches.c
201201
void ResolveNIDs();

Diff for: category.c

+19-21
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727

2828
const char *eboot_types[] = { "EBOOT.PBP", "PARAM.PBP", "PBOOT.PBP" };
2929

30-
Category *first_category[2] = { NULL, NULL };
31-
32-
Category *GetNextCategory(Category *prev, int location) {
30+
Category *GetNextCategory(Category *head[], Category *prev, int location) {
3331
u64 time = 0, last;
3432
Category *newest = NULL;
3533

@@ -38,7 +36,7 @@ Category *GetNextCategory(Category *prev, int location) {
3836
} else {
3937
last = (u64) -1;
4038
}
41-
Category *p = (Category *) first_category[location];
39+
Category *p = (Category *) head[location];
4240

4341
while (p) {
4442
if (p->mtime < last) {
@@ -54,22 +52,22 @@ Category *GetNextCategory(Category *prev, int location) {
5452
return newest;
5553
}
5654

57-
void ClearCategories(int location) {
55+
void ClearCategories(Category *head[], int location) {
5856
Category *next;
59-
Category *p = (void *) first_category[location];
57+
Category *p = (void *) head[location];
6058

6159
while (p) {
6260
next = p->next;
6361
sce_paf_private_free(p);
6462
p = next;
6563
}
6664

67-
first_category[location] = NULL;
65+
head[location] = NULL;
6866
}
6967

70-
int CountCategories(int location) {
68+
int CountCategories(Category *head[], int location) {
7169
int i = 0;
72-
Category *p = (void *) first_category[location];
70+
Category *p = (void *) head[location];
7371

7472
while (p) {
7573
i++;
@@ -79,12 +77,12 @@ int CountCategories(int location) {
7977
return i;
8078
}
8179

82-
void AddCategory(const char *category, u64 mtime, int location) {
80+
void AddCategory(Category *head[], const char *category, u64 mtime, int location) {
8381
Category *p, *category_entry;
8482

8583
while (1) {
8684
p = NULL;
87-
while ((p = GetNextCategory(p, location))) {
85+
while ((p = GetNextCategory(head, p, location))) {
8886
if (sce_paf_private_strcmp(category, &p->name) == 0) {
8987
return;
9088
}
@@ -104,10 +102,10 @@ void AddCategory(const char *category, u64 mtime, int location) {
104102
category_entry->location = location;
105103
sce_paf_private_strcpy(&category_entry->name, category);
106104

107-
if (!first_category[location]) {
108-
first_category[location] = category_entry;
105+
if (!head[location]) {
106+
head[location] = category_entry;
109107
} else {
110-
p = (Category *) first_category[location];
108+
p = (Category *) head[location];
111109
while (p->next) {
112110
p = p->next;
113111
}
@@ -116,16 +114,16 @@ void AddCategory(const char *category, u64 mtime, int location) {
116114
}
117115
}
118116

119-
void DelCategory(char *category, int location) {
117+
void DelCategory(Category *head[], char *category, int location) {
120118
Category *prev = NULL;
121-
Category *p = (Category *) first_category[location];
119+
Category *p = (Category *) head[location];
122120

123121
while (p) {
124122
if (sce_paf_private_strcmp(&p->name, category) == 0) {
125123
if (prev) {
126124
prev->next = p->next;
127125
} else {
128-
first_category[location] = p->next;
126+
head[location] = p->next;
129127
}
130128
break;
131129
}
@@ -134,8 +132,8 @@ void DelCategory(char *category, int location) {
134132
}
135133
}
136134

137-
Category *FindCategory(const char *category, int location) {
138-
Category *p = (Category *) first_category[location];
135+
Category *FindCategory(Category *head[], const char *category, int location) {
136+
Category *p = (Category *) head[location];
139137
while(p) {
140138
if (sce_paf_private_strcmp(&p->name, category) == 0) {
141139
break;
@@ -158,7 +156,7 @@ int is_category(const char *base, const char *path) {
158156
return 1;
159157
}
160158

161-
void IndexCategories(const char *path, int location) {
159+
void IndexCategories(Category *head[], const char *path, int location) {
162160
SceIoDirent dir;
163161
SceUID fd;
164162
u64 mtime;
@@ -194,7 +192,7 @@ void IndexCategories(const char *path, int location) {
194192
match = 0;
195193
sceRtcGetTick((pspTime *) &dir.d_stat.st_mtime, &mtime);
196194
kprintf("Adding %s as category\n", dir.d_name);
197-
AddCategory(dir.d_name, mtime, location);
195+
AddCategory(head, dir.d_name, mtime, location);
198196
}
199197
}
200198
}

Diff for: context.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ int PatchAddVshItemForContext(void *arg, int topitem, SceVshItem *item, int loca
117117

118118
//TODO: mark location in original context
119119
item->play_sound = 0;
120-
int malloc_size = (CountCategories(location) + uncategorized) * sizeof(SceContextItem) + 1;
120+
int malloc_size = (CountCategories(cat_list, location) + uncategorized) * sizeof(SceContextItem) + 1;
121121
context_items[location] = sce_paf_private_malloc(malloc_size);
122122
sce_paf_private_memset(context_items[location], 0, malloc_size);
123123

124-
while ((p = GetNextCategory(p, location))) {
124+
while ((p = GetNextCategory(cat_list, p, location))) {
125125

126126
if(p->location == MEMORY_STICK) {
127127
sce_paf_private_snprintf(context_items[location][index].text, 48, "gcv_%08X", (u32)p);

Diff for: gcread.c

+60-45
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ extern int me_fw;
4343
SceUID game_dfd = -1;
4444
SceUID opened_dfd = -1;
4545
int uncategorized;
46+
extern Category *folder_list[1];
4647

4748
inline void trim(char *str) {
4849
int i = sce_paf_private_strlen(str);
@@ -83,7 +84,7 @@ int is_category_folder(SceIoDirent *dir, char *cat) {
8384
kprintf("checking %s\n", dir->d_name);
8485
if(FIO_S_ISDIR(dir->d_stat.st_mode)) {
8586
if(!cat) {
86-
if(!config.prefix && FindCategory(dir->d_name, global_pos)) {
87+
if(!config.prefix && FindCategory(cat_list, dir->d_name, global_pos)) {
8788
return 1;
8889
}
8990
if(config.prefix && sce_paf_private_strncmp(dir->d_name, "CAT_", 4) == 0) {
@@ -132,12 +133,23 @@ SceUID sceIoDopenPatched(const char *path) {
132133
if(*category) {
133134
kprintf("category: %s\n", category);
134135
}
135-
game_dfd = sceIoDopen(path);
136-
return game_dfd;
136+
if(config.mode == MODE_FOLDER || config.subcats) {
137+
ClearCategories(folder_list, 0);
138+
game_dfd = sceIoDopen(path);
139+
return game_dfd;
140+
}
141+
return sceIoDopen(path);
137142
}
138143

144+
int sceIoDreadPatchedF(SceUID fd, SceIoDirent *dir);
145+
139146
int sceIoDreadPatchedME(SceUID fd, SceIoDirent *dir) {
140147
int res = -1;
148+
149+
if(fd == game_dfd) {
150+
return sceIoDreadPatchedF(fd, dir);
151+
}
152+
141153
kprintf("start\n");
142154
while(1) {
143155
if(catdfd >= 0) {
@@ -186,6 +198,11 @@ int sceIoDreadPatchedME(SceUID fd, SceIoDirent *dir) {
186198

187199
int sceIoDreadPatched(SceUID fd, SceIoDirent *dir) {
188200
int res = -1;
201+
202+
if(fd == game_dfd) {
203+
return sceIoDreadPatchedF(fd, dir);
204+
}
205+
189206
kprintf("called\n");
190207
while(1) {
191208
res = sceIoDread(fd, dir);
@@ -248,62 +265,60 @@ char *ReturnBasePathPatched(char *base) {
248265

249266

250267
int sceIoDreadPatchedF(SceUID fd, SceIoDirent *dir) {
251-
if (fd == game_dfd) {
252-
while (1) {
253-
if (opened_dfd >= 0) {
254-
int res = sceIoDread(opened_dfd, dir);
255-
if (res > 0) {
256-
if (dir->d_name[0] != '.') {
257-
sce_paf_private_strcpy(dir->d_name + 128, dir->d_name);
258-
sce_paf_private_snprintf(dir->d_name, 128, "%s/%s", user_buffer + 14, dir->d_name + 128);
259-
if (dir->d_private) {
260-
sce_paf_private_strcpy((char *)dir->d_private + 13, dir->d_name);
261-
}
262-
return res;
263-
} else {
264-
continue;
268+
while (1) {
269+
if (opened_dfd >= 0) {
270+
int res = sceIoDread(opened_dfd, dir);
271+
if (res > 0) {
272+
if (dir->d_name[0] != '.') {
273+
sce_paf_private_strcpy(dir->d_name + 128, dir->d_name);
274+
sce_paf_private_snprintf(dir->d_name, 128, "%s/%s", user_buffer + 14, dir->d_name + 128);
275+
if (dir->d_private) {
276+
sce_paf_private_strcpy((char *)dir->d_private + 13, dir->d_name);
265277
}
278+
return res;
266279
} else {
267-
sceIoDclose(opened_dfd);
268-
opened_dfd = -1;
280+
continue;
269281
}
282+
} else {
283+
sceIoDclose(opened_dfd);
284+
opened_dfd = -1;
270285
}
286+
}
271287

272-
int res = sceIoDread(fd, dir);
288+
int res = sceIoDread(fd, dir);
273289

274-
if (res > 0) {
275-
if (dir->d_name[0] != '.') {
276-
if (FIO_S_ISDIR(dir->d_stat.st_mode)) {
277-
SceIoStat stat;
278-
sce_paf_private_memset(&stat, 0, sizeof(SceIoStat));
279-
sce_paf_private_snprintf(user_buffer + 13, 128,"/%s/EBOOT.PBP", dir->d_name);
290+
if (res > 0) {
291+
if (dir->d_name[0] != '.') {
292+
if (FIO_S_ISDIR(dir->d_stat.st_mode)) {
293+
SceIoStat stat;
294+
sce_paf_private_memset(&stat, 0, sizeof(SceIoStat));
295+
sce_paf_private_snprintf(user_buffer + 13, 128,"/%s/EBOOT.PBP", dir->d_name);
280296

297+
if (sceIoGetstat(user_buffer, &stat) < 0) {
298+
sce_paf_private_snprintf(user_buffer + 13, 128, "/%s/PARAM.PBP", dir->d_name);
281299
if (sceIoGetstat(user_buffer, &stat) < 0) {
282-
sce_paf_private_snprintf(user_buffer + 13, 128, "/%s/PARAM.PBP", dir->d_name);
283-
if (sceIoGetstat(user_buffer, &stat) < 0) {
284-
u64 mtime;
285-
sceRtcGetTick((pspTime *) &dir->d_stat.st_mtime, &mtime);
286-
AddCategory(dir->d_name, mtime, global_pos);
287-
sce_paf_private_snprintf(user_buffer + 13, 128, "/%s", dir->d_name);
288-
opened_dfd = sceIoDopen(user_buffer);
289-
continue;
290-
} else {
291-
if (!config.uncategorized) {
292-
continue; // ignore this Dread
293-
}
294-
uncategorized = 1;
295-
}
300+
u64 mtime;
301+
sceRtcGetTick((pspTime *) &dir->d_stat.st_mtime, &mtime);
302+
AddCategory(folder_list, dir->d_name, mtime, 0);
303+
sce_paf_private_snprintf(user_buffer + 13, 128, "/%s", dir->d_name);
304+
opened_dfd = sceIoDopen(user_buffer);
305+
continue;
296306
} else {
297307
if (!config.uncategorized) {
298308
continue; // ignore this Dread
299309
}
300310
uncategorized = 1;
301311
}
312+
} else {
313+
if (!config.uncategorized) {
314+
continue; // ignore this Dread
315+
}
316+
uncategorized = 1;
302317
}
303318
}
304319
}
305-
return res;
306320
}
321+
return res;
307322
}
308323

309324
return sceIoDread(fd, dir);
@@ -313,7 +328,7 @@ int sceIoDreadPatchedF(SceUID fd, SceIoDirent *dir) {
313328
int sceIoDclosePatched(SceUID fd) {
314329
if(fd == game_dfd) {
315330
if(uncategorized) {
316-
AddCategory("Uncategorized", 1, global_pos);
331+
AddCategory(folder_list, "Uncategorized", 1, 0);
317332
}
318333
game_dfd = -1;
319334
}
@@ -340,9 +355,9 @@ void PatchGamePluginForGCread(u32 text_addr) {
340355
MAKE_STUB(text_addr+patches.io_dopen_stub[patch_index], sceIoDopenPatched);
341356
}
342357

343-
// if(config.mode != MODE_MULTI_MS && config.mode != MODE_CONTEXT_MENU) {
344-
// MAKE_STUB(text_addr+patches.io_dclose_stub[patch_index], sceIoDclosePatched);
345-
// }
358+
if(config.mode == MODE_FOLDER || config.subcats) {
359+
MAKE_STUB(text_addr+patches.io_dclose_stub[patch_index], sceIoDclosePatched);
360+
}
346361
//MAKE_STUB(text_addr+patches.io_open_stub, sceIoOpenPatched);
347362

348363
MAKE_JUMP(text_addr + patches.base_path[patch_index], ReturnBasePathPatched);

Diff for: mode.c

+8-6
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ void *GetSelectionArg;
3535
void *class_buffer = NULL;
3636
extern char user_buffer[256];
3737

38+
Category *folder_list[1] = { NULL };
39+
3840
int (*scePafAddGameItems)(void *unk, int count);
3941

4042
/* Functions */
@@ -43,7 +45,7 @@ int CategorizeGamePatched(void *unk, int folder, int unk2) {
4345
u32 *array = (u32 *) *(u32 *) ((*(u32 *) (text_addr_game + patches.struct_addr[patch_index])) + ((u32) folder << 2));
4446
char *title = (char *) array[68 / 4];
4547

46-
Category *p = GetNextCategory(NULL, global_pos);
48+
Category *p = GetNextCategory(folder_list, NULL, 0);
4749

4850
for (i = patches.index[patch_index]; p; i++) {
4951
char *name = &p->name;
@@ -55,15 +57,15 @@ int CategorizeGamePatched(void *unk, int folder, int unk2) {
5557
}
5658
}
5759

58-
p = GetNextCategory(p, global_pos);
60+
p = GetNextCategory(folder_list, p, 0);
5961
}
6062

6163
/* uncategorized */
6264
return CategorizeGame(unk, i - 1, unk2);
6365
}
6466

6567
int scePafAddGameItemsPatched(void *unk, int count UNUSED) {
66-
return scePafAddGameItems(unk, CountCategories(global_pos));
68+
return scePafAddGameItems(unk, CountCategories(folder_list, 0));
6769
}
6870

6971
wchar_t* GetGameSubtitle(void *arg0 UNUSED, SfoInfo *sfo) {
@@ -122,7 +124,7 @@ wchar_t* GetGameSubtitle(void *arg0 UNUSED, SfoInfo *sfo) {
122124
wchar_t *GetCategoryTitle(int number) {
123125
int i;
124126

125-
Category *p = GetNextCategory(NULL, global_pos);
127+
Category *p = GetNextCategory(folder_list, NULL, 0);
126128

127129
for (i = patches.index[patch_index]; p; i++) {
128130
if (i == number) {
@@ -133,7 +135,7 @@ wchar_t *GetCategoryTitle(int number) {
133135
return (wchar_t *) user_buffer;
134136
}
135137

136-
p = GetNextCategory(p, global_pos);
138+
p = GetNextCategory(folder_list, p, 0);
137139
}
138140

139141
return NULL;
@@ -296,7 +298,7 @@ int ToggleCategoryMode(int mode) {
296298

297299
if (by_category_mode == 0 && mode == 1) {
298300
by_category_mode = 1;
299-
count = CountCategories(global_pos);
301+
count = CountCategories(folder_list, 0);
300302

301303
for (i = 0; i < total; i++) {
302304
u32 addr = text_addr + ToggleCategoryPatches[i].addr;

0 commit comments

Comments
 (0)