Skip to content

Commit c9d6503

Browse files
committed
Bug Fix + Modified the Auto Action Commands code
Fixed the code that displays guard/superguard timings to work properly when an attack cannot be superguarded, or if the debug badge is equipped. If the player tries to superguard an attack that cannot be superguarded, a message will be printed saying so. Adjusted the Auto Action Commands code to guard/superguard more attacks. It now effectively works exactly the same as the Debug Badge.
1 parent 121e106 commit c9d6503

File tree

6 files changed

+110
-84
lines changed

6 files changed

+110
-84
lines changed

ttyd-tools/rel/include/mod.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Mod
1212

1313
private:
1414
void run();
15-
void preventButtonInputInBattle();
15+
void performBattleChecks();
1616
int32_t pauseMenuPreventUnpause(void *);
1717
bool infiniteItemUsage(int16_t, uint32_t);
1818
bool performPreBattleActions();

ttyd-tools/rel/source/assembly/AutoActionCommands.s

Lines changed: 0 additions & 18 deletions
This file was deleted.

ttyd-tools/rel/source/codes.cpp

Lines changed: 95 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "patch.h"
66
#include "menufunctions.h"
77
#include "global.h"
8+
#include "items.h"
89
#include "maps.h"
910

1011
#include <ttyd/system.h>
@@ -40,37 +41,6 @@ uint32_t disableBattles(void *ptr)
4041
reinterpret_cast<uint32_t>(ptr) + 0x4);
4142
}
4243

43-
void *autoActionCommands(void *ptr)
44-
{
45-
uint32_t tempPtr = reinterpret_cast<uint32_t>(ptr);
46-
47-
if (Cheat[AUTO_ACTION_COMMANDS].Active)
48-
{
49-
#ifdef TTYD_US
50-
const uint32_t StoreByteOffset = 0x307;
51-
#elif defined TTYD_JP
52-
const uint32_t StoreByteOffset = 0x303;
53-
#elif defined TTYD_EU
54-
const uint32_t StoreByteOffset = 0x30B;
55-
#endif
56-
57-
uint32_t tempStoreAddress = *reinterpret_cast<uint32_t *>(tempPtr + 0x1C90);
58-
if (tempStoreAddress)
59-
{
60-
if (checkButtonComboEveryFrame(Cheat[AUTO_ACTION_COMMANDS].ButtonCombo))
61-
{
62-
*reinterpret_cast<bool *>(tempStoreAddress + StoreByteOffset) = true;
63-
}
64-
else
65-
{
66-
*reinterpret_cast<bool *>(tempStoreAddress + StoreByteOffset) = false;
67-
}
68-
}
69-
}
70-
71-
return *reinterpret_cast<uint32_t **>(tempPtr + 0xEF4);
72-
}
73-
7444
uint32_t allowRunningFromBattles(void *ptr)
7545
{
7646
if (Cheat[RUN_FROM_BATTLES].Active)
@@ -100,6 +70,62 @@ bool checkForArtAttackHitboxesBool()
10070
}
10171
}
10272

73+
void Mod::performBattleChecks()
74+
{
75+
// Check to see if the Auto Action Commands cheat is active or not
76+
if (Cheat[AUTO_ACTION_COMMANDS].Active)
77+
{
78+
uint32_t MarioBattlePointer = reinterpret_cast<uint32_t>(getMarioBattlePointer());
79+
80+
if (MarioBattlePointer != 0)
81+
{
82+
#ifdef TTYD_US
83+
const uint32_t DebugBadgeAddressOffset = 0x307;
84+
#elif defined TTYD_JP
85+
const uint32_t DebugBadgeAddressOffset = 0x303;
86+
#elif defined TTYD_EU
87+
const uint32_t DebugBadgeAddressOffset = 0x30B;
88+
#endif
89+
90+
uint32_t PartnerBattlePointer = reinterpret_cast<uint32_t>(getPartnerBattlePointer());
91+
92+
if (checkButtonComboEveryFrame(Cheat[AUTO_ACTION_COMMANDS].ButtonCombo) ||
93+
checkIfBadgeEquipped(DebugBadge))
94+
{
95+
*reinterpret_cast<uint8_t *>(MarioBattlePointer + DebugBadgeAddressOffset) = 1;
96+
97+
if (PartnerBattlePointer != 0)
98+
{
99+
*reinterpret_cast<uint8_t *>(PartnerBattlePointer + DebugBadgeAddressOffset) = 1;
100+
}
101+
}
102+
else
103+
{
104+
*reinterpret_cast<uint8_t *>(MarioBattlePointer + DebugBadgeAddressOffset) = 0;
105+
106+
if (PartnerBattlePointer != 0)
107+
{
108+
*reinterpret_cast<uint8_t *>(PartnerBattlePointer + DebugBadgeAddressOffset) = 0;
109+
}
110+
}
111+
}
112+
}
113+
114+
// Prevent all buttons from being pressed when the menu is open, exccept for R and X
115+
if (MenuIsDisplayed)
116+
{
117+
if (!checkButtonComboEveryFrame(PAD_R) &&
118+
!checkButtonComboEveryFrame(PAD_X))
119+
{
120+
// The menu is open and neither R nor X are being pressed, so prevent the function from running
121+
return;
122+
}
123+
}
124+
125+
// Call original function
126+
mPFN_BattlePadManager_trampoline();
127+
}
128+
103129
void walkThroughMostObjects()
104130
{
105131
if (!Cheat[WALK_THROUGH_WALLS].Active ||
@@ -932,6 +958,26 @@ void actionCommandsTimingsInit()
932958
return DisplayActionCommands.Trampoline(battle_unit, attack_params);
933959
}
934960

961+
// Check to see if the attack will be automatically guarded/superguarded or not
962+
uint32_t MarioBattlePointer = reinterpret_cast<uint32_t>(getMarioBattlePointer());
963+
if (MarioBattlePointer != 0)
964+
{
965+
#ifdef TTYD_US
966+
const uint32_t DebugBadgeAddressOffset = 0x307;
967+
#elif defined TTYD_JP
968+
const uint32_t DebugBadgeAddressOffset = 0x303;
969+
#elif defined TTYD_EU
970+
const uint32_t DebugBadgeAddressOffset = 0x30B;
971+
#endif
972+
973+
uint8_t DebugBadgeCheck = *reinterpret_cast<uint8_t *>(MarioBattlePointer + DebugBadgeAddressOffset);
974+
if (DebugBadgeCheck > 0)
975+
{
976+
// The attack will be automatically guarded/superguarded
977+
return DisplayActionCommands.Trampoline(battle_unit, attack_params);
978+
}
979+
}
980+
935981
// Reset the values checked when drawing the text
936982
DisplayActionCommands.TypeToDraw = 0;
937983
DisplayActionCommands.Last_A_Frame = -1;
@@ -962,6 +1008,7 @@ void actionCommandsTimingsInit()
9621008
const uint32_t SuccessfulTiming = 1;
9631009
const uint32_t PressedTooManyButtons = 2;
9641010
const uint32_t PressedTooEarly = 3;
1011+
const uint32_t CannotBeSuperguarded = 4;
9651012

9661013
if (DefenseResult == 4)
9671014
{
@@ -992,10 +1039,23 @@ void actionCommandsTimingsInit()
9921039
}
9931040
else if (Last_B_Frame > -1)
9941041
{
995-
// Print how many frames early the player pressed B
996-
DisplayActionCommands.Last_B_Frame = Last_B_Frame;
997-
DisplayActionCommands.TypeToDraw = PressedTooEarly;
998-
DisplayActionCommands.DisplayTimer = secondsToFrames(3);
1042+
// Check if the attack can be superguarded or not
1043+
uint8_t SuperguardCheck = *reinterpret_cast<uint8_t *>(
1044+
reinterpret_cast<uint32_t>(attack_params) + 0x13);
1045+
1046+
if (SuperguardCheck > 0)
1047+
{
1048+
// Print how many frames early the player pressed B
1049+
DisplayActionCommands.Last_B_Frame = Last_B_Frame;
1050+
DisplayActionCommands.TypeToDraw = PressedTooEarly;
1051+
DisplayActionCommands.DisplayTimer = secondsToFrames(3);
1052+
}
1053+
else
1054+
{
1055+
// The attack cannot be superguarded, so print the text saying so
1056+
DisplayActionCommands.TypeToDraw = CannotBeSuperguarded;
1057+
DisplayActionCommands.DisplayTimer = secondsToFrames(3);
1058+
}
9991059
}
10001060

10011061
return DefenseResult;

ttyd-tools/rel/source/draw.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2612,12 +2612,14 @@ void drawActionCommandsTiming()
26122612
int32_t temp_Last_B_Frame = DisplayActionCommands.Last_B_Frame;
26132613

26142614
uint32_t TypeToDraw = DisplayActionCommands.TypeToDraw;
2615-
const char *TextToDraw;
26162615
char *tempDisplayBuffer = DisplayBuffer;
2616+
uint32_t IncrementWindowWidth = 129;
2617+
const char *TextToDraw;
26172618

26182619
const uint32_t SuccessfulTiming = 1;
26192620
const uint32_t PressedTooManyButtons = 2;
26202621
const uint32_t PressedTooEarly = 3;
2622+
const uint32_t CannotBeSuperguarded = 4;
26212623

26222624
// Check to see which text should be displayed
26232625
switch (TypeToDraw)
@@ -2675,7 +2677,7 @@ void drawActionCommandsTiming()
26752677
}
26762678

26772679
const char *CheckForPlural;
2678-
if (FramesEarly > 1)
2680+
if (FramesEarly != 1)
26792681
{
26802682
CheckForPlural = "s";
26812683
}
@@ -2693,6 +2695,12 @@ void drawActionCommandsTiming()
26932695
TextToDraw = tempDisplayBuffer;
26942696
break;
26952697
}
2698+
case CannotBeSuperguarded:
2699+
{
2700+
TextToDraw = "Cannot superguard this attack";
2701+
IncrementWindowWidth += 7;
2702+
break;
2703+
}
26962704
default:
26972705
{
26982706
DisplayActionCommands.DisplayTimer = 0;
@@ -2710,7 +2718,7 @@ void drawActionCommandsTiming()
27102718
float Scale = 0.75;
27112719

27122720
uint32_t LineLength = ttyd::fontmgr::FontGetMessageWidth(TextToDraw);
2713-
int32_t WindowWidth = 129 + (LineLength >> 1) - (LineLength % 10);
2721+
int32_t WindowWidth = IncrementWindowWidth + (LineLength >> 1) - (LineLength % 10);
27142722

27152723
drawTextWithWindow(TextToDraw, TextPosX, TextPosY, Alpha, TextColor,
27162724
Scale, WindowWidth, WindowColor, WindowCurve);
@@ -2739,10 +2747,10 @@ void drawTitleScreenInfo()
27392747
uint32_t TextColor = 0xFFFFFFFF;
27402748
uint8_t Alpha = 0xFF;
27412749
float Scale = 0.75;
2742-
PosX += 113;
2750+
PosX += 108;
27432751
PosY -= 14;
27442752

2745-
const char *String = "Practice Codes v3.0.9\nCreated by Zephiles";
2753+
const char *String = "Practice Codes v3.0.10\nCreated by Zephiles";
27462754
drawText(String, PosX, PosY, Alpha, TextColor, Scale);
27472755
}
27482756

ttyd-tools/rel/source/main.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ extern "C"
2626
void BranchBackPreventPreBattleSoftlock();
2727
void StartDisableBattles();
2828
void BranchBackDisableBattles();
29-
void StartAutoActionCommands();
30-
void BranchBackAutoActionCommands();
3129
void StartInfiniteItemUsage();
3230
void BranchBackInfiniteItemUsage();
3331
void StartReplaceJumpFallAnim();
@@ -310,22 +308,6 @@ int32_t Mod::pauseMenuPreventUnpause(void *pauseMenuPointer)
310308
}
311309
}
312310

313-
void Mod::preventButtonInputInBattle()
314-
{
315-
if (MenuIsDisplayed)
316-
{
317-
if (!checkButtonComboEveryFrame(PAD_R) &&
318-
!checkButtonComboEveryFrame(PAD_X))
319-
{
320-
// The menu is open and neither R nor X are being pressed, so prevent the function from running
321-
return;
322-
}
323-
}
324-
325-
// Call original function
326-
mPFN_BattlePadManager_trampoline();
327-
}
328-
329311
bool Mod::performPreBattleActions()
330312
{
331313
// Make sure the Jump and Hammer upgrades have been properly checked
@@ -448,7 +430,6 @@ void initAssemblyOverwrites()
448430
#ifdef TTYD_US
449431
void *PreventPreBattleSoftlockAddress = reinterpret_cast<void *>(0x800465CC);
450432
void *DisableBattlesAddress = reinterpret_cast<void *>(0x800448CC);
451-
void *AutoActionCommandsAddress = reinterpret_cast<void *>(0x800F78F0);
452433
void *AllowRunningFromBattles = reinterpret_cast<void *>(0x80123CA4);
453434
void *ForceNPCItemDropAddress = reinterpret_cast<void *>(0x8004EC10);
454435
void *DebugModeInitialzeAddress = reinterpret_cast<void *>(0x80009B2C);
@@ -471,7 +452,6 @@ void initAssemblyOverwrites()
471452
#elif defined TTYD_JP
472453
void *PreventPreBattleSoftlockAddress = reinterpret_cast<void *>(0x80045F28);
473454
void *DisableBattlesAddress = reinterpret_cast<void *>(0x80044228);
474-
void *AutoActionCommandsAddress = reinterpret_cast<void *>(0x800F29A4);
475455
void *AllowRunningFromBattles = reinterpret_cast<void *>(0x8011E7DC);
476456
void *ForceNPCItemDropAddress = reinterpret_cast<void *>(0x8004DFB0);
477457
void *DebugModeInitialzeAddress = reinterpret_cast<void *>(0x8000999C);
@@ -492,7 +472,6 @@ void initAssemblyOverwrites()
492472
#elif defined TTYD_EU
493473
void *PreventPreBattleSoftlockAddress = reinterpret_cast<void *>(0x800466B4);
494474
void *DisableBattlesAddress = reinterpret_cast<void *>(0x800449B4);
495-
void *AutoActionCommandsAddress = reinterpret_cast<void *>(0x800F875C);
496475
void *AllowRunningFromBattles = reinterpret_cast<void *>(0x80124BE4);
497476
void *ForceNPCItemDropAddress = reinterpret_cast<void *>(0x8004ECDC);
498477
void *DebugModeInitialzeAddress = reinterpret_cast<void *>(0x80009CF0);
@@ -519,9 +498,6 @@ void initAssemblyOverwrites()
519498

520499
writeStandardBranch(DisableBattlesAddress,
521500
StartDisableBattles, BranchBackDisableBattles);
522-
523-
writeStandardBranch(AutoActionCommandsAddress,
524-
StartAutoActionCommands, BranchBackAutoActionCommands);
525501

526502
writeStandardBranch(AllowRunningFromBattles,
527503
StartAllowRunningFromBattles, BranchBackAllowRunningFromBattles);

ttyd-tools/rel/source/mod.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void Mod::init()
4747
mPFN_BattlePadManager_trampoline = patch::hookFunction(
4848
ttyd::battle_pad::BattlePadManager, []()
4949
{
50-
gMod->preventButtonInputInBattle();
50+
gMod->performBattleChecks();
5151
});
5252

5353
mPFN_winRootMain_trampoline = patch::hookFunction(

0 commit comments

Comments
 (0)