Skip to content

Commit 962a9a2

Browse files
committed
isavegame matches and iSGReadLeader bugfixes
1 parent db4ddc5 commit 962a9a2

File tree

1 file changed

+38
-25
lines changed

1 file changed

+38
-25
lines changed

src/SB/Core/gc/isavegame.cpp

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -361,23 +361,27 @@ S32 iSGTgtSetActive(st_ISGSESSION* isgdata, S32 tgtidx)
361361
static S32 iSG_get_finfo(st_ISG_MEMCARD_DATA* mcdata, const char* dpath);
362362
static S32 iSG_isSpaceForFile(st_ISG_MEMCARD_DATA* mcdata, S32 param2, const char* param3,
363363
S32* param4, S32* param5, S32* param6);
364-
// Regswaps
365364
S32 iSGTgtHaveRoom(st_ISGSESSION* isgdata, S32 tidx, S32 fsize, const char* dpath,
366365
const char* fname, S32* bytesNeeded, S32* availOnDisk, S32* needFile)
367366
{
367+
st_ISG_MEMCARD_DATA* data;
368+
S32 i;
369+
S32 count;
370+
S32 opened;
371+
S32 is_space;
368372
if (isgdata->slot < 0)
369373
{
370374
return 0;
371375
}
372-
st_ISG_MEMCARD_DATA* data = &isgdata->mcdata[isgdata->slot];
376+
data = &isgdata->mcdata[isgdata->slot];
373377
if (data->unk_0 == NULL)
374378
{
375379
return 0;
376380
}
377-
S32 count = 0;
381+
count = 0;
378382
if (fname == NULL)
379383
{
380-
for (S32 i = 0; i < ISG_NUM_FILES; ++i)
384+
for (i = 0; i < ISG_NUM_FILES; ++i)
381385
{
382386
iTRCDisk::CheckDVDAndResetState();
383387
fname = iSGMakeName(ISG_NGTYP_GAMEFILE, NULL, i);
@@ -388,7 +392,7 @@ S32 iSGTgtHaveRoom(st_ISGSESSION* isgdata, S32 tidx, S32 fsize, const char* dpat
388392
}
389393
}
390394

391-
S32 is_space = iSG_isSpaceForFile(data, fsize, fname, bytesNeeded, availOnDisk, needFile);
395+
is_space = iSG_isSpaceForFile(data, fsize, fname, bytesNeeded, availOnDisk, needFile);
392396
if (count > 0 && *bytesNeeded > *availOnDisk)
393397
{
394398
if (needFile != NULL && *bytesNeeded > *availOnDisk)
@@ -400,8 +404,8 @@ S32 iSGTgtHaveRoom(st_ISGSESSION* isgdata, S32 tidx, S32 fsize, const char* dpat
400404
}
401405

402406
CARDFileInfo fileInfo;
403-
S32 opened = 0;
404-
for (S32 i = 0; i < CARD_MAX_FILE && isgdata->slot >= 0 && isgdata->slot < ISG_NUM_SLOTS; ++i)
407+
opened = 0;
408+
for (i = 0; i < CARD_MAX_FILE && isgdata->slot >= 0 && isgdata->slot < ISG_NUM_SLOTS; ++i)
405409
{
406410
if (CARDFastOpen(isgdata->slot, i, &fileInfo) == 0)
407411
{
@@ -426,23 +430,27 @@ S32 iSGTgtHaveRoom(st_ISGSESSION* isgdata, S32 tidx, S32 fsize, const char* dpat
426430
return (*bytesNeeded > *availOnDisk) ? 0 : is_space;
427431
}
428432

429-
// Regswaps, very similar to above
430433
S32 iSGTgtHaveRoomStartup(st_ISGSESSION* isgdata, S32 tidx, S32 fsize, const char* dpath,
431434
const char* fname, S32* bytesNeeded, S32* availOnDisk, S32* needFile)
432435
{
436+
st_ISG_MEMCARD_DATA* data;
437+
S32 i;
438+
S32 count;
439+
S32 opened;
440+
S32 is_space;
433441
if (isgdata->slot < 0)
434442
{
435443
return 0;
436444
}
437-
st_ISG_MEMCARD_DATA* data = &isgdata->mcdata[isgdata->slot];
445+
data = &isgdata->mcdata[isgdata->slot];
438446
if (data->unk_0 == NULL)
439447
{
440448
return 0;
441449
}
442-
S32 count = 0;
450+
count = 0;
443451
if (fname == NULL)
444452
{
445-
for (S32 i = 0; i < ISG_NUM_FILES; ++i)
453+
for (i = 0; i < ISG_NUM_FILES; ++i)
446454
{
447455
iTRCDisk::CheckDVDAndResetState();
448456
fname = iSGMakeName(ISG_NGTYP_GAMEFILE, NULL, i);
@@ -453,7 +461,7 @@ S32 iSGTgtHaveRoomStartup(st_ISGSESSION* isgdata, S32 tidx, S32 fsize, const cha
453461
}
454462
}
455463

456-
S32 is_space = iSG_isSpaceForFile(data, fsize, fname, bytesNeeded, availOnDisk, needFile);
464+
is_space = iSG_isSpaceForFile(data, fsize, fname, bytesNeeded, availOnDisk, needFile);
457465
if (count > 0 && *bytesNeeded > *availOnDisk)
458466
{
459467
if (needFile != NULL && *bytesNeeded > *availOnDisk)
@@ -465,8 +473,8 @@ S32 iSGTgtHaveRoomStartup(st_ISGSESSION* isgdata, S32 tidx, S32 fsize, const cha
465473
}
466474

467475
CARDFileInfo fileInfo;
468-
S32 opened = 0;
469-
for (S32 i = 0; i < CARD_MAX_FILE && isgdata->slot >= 0 && isgdata->slot < ISG_NUM_SLOTS; ++i)
476+
opened = 0;
477+
for (i = 0; i < CARD_MAX_FILE && isgdata->slot >= 0 && isgdata->slot < ISG_NUM_SLOTS; ++i)
470478
{
471479
if (CARDFastOpen(isgdata->slot, i, &fileInfo) == 0)
472480
{
@@ -751,20 +759,23 @@ S32 iSGLoadFile(st_ISGSESSION* isgdata, const char* fname, char* databuf, S32 as
751759
static S32 iSG_mc_fread(st_ISG_MEMCARD_DATA* mcdata, char*, S32, S32);
752760
S32 iSGReadLeader(st_ISGSESSION* isgdata, const char* fname, char* databuf, S32 numbytes, S32 async)
753761
{
754-
void* alloc = NULL;
762+
S32 bufsize;
763+
S32 iconsize;
755764
S32 allocsize;
756765
char* readbuf;
757-
S32 bufsize;
758766

759-
en_ASYNC_OPERR operr = ISG_OPERR_NONE;
760767
S32 readret = 0;
768+
st_ISG_MEMCARD_DATA* data;
769+
void* alloc = NULL;
770+
771+
en_ASYNC_OPERR operr = ISG_OPERR_NONE;
761772
if (isgdata->slot < 0)
762773
{
763774
isgdata->unk_26c = ISG_OPSTAT_FAILURE;
764775
isgdata->unk_268 = ISG_OPERR_NOCARD;
765776
return 0;
766777
}
767-
st_ISG_MEMCARD_DATA* data = &isgdata->mcdata[isgdata->slot];
778+
data = &isgdata->mcdata[isgdata->slot];
768779

769780
if (data->unk_12c != 0)
770781
{
@@ -774,14 +785,15 @@ S32 iSGReadLeader(st_ISGSESSION* isgdata, const char* fname, char* databuf, S32
774785
}
775786

776787
iTRCDisk::CheckDVDAndResetState();
777-
S32 iconsize = iSG_cubeicon_size(data->chan, data->sectorSize);
788+
iconsize = iSG_cubeicon_size(data->chan, data->sectorSize);
778789
S32 sectorsize200 = ALIGN_THING(data->sectorSize, 0x200);
779-
if ((S32)databuf % 32 != 0 || numbytes - ((numbytes / sectorsize200) * sectorsize200) != 0)
790+
if ((S32)databuf % 32 != 0 || numbytes - (numbytes / sectorsize200) * sectorsize200 != 0)
780791
{
781-
bufsize = (iconsize + 0x1ff & ~0x1ff);
782-
S32 allocsize = bufsize + 0x1f;
792+
S32 tmpsize = (numbytes + 0x1ff & ~0x1ff);
793+
allocsize = tmpsize + 0x1f;
783794
alloc = xMemPushTemp(allocsize);
784795
memset(alloc, 0, allocsize);
796+
bufsize = tmpsize;
785797
readbuf = (char*)((U32)alloc + 0x1f & ~0x1f);
786798
}
787799
else
@@ -798,7 +810,7 @@ S32 iSGReadLeader(st_ISGSESSION* isgdata, const char* fname, char* databuf, S32
798810
iSG_mc_fclose(data);
799811
}
800812

801-
if (readret == 0 && alloc != NULL)
813+
if (readret != 0 && alloc != NULL)
802814
{
803815
memcpy(databuf, readbuf, numbytes);
804816
}
@@ -1340,8 +1352,9 @@ static S32 iSG_get_fmoddate(st_ISG_MEMCARD_DATA* mcdata, const char* fname, int*
13401352
}
13411353
else
13421354
{
1343-
// FIXME: This first param isn't right, can't decipher the 64 bit math
1344-
OSTicksToCalendarTime((u64)mcdata->unk_b0.time * (u64)(GET_BUS_FREQUENCY() / 4), &time);
1355+
OSTime t = mcdata->unk_b0.time;
1356+
t = OSSecondsToTicks(t);
1357+
OSTicksToCalendarTime(t, &time);
13451358

13461359
if (sec)
13471360
{

0 commit comments

Comments
 (0)