|
22 | 22 | #include <ttyd/swdrv.h>
|
23 | 23 | #include <ttyd/win_main.h>
|
24 | 24 | #include <ttyd/itemdrv.h>
|
25 |
| -#include <ttyd/battle_ac.h> |
26 | 25 | #include <ttyd/battle_unit.h>
|
| 26 | +#include <ttyd/battle_ac.h> |
27 | 27 |
|
28 | 28 | #include <cstring>
|
29 | 29 | #include <cstdio>
|
@@ -1237,118 +1237,113 @@ int32_t Mod::preventMenuSounds(int32_t soundId, uint32_t unk1, uint32_t unk2, ui
|
1237 | 1237 | return mPFN_SoundEfxPlayEx_trampoline(soundId, unk1, unk2, unk3);
|
1238 | 1238 | }
|
1239 | 1239 |
|
1240 |
| -void actionCommandsTimingsInit() |
| 1240 | +int32_t Mod::displayActionCommandsTimingHook(void *battleUnitPtr, ttyd::battle_unit::AttackParams *attackParams) |
1241 | 1241 | {
|
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]) |
1246 | 1244 | {
|
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 |
1251 | 1259 |
|
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) |
1255 | 1262 | {
|
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); |
1270 | 1265 | }
|
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)) |
1282 | 1280 | {
|
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; |
1294 | 1283 | }
|
1295 | 1284 |
|
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)) |
1318 | 1286 | {
|
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; |
1322 | 1289 | }
|
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) |
1324 | 1332 | {
|
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; |
1327 | 1335 | DisplayActionCommands.TypeToDraw = PressedTooEarly;
|
1328 | 1336 | DisplayActionCommands.DisplayTimer = secondsToFrames(3);
|
1329 | 1337 | }
|
1330 |
| - else if (Last_B_Frame > -1) |
| 1338 | + else |
1331 | 1339 | {
|
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); |
1348 | 1343 | }
|
1349 |
| - |
1350 |
| - return DefenseResult; |
1351 |
| - }); |
| 1344 | + } |
| 1345 | + |
| 1346 | + return DefenseResult; |
1352 | 1347 | }
|
1353 | 1348 |
|
1354 | 1349 | void displayActionCommandsTiming()
|
|
0 commit comments