Skip to content

Commit c031c3e

Browse files
committed
Bug Fix + Added Additional Features
Fixed the game crashing if the player entered las_08 with the Sequence at 385 and with GSW(1121) at 7. GSW(1121) will be reduced to 6 in this instance in order to avoid the crash. Allowed being able to give actors badges inside of battles. When an actor that is neither Mario nor the partners is given a badge, all of the current badges equipped are cleared, and the new badge is equipped. Adjusted the window length for the button timing display to be dynamic.
1 parent 61e0a37 commit c031c3e

File tree

11 files changed

+154
-63
lines changed

11 files changed

+154
-63
lines changed

ttyd-tools/rel/include/commonfunctions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ void setNextMap(const char *map);
2121
void setNextBero(const char *bero);
2222
bool compareStrings(const char *str1, const char *str2);
2323
bool compareStringsSize(const char *str1, const char *str2, uint32_t size);
24+
bool compareStringToNextMap(const char *str);
2425
uint32_t getSystemLevel();
2526
void setSystemLevel(uint32_t value);
2627
void setSeq(const char *map, const char *bero);

ttyd-tools/rel/include/ttyd.eu.lst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@
784784
// 800F8A68:BattleStoreExp
785785
// 800F8A78:BattleStoreCoin
786786
// 800F8A8C:BattlePartyInfoWorkInit
787-
// 800F8B10:_EquipItem
787+
800F8B10:_EquipItem
788788
// 800F9188:BtlUnit_EquipItem
789789
// 800F9250:BattleTransPartyIdToUnitKind
790790
// 800F92B0:BattleTransPartyId

ttyd-tools/rel/include/ttyd.jp.lst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@
778778
// 800F2CB0:BattleStoreExp
779779
// 800F2CC0:BattleStoreCoin
780780
// 800F2CD4:BattlePartyInfoWorkInit
781-
// 800F2D50:_EquipItem
781+
800F2D50:_EquipItem
782782
// 800F33C8:BtlUnit_EquipItem
783783
// 800F3490:BattleTransPartyIdToUnitKind
784784
// 800F34F0:BattleTransPartyId

ttyd-tools/rel/include/ttyd.us.lst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@
783783
// 800F7BFC:BattleStoreExp
784784
// 800F7C0C:BattleStoreCoin
785785
// 800F7C20:BattlePartyInfoWorkInit
786-
// 800F7CA4:_EquipItem
786+
800F7CA4:_EquipItem
787787
// 800F831C:BtlUnit_EquipItem
788788
// 800F83E4:BattleTransPartyIdToUnitKind
789789
// 800F8444:BattleTransPartyId

ttyd-tools/rel/include/ttyd/battle.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ extern "C" {
2828
// BattleStoreExp
2929
// BattleStoreCoin
3030
// BattlePartyInfoWorkInit
31-
// _EquipItem
31+
void _EquipItem(void *battleUnitPtr, uint32_t unkBits, int16_t item);
3232
// BtlUnit_EquipItem
3333
// BattleTransPartyIdToUnitKind
3434
// BattleTransPartyId
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.global StartFixRoomProblems
2+
.global BranchBackFixRoomProblems
3+
4+
StartFixRoomProblems:
5+
bl fixRoomProblems
6+
7+
# Restore overwritten assembly
8+
li %r3,512
9+
10+
BranchBackFixRoomProblems:
11+
b 0

ttyd-tools/rel/source/codes.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ void bobberyEarly()
515515
// Turn off GSWF(3137)
516516
ttyd::swdrv::swClear(3137);
517517

518-
if (compareStrings(NextMap, reinterpret_cast<const char *>(muj_05)))
518+
if (compareStringToNextMap(reinterpret_cast<const char *>(muj_05)))
519519
{
520520
uint32_t NPC_6_Addresses_Start = (*reinterpret_cast<uint32_t *>(
521521
NPCAddressesStart)) + 0x1040;
@@ -899,9 +899,9 @@ void actionCommandsTimingsInit()
899899
DisplayActionCommands.Last_B_Frame = -1;
900900
DisplayActionCommands.TypeToDraw = -1;
901901

902-
int8_t Last_A_Frame = -1;
903-
int8_t Last_B_Frame = -1;
904-
int8_t ButtonPresses = 0;
902+
int32_t Last_A_Frame = -1;
903+
int32_t Last_B_Frame = -1;
904+
int32_t ButtonPresses = 0;
905905

906906
for (int32_t Frame = 0; Frame < 15; ++Frame)
907907
{
@@ -921,21 +921,21 @@ void actionCommandsTimingsInit()
921921
const int32_t DefenseResult = DisplayActionCommands.Trampoline(
922922
battle_unit, attack_params);
923923

924-
const int8_t SuccessfulTiming = 0;
925-
const int8_t PressedTooManyButtons = 1;
926-
const int8_t PressedTooEarly = 2;
924+
const int32_t SuccessfulTiming = 0;
925+
const int32_t PressedTooManyButtons = 1;
926+
const int32_t PressedTooEarly = 2;
927927

928-
if (DefenseResult == 5)
928+
if (DefenseResult == 4)
929929
{
930-
// Successful Superguard; print Last_B_Frame
931-
DisplayActionCommands.Last_B_Frame = Last_B_Frame;
930+
// Successful Guard; print Last_A_Frame
931+
DisplayActionCommands.Last_A_Frame = Last_A_Frame;
932932
DisplayActionCommands.TypeToDraw = SuccessfulTiming;
933933
DisplayActionCommands.DisplayTimer = secondsToFrames(3);
934934
}
935-
else if (DefenseResult == 4)
935+
else if (DefenseResult == 5)
936936
{
937-
// Successful Guard; print Last_A_Frame
938-
DisplayActionCommands.Last_A_Frame = Last_A_Frame;
937+
// Successful Superguard; print Last_B_Frame
938+
DisplayActionCommands.Last_B_Frame = Last_B_Frame;
939939
DisplayActionCommands.TypeToDraw = SuccessfulTiming;
940940
DisplayActionCommands.DisplayTimer = secondsToFrames(3);
941941
}
@@ -945,17 +945,17 @@ void actionCommandsTimingsInit()
945945
DisplayActionCommands.TypeToDraw = PressedTooManyButtons;
946946
DisplayActionCommands.DisplayTimer = secondsToFrames(3);
947947
}
948-
else if (Last_B_Frame > -1)
948+
else if (Last_A_Frame > -1)
949949
{
950950
// Print how many frames early the player pressed A
951-
DisplayActionCommands.Last_B_Frame = Last_B_Frame;
951+
DisplayActionCommands.Last_A_Frame = Last_A_Frame;
952952
DisplayActionCommands.TypeToDraw = PressedTooEarly;
953953
DisplayActionCommands.DisplayTimer = secondsToFrames(3);
954954
}
955-
else if (Last_A_Frame > -1)
955+
else if (Last_B_Frame > -1)
956956
{
957957
// Print how many frames early the player pressed B
958-
DisplayActionCommands.Last_A_Frame = Last_A_Frame;
958+
DisplayActionCommands.Last_B_Frame = Last_B_Frame;
959959
DisplayActionCommands.TypeToDraw = PressedTooEarly;
960960
DisplayActionCommands.DisplayTimer = secondsToFrames(3);
961961
}

ttyd-tools/rel/source/commonfunctions.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ bool compareStringsSize(const char *str1, const char *str2, uint32_t size)
168168
return ttyd::string::strncmp(str1, str2, size) == 0;
169169
}
170170

171+
bool compareStringToNextMap(const char *str)
172+
{
173+
return ttyd::string::strcmp(NextMap, str) == 0;
174+
}
175+
171176
uint32_t getSystemLevel()
172177
{
173178
return ttyd::mariost::marioStGetSystemLevel();

ttyd-tools/rel/source/draw.cpp

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,7 +1428,7 @@ void drawErrorMessage(const char *line)
14281428

14291429
int32_t TextPosX = -130;
14301430
// int32_t WindowWidth = 305;
1431-
uint16_t LineLength = ttyd::fontmgr::FontGetMessageWidth(line);
1431+
uint32_t LineLength = ttyd::fontmgr::FontGetMessageWidth(line);
14321432
int32_t WindowWidth = 80 + (LineLength >> 1) - (LineLength % 10);
14331433
drawErrorWindow(line, TextPosX, WindowWidth);
14341434
}
@@ -2551,7 +2551,7 @@ void drawPalaceSkipDetails()
25512551
PhantomEmberPosY,
25522552
PartnerPosY);
25532553

2554-
// uint16_t LineLength = ttyd::fontmgr::FontGetMessageWidth(tempDisplayBuffer);
2554+
// uint32_t LineLength = ttyd::fontmgr::FontGetMessageWidth(tempDisplayBuffer);
25552555
// int32_t WindowWidth = 245 + (LineLength >> 1) - (LineLength % 10);
25562556

25572557
/*drawTextWithWindow(tempDisplayBuffer, PosX, PosY, Alpha, TextColor,
@@ -2593,8 +2593,8 @@ void drawActionCommandsTiming()
25932593
#endif
25942594

25952595
uint32_t MarioBattlePointer = reinterpret_cast<uint32_t>(getMarioBattlePointer());
2596-
uint8_t SimplifiersEquipped = *reinterpret_cast<uint8_t *>(MarioBattlePointer + SimplifierOffset);
2597-
uint8_t UnsimplifiersEquipped = *reinterpret_cast<uint8_t *>(MarioBattlePointer + UnsimplifierOffset);
2596+
uint32_t SimplifiersEquipped = *reinterpret_cast<uint8_t *>(MarioBattlePointer + SimplifierOffset);
2597+
uint32_t UnsimplifiersEquipped = *reinterpret_cast<uint8_t *>(MarioBattlePointer + UnsimplifierOffset);
25982598

25992599
int32_t CommandDifficulty = UnsimplifiersEquipped - SimplifiersEquipped + 3;
26002600
if (CommandDifficulty < 0)
@@ -2606,42 +2606,42 @@ void drawActionCommandsTiming()
26062606
CommandDifficulty = 6;
26072607
}
26082608

2609-
int8_t temp_Last_A_Frame = DisplayActionCommands.Last_A_Frame;
2610-
int8_t temp_Last_B_Frame = DisplayActionCommands.Last_B_Frame;
2609+
int32_t temp_Last_A_Frame = DisplayActionCommands.Last_A_Frame;
2610+
int32_t temp_Last_B_Frame = DisplayActionCommands.Last_B_Frame;
26112611

2612-
uint8_t TypeToDraw = DisplayActionCommands.TypeToDraw;
2612+
int32_t TypeToDraw = DisplayActionCommands.TypeToDraw;
26132613
const char *TextToDraw;
26142614
char *tempDisplayBuffer = DisplayBuffer;
26152615

2616-
const int8_t SuccessfulTiming = 0;
2617-
const int8_t PressedTooManyButtons = 1;
2618-
const int8_t PressedTooEarly = 2;
2616+
const int32_t SuccessfulTiming = 0;
2617+
const int32_t PressedTooManyButtons = 1;
2618+
const int32_t PressedTooEarly = 2;
26192619

26202620
// Check to see which text should be displayed
26212621
switch (TypeToDraw)
26222622
{
26232623
case SuccessfulTiming:
26242624
{
2625-
int8_t CurrentDifficultyFrames;
2626-
int8_t FramePressed;
2627-
const char *String;
2625+
int32_t CurrentDifficultyFrames;
2626+
int32_t FramePressed;
2627+
char Button;
26282628

2629-
if (temp_Last_B_Frame > -1)
2629+
if (temp_Last_A_Frame > -1)
26302630
{
2631-
CurrentDifficultyFrames = SuperguardFrames[CommandDifficulty];
2632-
FramePressed = CurrentDifficultyFrames - temp_Last_B_Frame;
2633-
String = "B";
2631+
CurrentDifficultyFrames = GuardFrames[CommandDifficulty];
2632+
FramePressed = CurrentDifficultyFrames - temp_Last_A_Frame;
2633+
Button = 'A';
26342634
}
26352635
else
26362636
{
2637-
CurrentDifficultyFrames = GuardFrames[CommandDifficulty];
2638-
FramePressed = CurrentDifficultyFrames - temp_Last_A_Frame;
2639-
String = "A";
2637+
CurrentDifficultyFrames = SuperguardFrames[CommandDifficulty];
2638+
FramePressed = CurrentDifficultyFrames - temp_Last_B_Frame;
2639+
Button = 'B';
26402640
}
26412641

26422642
sprintf(tempDisplayBuffer,
2643-
"Pressed %s on frame %d of %d",
2644-
String,
2643+
"Pressed %c on frame %ld of %ld",
2644+
Button,
26452645
FramePressed,
26462646
CurrentDifficultyFrames);
26472647

@@ -2655,21 +2655,21 @@ void drawActionCommandsTiming()
26552655
}
26562656
case PressedTooEarly:
26572657
{
2658-
int8_t CurrentDifficultyFrames;
2659-
int8_t FramesEarly;
2660-
const char *String;
2658+
int32_t CurrentDifficultyFrames;
2659+
int32_t FramesEarly;
2660+
char Button;
26612661

2662-
if (temp_Last_B_Frame > -1)
2662+
if (temp_Last_A_Frame > -1)
26632663
{
2664-
CurrentDifficultyFrames = SuperguardFrames[CommandDifficulty];
2665-
FramesEarly = temp_Last_B_Frame - CurrentDifficultyFrames + 1;
2666-
String = "B";
2664+
CurrentDifficultyFrames = GuardFrames[CommandDifficulty];
2665+
FramesEarly = temp_Last_A_Frame - CurrentDifficultyFrames + 1;
2666+
Button = 'A';
26672667
}
26682668
else
26692669
{
2670-
CurrentDifficultyFrames = GuardFrames[CommandDifficulty];
2671-
FramesEarly = temp_Last_A_Frame - CurrentDifficultyFrames + 1;
2672-
String = "A";
2670+
CurrentDifficultyFrames = SuperguardFrames[CommandDifficulty];
2671+
FramesEarly = temp_Last_B_Frame - CurrentDifficultyFrames + 1;
2672+
Button = 'B';
26732673
}
26742674

26752675
const char *CheckForPlural;
@@ -2683,8 +2683,8 @@ void drawActionCommandsTiming()
26832683
}
26842684

26852685
sprintf(tempDisplayBuffer,
2686-
"Pressed %s %d frame%s early",
2687-
String,
2686+
"Pressed %c %ld frame%s early",
2687+
Button,
26882688
FramesEarly,
26892689
CheckForPlural);
26902690

@@ -2703,10 +2703,13 @@ void drawActionCommandsTiming()
27032703
uint8_t Alpha = 0xFF;
27042704
int32_t TextPosX = -232;
27052705
int32_t TextPosY = -105;
2706-
int32_t WindowWidth = 320;
2706+
// int32_t WindowWidth = 320;
27072707
int32_t WindowCurve = 10;
27082708
float Scale = 0.75;
27092709

2710+
uint32_t LineLength = ttyd::fontmgr::FontGetMessageWidth(TextToDraw);
2711+
int32_t WindowWidth = 129 + (LineLength >> 1) - (LineLength % 10);
2712+
27102713
drawTextWithWindow(TextToDraw, TextPosX, TextPosY, Alpha, TextColor,
27112714
Scale, WindowWidth, WindowColor, WindowCurve);
27122715

@@ -2737,7 +2740,7 @@ void drawTitleScreenInfo()
27372740
PosX += 113;
27382741
PosY -= 14;
27392742

2740-
const char *String = "Practice Codes v3.0.6\nCreated by Zephiles";
2743+
const char *String = "Practice Codes v3.0.7\nCreated by Zephiles";
27412744
drawText(String, PosX, PosY, Alpha, TextColor, Scale);
27422745
}
27432746

ttyd-tools/rel/source/main.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "draw.h"
88
#include "patch.h"
99

10+
#include <ttyd/swdrv.h>
1011
#include <ttyd/mario.h>
1112
#include <ttyd/evt_sub.h>
1213
#include <ttyd/mario_pouch.h>
@@ -50,6 +51,8 @@ extern "C"
5051
void BranchBackPreventTextboxSelection();
5152
void StartPreventJumpAndHammer();
5253
void BranchBackPreventJumpAndHammer();
54+
void StartFixRoomProblems();
55+
void BranchBackFixRoomProblems();
5356
}
5457

5558
// Additional function used by assembly overwrites
@@ -185,11 +188,31 @@ void preventTextboxOptionSelection(char *currentText, void *storeAddress,
185188
reinterpret_cast<uint32_t>(storeAddress) + 0x9C) = NewOption;
186189
}
187190

191+
void fixRoomProblems()
192+
{
193+
// Prevent the game from crashing if the player entered las_08 with the Sequence as 385 and GSW(1121) at 7
194+
if (compareStringToNextMap("las_08"))
195+
{
196+
// Check if the Sequence is currently at 385
197+
uint32_t SequencePosition = getSequencePosition();
198+
if (SequencePosition == 385)
199+
{
200+
// Check if GSW(1121) is currently at 7
201+
uint32_t GSW_1121 = ttyd::swdrv::swByteGet(1121);
202+
if (GSW_1121 == 7)
203+
{
204+
// Lower the value to 6 to prevent the game from crashing
205+
ttyd::swdrv::swByteSet(1121, 6);
206+
}
207+
}
208+
}
209+
}
210+
188211
const char *replaceJumpFallAnim(char *jumpFallString)
189212
{
190213
if (compareStringsSize(jumpFallString, "M_J_", 4))
191214
{
192-
if (compareStrings(NextMap, "gor_01"))
215+
if (compareStringToNextMap("gor_01"))
193216
{
194217
// Return an arbitrary string
195218
const char *newString = "gor_01";
@@ -423,6 +446,7 @@ void initAssemblyOverwrites()
423446
void *BacktraceScreenFontSizeAddress = reinterpret_cast<void *>(0x80428BC0);
424447
void *BacktraceScreenPPCHaltBranchAddress = reinterpret_cast<void *>(0x8025E4A4);
425448
void *BacktraceScreenEndBranchAddress = reinterpret_cast<void *>(0x8025E4A8);
449+
void *FixRoomProblemsAddress = reinterpret_cast<void *>(0x800087C8);
426450
#elif defined TTYD_JP
427451
void *PreventPreBattleSoftlockAddress = reinterpret_cast<void *>(0x80045F28);
428452
void *DisableBattlesAddress = reinterpret_cast<void *>(0x80044228);
@@ -442,6 +466,7 @@ void initAssemblyOverwrites()
442466
void *FixBlooperCrash2Address = reinterpret_cast<void *>(0x8010A79C);
443467
void *FixMarioKeyOnAddress = reinterpret_cast<void *>(0x8005B370);
444468
void *PreventTextboxSelectionAddress = reinterpret_cast<void *>(0x800CE01C);
469+
void *FixRoomProblemsAddress = reinterpret_cast<void *>(0x800086F0);
445470
#elif defined TTYD_EU
446471
void *PreventPreBattleSoftlockAddress = reinterpret_cast<void *>(0x800466B4);
447472
void *DisableBattlesAddress = reinterpret_cast<void *>(0x800449B4);
@@ -464,6 +489,7 @@ void initAssemblyOverwrites()
464489
void *BacktraceScreenFontSizeAddress = reinterpret_cast<void *>(0x804356C8);
465490
void *BacktraceScreenPPCHaltBranchAddress = reinterpret_cast<void *>(0x8026207C);
466491
void *BacktraceScreenEndBranchAddress = reinterpret_cast<void *>(0x80262080);
492+
void *FixRoomProblemsAddress = reinterpret_cast<void *>(0x80008994);
467493
#endif
468494

469495
writeStandardBranch(PreventPreBattleSoftlockAddress,
@@ -502,6 +528,9 @@ void initAssemblyOverwrites()
502528
writeStandardBranch(PreventTextboxSelectionAddress,
503529
StartPreventTextboxSelection, BranchBackPreventTextboxSelection);
504530

531+
writeStandardBranch(FixRoomProblemsAddress,
532+
StartFixRoomProblems, BranchBackFixRoomProblems);
533+
505534
*reinterpret_cast<uint32_t *>(DebugModeInitialzeAddress) = 0x3800FFFF; // li r0,-1
506535
*reinterpret_cast<uint32_t *>(DebugModeShowBuildDateAddress) = 0x60000000; // nop
507536

0 commit comments

Comments
 (0)