Fix early hits (#363)

Sometimes, the player can ground pound a pole before even landing or punch/kick an enemy at high speeds which will kill the enemy but not give bounce back to the player. This fixes those, although there are definitely mod incompatibilities.
This commit is contained in:
Sunk 2024-10-17 04:31:01 -04:00 committed by GitHub
parent 5300b559d3
commit 9621424069
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 14 additions and 4 deletions

View file

@ -3707,6 +3707,9 @@ INT_TWIRL = (1 << 8)
--- @type InteractionFlag
INT_GROUND_POUND_OR_TWIRL = (INT_GROUND_POUND | INT_TWIRL)
--- @type InteractionFlag
INT_LUA = (1 << 31)
--- @class InteractionType
--- @type InteractionType

View file

@ -1309,6 +1309,7 @@
| INT_HIT_FROM_BELOW | (1 << 7) |
| INT_TWIRL | (1 << 8) |
| INT_GROUND_POUND_OR_TWIRL | (INT_GROUND_POUND | INT_TWIRL) |
| INT_LUA | (1 << 31) |
### [enum InteractionType](#InteractionType)
| Identifier | Value |

View file

@ -158,7 +158,8 @@ u32 determine_interaction(struct MarioState *m, struct Object *o) {
if (interaction == 0 && action & ACT_FLAG_ATTACKING) {
u32 flags = (MARIO_PUNCHING | MARIO_KICKING | MARIO_TRIPPING);
if (m->flags & flags) {
if ((action == ACT_PUNCHING || action == ACT_MOVE_PUNCHING || action == ACT_JUMP_KICK) ||
(m->flags & flags && interaction & INT_LUA)) {
s16 dYawToObject = mario_obj_angle_to_object(m, o) - m->faceAngle[1];
if (m->flags & MARIO_PUNCHING) {
@ -236,6 +237,7 @@ u32 determine_interaction(struct MarioState *m, struct Object *o) {
u32 attack_object(struct MarioState* m, struct Object *o, s32 interaction) {
if (!o) { return 0; }
u32 attackType = 0;
interaction &= ~INT_LUA;
switch (interaction) {
case INT_GROUND_POUND:
@ -1868,7 +1870,7 @@ u32 interact_breakable(struct MarioState *m, UNUSED u32 interactType, struct Obj
m->interactObj = o;
switch (interaction) {
switch (interaction & ~INT_LUA) {
case INT_HIT_FROM_ABOVE:
bounce_off_object(m, o, 30.0f); //! Not in the 0x8F mask
break;
@ -1900,7 +1902,7 @@ u32 interact_koopa_shell(struct MarioState *m, UNUSED u32 interactType, struct O
if (!(m->action & ACT_FLAG_RIDING_SHELL)) {
u32 interaction = determine_interaction(m, o);
if (interaction == INT_HIT_FROM_ABOVE || m->action == ACT_WALKING
if (interaction & INT_HIT_FROM_ABOVE || m->action == ACT_WALKING
|| m->action == ACT_HOLD_WALKING) {
m->interactObj = o;
m->usedObj = o;

View file

@ -53,6 +53,7 @@ enum InteractionFlag {
INT_HIT_FROM_BELOW = /* 0x00000080 */ (1 << 7),
INT_TWIRL = /* 0x00000100 */ (1 << 8),
INT_GROUND_POUND_OR_TWIRL = (INT_GROUND_POUND | INT_TWIRL),
INT_LUA = /* 0x10000000 */ (1 << 31) ,
};
#define INT_ATTACK_NOT_FROM_BELOW (INT_GROUND_POUND_OR_TWIRL | INT_PUNCH | INT_KICK | INT_TRIP | INT_SLIDE_KICK | INT_FAST_ATTACK_OR_SHELL | INT_HIT_FROM_ABOVE)

View file

@ -2635,7 +2635,8 @@ s32 cur_obj_is_mario_ground_pounding_platform(void) {
if (!is_player_active(&gMarioStates[i])) { continue; }
if (!gMarioStates[i].marioObj) { continue; }
if (gMarioStates[i].marioObj->platform == o) {
if ((determine_interaction(&gMarioStates[i], o) & INT_GROUND_POUND) || (gMarioStates[i].action == ACT_GROUND_POUND_LAND)) {
u32 interaction = determine_interaction(&gMarioStates[i], o);
if ((gMarioStates[i].action == ACT_GROUND_POUND_LAND) || (interaction & INT_GROUND_POUND && interaction & INT_LUA)) {
return TRUE;
}
}

View file

@ -1419,6 +1419,7 @@ char gSmluaConstants[] = ""
"INT_HIT_FROM_BELOW = (1 << 7)\n"
"INT_TWIRL = (1 << 8)\n"
"INT_GROUND_POUND_OR_TWIRL = (INT_GROUND_POUND | INT_TWIRL)\n"
"INT_LUA = (1 << 31)\n"
"INT_ATTACK_NOT_FROM_BELOW = (INT_GROUND_POUND_OR_TWIRL | INT_PUNCH | INT_KICK | INT_TRIP | INT_SLIDE_KICK | INT_FAST_ATTACK_OR_SHELL | INT_HIT_FROM_ABOVE)\n"
"INT_ANY_ATTACK = (INT_GROUND_POUND_OR_TWIRL | INT_PUNCH | INT_KICK | INT_TRIP | INT_SLIDE_KICK | INT_FAST_ATTACK_OR_SHELL | INT_HIT_FROM_ABOVE | INT_HIT_FROM_BELOW)\n"
"INT_ATTACK_NOT_WEAK_FROM_ABOVE = (INT_GROUND_POUND_OR_TWIRL | INT_PUNCH | INT_KICK | INT_TRIP | INT_HIT_FROM_BELOW)\n"

View file

@ -1217,6 +1217,7 @@ int smlua_hook_mario_action(lua_State* L) {
lua_Integer interactionType = 0;
if (paramCount >= 3) {
interactionType = smlua_to_integer(L, 3);
interactionType |= (1 << 31); /* INT_LUA */
if (!gSmLuaConvertSuccess) {
LOG_LUA_LINE("Hook Action: tried to hook invalid interactionType: %lld, %u", interactionType, gSmLuaConvertSuccess);
return 0;