Skip to content

Commit eeba7d5

Browse files
committed
Renamed performRelPatches to performRelAndMapPatches, and moved fixRoomProblems into performRelAndMapPatches
The reason for this change is that fixRoomProblems was running too early, so some values could be changed after the fixes were applied.
1 parent 9c9ef5b commit eeba7d5

File tree

4 files changed

+52
-58
lines changed

4 files changed

+52
-58
lines changed

ttyd-tools/rel/include/assembly.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ bool displayMegaJumpBadgeInMenu(uint32_t checkBit);
3131
bool displayMegaHammerBadgesInMenu(uint32_t checkBit);
3232
uint32_t fixBlooperCrash1(uint32_t unkValue, void *battleUnitPointer);
3333
void preventTextboxOptionSelection(char *currentText, void *storeAddress, int32_t selectedOption);
34-
uint32_t fixRoomProblems();
3534
void *fixEvtMapBlendSetFlagPartnerCrash(void *partnerPtr);
3635
void *fixEvtMapBlendSetFlagFollowerCrash(void *followerPtr);
3736
const char *replaceJumpFallAnim(char *jumpFallString);

ttyd-tools/rel/include/mod.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Mod
2727
uint32_t pauseArtAttackTimer();
2828
uint32_t setIndexWarpEntrance(ttyd::evtmgr::EvtEntry *, uint32_t);
2929
int32_t fixMarioKeyOn();
30-
bool performRelPatches(gc::OSModule::OSModuleInfo *, void *);
30+
bool performRelAndMapPatches(gc::OSModule::OSModuleInfo *, void *);
3131
void *disableBattles(uint32_t, void *);
3232
void drawArtAttackHitboxes(ttyd::dispdrv::CameraId);
3333
int32_t displayActionCommandsTimingHook(void *, ttyd::battle_unit::AttackParams *);

ttyd-tools/rel/source/main.cpp

Lines changed: 50 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -110,55 +110,6 @@ void preventTextboxOptionSelection(char *currentText, void *storeAddress, int32_
110110
reinterpret_cast<uint32_t>(storeAddress) + 0x9C) = NewOption;
111111
}
112112

113-
uint32_t fixRoomProblems()
114-
{
115-
uint32_t SequencePosition = getSequencePosition();
116-
117-
if (compareStringToNextMap("nok_00"))
118-
{
119-
// Prevent the game from crashing if the player enters the intro cutscene after interacting with an NPC that is past slot 10
120-
// Check if the cutscene is going to play
121-
if (SequencePosition < 26)
122-
{
123-
// Clear the pointer used to check which animation Mario should use when greeting the Koopa
124-
uint32_t fbatPointer = reinterpret_cast<uint32_t>(ttyd::npcdrv::fbatGetPointer());
125-
*reinterpret_cast<uint32_t *>(fbatPointer + 0x4) = 0; // Mario will do no animation when the pointer is not set
126-
}
127-
}
128-
else if (compareStringToNextMap("rsh_05_a"))
129-
{
130-
// Prevent the game from crashing if the player enters rsh_05_a with the Sequence past 338
131-
if (SequencePosition > 338)
132-
{
133-
// Set the Sequence to 338 to prevent the crash
134-
setSequencePosition(338);
135-
}
136-
}
137-
else if (compareStringToNextMap("aji_13"))
138-
{
139-
// Prevent the game from crashing if the conveyor belt has not been activated
140-
// Set GW(11) to 0 upon entering the room to prevent the crash
141-
setGW(11, 0);
142-
}
143-
else if (compareStringToNextMap("las_08"))
144-
{
145-
// Prevent the game from crashing if the player entered las_08 with the Sequence as 385 and GSW(1121) at 7
146-
if (SequencePosition == 385)
147-
{
148-
// Check if GSW(1121) is currently at 7
149-
uint32_t GSW_1121 = ttyd::swdrv::swByteGet(1121);
150-
if (GSW_1121 == 7)
151-
{
152-
// Lower the value to 6 to prevent the game from crashing
153-
ttyd::swdrv::swByteSet(1121, 6);
154-
}
155-
}
156-
}
157-
158-
// The overwritten instruction sets r3 to 512, so return 512
159-
return 512;
160-
}
161-
162113
void *fixEvtMapBlendSetFlagPartnerCrash(void *partnerPtr)
163114
{
164115
// Bring out a partner if no partner is currently out
@@ -420,8 +371,57 @@ int32_t Mod::fixMarioKeyOn()
420371
return mPFN_marioKeyOn_trampoline();
421372
}
422373

423-
bool Mod::performRelPatches(gc::OSModule::OSModuleInfo *newModule, void *bss)
374+
void fixRoomProblems()
424375
{
376+
uint32_t SequencePosition = getSequencePosition();
377+
378+
if (compareStringToNextMap("nok_00"))
379+
{
380+
// Prevent the game from crashing if the player enters the intro cutscene after interacting with an NPC that is past slot 10
381+
// Check if the cutscene is going to play
382+
if (SequencePosition < 26)
383+
{
384+
// Clear the pointer used to check which animation Mario should use when greeting the Koopa
385+
uint32_t fbatPointer = reinterpret_cast<uint32_t>(ttyd::npcdrv::fbatGetPointer());
386+
*reinterpret_cast<uint32_t *>(fbatPointer + 0x4) = 0; // Mario will do no animation when the pointer is not set
387+
}
388+
}
389+
else if (compareStringToNextMap("rsh_05_a"))
390+
{
391+
// Prevent the game from crashing if the player enters rsh_05_a with the Sequence past 338
392+
if (SequencePosition > 338)
393+
{
394+
// Set the Sequence to 338 to prevent the crash
395+
setSequencePosition(338);
396+
}
397+
}
398+
else if (compareStringToNextMap("aji_13"))
399+
{
400+
// Prevent the game from crashing if the conveyor belt has not been activated
401+
// Set GW(11) to 0 upon entering the room to prevent the crash
402+
setGW(11, 0);
403+
}
404+
else if (compareStringToNextMap("las_08"))
405+
{
406+
// Prevent the game from crashing if the player entered las_08 with the Sequence as 385 and GSW(1121) at 7
407+
if (SequencePosition == 385)
408+
{
409+
// Check if GSW(1121) is currently at 7
410+
uint32_t GSW_1121 = ttyd::swdrv::swByteGet(1121);
411+
if (GSW_1121 == 7)
412+
{
413+
// Lower the value to 6 to prevent the game from crashing
414+
ttyd::swdrv::swByteSet(1121, 6);
415+
}
416+
}
417+
}
418+
}
419+
420+
bool Mod::performRelAndMapPatches(gc::OSModule::OSModuleInfo *newModule, void *bss)
421+
{
422+
// Check to see if any fixes need to be applied to specific maps
423+
fixRoomProblems();
424+
425425
// Call the original function immediately, as the REL file should be linked before applying patches
426426
const bool Result = mPFN_OSLink_trampoline(newModule, bss);
427427

@@ -618,7 +618,6 @@ void initAddressOverwrites()
618618
void *FixBlooperCrash1Address = reinterpret_cast<void *>(0x8010F810);
619619
void *FixBlooperCrash2Address = reinterpret_cast<void *>(0x8010F888);
620620
void *PreventTextboxSelectionAddress = reinterpret_cast<void *>(0x800D214C);
621-
void *FixRoomProblemsAddress = reinterpret_cast<void *>(0x800087C8);
622621
void *DisableDPadOptionsDisplayAddress = reinterpret_cast<void *>(0x8013D148);
623622
void *FixEvtMapBlendSetFlagPartnerCrashAddress = reinterpret_cast<void *>(0x800389C4);
624623
void *FixEvtMapBlendSetFlagFollowerCrashAddress = reinterpret_cast<void *>(0x80038A0C);
@@ -642,7 +641,6 @@ void initAddressOverwrites()
642641
void *FixBlooperCrash1Address = reinterpret_cast<void *>(0x8010A724);
643642
void *FixBlooperCrash2Address = reinterpret_cast<void *>(0x8010A79C);
644643
void *PreventTextboxSelectionAddress = reinterpret_cast<void *>(0x800CE01C);
645-
void *FixRoomProblemsAddress = reinterpret_cast<void *>(0x800086F0);
646644
void *DisableDPadOptionsDisplayAddress = reinterpret_cast<void *>(0x80137C1C);
647645
void *FixEvtMapBlendSetFlagPartnerCrashAddress = reinterpret_cast<void *>(0x80038328);
648646
void *FixEvtMapBlendSetFlagFollowerCrashAddress = reinterpret_cast<void *>(0x80038370);
@@ -666,7 +664,6 @@ void initAddressOverwrites()
666664
void *FixBlooperCrash1Address = reinterpret_cast<void *>(0x801106E8);
667665
void *FixBlooperCrash2Address = reinterpret_cast<void *>(0x80110760);
668666
void *PreventTextboxSelectionAddress = reinterpret_cast<void *>(0x800D2F44);
669-
void *FixRoomProblemsAddress = reinterpret_cast<void *>(0x80008994);
670667
void *DisableDPadOptionsDisplayAddress = reinterpret_cast<void *>(0x8013EC30);
671668
void *FixEvtMapBlendSetFlagPartnerCrashAddress = reinterpret_cast<void *>(0x80038AAC);
672669
void *FixEvtMapBlendSetFlagFollowerCrashAddress = reinterpret_cast<void *>(0x80038AF4);
@@ -693,8 +690,6 @@ void initAddressOverwrites()
693690

694691
patch::writeBranchBL(PreventTextboxSelectionAddress, reinterpret_cast<void *>(StartPreventTextboxSelection));
695692

696-
patch::writeBranchBL(FixRoomProblemsAddress, reinterpret_cast<void *>(fixRoomProblems));
697-
698693
patch::writeBranchBL(DisableDPadOptionsDisplayAddress, reinterpret_cast<void *>(StartDisableDPadOptionsDisplay));
699694

700695
patch::writeBranchBL(FixEvtMapBlendSetFlagPartnerCrashAddress, reinterpret_cast<void *>(StartFixEvtMapBlendSetFlagPartnerCrash));

ttyd-tools/rel/source/mod.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ void Mod::init()
109109
mPFN_OSLink_trampoline = patch::hookFunction(
110110
gc::OSModule::OSLink, [](gc::OSModule::OSModuleInfo *newModule, void *bss)
111111
{
112-
return gMod->performRelPatches(newModule, bss);
112+
return gMod->performRelAndMapPatches(newModule, bss);
113113
});
114114

115115
mPFN_fbatHitCheck_trampoline = patch::hookFunction(

0 commit comments

Comments
 (0)