Merge remote-tracking branch 'Egg/decompile_mail_data'

This commit is contained in:
Diegoisawesome 2017-12-17 22:51:40 -06:00
commit 6a674e1e83
22 changed files with 473 additions and 856 deletions

View File

@ -113,8 +113,8 @@ _081DB4D4:
bx r1
thumb_func_end sub_81DB494
thumb_func_start sub_81DB4DC
sub_81DB4DC: @ 81DB4DC
thumb_func_start PadNameString
PadNameString: @ 81DB4DC
push {r4,r5,lr}
adds r4, r0, 0
lsls r1, 24
@ -156,7 +156,7 @@ _081DB51E:
pop {r4,r5}
pop {r0}
bx r0
thumb_func_end sub_81DB4DC
thumb_func_end PadNameString
thumb_func_start sub_81DB52C
sub_81DB52C: @ 81DB52C

View File

@ -3360,7 +3360,7 @@ _081AC8D4:
bl memcpy
ldr r0, =gSpecialVar_ItemId
ldrh r0, [r0]
bl itemid_is_mail
bl ItemIsMail
lsls r0, 24
lsrs r0, 24
cmp r0, 0x1
@ -4664,7 +4664,7 @@ item_menu_type_b: @ 81AD4B4
lsrs r4, r0, 24
ldr r5, =gSpecialVar_ItemId
ldrh r0, [r5]
bl itemid_is_mail
bl ItemIsMail
lsls r0, 24
lsrs r0, 24
cmp r0, 0x1

View File

@ -266,7 +266,7 @@ sub_80FD254: @ 80FD254
ldr r1, =bag_menu_mail_related
mov r0, sp
movs r2, 0
bl sub_8121478
bl ReadMail
add sp, 0x24
pop {r0}
bx r0

View File

@ -1,589 +0,0 @@
.include "asm/macros.inc"
.include "constants/constants.inc"
.syntax unified
.text
thumb_func_start ClearMailData
ClearMailData: @ 80D436C
push {r4,r5,lr}
movs r4, 0
ldr r5, =gSaveBlock1Ptr
_080D4372:
lsls r1, r4, 3
adds r1, r4
lsls r1, 2
ldr r0, =0x00002be0
adds r1, r0
ldr r0, [r5]
adds r0, r1
bl ClearMailStruct
adds r0, r4, 0x1
lsls r0, 24
lsrs r4, r0, 24
cmp r4, 0xF
bls _080D4372
pop {r4,r5}
pop {r0}
bx r0
.pool
thumb_func_end ClearMailData
thumb_func_start ClearMailStruct
ClearMailStruct: @ 80D439C
push {r4-r6,lr}
adds r3, r0, 0
ldr r0, =0x0000ffff
adds r4, r0, 0
adds r1, r3, 0
movs r2, 0x8
_080D43A8:
ldrh r0, [r1]
orrs r0, r4
strh r0, [r1]
adds r1, 0x2
subs r2, 0x1
cmp r2, 0
bge _080D43A8
movs r2, 0
adds r6, r3, 0
adds r6, 0x1A
adds r4, r3, 0
adds r4, 0x12
movs r5, 0xFF
_080D43C2:
adds r1, r4, r2
ldrb r0, [r1]
orrs r0, r5
strb r0, [r1]
adds r2, 0x1
cmp r2, 0x7
ble _080D43C2
adds r1, r6, 0
movs r2, 0
adds r0, r1, 0x3
_080D43D6:
strb r2, [r0]
subs r0, 0x1
cmp r0, r1
bge _080D43D6
movs r1, 0
movs r0, 0x1
strh r0, [r3, 0x1E]
strh r1, [r3, 0x20]
pop {r4-r6}
pop {r0}
bx r0
.pool
thumb_func_end ClearMailStruct
thumb_func_start MonHasMail
MonHasMail: @ 80D43F0
push {r4,lr}
adds r4, r0, 0
movs r1, 0xC
bl GetMonData
lsls r0, 16
lsrs r0, 16
bl itemid_is_mail
lsls r0, 24
cmp r0, 0
beq _080D4418
adds r0, r4, 0
movs r1, 0x40
bl GetMonData
cmp r0, 0xFF
beq _080D4418
movs r0, 0x1
b _080D441A
_080D4418:
movs r0, 0
_080D441A:
pop {r4}
pop {r1}
bx r1
thumb_func_end MonHasMail
thumb_func_start sub_80D4420
sub_80D4420: @ 80D4420
push {r4-r7,lr}
mov r7, r10
mov r6, r9
mov r5, r8
push {r5-r7}
sub sp, 0xC
mov r8, r0
lsls r1, 16
lsrs r0, r1, 16
str r0, [sp, 0x8]
mov r0, sp
movs r2, 0
ldrb r3, [r0, 0x8]
strb r3, [r0]
lsrs r1, 24
strb r1, [r0, 0x1]
add r3, sp, 0x4
strb r2, [r3]
ldr r4, =gSaveBlock1Ptr
mov r10, r4
mov r9, r3
adds r4, r3, 0
_080D444C:
mov r1, r10
ldr r0, [r1]
ldrb r2, [r4]
lsls r1, r2, 3
adds r1, r2
lsls r1, 2
adds r0, r1
movs r1, 0xB0
lsls r1, 6
adds r0, r1
ldrh r0, [r0]
cmp r0, 0
beq _080D4468
b _080D45A8
_080D4468:
movs r4, 0
ldr r2, =gSaveBlock2Ptr
mov r12, r2
ldr r7, =gSaveBlock1Ptr
add r5, sp, 0x4
ldr r3, =0x0000ffff
adds r6, r3, 0
_080D4476:
ldr r2, [r7]
lsls r3, r4, 1
ldrb r1, [r5]
lsls r0, r1, 3
adds r0, r1
lsls r0, 2
adds r3, r0
ldr r0, =0x00002be0
adds r2, r0
adds r2, r3
ldrh r0, [r2]
orrs r0, r6
strh r0, [r2]
adds r0, r4, 0x1
lsls r0, 24
lsrs r4, r0, 24
cmp r4, 0x8
bls _080D4476
movs r4, 0
ldr r5, =gSaveBlock1Ptr
add r3, sp, 0x4
_080D44A0:
ldr r2, [r5]
ldrb r1, [r3]
lsls r0, r1, 3
adds r0, r1
lsls r0, 2
adds r0, r4, r0
ldr r1, =0x00002bf2
adds r2, r1
adds r2, r0
mov r1, r12
ldr r0, [r1]
adds r0, r4
ldrb r0, [r0]
strb r0, [r2]
adds r0, r4, 0x1
lsls r0, 24
lsrs r4, r0, 24
cmp r4, 0x6
bls _080D44A0
mov r3, r10
ldr r2, [r3]
mov r0, r9
ldrb r1, [r0]
lsls r0, r1, 3
adds r0, r1
lsls r0, 2
adds r0, r4, r0
ldr r1, =0x00002bf2
adds r2, r1
adds r2, r0
movs r0, 0xFF
strb r0, [r2]
mov r2, r9
ldrb r1, [r2]
lsls r0, r1, 3
adds r0, r1
lsls r0, 2
ldr r1, [r3]
adds r0, r1
ldr r3, =0x00002bf2
adds r0, r3
movs r1, 0
bl sub_81DB4DC
movs r4, 0
ldr r6, =gSaveBlock1Ptr
add r3, sp, 0x4
ldr r5, =gSaveBlock2Ptr
_080D4500:
ldr r2, [r6]
ldrb r1, [r3]
lsls r0, r1, 3
adds r0, r1
lsls r0, 2
adds r0, r4, r0
ldr r1, =0x00002bfa
adds r2, r1
adds r2, r0
ldr r0, [r5]
adds r0, 0xA
adds r0, r4
ldrb r0, [r0]
strb r0, [r2]
adds r0, r4, 0x1
lsls r0, 24
lsrs r4, r0, 24
cmp r4, 0x3
bls _080D4500
mov r0, r8
movs r1, 0xB
bl GetBoxMonData
adds r4, r0, 0
lsls r4, 16
lsrs r4, 16
mov r0, r8
movs r1, 0
bl GetBoxMonData
adds r1, r0, 0
adds r0, r4, 0
bl sub_80D45C8
mov r2, r10
ldr r3, [r2]
mov r4, r9
ldrb r2, [r4]
lsls r1, r2, 3
adds r1, r2
lsls r1, 2
adds r1, r3, r1
ldr r2, =0x00002bfe
adds r1, r2
strh r0, [r1]
ldrb r1, [r4]
lsls r0, r1, 3
adds r0, r1
lsls r0, 2
adds r3, r0
movs r4, 0xB0
lsls r4, 6
adds r3, r4
mov r0, sp
ldrh r0, [r0, 0x8]
strh r0, [r3]
mov r0, r8
movs r1, 0x40
mov r2, r9
bl SetMonData
mov r0, r8
movs r1, 0xC
mov r2, sp
bl SetMonData
mov r1, r9
ldrb r0, [r1]
b _080D45B6
.pool
_080D45A8:
adds r0, r2, 0x1
strb r0, [r3]
ldrb r0, [r4]
cmp r0, 0x5
bhi _080D45B4
b _080D444C
_080D45B4:
movs r0, 0xFF
_080D45B6:
add sp, 0xC
pop {r3-r5}
mov r8, r3
mov r9, r4
mov r10, r5
pop {r4-r7}
pop {r1}
bx r1
thumb_func_end sub_80D4420
thumb_func_start sub_80D45C8
sub_80D45C8: @ 80D45C8
push {lr}
lsls r0, 16
lsrs r0, 16
cmp r0, 0xC9
bne _080D45E0
adds r0, r1, 0
bl mon_icon_personality_to_unown_id
lsls r0, 16
ldr r1, =0x75300000
adds r0, r1
lsrs r0, 16
_080D45E0:
pop {r1}
bx r1
.pool
thumb_func_end sub_80D45C8
thumb_func_start sub_80D45E8
sub_80D45E8: @ 80D45E8
push {lr}
lsls r0, 16
lsrs r3, r0, 16
ldr r0, =0xffff8ad0
adds r2, r3, r0
lsls r0, r2, 16
lsrs r0, 16
cmp r0, 0x1B
bhi _080D4604
movs r0, 0xC9
strh r2, [r1]
b _080D4606
.pool
_080D4604:
adds r0, r3, 0
_080D4606:
pop {r1}
bx r1
thumb_func_end sub_80D45E8
thumb_func_start GiveMailToMon2
GiveMailToMon2: @ 80D460C
push {r4-r7,lr}
sub sp, 0x8
adds r6, r0, 0
adds r7, r1, 0
ldrh r5, [r7, 0x20]
adds r1, r5, 0
bl sub_80D4420
add r4, sp, 0x4
strb r0, [r4]
ldrb r2, [r4]
cmp r2, 0xFF
beq _080D4670
ldr r0, =gSaveBlock1Ptr
ldr r1, [r0]
lsls r0, r2, 3
adds r0, r2
lsls r0, 2
adds r1, r0
ldr r0, =0x00002be0
adds r1, r0
adds r0, r7, 0
ldm r0!, {r2,r3,r7}
stm r1!, {r2,r3,r7}
ldm r0!, {r2,r3,r7}
stm r1!, {r2,r3,r7}
ldm r0!, {r2,r3,r7}
stm r1!, {r2,r3,r7}
adds r0, r6, 0
movs r1, 0x40
adds r2, r4, 0
bl SetMonData
mov r0, sp
strb r5, [r0]
mov r1, sp
lsrs r0, r5, 8
strb r0, [r1, 0x1]
adds r0, r6, 0
movs r1, 0xC
mov r2, sp
bl SetMonData
ldrb r0, [r4]
b _080D4672
.pool
_080D4670:
movs r0, 0xFF
_080D4672:
add sp, 0x8
pop {r4-r7}
pop {r1}
bx r1
thumb_func_end GiveMailToMon2
thumb_func_start sub_80D467C
sub_80D467C: @ 80D467C
movs r0, 0
bx lr
thumb_func_end sub_80D467C
thumb_func_start TakeMailFromMon
TakeMailFromMon: @ 80D4680
push {r4,lr}
sub sp, 0x8
adds r4, r0, 0
bl MonHasMail
lsls r0, 24
cmp r0, 0
beq _080D46D2
adds r0, r4, 0
movs r1, 0x40
bl GetMonData
add r2, sp, 0x4
strb r0, [r2]
ldr r0, =gSaveBlock1Ptr
ldr r3, [r0]
ldrb r1, [r2]
lsls r0, r1, 3
adds r0, r1
lsls r0, 2
adds r3, r0
movs r0, 0xB0
lsls r0, 6
adds r3, r0
movs r1, 0
movs r0, 0
strh r0, [r3]
movs r0, 0xFF
strb r0, [r2]
mov r0, sp
strb r1, [r0]
strb r1, [r0, 0x1]
adds r0, r4, 0
movs r1, 0x40
bl SetMonData
adds r0, r4, 0
movs r1, 0xC
mov r2, sp
bl SetMonData
_080D46D2:
add sp, 0x8
pop {r4}
pop {r0}
bx r0
.pool
thumb_func_end TakeMailFromMon
thumb_func_start sub_80D46E0
sub_80D46E0: @ 80D46E0
lsls r0, 24
lsrs r0, 24
ldr r1, =gSaveBlock1Ptr
ldr r2, [r1]
lsls r1, r0, 3
adds r1, r0
lsls r1, 2
adds r2, r1
movs r0, 0xB0
lsls r0, 6
adds r2, r0
movs r0, 0
strh r0, [r2]
bx lr
.pool
thumb_func_end sub_80D46E0
thumb_func_start sub_80D4700
sub_80D4700: @ 80D4700
push {r4-r7,lr}
mov r7, r9
mov r6, r8
push {r6,r7}
sub sp, 0xC
adds r5, r0, 0
mov r0, sp
movs r1, 0
strb r1, [r0]
strb r1, [r0, 0x1]
add r1, sp, 0x4
movs r0, 0xFF
strb r0, [r1]
movs r7, 0x6
mov r9, r1
ldr r0, =gSaveBlock1Ptr
mov r8, r0
ldr r3, =0x00002be0
_080D4724:
mov r1, r8
ldr r0, [r1]
lsls r1, r7, 3
adds r1, r7
lsls r1, 2
adds r4, r0, r1
movs r2, 0xB0
lsls r2, 6
adds r0, r4, r2
ldrh r6, [r0]
cmp r6, 0
bne _080D47A0
adds r4, r3
adds r0, r5, 0
movs r1, 0x40
str r3, [sp, 0x8]
bl GetMonData
mov r1, r8
ldr r2, [r1]
lsls r1, r0, 3
adds r1, r0
lsls r1, 2
adds r1, r2
ldr r3, [sp, 0x8]
adds r1, r3
ldm r1!, {r0,r2,r3}
stm r4!, {r0,r2,r3}
ldm r1!, {r0,r2,r3}
stm r4!, {r0,r2,r3}
ldm r1!, {r0,r2,r3}
stm r4!, {r0,r2,r3}
adds r0, r5, 0
movs r1, 0x40
bl GetMonData
mov r1, r8
ldr r2, [r1]
lsls r1, r0, 3
adds r1, r0
lsls r1, 2
adds r2, r1
movs r3, 0xB0
lsls r3, 6
adds r2, r3
strh r6, [r2]
adds r0, r5, 0
movs r1, 0x40
mov r2, r9
bl SetMonData
adds r0, r5, 0
movs r1, 0xC
mov r2, sp
bl SetMonData
adds r0, r7, 0
b _080D47AC
.pool
_080D47A0:
adds r0, r7, 0x1
lsls r0, 24
lsrs r7, r0, 24
cmp r7, 0xF
bls _080D4724
movs r0, 0xFF
_080D47AC:
add sp, 0xC
pop {r3,r4}
mov r8, r3
mov r9, r4
pop {r4-r7}
pop {r1}
bx r1
thumb_func_end sub_80D4700
thumb_func_start itemid_is_mail
itemid_is_mail: @ 80D47BC
push {lr}
lsls r0, 16
lsrs r0, 16
cmp r0, 0x84
bgt _080D47CE
cmp r0, 0x79
blt _080D47CE
movs r0, 0x1
b _080D47D0
_080D47CE:
movs r0, 0
_080D47D0:
pop {r1}
bx r1
thumb_func_end itemid_is_mail
.align 2, 0 @ Don't pad with nop.

View File

@ -512,7 +512,7 @@ itemid_80BF6D8_mail_related: @ 812217C
bne _081221A4
_08122192:
adds r0, r4, 0
bl itemid_is_mail
bl ItemIsMail
lsls r0, 24
lsrs r0, 24
cmp r0, 0x1

View File

@ -721,7 +721,7 @@ _08153D86:
bl GetMonData
lsls r0, 16
lsrs r0, 16
bl itemid_is_mail
bl ItemIsMail
lsls r0, 24
cmp r0, 0
beq _08153DA4

View File

@ -3402,14 +3402,14 @@ sub_81B1DB8: @ 81B1DB8
lsrs r4, r5, 16
adds r7, r4, 0
adds r0, r4, 0
bl itemid_is_mail
bl ItemIsMail
lsls r0, 24
lsrs r0, 24
cmp r0, 0x1
bne _081B1DE2
adds r0, r6, 0
adds r1, r4, 0
bl sub_80D4420
bl GiveMailToMon
lsls r0, 24
lsrs r0, 24
cmp r0, 0xFF
@ -6216,7 +6216,7 @@ _081B34D2:
bl GetMonData
lsls r0, 16
lsrs r0, 16
bl itemid_is_mail
bl ItemIsMail
lsls r0, 24
cmp r0, 0
beq _081B3508
@ -7791,7 +7791,7 @@ _081B425A:
.pool
_081B4278:
ldrh r0, [r6]
bl itemid_is_mail
bl ItemIsMail
lsls r0, 24
cmp r0, 0
beq _081B42A4
@ -7999,7 +7999,7 @@ _081B4402:
.pool
_081B4458:
ldrh r0, [r5]
bl itemid_is_mail
bl ItemIsMail
lsls r0, 24
cmp r0, 0
beq _081B4498
@ -8681,7 +8681,7 @@ sub_81B4A98: @ 81B4A98
adds r0, r1
ldr r1, =sub_81B4AE0
movs r2, 0x1
bl sub_8121478
bl ReadMail
pop {r0}
bx r0
.pool
@ -8801,7 +8801,7 @@ _081B4BC6:
muls r0, r1
ldr r1, =gPlayerParty
adds r0, r1
bl sub_80D4700
bl TakeMailFromMon2
lsls r0, 24
lsrs r0, 24
cmp r0, 0xFF
@ -10735,7 +10735,7 @@ sub_81B5CB0: @ 81B5CB0
b _081B5D24
.pool
_081B5CD8:
bl itemid_is_mail
bl ItemIsMail
lsls r0, 24
cmp r0, 0
beq _081B5CFC
@ -10821,7 +10821,7 @@ _081B5D68:
adds r0, r7, r5
ldrb r4, [r0]
adds r0, r1, 0
bl itemid_is_mail
bl ItemIsMail
adds r1, r0, 0
lsls r1, 24
lsrs r1, 24
@ -10853,7 +10853,7 @@ _081B5DAC:
adds r0, r5, r7
ldrb r4, [r0, 0x6]
adds r0, r1, 0
bl itemid_is_mail
bl ItemIsMail
adds r1, r0, 0
lsls r1, 24
lsrs r1, 24
@ -14728,7 +14728,7 @@ sub_81B7FAC: @ 81B7FAC
.pool
_081B7FF8:
ldrh r0, [r5]
bl itemid_is_mail
bl ItemIsMail
lsls r0, 24
cmp r0, 0
beq _081B800C
@ -14770,7 +14770,7 @@ sub_81B8044: @ 81B8044
lsrs r4, r0, 24
ldr r5, =gUnknown_0203CEC8
ldrh r0, [r5, 0xC]
bl itemid_is_mail
bl ItemIsMail
lsls r0, 24
cmp r0, 0
beq _081B807C
@ -15093,7 +15093,7 @@ _081B82FA:
.pool
_081B8338:
adds r0, r4, 0
bl itemid_is_mail
bl ItemIsMail
lsls r0, 24
cmp r0, 0
beq _081B835C

View File

@ -1263,7 +1263,7 @@ sub_816B8A4: @ 816B8A4
adds r0, r1
ldr r1, =sub_816B900
movs r2, 0x1
bl sub_8121478
bl ReadMail
adds r0, r4, 0
bl DestroyTask
_0816B8E6:

View File

@ -156,7 +156,7 @@ mon_icon_convert_unown_species_id: @ 80D2E08
cmp r2, 0xC9
bne _080D2E32
adds r0, r1, 0
bl mon_icon_personality_to_unown_id
bl GetUnownLetterByPersonality
lsls r0, 16
lsrs r0, 16
cmp r0, 0
@ -186,8 +186,8 @@ _080D2E40:
bx r1
thumb_func_end mon_icon_convert_unown_species_id
thumb_func_start mon_icon_personality_to_unown_id
mon_icon_personality_to_unown_id: @ 80D2E48
thumb_func_start GetUnownLetterByPersonality
GetUnownLetterByPersonality: @ 80D2E48
push {lr}
adds r2, r0, 0
cmp r2, 0
@ -219,7 +219,7 @@ _080D2E7E:
_080D2E80:
pop {r1}
bx r1
thumb_func_end mon_icon_personality_to_unown_id
thumb_func_end GetUnownLetterByPersonality
thumb_func_start sub_80D2E84
sub_80D2E84: @ 80D2E84
@ -229,7 +229,7 @@ sub_80D2E84: @ 80D2E84
lsrs r4, r0, 16
adds r0, r4, 0
mov r1, sp
bl sub_80D45E8
bl MailSpeciesToSpecies
lsls r0, 16
lsrs r0, 16
cmp r0, 0xC9

View File

@ -2201,7 +2201,7 @@ _080C83CC:
ldr r1, =0x00000ce6
adds r0, r1
ldrh r0, [r0]
bl itemid_is_mail
bl ItemIsMail
lsls r0, 24
cmp r0, 0
beq _080C83F4
@ -2304,7 +2304,7 @@ _080C84C8:
ldr r1, =0x00000ce6
adds r0, r1
ldrh r0, [r0]
bl itemid_is_mail
bl ItemIsMail
lsls r0, 24
cmp r0, 0
beq _080C84F8
@ -2874,7 +2874,7 @@ _080C8A0C:
ldr r2, =0x00000ce6
adds r0, r2
ldrh r0, [r0]
bl itemid_is_mail
bl ItemIsMail
lsls r0, 24
cmp r0, 0
bne _080C8A8C
@ -2913,7 +2913,7 @@ _080C8A7C:
ldr r2, =0x00000ce6
adds r0, r1, r2
ldrh r0, [r0]
bl itemid_is_mail
bl ItemIsMail
lsls r0, 24
cmp r0, 0
beq _080C8A98
@ -3661,7 +3661,7 @@ _080C914E:
ldr r1, =0x00000ce6
adds r0, r1
ldrh r0, [r0]
bl itemid_is_mail
bl ItemIsMail
lsls r0, 24
cmp r0, 0
bne _080C9168
@ -3943,7 +3943,7 @@ _080C93E4:
ldr r1, =0x00000ce6
adds r0, r1
ldrh r0, [r0]
bl itemid_is_mail
bl ItemIsMail
lsls r0, 24
cmp r0, 0
bne _080C9404
@ -16168,7 +16168,7 @@ sub_80CFB44: @ 80CFB44
.pool
_080CFB8C:
ldrh r0, [r1]
bl itemid_is_mail
bl ItemIsMail
lsls r0, 24
cmp r0, 0
bne _080CFBA4
@ -16197,7 +16197,7 @@ _080CFBAC:
.pool
_080CFBCC:
ldrh r0, [r1]
bl itemid_is_mail
bl ItemIsMail
lsls r0, 24
lsrs r0, 24
cmp r0, 0x1

View File

@ -4207,7 +4207,7 @@ sub_81C61E0: @ 81C61E0
cmp r0, 0x3
beq _081C620C
ldrh r0, [r4]
bl itemid_is_mail
bl ItemIsMail
lsls r0, 24
lsrs r0, 24
cmp r0, 0x1
@ -4673,7 +4673,7 @@ sub_81C6648: @ 81C6648
bl sub_81C61A8
ldr r5, =gSpecialVar_ItemId
ldrh r0, [r5]
bl itemid_is_mail
bl ItemIsMail
lsls r0, 24
lsrs r0, 24
cmp r0, 0x1

View File

@ -3650,7 +3650,7 @@ _080E8A78:
beq _080E8A90
mov r0, r8
movs r1, 0xFC
bl sub_81DB4DC
bl PadNameString
_080E8A90:
ldrb r1, [r7]
lsrs r1, 4

View File

@ -13369,7 +13369,7 @@ sub_807E7E8: @ 807E7E8
ldrh r0, [r5, 0x28]
cmp r0, 0
beq _0807E960
bl itemid_is_mail
bl ItemIsMail
lsls r0, 24
cmp r0, 0
beq _0807E954
@ -13442,7 +13442,7 @@ _0807E98E:
bl StringCopy
adds r0, r4, 0
movs r1, 0
bl sub_81DB4DC
bl PadNameString
ldr r1, [r6, 0x18]
lsrs r0, r1, 24
strb r0, [r5, 0x1A]

View File

@ -379,10 +379,12 @@ struct EasyChatPair
u16 words[2];
}; /*size = 0x8*/
#define MAIL_WORDS_COUNT 9
struct MailStruct
{
/*0x00*/ u16 words[9];
/*0x12*/ u8 playerName[8];
/*0x00*/ u16 words[MAIL_WORDS_COUNT];
/*0x12*/ u8 playerName[PLAYER_NAME_LENGTH];
/*0x1A*/ u8 trainerId[4];
/*0x1E*/ u16 species;
/*0x20*/ u16 itemId;

View File

@ -14,7 +14,7 @@ s32 sub_81DB3D8(const struct MenuAction *str, u8* arg1, s32 arg2);
// sub_81DB41C
// CopyMonCategoryText
// sub_81DB494
// sub_81DB4DC
void PadNameString(u8 *dst, u8 padWith);
// sub_81DB554
// sub_81DB5AC
u32 sub_81DB604(const u8 *);

View File

@ -14,10 +14,20 @@
|| itemId == ITEM_FAB_MAIL \
|| itemId == ITEM_RETRO_MAIL))
// mail.h
void ReadMail(struct MailStruct *mail, void (*callback)(void), bool8 flag);
bool8 MonHasMail(struct Pokemon *mon);
void TakeMailFromMon(struct Pokemon *mon);
u8 GiveMailToMon2(struct Pokemon *mon, struct MailStruct *mail);
// mail_data.h
void ClearMailData(void);
void ClearMailStruct(struct MailStruct *mail);
bool8 MonHasMail(struct Pokemon *mon);
u8 GiveMailToMon(struct Pokemon *mon, u16 itemId);
u16 SpeciesToMailSpecies(u16 species, u32 personality);
u16 MailSpeciesToSpecies(u16 mailSpecies, u16 *buffer);
u8 GiveMailToMon2(struct Pokemon *mon, struct MailStruct *mail);
void TakeMailFromMon(struct Pokemon *mon);
void ClearMailItemId(u8 mailId);
u8 TakeMailFromMon2(struct Pokemon *mon);
bool8 ItemIsMail(u16 itemId);
#endif // GUARD_MAIL_H

View File

@ -1,12 +0,0 @@
#ifndef GUARD_MAIL_DATA_H
#define GUARD_MAIL_DATA_H
// Exported type declarations
// Exported RAM declarations
// Exported ROM declarations
u16 sub_80D45E8(u16, u16 *);
#endif //GUARD_MAIL_DATA_H

View File

@ -3,6 +3,7 @@
const u8 *GetMonIconPtr(u16 speciesId, u32 personality, u32 frameNo);
const u16 *GetValidMonIconPalettePtr(u16 speciesId);
u16 GetUnownLetterByPersonality(u32 personality);
u16 sub_80D2E84(u16 speciesId);
void sub_80D2F68(u16 iconId);
u8 sub_80D2D78(u16 iconId, void callback(struct Sprite *), u16 x, u16 y, u16 a4, u8 a5);

View File

@ -134,7 +134,7 @@ SECTIONS {
asm/pokemon_icon.o(.text);
asm/script_movement.o(.text);
asm/fldeff_cut.o(.text);
asm/mail_data.o(.text);
src/mail_data.o(.text);
asm/map_name_popup.o(.text);
asm/item_menu_icons.o(.text);
asm/battle_anim_80D51AC.o(.text);

View File

@ -185,7 +185,7 @@ extern void sub_80356D0(void);
extern void GetFrontierTrainerName(u8* dst, u16 trainerId); // battle tower
extern void sub_8166188(void); // battle tower, sets link battle mons level but why?
extern void sub_8165B88(u8* dst, u16 trainerId); // battle tower, gets language
extern void sub_81DB4DC(u8* dst, u8 arg2); //
extern void PadNameString(u8* dst, u8 arg2); //
extern void sub_81B9150(void);
extern void sub_800AC34(void);
extern void sub_80B3AF8(u8 taskId); // cable club
@ -1140,7 +1140,7 @@ static void sub_80379F8(u8 arrayIdPlus)
gUnknown_02022FF8[i].gender = GetMonGender(&gPlayerParty[arrayIdPlus + i]);
StripExtCtrlCodes(gUnknown_02022FF8[i].nickname);
if (GetMonData(&gPlayerParty[arrayIdPlus + i], MON_DATA_LANGUAGE) != LANGUAGE_JAPANESE)
sub_81DB4DC(gUnknown_02022FF8[i].nickname, 0);
PadNameString(gUnknown_02022FF8[i].nickname, CHAR_SPACE);
}
memcpy(gUnknown_02023058, gUnknown_02022FF8, sizeof(gUnknown_02022FF8));
}

View File

@ -1,4 +1,5 @@
#include "global.h"
#include "mail.h"
#include "constants/items.h"
#include "main.h"
#include "overworld.h"
@ -18,117 +19,6 @@
#include "constants/species.h"
#include "malloc.h"
#include "easy_chat.h"
#include "mail_data.h"
#include "mail.h"
// Static type declarations
struct UnkMailStruct
{
u32 numEasyChatWords:2;
u32 xOffset:6;
u32 lineHeight:8;
};
struct MailLayout
{
u8 numSubStructs;
u8 signatureYPos;
u8 signatureWidth;
u8 wordsXPos;
u8 wordsYPos;
const struct UnkMailStruct *var8;
};
struct MailGraphics
{
const u16 *palette;
const u8 *tiles;
const u8 *tileMap;
u16 var0C;
u16 var0E;
u16 color10;
u16 color12;
};
// Static RAM declarations
static EWRAM_DATA struct
{
/*0x0000*/ u8 strbuf[8][64];
/*0x0200*/ u8 playerName[12];
/*0x020C*/ MainCallback callback;
/*0x0210*/ MainCallback callback2;
/*0x0214*/ struct MailStruct *mail;
/*0x0218*/ bool8 flag;
/*0x0219*/ u8 signatureWidth;
/*0x021a*/ u8 mailType;
/*0x021b*/ u8 animsActive;
/*0x021c*/ u8 monIconSprite;
/*0x021d*/ u8 language;
/*0x021e*/ bool8 playerIsSender;
/*0x0220*/ void (*parserSingle)(u8 *dest, u16 word);
/*0x0224*/ void (*parserMultiple)(u8 *dest, const u16 *src, u16 length1, u16 length2);
/*0x0228*/ const struct MailLayout *layout;
/*0x022c*/ u8 bg1TilemapBuffer[0x1000];
/*0x122c*/ u8 bg2TilemapBuffer[0x1000];
} *gUnknown_0203A134 = NULL;
// Static ROM declarations
void sub_81219F0(void);
void sub_8121A1C(void);
void sub_8121B1C(void);
void sub_8121C50(void);
void sub_8121C64(void);
void sub_8121C98(void);
void sub_8121CC0(void);
void sub_8121D00(void);
// .rodata
const struct BgTemplate gUnknown_0859F290[] = {
{
.bg = 0,
.charBaseIndex = 2,
.mapBaseIndex = 31,
.priority = 0
}, {
.bg = 1,
.charBaseIndex = 0,
.mapBaseIndex = 30,
.priority = 1
}, {
.bg = 2,
.charBaseIndex = 0,
.mapBaseIndex = 29,
.priority = 2
}
};
const struct WindowTemplate gUnknown_0859F29C[] = {
{
.priority = 0,
.tilemapLeft = 2,
.tilemapTop = 3,
.width = 26,
.height = 15,
.paletteNum = 15,
.baseBlock = 1
},
DUMMY_WIN_TEMPLATE
};
const u8 gUnknown_0859F2AC[] = {
0,
10,
11
};
const u16 gUnknown_0859F2B0[][2] = {
{ 0x6ACD, 0x51A5 },
{ 0x45FC, 0x38D4 }
};
extern const u16 gUnknown_08DBE818[];
extern const u16 gUnknown_08DBE838[];
@ -167,7 +57,118 @@ extern const u8 gUnknown_08DC04E8[];
extern const u8 gUnknown_08DBF904[];
extern const u8 gUnknown_08DC0600[];
const struct MailGraphics gUnknown_0859F2B8[] = {
// Static type declarations
struct UnkMailStruct
{
u32 numEasyChatWords:2;
u32 xOffset:6;
u32 lineHeight:8;
};
struct MailLayout
{
u8 numSubStructs;
u8 signatureYPos;
u8 signatureWidth;
u8 wordsXPos;
u8 wordsYPos;
const struct UnkMailStruct *var8;
};
struct MailGraphics
{
const u16 *palette;
const u8 *tiles;
const u8 *tileMap;
u16 var0C;
u16 var0E;
u16 color10;
u16 color12;
};
struct MailRead
{
/*0x0000*/ u8 strbuf[8][64];
/*0x0200*/ u8 playerName[12];
/*0x020C*/ MainCallback callback;
/*0x0210*/ MainCallback callback2;
/*0x0214*/ struct MailStruct *mail;
/*0x0218*/ bool8 flag;
/*0x0219*/ u8 signatureWidth;
/*0x021a*/ u8 mailType;
/*0x021b*/ u8 animsActive;
/*0x021c*/ u8 monIconSprite;
/*0x021d*/ u8 language;
/*0x021e*/ bool8 playerIsSender;
/*0x0220*/ void (*parserSingle)(u8 *dest, u16 word);
/*0x0224*/ void (*parserMultiple)(u8 *dest, const u16 *src, u16 length1, u16 length2);
/*0x0228*/ const struct MailLayout *layout;
/*0x022c*/ u8 bg1TilemapBuffer[0x1000];
/*0x122c*/ u8 bg2TilemapBuffer[0x1000];
};
// Static RAM declarations
static EWRAM_DATA struct MailRead *sMailRead = NULL;
// Static ROM declarations
static void CB2_InitMailRead(void);
static void sub_8121A1C(void);
static void sub_8121B1C(void);
static void VBlankCB_MailRead(void);
static void CB2_MailRead(void);
static void CB2_WaitForPaletteExitOnKeyPress(void);
static void CB2_ExitOnKeyPress(void);
static void CB2_ExitMailReadFreeVars(void);
// .rodata
static const struct BgTemplate sUnknown_0859F290[] = {
{
.bg = 0,
.charBaseIndex = 2,
.mapBaseIndex = 31,
.priority = 0
}, {
.bg = 1,
.charBaseIndex = 0,
.mapBaseIndex = 30,
.priority = 1
}, {
.bg = 2,
.charBaseIndex = 0,
.mapBaseIndex = 29,
.priority = 2
}
};
static const struct WindowTemplate sUnknown_0859F29C[] = {
{
.priority = 0,
.tilemapLeft = 2,
.tilemapTop = 3,
.width = 26,
.height = 15,
.paletteNum = 15,
.baseBlock = 1
},
DUMMY_WIN_TEMPLATE
};
static const u8 sUnknown_0859F2AC[] = {
0,
10,
11
};
static const u16 sUnknown_0859F2B0[][2] = {
{ 0x6ACD, 0x51A5 },
{ 0x45FC, 0x38D4 }
};
static const struct MailGraphics sUnknown_0859F2B8[] = {
{
gUnknown_08DBE818, gUnknown_08DBE998, gUnknown_08DBFBA4, 0x02c0, 0x0000, 0x294a, 0x6739
}, {
@ -195,13 +196,13 @@ const struct MailGraphics gUnknown_0859F2B8[] = {
}
};
const struct UnkMailStruct Unknown_0859F3A8[] = {
static const struct UnkMailStruct Unknown_0859F3A8[] = {
{ .numEasyChatWords = 3, .lineHeight = 16 },
{ .numEasyChatWords = 3, .lineHeight = 16 },
{ .numEasyChatWords = 3, .lineHeight = 16 }
};
const struct MailLayout gUnknown_0859F3B4[] = {
static const struct MailLayout sUnknown_0859F3B4[] = {
{ 0x03, 0x00, 0x00, 0x02, 0x04, Unknown_0859F3A8 },
{ 0x03, 0x00, 0x00, 0x02, 0x04, Unknown_0859F3A8 },
{ 0x03, 0x00, 0x00, 0x02, 0x04, Unknown_0859F3A8 },
@ -216,7 +217,7 @@ const struct MailLayout gUnknown_0859F3B4[] = {
{ 0x03, 0x00, 0x00, 0x02, 0x00, Unknown_0859F3A8 }
};
const struct UnkMailStruct Unknown_0859F444[] = {
static const struct UnkMailStruct Unknown_0859F444[] = {
{ .numEasyChatWords = 2, .lineHeight = 16 },
{ .numEasyChatWords = 2, .lineHeight = 16 },
{ .numEasyChatWords = 2, .lineHeight = 16 },
@ -224,7 +225,7 @@ const struct UnkMailStruct Unknown_0859F444[] = {
{ .numEasyChatWords = 1, .lineHeight = 16 }
};
const struct MailLayout gUnknown_0859F458[] = {
static const struct MailLayout sUnknown_0859F458[] = {
{ 0x05, 0x07, 0x58, 0x0b, 0x1e, Unknown_0859F444 },
{ 0x05, 0x0a, 0x60, 0x09, 0x1e, Unknown_0859F444 },
{ 0x05, 0x0c, 0x68, 0x05, 0x1e, Unknown_0859F444 },
@ -241,23 +242,23 @@ const struct MailLayout gUnknown_0859F458[] = {
// What the heck are these meant to be? Call them u16 for now.
const u16 Unknown_0859F4E8[] = {
static const u16 Unknown_0859F4E8[] = {
0x00, 0x4000, 0x00, 0x00
};
const u16 Unknown_0859F4F0[] = {
static const u16 Unknown_0859F4F0[] = {
0x00, 0x00, -1, 0x00
};
const u16 Unknown_0859F4F8[] = {
static const u16 Unknown_0859F4F8[] = {
0x04, 0x00, -1, 0x00
};
const u16 Unknown_0859F500[] = {
static const u16 Unknown_0859F500[] = {
0x00, 0x40, -1, 0x00
};
const u16 *const gUnknown_0859F508[] = {
static const u16 *const sUnknown_0859F508[] = {
Unknown_0859F4F0,
Unknown_0859F4F8,
Unknown_0859F500
@ -265,60 +266,62 @@ const u16 *const gUnknown_0859F508[] = {
// .text
void sub_8121478(struct MailStruct *mail, MainCallback callback, bool8 flag) {
void ReadMail(struct MailStruct *mail, void (*callback)(void), bool8 flag)
{
u16 buffer[2];
u16 species;
gUnknown_0203A134 = calloc(1, sizeof(*gUnknown_0203A134));
gUnknown_0203A134->language = LANGUAGE_ENGLISH;
gUnknown_0203A134->playerIsSender = TRUE;
gUnknown_0203A134->parserSingle = CopyEasyChatWord;
gUnknown_0203A134->parserMultiple = ConvertEasyChatWordsToString;
if (mail->itemId >= ITEM_ORANGE_MAIL && mail->itemId <= ITEM_RETRO_MAIL) {
gUnknown_0203A134->mailType = mail->itemId - ITEM_ORANGE_MAIL;
sMailRead = calloc(1, sizeof(*sMailRead));
sMailRead->language = LANGUAGE_ENGLISH;
sMailRead->playerIsSender = TRUE;
sMailRead->parserSingle = CopyEasyChatWord;
sMailRead->parserMultiple = ConvertEasyChatWordsToString;
if (IS_ITEM_MAIL(mail->itemId))
{
sMailRead->mailType = mail->itemId - ITEM_ORANGE_MAIL;
}
else
{
gUnknown_0203A134->mailType = 0;
sMailRead->mailType = 0;
flag = FALSE;
}
switch (gUnknown_0203A134->playerIsSender)
switch (sMailRead->playerIsSender)
{
case FALSE:
default:
gUnknown_0203A134->layout = &gUnknown_0859F3B4[gUnknown_0203A134->mailType];
sMailRead->layout = &sUnknown_0859F3B4[sMailRead->mailType];
break;
case TRUE:
gUnknown_0203A134->layout = &gUnknown_0859F458[gUnknown_0203A134->mailType];
sMailRead->layout = &sUnknown_0859F458[sMailRead->mailType];
break;
}
species = sub_80D45E8(mail->species, buffer);
species = MailSpeciesToSpecies(mail->species, buffer);
if (species >= SPECIES_BULBASAUR && species < NUM_SPECIES)
{
switch (gUnknown_0203A134->mailType)
switch (sMailRead->mailType)
{
default:
gUnknown_0203A134->animsActive = 0;
sMailRead->animsActive = 0;
break;
case ITEM_BEAD_MAIL - ITEM_ORANGE_MAIL:
gUnknown_0203A134->animsActive = 1;
sMailRead->animsActive = 1;
break;
case ITEM_DREAM_MAIL - ITEM_ORANGE_MAIL:
gUnknown_0203A134->animsActive = 2;
sMailRead->animsActive = 2;
break;
}
}
else
{
gUnknown_0203A134->animsActive = 0;
sMailRead->animsActive = 0;
}
gUnknown_0203A134->mail = mail;
gUnknown_0203A134->callback = callback;
gUnknown_0203A134->flag = flag;
SetMainCallback2(sub_81219F0);
sMailRead->mail = mail;
sMailRead->callback = callback;
sMailRead->flag = flag;
SetMainCallback2(CB2_InitMailRead);
}
bool8 sub_81215EC(void)
static bool8 MailReadBuildGraphics(void)
{
u16 icon;
@ -352,21 +355,21 @@ bool8 sub_81215EC(void)
SetGpuReg(REG_OFFSET_BG2HOFS, 0x0000);
SetGpuReg(REG_OFFSET_BG3HOFS, 0x0000);
SetGpuReg(REG_OFFSET_BG3VOFS, 0x0000);
SetGpuReg(REG_OFFSET_BLDCNT, 0x0000);
SetGpuReg(REG_OFFSET_BLDCNT, 0x0000);
SetGpuReg(REG_OFFSET_BLDALPHA, 0x0000);
break;
case 6:
ResetBgsAndClearDma3BusyFlags(0);
InitBgsFromTemplates(0, gUnknown_0859F290, 3);
SetBgTilemapBuffer(1, gUnknown_0203A134->bg1TilemapBuffer);
SetBgTilemapBuffer(2, gUnknown_0203A134->bg2TilemapBuffer);
InitBgsFromTemplates(0, sUnknown_0859F290, 3);
SetBgTilemapBuffer(1, sMailRead->bg1TilemapBuffer);
SetBgTilemapBuffer(2, sMailRead->bg2TilemapBuffer);
break;
case 7:
InitWindows(gUnknown_0859F29C);
InitWindows(sUnknown_0859F29C);
DeactivateAllTextPrinters();
break;
case 8:
decompress_and_copy_tile_data_to_vram(1, gUnknown_0859F2B8[gUnknown_0203A134->mailType].tiles, 0, 0, 0);
decompress_and_copy_tile_data_to_vram(1, sUnknown_0859F2B8[sMailRead->mailType].tiles, 0, 0, 0);
break;
case 9:
if (free_temp_tile_data_buffers_if_possible())
@ -377,7 +380,7 @@ bool8 sub_81215EC(void)
case 10:
FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 30, 20);
FillBgTilemapBufferRect_Palette0(2, 1, 0, 0, 30, 20);
CopyToBgTilemapBuffer(1, gUnknown_0859F2B8[gUnknown_0203A134->mailType].tileMap, 0, 0);
CopyToBgTilemapBuffer(1, sUnknown_0859F2B8[sMailRead->mailType].tileMap, 0, 0);
break;
case 11:
CopyBgTilemapBufferToVram(0);
@ -386,24 +389,24 @@ bool8 sub_81215EC(void)
break;
case 12:
LoadPalette(GetOverworldTextboxPalettePtr(), 240, 32);
gPlttBufferUnfaded[250] = gUnknown_0859F2B8[gUnknown_0203A134->mailType].color10;
gPlttBufferFaded[250] = gUnknown_0859F2B8[gUnknown_0203A134->mailType].color10;
gPlttBufferUnfaded[251] = gUnknown_0859F2B8[gUnknown_0203A134->mailType].color12;
gPlttBufferFaded[251] = gUnknown_0859F2B8[gUnknown_0203A134->mailType].color12;
LoadPalette(gUnknown_0859F2B8[gUnknown_0203A134->mailType].palette, 0, 32);
gPlttBufferUnfaded[10] = gUnknown_0859F2B0[gSaveBlock2Ptr->playerGender][0];
gPlttBufferFaded[10] = gUnknown_0859F2B0[gSaveBlock2Ptr->playerGender][0];
gPlttBufferUnfaded[11] = gUnknown_0859F2B0[gSaveBlock2Ptr->playerGender][1];
gPlttBufferFaded[11] = gUnknown_0859F2B0[gSaveBlock2Ptr->playerGender][1];
gPlttBufferUnfaded[250] = sUnknown_0859F2B8[sMailRead->mailType].color10;
gPlttBufferFaded[250] = sUnknown_0859F2B8[sMailRead->mailType].color10;
gPlttBufferUnfaded[251] = sUnknown_0859F2B8[sMailRead->mailType].color12;
gPlttBufferFaded[251] = sUnknown_0859F2B8[sMailRead->mailType].color12;
LoadPalette(sUnknown_0859F2B8[sMailRead->mailType].palette, 0, 32);
gPlttBufferUnfaded[10] = sUnknown_0859F2B0[gSaveBlock2Ptr->playerGender][0];
gPlttBufferFaded[10] = sUnknown_0859F2B0[gSaveBlock2Ptr->playerGender][0];
gPlttBufferUnfaded[11] = sUnknown_0859F2B0[gSaveBlock2Ptr->playerGender][1];
gPlttBufferFaded[11] = sUnknown_0859F2B0[gSaveBlock2Ptr->playerGender][1];
break;
case 13:
if (gUnknown_0203A134->flag)
if (sMailRead->flag)
{
sub_8121A1C();
}
break;
case 14:
if (gUnknown_0203A134->flag)
if (sMailRead->flag)
{
sub_8121B1C();
RunTextPrinters();
@ -416,20 +419,20 @@ bool8 sub_81215EC(void)
}
break;
case 16:
SetVBlankCallback(sub_8121C50);
SetVBlankCallback(VBlankCB_MailRead);
gPaletteFade.bufferTransferDisabled = TRUE;
break;
case 17:
icon = sub_80D2E84(gUnknown_0203A134->mail->species);
switch (gUnknown_0203A134->animsActive)
icon = sub_80D2E84(sMailRead->mail->species);
switch (sMailRead->animsActive)
{
case 1:
sub_80D2F68(icon);
gUnknown_0203A134->monIconSprite = sub_80D2D78(icon, SpriteCallbackDummy, 0x60, 0x80, 0, 0);
sMailRead->monIconSprite = sub_80D2D78(icon, SpriteCallbackDummy, 0x60, 0x80, 0, 0);
break;
case 2:
sub_80D2F68(icon);
gUnknown_0203A134->monIconSprite = sub_80D2D78(icon, SpriteCallbackDummy, 0x28, 0x80, 0, 0);
sMailRead->monIconSprite = sub_80D2D78(icon, SpriteCallbackDummy, 0x28, 0x80, 0, 0);
break;
}
break;
@ -440,53 +443,53 @@ bool8 sub_81215EC(void)
ShowBg(2);
BeginNormalPaletteFade(-1, 0, 16, 0, 0);
gPaletteFade.bufferTransferDisabled = FALSE;
gUnknown_0203A134->callback2 = sub_8121C98;
sMailRead->callback2 = CB2_WaitForPaletteExitOnKeyPress;
return TRUE;
default:
return FALSE;
}
gMain.state ++;
gMain.state++;
return FALSE;
}
void sub_81219F0(void)
static void CB2_InitMailRead(void)
{
do
{
if (sub_81215EC() == TRUE)
if (MailReadBuildGraphics() == TRUE)
{
SetMainCallback2(sub_8121C64);
SetMainCallback2(CB2_MailRead);
break;
}
} while (sub_81221AC() != TRUE);
}
void sub_8121A1C(void)
static void sub_8121A1C(void)
{
u16 i;
u8 total;
u8 *ptr;
total = 0;
for (i = 0; i < gUnknown_0203A134->layout->numSubStructs; i ++)
for (i = 0; i < sMailRead->layout->numSubStructs; i ++)
{
ConvertEasyChatWordsToString(gUnknown_0203A134->strbuf[i], &gUnknown_0203A134->mail->words[total], gUnknown_0203A134->layout->var8[i].numEasyChatWords, 1);
total += gUnknown_0203A134->layout->var8[i].numEasyChatWords;
ConvertEasyChatWordsToString(sMailRead->strbuf[i], &sMailRead->mail->words[total], sMailRead->layout->var8[i].numEasyChatWords, 1);
total += sMailRead->layout->var8[i].numEasyChatWords;
}
ptr = StringCopy(gUnknown_0203A134->playerName, gUnknown_0203A134->mail->playerName);
if (!gUnknown_0203A134->playerIsSender)
ptr = StringCopy(sMailRead->playerName, sMailRead->mail->playerName);
if (!sMailRead->playerIsSender)
{
StringCopy(ptr, gText_FromSpace);
gUnknown_0203A134->signatureWidth = gUnknown_0203A134->layout->signatureWidth - (StringLength(gUnknown_0203A134->playerName) * 8 - 0x60);
sMailRead->signatureWidth = sMailRead->layout->signatureWidth - (StringLength(sMailRead->playerName) * 8 - 0x60);
}
else
{
sub_81DB52C(gUnknown_0203A134->playerName);
gUnknown_0203A134->signatureWidth = gUnknown_0203A134->layout->signatureWidth;
sub_81DB52C(sMailRead->playerName);
sMailRead->signatureWidth = sMailRead->layout->signatureWidth;
}
}
void sub_8121B1C(void)
static void sub_8121B1C(void)
{
u16 i;
u8 strbuf[0x20];
@ -500,77 +503,76 @@ void sub_8121B1C(void)
PutWindowTilemap(1);
FillWindowPixelBuffer(0, 0);
FillWindowPixelBuffer(1, 0);
for (i = 0; i < gUnknown_0203A134->layout->numSubStructs; i ++)
for (i = 0; i < sMailRead->layout->numSubStructs; i ++)
{
if (gUnknown_0203A134->strbuf[i][0] == EOS || gUnknown_0203A134->strbuf[i][0] == CHAR_SPACE)
if (sMailRead->strbuf[i][0] == EOS || sMailRead->strbuf[i][0] == CHAR_SPACE)
{
continue;
}
box_print(0, 1, gUnknown_0203A134->layout->var8[i].xOffset + gUnknown_0203A134->layout->wordsYPos, y + gUnknown_0203A134->layout->wordsXPos, gUnknown_0859F2AC, 0, gUnknown_0203A134->strbuf[i]);
y += gUnknown_0203A134->layout->var8[i].lineHeight;
box_print(0, 1, sMailRead->layout->var8[i].xOffset + sMailRead->layout->wordsYPos, y + sMailRead->layout->wordsXPos, sUnknown_0859F2AC, 0, sMailRead->strbuf[i]);
y += sMailRead->layout->var8[i].lineHeight;
}
bufptr = StringCopy(strbuf, gText_FromSpace);
StringCopy(bufptr, gUnknown_0203A134->playerName);
box_x = GetStringCenterAlignXOffset(1, strbuf, gUnknown_0203A134->signatureWidth) + 0x68;
box_y = gUnknown_0203A134->layout->signatureYPos + 0x58;
box_print(0, 1, box_x, box_y, gUnknown_0859F2AC, 0, strbuf);
StringCopy(bufptr, sMailRead->playerName);
box_x = GetStringCenterAlignXOffset(1, strbuf, sMailRead->signatureWidth) + 0x68;
box_y = sMailRead->layout->signatureYPos + 0x58;
box_print(0, 1, box_x, box_y, sUnknown_0859F2AC, 0, strbuf);
CopyWindowToVram(0, 3);
CopyWindowToVram(1, 3);
}
void sub_8121C50(void)
static void VBlankCB_MailRead(void)
{
LoadOam();
ProcessSpriteCopyRequests();
TransferPlttBuffer();
}
void sub_8121C64(void)
static void CB2_MailRead(void)
{
if (gUnknown_0203A134->animsActive != 0)
if (sMailRead->animsActive != 0)
{
AnimateSprites();
BuildOamBuffer();
}
gUnknown_0203A134->callback2();
sMailRead->callback2();
}
void sub_8121C98(void)
static void CB2_WaitForPaletteExitOnKeyPress(void)
{
if (!UpdatePaletteFade())
{
gUnknown_0203A134->callback2 = sub_8121CC0;
sMailRead->callback2 = CB2_ExitOnKeyPress;
}
}
void sub_8121CC0(void)
static void CB2_ExitOnKeyPress(void)
{
if (gMain.newKeys & (A_BUTTON | B_BUTTON))
{
BeginNormalPaletteFade(-1, 0, 0, 16, 0);
gUnknown_0203A134->callback2 = sub_8121D00;
sMailRead->callback2 = CB2_ExitMailReadFreeVars;
}
}
void sub_8121D00(void)
static void CB2_ExitMailReadFreeVars(void)
{
if (!UpdatePaletteFade())
{
SetMainCallback2(gUnknown_0203A134->callback);
switch (gUnknown_0203A134->animsActive)
SetMainCallback2(sMailRead->callback);
switch (sMailRead->animsActive)
{
case 1:
case 2:
sub_80D2FF0(sub_80D2E84(gUnknown_0203A134->mail->species));
sub_80D2EF8(&gSprites[gUnknown_0203A134->monIconSprite]);
sub_80D2FF0(sub_80D2E84(sMailRead->mail->species));
sub_80D2EF8(&gSprites[sMailRead->monIconSprite]);
}
memset(gUnknown_0203A134, 0, sizeof(*gUnknown_0203A134));
memset(sMailRead, 0, sizeof(*sMailRead));
ResetPaletteFade();
UnsetBgTilemapBuffer(0);
UnsetBgTilemapBuffer(1);
ResetBgsAndClearDma3BusyFlags(0);
FreeAllWindowBuffers();
free(gUnknown_0203A134);
gUnknown_0203A134 = NULL;
FREE_AND_SET_NULL(sMailRead);
}
}

203
src/mail_data.c Normal file
View File

@ -0,0 +1,203 @@
#include "global.h"
#include "mail.h"
#include "constants/items.h"
#include "pokemon.h"
#include "pokemon_icon.h"
#include "constants/species.h"
#include "text.h"
#include "international_string_util.h"
void ClearMailData(void)
{
u8 i;
for (i = 0; i < MAIL_COUNT; i++)
ClearMailStruct(&gSaveBlock1Ptr->mail[i]);
}
void ClearMailStruct(struct MailStruct *mail)
{
s32 i;
for (i = 0; i < MAIL_WORDS_COUNT; i++)
mail->words[i] = 0xFFFF;
for (i = 0; i < PLAYER_NAME_LENGTH; i++)
mail->playerName[i] = EOS;
for (i = 0; i < 4; i++)
mail->trainerId[i] = 0;
mail->species = SPECIES_BULBASAUR;
mail->itemId = ITEM_NONE;
}
bool8 MonHasMail(struct Pokemon *mon)
{
u16 heldItem = GetMonData(mon, MON_DATA_HELD_ITEM);
if (ItemIsMail(heldItem) && GetMonData(mon, MON_DATA_MAIL) != 0xFF)
return TRUE;
else
return FALSE;
}
u8 GiveMailToMon(struct Pokemon *mon, u16 itemId)
{
u8 heldItem[2];
u8 id, i;
u16 species;
u32 personality;
heldItem[0] = itemId;
heldItem[1] = itemId >> 8;
for (id = 0; id < PARTY_SIZE; id++)
{
if (gSaveBlock1Ptr->mail[id].itemId == 0)
{
for (i = 0; i < MAIL_WORDS_COUNT; i++)
gSaveBlock1Ptr->mail[id].words[i] = 0xFFFF;
for (i = 0; i < PLAYER_NAME_LENGTH - 1; i++)
gSaveBlock1Ptr->mail[id].playerName[i] = gSaveBlock2Ptr->playerName[i];
gSaveBlock1Ptr->mail[id].playerName[i] = EOS;
PadNameString(gSaveBlock1Ptr->mail[id].playerName, CHAR_SPACE);
for (i = 0; i < 4; i++)
gSaveBlock1Ptr->mail[id].trainerId[i] = gSaveBlock2Ptr->playerTrainerId[i];
species = GetBoxMonData(&mon->box, MON_DATA_SPECIES);
personality = GetBoxMonData(&mon->box, MON_DATA_PERSONALITY);
gSaveBlock1Ptr->mail[id].species = SpeciesToMailSpecies(species, personality);
gSaveBlock1Ptr->mail[id].itemId = itemId;
SetMonData(mon, MON_DATA_MAIL, &id);
SetMonData(mon, MON_DATA_HELD_ITEM, heldItem);
return id;
}
}
return 0xFF;
}
u16 SpeciesToMailSpecies(u16 species, u32 personality)
{
if (species == SPECIES_UNOWN)
{
u32 species = GetUnownLetterByPersonality(personality) + 30000;
return species;
}
return species;
}
u16 MailSpeciesToSpecies(u16 mailSpecies, u16 *buffer)
{
u16 result;
if (mailSpecies >= 30000 && mailSpecies < (30000 + UNOWN_FORM_COUNT))
{
result = SPECIES_UNOWN;
*buffer = mailSpecies - 30000;
}
else
{
result = mailSpecies;
}
return result;
}
u8 GiveMailToMon2(struct Pokemon *mon, struct MailStruct *mail)
{
u8 heldItem[2];
u16 itemId = mail->itemId;
u8 mailId = GiveMailToMon(mon, itemId);
if (mailId == 0xFF)
return 0xFF;
gSaveBlock1Ptr->mail[mailId] = *mail;
SetMonData(mon, MON_DATA_MAIL, &mailId);
heldItem[0] = itemId;
heldItem[1] = itemId >> 8;
SetMonData(mon, MON_DATA_HELD_ITEM, heldItem);
return mailId;
}
static bool32 DummyMailFunc(void)
{
return FALSE;
}
void TakeMailFromMon(struct Pokemon *mon)
{
u8 heldItem[2];
u8 mailId;
if (MonHasMail(mon))
{
mailId = GetMonData(mon, MON_DATA_MAIL);
gSaveBlock1Ptr->mail[mailId].itemId = ITEM_NONE;
mailId = 0xFF;
heldItem[0] = ITEM_NONE;
heldItem[1] = ITEM_NONE << 8;
SetMonData(mon, MON_DATA_MAIL, &mailId);
SetMonData(mon, MON_DATA_HELD_ITEM, heldItem);
}
}
void ClearMailItemId(u8 mailId)
{
gSaveBlock1Ptr->mail[mailId].itemId = ITEM_NONE;
}
u8 TakeMailFromMon2(struct Pokemon *mon)
{
u8 i;
u8 newHeldItem[2];
u8 newMailId;
newHeldItem[0] = ITEM_NONE;
newHeldItem[1] = ITEM_NONE << 8;
newMailId = 0xFF;
for (i = PARTY_SIZE; i < MAIL_COUNT; i++)
{
if (gSaveBlock1Ptr->mail[i].itemId == ITEM_NONE)
{
memcpy(&gSaveBlock1Ptr->mail[i], &gSaveBlock1Ptr->mail[GetMonData(mon, MON_DATA_MAIL)], sizeof(struct MailStruct));
gSaveBlock1Ptr->mail[GetMonData(mon, MON_DATA_MAIL)].itemId = ITEM_NONE;
SetMonData(mon, MON_DATA_MAIL, &newMailId);
SetMonData(mon, MON_DATA_HELD_ITEM, newHeldItem);
return i;
}
}
return 0xFF;
}
bool8 ItemIsMail(u16 itemId)
{
switch (itemId)
{
case ITEM_ORANGE_MAIL:
case ITEM_HARBOR_MAIL:
case ITEM_GLITTER_MAIL:
case ITEM_MECH_MAIL:
case ITEM_WOOD_MAIL:
case ITEM_WAVE_MAIL:
case ITEM_BEAD_MAIL:
case ITEM_SHADOW_MAIL:
case ITEM_TROPIC_MAIL:
case ITEM_DREAM_MAIL:
case ITEM_FAB_MAIL:
case ITEM_RETRO_MAIL:
return TRUE;
default:
return FALSE;
}
}