|
5 | 5 | #include "patch.h"
|
6 | 6 | #include "menufunctions.h"
|
7 | 7 | #include "global.h"
|
| 8 | +#include "items.h" |
8 | 9 | #include "maps.h"
|
9 | 10 |
|
10 | 11 | #include <ttyd/system.h>
|
@@ -40,37 +41,6 @@ uint32_t disableBattles(void *ptr)
|
40 | 41 | reinterpret_cast<uint32_t>(ptr) + 0x4);
|
41 | 42 | }
|
42 | 43 |
|
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 |
| - |
74 | 44 | uint32_t allowRunningFromBattles(void *ptr)
|
75 | 45 | {
|
76 | 46 | if (Cheat[RUN_FROM_BATTLES].Active)
|
@@ -100,6 +70,62 @@ bool checkForArtAttackHitboxesBool()
|
100 | 70 | }
|
101 | 71 | }
|
102 | 72 |
|
| 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 | + |
103 | 129 | void walkThroughMostObjects()
|
104 | 130 | {
|
105 | 131 | if (!Cheat[WALK_THROUGH_WALLS].Active ||
|
@@ -932,6 +958,26 @@ void actionCommandsTimingsInit()
|
932 | 958 | return DisplayActionCommands.Trampoline(battle_unit, attack_params);
|
933 | 959 | }
|
934 | 960 |
|
| 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 | + |
935 | 981 | // Reset the values checked when drawing the text
|
936 | 982 | DisplayActionCommands.TypeToDraw = 0;
|
937 | 983 | DisplayActionCommands.Last_A_Frame = -1;
|
@@ -962,6 +1008,7 @@ void actionCommandsTimingsInit()
|
962 | 1008 | const uint32_t SuccessfulTiming = 1;
|
963 | 1009 | const uint32_t PressedTooManyButtons = 2;
|
964 | 1010 | const uint32_t PressedTooEarly = 3;
|
| 1011 | + const uint32_t CannotBeSuperguarded = 4; |
965 | 1012 |
|
966 | 1013 | if (DefenseResult == 4)
|
967 | 1014 | {
|
@@ -992,10 +1039,23 @@ void actionCommandsTimingsInit()
|
992 | 1039 | }
|
993 | 1040 | else if (Last_B_Frame > -1)
|
994 | 1041 | {
|
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 | + } |
999 | 1059 | }
|
1000 | 1060 |
|
1001 | 1061 | return DefenseResult;
|
|
0 commit comments