Skip to content

Commit 4a5a01c

Browse files
committed
Moved fixRoomProblems to initStageEvents
There may be a possible instance where OSLink wont be called when entering a new room, so initStageEvents is a better place for it, since initStageEvents is set to run just before the check for whether OSLink should run or not
1 parent 8f9f378 commit 4a5a01c

File tree

5 files changed

+64
-53
lines changed

5 files changed

+64
-53
lines changed

ttyd-tools/rel/include/main.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#pragma once
2+
3+
#include <cstdint>
4+
5+
namespace mod {
6+
7+
void fixRoomProblems();
8+
9+
}

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 performRelAndMapPatches(gc::OSModule::OSModuleInfo *, void *);
30+
bool performRelPatches(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: 49 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "main.h"
12
#include "global.h"
23
#include "commonfunctions.h"
34
#include "menufunctions.h"
@@ -110,6 +111,52 @@ void preventTextboxOptionSelection(char *currentText, void *storeAddress, int32_
110111
reinterpret_cast<uint32_t>(storeAddress) + 0x9C) = NewOption;
111112
}
112113

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

374-
void fixRoomProblems()
421+
bool Mod::performRelPatches(gc::OSModule::OSModuleInfo *newModule, void *bss)
375422
{
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-
425423
// Call the original function immediately, as the REL file should be linked before applying patches
426424
const bool Result = mPFN_OSLink_trampoline(newModule, bss);
427425

@@ -716,7 +714,7 @@ void initAddressOverwrites()
716714

717715
*reinterpret_cast<uint32_t *>(msgWindowMrAddress) = 0x38830001; // addi r4,r3,1
718716

719-
// Set the initial value for the debug mode variable, to allow backtrace screens before the title sequence begins
717+
// Set the initial value for the debug mode variable
720718
*reinterpret_cast<int32_t *>(
721719
reinterpret_cast<uint32_t>(
722720
ttyd::seq_title::seqTitleWorkPointer2) + 0x30) = -1;

ttyd-tools/rel/source/menufunctions.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "commonfunctions.h"
44
#include "codes.h"
55
#include "memorywatch.h"
6+
#include "main.h"
67

78
#include <gc/os.h>
89
#include <gc/OSTime.h>
@@ -3697,6 +3698,9 @@ bool getEventDetails(int32_t index, WarpByEventDetailsStruct *warpByEventDetails
36973698

36983699
void *initStageEvents()
36993700
{
3701+
// Check to see if any fixes need to be applied to specific maps
3702+
fixRoomProblems();
3703+
37003704
if (!WarpByEvent.ShouldInit)
37013705
{
37023706
// The overwritten instruction sets r3 to the global work pointer, so return the global work pointer

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->performRelAndMapPatches(newModule, bss);
112+
return gMod->performRelPatches(newModule, bss);
113113
});
114114

115115
mPFN_fbatHitCheck_trampoline = patch::hookFunction(

0 commit comments

Comments
 (0)