From b60611c38e904dac5c83f76fc2fbb880baaf0d33 Mon Sep 17 00:00:00 2001 From: Marcus Huderle Date: Tue, 26 Feb 2019 11:17:41 -0600 Subject: [PATCH] Finish decompiling easy_chat.c code --- asm/easy_chat.s | 1179 ------------------------------------------- include/easy_chat.h | 3 +- include/global.h | 3 +- ld_script.txt | 2 +- src/easy_chat.c | 464 ++++++++++++++++- 5 files changed, 447 insertions(+), 1204 deletions(-) delete mode 100644 asm/easy_chat.s diff --git a/asm/easy_chat.s b/asm/easy_chat.s deleted file mode 100644 index 2051e67e1..000000000 --- a/asm/easy_chat.s +++ /dev/null @@ -1,1179 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - thumb_func_start sub_811F01C -sub_811F01C: @ 811F01C - push {r4-r6,lr} - bl sub_811EFF0 - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0x21 - bne _0811F048 - b _0811F082 -_0811F02C: - adds r0, r5, 0 - bl sub_811EFC0 - ldr r0, =0x000001ff - ands r4, r0 - movs r1, 0xA0 - lsls r1, 6 - adds r0, r1, 0 - orrs r4, r0 - adds r0, r4, 0 - b _0811F084 - .pool -_0811F048: - bl Random - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x21 - subs r1, r4 - bl __modsi3 - lsls r0, 16 - lsrs r6, r0, 16 - movs r4, 0 -_0811F05E: - lsls r0, r4, 24 - lsrs r5, r0, 24 - adds r0, r5, 0 - bl sub_811EF98 - lsls r0, 24 - cmp r0, 0 - bne _0811F078 - cmp r6, 0 - beq _0811F02C - subs r0, r6, 0x1 - lsls r0, 16 - lsrs r6, r0, 16 -_0811F078: - adds r0, r4, 0x1 - lsls r0, 16 - lsrs r4, r0, 16 - cmp r4, 0x20 - bls _0811F05E -_0811F082: - ldr r0, =0x0000ffff -_0811F084: - pop {r4-r6} - pop {r1} - bx r1 - .pool - thumb_func_end sub_811F01C - - thumb_func_start sub_811F090 -sub_811F090: @ 811F090 - push {r4,r5,lr} - bl sub_811EFF0 - lsls r0, 24 - lsrs r5, r0, 24 - cmp r5, 0 - bne _0811F0B4 - b _0811F0EA -_0811F0A0: - ldr r0, =0x000001ff - ands r4, r0 - movs r1, 0xA0 - lsls r1, 6 - adds r0, r1, 0 - orrs r4, r0 - adds r0, r4, 0 - b _0811F0EC - .pool -_0811F0B4: - bl Random - lsls r0, 16 - lsrs r0, 16 - adds r1, r5, 0 - bl __umodsi3 - lsls r0, 16 - lsrs r5, r0, 16 - movs r4, 0 -_0811F0C8: - lsls r0, r4, 24 - lsrs r0, 24 - bl sub_811EF98 - lsls r0, 24 - cmp r0, 0 - beq _0811F0E0 - cmp r5, 0 - beq _0811F0A0 - subs r0, r5, 0x1 - lsls r0, 16 - lsrs r5, r0, 16 -_0811F0E0: - adds r0, r4, 0x1 - lsls r0, 16 - lsrs r4, r0, 16 - cmp r4, 0x20 - bls _0811F0C8 -_0811F0EA: - ldr r0, =0x0000ffff -_0811F0EC: - pop {r4,r5} - pop {r1} - bx r1 - .pool - thumb_func_end sub_811F090 - - thumb_func_start sub_811F0F8 -sub_811F0F8: @ 811F0F8 - push {lr} - bl IsNationalPokedexEnabled - lsls r0, 24 - lsrs r0, 24 - pop {r1} - bx r1 - thumb_func_end sub_811F0F8 - - thumb_func_start sub_811F108 -sub_811F108: @ 811F108 - push {r4-r7,lr} - movs r0, 0 - bl EasyChat_GetNumWordsInGroup - lsls r0, 16 - lsrs r4, r0, 16 - cmp r4, 0 - bne _0811F128 - b _0811F172 -_0811F11A: - ldrh r1, [r5] - ldr r0, =0x000001ff - ands r0, r1 - b _0811F174 - .pool -_0811F128: - bl Random - lsls r0, 16 - lsrs r0, 16 - adds r1, r4, 0 - bl __umodsi3 - lsls r0, 16 - lsrs r4, r0, 16 - ldr r0, =gEasyChatGroups - ldr r5, [r0] - ldrh r7, [r0, 0x4] - movs r6, 0 - cmp r6, r7 - bcs _0811F172 -_0811F146: - ldrh r0, [r5] - bl SpeciesToNationalPokedexNum - lsls r0, 16 - lsrs r0, 16 - movs r1, 0 - bl GetSetPokedexFlag - lsls r0, 24 - cmp r0, 0 - beq _0811F166 - cmp r4, 0 - beq _0811F11A - subs r0, r4, 0x1 - lsls r0, 16 - lsrs r4, r0, 16 -_0811F166: - adds r5, 0x2 - adds r0, r6, 0x1 - lsls r0, 16 - lsrs r6, r0, 16 - cmp r6, r7 - bcc _0811F146 -_0811F172: - ldr r0, =0x0000ffff -_0811F174: - pop {r4-r7} - pop {r1} - bx r1 - .pool - thumb_func_end sub_811F108 - - thumb_func_start InitEasyChatPhrases -InitEasyChatPhrases: @ 811F184 - push {r4-r7,lr} - movs r2, 0 - ldr r5, =gSaveBlock1Ptr - ldr r4, =0x00002bb0 - ldr r3, =gUnknown_0859E62C -_0811F18E: - ldr r1, [r5] - lsls r0, r2, 1 - adds r1, r4 - adds r1, r0 - adds r0, r3 - ldrh r0, [r0] - strh r0, [r1] - adds r0, r2, 0x1 - lsls r0, 16 - lsrs r2, r0, 16 - cmp r2, 0x3 - bls _0811F18E - movs r2, 0 - ldr r5, =gSaveBlock1Ptr - ldr r4, =0x00002bbc - ldr r3, =gUnknown_0859E634 -_0811F1AE: - ldr r1, [r5] - lsls r0, r2, 1 - adds r1, r4 - adds r1, r0 - adds r0, r3 - ldrh r0, [r0] - strh r0, [r1] - adds r0, r2, 0x1 - lsls r0, 16 - lsrs r2, r0, 16 - cmp r2, 0x5 - bls _0811F1AE - movs r2, 0 - ldr r5, =gSaveBlock1Ptr - ldr r4, =0x00002bc8 - ldr r3, =gUnknown_0859E640 -_0811F1CE: - ldr r1, [r5] - lsls r0, r2, 1 - adds r1, r4 - adds r1, r0 - adds r0, r3 - ldrh r0, [r0] - strh r0, [r1] - adds r0, r2, 0x1 - lsls r0, 16 - lsrs r2, r0, 16 - cmp r2, 0x5 - bls _0811F1CE - movs r2, 0 - ldr r5, =gSaveBlock1Ptr - ldr r4, =0x00002bd4 - ldr r3, =gUnknown_0859E64C -_0811F1EE: - ldr r1, [r5] - lsls r0, r2, 1 - adds r1, r4 - adds r1, r0 - adds r0, r3 - ldrh r0, [r0] - strh r0, [r1] - adds r0, r2, 0x1 - lsls r0, 16 - lsrs r2, r0, 16 - cmp r2, 0x5 - bls _0811F1EE - movs r2, 0 - ldr r7, =gSaveBlock1Ptr - ldr r6, =0x00002be0 - ldr r0, =0x0000ffff - adds r5, r0, 0 -_0811F210: - movs r3, 0 - lsls r0, r2, 3 - adds r0, r2 - lsls r4, r0, 2 -_0811F218: - ldr r1, [r7] - lsls r0, r3, 1 - adds r0, r4 - adds r1, r6 - adds r1, r0 - ldrh r0, [r1] - orrs r0, r5 - strh r0, [r1] - adds r0, r3, 0x1 - lsls r0, 16 - lsrs r3, r0, 16 - cmp r3, 0x8 - bls _0811F218 - adds r0, r2, 0x1 - lsls r0, 16 - lsrs r2, r0, 16 - cmp r2, 0xF - bls _0811F210 - movs r2, 0 - ldr r4, =gSaveBlock1Ptr - ldr r3, =0x00002e20 - movs r1, 0 -_0811F244: - ldr r0, [r4] - adds r0, r3 - adds r0, r2 - strb r1, [r0] - adds r0, r2, 0x1 - lsls r0, 16 - lsrs r2, r0, 16 - cmp r2, 0x3F - bls _0811F244 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end InitEasyChatPhrases - - thumb_func_start sub_811F28C -sub_811F28C: @ 811F28C - push {r4,lr} - ldr r4, =gUnknown_0203A120 - ldr r0, =0x00003ba4 - bl Alloc - str r0, [r4] - cmp r0, 0 - beq _0811F2B0 - bl sub_811F2D4 - bl sub_811F46C - movs r0, 0x1 - b _0811F2B2 - .pool -_0811F2B0: - movs r0, 0 -_0811F2B2: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_811F28C - - thumb_func_start sub_811F2B8 -sub_811F2B8: @ 811F2B8 - push {r4,lr} - ldr r4, =gUnknown_0203A120 - ldr r0, [r4] - cmp r0, 0 - beq _0811F2CA - bl Free - movs r0, 0 - str r0, [r4] -_0811F2CA: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_811F2B8 - - thumb_func_start sub_811F2D4 -sub_811F2D4: @ 811F2D4 - push {r4,r5,lr} - ldr r4, =gUnknown_0203A120 - ldr r0, [r4] - movs r5, 0 - strh r5, [r0] - movs r0, 0 - bl GetNationalPokedexCount - lsls r0, 16 - cmp r0, 0 - beq _0811F2FC - ldr r0, [r4] - ldrh r1, [r0] - adds r2, r1, 0x1 - strh r2, [r0] - lsls r1, 16 - lsrs r1, 15 - adds r0, 0x2 - adds r0, r1 - strh r5, [r0] -_0811F2FC: - movs r3, 0x1 -_0811F2FE: - ldr r0, [r4] - ldrh r2, [r0] - adds r1, r2, 0x1 - strh r1, [r0] - lsls r2, 16 - lsrs r2, 15 - adds r0, 0x2 - adds r0, r2 - strh r3, [r0] - adds r3, 0x1 - cmp r3, 0x10 - ble _0811F2FE - ldr r0, =0x00000864 @ = FLAG_SYS_GAME_CLEAR - bl FlagGet - lsls r0, 24 - cmp r0, 0 - beq _0811F358 - ldr r0, =gUnknown_0203A120 - ldr r2, [r0] - ldrh r0, [r2] - adds r1, r0, 0x1 - strh r1, [r2] - lsls r0, 16 - lsrs r0, 15 - adds r3, r2, 0x2 - adds r0, r3, r0 - movs r1, 0x11 - strh r1, [r0] - ldrh r0, [r2] - adds r1, r0, 0x1 - strh r1, [r2] - lsls r0, 16 - lsrs r0, 15 - adds r0, r3, r0 - movs r1, 0x12 - strh r1, [r0] - ldrh r0, [r2] - adds r1, r0, 0x1 - strh r1, [r2] - lsls r0, 16 - lsrs r0, 15 - adds r3, r0 - movs r0, 0x13 - strh r0, [r3] -_0811F358: - ldr r0, =0x00000866 - bl FlagGet - lsls r0, 24 - cmp r0, 0 - beq _0811F37A - ldr r0, =gUnknown_0203A120 - ldr r0, [r0] - ldrh r1, [r0] - adds r2, r1, 0x1 - strh r2, [r0] - lsls r1, 16 - lsrs r1, 15 - adds r0, 0x2 - adds r0, r1 - movs r1, 0x14 - strh r1, [r0] -_0811F37A: - bl IsNationalPokedexEnabled - cmp r0, 0 - beq _0811F398 - ldr r0, =gUnknown_0203A120 - ldr r0, [r0] - ldrh r1, [r0] - adds r2, r1, 0x1 - strh r2, [r0] - lsls r1, 16 - lsrs r1, 15 - adds r0, 0x2 - adds r0, r1 - movs r1, 0x15 - strh r1, [r0] -_0811F398: - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_811F2D4 - - thumb_func_start sub_811F3AC -sub_811F3AC: @ 811F3AC - ldr r0, =gUnknown_0203A120 - ldr r0, [r0] - ldrb r0, [r0] - bx lr - .pool - thumb_func_end sub_811F3AC - - thumb_func_start sub_811F3B8 -sub_811F3B8: @ 811F3B8 - push {lr} - lsls r0, 24 - lsrs r2, r0, 24 - ldr r0, =gUnknown_0203A120 - ldr r1, [r0] - ldrh r0, [r1] - cmp r2, r0 - bcs _0811F3D8 - lsls r0, r2, 1 - adds r1, 0x2 - adds r1, r0 - ldrb r0, [r1] - b _0811F3DA - .pool -_0811F3D8: - movs r0, 0x16 -_0811F3DA: - pop {r1} - bx r1 - thumb_func_end sub_811F3B8 - - thumb_func_start sub_811F3E0 -sub_811F3E0: @ 811F3E0 - push {r4,r5,lr} - adds r4, r0, 0 - lsls r1, 24 - lsls r2, 16 - lsrs r5, r2, 16 - ldr r0, =gEasyChatGroupNamePointers - lsrs r1, 22 - adds r1, r0 - ldr r1, [r1] - adds r0, r4, 0 - bl StringCopy - adds r1, r0, 0 - subs r4, r1, r4 - lsls r4, 16 - lsrs r0, r4, 16 - cmp r0, r5 - bcs _0811F414 - movs r2, 0 -_0811F406: - strb r2, [r1] - adds r1, 0x1 - adds r0, 0x1 - lsls r0, 16 - lsrs r0, 16 - cmp r0, r5 - bcc _0811F406 -_0811F414: - movs r0, 0xFF - strb r0, [r1] - adds r0, r1, 0 - pop {r4,r5} - pop {r1} - bx r1 - .pool - thumb_func_end sub_811F3E0 - - thumb_func_start sub_811F424 -sub_811F424: @ 811F424 - lsls r0, 24 - ldr r1, =gEasyChatGroupNamePointers - lsrs r0, 22 - adds r0, r1 - ldr r0, [r0] - bx lr - .pool - thumb_func_end sub_811F424 - - thumb_func_start CopyEasyChatWordPadded -@ char *CopyEasyChatWordPadded(char *dest, u16 groupIdWordIdPair, u16 minLength) -CopyEasyChatWordPadded: @ 811F434 - push {r4,r5,lr} - adds r4, r0, 0 - lsls r1, 16 - lsrs r1, 16 - lsls r2, 16 - lsrs r5, r2, 16 - bl CopyEasyChatWord - adds r1, r0, 0 - subs r4, r1, r4 - lsls r4, 16 - lsrs r0, r4, 16 - cmp r0, r5 - bcs _0811F460 - movs r2, 0 -_0811F452: - strb r2, [r1] - adds r1, 0x1 - adds r0, 0x1 - lsls r0, 16 - lsrs r0, 16 - cmp r0, r5 - bcc _0811F452 -_0811F460: - movs r0, 0xFF - strb r0, [r1] - adds r0, r1, 0 - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end CopyEasyChatWordPadded - - thumb_func_start sub_811F46C -sub_811F46C: @ 811F46C - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x10 - movs r3, 0 -_0811F47A: - ldr r2, =gEasyChatWordsByLetterPointers - lsls r1, r3, 3 - adds r0, r2, 0x4 - adds r0, r1, r0 - ldr r0, [r0] - str r0, [sp] - adds r1, r2 - ldr r7, [r1] - ldr r0, =gUnknown_0203A120 - ldr r1, [r0] - lsls r2, r3, 1 - adds r1, 0x2E - adds r1, r2 - movs r0, 0 - strh r0, [r1] - mov r10, r0 - movs r1, 0 - str r2, [sp, 0x4] - adds r0, r3, 0x1 - str r0, [sp, 0x8] - ldr r2, [sp] - cmp r1, r2 - bge _0811F530 -_0811F4A8: - ldrh r0, [r7] - ldr r2, =0x0000ffff - cmp r0, r2 - bne _0811F4FC - adds r7, 0x2 - ldrh r4, [r7] - adds r7, 0x2 - adds r0, r1, 0x1 - adds r1, r0, r4 - b _0811F4FE - .pool -_0811F4C8: - ldr r0, =gUnknown_0203A120 - ldr r2, [r0] - mov r0, r10 - lsls r1, r0, 1 - lsls r0, r3, 4 - adds r0, r3 - lsls r0, 3 - subs r0, r3 - lsls r0, 2 - adds r1, r0 - adds r0, r2, 0 - adds r0, 0x64 - adds r0, r1 - ldrh r1, [r5] - strh r1, [r0] - movs r0, 0x1 - add r10, r0 - adds r2, 0x2E - ldr r0, [sp, 0x4] - adds r2, r0 - ldrh r0, [r2] - adds r0, 0x1 - strh r0, [r2] - b _0811F526 - .pool -_0811F4FC: - movs r4, 0x1 -_0811F4FE: - movs r6, 0 - adds r1, 0x1 - mov r9, r1 - lsls r2, r4, 1 - mov r8, r2 - cmp r6, r4 - bge _0811F526 - adds r5, r7, 0 -_0811F50E: - ldrh r0, [r5] - str r3, [sp, 0xC] - bl sub_811F860 - lsls r0, 24 - ldr r3, [sp, 0xC] - cmp r0, 0 - bne _0811F4C8 - adds r5, 0x2 - adds r6, 0x1 - cmp r6, r4 - blt _0811F50E -_0811F526: - add r7, r8 - mov r1, r9 - ldr r0, [sp] - cmp r1, r0 - blt _0811F4A8 -_0811F530: - ldr r3, [sp, 0x8] - cmp r3, 0x1A - ble _0811F47A - add sp, 0x10 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_811F46C - - thumb_func_start sub_811F548 -sub_811F548: @ 811F548 - push {lr} - lsls r1, 16 - lsrs r1, 16 - cmp r0, 0 - bne _0811F55A - adds r0, r1, 0 - bl sub_811F5C4 - b _0811F560 -_0811F55A: - adds r0, r1, 0 - bl sub_811F6B8 -_0811F560: - ldr r1, =gUnknown_0203A120 - ldr r1, [r1] - ldr r2, =0x00003ba0 - adds r1, r2 - strh r0, [r1] - pop {r0} - bx r0 - .pool - thumb_func_end sub_811F548 - - thumb_func_start sub_811F578 -sub_811F578: @ 811F578 - push {lr} - lsls r0, 16 - lsrs r2, r0, 16 - ldr r0, =gUnknown_0203A120 - ldr r1, [r0] - ldr r3, =0x00003ba0 - adds r0, r1, r3 - ldrh r0, [r0] - cmp r2, r0 - bcs _0811F5A4 - lsls r0, r2, 1 - ldr r2, =0x00003984 - adds r1, r2 - adds r1, r0 - ldrh r0, [r1] - b _0811F5A6 - .pool -_0811F5A4: - ldr r0, =0x0000ffff -_0811F5A6: - pop {r1} - bx r1 - .pool - thumb_func_end sub_811F578 - - thumb_func_start sub_811F5B0 -sub_811F5B0: @ 811F5B0 - ldr r0, =gUnknown_0203A120 - ldr r0, [r0] - ldr r1, =0x00003ba0 - adds r0, r1 - ldrh r0, [r0] - bx lr - .pool - thumb_func_end sub_811F5B0 - - thumb_func_start sub_811F5C4 -sub_811F5C4: @ 811F5C4 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - lsls r0, 16 - lsrs r2, r0, 16 - ldr r1, =gEasyChatGroups - lsls r0, r2, 3 - adds r0, r1 - ldrh r3, [r0, 0x4] - mov r8, r3 - cmp r2, 0 - beq _0811F5EC - cmp r2, 0x15 - beq _0811F5EC - cmp r2, 0x12 - beq _0811F5EC - cmp r2, 0x13 - bne _0811F64C -_0811F5EC: - lsls r0, r2, 3 - adds r0, r1 - ldr r1, [r0] - movs r7, 0 - movs r5, 0 - cmp r5, r8 - bcs _0811F698 - movs r0, 0x7F - ands r0, r2 - lsls r0, 9 - mov r9, r0 - adds r4, r1, 0 - lsls r6, r2, 24 -_0811F606: - ldrh r0, [r4] - lsrs r1, r6, 24 - bl sub_811F764 - lsls r0, 24 - cmp r0, 0 - beq _0811F630 - ldr r0, =gUnknown_0203A120 - ldr r2, [r0] - lsls r0, r5, 1 - ldr r1, =0x00003984 - adds r2, r1 - adds r2, r0 - ldrh r0, [r4] - ldr r3, =0x000001ff - adds r1, r3, 0 - ands r0, r1 - mov r1, r9 - orrs r0, r1 - strh r0, [r2] - adds r5, 0x1 -_0811F630: - adds r4, 0x2 - adds r7, 0x1 - cmp r7, r8 - bcc _0811F606 - b _0811F698 - .pool -_0811F64C: - ldr r1, [r0] - movs r7, 0 - movs r5, 0 - cmp r5, r8 - bcs _0811F698 - movs r0, 0x7F - ands r0, r2 - lsls r0, 9 - mov r10, r0 - adds r6, r1, 0 - lsls r2, 24 - mov r9, r2 -_0811F664: - ldrh r4, [r6, 0x4] - adds r0, r4, 0 - mov r2, r9 - lsrs r1, r2, 24 - bl sub_811F764 - lsls r0, 24 - cmp r0, 0 - beq _0811F690 - ldr r0, =gUnknown_0203A120 - ldr r1, [r0] - lsls r0, r5, 1 - ldr r3, =0x00003984 - adds r1, r3 - adds r1, r0 - ldr r2, =0x000001ff - adds r0, r2, 0 - ands r4, r0 - mov r3, r10 - orrs r4, r3 - strh r4, [r1] - adds r5, 0x1 -_0811F690: - adds r6, 0xC - adds r7, 0x1 - cmp r7, r8 - bcc _0811F664 -_0811F698: - lsls r0, r5, 16 - lsrs r0, 16 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - .pool - thumb_func_end sub_811F5C4 - - thumb_func_start sub_811F6B8 -sub_811F6B8: @ 811F6B8 - push {r4-r7,lr} - mov r7, r8 - push {r7} - lsls r0, 16 - lsrs r1, r0, 16 - movs r4, 0 - movs r6, 0 - ldr r3, =gUnknown_0203A120 - ldr r0, [r3] - lsls r5, r1, 1 - adds r0, 0x2E - adds r0, r5 - ldrh r0, [r0] - cmp r6, r0 - bcs _0811F718 - mov r8, r3 - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 3 - subs r0, r1 - lsls r7, r0, 2 - ldr r0, =0x00003984 - mov r12, r0 -_0811F6E6: - mov r0, r8 - ldr r3, [r0] - adds r1, r6, 0 - adds r0, r1, 0x1 - lsls r0, 16 - lsrs r6, r0, 16 - lsls r1, 1 - mov r0, r12 - adds r2, r3, r0 - adds r2, r1 - lsls r1, r4, 1 - adds r1, r7 - adds r0, r3, 0 - adds r0, 0x64 - adds r0, r1 - ldrh r0, [r0] - strh r0, [r2] - adds r0, r4, 0x1 - lsls r0, 16 - lsrs r4, r0, 16 - adds r3, 0x2E - adds r3, r5 - ldrh r3, [r3] - cmp r4, r3 - bcc _0811F6E6 -_0811F718: - adds r0, r6, 0 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r1} - bx r1 - .pool - thumb_func_end sub_811F6B8 - - thumb_func_start sub_811F72C -sub_811F72C: @ 811F72C - push {r4,lr} - lsls r0, 24 - lsrs r3, r0, 24 - movs r2, 0 - ldr r0, =gUnknown_0203A120 - ldr r0, [r0] - ldrh r1, [r0] - cmp r2, r1 - bge _0811F75C - adds r4, r3, 0 - adds r3, r1, 0 - adds r1, r0, 0x2 -_0811F744: - ldrh r0, [r1] - cmp r0, r4 - bne _0811F754 - movs r0, 0x1 - b _0811F75E - .pool -_0811F754: - adds r1, 0x2 - adds r2, 0x1 - cmp r2, r3 - blt _0811F744 -_0811F75C: - movs r0, 0 -_0811F75E: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_811F72C - - thumb_func_start sub_811F764 -sub_811F764: @ 811F764 - push {r4,lr} - lsls r0, 16 - lsrs r4, r0, 16 - lsls r1, 24 - lsrs r2, r1, 24 - cmp r2, 0x15 - bhi _0811F81A - lsls r0, r2, 2 - ldr r1, =_0811F780 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_0811F780: - .4byte _0811F7D8 - .4byte _0811F81A - .4byte _0811F81A - .4byte _0811F81A - .4byte _0811F81A - .4byte _0811F81A - .4byte _0811F81A - .4byte _0811F81A - .4byte _0811F81A - .4byte _0811F81A - .4byte _0811F81A - .4byte _0811F81A - .4byte _0811F81A - .4byte _0811F81A - .4byte _0811F81A - .4byte _0811F81A - .4byte _0811F81A - .4byte _0811F81A - .4byte _0811F808 - .4byte _0811F808 - .4byte _0811F80C - .4byte _0811F7EE -_0811F7D8: - adds r0, r4, 0 - bl SpeciesToNationalPokedexNum - lsls r0, 16 - lsrs r0, 16 - movs r1, 0 - bl GetSetPokedexFlag - lsls r0, 24 - lsrs r0, 24 - b _0811F82C -_0811F7EE: - adds r0, r4, 0 - bl sub_811F838 - cmp r0, 0 - beq _0811F808 - adds r0, r4, 0 - bl SpeciesToNationalPokedexNum - lsls r0, 16 - lsrs r0, 16 - movs r1, 0 - bl GetSetPokedexFlag -_0811F808: - movs r0, 0x1 - b _0811F82C -_0811F80C: - lsls r0, r4, 24 - lsrs r0, 24 - bl sub_811EF98 - lsls r0, 24 - lsrs r0, 24 - b _0811F82C -_0811F81A: - ldr r1, =gEasyChatGroups - lsls r0, r2, 3 - adds r0, r1 - ldr r1, [r0] - lsls r0, r4, 1 - adds r0, r4 - lsls r0, 2 - adds r0, r1 - ldrb r0, [r0, 0x8] -_0811F82C: - pop {r4} - pop {r1} - bx r1 - .pool - thumb_func_end sub_811F764 - - thumb_func_start sub_811F838 -sub_811F838: @ 811F838 - push {lr} - lsls r0, 16 - lsrs r3, r0, 16 - movs r2, 0 - ldr r1, =gUnknown_0859E658 -_0811F842: - ldrh r0, [r1] - cmp r0, r3 - bne _0811F850 - movs r0, 0x1 - b _0811F85A - .pool -_0811F850: - adds r1, 0x2 - adds r2, 0x1 - cmp r2, 0 - beq _0811F842 - movs r0, 0 -_0811F85A: - pop {r1} - bx r1 - thumb_func_end sub_811F838 - - thumb_func_start sub_811F860 -sub_811F860: @ 811F860 - push {r4,r5,lr} - lsls r0, 16 - lsrs r5, r0, 25 - lsls r0, 7 - lsrs r4, r0, 23 - adds r0, r5, 0 - bl sub_811F72C - lsls r0, 24 - cmp r0, 0 - beq _0811F884 - adds r0, r4, 0 - adds r1, r5, 0 - bl sub_811F764 - lsls r0, 24 - lsrs r0, 24 - b _0811F886 -_0811F884: - movs r0, 0 -_0811F886: - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end sub_811F860 - - thumb_func_start InitializeEasyChatWordArray -InitializeEasyChatWordArray: @ 811F88C - push {lr} - adds r2, r0, 0 - lsls r1, 16 - ldr r0, =0xffff0000 - adds r1, r0 - lsrs r0, r1, 16 - ldr r1, =0x0000ffff - cmp r0, r1 - beq _0811F8AE - adds r3, r1, 0 -_0811F8A0: - strh r3, [r2] - adds r2, 0x2 - subs r0, 0x1 - lsls r0, 16 - lsrs r0, 16 - cmp r0, r1 - bne _0811F8A0 -_0811F8AE: - pop {r0} - bx r0 - .pool - thumb_func_end InitializeEasyChatWordArray - -@void sub_811F8BC() { -@ s16* v; -@ s16* ptr; -@ v = GetSaveBlock1Field3564(); -@ for (ptr = v + 3; ptr >= v; ptr--) { -@ *ptr = -1; -@ } -@} - thumb_func_start sub_811F8BC -sub_811F8BC: @ 811F8BC - push {lr} - bl GetSaveBlock1Field3564 - ldr r1, =0x0000ffff - adds r2, r1, 0 - adds r1, r0, 0x6 -_0811F8C8: - strh r2, [r1] - subs r1, 0x2 - cmp r1, r0 - bge _0811F8C8 - pop {r0} - bx r0 - .pool - thumb_func_end sub_811F8BC - - thumb_func_start sub_811F8D8 -sub_811F8D8: @ 811F8D8 - push {r4,r5,lr} - asrs r4, r0, 9 - movs r1, 0x7F - ldr r5, =0x000001ff - ands r5, r0 - ands r4, r1 - adds r0, r4, 0 - bl sub_811EA28 - lsls r0, 24 - cmp r0, 0 - beq _0811F904 - adds r0, r5, 0 - adds r1, r4, 0 - bl sub_811F764 - lsls r0, 24 - lsrs r0, 24 - b _0811F906 - .pool -_0811F904: - movs r0, 0 -_0811F906: - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end sub_811F8D8 - - .align 2, 0 @ Don't pad with nop. diff --git a/include/easy_chat.h b/include/easy_chat.h index c55fca81b..b3639af21 100644 --- a/include/easy_chat.h +++ b/include/easy_chat.h @@ -6,7 +6,7 @@ void InitEasyChatPhrases(void); void easy_chat_input_maybe(void); u8 * CopyEasyChatWord(u8 *dest, u16 word); -bool32 sub_811F8D8(u16 word); +bool32 sub_811F8D8(int word); void InitializeEasyChatWordArray(u16 *words, u16 length); u8 *ConvertEasyChatWordsToString(u8 *dest, const u16 *src, u16 columns, u16 rows); bool8 ECWord_CheckIfOutsideOfValidRange(u16 word); @@ -15,5 +15,6 @@ u16 sub_811F01C(void); u16 EasyChat_GetNumWordsInGroup(u8); u16 sub_811EE90(u16); void sub_811A20C(u8 kind, u16 *words, MainCallback callback, u8 sizeParam); +void sub_811F8BC(void); #endif // GUARD_EASYCHAT_H diff --git a/include/global.h b/include/global.h index cc308c3c9..ee0ba6893 100644 --- a/include/global.h +++ b/include/global.h @@ -875,8 +875,7 @@ struct SaveBlock1 /*0x2BC8*/ u16 unk2BC8[6]; /*0x2BD4*/ u16 unk2BD4[6]; /*0x2BE0*/ struct MailStruct mail[MAIL_COUNT]; - /*0x2E20*/ u8 additionalPhrases[5]; // bitfield for 33 additional phrases in easy chat system - /*0x2E25*/ u8 unk2E25[3]; // possibly padding? + /*0x2E20*/ u8 additionalPhrases[8]; // bitfield for 33 additional phrases in easy chat system /*0x2E28*/ OldMan oldMan; /*0x2e64*/ struct EasyChatPair easyChatPairs[5]; //Dewford trend [0] and some other stuff /*0x2e90*/ struct ContestWinner contestWinners[13]; // 0 - 5 used in contest hall, 6 - 7 unused?, 8 - 12 museum diff --git a/ld_script.txt b/ld_script.txt index eaf75c3de..107606833 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -178,7 +178,6 @@ SECTIONS { src/battle_intro.o(.text); src/bike.o(.text); src/easy_chat.o(.text); - asm/easy_chat.o(.text); src/mon_markings.o(.text); src/mauville_old_man.o(.text); src/mail.o(.text); @@ -501,6 +500,7 @@ SECTIONS { src/battle_anim_utility_funcs.o(.rodata); src/battle_intro.o(.rodata); src/bike.o(.rodata); + src/easy_chat.o(.rodata); data/easy_chat.o(.rodata); src/mon_markings.o(.rodata); src/mauville_old_man.o(.rodata); diff --git a/src/easy_chat.c b/src/easy_chat.c index 3fdc88823..6a103dd7b 100644 --- a/src/easy_chat.c +++ b/src/easy_chat.c @@ -141,9 +141,26 @@ struct EasyChatGroup u16 numEnabledWords; }; +struct Unk203A120 +{ + u16 unk0; + u16 unk2[EC_NUM_GROUPS]; + u16 unk2E[27]; + u16 unk64[27][270]; + u8 filler3958[0x2C]; + u16 unk3984[0x10E]; + u16 unk3BA0; +}; /*size = 0x3BA4*/ + +struct EasyChatWordsByLetter +{ + const u16 *words; + int numWords; +}; + EWRAM_DATA struct EasyChatScreen *gEasyChatScreen = NULL; EWRAM_DATA struct Unk203A11C *gUnknown_0203A11C = 0; -EWRAM_DATA void *gUnknown_0203A120 = 0; +EWRAM_DATA struct Unk203A120 *gUnknown_0203A120 = 0; static void sub_811A2C0(u8); static void sub_811A278(void); @@ -178,9 +195,9 @@ static bool8 sub_811BFA4(void); static void sub_811C13C(void); static void sub_811C158(u16); static bool8 sub_811C170(void); -bool8 sub_811F28C(void); -void sub_811F2B8(void); -u8 sub_811F3AC(void); +static bool8 sub_811F28C(void); +static void sub_811F2B8(void); +static u8 sub_811F3AC(void); int sub_811BA3C(void); int sub_811B184(void); int sub_811B264(void); @@ -202,13 +219,13 @@ static int sub_811BDB0(void); static int sub_811BD2C(void); int sub_811BCF4(void); static u16 sub_811B8E8(void); -int sub_811F3B8(u8); -void sub_811F548(int, u16); +static u8 sub_811F3B8(u8); +static void sub_811F548(int, u16); static int sub_811B908(void); -u16 sub_811F5B0(void); +static u16 sub_811F5B0(void); static void sub_811B488(u16); u16 sub_811B940(void); -u16 sub_811F578(u16); +static u16 sub_811F578(u16); int sub_811BF88(int); static u16 sub_811B8C8(void); static int sub_811B568(u32); @@ -310,7 +327,7 @@ static void sub_811DD84(void); static void sub_811D6F4(void); static void sub_811D758(void); static void sub_811D794(void); -const u8 *sub_811F424(u8); +static const u8 *GetEasyChatWordGroupName(u8); static void sub_811D864(u8, u8); static void sub_811D950(u8, u8); static void sub_811DADC(u8); @@ -319,9 +336,16 @@ static void sub_811E0EC(s8, s8); static void sub_811E1A4(s8, s8); static void sub_811E2DC(struct Sprite *); static void sub_811E34C(u8, u8); -bool8 sub_811F0F8(void); -u16 sub_811F108(void); -u8 *CopyEasyChatWordPadded(u8 *, u16, u16); +static bool8 sub_811F0F8(void); +static u16 sub_811F108(void); +static void sub_811F2D4(void); +static void sub_811F46C(void); +static u8 *CopyEasyChatWordPadded(u8 *, u16, u16); +static u8 sub_811F860(u16); +static u16 sub_811F5C4(u16); +static u16 sub_811F6B8(u16); +bool8 sub_811F764(u16, u8); +static int sub_811F838(u16); extern const struct { u16 word; @@ -356,6 +380,13 @@ extern const u8 gUnknown_08597D08[]; extern const u8 gUnknown_08597E60[][4]; extern const u8 *const gUnknown_08597E6C[][4]; extern const struct EasyChatGroup gEasyChatGroups[]; +extern const u16 gUnknown_0859E62C[]; +extern const u16 gUnknown_0859E634[]; +extern const u16 gUnknown_0859E640[]; +extern const u16 gUnknown_0859E64C[]; +extern const u8 *const gEasyChatGroupNamePointers[]; +extern const struct EasyChatWordsByLetter gEasyChatWordsByLetterPointers[]; +extern const u16 gUnknown_0859E658[1]; void sub_811A20C(u8 kind, u16 *words, MainCallback callback, u8 sizeParam) { @@ -1248,8 +1279,8 @@ static int sub_811B2B0(void) if (gEasyChatScreen->unk_09 == 0) { - u8 var0 = sub_811F3B8(sub_811B8E8()); - sub_811F548(0, var0); + u8 groupId = sub_811F3B8(sub_811B8E8()); + sub_811F548(0, groupId); } else { @@ -3265,14 +3296,14 @@ static void sub_811D6F4(void) { for (x = 0; x < 2; x++) { - u8 index = sub_811F3B8(i++); - if (index == 22) + u8 groupId = sub_811F3B8(i++); + if (groupId == EC_NUM_GROUPS) { sub_811DDAC(sub_811BBBC(), 0); return; } - sub_811D028(2, 1, sub_811F424(index), x * 84 + 10, y, 0xFF, NULL); + sub_811D028(2, 1, GetEasyChatWordGroupName(groupId), x * 84 + 10, y, 0xFF, NULL); } y += 16; @@ -4077,7 +4108,7 @@ static void sub_811E948(void) PutWindowTilemap(windowId); } -bool8 sub_811EA28(u8 groupId) +static bool8 sub_811EA28(u8 groupId) { switch (groupId) { @@ -4397,10 +4428,10 @@ void sub_811EF6C(void) CopyEasyChatWord(gStringVar2, easyChatWord); } -u8 sub_811EF98(u8 additionalPhraseId) +static bool8 sub_811EF98(u8 additionalPhraseId) { int byteOffset = additionalPhraseId / 8; - int shift = additionalPhraseId & 0x7; + int shift = additionalPhraseId % 8; return (gSaveBlock1Ptr->additionalPhrases[byteOffset] >> shift) & 1; } @@ -4409,7 +4440,7 @@ void sub_811EFC0(u8 additionalPhraseId) if (additionalPhraseId < 33) { int byteOffset = additionalPhraseId / 8; - int shift = additionalPhraseId & 0x7; + int shift = additionalPhraseId % 8; gSaveBlock1Ptr->additionalPhrases[byteOffset] |= 1 << shift; } } @@ -4427,3 +4458,394 @@ u8 sub_811EFF0(void) return numAdditionalPhrasesUnlocked; } + +u16 sub_811F01C(void) +{ + u16 i; + u16 additionalPhraseId; + u8 numAdditionalPhrasesUnlocked = sub_811EFF0(); + if (numAdditionalPhrasesUnlocked == 33) + return 0xFFFF; + + additionalPhraseId = Random() % (33 - numAdditionalPhrasesUnlocked); + for (i = 0; i < 33; i++) + { + if (!sub_811EF98(i)) + { + if (additionalPhraseId) + { + additionalPhraseId--; + } + else + { + sub_811EFC0(i); + return EC_WORD(EC_GROUP_TRENDY_SAYING, i); + } + } + } + + return 0xFFFF; +} + +u16 sub_811F090(void) +{ + u16 i; + u16 additionalPhraseId = sub_811EFF0(); + if (additionalPhraseId == 0) + return 0xFFFF; + + additionalPhraseId = Random() % additionalPhraseId; + for (i = 0; i < 33; i++) + { + if (sub_811EF98(i)) + { + if (additionalPhraseId) + additionalPhraseId--; + else + return EC_WORD(EC_GROUP_TRENDY_SAYING, i); + } + } + + return 0xFFFF; +} + +static bool8 sub_811F0F8(void) +{ + return IsNationalPokedexEnabled(); +} + +static u16 sub_811F108(void) +{ + u16 i; + u16 numWords; + const u16 *species; + u16 index = EasyChat_GetNumWordsInGroup(EC_GROUP_POKEMON); + if (index == 0) + return 0xFFFF; + + index = Random() % index; + species = gEasyChatGroups[EC_GROUP_POKEMON].wordData.valueList; + numWords = gEasyChatGroups[EC_GROUP_POKEMON].numWords; + for (i = 0; i < numWords; i++) + { + u16 dexNum = SpeciesToNationalPokedexNum(*species); + if (GetSetPokedexFlag(dexNum, FLAG_GET_SEEN)) + { + if (index) + index--; + else + return EC_WORD(EC_GROUP_POKEMON, *species); + } + + species++; + } + + return 0xFFFF; +} + +void InitEasyChatPhrases(void) +{ + u16 i, j; + + for (i = 0; i < 4; i++) + gSaveBlock1Ptr->unk2BB0[i] = gUnknown_0859E62C[i]; + + for (i = 0; i < 6; i++) + gSaveBlock1Ptr->unk2BBC[i] = gUnknown_0859E634[i]; + + for (i = 0; i < 6; i++) + gSaveBlock1Ptr->unk2BC8[i] = gUnknown_0859E640[i]; + + for (i = 0; i < 6; i++) + gSaveBlock1Ptr->unk2BD4[i] = gUnknown_0859E64C[i]; + + for (i = 0; i < MAIL_COUNT; i++) + { + for (j = 0; j < MAIL_WORDS_COUNT; j++) + gSaveBlock1Ptr->mail[i].words[j] = 0xFFFF; + } + + // BUG: This is supposed to clear 64 bits, but this loop is clearing 64 bytes. + // However, this bug has no resulting effect on gameplay because only the + // Mauville old man data is corrupted, which is initialized directly after + // this function is called when starting a new game. + for (i = 0; i < 64; i++) + gSaveBlock1Ptr->additionalPhrases[i] = 0; +} + +static bool8 sub_811F28C(void) +{ + gUnknown_0203A120 = Alloc(sizeof(*gUnknown_0203A120)); + if (!gUnknown_0203A120) + return FALSE; + + sub_811F2D4(); + sub_811F46C(); + return TRUE; +} + +static void sub_811F2B8(void) +{ + if (gUnknown_0203A120) + FREE_AND_SET_NULL(gUnknown_0203A120); +} + +static void sub_811F2D4(void) +{ + int i; + + gUnknown_0203A120->unk0 = 0; + if (GetNationalPokedexCount(FLAG_GET_SEEN)) + gUnknown_0203A120->unk2[gUnknown_0203A120->unk0++] = EC_GROUP_POKEMON; + + for (i = EC_GROUP_TRAINER; i <= EC_GROUP_ADJECTIVES; i++) + gUnknown_0203A120->unk2[gUnknown_0203A120->unk0++] = i; + + if (FlagGet(FLAG_SYS_GAME_CLEAR)) + { + gUnknown_0203A120->unk2[gUnknown_0203A120->unk0++] = EC_GROUP_EVENTS; + gUnknown_0203A120->unk2[gUnknown_0203A120->unk0++] = EC_GROUP_MOVE_1; + gUnknown_0203A120->unk2[gUnknown_0203A120->unk0++] = EC_GROUP_MOVE_2; + } + + if (FlagGet(FLAG_SYS_HIPSTER_MEET)) + gUnknown_0203A120->unk2[gUnknown_0203A120->unk0++] = EC_GROUP_TRENDY_SAYING; + + if (IsNationalPokedexEnabled()) + gUnknown_0203A120->unk2[gUnknown_0203A120->unk0++] = EC_GROUP_POKEMON_2; +} + +static u8 sub_811F3AC(void) +{ + return gUnknown_0203A120->unk0; +} + +static u8 sub_811F3B8(u8 index) +{ + if (index >= gUnknown_0203A120->unk0) + return EC_NUM_GROUPS; + else + return gUnknown_0203A120->unk2[index]; +} + +u8 *unref_sub_811F3E0(u8 *dest, u8 groupId, u16 totalChars) +{ + u16 i; + u8 *str = StringCopy(dest, gEasyChatGroupNamePointers[groupId]); + for (i = str - dest; i < totalChars; i++) + { + *str = CHAR_SPACE; + str++; + } + + *str = EOS; + return str; +} + +static const u8 *GetEasyChatWordGroupName(u8 groupId) +{ + return gEasyChatGroupNamePointers[groupId]; +} + +static u8 *CopyEasyChatWordPadded(u8 *dest, u16 easyChatWord, u16 totalChars) +{ + u16 i; + u8 *str = CopyEasyChatWord(dest, easyChatWord); + for (i = str - dest; i < totalChars; i++) + { + *str = CHAR_SPACE; + str++; + } + + *str = EOS; + return str; +} + +static void sub_811F46C(void) +{ + int i, j, k; + int numWords; + const u16 *words; + u16 numToProcess; + int index; + + for (i = 0; i < 27; i++) + { + numWords = gEasyChatWordsByLetterPointers[i].numWords; + words = gEasyChatWordsByLetterPointers[i].words; + gUnknown_0203A120->unk2E[i] = 0; + index = 0; + for (j = 0; j < numWords; j++) + { + if (*words == 0xFFFF) + { + words++; + numToProcess = *words; + words++; + j += 1 + numToProcess; + } + else + { + numToProcess = 1; + } + + for (k = 0; k < numToProcess; k++) + { + if (sub_811F860(words[k])) + { + gUnknown_0203A120->unk64[i][index++] = words[k]; + gUnknown_0203A120->unk2E[i]++; + break; + } + } + + words += numToProcess; + } + } +} + +static void sub_811F548(int arg0, u16 groupId) +{ + if (!arg0) + gUnknown_0203A120->unk3BA0 = sub_811F5C4(groupId); + else + gUnknown_0203A120->unk3BA0 = sub_811F6B8(groupId); +} + +static u16 sub_811F578(u16 arg0) +{ + if (arg0 >= gUnknown_0203A120->unk3BA0) + return 0xFFFF; + else + return gUnknown_0203A120->unk3984[arg0]; +} + +static u16 sub_811F5B0(void) +{ + return gUnknown_0203A120->unk3BA0; +} + +static u16 sub_811F5C4(u16 groupId) +{ + u32 i; + int totalWords; + const u16 *list; + const struct EasyChatWordInfo *wordInfo; + u16 numWords = gEasyChatGroups[groupId].numWords; + + if (groupId == EC_GROUP_POKEMON || groupId == EC_GROUP_POKEMON_2 + || groupId == EC_GROUP_MOVE_1 || groupId == EC_GROUP_MOVE_2) + { + list = gEasyChatGroups[groupId].wordData.valueList; + for (i = 0, totalWords = 0; i < numWords; i++) + { + if (sub_811F764(list[i], groupId)) + gUnknown_0203A120->unk3984[totalWords++] = EC_WORD(groupId, list[i]); + } + + return totalWords; + } + else + { + wordInfo = gEasyChatGroups[groupId].wordData.words; + for (i = 0, totalWords = 0; i < numWords; i++) + { + u16 alphabeticalOrder = wordInfo[i].alphabeticalOrder; + if (sub_811F764(alphabeticalOrder, groupId)) + gUnknown_0203A120->unk3984[totalWords++] = EC_WORD(groupId, alphabeticalOrder); + } + + return totalWords; + } +} + +static u16 sub_811F6B8(u16 alphabeticalGroup) +{ + u16 i; + u16 totalWords; + + for (i = 0, totalWords = 0; i < gUnknown_0203A120->unk2E[alphabeticalGroup]; i++) + gUnknown_0203A120->unk3984[totalWords++] = gUnknown_0203A120->unk64[alphabeticalGroup][i]; + + return totalWords; +} + +static bool8 sub_811F72C(u8 arg0) +{ + int i; + for (i = 0; i < gUnknown_0203A120->unk0; i++) + { + if (gUnknown_0203A120->unk2[i] == arg0) + return TRUE; + } + + return FALSE; +} + +bool8 sub_811F764(u16 wordIndex, u8 groupId) +{ + switch (groupId) + { + case EC_GROUP_POKEMON: + return GetSetPokedexFlag(SpeciesToNationalPokedexNum(wordIndex), FLAG_GET_SEEN); + case EC_GROUP_POKEMON_2: + if (sub_811F838(wordIndex)) + GetSetPokedexFlag(SpeciesToNationalPokedexNum(wordIndex), FLAG_GET_SEEN); + return TRUE; + case EC_GROUP_MOVE_1: + case EC_GROUP_MOVE_2: + return TRUE; + case EC_GROUP_TRENDY_SAYING: + return sub_811EF98(wordIndex); + default: + return gEasyChatGroups[groupId].wordData.words[wordIndex].enabled; + } +} + +static int sub_811F838(u16 species) +{ + u32 i; + for (i = 0; i < ARRAY_COUNT(gUnknown_0859E658); i++) + { + if (gUnknown_0859E658[i] == species) + return TRUE; + } + + return FALSE; +} + +static u8 sub_811F860(u16 easyChatWord) +{ + u8 groupId = EC_GROUP(easyChatWord); + u32 index = EC_INDEX(easyChatWord); + if (!sub_811F72C(groupId)) + return FALSE; + else + return sub_811F764(index, groupId); +} + +void InitializeEasyChatWordArray(u16 *words, u16 length) +{ + u16 i; + for (i = length - 1; i != 0xFFFF; i--) + *(words++) = 0xFFFF; +} + +void sub_811F8BC(void) +{ + int i; + u16 *words = GetSaveBlock1Field3564(); + for (i = 0; i < 4; i++) + words[i] = 0xFFFF; +} + +bool32 sub_811F8D8(int easyChatWord) +{ + int groupId = EC_GROUP(easyChatWord); + int mask = 0x7F; + int index = EC_INDEX(easyChatWord); + if (!sub_811EA28(groupId & mask)) + return FALSE; + else + return sub_811F764(index, groupId & mask); +}