Skip to content
This repository has been archived by the owner on Aug 31, 2024. It is now read-only.

Commit

Permalink
Merge pull request ps2homebrew#517 from AKuHAK/UL_fix
Browse files Browse the repository at this point in the history
Fixed USBExtreme issue
  • Loading branch information
rickgaiser authored Aug 29, 2021
2 parents 41881ba + ed24de1 commit 39df52a
Showing 1 changed file with 29 additions and 33 deletions.
62 changes: 29 additions & 33 deletions src/supportbase.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,51 +403,47 @@ int sbReadList(base_game_info_t **list, const char *prefix, int *fsize, int *gam
snprintf(path, sizeof(path), "%sul.cfg", prefix);
fd = openFile(path, O_RDONLY);
if (fd >= 0) {
int ulcount;
USBExtreme_game_entry_t GameEntry;

if (count < 0)
count = 0;
size = getFileSize(fd);
*fsize = size;
ulcount = size / sizeof(USBExtreme_game_entry_t);
count += size / sizeof(USBExtreme_game_entry_t);

if (ulcount > 0) {
if ((*list = (base_game_info_t *)malloc(sizeof(base_game_info_t) * ulcount)) != NULL) {
memset(*list, 0, sizeof(base_game_info_t) * ulcount);
if (count > 0) {
if ((*list = (base_game_info_t *)malloc(sizeof(base_game_info_t) * count)) != NULL) {
memset(*list, 0, sizeof(base_game_info_t) * count);

while (size > 0) {
int ulfd = 1;
u8 part;
unsigned int name_checksum;
base_game_info_t *g = &(*list)[id++];

// populate game entry in list even if entry corrupted
read(fd, &GameEntry, sizeof(USBExtreme_game_entry_t));
size -= sizeof(USBExtreme_game_entry_t);

// populate game entry in list only if it has valid magic
if (!memcmp(GameEntry.magic, "ul.", 3)) {
int ulfd = 1;
u8 part;
unsigned int name_checksum;
base_game_info_t *g = &(*list)[id++];
count++;

// to ensure no leaks happen, we copy manually and pad the strings
memcpy(g->name, GameEntry.name, UL_GAME_NAME_MAX);
g->name[UL_GAME_NAME_MAX] = '\0';
memcpy(g->startup, GameEntry.startup, GAME_STARTUP_MAX);
g->startup[GAME_STARTUP_MAX] = '\0';
g->extension[0] = '\0';
g->parts = GameEntry.parts;
g->media = GameEntry.media;
g->format = GAME_FORMAT_USBLD;
g->sizeMB = 0;
name_checksum = USBA_crc32(g->name);

// calculate total size
for (part = 0; part < g->parts && ulfd >= 0; part++) {
snprintf(path, sizeof(path), "%sul.%08X.%s.%02x", prefix, name_checksum, g->startup, part);
ulfd = openFile(path, O_RDONLY);
if (ulfd >= 0) {
g->sizeMB += (getFileSize(ulfd) >> 20);
close(ulfd);
}
// to ensure no leaks happen, we copy manually and pad the strings
memcpy(g->name, GameEntry.name, UL_GAME_NAME_MAX);
g->name[UL_GAME_NAME_MAX] = '\0';
memcpy(g->startup, GameEntry.startup, GAME_STARTUP_MAX);
g->startup[GAME_STARTUP_MAX] = '\0';
g->extension[0] = '\0';
g->parts = GameEntry.parts;
g->media = GameEntry.media;
g->format = GAME_FORMAT_USBLD;
g->sizeMB = 0;
name_checksum = USBA_crc32(g->name);

// calculate total size for individual game
for (part = 0; part < g->parts && ulfd >= 0; part++) {
snprintf(path, sizeof(path), "%sul.%08X.%s.%02x", prefix, name_checksum, g->startup, part);
ulfd = openFile(path, O_RDONLY);
if (ulfd >= 0) {
g->sizeMB += (getFileSize(ulfd) >> 20);
close(ulfd);
}
}
}
Expand Down

0 comments on commit 39df52a

Please sign in to comment.