fix cross-floor commands in EnemyDamageSync

This commit is contained in:
Martin Michelsen
2025-09-10 21:08:43 -07:00
parent b1d51cdbbe
commit c7a0873ca8
5 changed files with 132 additions and 106 deletions
@@ -155,7 +155,13 @@ handle_6xE4: # [std] (G_IncrementEnemyDamage_Extension_6xE4* cmd @ r3) -> void
blt handle_6xE4_return
cmplwi r3, 0x1B50
bge handle_6xE4_return
bl state_for_enemy # auto* st = state_for_enemy(cmd->header.entity_id);
bl get_enemy_entity
stw [r1 + 0x18], r3 # TObjEnemy* ene @ var18 = get_enemy_entity(cmd->header.entity_id);
li r3, 2
lhbrx r3, [r31 + r3]
bl state_for_enemy # EnemyState* st = state_for_enemy(cmd->header.entity_id);
lhz r4, [r3 + 6] # st->total_damage
li r5, 0x04
@@ -175,7 +181,10 @@ handle_6xE4: # [std] (G_IncrementEnemyDamage_Extension_6xE4* cmd @ r3) -> void
ori r4, r4, 0x800
stw [r3], r4 # st->game_flags |= 0x800;
# Send 6x0A with dead flag
# Send 6x0A with dead flag, but only if the entity is constructed
lwz r6, [r1 + 0x18]
cmplwi r6, 0
beq handle_6xE4_return
stw [r1 + 0x14], r4
li r6, 0x12
sthbrx [r1 + r6], r5
@@ -198,9 +207,7 @@ handle_6xE4_damage_nonnegative:
mr r30, r3
bl send_debug_info
li r3, 2
lhbrx r3, [r31 + r3]
bl get_enemy_entity
lwz r3, [r1 + 0x18] # if (ene) ene->v50_on_state_updated(&st);
cmplwi r3, 0
beq handle_6xE4_return
mr r4, r30
@@ -179,6 +179,11 @@ handle_6xE4: # [std] (G_6xE4* cmd @ [esp + 4]) -> void
cmp eax, 0x1B50
jge handle_6xE4_return
mov edi, eax
call <VERS 0x002B36B0 0x002B4180 0x002B5710 0x002B5220 0x002B5400 0x002B5240 0x002B5510> # TObjEnemy* ene = get_enemy_entity(cmd->header.entity_id);
push eax
movzx eax, word [ebx + 2]
and eax, 0x0FFF
imul eax, eax, 0x0C
add eax, [<VERS 0x00633068 0x006336C8 0x0063B210 0x006386F8 0x00637F90 0x006386F8 0x00638A90>] # eax = state_for_enemy(cmd->header.entity_id)
@@ -192,9 +197,12 @@ handle_6xE4: # [std] (G_6xE4* cmd @ [esp + 4]) -> void
mov [eax + 0x06], di # st.total_damage = cmd->max_hp;
mov edx, [eax]
test edx, 0x800
jnz handle_6xE4_return
jnz handle_6xE4_return_pop_ene
or edx, 0x800
mov [eax], edx
cmp dword [esp], 0
je handle_6xE4_return_pop_ene
push edx # out_cmd.flags
sub esp, 8
mov word [esp], 0x030A # out_cmd.header.{subcommand,size}
@@ -216,7 +224,7 @@ handle_6xE4_root_protocol_missing:
call <VERS 0x002DBC30 0x002DC7B0 0x002DE070 0x002DDB90 0x002DE090 0x002DDBC0 0x002DE0C0> # handle_60(&out_cmd)
mov dword [<VERS 0x0071E8C8 0x0071EF28 0x00726A68 0x00723F68 0x007237E8 0x00723F68 0x007242E8>], 0
add esp, 0x10
add esp, 0x14
jmp handle_6xE4_return
handle_6xE4_damage_less_than_max_hp:
@@ -226,15 +234,16 @@ handle_6xE4_damage_less_than_max_hp:
mov [eax + 0x06], dx # st.total_damage = std::max<int16_t>(st.total_damage + cmd->hit_amount, 0);
mov esi, eax # esi = ene_st
movzx di, word [ebx + 2]
call <VERS 0x002B36B0 0x002B4180 0x002B5710 0x002B5220 0x002B5400 0x002B5240 0x002B5510> # auto* ene = get_enemy_entity(cmd->header.entity_id);
mov eax, [esp] # eax = ene
test eax, eax
jz handle_6xE4_return
jz handle_6xE4_return_pop_ene
mov ecx, eax
push esi
mov edx, [ecx]
call [edx + 0x138] # ene->vtable[0x4E](ene, &st);
handle_6xE4_return_pop_ene:
add esp, 4
handle_6xE4_return:
pop edi
pop esi
@@ -37,6 +37,11 @@ handle_6xE4_start: # (G_6xE4* cmd @ [esp + 4]) -> void
cmp eax, 0x1B50
jge handle_6xE4_return
movzx eax, word [ebx + 2]
.include GetEnemyEntity-59NL # auto* ene = get_enemy_entity(cmd->header.entity_id);
push eax
movzx eax, word [ebx + 2]
and eax, 0x0FFF
imul eax, eax, 0x0C
add eax, [0x00AB02B8] # eax = state_for_enemy(cmd->header.entity_id)
@@ -50,9 +55,11 @@ handle_6xE4_start: # (G_6xE4* cmd @ [esp + 4]) -> void
mov [eax + 0x06], di # st.total_damage = cmd->max_hp;
mov edx, [eax]
test edx, 0x800
jnz handle_6xE4_return
jnz handle_6xE4_return_pop_ene
or edx, 0x800
mov [eax], edx
cmp dword [esp], 0
je handle_6xE4_return_pop_ene
push edx # out_cmd.flags
sub esp, 8
mov word [esp], 0x030A # out_cmd.header.{subcommand,size}
@@ -64,7 +71,7 @@ handle_6xE4_start: # (G_6xE4* cmd @ [esp + 4]) -> void
mov ecx, esp
mov edx, 0x008003E0
call edx # send_and_handle_60(&out_cmd);
add esp, 0x0C
add esp, 0x10
jmp handle_6xE4_return
handle_6xE4_damage_less_than_max_hp:
@@ -74,15 +81,16 @@ handle_6xE4_damage_less_than_max_hp:
mov [eax + 0x06], dx # st.total_damage = std::max<int16_t>(st.total_damage + cmd->hit_amount, 0);
mov edx, eax # edx = ene_st
movzx eax, word [ebx + 2]
.include GetEnemyEntity-59NL # auto* ene = get_enemy_entity(cmd->header.entity_id);
mov eax, [esp] # eax = ene
test eax, eax
jz handle_6xE4_return
jz handle_6xE4_return_pop_ene
mov ecx, eax
push edx
mov edx, [ecx]
call [edx + 0x148] # ene->vtable[0x52](ene, &st);
handle_6xE4_return_pop_ene:
add esp, 4
handle_6xE4_return:
pop edi
pop esi