Skip to content

Commit ed53efb

Browse files
committed
Moved the Action Commands Timing function hook to mod.cpp
1 parent 100f5b5 commit ed53efb

File tree

6 files changed

+110
-106
lines changed

6 files changed

+110
-106
lines changed

ttyd-tools/rel/include/codes.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ void displayMemoryWatches();
3434
void displayYoshiSkipDetails();
3535
void displayPalaceSkipDetails();
3636
void displayBlimpTicketSkipDetails();
37-
void actionCommandsTimingsInit();
3837
void displayActionCommandsTiming();
3938

4039
int32_t warpToMap(uint32_t value);

ttyd-tools/rel/include/global.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#pragma once
22

33
#include <ttyd/item_data.h>
4-
#include <ttyd/battle_unit.h>
54

65
#include <cstdint>
76

@@ -629,9 +628,8 @@ struct OnScreenTimerDisplay
629628
}
630629
};
631630

632-
struct DisplayActionCommandTiming
631+
struct DisplayActionCommandsTiming
633632
{
634-
int32_t (*Trampoline)(void *, ttyd::battle_unit::AttackParams *);
635633
uint16_t DisplayTimer;
636634
uint8_t TypeToDraw;
637635
int8_t Last_A_Frame;
@@ -756,7 +754,7 @@ extern TrickDisplay YoshiSkip;
756754
extern TrickDisplay PalaceSkip;
757755
extern BlimpTicketSkipStruct BlimpTicketSkip;
758756
extern OnScreenTimerDisplay OnScreenTimer;
759-
extern DisplayActionCommandTiming DisplayActionCommands;
757+
extern DisplayActionCommandsTiming DisplayActionCommands;
760758
extern MemoryCardStruct MenuSettings;
761759
extern WarpByEventStruct WarpByEvent;
762760
extern WarpByIndexStruct WarpByIndex;

ttyd-tools/rel/include/mod.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <gc/OSModule.h>
4+
#include <ttyd/battle_unit.h>
45

56
#include <cstdint>
67

@@ -26,6 +27,7 @@ class Mod
2627
bool performRelPatches(gc::OSModule::OSModuleInfo *, void *);
2728
void *disableBattles(uint32_t, void *);
2829
void drawArtAttackHitboxes(uint32_t);
30+
int32_t displayActionCommandsTimingHook(void *, ttyd::battle_unit::AttackParams *);
2931

3032
private:
3133
void (*mPFN_marioStMain_trampoline)() = nullptr;
@@ -44,6 +46,9 @@ class Mod
4446
bool (*mPFN_OSLink_trampoline)(gc::OSModule::OSModuleInfo *, void *) = nullptr;
4547
void *(*mPFN_fbatHitCheck_trampoline)(uint32_t, void *) = nullptr;
4648
void (*mPFN_scissor_disp_control_trampoline)(uint32_t) = nullptr;
49+
50+
int32_t (*mPFN_BattleActionCommandCheckDefence_trampoline)(
51+
void *, ttyd::battle_unit::AttackParams *) = nullptr;
4752
};
4853

4954
}

ttyd-tools/rel/source/codes.cpp

Lines changed: 92 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
#include <ttyd/swdrv.h>
2323
#include <ttyd/win_main.h>
2424
#include <ttyd/itemdrv.h>
25-
#include <ttyd/battle_ac.h>
2625
#include <ttyd/battle_unit.h>
26+
#include <ttyd/battle_ac.h>
2727

2828
#include <cstring>
2929
#include <cstdio>
@@ -1237,118 +1237,113 @@ int32_t Mod::preventMenuSounds(int32_t soundId, uint32_t unk1, uint32_t unk2, ui
12371237
return mPFN_SoundEfxPlayEx_trampoline(soundId, unk1, unk2, unk3);
12381238
}
12391239

1240-
void actionCommandsTimingsInit()
1240+
int32_t Mod::displayActionCommandsTimingHook(void *battleUnitPtr, ttyd::battle_unit::AttackParams *attackParams)
12411241
{
1242-
// Credits to Jdaster64 for writing the original code for this
1243-
DisplayActionCommands.Trampoline = patch::hookFunction(
1244-
ttyd::battle_ac::BattleActionCommandCheckDefence, [](
1245-
void *battleUnitPtr, ttyd::battle_unit::AttackParams *attackParams)
1242+
// Credits to Jdaster64 for writing the original code for this function
1243+
if (!Displays[GUARD_SUPERGUARD_TIMINGS])
12461244
{
1247-
if (!Displays[GUARD_SUPERGUARD_TIMINGS])
1248-
{
1249-
return DisplayActionCommands.Trampoline(battleUnitPtr, attackParams);
1250-
}
1245+
return mPFN_BattleActionCommandCheckDefence_trampoline(battleUnitPtr, attackParams);
1246+
}
1247+
1248+
// Check to see if the attack will be automatically guarded/superguarded or not
1249+
uint32_t MarioBattlePointer = reinterpret_cast<uint32_t>(getMarioBattlePointer());
1250+
if (MarioBattlePointer)
1251+
{
1252+
#ifdef TTYD_US
1253+
const uint32_t DebugBadgeAddressOffset = 0x307;
1254+
#elif defined TTYD_JP
1255+
const uint32_t DebugBadgeAddressOffset = 0x303;
1256+
#elif defined TTYD_EU
1257+
const uint32_t DebugBadgeAddressOffset = 0x30B;
1258+
#endif
12511259

1252-
// Check to see if the attack will be automatically guarded/superguarded or not
1253-
uint32_t MarioBattlePointer = reinterpret_cast<uint32_t>(getMarioBattlePointer());
1254-
if (MarioBattlePointer)
1260+
uint8_t DebugBadgeCheck = *reinterpret_cast<uint8_t *>(MarioBattlePointer + DebugBadgeAddressOffset);
1261+
if (DebugBadgeCheck > 0)
12551262
{
1256-
#ifdef TTYD_US
1257-
const uint32_t DebugBadgeAddressOffset = 0x307;
1258-
#elif defined TTYD_JP
1259-
const uint32_t DebugBadgeAddressOffset = 0x303;
1260-
#elif defined TTYD_EU
1261-
const uint32_t DebugBadgeAddressOffset = 0x30B;
1262-
#endif
1263-
1264-
uint8_t DebugBadgeCheck = *reinterpret_cast<uint8_t *>(MarioBattlePointer + DebugBadgeAddressOffset);
1265-
if (DebugBadgeCheck > 0)
1266-
{
1267-
// The attack will be automatically guarded/superguarded
1268-
return DisplayActionCommands.Trampoline(battleUnitPtr, attackParams);
1269-
}
1263+
// The attack will be automatically guarded/superguarded
1264+
return mPFN_BattleActionCommandCheckDefence_trampoline(battleUnitPtr, attackParams);
12701265
}
1271-
1272-
// Reset the values checked when drawing the text
1273-
DisplayActionCommands.TypeToDraw = 0;
1274-
DisplayActionCommands.Last_A_Frame = -1;
1275-
DisplayActionCommands.Last_B_Frame = -1;
1276-
1277-
int32_t Last_A_Frame = -1;
1278-
int32_t Last_B_Frame = -1;
1279-
int32_t ButtonPresses = 0;
1280-
1281-
for (int32_t Frame = 0; Frame < 15; ++Frame)
1266+
}
1267+
1268+
// Reset the values checked when drawing the text
1269+
DisplayActionCommands.TypeToDraw = 0;
1270+
DisplayActionCommands.Last_A_Frame = -1;
1271+
DisplayActionCommands.Last_B_Frame = -1;
1272+
1273+
int32_t Last_A_Frame = -1;
1274+
int32_t Last_B_Frame = -1;
1275+
int32_t ButtonPresses = 0;
1276+
1277+
for (int32_t Frame = 0; Frame < 15; ++Frame)
1278+
{
1279+
if (ttyd::battle_ac::BattleACPadCheckRecordTrigger(Frame, PAD_A))
12821280
{
1283-
if (ttyd::battle_ac::BattleACPadCheckRecordTrigger(Frame, PAD_A))
1284-
{
1285-
Last_A_Frame = Frame;
1286-
++ButtonPresses;
1287-
}
1288-
1289-
if (ttyd::battle_ac::BattleACPadCheckRecordTrigger(Frame, PAD_B))
1290-
{
1291-
Last_B_Frame = Frame;
1292-
++ButtonPresses;
1293-
}
1281+
Last_A_Frame = Frame;
1282+
++ButtonPresses;
12941283
}
12951284

1296-
const int32_t DefenseResult = DisplayActionCommands.Trampoline(battleUnitPtr, attackParams);
1297-
1298-
const uint32_t SuccessfulTiming = 1;
1299-
const uint32_t PressedTooManyButtons = 2;
1300-
const uint32_t PressedTooEarly = 3;
1301-
const uint32_t CannotBeSuperguarded = 4;
1302-
1303-
if (DefenseResult == 4)
1304-
{
1305-
// Successful Guard; print Last_A_Frame
1306-
DisplayActionCommands.Last_A_Frame = Last_A_Frame;
1307-
DisplayActionCommands.TypeToDraw = SuccessfulTiming;
1308-
DisplayActionCommands.DisplayTimer = secondsToFrames(3);
1309-
}
1310-
else if (DefenseResult == 5)
1311-
{
1312-
// Successful Superguard; print Last_B_Frame
1313-
DisplayActionCommands.Last_B_Frame = Last_B_Frame;
1314-
DisplayActionCommands.TypeToDraw = SuccessfulTiming;
1315-
DisplayActionCommands.DisplayTimer = secondsToFrames(3);
1316-
}
1317-
else if (ButtonPresses > 1) // Unsuccessful, otherwise...
1285+
if (ttyd::battle_ac::BattleACPadCheckRecordTrigger(Frame, PAD_B))
13181286
{
1319-
// Hit too many buttons in last 15 frames
1320-
DisplayActionCommands.TypeToDraw = PressedTooManyButtons;
1321-
DisplayActionCommands.DisplayTimer = secondsToFrames(3);
1287+
Last_B_Frame = Frame;
1288+
++ButtonPresses;
13221289
}
1323-
else if (Last_A_Frame > -1)
1290+
}
1291+
1292+
const int32_t DefenseResult = mPFN_BattleActionCommandCheckDefence_trampoline(battleUnitPtr, attackParams);
1293+
1294+
const uint32_t SuccessfulTiming = 1;
1295+
const uint32_t PressedTooManyButtons = 2;
1296+
const uint32_t PressedTooEarly = 3;
1297+
const uint32_t CannotBeSuperguarded = 4;
1298+
1299+
if (DefenseResult == 4)
1300+
{
1301+
// Successful Guard; print Last_A_Frame
1302+
DisplayActionCommands.Last_A_Frame = Last_A_Frame;
1303+
DisplayActionCommands.TypeToDraw = SuccessfulTiming;
1304+
DisplayActionCommands.DisplayTimer = secondsToFrames(3);
1305+
}
1306+
else if (DefenseResult == 5)
1307+
{
1308+
// Successful Superguard; print Last_B_Frame
1309+
DisplayActionCommands.Last_B_Frame = Last_B_Frame;
1310+
DisplayActionCommands.TypeToDraw = SuccessfulTiming;
1311+
DisplayActionCommands.DisplayTimer = secondsToFrames(3);
1312+
}
1313+
else if (ButtonPresses > 1) // Unsuccessful, otherwise...
1314+
{
1315+
// Hit too many buttons in last 15 frames
1316+
DisplayActionCommands.TypeToDraw = PressedTooManyButtons;
1317+
DisplayActionCommands.DisplayTimer = secondsToFrames(3);
1318+
}
1319+
else if (Last_A_Frame > -1)
1320+
{
1321+
// Print how many frames early the player pressed A
1322+
DisplayActionCommands.Last_A_Frame = Last_A_Frame;
1323+
DisplayActionCommands.TypeToDraw = PressedTooEarly;
1324+
DisplayActionCommands.DisplayTimer = secondsToFrames(3);
1325+
}
1326+
else if (Last_B_Frame > -1)
1327+
{
1328+
// Check if the attack can be superguarded or not
1329+
int8_t GuardTypesCheck = attackParams->guardTypesAllowed;
1330+
1331+
if (GuardTypesCheck > 0)
13241332
{
1325-
// Print how many frames early the player pressed A
1326-
DisplayActionCommands.Last_A_Frame = Last_A_Frame;
1333+
// Print how many frames early the player pressed B
1334+
DisplayActionCommands.Last_B_Frame = Last_B_Frame;
13271335
DisplayActionCommands.TypeToDraw = PressedTooEarly;
13281336
DisplayActionCommands.DisplayTimer = secondsToFrames(3);
13291337
}
1330-
else if (Last_B_Frame > -1)
1338+
else
13311339
{
1332-
// Check if the attack can be superguarded or not
1333-
int8_t GuardTypesCheck = attackParams->guardTypesAllowed;
1334-
1335-
if (GuardTypesCheck > 0)
1336-
{
1337-
// Print how many frames early the player pressed B
1338-
DisplayActionCommands.Last_B_Frame = Last_B_Frame;
1339-
DisplayActionCommands.TypeToDraw = PressedTooEarly;
1340-
DisplayActionCommands.DisplayTimer = secondsToFrames(3);
1341-
}
1342-
else
1343-
{
1344-
// The attack cannot be superguarded, so print the text saying so
1345-
DisplayActionCommands.TypeToDraw = CannotBeSuperguarded;
1346-
DisplayActionCommands.DisplayTimer = secondsToFrames(3);
1347-
}
1340+
// The attack cannot be superguarded, so print the text saying so
1341+
DisplayActionCommands.TypeToDraw = CannotBeSuperguarded;
1342+
DisplayActionCommands.DisplayTimer = secondsToFrames(3);
13481343
}
1349-
1350-
return DefenseResult;
1351-
});
1344+
}
1345+
1346+
return DefenseResult;
13521347
}
13531348

13541349
void displayActionCommandsTiming()

ttyd-tools/rel/source/global.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace mod {
55

6-
const char *VersionNumber = "v3.0.37";
6+
const char *VersionNumber = "v3.0.38";
77

88
const char *RootLines[] =
99
{
@@ -1826,7 +1826,7 @@ struct TrickDisplay YoshiSkip;
18261826
struct TrickDisplay PalaceSkip;
18271827
struct BlimpTicketSkipStruct BlimpTicketSkip;
18281828
struct OnScreenTimerDisplay OnScreenTimer;
1829-
struct DisplayActionCommandTiming DisplayActionCommands;
1829+
struct DisplayActionCommandsTiming DisplayActionCommands;
18301830
struct MemoryCardStruct MenuSettings;
18311831
struct WarpByEventStruct WarpByEvent;
18321832
struct WarpByIndexStruct WarpByIndex;

ttyd-tools/rel/source/mod.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "mod.h"
22
#include "global.h"
3-
#include "codes.h"
43
#include "patch.h"
54

65
#include <gc/OSModule.h>
@@ -15,6 +14,8 @@
1514
#include <ttyd/evt_bero.h>
1615
#include <ttyd/mario.h>
1716
#include <ttyd/npcdrv.h>
17+
#include <ttyd/battle_ac.h>
18+
#include <ttyd/battle_unit.h>
1819
#include <ttyd/fontmgr.h>
1920
#include <ttyd/windowdrv.h>
2021
#include <ttyd/seq_logo.h>
@@ -39,7 +40,6 @@ void Mod::init()
3940
gMod = this;
4041
initMenuVars();
4142
initAddressOverwrites();
42-
actionCommandsTimingsInit();
4343

4444
mPFN_marioStMain_trampoline = patch::hookFunction(
4545
ttyd::mariost::marioStMain, []()
@@ -119,6 +119,13 @@ void Mod::init()
119119
{
120120
return gMod->drawArtAttackHitboxes(camId);
121121
});
122+
123+
mPFN_BattleActionCommandCheckDefence_trampoline = patch::hookFunction(
124+
ttyd::battle_ac::BattleActionCommandCheckDefence, [](
125+
void *battleUnitPtr, ttyd::battle_unit::AttackParams *attackParams)
126+
{
127+
return gMod->displayActionCommandsTimingHook(battleUnitPtr, attackParams);
128+
});
122129

123130
// Initialize typesetting early
124131
ttyd::fontmgr::fontmgrTexSetup();

0 commit comments

Comments
 (0)