Skip to content

Commit f8d3583

Browse files
committed
Fixed the standard heap corrupting when in the Shadow Queen cutscene before the final battle
Modifed the script used for this to not spawn as many textboxes. Doing this also requires adjusting how long the script should wait for at the end of the loop.
1 parent 6aa61b6 commit f8d3583

File tree

2 files changed

+69
-3
lines changed

2 files changed

+69
-3
lines changed

ttyd-tools/rel/source/commonfunctions.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ bool checkIfInGame()
6666
ttyd::seqdrv::SeqIndex CurrentSeq = ttyd::seqdrv::seqGetSeq();
6767
if (CurrentSeq == Game)
6868
{
69-
uint32_t Current_REL_Loaded = *reinterpret_cast<uint32_t *>(
69+
uint32_t Current_REL_Loaded_Pointer = *reinterpret_cast<uint32_t *>(
7070
*reinterpret_cast<uint32_t *>(GlobalWorkPointer) + 0x15C);
7171

72-
if (Current_REL_Loaded != 0)
72+
if (Current_REL_Loaded_Pointer != 0)
7373
{
7474
#ifdef TTYD_US
7575
const uint32_t DMO = 0x4;
@@ -79,7 +79,7 @@ bool checkIfInGame()
7979
const uint32_t DMO = 0x5;
8080
#endif
8181

82-
uint32_t Current_REL_Id = *reinterpret_cast<uint32_t *>(Current_REL_Loaded);
82+
uint32_t Current_REL_Id = *reinterpret_cast<uint32_t *>(Current_REL_Loaded_Pointer);
8383
if (Current_REL_Id != DMO)
8484
{
8585
// Currently not in the intro

ttyd-tools/rel/source/main.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,69 @@ uint32_t Mod::pauseArtAttackTimer()
364364
return mPFN_scissor_timer_main_trampoline();
365365
}
366366

367+
void performRELPatches()
368+
{
369+
// Only run during screen transitions
370+
if (!checkForSpecificSeq(ttyd::seqdrv::SeqIndex::kMapChange))
371+
{
372+
return;
373+
}
374+
375+
// Make sure a REL file is currently loaded
376+
uint32_t Current_REL_Loaded_Pointer = *reinterpret_cast<uint32_t *>(
377+
*reinterpret_cast<uint32_t *>(GlobalWorkPointer) + 0x15C);
378+
379+
if (Current_REL_Loaded_Pointer == 0)
380+
{
381+
return;
382+
}
383+
384+
#ifdef TTYD_US
385+
const uint32_t LAS = 0x10;
386+
const uint32_t SQ_Cutscene_Spawn_Textboxes_Script_Offset = 0x36FBC;
387+
const uint32_t SQ_Cutscene_Spawn_Textboxes_Script_Loop_Offset = 0x64;
388+
const uint32_t SQ_Cutscene_Spawn_Textboxes_Script_WaitMS_Offset = 0x114;
389+
#elif defined TTYD_JP
390+
const uint32_t LAS = 0x11;
391+
const uint32_t SQ_Cutscene_Spawn_Textboxes_Script_Offset = 0x36FC0;
392+
const uint32_t SQ_Cutscene_Spawn_Textboxes_Script_Loop_Offset = 0x58;
393+
const uint32_t SQ_Cutscene_Spawn_Textboxes_Script_WaitMS_Offset = 0xD4;
394+
#elif defined TTYD_EU
395+
const uint32_t LAS = 0x11;
396+
const uint32_t SQ_Cutscene_Spawn_Textboxes_Script_Offset = 0x36FBC;
397+
const uint32_t SQ_Cutscene_Spawn_Textboxes_Script_Loop_Offset = 0x64;
398+
const uint32_t SQ_Cutscene_Spawn_Textboxes_Script_WaitMS_Offset = 0x114;
399+
#endif
400+
401+
uint32_t CurrentREL = *reinterpret_cast<uint32_t *>(Current_REL_Loaded_Pointer);
402+
switch (CurrentREL)
403+
{
404+
case LAS:
405+
{
406+
if (compareStringToNextMap("las_29"))
407+
{
408+
// Make changes to the function that spawns the textboxes, to prevent the standard heap from being corrupted
409+
// Change the loop count from 10 to 5
410+
*reinterpret_cast<uint32_t *>(
411+
Current_REL_Loaded_Pointer +
412+
SQ_Cutscene_Spawn_Textboxes_Script_Offset +
413+
SQ_Cutscene_Spawn_Textboxes_Script_Loop_Offset) = 5;
414+
415+
// Wait for 400ms instead of 200ms at the end of the loop
416+
*reinterpret_cast<uint32_t *>(
417+
Current_REL_Loaded_Pointer +
418+
SQ_Cutscene_Spawn_Textboxes_Script_Offset +
419+
SQ_Cutscene_Spawn_Textboxes_Script_WaitMS_Offset) = 400;
420+
}
421+
return;
422+
}
423+
default:
424+
{
425+
return;
426+
}
427+
}
428+
}
429+
367430
void addTextToHeapArray(char *text)
368431
{
369432
char *tempHeapBuffer = HeapBuffer;
@@ -692,6 +755,9 @@ void Mod::run()
692755
displayStickAngle();
693756
displayMemoryWatches();
694757

758+
// Perform any necessaery REL patches
759+
performRELPatches();
760+
695761
// Check the heaps
696762
checkHeaps();
697763
}

0 commit comments

Comments
 (0)