From 1fe52085606ccd9258eea5a037c43b30fc04d7c5 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Mon, 1 Apr 2019 12:05:58 -0400 Subject: [PATCH] through sub_801A02C --- asm/union_room_player_avatar.s | 949 +----------------- data/union_room_player_avatar.s | 35 - .../event_object_movement_constants.h | 2 + include/event_object_movement.h | 4 + include/field_player_avatar.h | 12 +- include/fieldmap.h | 1 + include/global.fieldmap.h | 27 +- include/union_room.h | 2 +- ld_script.txt | 2 + src/union_room_player_avatar.c | 462 +++++++++ 10 files changed, 494 insertions(+), 1002 deletions(-) create mode 100644 src/union_room_player_avatar.c diff --git a/asm/union_room_player_avatar.s b/asm/union_room_player_avatar.s index aa9fa5e85..95c1f8d90 100755 --- a/asm/union_room_player_avatar.s +++ b/asm/union_room_player_avatar.s @@ -5,951 +5,6 @@ .text - thumb_func_start is_walking_or_running -is_walking_or_running: @ 8019958 - push {lr} - ldr r0, =gPlayerAvatar - ldrb r0, [r0, 0x3] - cmp r0, 0x2 - beq _08019966 - cmp r0, 0 - bne _08019970 -_08019966: - movs r0, 0x1 - b _08019972 - .pool -_08019970: - movs r0, 0 -_08019972: - pop {r1} - bx r1 - thumb_func_end is_walking_or_running - - thumb_func_start sub_8019978 -sub_8019978: @ 8019978 - ldr r3, =gUnknown_082F072C - movs r2, 0x7 - ands r2, r1 - lsls r1, r0, 2 - adds r1, r0 - lsls r1, 1 - adds r2, r1 - adds r2, r3 - ldrb r0, [r2] - bx lr - .pool - thumb_func_end sub_8019978 - - thumb_func_start sub_8019990 -sub_8019990: @ 8019990 - push {r4-r6,lr} - mov r6, r8 - push {r6} - ldr r4, =gUnknown_082F0740 - mov r8, r4 - lsls r0, 2 - adds r4, r0, r4 - movs r6, 0 - ldrsh r5, [r4, r6] - ldr r6, =gUnknown_082F0760 - lsls r1, 1 - adds r4, r1, r6 - ldrb r4, [r4] - lsls r4, 24 - asrs r4, 24 - adds r5, r4 - adds r5, 0x7 - str r5, [r2] - movs r2, 0x2 - add r8, r2 - add r0, r8 - movs r4, 0 - ldrsh r0, [r0, r4] - adds r6, 0x1 - adds r1, r6 - ldrb r1, [r1] - lsls r1, 24 - asrs r1, 24 - adds r0, r1 - adds r0, 0x7 - str r0, [r3] - pop {r3} - mov r8, r3 - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8019990 - - thumb_func_start sub_80199E0 -sub_80199E0: @ 80199E0 - push {r4-r7,lr} - mov r12, r3 - ldr r7, =gUnknown_082F0740 - lsls r5, r0, 2 - adds r0, r5, r7 - movs r4, 0 - ldrsh r3, [r0, r4] - ldr r6, =gUnknown_082F0760 - lsls r4, r1, 1 - adds r0, r4, r6 - ldrb r0, [r0] - lsls r0, 24 - asrs r0, 24 - adds r3, r0 - adds r3, 0x7 - cmp r3, r2 - bne _08019A28 - adds r0, r7, 0x2 - adds r0, r5, r0 - movs r2, 0 - ldrsh r1, [r0, r2] - adds r0, r6, 0x1 - adds r0, r4, r0 - ldrb r0, [r0] - lsls r0, 24 - asrs r0, 24 - adds r1, r0 - adds r1, 0x7 - cmp r1, r12 - bne _08019A28 - movs r0, 0x1 - b _08019A2A - .pool -_08019A28: - movs r0, 0 -_08019A2A: - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_80199E0 - - thumb_func_start IsUnionRoomPlayerHidden -IsUnionRoomPlayerHidden: @ 8019A30 - push {lr} - ldr r1, =0x000002bf - adds r0, r1 - lsls r0, 16 - lsrs r0, 16 - bl FlagGet - lsls r0, 24 - lsrs r0, 24 - pop {r1} - bx r1 - .pool - thumb_func_end IsUnionRoomPlayerHidden - - thumb_func_start HideUnionRoomPlayer -HideUnionRoomPlayer: @ 8019A4C - push {lr} - ldr r1, =0x000002bf - adds r0, r1 - lsls r0, 16 - lsrs r0, 16 - bl FlagSet - pop {r0} - bx r0 - .pool - thumb_func_end HideUnionRoomPlayer - - thumb_func_start ShowUnionRoomPlayer -ShowUnionRoomPlayer: @ 8019A64 - push {lr} - ldr r1, =0x000002bf - adds r0, r1 - lsls r0, 16 - lsrs r0, 16 - bl FlagClear - pop {r0} - bx r0 - .pool - thumb_func_end ShowUnionRoomPlayer - - thumb_func_start SetUnionRoomPlayerGfx -SetUnionRoomPlayerGfx: @ 8019A7C - push {lr} - ldr r2, =0x00004010 - adds r0, r2 - lsls r0, 16 - lsrs r0, 16 - lsls r1, 16 - lsrs r1, 16 - bl VarSet - pop {r0} - bx r0 - .pool - thumb_func_end SetUnionRoomPlayerGfx - - thumb_func_start CreateUnionRoomPlayerEventObject -CreateUnionRoomPlayerEventObject: @ 8019A98 - push {lr} - ldr r1, =gUnknown_082F0774 - adds r0, r1 - ldrb r0, [r0] - ldr r1, =gSaveBlock1Ptr - ldr r2, [r1] - ldrb r1, [r2, 0x5] - ldrb r2, [r2, 0x4] - bl show_sprite - pop {r0} - bx r0 - .pool - thumb_func_end CreateUnionRoomPlayerEventObject - - thumb_func_start RemoveUnionRoomPlayerEventObject -RemoveUnionRoomPlayerEventObject: @ 8019AB8 - push {lr} - ldr r1, =gUnknown_082F0774 - adds r0, r1 - ldrb r0, [r0] - ldr r1, =gSaveBlock1Ptr - ldr r2, [r1] - ldrb r1, [r2, 0x5] - ldrb r2, [r2, 0x4] - bl RemoveEventObjectByLocalIdAndMap - pop {r0} - bx r0 - .pool - thumb_func_end RemoveUnionRoomPlayerEventObject - - thumb_func_start SetUnionRoomPlayerEnterExitMovement -SetUnionRoomPlayerEnterExitMovement: @ 8019AD8 - push {r4,r5,lr} - sub sp, 0x4 - adds r5, r1, 0 - ldr r1, =gUnknown_082F0774 - adds r0, r1 - ldrb r0, [r0] - ldr r1, =gSaveBlock1Ptr - ldr r2, [r1] - ldrb r1, [r2, 0x5] - ldrb r2, [r2, 0x4] - mov r3, sp - bl TryGetEventObjectIdByLocalIdAndMap - lsls r0, 24 - cmp r0, 0 - bne _08019B30 - mov r0, sp - ldrb r1, [r0] - lsls r0, r1, 3 - adds r0, r1 - lsls r0, 2 - ldr r1, =gEventObjects - adds r4, r0, r1 - adds r0, r4, 0 - bl EventObjectIsMovementOverridden - lsls r0, 24 - cmp r0, 0 - bne _08019B30 - ldrb r1, [r5] - adds r0, r4, 0 - bl EventObjectSetHeldMovement - lsls r0, 24 - cmp r0, 0 - bne _08019B30 - movs r0, 0x1 - b _08019B32 - .pool -_08019B30: - movs r0, 0 -_08019B32: - add sp, 0x4 - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end SetUnionRoomPlayerEnterExitMovement - - thumb_func_start sub_8019B3C -sub_8019B3C: @ 8019B3C - push {r4,lr} - sub sp, 0x4 - ldr r1, =gUnknown_082F0774 - adds r0, r1 - ldrb r0, [r0] - ldr r1, =gSaveBlock1Ptr - ldr r2, [r1] - ldrb r1, [r2, 0x5] - ldrb r2, [r2, 0x4] - mov r3, sp - bl TryGetEventObjectIdByLocalIdAndMap - lsls r0, 24 - cmp r0, 0 - bne _08019B9C - mov r0, sp - ldrb r1, [r0] - lsls r0, r1, 3 - adds r0, r1 - lsls r0, 2 - ldr r1, =gEventObjects - adds r4, r0, r1 - adds r0, r4, 0 - bl EventObjectClearHeldMovementIfFinished - lsls r0, 24 - cmp r0, 0 - bne _08019B84 - movs r0, 0 - b _08019B9E - .pool -_08019B84: - bl ScriptContext2_IsEnabled - lsls r0, 24 - cmp r0, 0 - bne _08019B96 - adds r0, r4, 0 - bl UnfreezeEventObject - b _08019B9C -_08019B96: - adds r0, r4, 0 - bl FreezeEventObject -_08019B9C: - movs r0, 0x1 -_08019B9E: - add sp, 0x4 - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_8019B3C - - thumb_func_start sub_8019BA8 -sub_8019BA8: @ 8019BA8 - push {lr} - ldr r2, =gUnknown_02022C68 - movs r1, 0 - str r1, [r2] - ldr r1, =gUnknown_02022C64 - str r0, [r1] - movs r1, 0 - movs r2, 0x7 -_08019BB8: - strb r1, [r0] - strb r1, [r0, 0x1] - strb r1, [r0, 0x2] - strb r1, [r0, 0x3] - adds r0, 0x4 - subs r2, 0x1 - cmp r2, 0 - bge _08019BB8 - bl sub_8019DF4 - lsls r0, 24 - lsrs r0, 24 - pop {r1} - bx r1 - .pool - thumb_func_end sub_8019BA8 - - thumb_func_start sub_8019BDC -sub_8019BDC: @ 8019BDC - push {r4,r5,lr} - adds r5, r0, 0 - adds r4, r1, 0 - movs r0, 0 - ldrsb r0, [r5, r0] - cmp r0, 0 - beq _08019BF0 - cmp r0, 0x1 - beq _08019C10 - b _08019C2E -_08019BF0: - ldr r1, =gUnknown_082F078C - adds r0, r4, 0 - bl SetUnionRoomPlayerEnterExitMovement - cmp r0, 0x1 - bne _08019C2E - adds r0, r4, 0 - bl HideUnionRoomPlayer - ldrb r0, [r5] - adds r0, 0x1 - strb r0, [r5] - b _08019C2E - .pool -_08019C10: - adds r0, r4, 0 - bl sub_8019B3C - cmp r0, 0 - beq _08019C2E - adds r0, r4, 0 - bl RemoveUnionRoomPlayerEventObject - adds r0, r4, 0 - bl HideUnionRoomPlayer - movs r0, 0 - strb r0, [r5] - movs r0, 0x1 - b _08019C30 -_08019C2E: - movs r0, 0 -_08019C30: - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end sub_8019BDC - - thumb_func_start sub_8019C38 -sub_8019C38: @ 8019C38 - push {r4-r7,lr} - sub sp, 0x4 - adds r6, r0, 0 - adds r5, r1, 0 - adds r7, r2, 0 - movs r0, 0 - ldrsb r0, [r6, r0] - cmp r0, 0x2 - beq _08019CD4 - cmp r0, 0x2 - bgt _08019C54 - cmp r0, 0 - beq _08019C5A - b _08019CE6 -_08019C54: - cmp r0, 0x3 - beq _08019CBC - b _08019CE6 -_08019C5A: - bl is_walking_or_running - cmp r0, 0 - beq _08019CE6 - mov r4, sp - adds r4, 0x2 - mov r0, sp - adds r1, r4, 0 - bl PlayerGetDestCoords - mov r0, sp - movs r1, 0 - ldrsh r2, [r0, r1] - movs r0, 0 - ldrsh r3, [r4, r0] - adds r0, r5, 0 - movs r1, 0 - bl sub_80199E0 - cmp r0, 0x1 - beq _08019CE6 - mov r0, sp - adds r1, r4, 0 - bl player_get_pos_including_state_based_drift - mov r0, sp - movs r1, 0 - ldrsh r2, [r0, r1] - movs r0, 0 - ldrsh r3, [r4, r0] - adds r0, r5, 0 - movs r1, 0 - bl sub_80199E0 - cmp r0, 0x1 - beq _08019CE6 - ldrb r1, [r7, 0x1] - adds r0, r5, 0 - bl SetUnionRoomPlayerGfx - adds r0, r5, 0 - bl CreateUnionRoomPlayerEventObject - adds r0, r5, 0 - bl ShowUnionRoomPlayer - ldrb r0, [r6] - adds r0, 0x1 - strb r0, [r6] -_08019CBC: - ldr r1, =gUnknown_082F078E - adds r0, r5, 0 - bl SetUnionRoomPlayerEnterExitMovement - cmp r0, 0x1 - bne _08019CE6 - ldrb r0, [r6] - adds r0, 0x1 - strb r0, [r6] - b _08019CE6 - .pool -_08019CD4: - adds r0, r5, 0 - bl sub_8019B3C - cmp r0, 0 - beq _08019CE6 - movs r0, 0 - strb r0, [r6] - movs r0, 0x1 - b _08019CE8 -_08019CE6: - movs r0, 0 -_08019CE8: - add sp, 0x4 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_8019C38 - - thumb_func_start sub_8019CF0 -sub_8019CF0: @ 8019CF0 - push {r4,lr} - ldr r3, =gUnknown_02022C64 - lsls r0, 2 - ldr r4, [r3] - adds r4, r0 - movs r0, 0x1 - strb r0, [r4, 0x3] - adds r0, r1, 0 - adds r1, r2, 0 - bl sub_8019978 - strb r0, [r4, 0x1] - ldrb r0, [r4] - cmp r0, 0 - beq _08019D18 - movs r0, 0 - b _08019D1A - .pool -_08019D18: - movs r0, 0x1 -_08019D1A: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_8019CF0 - - thumb_func_start AGBAssert -AGBAssert: @ 8019D20 - push {lr} - ldr r1, =gUnknown_02022C64 - lsls r0, 2 - ldr r1, [r1] - adds r1, r0 - movs r0, 0x2 - strb r0, [r1, 0x3] - ldrb r0, [r1] - cmp r0, 0x1 - beq _08019D3C - movs r0, 0 - b _08019D3E - .pool -_08019D3C: - movs r0, 0x1 -_08019D3E: - pop {r1} - bx r1 - thumb_func_end AGBAssert - - thumb_func_start sub_8019D44 -sub_8019D44: @ 8019D44 - push {r4,r5,lr} - adds r5, r0, 0 - adds r4, r1, 0 - ldrb r1, [r4] - cmp r1, 0x1 - beq _08019DA6 - cmp r1, 0x1 - bgt _08019D5A - cmp r1, 0 - beq _08019D64 - b _08019DC6 -_08019D5A: - cmp r1, 0x2 - beq _08019D70 - cmp r1, 0x3 - beq _08019DB4 - b _08019DC6 -_08019D64: - ldrb r0, [r4, 0x3] - cmp r0, 0x1 - bne _08019DC6 - movs r0, 0x2 - strb r0, [r4] - strb r1, [r4, 0x2] -_08019D70: - adds r0, r5, 0 - movs r1, 0 - bl sub_8019F8C - adds r1, r0, 0 - cmp r1, 0 - bne _08019D96 - ldrb r0, [r4, 0x3] - cmp r0, 0x2 - bne _08019D96 - strb r1, [r4] - strb r1, [r4, 0x2] - adds r0, r5, 0 - bl RemoveUnionRoomPlayerEventObject - adds r0, r5, 0 - bl HideUnionRoomPlayer - b _08019DC6 -_08019D96: - adds r0, r4, 0x2 - adds r1, r5, 0 - adds r2, r4, 0 - bl sub_8019C38 - cmp r0, 0x1 - bne _08019DC6 - b _08019DC4 -_08019DA6: - ldrb r0, [r4, 0x3] - cmp r0, 0x2 - bne _08019DC6 - movs r1, 0 - movs r0, 0x3 - strb r0, [r4] - strb r1, [r4, 0x2] -_08019DB4: - adds r0, r4, 0x2 - adds r1, r5, 0 - adds r2, r4, 0 - bl sub_8019BDC - cmp r0, 0x1 - bne _08019DC6 - movs r0, 0 -_08019DC4: - strb r0, [r4] -_08019DC6: - movs r0, 0 - strb r0, [r4, 0x3] - pop {r4,r5} - pop {r0} - bx r0 - thumb_func_end sub_8019D44 - - thumb_func_start sub_8019DD0 -sub_8019DD0: @ 8019DD0 - push {r4,r5,lr} - movs r4, 0 - ldr r5, =gUnknown_02022C64 -_08019DD6: - lsls r0, r4, 2 - ldr r1, [r5] - adds r1, r0 - adds r0, r4, 0 - bl sub_8019D44 - adds r4, 0x1 - cmp r4, 0x7 - ble _08019DD6 - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8019DD0 - - thumb_func_start sub_8019DF4 -sub_8019DF4: @ 8019DF4 - push {r4,lr} - ldr r4, =sub_8019DD0 - adds r0, r4, 0 - bl FuncIsActiveTask - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1 - beq _08019E18 - adds r0, r4, 0 - movs r1, 0x5 - bl CreateTask - lsls r0, 24 - lsrs r0, 24 - b _08019E1A - .pool -_08019E18: - movs r0, 0x10 -_08019E1A: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_8019DF4 - - thumb_func_start sub_8019E20 -sub_8019E20: @ 8019E20 - push {lr} - ldr r0, =sub_8019DD0 - bl FindTaskIdByFunc - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0xF - bhi _08019E34 - bl DestroyTask -_08019E34: - pop {r0} - bx r0 - .pool - thumb_func_end sub_8019E20 - - thumb_func_start sub_8019E3C -sub_8019E3C: @ 8019E3C - push {r4,lr} - movs r4, 0 -_08019E40: - adds r0, r4, 0 - bl IsUnionRoomPlayerHidden - cmp r0, 0 - bne _08019E56 - adds r0, r4, 0 - bl RemoveUnionRoomPlayerEventObject - adds r0, r4, 0 - bl HideUnionRoomPlayer -_08019E56: - adds r4, 0x1 - cmp r4, 0x7 - ble _08019E40 - ldr r1, =gUnknown_02022C64 - movs r0, 0 - str r0, [r1] - bl sub_8019E20 - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8019E3C - - thumb_func_start sub_8019E70 -sub_8019E70: @ 8019E70 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x10 - str r0, [sp, 0x8] - mov r9, r1 - movs r7, 0 - mov r0, r9 - lsls r0, 2 - mov r8, r0 - ldr r0, =gUnknown_082F0740 - mov r2, r8 - adds r1, r2, r0 - ldrh r1, [r1] - mov r2, sp - strh r1, [r2, 0xC] - adds r0, 0x2 - add r0, r8 - ldrh r0, [r0] - mov r10, r0 - ldr r6, =gUnknown_082F0760 -_08019E9E: - mov r5, r8 - add r5, r9 - adds r5, r7 - adds r4, r5, 0 - subs r4, 0x38 - lsls r4, 24 - lsrs r4, 24 - movs r2, 0 - ldrsb r2, [r6, r2] - mov r0, sp - ldrh r0, [r0, 0xC] - adds r2, r0, r2 - lsls r2, 16 - asrs r2, 16 - movs r3, 0x1 - ldrsb r3, [r6, r3] - add r3, r10 - lsls r3, 16 - asrs r3, 16 - movs r0, 0x3 - str r0, [sp] - movs r0, 0x1 - str r0, [sp, 0x4] - movs r0, 0x41 - adds r1, r4, 0 - bl sprite_new - ldr r1, [sp, 0x8] - adds r5, r1, r5 - strb r0, [r5] - adds r0, r4, 0 - movs r1, 0x1 - bl sub_8097C44 - adds r6, 0x2 - adds r7, 0x1 - cmp r7, 0x4 - ble _08019E9E - add sp, 0x10 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8019E70 - - thumb_func_start sub_8019F04 -sub_8019F04: @ 8019F04 - push {r4-r6,lr} - adds r5, r0, 0 - movs r4, 0 - ldr r6, =gSprites -_08019F0C: - adds r0, r5, r4 - ldrb r1, [r0] - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - adds r0, r6 - bl DestroySprite - adds r4, 0x1 - cmp r4, 0x27 - ble _08019F0C - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8019F04 - - thumb_func_start sub_8019F2C -sub_8019F2C: @ 8019F2C - push {r4-r7,lr} - sub sp, 0x8 - movs r5, 0 - add r7, sp, 0x4 -_08019F34: - movs r4, 0 - adds r6, r5, 0x1 -_08019F38: - adds r0, r5, 0 - adds r1, r4, 0 - mov r2, sp - adds r3, r7, 0 - bl sub_8019990 - ldr r0, [sp] - ldr r1, [sp, 0x4] - movs r2, 0 - bl sub_8088B94 - adds r4, 0x1 - cmp r4, 0x4 - ble _08019F38 - adds r5, r6, 0 - cmp r5, 0x7 - ble _08019F34 - add sp, 0x8 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_8019F2C - - thumb_func_start sub_8019F64 -sub_8019F64: @ 8019F64 - push {lr} - adds r1, r0, 0 - cmp r1, 0 - beq _08019F78 - ldr r0, =gUnknown_082F076F - adds r0, r1, r0 - ldrb r0, [r0] - b _08019F88 - .pool -_08019F78: - ldrb r1, [r2, 0xA] - movs r0, 0x7F - ands r0, r1 - cmp r0, 0x45 - beq _08019F86 - movs r0, 0x4 - b _08019F88 -_08019F86: - movs r0, 0x1 -_08019F88: - pop {r1} - bx r1 - thumb_func_end sub_8019F64 - - thumb_func_start sub_8019F8C -sub_8019F8C: @ 8019F8C - push {lr} - adds r2, r0, 0 - lsls r0, r2, 2 - adds r0, r2 - adds r0, r1 - subs r0, 0x38 - lsls r0, 24 - lsrs r0, 24 - bl sub_8097C8C - pop {r1} - bx r1 - thumb_func_end sub_8019F8C - - thumb_func_start sub_8019FA4 -sub_8019FA4: @ 8019FA4 - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - sub sp, 0x8 - adds r5, r0, 0 - adds r6, r1, 0 - mov r9, r3 - lsls r2, 24 - lsrs r2, 24 - mov r8, r2 - lsls r0, r5, 2 - adds r0, r5 - adds r7, r0, r6 - adds r0, r5, 0 - bl sub_8019F8C - cmp r0, 0x1 - bne _08019FE2 - adds r4, r7, 0 - subs r4, 0x38 - lsls r4, 24 - lsrs r4, 24 - adds r0, r4, 0 - movs r1, 0 - bl sub_8097C44 - adds r0, r4, 0 - movs r1, 0x1 - bl sub_8097CC4 -_08019FE2: - adds r0, r7, 0 - subs r0, 0x38 - lsls r0, 24 - lsrs r0, 24 - mov r1, r8 - bl sub_8097BB4 - adds r0, r6, 0 - adds r1, r5, 0 - mov r2, r9 - bl sub_8019F64 - adds r2, r0, 0 - lsls r2, 24 - lsrs r2, 24 - adds r0, r6, 0 - adds r1, r5, 0 - bl sub_801A3B0 - add r3, sp, 0x4 - adds r0, r5, 0 - adds r1, r6, 0 - mov r2, sp - bl sub_8019990 - ldr r0, [sp] - ldr r1, [sp, 0x4] - movs r2, 0x1 - bl sub_8088B94 - add sp, 0x8 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_8019FA4 - - thumb_func_start sub_801A02C -sub_801A02C: @ 801A02C - push {r4,r5,lr} - sub sp, 0x8 - adds r4, r0, 0 - adds r5, r1, 0 - lsls r0, r4, 2 - adds r0, r4 - adds r0, r5 - subs r0, 0x38 - lsls r0, 24 - lsrs r0, 24 - movs r1, 0x2 - bl sub_8097CC4 - add r3, sp, 0x4 - adds r0, r4, 0 - adds r1, r5, 0 - mov r2, sp - bl sub_8019990 - ldr r0, [sp] - ldr r1, [sp, 0x4] - movs r2, 0 - bl sub_8088B94 - add sp, 0x8 - pop {r4,r5} - pop {r0} - bx r0 - thumb_func_end sub_801A02C - thumb_func_start sub_801A064 sub_801A064: @ 801A064 push {r4-r7,lr} @@ -1137,7 +192,7 @@ _0801A1F0: b _0801A20E _0801A200: adds r0, r5, 0 - bl AGBAssert + bl sub_8019D20 adds r0, r5, 0 adds r1, r4, 0 bl sub_801A064 @@ -1151,7 +206,7 @@ _0801A20E: sub_801A214: @ 801A214 push {r4,r5,lr} adds r5, r0, 0 - bl AGBAssert + bl sub_8019D20 movs r4, 0 _0801A21E: adds r0, r5, 0 diff --git a/data/union_room_player_avatar.s b/data/union_room_player_avatar.s index 5f86ab4d2..65e8d4229 100755 --- a/data/union_room_player_avatar.s +++ b/data/union_room_player_avatar.s @@ -3,41 +3,6 @@ .section .rodata - .align 2 -gUnknown_082F072C:: @ 82F072C - .byte 0x21, 0x2c, 0x1f, 0x23, 0x25, 0x24, 0x41, 0x42 - .byte 0x00, 0x00, 0x22, 0x28, 0x20, 0x2f, 0x2f, 0x0e - .byte 0x14, 0x2d, 0x00, 0x00 - - .align 2 -gUnknown_082F0740:: @ 82F0740 - .2byte 0x0004, 0x0006, 0x000d, 0x0008 - .2byte 0x000a, 0x0006, 0x0001, 0x0008 - .2byte 0x000d, 0x0004, 0x0007, 0x0004 - .2byte 0x0001, 0x0004, 0x0007, 0x0008 - - .align 2 -gUnknown_082F0760:: @ 82F0760 - .byte 0x00, 0x00, 0x01, 0x00, 0x00, 0xff, 0xff, 0x00 - .byte 0x00, 0x01 - -gUnknown_082F076A:: @ 82F076A - .byte 0x00, 0x02, 0x01, 0x04, 0x03 - -gUnknown_082F076F:: @ 82F076F - .byte 0x01, 0x03, 0x01, 0x04, 0x02 - -gUnknown_082F0774:: @ 82F0774 - .byte 0x09, 0x08, 0x07, 0x02, 0x06, 0x05, 0x04, 0x03 - .byte 0xbf, 0x02, 0xc0, 0x02, 0xc1, 0x02, 0xc2, 0x02 - .byte 0xc3, 0x02, 0xc4, 0x02, 0xc5, 0x02, 0xc6, 0x02 - -gUnknown_082F078C:: @ 82F078C - .byte 0x9c, 0xfe - -gUnknown_082F078E:: @ 82F078E - .byte 0x9d, 0xfe - .align 2 gWirelessInfoScreenPal:: @ 82F0790 .incbin "graphics/interface/wireless_info_screen.gbapal" diff --git a/include/constants/event_object_movement_constants.h b/include/constants/event_object_movement_constants.h index 2a80f9a09..b1f9b4cb5 100755 --- a/include/constants/event_object_movement_constants.h +++ b/include/constants/event_object_movement_constants.h @@ -242,4 +242,6 @@ #define MOVEMENT_ACTION_FLY_UP 0x9C #define MOVEMENT_ACTION_FLY_DOWN 0x9D +#define MOVEMENT_ACTION_STEP_END 0xFE + #endif // GUARD_CONSTANTS_EVENTOBJMV_H diff --git a/include/event_object_movement.h b/include/event_object_movement.h index 63ac09f2d..4a8e0d373 100644 --- a/include/event_object_movement.h +++ b/include/event_object_movement.h @@ -413,5 +413,9 @@ u8 MovementType_RunInPlace_Step0(struct EventObject *, struct Sprite *); u8 MovementType_Invisible_Step0(struct EventObject *, struct Sprite *); u8 MovementType_Invisible_Step1(struct EventObject *, struct Sprite *); u8 MovementType_Invisible_Step2(struct EventObject *, struct Sprite *); +void sub_8097C44(u8 var, bool32 var2); +bool32 sub_8097C8C(u8 var); +void sub_8097BB4(u8 var1, u8 graphicsId); +void sub_8097CC4(u8 var1, u8 var2); #endif //GUARD_FIELD_EVENT_OBJ_H diff --git a/include/field_player_avatar.h b/include/field_player_avatar.h index ca3d41546..8d87779e6 100644 --- a/include/field_player_avatar.h +++ b/include/field_player_avatar.h @@ -1,17 +1,6 @@ #ifndef GUARD_FIELD_PLAYER_AVATAR_H #define GUARD_FIELD_PLAYER_AVATAR_H -enum { - PLAYER_AVATAR_STATE_NORMAL, - PLAYER_AVATAR_STATE_MACH_BIKE, - PLAYER_AVATAR_STATE_ACRO_BIKE, - PLAYER_AVATAR_STATE_SURFING, - PLAYER_AVATAR_STATE_UNDERWATER, - PLAYER_AVATAR_STATE_FIELD_MOVE, - PLAYER_AVATAR_STATE_FISHING, - PLAYER_AVATAR_STATE_WATERING, -}; - void player_step(u8 a, u16 b, u16 c); void ClearPlayerAvatarInfo(void); void SetPlayerAvatarExtraStateTransition(u8, u8); @@ -73,5 +62,6 @@ void sub_808D1C8(void); bool32 sub_808D1B4(void); bool32 sub_808D1E8(void); void sub_808C0A8(u8 a); +u8 player_get_pos_including_state_based_drift(s16 *x, s16 *y); #endif // GUARD_FIELD_PLAYER_AVATAR_H diff --git a/include/fieldmap.h b/include/fieldmap.h index bb5b0e290..2384ed46a 100644 --- a/include/fieldmap.h +++ b/include/fieldmap.h @@ -50,5 +50,6 @@ void SpriteCB_HallOfFameMonitor(struct Sprite *); // field_region_map.c void FieldInitRegionMap(MainCallback callback); +void sub_8088B94(int x, int y, int a2); #endif //GUARD_FIELDMAP_H diff --git a/include/global.fieldmap.h b/include/global.fieldmap.h index e35d900d8..3aa44ec9a 100644 --- a/include/global.fieldmap.h +++ b/include/global.fieldmap.h @@ -232,14 +232,25 @@ struct EventObjectGraphicsInfo /*0x20*/ const union AffineAnimCmd *const *affineAnims; }; -#define PLAYER_AVATAR_FLAG_ON_FOOT (1 << 0) -#define PLAYER_AVATAR_FLAG_MACH_BIKE (1 << 1) -#define PLAYER_AVATAR_FLAG_ACRO_BIKE (1 << 2) -#define PLAYER_AVATAR_FLAG_SURFING (1 << 3) -#define PLAYER_AVATAR_FLAG_UNDERWATER (1 << 4) -#define PLAYER_AVATAR_FLAG_5 (1 << 5) -#define PLAYER_AVATAR_FLAG_6 (1 << 6) -#define PLAYER_AVATAR_FLAG_DASH (1 << 7) +enum { + PLAYER_AVATAR_STATE_NORMAL, + PLAYER_AVATAR_STATE_MACH_BIKE, + PLAYER_AVATAR_STATE_ACRO_BIKE, + PLAYER_AVATAR_STATE_SURFING, + PLAYER_AVATAR_STATE_UNDERWATER, + PLAYER_AVATAR_STATE_FIELD_MOVE, + PLAYER_AVATAR_STATE_FISHING, + PLAYER_AVATAR_STATE_WATERING, +}; + +#define PLAYER_AVATAR_FLAG_ON_FOOT (1 << PLAYER_AVATAR_STATE_NORMAL) +#define PLAYER_AVATAR_FLAG_MACH_BIKE (1 << PLAYER_AVATAR_STATE_MACH_BIKE) +#define PLAYER_AVATAR_FLAG_ACRO_BIKE (1 << PLAYER_AVATAR_STATE_ACRO_BIKE) +#define PLAYER_AVATAR_FLAG_SURFING (1 << PLAYER_AVATAR_STATE_SURFING) +#define PLAYER_AVATAR_FLAG_UNDERWATER (1 << PLAYER_AVATAR_STATE_UNDERWATER) +#define PLAYER_AVATAR_FLAG_5 (1 << PLAYER_AVATAR_STATE_FIELD_MOVE) +#define PLAYER_AVATAR_FLAG_6 (1 << PLAYER_AVATAR_STATE_FISHING) +#define PLAYER_AVATAR_FLAG_DASH (1 << PLAYER_AVATAR_STATE_WATERING) enum { diff --git a/include/union_room.h b/include/union_room.h index ca3c87ab1..538d37716 100644 --- a/include/union_room.h +++ b/include/union_room.h @@ -90,7 +90,7 @@ struct UnkStruct_8019BA8 { u8 field_0; u8 field_1; - u8 field_2; + s8 field_2; u8 field_3; }; diff --git a/ld_script.txt b/ld_script.txt index 5230fee78..b9d20d72e 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -56,6 +56,7 @@ SECTIONS { src/link_rfu.o(.text); src/union_room.o(.text); src/mystery_gift.o(.text); + src/union_room_player_avatar.o(.text); asm/union_room_player_avatar.o(.text); src/mevent2.o(.text); src/mevent_801BAAC.o(.text); @@ -411,6 +412,7 @@ SECTIONS { src/link_rfu.o(.rodata); src/union_room.o(.rodata); src/mystery_gift.o(.rodata); + src/union_room_player_avatar.o(.rodata); data/union_room_player_avatar.o(.rodata); src/mevent2.o(.rodata); src/mevent_801BAAC.o(.rodata); diff --git a/src/union_room_player_avatar.c b/src/union_room_player_avatar.c new file mode 100644 index 000000000..298ad04c7 --- /dev/null +++ b/src/union_room_player_avatar.c @@ -0,0 +1,462 @@ +#include "global.h" +#include "constants/flags.h" +#include "constants/event_object_movement_constants.h" +#include "event_data.h" +#include "event_object_movement.h" +#include "script.h" +#include "field_player_avatar.h" +#include "fieldmap.h" +#include "union_room.h" +#include "task.h" + +EWRAM_DATA struct UnkStruct_8019BA8 * gUnknown_02022C64 = NULL; +EWRAM_DATA u32 gUnknown_02022C68 = 0; + +u8 sub_8019DF4(void); +bool32 sub_8019F8C(u32 playerIdx, u32 arg1); +void sub_801A3B0(u32 arg0, u32 arg1, u8 arg2); + +ALIGNED(4) const u8 gUnknown_082F072C[][10] = { + {0x21, 0x2c, 0x1f, 0x23, 0x25, 0x24, 0x41, 0x42}, + {0x22, 0x28, 0x20, 0x2f, 0x2f, 0x0e, 0x14, 0x2d} +}; + +const s16 gUnknown_082F0740[][2] = { + {0x4, 0x6}, + {0xd, 0x8}, + {0xa, 0x6}, + {0x1, 0x8}, + {0xd, 0x4}, + {0x7, 0x4}, + {0x1, 0x4}, + {0x7, 0x8} +}; + +const s8 gUnknown_082F0760[][2] = { + { 0, 0}, + { 1, 0}, + { 0, -1}, + {-1, 0}, + { 0, 1} +}; + +const u8 gUnknown_082F076A[] = { + 0x00, 0x02, 0x01, 0x04, 0x03 +}; + +const u8 gUnknown_082F076F[] = { + 0x01, 0x03, 0x01, 0x04, 0x02 +}; + +const u8 gUnknown_082F0774[] = { + 0x09, 0x08, 0x07, 0x02, 0x06, 0x05, 0x04, 0x03, + 0xbf, 0x02, 0xc0, 0x02, 0xc1, 0x02, 0xc2, 0x02, + 0xc3, 0x02, 0xc4, 0x02, 0xc5, 0x02, 0xc6, 0x02 +}; + +const u8 gUnknown_082F078C[2] = { + MOVEMENT_ACTION_FLY_UP, + MOVEMENT_ACTION_STEP_END +}; + +const u8 gUnknown_082F078E[2] = { + MOVEMENT_ACTION_FLY_DOWN, + MOVEMENT_ACTION_STEP_END +}; + +bool32 is_walking_or_running(void) +{ + if (gPlayerAvatar.tileTransitionState == 2 || gPlayerAvatar.tileTransitionState == 0) + { + return TRUE; + } + else + { + return FALSE; + } +} + +u8 sub_8019978(u32 a0, u32 a1) +{ + return gUnknown_082F072C[a0][a1 % 8]; +} + +void sub_8019990(u32 a0, u32 a1, s32 * a2, s32 * a3) +{ + *a2 = gUnknown_082F0740[a0][0] + gUnknown_082F0760[a1][0] + 7; + *a3 = gUnknown_082F0740[a0][1] + gUnknown_082F0760[a1][1] + 7; +} + +bool32 sub_80199E0(u32 a0, u32 a1, s32 a2, s32 a3) +{ + if (gUnknown_082F0740[a0][0] + gUnknown_082F0760[a1][0] + 7 != a2) + { + return FALSE; + } + else if (gUnknown_082F0740[a0][1] + gUnknown_082F0760[a1][1] + 7 != a3) + { + return FALSE; + } + else + { + return TRUE; + } +} + +bool32 IsUnionRoomPlayerHidden(u32 player_idx) +{ + return FlagGet(FLAG_HIDE_UNION_ROOM_PLAYER_1 + player_idx); +} + +void HideUnionRoomPlayer(u32 player_idx) +{ + FlagSet(FLAG_HIDE_UNION_ROOM_PLAYER_1 + player_idx); +} + +void ShowUnionRoomPlayer(u32 player_idx) +{ + FlagClear(FLAG_HIDE_UNION_ROOM_PLAYER_1 + player_idx); +} + +void SetUnionRoomPlayerGfx(u32 playerIdx, u32 gfxId) +{ + VarSet(VAR_OBJ_GFX_ID_0 + playerIdx, gfxId); +} + +void CreateUnionRoomPlayerEventObject(u32 playerIdx) +{ + show_sprite(gUnknown_082F0774[playerIdx], gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup); +} + +void RemoveUnionRoomPlayerEventObject(u32 playerIdx) +{ + RemoveEventObjectByLocalIdAndMap(gUnknown_082F0774[playerIdx], gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup); +} + +bool32 SetUnionRoomPlayerEnterExitMovement(u32 playerIdx, const u8 * movement) +{ + u8 objectId; + struct EventObject * object; + if (TryGetEventObjectIdByLocalIdAndMap(gUnknown_082F0774[playerIdx], gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, &objectId)) + { + return FALSE; + } + object = &gEventObjects[objectId]; + if (EventObjectIsMovementOverridden(object)) + { + return FALSE; + } + if (EventObjectSetHeldMovement(object, *movement)) + { + return FALSE; + } + return TRUE; +} + +bool32 sub_8019B3C(u32 playerIdx) +{ + u8 objectId; + struct EventObject * object; + if (TryGetEventObjectIdByLocalIdAndMap(gUnknown_082F0774[playerIdx], gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, &objectId)) + { + return TRUE; + } + object = &gEventObjects[objectId]; + if (!EventObjectClearHeldMovementIfFinished(object)) + { + return FALSE; + } + if (!ScriptContext2_IsEnabled()) + { + UnfreezeEventObject(object); + } + else + { + FreezeEventObject(object); + } + return TRUE; +} + +u8 sub_8019BA8(struct UnkStruct_8019BA8 * ptr) +{ + s32 i; + + gUnknown_02022C68 = 0; + gUnknown_02022C64 = ptr; + for (i = 0; i < 8; i++) + { + ptr[i].field_0 = 0; + ptr[i].field_1 = 0; + ptr[i].field_2 = 0; + ptr[i].field_3 = 0; + } + return sub_8019DF4(); +} + +bool32 sub_8019BDC(s8 * a0, u32 playerIdx, struct UnkStruct_8019BA8 * ptr) +{ + switch (*a0) + { + case 0: + if (SetUnionRoomPlayerEnterExitMovement(playerIdx, gUnknown_082F078C) == TRUE) + { + HideUnionRoomPlayer(playerIdx); + (*a0)++; + } + break; + case 1: + if (sub_8019B3C(playerIdx)) + { + RemoveUnionRoomPlayerEventObject(playerIdx); + HideUnionRoomPlayer(playerIdx); + *a0 = 0; + return TRUE; + } + break; + } + return FALSE; +} + +bool32 sub_8019C38(s8 * a0, u32 playerIdx, struct UnkStruct_8019BA8 * ptr) +{ + s16 x, y; + + switch (*a0) + { + case 0: + if (!is_walking_or_running()) + { + break; + } + PlayerGetDestCoords(&x, &y); + if (sub_80199E0(playerIdx, 0, x, y) == 1) + { + break; + } + player_get_pos_including_state_based_drift(&x, &y); + if (sub_80199E0(playerIdx, 0, x, y) == 1) + { + break; + } + SetUnionRoomPlayerGfx(playerIdx, ptr->field_1); + CreateUnionRoomPlayerEventObject(playerIdx); + ShowUnionRoomPlayer(playerIdx); + (*a0)++; + // fallthrough + case 3: // incorrect? + if (SetUnionRoomPlayerEnterExitMovement(playerIdx, gUnknown_082F078E) == 1) + { + (*a0)++; + } + break; + case 2: + if (sub_8019B3C(playerIdx)) + { + *a0 = 0; + return TRUE; + } + break; + } + return FALSE; +} + +bool32 sub_8019CF0(u32 playerIdx, u32 a1, u32 a2) +{ + struct UnkStruct_8019BA8 * ptr = &gUnknown_02022C64[playerIdx]; + ptr->field_3 = 1; + ptr->field_1 = sub_8019978(a1, a2); + if (ptr->field_0 == 0) + { + return TRUE; + } + else + { + return FALSE; + } +} + +bool32 sub_8019D20(u32 playerIdx) +{ + struct UnkStruct_8019BA8 * ptr = &gUnknown_02022C64[playerIdx]; + ptr->field_3 = 2; + if (ptr->field_0 == 1) + { + return TRUE; + } + else + { + return FALSE; + } +} + +void sub_8019D44(u32 playerIdx, struct UnkStruct_8019BA8 * ptr) +{ + switch (ptr->field_0) + { + case 0: + if (ptr->field_3 == 1) + { + ptr->field_0 = 2; + ptr->field_2 = 0; + } + else + { + break; + } + // fallthrough + case 2: + if (!sub_8019F8C(playerIdx, 0) && ptr->field_3 == 2) + { + ptr->field_0 = 0; + ptr->field_2 = 0; + RemoveUnionRoomPlayerEventObject(playerIdx); + HideUnionRoomPlayer(playerIdx); + } + else if (sub_8019C38(&ptr->field_2, playerIdx, ptr) == 1) + { + ptr->field_0 = 1; + } + break; + case 1: + if (ptr->field_3 == 2) + { + ptr->field_0 = 3; + ptr->field_2 = 0; + } + else + { + break; + } + // fallthrough + case 3: + if (sub_8019BDC(&ptr->field_2, playerIdx, ptr) == 1) + { + ptr->field_0 = 0; + } + break; + } + ptr->field_3 = 0; +} + +void sub_8019DD0(u8 taskId) +{ + s32 i; + for (i = 0; i < 8; i++) + { + sub_8019D44(i, &gUnknown_02022C64[i]); + } +} + +u8 sub_8019DF4(void) +{ + if (FuncIsActiveTask(sub_8019DD0) == 1) + { + return NUM_TASKS; + } + else + { + return CreateTask(sub_8019DD0, 5); + } +} + +void sub_8019E20(void) +{ + u8 taskId = FindTaskIdByFunc(sub_8019DD0); + if (taskId < NUM_TASKS) + { + DestroyTask(taskId); + } +} + +void sub_8019E3C(void) +{ + s32 i; + for (i = 0; i < 8; i++) + { + if (!IsUnionRoomPlayerHidden(i)) + { + RemoveUnionRoomPlayerEventObject(i); + HideUnionRoomPlayer(i); + } + } + gUnknown_02022C64 = NULL; + sub_8019E20(); +} + +void sub_8019E70(u8 * sp8, s32 r9) +{ + s32 r7; + + for (r7 = 0; r7 < 5; r7++) + { + s32 r5 = 5 * r9 + r7; + sp8[r5] = sprite_new(0x41, r5 - 0x38, gUnknown_082F0740[r9][0] + gUnknown_082F0760[r7][0], gUnknown_082F0740[r9][1] + gUnknown_082F0760[r7][1], 3, 1); + sub_8097C44(r5 - 0x38, TRUE); + } +} + +void sub_8019F04(u8 * r5) +{ + s32 i; + for (i = 0; i < 40; i++) + { + DestroySprite(&gSprites[r5[i]]); + } +} + +void sub_8019F2C(void) +{ + s32 i, j, x, y; + for (i = 0; i < 8; i++) + { + for (j = 0; j < 5; j++) + { + sub_8019990(i, j, &x, &y); + sub_8088B94(x, y, 0); + } + } +} + +u8 sub_8019F64(u32 r1, u32 unused, struct UnkLinkRfuStruct_02022B14 * r2) +{ + if (r1 != 0) + { + return gUnknown_082F076F[r1]; + } + else if (r2->unk_0a_0 == 0x45) + { + return 1; + } + else + { + return 4; + } +} + +u32 sub_8019F8C(u32 a0, u32 a1) +{ + return sub_8097C8C(5 * a0 + a1 - 0x38); +} + +void sub_8019FA4(u32 r5, u32 r6, u8 r8, struct UnkLinkRfuStruct_02022B14 * r9) +{ + s32 x, y; + s32 r7 = 5 * r5 + r6; + if (sub_8019F8C(r5, r6) == 1) + { + sub_8097C44(r7 - 0x38, FALSE); + sub_8097CC4(r7 - 0x38, 1); + } + sub_8097BB4(r7 - 0x38, r8); + sub_801A3B0(r6, r5, sub_8019F64(r6, r5, r9)); + sub_8019990(r5, r6, &x, &y); + sub_8088B94(x, y, 1); +} + +void sub_801A02C(u32 a0, u32 a1) +{ + s32 x, y; + sub_8097CC4(5 * a0 + a1 - 0x38, 2); + sub_8019990(a0, a1, &x, &y); + sub_8088B94(x, y, 0); +}