From e6caf0ff1019a1744df5b7c550a1a40db33d0154 Mon Sep 17 00:00:00 2001 From: Marcus Huderle Date: Sun, 24 Mar 2019 17:20:35 -0500 Subject: [PATCH] Port mevent2.c from pokefirered --- asm/mevent2.s | 1425 -------------------------- asm/mevent_news.s | 8 +- data/{mevent2.s => mevent_801BAAC.s} | 6 - include/constants/flags.h | 35 +- include/global.h | 75 +- include/link.h | 2 +- include/main.h | 2 + include/mevent.h | 36 + include/mevent_news.h | 6 + ld_script.txt | 5 +- src/easy_chat.c | 4 +- src/mevent2.c | 626 +++++++++++ sym_ewram.txt | 3 +- 13 files changed, 771 insertions(+), 1462 deletions(-) delete mode 100755 asm/mevent2.s rename data/{mevent2.s => mevent_801BAAC.s} (96%) create mode 100755 include/mevent.h create mode 100755 include/mevent_news.h create mode 100755 src/mevent2.c diff --git a/asm/mevent2.s b/asm/mevent2.s deleted file mode 100755 index 6d894207f..000000000 --- a/asm/mevent2.s +++ /dev/null @@ -1,1425 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - -@void sub_801AFD8() { -@ CpuFill32(0, &gSaveBlock1Ptr->field_322C, 219); -@ sub_801B180(); -@ sub_811F8BC(); -@} - thumb_func_start sub_801AFD8 -sub_801AFD8: @ 801AFD8 - push {lr} - sub sp, 0x4 - movs r0, 0 - str r0, [sp] - ldr r0, =gSaveBlock1Ptr - ldr r1, [r0] - ldr r0, =0x0000322c - adds r1, r0 - ldr r2, =0x050000db - mov r0, sp - bl CpuSet - bl sub_801B180 - bl sub_811F8BC - add sp, 0x4 - pop {r0} - bx r0 - .pool - thumb_func_end sub_801AFD8 - - thumb_func_start sub_801B00C -sub_801B00C: @ 801B00C - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldr r1, =0x00003230 - adds r0, r1 - bx lr - .pool - thumb_func_end sub_801B00C - - thumb_func_start sav1_get_mevent_buffer_1 -sav1_get_mevent_buffer_1: @ 801B020 - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldr r1, =0x000033f0 - adds r0, r1 - bx lr - .pool - thumb_func_end sav1_get_mevent_buffer_1 - - thumb_func_start sav1_get_mevent_buffer_2 -sav1_get_mevent_buffer_2: @ 801B034 - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - movs r1, 0xD5 - lsls r1, 6 - adds r0, r1 - bx lr - .pool - thumb_func_end sav1_get_mevent_buffer_2 - - thumb_func_start GetSaveBlock1Field356C -GetSaveBlock1Field356C: @ 801B044 - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldr r1, =0x0000356c - adds r0, r1 - bx lr - .pool - thumb_func_end GetSaveBlock1Field356C - - thumb_func_start GetSaveBlock1Field3564 -GetSaveBlock1Field3564: @ 801B058 - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldr r1, =0x00003564 - adds r0, r1 - bx lr - .pool - thumb_func_end GetSaveBlock1Field3564 - - thumb_func_start sub_801B06C -sub_801B06C: @ 801B06C - push {lr} - bl sub_801B14C - pop {r0} - bx r0 - thumb_func_end sub_801B06C - - thumb_func_start sub_801B078 -sub_801B078: @ 801B078 - push {r4-r7,lr} - adds r7, r0, 0 - bl sub_801B114 - cmp r0, 0 - beq _0801B0C4 - bl sub_801B14C - ldr r4, =gSaveBlock1Ptr - ldr r0, [r4] - ldr r5, =0x00003230 - adds r0, r5 - movs r6, 0xDE - lsls r6, 1 - adds r1, r7, 0 - adds r2, r6, 0 - bl memcpy - ldr r0, [r4] - adds r0, r5 - adds r1, r6, 0 - bl CalcCRC16WithTable - ldr r1, [r4] - ldr r2, =0x0000322c - adds r1, r2 - lsls r0, 16 - lsrs r0, 16 - str r0, [r1] - movs r0, 0x1 - b _0801B0C6 - .pool -_0801B0C4: - movs r0, 0 -_0801B0C6: - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_801B078 - - thumb_func_start sub_801B0CC -sub_801B0CC: @ 801B0CC - push {r4,lr} - ldr r4, =gSaveBlock1Ptr - ldr r0, [r4] - ldr r1, =0x00003230 - adds r0, r1 - movs r1, 0xDE - lsls r1, 1 - bl CalcCRC16WithTable - lsls r0, 16 - lsrs r0, 16 - ldr r4, [r4] - ldr r2, =0x0000322c - adds r1, r4, r2 - ldr r1, [r1] - cmp r0, r1 - bne _0801B10C - ldr r1, =0x00003230 - adds r0, r4, r1 - bl sub_801B114 - cmp r0, 0 - beq _0801B10C - movs r0, 0x1 - b _0801B10E - .pool -_0801B10C: - movs r0, 0 -_0801B10E: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_801B0CC - - thumb_func_start sub_801B114 -sub_801B114: @ 801B114 - push {lr} - ldrh r0, [r0] - cmp r0, 0 - beq _0801B120 - movs r0, 0x1 - b _0801B122 -_0801B120: - movs r0, 0 -_0801B122: - pop {r1} - bx r1 - thumb_func_end sub_801B114 - - thumb_func_start sub_801B128 -sub_801B128: @ 801B128 - push {lr} - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldr r1, =0x00003230 - adds r0, r1 - ldrb r0, [r0, 0x2] - cmp r0, 0 - beq _0801B144 - movs r0, 0x1 - b _0801B146 - .pool -_0801B144: - movs r0, 0 -_0801B146: - pop {r1} - bx r1 - thumb_func_end sub_801B128 - - thumb_func_start sub_801B14C -sub_801B14C: @ 801B14C - push {r4,lr} - sub sp, 0x4 - movs r4, 0 - str r4, [sp] - bl sub_801B00C - adds r1, r0, 0 - ldr r2, =0x0500006f - mov r0, sp - bl CpuSet - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldr r1, =0x0000322c - adds r0, r1 - str r4, [r0] - add sp, 0x4 - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_801B14C - - thumb_func_start sub_801B180 -sub_801B180: @ 801B180 - push {lr} - sub sp, 0x4 - movs r0, 0 - str r0, [sp] - bl GetSaveBlock1Field356C - adds r1, r0, 0 - ldr r2, =0x05000001 - mov r0, sp - bl CpuSet - bl sub_801DBC0 - add sp, 0x4 - pop {r0} - bx r0 - .pool - thumb_func_end sub_801B180 - - thumb_func_start sub_801B1A4 -sub_801B1A4: @ 801B1A4 - push {r4,r5,lr} - adds r5, r0, 0 - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldr r1, =0x00003230 - adds r4, r0, r1 - bl sub_801B0CC - cmp r0, 0 - bne _0801B1C4 -_0801B1B8: - movs r0, 0 - b _0801B1DC - .pool -_0801B1C4: - movs r2, 0 - ldr r3, =0x000001bb -_0801B1C8: - adds r0, r4, r2 - adds r1, r5, r2 - ldrb r0, [r0] - ldrb r1, [r1] - cmp r0, r1 - bne _0801B1B8 - adds r2, 0x1 - cmp r2, r3 - bls _0801B1C8 - movs r0, 0x1 -_0801B1DC: - pop {r4,r5} - pop {r1} - bx r1 - .pool - thumb_func_end sub_801B1A4 - - thumb_func_start sub_801B1E8 -sub_801B1E8: @ 801B1E8 - push {lr} - bl sub_801B330 - bl sub_801B368 - bl sub_801B9F8 - bl ClearRamScript - bl sub_809D4D8 - bl sub_809D570 - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0x00000bec - adds r0, r1 - bl ClearEReaderTrainer - pop {r0} - bx r0 - .pool - thumb_func_end sub_801B1E8 - - thumb_func_start sub_801B21C -sub_801B21C: @ 801B21C - push {r4-r7,lr} - adds r7, r0, 0 - bl sub_801B2CC - cmp r0, 0 - beq _0801B274 - bl sub_801B1E8 - ldr r4, =gSaveBlock1Ptr - ldr r0, [r4] - ldr r5, =0x000033f0 - adds r0, r5 - movs r6, 0xA6 - lsls r6, 1 - adds r1, r7, 0 - adds r2, r6, 0 - bl memcpy - ldr r0, [r4] - adds r0, r5 - adds r1, r6, 0 - bl CalcCRC16WithTable - ldr r1, [r4] - ldr r3, =0x000033ec - adds r2, r1, r3 - lsls r0, 16 - lsrs r0, 16 - str r0, [r2] - movs r0, 0xD5 - lsls r0, 6 - adds r2, r1, r0 - adds r1, r5 - ldrh r0, [r1, 0x2] - strh r0, [r2, 0x6] - movs r0, 0x1 - b _0801B276 - .pool -_0801B274: - movs r0, 0 -_0801B276: - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_801B21C - - thumb_func_start sub_801B27C -sub_801B27C: @ 801B27C - push {r4,r5,lr} - ldr r5, =gSaveBlock1Ptr - ldr r0, [r5] - ldr r1, =0x000033ec - adds r4, r0, r1 - adds r1, 0x4 - adds r0, r1 - movs r1, 0xA6 - lsls r1, 1 - bl CalcCRC16WithTable - lsls r0, 16 - lsrs r0, 16 - ldr r1, [r4] - cmp r1, r0 - bne _0801B2C4 - ldr r0, [r5] - ldr r1, =0x000033f0 - adds r0, r1 - bl sub_801B2CC - cmp r0, 0 - beq _0801B2C4 - bl sub_80991F8 - cmp r0, 0 - beq _0801B2C4 - movs r0, 0x1 - b _0801B2C6 - .pool -_0801B2C4: - movs r0, 0 -_0801B2C6: - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end sub_801B27C - - thumb_func_start sub_801B2CC -sub_801B2CC: @ 801B2CC - push {lr} - adds r2, r0, 0 - ldrh r0, [r2] - cmp r0, 0 - beq _0801B302 - ldrb r1, [r2, 0x8] - lsls r0, r1, 30 - lsrs r0, 30 - cmp r0, 0x2 - bhi _0801B302 - movs r0, 0xC0 - ands r0, r1 - cmp r0, 0 - beq _0801B2F0 - cmp r0, 0x40 - beq _0801B2F0 - cmp r0, 0x80 - bne _0801B302 -_0801B2F0: - lsls r0, r1, 26 - lsrs r0, 28 - cmp r0, 0x7 - bhi _0801B302 - ldrb r0, [r2, 0x9] - cmp r0, 0x7 - bhi _0801B302 - movs r0, 0x1 - b _0801B304 -_0801B302: - movs r0, 0 -_0801B304: - pop {r1} - bx r1 - thumb_func_end sub_801B2CC - - thumb_func_start sub_801B308 -sub_801B308: @ 801B308 - push {lr} - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldr r1, =0x000033f0 - adds r0, r1 - ldrb r1, [r0, 0x8] - movs r0, 0xC0 - ands r0, r1 - cmp r0, 0 - beq _0801B328 - movs r0, 0x1 - b _0801B32A - .pool -_0801B328: - movs r0, 0 -_0801B32A: - pop {r1} - bx r1 - thumb_func_end sub_801B308 - - thumb_func_start sub_801B330 -sub_801B330: @ 801B330 - push {r4,r5,lr} - sub sp, 0x4 - movs r5, 0 - str r5, [sp] - ldr r4, =gSaveBlock1Ptr - ldr r1, [r4] - ldr r0, =0x000033f0 - adds r1, r0 - ldr r2, =0x05000053 - mov r0, sp - bl CpuSet - ldr r0, [r4] - ldr r1, =0x000033ec - adds r0, r1 - str r5, [r0] - add sp, 0x4 - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_801B330 - - thumb_func_start sub_801B368 -sub_801B368: @ 801B368 - push {r4,lr} - sub sp, 0x4 - movs r4, 0 - str r4, [sp] - bl sav1_get_mevent_buffer_2 - adds r1, r0, 0 - ldr r2, =0x05000009 - mov r0, sp - bl CpuSet - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldr r1, =0x0000353c - adds r0, r1 - str r4, [r0] - add sp, 0x4 - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_801B368 - - thumb_func_start sub_801B39C -sub_801B39C: @ 801B39C - push {lr} - bl sub_801B27C - cmp r0, 0 - bne _0801B3AA - movs r0, 0 - b _0801B3B4 -_0801B3AA: - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldr r1, =0x000033f0 - adds r0, r1 - ldrh r0, [r0] -_0801B3B4: - pop {r1} - bx r1 - .pool - thumb_func_end sub_801B39C - - thumb_func_start sub_801B3C0 -sub_801B3C0: @ 801B3C0 - push {lr} - adds r2, r0, 0 - ldrb r1, [r2, 0x8] - movs r0, 0xC0 - ands r0, r1 - cmp r0, 0x40 - bne _0801B3D4 - movs r0, 0x3F - ands r0, r1 - strb r0, [r2, 0x8] -_0801B3D4: - pop {r0} - bx r0 - thumb_func_end sub_801B3C0 - - thumb_func_start sub_801B3D8 -sub_801B3D8: @ 801B3D8 - push {lr} - lsls r0, 16 - ldr r1, =0xfc180000 - adds r0, r1 - lsrs r0, 16 - cmp r0, 0x13 - bls _0801B3F0 - movs r0, 0 - b _0801B3F2 - .pool -_0801B3F0: - movs r0, 0x1 -_0801B3F2: - pop {r1} - bx r1 - thumb_func_end sub_801B3D8 - - thumb_func_start sub_801B3F8 -sub_801B3F8: @ 801B3F8 - push {r4,lr} - bl sub_801B39C - lsls r0, 16 - lsrs r4, r0, 16 - adds r0, r4, 0 - bl sub_801B3D8 - cmp r0, 0 - beq _0801B430 - ldr r1, =gUnknown_082F0DE8 - ldr r2, =0xfffffc18 - adds r0, r4, r2 - lsls r0, 1 - adds r0, r1 - ldrh r0, [r0] - bl FlagGet - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1 - beq _0801B430 - movs r0, 0x1 - b _0801B432 - .pool -_0801B430: - movs r0, 0 -_0801B432: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_801B3F8 - - thumb_func_start sub_801B438 -sub_801B438: @ 801B438 - push {lr} - movs r3, 0 - cmp r3, r1 - bge _0801B45A - adds r2, r0, 0 - adds r2, 0x8 -_0801B444: - ldrh r0, [r2, 0xE] - cmp r0, 0 - beq _0801B452 - ldrh r0, [r2] - cmp r0, 0 - beq _0801B452 - adds r3, 0x1 -_0801B452: - adds r2, 0x2 - subs r1, 0x1 - cmp r1, 0 - bne _0801B444 -_0801B45A: - adds r0, r3, 0 - pop {r1} - bx r1 - thumb_func_end sub_801B438 - - thumb_func_start sub_801B460 -sub_801B460: @ 801B460 - push {r4-r7,lr} - adds r5, r0, 0 - adds r4, r1, 0 - movs r1, 0 - cmp r1, r2 - bge _0801B49A - ldrh r6, [r4, 0x2] - movs r0, 0x16 - adds r0, r5 - mov r12, r0 -_0801B474: - lsls r3, r1, 1 - mov r7, r12 - ldrh r0, [r7] - cmp r0, r6 - beq _0801B48C - adds r0, r5, 0 - adds r0, 0x8 - adds r0, r3 - ldrh r0, [r0] - ldrh r3, [r4] - cmp r0, r3 - bne _0801B490 -_0801B48C: - movs r0, 0x1 - b _0801B49C -_0801B490: - movs r7, 0x2 - add r12, r7 - adds r1, 0x1 - cmp r1, r2 - blt _0801B474 -_0801B49A: - movs r0, 0 -_0801B49C: - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_801B460 - - thumb_func_start sub_801B4A4 -sub_801B4A4: @ 801B4A4 - push {lr} - adds r1, r0, 0 - ldrh r0, [r1, 0x2] - cmp r0, 0 - beq _0801B4C4 - ldrh r1, [r1] - cmp r1, 0 - beq _0801B4C4 - ldr r0, =0x0000019b - cmp r1, r0 - bhi _0801B4C4 - movs r0, 0x1 - b _0801B4C6 - .pool -_0801B4C4: - movs r0, 0 -_0801B4C6: - pop {r1} - bx r1 - thumb_func_end sub_801B4A4 - - thumb_func_start sub_801B4CC -sub_801B4CC: @ 801B4CC - push {lr} - bl sub_801B27C - cmp r0, 0 - beq _0801B500 - ldr r0, =gSaveBlock1Ptr - ldr r3, [r0] - ldr r0, =0x000033f0 - adds r2, r3, r0 - ldrb r1, [r2, 0x8] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x1 - bne _0801B500 - movs r1, 0xD5 - lsls r1, 6 - adds r0, r3, r1 - ldrb r1, [r2, 0x9] - bl sub_801B438 - b _0801B502 - .pool -_0801B500: - movs r0, 0 -_0801B502: - pop {r1} - bx r1 - thumb_func_end sub_801B4CC - - thumb_func_start sub_801B508 -sub_801B508: @ 801B508 - push {r4-r6,lr} - adds r5, r0, 0 - ldr r6, =gSaveBlock1Ptr - ldr r0, [r6] - ldr r1, =0x000033f0 - adds r0, r1 - ldrb r4, [r0, 0x9] - adds r0, r5, 0 - bl sub_801B4A4 - cmp r0, 0 - beq _0801B572 - ldr r0, [r6] - movs r1, 0xD5 - lsls r1, 6 - adds r0, r1 - adds r1, r5, 0 - adds r2, r4, 0 - bl sub_801B460 - cmp r0, 0 - beq _0801B54C - b _0801B572 - .pool -_0801B540: - ldrh r0, [r5, 0x2] - strh r0, [r1] - ldrh r0, [r5] - strh r0, [r2] - movs r0, 0x1 - b _0801B574 -_0801B54C: - movs r3, 0 - cmp r3, r4 - bge _0801B572 - ldr r0, [r6] - ldr r6, =0x00003548 - adds r2, r0, r6 - adds r6, 0xE - adds r1, r0, r6 -_0801B55C: - ldrh r0, [r2, 0xE] - cmp r0, 0 - bne _0801B568 - ldrh r0, [r2] - cmp r0, 0 - beq _0801B540 -_0801B568: - adds r2, 0x2 - adds r1, 0x2 - adds r3, 0x1 - cmp r3, r4 - blt _0801B55C -_0801B572: - movs r0, 0 -_0801B574: - pop {r4-r6} - pop {r1} - bx r1 - .pool - thumb_func_end sub_801B508 - - thumb_func_start sub_801B580 -sub_801B580: @ 801B580 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x4 - adds r5, r0, 0 - adds r4, r1, 0 - movs r0, 0 - str r0, [sp] - ldr r2, =0x05000019 - mov r0, sp - adds r1, r5, 0 - bl CpuSet - ldr r0, =0x00000101 - str r0, [r5] - movs r0, 0x1 - strh r0, [r5, 0x4] - str r0, [r5, 0x8] - cmp r4, 0 - beq _0801B5C0 - movs r0, 0x5 - strh r0, [r5, 0xC] - ldr r0, =0x00000201 - b _0801B5C8 - .pool -_0801B5C0: - movs r0, 0x4 - strh r0, [r5, 0xC] - movs r0, 0x80 - lsls r0, 2 -_0801B5C8: - str r0, [r5, 0x10] - bl sub_801B27C - cmp r0, 0 - beq _0801B5FC - bl sav1_get_mevent_buffer_1 - ldrh r0, [r0] - strh r0, [r5, 0x14] - bl sav1_get_mevent_buffer_2 - adds r1, r5, 0 - adds r1, 0x20 - ldm r0!, {r2-r4} - stm r1!, {r2-r4} - ldm r0!, {r2-r4} - stm r1!, {r2-r4} - ldm r0!, {r2-r4} - stm r1!, {r2-r4} - bl sav1_get_mevent_buffer_1 - ldrb r1, [r0, 0x9] - adds r0, r5, 0 - adds r0, 0x44 - strb r1, [r0] - b _0801B5FE -_0801B5FC: - strh r0, [r5, 0x14] -_0801B5FE: - adds r4, r5, 0 - adds r4, 0x4C - ldr r0, =gSaveBlock2Ptr - mov r8, r0 - adds r6, r5, 0 - adds r6, 0x45 - adds r7, r5, 0 - adds r7, 0x50 - movs r1, 0x5C - adds r1, r5 - mov r9, r1 - movs r2, 0x60 - adds r2, r5 - mov r10, r2 - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldr r3, =0x00003564 - adds r2, r0, r3 - adds r1, r5, 0 - adds r1, 0x16 - movs r3, 0x3 -_0801B628: - ldrh r0, [r2] - strh r0, [r1] - adds r2, 0x2 - adds r1, 0x2 - subs r3, 0x1 - cmp r3, 0 - bge _0801B628 - mov r0, r8 - ldr r1, [r0] - adds r1, 0xA - adds r0, r4, 0 - bl CopyTrainerId - mov r2, r8 - ldr r1, [r2] - adds r0, r6, 0 - bl StringCopy - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldr r3, =0x00002bb0 - adds r2, r0, r3 - adds r1, r7, 0 - movs r3, 0x5 -_0801B658: - ldrh r0, [r2] - strh r0, [r1] - adds r2, 0x2 - adds r1, 0x2 - subs r3, 0x1 - cmp r3, 0 - bge _0801B658 - ldr r1, =RomHeaderGameCode - mov r0, r9 - movs r2, 0x4 - bl memcpy - ldr r0, =RomHeaderSoftwareVersion - ldrb r0, [r0] - mov r4, r10 - strb r0, [r4] - add sp, 0x4 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_801B580 - - thumb_func_start sub_801B6A0 -sub_801B6A0: @ 801B6A0 - push {r4,lr} - adds r2, r0, 0 - adds r4, r1, 0 - ldr r1, [r2] - ldr r0, =0x00000101 - cmp r1, r0 - bne _0801B6DC - ldrh r1, [r2, 0x4] - movs r3, 0x1 - adds r0, r3, 0 - ands r0, r1 - cmp r0, 0 - beq _0801B6DC - ldr r0, [r2, 0x8] - ands r0, r3 - cmp r0, 0 - beq _0801B6DC - cmp r4, 0 - bne _0801B6E4 - ldrh r1, [r2, 0xC] - movs r0, 0x4 - ands r0, r1 - cmp r0, 0 - beq _0801B6DC - ldr r0, [r2, 0x10] - movs r1, 0xE0 - lsls r1, 2 - ands r0, r1 - cmp r0, 0 - bne _0801B6E4 -_0801B6DC: - movs r0, 0 - b _0801B6E6 - .pool -_0801B6E4: - movs r0, 0x1 -_0801B6E6: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_801B6A0 - - thumb_func_start sub_801B6EC -sub_801B6EC: @ 801B6EC - push {lr} - ldrh r1, [r1, 0x14] - cmp r1, 0 - bne _0801B6F8 - movs r0, 0 - b _0801B704 -_0801B6F8: - ldrh r0, [r0] - cmp r0, r1 - beq _0801B702 - movs r0, 0x2 - b _0801B704 -_0801B702: - movs r0, 0x1 -_0801B704: - pop {r1} - bx r1 - thumb_func_end sub_801B6EC - - thumb_func_start sub_801B708 -sub_801B708: @ 801B708 - push {r4-r6,lr} - adds r6, r0, 0 - adds r4, r1, 0 - adds r5, r4, 0 - adds r5, 0x20 - adds r4, 0x44 - ldrb r1, [r4] - adds r0, r5, 0 - bl sub_801B438 - ldrb r2, [r4] - subs r4, r2, r0 - cmp r4, 0 - bne _0801B728 - movs r0, 0x1 - b _0801B742 -_0801B728: - adds r0, r5, 0 - adds r1, r6, 0 - bl sub_801B460 - cmp r0, 0 - beq _0801B738 - movs r0, 0x3 - b _0801B742 -_0801B738: - cmp r4, 0x1 - beq _0801B740 - movs r0, 0x2 - b _0801B742 -_0801B740: - movs r0, 0x4 -_0801B742: - pop {r4-r6} - pop {r1} - bx r1 - thumb_func_end sub_801B708 - - thumb_func_start sub_801B748 -sub_801B748: @ 801B748 - push {r4,lr} - movs r3, 0 - adds r2, r0, 0 - adds r2, 0x16 -_0801B750: - ldrh r0, [r2] - ldrh r4, [r1] - cmp r0, r4 - beq _0801B75C - movs r0, 0 - b _0801B768 -_0801B75C: - adds r1, 0x2 - adds r2, 0x2 - adds r3, 0x1 - cmp r3, 0x3 - ble _0801B750 - movs r0, 0x1 -_0801B768: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_801B748 - - thumb_func_start sub_801B770 -sub_801B770: @ 801B770 - push {lr} - adds r2, r0, 0 - adds r2, 0x20 - adds r0, 0x44 - ldrb r1, [r0] - adds r0, r2, 0 - bl sub_801B438 - pop {r1} - bx r1 - thumb_func_end sub_801B770 - - thumb_func_start sub_801B784 -sub_801B784: @ 801B784 - push {lr} - adds r2, r0, 0 - cmp r1, 0x4 - bhi _0801B7D0 - lsls r0, r1, 2 - ldr r1, =_0801B79C - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_0801B79C: - .4byte _0801B7B0 - .4byte _0801B7B4 - .4byte _0801B7B8 - .4byte _0801B7BC - .4byte _0801B7C8 -_0801B7B0: - ldrh r0, [r2, 0x20] - b _0801B7D2 -_0801B7B4: - ldrh r0, [r2, 0x22] - b _0801B7D2 -_0801B7B8: - ldrh r0, [r2, 0x24] - b _0801B7D2 -_0801B7BC: - adds r0, r2, 0 - bl sub_801B770 - lsls r0, 16 - lsrs r0, 16 - b _0801B7D2 -_0801B7C8: - adds r0, r2, 0 - adds r0, 0x44 - ldrb r0, [r0] - b _0801B7D2 -_0801B7D0: - movs r0, 0 -_0801B7D2: - pop {r1} - bx r1 - thumb_func_end sub_801B784 - - thumb_func_start sub_801B7D8 -sub_801B7D8: @ 801B7D8 - push {r4,lr} - adds r4, r0, 0 - ldr r2, =gSaveBlock1Ptr - ldr r0, [r2] - ldr r1, =0x000033f0 - adds r0, r1 - ldrb r1, [r0, 0x8] - movs r0, 0x3 - ands r0, r1 - adds r3, r2, 0 - cmp r0, 0x2 - bne _0801B850 - movs r2, 0 - cmp r4, 0x4 - bhi _0801B83A - lsls r0, r4, 2 - ldr r1, =_0801B80C - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_0801B80C: - .4byte _0801B820 - .4byte _0801B828 - .4byte _0801B834 - .4byte _0801B83A - .4byte _0801B83A -_0801B820: - ldr r0, [r3] - movs r1, 0xD5 - lsls r1, 6 - b _0801B838 -_0801B828: - ldr r0, [r3] - ldr r1, =0x00003542 - b _0801B838 - .pool -_0801B834: - ldr r0, [r3] - ldr r1, =0x00003544 -_0801B838: - adds r2, r0, r1 -_0801B83A: - cmp r2, 0 - beq _0801B850 - ldrh r0, [r2] - adds r0, 0x1 - strh r0, [r2] - lsls r0, 16 - lsrs r0, 16 - ldr r1, =0x000003e7 - cmp r0, r1 - bls _0801B850 - strh r1, [r2] -_0801B850: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_801B7D8 - - thumb_func_start mevent_081445C0 -mevent_081445C0: @ 801B860 - push {lr} - cmp r0, 0x4 - bhi _0801B938 - lsls r0, 2 - ldr r1, =_0801B874 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_0801B874: - .4byte _0801B888 - .4byte _0801B8AC - .4byte _0801B8D0 - .4byte _0801B8F4 - .4byte _0801B918 -_0801B888: - ldr r0, =gSaveBlock1Ptr - ldr r2, [r0] - ldr r1, =0x000033f0 - adds r0, r2, r1 - ldrb r1, [r0, 0x8] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x2 - bne _0801B938 - movs r1, 0xD5 - lsls r1, 6 - adds r0, r2, r1 - ldrh r0, [r0] - b _0801B93A - .pool -_0801B8AC: - ldr r0, =gSaveBlock1Ptr - ldr r2, [r0] - ldr r1, =0x000033f0 - adds r0, r2, r1 - ldrb r1, [r0, 0x8] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x2 - bne _0801B938 - movs r1, 0xD5 - lsls r1, 6 - adds r0, r2, r1 - ldrh r0, [r0, 0x2] - b _0801B93A - .pool -_0801B8D0: - ldr r0, =gSaveBlock1Ptr - ldr r2, [r0] - ldr r1, =0x000033f0 - adds r0, r2, r1 - ldrb r1, [r0, 0x8] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x2 - bne _0801B938 - movs r1, 0xD5 - lsls r1, 6 - adds r0, r2, r1 - ldrh r0, [r0, 0x4] - b _0801B93A - .pool -_0801B8F4: - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldr r1, =0x000033f0 - adds r0, r1 - ldrb r1, [r0, 0x8] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x1 - bne _0801B938 - bl sub_801B4CC - lsls r0, 16 - lsrs r0, 16 - b _0801B93A - .pool -_0801B918: - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldr r1, =0x000033f0 - adds r2, r0, r1 - ldrb r1, [r2, 0x8] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x1 - bne _0801B938 - ldrb r0, [r2, 0x9] - b _0801B93A - .pool -_0801B938: - movs r0, 0 -_0801B93A: - pop {r1} - bx r1 - thumb_func_end mevent_081445C0 - - thumb_func_start sub_801B940 -sub_801B940: @ 801B940 - ldr r1, =gUnknown_02022C70 - movs r0, 0 - str r0, [r1] - bx lr - .pool - thumb_func_end sub_801B940 - - thumb_func_start sub_801B94C -sub_801B94C: @ 801B94C - push {r4,r5,lr} - lsls r0, 16 - lsrs r0, 16 - adds r4, r0, 0 - ldr r5, =gUnknown_02022C70 - movs r0, 0 - str r0, [r5] - cmp r4, 0 - beq _0801B98A - bl sub_801B27C - cmp r0, 0 - beq _0801B988 - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldr r1, =0x000033f0 - adds r0, r1 - ldrh r0, [r0] - cmp r0, r4 - bne _0801B988 - movs r0, 0x1 - str r0, [r5] - b _0801B98A - .pool -_0801B988: - movs r0, 0 -_0801B98A: - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end sub_801B94C - - thumb_func_start sub_801B990 -sub_801B990: @ 801B990 - push {lr} - adds r2, r0, 0 - ldr r0, =gUnknown_02022C70 - ldr r0, [r0] - cmp r0, 0 - beq _0801B9EC - cmp r2, 0x1 - beq _0801B9DC - cmp r2, 0x1 - bcc _0801B9C0 - cmp r2, 0x2 - bne _0801B9EC - ldr r0, =gSaveBlock1Ptr - ldr r2, [r0] - ldr r0, =0x00003584 - adds r2, r0 - movs r0, 0x2 - b _0801B9CA - .pool -_0801B9C0: - ldr r0, =gSaveBlock1Ptr - ldr r2, [r0] - ldr r0, =0x00003570 - adds r2, r0 - movs r0, 0 -_0801B9CA: - movs r3, 0x5 - bl sub_801BA8C - b _0801B9EC - .pool -_0801B9DC: - ldr r0, =gSaveBlock1Ptr - ldr r2, [r0] - ldr r0, =0x00003570 - adds r2, r0 - movs r0, 0x1 - movs r3, 0x5 - bl sub_801BA8C -_0801B9EC: - pop {r0} - bx r0 - .pool - thumb_func_end sub_801B990 - - thumb_func_start sub_801B9F8 -sub_801B9F8: @ 801B9F8 - push {lr} - sub sp, 0x4 - movs r0, 0 - str r0, [sp] - ldr r0, =gSaveBlock1Ptr - ldr r1, [r0] - ldr r0, =0x00003570 - adds r1, r0 - ldr r2, =0x0500000a - mov r0, sp - bl CpuSet - add sp, 0x4 - pop {r0} - bx r0 - .pool - thumb_func_end sub_801B9F8 - - thumb_func_start sub_801BA24 -sub_801BA24: @ 801BA24 - push {r4,r5,lr} - adds r5, r0, 0 - adds r4, r1, 0 - movs r1, 0 - cmp r1, r2 - bge _0801BA46 - ldr r0, [r4] - cmp r0, r5 - beq _0801BA46 - adds r3, r4, 0 -_0801BA38: - adds r3, 0x4 - adds r1, 0x1 - cmp r1, r2 - bge _0801BA46 - ldr r0, [r3] - cmp r0, r5 - bne _0801BA38 -_0801BA46: - cmp r1, r2 - bne _0801BA68 - subs r3, r1, 0x1 - cmp r3, 0 - ble _0801BA62 - lsls r0, r3, 2 - subs r0, 0x4 - adds r2, r0, r4 -_0801BA56: - ldr r0, [r2] - str r0, [r2, 0x4] - subs r2, 0x4 - subs r3, 0x1 - cmp r3, 0 - bgt _0801BA56 -_0801BA62: - str r5, [r4] - movs r0, 0x1 - b _0801BA84 -_0801BA68: - adds r3, r1, 0 - cmp r3, 0 - ble _0801BA80 - lsls r0, r3, 2 - subs r0, 0x4 - adds r2, r0, r4 -_0801BA74: - ldr r0, [r2] - str r0, [r2, 0x4] - subs r2, 0x4 - subs r3, 0x1 - cmp r3, 0 - bgt _0801BA74 -_0801BA80: - str r5, [r4] - movs r0, 0 -_0801BA84: - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end sub_801BA24 - - thumb_func_start sub_801BA8C -sub_801BA8C: @ 801BA8C - push {r4,lr} - adds r4, r0, 0 - adds r0, r1, 0 - adds r1, r2, 0 - adds r2, r3, 0 - bl sub_801BA24 - cmp r0, 0 - beq _0801BAA4 - adds r0, r4, 0 - bl sub_801B7D8 -_0801BAA4: - pop {r4} - pop {r0} - bx r0 - thumb_func_end sub_801BA8C - - .align 2, 0 @ don't pad with nop diff --git a/asm/mevent_news.s b/asm/mevent_news.s index 463e43c15..b49676ddb 100644 --- a/asm/mevent_news.s +++ b/asm/mevent_news.s @@ -9,7 +9,7 @@ sub_801DB68: @ 801DB68 push {r4,r5,lr} adds r4, r0, 0 - bl GetSaveBlock1Field356C + bl sub_801B044 adds r5, r0, 0 movs r0, 0x3 adds r1, r4, 0 @@ -55,7 +55,7 @@ _0801DBB8: thumb_func_start sub_801DBC0 sub_801DBC0: @ 801DBC0 push {lr} - bl GetSaveBlock1Field356C + bl sub_801B044 movs r1, 0 strb r1, [r0] strb r1, [r0, 0x1] @@ -72,7 +72,7 @@ sub_801DBDC: @ 801DBDC ldr r0, =0x0000402e bl GetVarPointer adds r4, r0, 0 - bl GetSaveBlock1Field356C + bl sub_801B044 adds r2, r0, 0 ldr r0, [r2] lsls r0, 24 @@ -103,7 +103,7 @@ _0801DC10: sub_801DC20: @ 801DC20 push {r4-r6,lr} ldr r6, =gSpecialVar_Result - bl GetSaveBlock1Field356C + bl sub_801B044 adds r4, r0, 0 bl IsMysteryEventEnabled cmp r0, 0 diff --git a/data/mevent2.s b/data/mevent_801BAAC.s similarity index 96% rename from data/mevent2.s rename to data/mevent_801BAAC.s index cc2b69afe..37c1ae46f 100755 --- a/data/mevent2.s +++ b/data/mevent_801BAAC.s @@ -3,12 +3,6 @@ .section .rodata - .align 2 -gUnknown_082F0DE8:: @ 82F0DE8 - .2byte 0x013a, 0x013b, 0x013c, 0x013d, 0x013e, 0x013f, 0x0140, 0x0141 - .2byte 0x0142, 0x0143, 0x0144, 0x0145, 0x0146, 0x0147, 0x0148, 0x0149 - .2byte 0x014a, 0x014b, 0x014c, 0x014d - .align 2 gUnknown_082F0E10:: @ 82F0E10 .byte 0x00, 0x02, 0x03 diff --git a/include/constants/flags.h b/include/constants/flags.h index 230fbabaf..f28af3278 100644 --- a/include/constants/flags.h +++ b/include/constants/flags.h @@ -336,24 +336,23 @@ #define FLAG_RECEIVED_AURORA_TICKET 0x13A // RECEIVED Aurora Ticket in Mystery Gift #define FLAG_RECEIVED_MYSTIC_TICKET 0x13B // RECEIVED Mystic Ticket in Mystery Gift #define FLAG_RECEIVED_OLD_SEA_MAP 0x13C // RECEIVED Old Sea Map in Mystery Gift - -#define FLAG_UNUSED_0x13D 0x13D // Unused Flag -#define FLAG_UNUSED_0x13E 0x13E // Unused Flag -#define FLAG_UNUSED_0x13F 0x13F // Unused Flag -#define FLAG_UNUSED_0x140 0x140 // Unused Flag -#define FLAG_UNUSED_0x141 0x141 // Unused Flag -#define FLAG_UNUSED_0x142 0x142 // Unused Flag -#define FLAG_UNUSED_0x143 0x143 // Unused Flag -#define FLAG_UNUSED_0x144 0x144 // Unused Flag -#define FLAG_UNUSED_0x145 0x145 // Unused Flag -#define FLAG_UNUSED_0x146 0x146 // Unused Flag -#define FLAG_UNUSED_0x147 0x147 // Unused Flag -#define FLAG_UNUSED_0x148 0x148 // Unused Flag -#define FLAG_UNUSED_0x149 0x149 // Unused Flag -#define FLAG_UNUSED_0x14A 0x14A // Unused Flag -#define FLAG_UNUSED_0x14B 0x14B // Unused Flag -#define FLAG_UNUSED_0x14C 0x14C // Unused Flag -#define FLAG_UNUSED_0x14D 0x14D // Unused Flag +#define FLAG_UNUSED_MYSTERY_GIFT_0x13D 0x13D +#define FLAG_UNUSED_MYSTERY_GIFT_0x13E 0x13E +#define FLAG_UNUSED_MYSTERY_GIFT_0x13F 0x13F +#define FLAG_UNUSED_MYSTERY_GIFT_0x140 0x140 +#define FLAG_UNUSED_MYSTERY_GIFT_0x141 0x141 +#define FLAG_UNUSED_MYSTERY_GIFT_0x142 0x142 +#define FLAG_UNUSED_MYSTERY_GIFT_0x143 0x143 +#define FLAG_UNUSED_MYSTERY_GIFT_0x144 0x144 +#define FLAG_UNUSED_MYSTERY_GIFT_0x145 0x145 +#define FLAG_UNUSED_MYSTERY_GIFT_0x146 0x146 +#define FLAG_UNUSED_MYSTERY_GIFT_0x147 0x147 +#define FLAG_UNUSED_MYSTERY_GIFT_0x148 0x148 +#define FLAG_UNUSED_MYSTERY_GIFT_0x149 0x149 +#define FLAG_UNUSED_MYSTERY_GIFT_0x14A 0x14A +#define FLAG_UNUSED_MYSTERY_GIFT_0x14B 0x14B +#define FLAG_UNUSED_MYSTERY_GIFT_0x14C 0x14C +#define FLAG_UNUSED_MYSTERY_GIFT_0x14D 0x14D #define FLAG_MIRAGE_TOWER_VISIBLE 0x14E #define FLAG_CHOSE_CLAW_FOSSIL 0x14F // Player chose Claw Fossil diff --git a/include/global.h b/include/global.h index 1f9ac5185..d738deb3c 100644 --- a/include/global.h +++ b/include/global.h @@ -808,6 +808,76 @@ struct SaveTrainerHill /*0x3D6E*/ u16 tag:2; // x40, x80 = xC0 }; +struct MysteryEventStruct +{ + u8 unk_0_0:2; + u8 unk_0_2:3; + u8 unk_0_5:3; + u8 unk_1; +}; + + struct MEventBuffer_3120_Sub +{ + u16 unk_00; + u8 unk_02; + u8 unk_03; + u8 unk_04[40]; + u8 unk_2C[10][40]; +}; + + struct MEventBuffer_3120 +{ + u32 crc; + struct MEventBuffer_3120_Sub data; +}; + + struct MEventBuffer_32E0_Sub +{ + u16 unk_00; + u16 unk_02; + u32 unk_04; + u8 unk_08_0:2; + u8 unk_08_2:4; + u8 unk_08_6:2; + u8 unk_09; + u8 unk_0A[40]; + u8 unk_32[40]; + u8 unk_5A[4][40]; + u8 unk_FA[40]; + u8 unk_122[40]; +}; + + struct MEventBuffer_32E0 +{ + u32 crc; + struct MEventBuffer_32E0_Sub data; +}; + + struct MEventBuffer_3430_Sub +{ + u16 unk_00; + u16 unk_02; + u16 unk_04; + u16 unk_06; + u16 unk_08[2][7]; +}; + + struct MEventBuffer_3430 +{ + u32 crc; + struct MEventBuffer_3430_Sub data; +}; + + struct MEventBuffers +{ + /*0x000 0x322C*/ struct MEventBuffer_3120 buffer_000; + /*0x1c0 0x33EC*/ struct MEventBuffer_32E0 buffer_1c0; + /*0x310 0x353C*/ struct MEventBuffer_3430 buffer_310; + /*0x338 0x3564*/ u16 unk_338[4]; + /*0x340 0x356C*/ struct MysteryEventStruct unk_340; + /*0x344 0x3570*/ u32 unk_344[2][5]; +}; // 0x36C 0x3598 + struct SaveBlock1 { /*0x00*/ struct Coords16 pos; @@ -884,14 +954,15 @@ struct SaveBlock1 /*0x31A8*/ u8 giftRibbons[52]; /*0x31DC*/ struct Roamer roamer; /*0x31F8*/ struct EnigmaBerry enigmaBerry; - /*0x322C*/ u8 field_322C[1260]; + /*0x322C*/ struct MEventBuffers unk_322C; + /*0x3598*/ u8 field_3598[0x180]; /*0x3718*/ u32 trainerHillTimes[4]; /*0x3728*/ struct RamScript ramScript; /*0x3B14*/ struct RecordMixingGift recordMixingGift; /*0x3B24*/ u8 seen2[DEX_FLAGS_NO]; /*0x3B58*/ LilycoveLady lilycoveLady; /*0x3B98*/ struct TrainerNameRecord trainerNameRecords[20]; - /*0x3C88*/ u8 filler_3C88[0xDC]; + /*0x3C88*/ u8 unk3C88[11][20]; /*0x3D64*/ struct SaveTrainerHill trainerHill; /*0x3D70*/ struct WaldaPhrase waldaPhrase; // sizeof: 0x3D88 diff --git a/include/link.h b/include/link.h index 1e865e72b..b2d4284b7 100644 --- a/include/link.h +++ b/include/link.h @@ -306,7 +306,7 @@ void sub_8009FAC(void); bool8 sub_800A4D8(u8 a0); u8 sub_800A9D8(void); u8 sub_800A0C8(s32, s32); -u16 *GetSaveBlock1Field3564(void); +u16 *sub_801B058(void); u8 sub_800A9A8(void); void sub_800AD10(void); void sub_800AB18(void); diff --git a/include/main.h b/include/main.h index 4f9a9e61a..6c67fbe9f 100644 --- a/include/main.h +++ b/include/main.h @@ -42,6 +42,8 @@ struct Main extern const u8 gGameVersion; extern const u8 gGameLanguage; +extern const u8 RomHeaderGameCode[4]; +extern const u8 RomHeaderSoftwareVersion; extern u16 gKeyRepeatStartDelay; extern bool8 gLinkTransferringData; diff --git a/include/mevent.h b/include/mevent.h new file mode 100755 index 000000000..ce50591b1 --- /dev/null +++ b/include/mevent.h @@ -0,0 +1,36 @@ +#ifndef GUARD_MEVENT_H +#define GUARD_MEVENT_H + +#include + +struct MEvent_Str_1 +{ + u16 unk_000; + size_t unk_004; + const void * unk_008; +}; + +struct MEvent_Str_2 +{ + u8 fill_00[0x40]; +}; + +struct MEventStruct_Unk1442CC +{ + u32 unk_00; + u16 unk_04; + u32 unk_08; + u16 unk_0C; + u32 unk_10; + u16 unk_14; + u16 unk_16[4]; + struct MEventBuffer_3430_Sub unk_20; + u8 unk_44; + u8 unk_45[7]; + u8 unk_4C[4]; + u16 unk_50[6]; + u8 unk_5C[4]; + u8 unk_60; +}; + +#endif //GUARD_MEVENT_H diff --git a/include/mevent_news.h b/include/mevent_news.h new file mode 100755 index 000000000..698d7148c --- /dev/null +++ b/include/mevent_news.h @@ -0,0 +1,6 @@ +#ifndef GUARD_MEVENT_NEWS_H +#define GUARD_MEVENT_NEWS_H + +void sub_801DBC0(void); + +#endif //GUARD_MEVENT_NEWS_H diff --git a/ld_script.txt b/ld_script.txt index d5d894528..b4f99d606 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -56,7 +56,7 @@ SECTIONS { src/link_rfu.o(.text); src/union_room.o(.text); asm/union_room.o(.text); - asm/mevent2.o(.text); + src/mevent2.o(.text); asm/mevent_801BAAC.o(.text); asm/mevent_server.o(.text); asm/mevent_server_ish.o(.text); @@ -409,7 +409,8 @@ SECTIONS { src/link_rfu.o(.rodata); src/union_room.o(.rodata); data/union_room.o(.rodata); - data/mevent2.o(.rodata); + src/mevent2.o(.rodata); + data/mevent_801BAAC.o(.rodata); data/mevent_server.o(.rodata); data/union_room_chat.o(.rodata); data/berry_crush.o(.rodata); diff --git a/src/easy_chat.c b/src/easy_chat.c index 4cc8b9c5b..a6d22f8bf 100644 --- a/src/easy_chat.c +++ b/src/easy_chat.c @@ -1318,7 +1318,7 @@ void ShowEasyChatScreen(void) words = gSaveBlock2Ptr->apprentices[0].easyChatWords; break; case EASY_CHAT_TYPE_QUESTIONNAIRE: - words = GetSaveBlock1Field3564(); + words = sub_801B058(); break; default: return; @@ -5531,7 +5531,7 @@ void InitializeEasyChatWordArray(u16 *words, u16 length) void sub_811F8BC(void) { int i; - u16 *words = GetSaveBlock1Field3564(); + u16 *words = sub_801B058(); for (i = 0; i < 4; i++) words[i] = 0xFFFF; } diff --git a/src/mevent2.c b/src/mevent2.c new file mode 100755 index 000000000..9a6f713ea --- /dev/null +++ b/src/mevent2.c @@ -0,0 +1,626 @@ +#include "global.h" +#include "util.h" +#include "main.h" +#include "event_data.h" +#include "easy_chat.h" +#include "script.h" +#include "battle_tower.h" +#include "mevent_news.h" +#include "string_util.h" +#include "new_game.h" +#include "mevent.h" +#include "constants/species.h" + +static EWRAM_DATA bool32 gUnknown_02022C70 = FALSE; + +void sub_801B180(void); +void sub_801B14C(void); +bool32 sub_801B114(const struct MEventBuffer_3120_Sub * data); +bool32 sub_801B2CC(const struct MEventBuffer_32E0_Sub * data); +void sub_801B330(void); +void sub_801B368(void); +void sub_801B9F8(void); +void sub_801BA8C(u32 a0, u32 a1, u32 * a2, int a3); + +void sub_801AFD8(void) +{ + CpuFill32(0, &gSaveBlock1Ptr->unk_322C, sizeof(gSaveBlock1Ptr->unk_322C)); + sub_801B180(); + sub_811F8BC(); +} + +struct MEventBuffer_3120_Sub * sub_801B00C(void) +{ + return &gSaveBlock1Ptr->unk_322C.buffer_000.data; +} + +struct MEventBuffer_32E0_Sub * sav1_get_mevent_buffer_1(void) +{ + return &gSaveBlock1Ptr->unk_322C.buffer_1c0.data; +} + +struct MEventBuffer_3430_Sub * sav1_get_mevent_buffer_2(void) +{ + return &gSaveBlock1Ptr->unk_322C.buffer_310.data; +} + +struct MysteryEventStruct * sub_801B044(void) +{ + return &gSaveBlock1Ptr->unk_322C.unk_340; +} + +u16 * sub_801B058(void) +{ + return gSaveBlock1Ptr->unk_322C.unk_338; +} + +void sub_801B06C(void) +{ + sub_801B14C(); +} + +bool32 sub_801B078(const struct MEventBuffer_3120_Sub * src) +{ + if (!sub_801B114(src)) + return FALSE; + + sub_801B14C(); + gSaveBlock1Ptr->unk_322C.buffer_000.data = *src; + gSaveBlock1Ptr->unk_322C.buffer_000.crc = CalcCRC16WithTable((void *)&gSaveBlock1Ptr->unk_322C.buffer_000.data, sizeof(struct MEventBuffer_3120_Sub)); + return TRUE; +} + +bool32 sub_801B0CC(void) +{ + if (CalcCRC16WithTable((void *)&gSaveBlock1Ptr->unk_322C.buffer_000.data, sizeof(struct MEventBuffer_3120_Sub)) != gSaveBlock1Ptr->unk_322C.buffer_000.crc) + return FALSE; + if (!sub_801B114(&gSaveBlock1Ptr->unk_322C.buffer_000.data)) + return FALSE; + + return TRUE; +} + +bool32 sub_801B114(const struct MEventBuffer_3120_Sub * data) +{ + if (data->unk_00 == 0) + return FALSE; + + return TRUE; +} + +bool32 sub_801B128(void) +{ + const struct MEventBuffer_3120_Sub * data = &gSaveBlock1Ptr->unk_322C.buffer_000.data; + if (data->unk_02 == 0) + return FALSE; + + return TRUE; +} + +void sub_801B14C(void) +{ + CpuFill32(0, sub_801B00C(), sizeof(gSaveBlock1Ptr->unk_322C.buffer_000.data)); + gSaveBlock1Ptr->unk_322C.buffer_000.crc = 0; +} + +void sub_801B180(void) +{ + CpuFill32(0, sub_801B044(), sizeof(struct MysteryEventStruct)); + sub_801DBC0(); +} + +bool32 sub_801B1A4(const u8 * src) +{ + const u8 * r5 = (const u8 *)&gSaveBlock1Ptr->unk_322C.buffer_000.data; + u32 i; + if (!sub_801B0CC()) + return FALSE; + + for (i = 0; i < sizeof(struct MEventBuffer_3120_Sub); i++) + { + if (r5[i] != src[i]) + return FALSE; + } + + return TRUE; +} + +void sub_801B1E8(void) +{ + sub_801B330(); + sub_801B368(); + sub_801B9F8(); + ClearRamScript(); + sub_809D4D8(); + sub_809D570(); + ClearEReaderTrainer(&gSaveBlock2Ptr->frontier.ereaderTrainer); +} + +bool32 sub_801B21C(const struct MEventBuffer_32E0_Sub * data) +{ + struct MEventBuffer_3430_Sub * r2; + struct MEventBuffer_32E0_Sub * r1; + if (!sub_801B2CC(data)) + return FALSE; + + sub_801B1E8(); + memcpy(&gSaveBlock1Ptr->unk_322C.buffer_1c0.data, data, sizeof(struct MEventBuffer_32E0_Sub)); + gSaveBlock1Ptr->unk_322C.buffer_1c0.crc = CalcCRC16WithTable((void *)&gSaveBlock1Ptr->unk_322C.buffer_1c0.data, sizeof(struct MEventBuffer_32E0_Sub)); + r2 = &gSaveBlock1Ptr->unk_322C.buffer_310.data; + r1 = &gSaveBlock1Ptr->unk_322C.buffer_1c0.data; + r2->unk_06 = r1->unk_02; + return TRUE; +} + +bool32 sub_801B27C(void) +{ + if (gSaveBlock1Ptr->unk_322C.buffer_1c0.crc != CalcCRC16WithTable((void *)&gSaveBlock1Ptr->unk_322C.buffer_1c0.data, sizeof(struct MEventBuffer_32E0_Sub))) + return FALSE; + if (!sub_801B2CC(&gSaveBlock1Ptr->unk_322C.buffer_1c0.data)) + return FALSE; + if (!sub_80991F8()) + return FALSE; + + return TRUE; +} + +bool32 sub_801B2CC(const struct MEventBuffer_32E0_Sub * data) +{ + if (data->unk_00 == 0) + return FALSE; + if (data->unk_08_0 > 2) + return FALSE; + if (!(data->unk_08_6 == 0 || data->unk_08_6 == 1 || data->unk_08_6 == 2)) + return FALSE; + if (data->unk_08_2 > 7) + return FALSE; + if (data->unk_09 > 7) + return FALSE; + + return TRUE; +} + +bool32 sub_801B308(void) +{ + const struct MEventBuffer_32E0_Sub * data = &gSaveBlock1Ptr->unk_322C.buffer_1c0.data; + if (data->unk_08_6 == 0) + return FALSE; + + return TRUE; +} + +void sub_801B330(void) +{ + CpuFill32(0, &gSaveBlock1Ptr->unk_322C.buffer_1c0.data, sizeof(struct MEventBuffer_32E0_Sub)); + gSaveBlock1Ptr->unk_322C.buffer_1c0.crc = 0; +} + +void sub_801B368(void) +{ + CpuFill32(0, sav1_get_mevent_buffer_2(), 18 * sizeof(u16)); + gSaveBlock1Ptr->unk_322C.buffer_310.crc = 0; +} + +u16 sub_801B39C(void) +{ + if (sub_801B27C()) + return gSaveBlock1Ptr->unk_322C.buffer_1c0.data.unk_00; + + return 0; +} + +void sub_801B3C0(struct MEventBuffer_32E0_Sub * buffer) +{ + if (buffer->unk_08_6 == 1) + buffer->unk_08_6 = 0; +} + +bool32 sub_801B3D8(u16 a0) +{ + if (a0 >= 1000 && a0 < 1020) + return TRUE; + + return FALSE; +} + +static const u16 sMysteryGiftFlags[] = +{ + FLAG_RECEIVED_AURORA_TICKET, + FLAG_RECEIVED_MYSTIC_TICKET, + FLAG_RECEIVED_OLD_SEA_MAP, + FLAG_UNUSED_MYSTERY_GIFT_0x13D, + FLAG_UNUSED_MYSTERY_GIFT_0x13E, + FLAG_UNUSED_MYSTERY_GIFT_0x13F, + FLAG_UNUSED_MYSTERY_GIFT_0x140, + FLAG_UNUSED_MYSTERY_GIFT_0x141, + FLAG_UNUSED_MYSTERY_GIFT_0x142, + FLAG_UNUSED_MYSTERY_GIFT_0x143, + FLAG_UNUSED_MYSTERY_GIFT_0x144, + FLAG_UNUSED_MYSTERY_GIFT_0x145, + FLAG_UNUSED_MYSTERY_GIFT_0x146, + FLAG_UNUSED_MYSTERY_GIFT_0x147, + FLAG_UNUSED_MYSTERY_GIFT_0x148, + FLAG_UNUSED_MYSTERY_GIFT_0x149, + FLAG_UNUSED_MYSTERY_GIFT_0x14A, + FLAG_UNUSED_MYSTERY_GIFT_0x14B, + FLAG_UNUSED_MYSTERY_GIFT_0x14C, + FLAG_UNUSED_MYSTERY_GIFT_0x14D, +}; + +bool32 sub_801B3F8(void) +{ + u16 value = sub_801B39C(); + if (!sub_801B3D8(value)) + return FALSE; + + if (FlagGet(sMysteryGiftFlags[value - 1000]) == TRUE) + return FALSE; + + return TRUE; +} + +int sub_801B438(const struct MEventBuffer_3430_Sub * data, int size) +{ + int r3 = 0; + int i; + for (i = 0; i < size; i++) + { + if (data->unk_08[1][i] && data->unk_08[0][i]) + r3++; + } + + return r3; +} + +bool32 sub_801B460(const struct MEventBuffer_3430_Sub * data1, const u16 * data2, int size) +{ + int i; + for (i = 0; i < size; i++) + { + if (data1->unk_08[1][i] == data2[1]) + return TRUE; + if (data1->unk_08[0][i] == data2[0]) + return TRUE; + } + + return FALSE; +} + +bool32 sub_801B4A4(const u16 * data) +{ + if (data[1] == 0) + return FALSE; + if (data[0] == 0) + return FALSE; + if (data[0] >= NUM_SPECIES) + return FALSE; + return TRUE; +} + +int sub_801B4CC(void) +{ + struct MEventBuffer_32E0_Sub * data; + if (!sub_801B27C()) + return 0; + + data = &gSaveBlock1Ptr->unk_322C.buffer_1c0.data; + if (data->unk_08_0 != 1) + return 0; + + return sub_801B438(&gSaveBlock1Ptr->unk_322C.buffer_310.data, data->unk_09); +} + +bool32 sub_801B508(const u16 * data) +{ + struct MEventBuffer_32E0_Sub * buffer = &gSaveBlock1Ptr->unk_322C.buffer_1c0.data; + int size = buffer->unk_09; + int i; + if (!sub_801B4A4(data)) + return FALSE; + + if (sub_801B460(&gSaveBlock1Ptr->unk_322C.buffer_310.data, data, size)) + return FALSE; + + for (i = 0; i < size; i++) + { + if (gSaveBlock1Ptr->unk_322C.buffer_310.data.unk_08[1][i] == 0 && gSaveBlock1Ptr->unk_322C.buffer_310.data.unk_08[0][i] == 0) + { + gSaveBlock1Ptr->unk_322C.buffer_310.data.unk_08[1][i] = data[1]; + gSaveBlock1Ptr->unk_322C.buffer_310.data.unk_08[0][i] = data[0]; + return TRUE; + } + } + + return FALSE; +} + +void sub_801B580(struct MEventStruct_Unk1442CC * data, bool32 a1) +{ + int i; + CpuFill32(0, data, sizeof(struct MEventStruct_Unk1442CC)); + data->unk_00 = 0x101; + data->unk_04 = 1; + data->unk_08 = 1; + + if (a1) + { + data->unk_0C = 5; + data->unk_10 = 0x0201; + } + else + { + data->unk_0C = 4; + data->unk_10 = 0x0200; + } + + if (sub_801B27C()) + { + data->unk_14 = sav1_get_mevent_buffer_1()->unk_00; + data->unk_20 = *sav1_get_mevent_buffer_2(); + data->unk_44 = sav1_get_mevent_buffer_1()->unk_09; + } + else + { + data->unk_14 = 0; + } + + for (i = 0; i < 4; i++) + data->unk_16[i] = gSaveBlock1Ptr->unk_322C.unk_338[i]; + + CopyTrainerId(data->unk_4C, gSaveBlock2Ptr->playerTrainerId); + StringCopy(data->unk_45, gSaveBlock2Ptr->playerName); + for (i = 0; i < 6; i++) + data->unk_50[i] = gSaveBlock1Ptr->easyChatProfile[i]; + + memcpy(data->unk_5C, RomHeaderGameCode, 4); + data->unk_60 = RomHeaderSoftwareVersion; +} + +bool32 sub_801B6A0(const struct MEventStruct_Unk1442CC * data, bool32 a1) +{ + if (data->unk_00 != 0x101) + return FALSE; + + if (!(data->unk_04 & 1)) + return FALSE; + + if (!(data->unk_08 & 1)) + return FALSE; + + if (!a1) + { + if (!(data->unk_0C & 4)) + return FALSE; + + if (!(data->unk_10 & 0x380)) + return FALSE; + } + + return TRUE; +} + +u32 sub_801B6EC(const u16 * a0, const struct MEventStruct_Unk1442CC * a1, void * unused) +{ + if (a1->unk_14 == 0) + return 0; + + if (*a0 == a1->unk_14) + return 1; + + return 2; +} + +u32 sub_801B708(const u16 * a0, const struct MEventStruct_Unk1442CC * a1, void * unused) +{ + int r4 = a1->unk_44 - sub_801B438(&a1->unk_20, a1->unk_44); + if (r4 == 0) + return 1; + if (sub_801B460(&a1->unk_20, a0, a1->unk_44)) + return 3; + if (r4 == 1) + return 4; + return 2; +} + +bool32 sub_801B748(const struct MEventStruct_Unk1442CC * a0, const u16 * a1) +{ + int i; + for (i = 0; i < 4; i++) + { + if (a0->unk_16[i] != a1[i]) + return FALSE; + } + + return TRUE; +} + +int sub_801B770(const struct MEventStruct_Unk1442CC * a0) +{ + return sub_801B438(&a0->unk_20, a0->unk_44); +} + +u16 sub_801B784(const struct MEventStruct_Unk1442CC * a0, u32 command) +{ + switch (command) + { + case 0: + return a0->unk_20.unk_00; + case 1: + return a0->unk_20.unk_02; + case 2: + return a0->unk_20.unk_04; + case 3: + return sub_801B770(a0); + case 4: + return a0->unk_44; + default: + AGB_ASSERT(0); + return 0; + } +} + +void sub_801B7D8(u32 command) +{ + struct MEventBuffer_32E0_Sub * data = &gSaveBlock1Ptr->unk_322C.buffer_1c0.data; + if (data->unk_08_0 == 2) + { + u16 * dest = NULL; + switch (command) + { + case 0: + dest = &gSaveBlock1Ptr->unk_322C.buffer_310.data.unk_00; + break; + case 1: + dest = &gSaveBlock1Ptr->unk_322C.buffer_310.data.unk_02; + break; + case 2: + dest = &gSaveBlock1Ptr->unk_322C.buffer_310.data.unk_04; + break; + case 3: + break; + case 4: + break; + } + + if (dest == NULL) + AGB_ASSERT(0); + else if (++(*dest) > 999) + *dest = 999; + } +} + +u16 mevent_081445C0(u32 command) +{ + switch (command) + { + case 0: + { + struct MEventBuffer_32E0_Sub *data = &gSaveBlock1Ptr->unk_322C.buffer_1c0.data; + if (data->unk_08_0 == 2) + { + struct MEventBuffer_3430_Sub * buffer = &gSaveBlock1Ptr->unk_322C.buffer_310.data; + return buffer->unk_00; + } + break; + } + case 1: + { + struct MEventBuffer_32E0_Sub *data = &gSaveBlock1Ptr->unk_322C.buffer_1c0.data; + if (data->unk_08_0 == 2) + { + struct MEventBuffer_3430_Sub * buffer = &gSaveBlock1Ptr->unk_322C.buffer_310.data; + return buffer->unk_02; + } + break; + } + case 2: + { + struct MEventBuffer_32E0_Sub *data = &gSaveBlock1Ptr->unk_322C.buffer_1c0.data; + if (data->unk_08_0 == 2) + { + struct MEventBuffer_3430_Sub * buffer = &gSaveBlock1Ptr->unk_322C.buffer_310.data; + return buffer->unk_04; + } + break; + } + case 3: + { + struct MEventBuffer_32E0_Sub *data = &gSaveBlock1Ptr->unk_322C.buffer_1c0.data; + if (data->unk_08_0 == 1) + return sub_801B4CC(); + break; + } + case 4: + { + struct MEventBuffer_32E0_Sub *data = &gSaveBlock1Ptr->unk_322C.buffer_1c0.data; + if (data->unk_08_0 == 1) + return data->unk_09; + break; + } + } + + AGB_ASSERT(0); + return 0; +} + +void sub_801B940(void) +{ + gUnknown_02022C70 = FALSE; +} + +bool32 sub_801B94C(u16 a0) +{ + gUnknown_02022C70 = FALSE; + if (a0 == 0) + return FALSE; + + if (!sub_801B27C()) + return FALSE; + + if (gSaveBlock1Ptr->unk_322C.buffer_1c0.data.unk_00 != a0) + return FALSE; + + gUnknown_02022C70 = TRUE; + return TRUE; +} + +void sub_801B990(u32 a0, u32 a1) +{ + if (gUnknown_02022C70) + { + switch (a0) + { + case 2: + sub_801BA8C(2, a1, gSaveBlock1Ptr->unk_322C.unk_344[1], 5); + break; + case 0: + sub_801BA8C(0, a1, gSaveBlock1Ptr->unk_322C.unk_344[0], 5); + break; + case 1: + sub_801BA8C(1, a1, gSaveBlock1Ptr->unk_322C.unk_344[0], 5); + break; + default: + AGB_ASSERT(0); + } + } +} + +void sub_801B9F8(void) +{ + CpuFill32(0, gSaveBlock1Ptr->unk_322C.unk_344, sizeof(gSaveBlock1Ptr->unk_322C.unk_344)); +} + +bool32 sub_801BA24(u32 a0, u32 * a1, int size) +{ + int i; + int j; + + for (i = 0; i < size; i++) + { + if (a1[i] == a0) + break; + } + + if (i == size) + { + for (j = size - 1; j > 0; j--) + a1[j] = a1[j - 1]; + + a1[0] = a0; + return TRUE; + } + else + { + for (j = i; j > 0; j--) + a1[j] = a1[j - 1]; + + a1[0] = a0; + return FALSE; + } +} + +void sub_801BA8C(u32 a0, u32 a1, u32 * a2, int a3) +{ + if (sub_801BA24(a1, a2, a3)) + sub_801B7D8(a0); +} diff --git a/sym_ewram.txt b/sym_ewram.txt index 660c7558d..0cc9b7744 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -46,8 +46,7 @@ gUnknown_02022C68: @ 2022C68 gUnknown_02022C6C: @ 2022C6C .space 0x4 -gUnknown_02022C70: @ 2022C70 - .space 0x4 + .include "src/mevent2.o" gUnknown_02022C74: @ 2022C74 .space 0x4