From e50f4b499928ac9010ecd96cff96de9f7bda2846 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sun, 3 Jun 2018 22:39:10 +0200 Subject: [PATCH] still going --- asm/rom_8011DC0.s | 940 --------------------------------- include/cable_club.h | 1 + include/field_control_avatar.h | 1 + include/link.h | 2 +- include/link_rfu.h | 2 + include/trade.h | 4 +- include/trainer_card.h | 3 + src/rom_8011DC0.c | 385 +++++++++++++- src/walda_phrase.c | 1 - 9 files changed, 394 insertions(+), 945 deletions(-) diff --git a/asm/rom_8011DC0.s b/asm/rom_8011DC0.s index 97b27bab9..e811bb428 100644 --- a/asm/rom_8011DC0.s +++ b/asm/rom_8011DC0.s @@ -6,947 +6,7 @@ .text - thumb_func_start sub_8013B8C -sub_8013B8C: @ 8013B8C - push {lr} - lsls r1, 5 - ldr r0, [r0] - adds r3, r0, r1 - ldr r0, =gUnknown_02022C2C - ldrb r0, [r0] - cmp r0, 0x4 - bne _08013BCE - ldrb r1, [r3, 0x1] - movs r0, 0x3C - ands r0, r1 - cmp r0, 0xC - beq _08013BCE - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldrb r1, [r0, 0x9] - movs r2, 0x80 - adds r0, r2, 0 - ands r0, r1 - cmp r0, 0 - bne _08013BC4 - movs r0, 0x1 - b _08013BD4 - .pool -_08013BC4: - ldrb r1, [r3] - adds r0, r2, 0 - ands r0, r1 - cmp r0, 0 - beq _08013BD2 -_08013BCE: - movs r0, 0 - b _08013BD4 -_08013BD2: - movs r0, 0x2 -_08013BD4: - pop {r1} - bx r1 - thumb_func_end sub_8013B8C - thumb_func_start sub_8013BD8 -sub_8013BD8: @ 8013BD8 - push {r4,lr} - adds r4, r0, 0 - strb r1, [r4, 0xF] - bl sub_800E0E8 - movs r0, 0 - movs r1, 0 - bl CreateWirelessStatusIndicatorSprite - ldrb r0, [r4, 0xE] - bl sub_81AE70C - ldr r0, =gStringVar1 - ldrb r2, [r4, 0xF] - lsls r2, 5 - ldr r1, [r4] - adds r1, r2 - bl sub_8018404 - ldr r1, =gUnknown_082F0530 - ldr r0, =gSpecialVar_0x8004 - ldrh r0, [r0] - adds r0, r1 - ldrb r0, [r0] - movs r1, 0 - movs r2, 0x1 - bl sub_8011090 - ldrb r1, [r4, 0xF] - lsls r1, 5 - ldr r0, [r4] - adds r0, r1 - adds r4, r0, 0 - adds r4, 0x10 - adds r0, 0x2 - bl ReadAsU16 - adds r1, r0, 0 - lsls r1, 16 - lsrs r1, 16 - adds r0, r4, 0 - bl sub_8011FC8 - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8013BD8 - - thumb_func_start sub_8013C40 -sub_8013C40: @ 8013C40 - push {lr} - ldr r0, =sub_8013C7C - movs r1, 0 - bl CreateTask - lsls r0, 24 - lsrs r0, 24 - ldr r3, =gUnknown_02022C30 - lsls r1, r0, 2 - adds r1, r0 - lsls r1, 3 - ldr r2, =gTasks + 0x8 - adds r1, r2 - str r1, [r3] - movs r2, 0 - strb r2, [r1, 0x8] - strb r2, [r1, 0x9] - ldr r2, =gUnknown_03000DA4 - str r1, [r2] - pop {r1} - bx r1 - .pool - thumb_func_end sub_8013C40 - - thumb_func_start sub_8013C7C -sub_8013C7C: @ 8013C7C - push {r4,r5,lr} - lsls r0, 24 - lsrs r5, r0, 24 - ldr r0, =gUnknown_02022C30 - ldr r4, [r0] - ldrb r0, [r4, 0x8] - cmp r0, 0xB - bhi _08013D80 - lsls r0, 2 - ldr r1, =_08013CA0 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_08013CA0: - .4byte _08013CD0 - .4byte _08013D80 - .4byte _08013D04 - .4byte _08013D28 - .4byte _08013D80 - .4byte _08013D80 - .4byte _08013D80 - .4byte _08013D80 - .4byte _08013D80 - .4byte _08013D80 - .4byte _08013D58 - .4byte _08013D76 -_08013CD0: - movs r0, 0 - movs r1, 0 - movs r2, 0 - bl sub_8010F84 - bl sub_800B488 - bl OpenLink - bl sub_8011C5C - movs r0, 0x1 - bl sub_80111B0 - movs r0, 0x70 - bl AllocZeroed - str r0, [r4, 0x4] - movs r0, 0x80 - lsls r0, 2 - bl AllocZeroed - str r0, [r4] - movs r0, 0x2 - strb r0, [r4, 0x8] - b _08013D80 -_08013D04: - ldr r0, [r4, 0x4] - movs r1, 0x4 - bl sub_80175EC - ldr r0, [r4] - movs r1, 0x10 - bl sub_8017580 - ldr r0, [r4, 0x4] - movs r1, 0xFF - bl sub_8016FC0 - movs r1, 0 - strb r0, [r4, 0x11] - strb r1, [r4, 0xF] - movs r0, 0x3 - strb r0, [r4, 0x8] - b _08013D80 -_08013D28: - bl sub_8013E44 - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1 - bne _08013D3A - movs r0, 0x2 - bl PlaySE -_08013D3A: - ldr r0, =gTasks - lsls r1, r5, 2 - adds r1, r5 - lsls r1, 3 - adds r1, r0 - movs r2, 0x26 - ldrsh r0, [r1, r2] - cmp r0, 0xFF - bne _08013D80 - movs r0, 0xA - strb r0, [r4, 0x8] - b _08013D80 - .pool -_08013D58: - ldrb r0, [r4, 0x11] - bl DestroyTask - ldr r0, [r4] - bl Free - ldr r0, [r4, 0x4] - bl Free - bl sub_800EDD4 - ldrb r0, [r4, 0x8] - adds r0, 0x1 - strb r0, [r4, 0x8] - b _08013D80 -_08013D76: - bl sub_800EDD4 - adds r0, r5, 0 - bl DestroyTask -_08013D80: - pop {r4,r5} - pop {r0} - bx r0 - thumb_func_end sub_8013C7C - - thumb_func_start sub_8013D88 -sub_8013D88: @ 8013D88 - push {lr} - adds r2, r0, 0 - cmp r1, 0xFF - bne _08013D94 -_08013D90: - movs r0, 0x1 - b _08013DB8 -_08013D94: - cmp r1, 0x16 - bhi _08013DB6 - ldr r0, =gUnknown_082F04D8 - lsls r1, 2 - adds r1, r0 - ldr r1, [r1] - b _08013DB0 - .pool -_08013DA8: - ldrb r0, [r1] - cmp r0, r2 - beq _08013D90 - adds r1, 0x1 -_08013DB0: - ldrb r0, [r1] - cmp r0, 0xFF - bne _08013DA8 -_08013DB6: - movs r0, 0 -_08013DB8: - pop {r1} - bx r1 - thumb_func_end sub_8013D88 - - thumb_func_start sub_8013DBC -sub_8013DBC: @ 8013DBC - push {lr} - ldr r0, [r0] - lsls r1, 5 - adds r1, r0, r1 - ldrb r2, [r1, 0x1A] - lsls r0, r2, 30 - lsrs r0, 30 - cmp r0, 0x1 - bne _08013DEE - ldrb r0, [r1, 0xA] - lsrs r0, 7 - cmp r0, 0 - beq _08013DDA - movs r0, 0x3 - b _08013DF0 -_08013DDA: - lsls r0, r2, 29 - cmp r0, 0 - bge _08013DE4 - movs r0, 0x1 - b _08013DF0 -_08013DE4: - ldrb r0, [r1, 0x1B] - cmp r0, 0 - beq _08013DEE - movs r0, 0x2 - b _08013DF0 -_08013DEE: - movs r0, 0 -_08013DF0: - pop {r1} - bx r1 - thumb_func_end sub_8013DBC - - thumb_func_start sub_8013DF4 -sub_8013DF4: @ 8013DF4 - push {r4-r6,lr} - mov r6, r8 - push {r6} - sub sp, 0x8 - adds r5, r0, 0 - adds r4, r1, 0 - adds r6, r2, 0 - lsls r5, 24 - lsrs r5, 24 - lsls r6, 24 - lsrs r6, 24 - ldr r0, =gUnknown_02022C30 - ldr r0, [r0] - mov r8, r0 - bl sub_8013DBC - lsls r0, 24 - lsrs r0, 24 - lsls r1, r4, 5 - mov r2, r8 - ldr r3, [r2] - adds r3, r1 - str r0, [sp] - lsls r4, 24 - lsrs r4, 24 - str r4, [sp, 0x4] - adds r0, r5, 0 - movs r1, 0x8 - adds r2, r6, 0 - bl sub_80177B8 - add sp, 0x8 - pop {r3} - mov r8, r3 - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8013DF4 - - thumb_func_start sub_8013E44 -sub_8013E44: @ 8013E44 - push {r4-r7,lr} - mov r7, r8 - push {r7} - sub sp, 0x4 - ldr r0, =gUnknown_02022C30 - ldr r6, [r0] - movs r7, 0 - movs r3, 0 -_08013E54: - ldr r0, [r6] - lsls r5, r3, 5 - adds r2, r0, r5 - ldrb r0, [r2, 0x1A] - lsls r0, 30 - mov r8, r5 - cmp r0, 0 - beq _08013F20 - ldr r1, [r6, 0x4] - adds r0, r2, 0 - str r3, [sp] - bl sub_80176E4 - adds r4, r0, 0 - ldr r3, [sp] - cmp r4, 0xFF - beq _08013EEE - ldr r0, [r6] - adds r2, r0, r5 - ldrb r1, [r2, 0x1A] - lsls r0, r1, 30 - lsrs r0, 30 - cmp r0, 0x1 - bne _08013ECC - lsls r0, r4, 3 - subs r0, r4 - lsls r4, r0, 2 - ldr r1, [r6, 0x4] - adds r1, r4 - adds r0, r2, 0 - bl sub_8017678 - ldr r3, [sp] - cmp r0, 0 - beq _08013EB0 - ldr r1, [r6] - ldr r0, [r6, 0x4] - adds r1, r5 - adds r0, r4 - ldm r0!, {r2,r4,r7} - stm r1!, {r2,r4,r7} - ldm r0!, {r2,r4,r7} - stm r1!, {r2,r4,r7} - b _08013EDA - .pool -_08013EB0: - ldr r0, [r6] - adds r1, r0, r5 - ldrb r0, [r1, 0x1B] - cmp r0, 0 - beq _08013EE4 - subs r0, 0x1 - strb r0, [r1, 0x1B] - ldr r0, [r6] - adds r0, r5 - ldrb r0, [r0, 0x1B] - cmp r0, 0 - bne _08013EE4 - movs r7, 0x2 - b _08013EE4 -_08013ECC: - movs r4, 0x4 - negs r4, r4 - adds r0, r4, 0 - ands r0, r1 - movs r1, 0x1 - orrs r0, r1 - strb r0, [r2, 0x1A] -_08013EDA: - ldr r0, [r6] - adds r0, r5 - movs r1, 0x40 - strb r1, [r0, 0x1B] - movs r7, 0x1 -_08013EE4: - ldr r0, [r6] - add r0, r8 - movs r1, 0 - strh r1, [r0, 0x18] - b _08013F20 -_08013EEE: - ldr r0, [r6] - adds r1, r0, r5 - ldrb r0, [r1, 0x1A] - lsls r0, 30 - lsrs r0, 30 - cmp r0, 0x2 - beq _08013F20 - ldrh r0, [r1, 0x18] - adds r0, 0x1 - strh r0, [r1, 0x18] - ldr r0, [r6] - adds r2, r0, r5 - ldrh r1, [r2, 0x18] - ldr r0, =0x0000012b - cmp r1, r0 - bls _08013F20 - ldrb r0, [r2, 0x1A] - movs r7, 0x4 - negs r7, r7 - adds r1, r7, 0 - ands r0, r1 - movs r1, 0x2 - orrs r0, r1 - strb r0, [r2, 0x1A] - movs r7, 0x2 -_08013F20: - adds r0, r3, 0x1 - lsls r0, 24 - lsrs r3, r0, 24 - cmp r3, 0xF - bls _08013E54 - movs r5, 0 - movs r4, 0x3 -_08013F2E: - ldr r0, [r6] - ldr r1, [r6, 0x4] - adds r1, r5 - movs r2, 0x10 - bl sub_8017734 - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0xFF - beq _08013F44 - movs r7, 0x1 -_08013F44: - adds r5, 0x1C - subs r4, 0x1 - cmp r4, 0 - bge _08013F2E - adds r0, r7, 0 - add sp, 0x4 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r1} - bx r1 - .pool - thumb_func_end sub_8013E44 - - thumb_func_start sub_8013F60 -sub_8013F60: @ 8013F60 - push {r4,lr} - adds r4, r0, 0 - lsls r4, 24 - lsrs r4, 24 - bl sub_80773AC - adds r0, r4, 0 - bl DestroyTask - pop {r4} - pop {r0} - bx r0 - thumb_func_end sub_8013F60 - - thumb_func_start sub_8013F78 -sub_8013F78: @ 8013F78 - push {lr} - ldr r0, =sub_8013F60 - movs r1, 0 - bl CreateTask - lsls r0, 24 - lsrs r0, 24 - pop {r1} - bx r1 - .pool - thumb_func_end sub_8013F78 - - thumb_func_start sub_8013F90 -sub_8013F90: @ 8013F90 - push {r4-r7,lr} - mov r7, r8 - push {r7} - lsls r0, 24 - lsrs r6, r0, 24 - ldr r0, =gUnknown_02022C40 - mov r8, r0 - bl GetMultiplayerId - adds r1, r0, 0 - lsls r1, 24 - lsrs r1, 24 - mov r0, r8 - bl sub_8018120 - adds r7, r0, 0 - ldr r1, =gTasks - lsls r0, r6, 2 - adds r0, r6 - lsls r0, 3 - adds r5, r0, r1 - movs r1, 0x8 - ldrsh r0, [r5, r1] - cmp r0, 0x1 - beq _08013FFC - cmp r0, 0x1 - bgt _08013FD4 - cmp r0, 0 - beq _08013FDE - b _080140BC - .pool -_08013FD4: - cmp r0, 0x2 - beq _08014038 - cmp r0, 0x3 - beq _08014070 - b _080140BC -_08013FDE: - ldrh r0, [r5, 0x8] - adds r0, 0x1 - strh r0, [r5, 0x8] - movs r0, 0x64 - adds r1, r7, 0 - muls r1, r0 - ldr r0, =gPlayerParty - adds r1, r0 - movs r0, 0 - movs r2, 0x64 - bl SendBlock - b _080140BC - .pool -_08013FFC: - bl GetBlockReceivedStatus - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x3 - bne _080140BC - bl GetMultiplayerId - adds r1, r0, 0 - ldr r0, =gEnemyParty - movs r2, 0x1 - eors r1, r2 - lsls r1, 24 - lsrs r1, 16 - ldr r2, =gBlockRecvBuffer - adds r1, r2 - movs r2, 0x64 - bl memcpy - movs r0, 0x32 - bl IncrementGameStat - bl ResetBlockReceivedFlags - b _0801405A - .pool -_08014038: - ldr r4, =gBlockSendBuffer - ldr r0, =gSaveBlock1Ptr - ldr r1, [r0] - ldr r0, =0x00002be0 - adds r1, r0 - adds r0, r4, 0 - movs r2, 0xDC - bl memcpy - movs r0, 0 - adds r1, r4, 0 - movs r2, 0xDC - bl SendBlock - lsls r0, 24 - cmp r0, 0 - beq _080140BC -_0801405A: - ldrh r0, [r5, 0x8] - adds r0, 0x1 - strh r0, [r5, 0x8] - b _080140BC - .pool -_08014070: - bl GetBlockReceivedStatus - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x3 - bne _080140BC - ldr r4, =gUnknown_020321C0 - bl GetMultiplayerId - adds r1, r0, 0 - movs r0, 0x1 - eors r1, r0 - lsls r1, 24 - lsrs r1, 16 - ldr r0, =gBlockRecvBuffer - adds r1, r0 - adds r0, r4, 0 - movs r2, 0xD8 - bl memcpy - bl ResetBlockReceivedFlags - ldr r1, =gUnknown_02032298 - strb r7, [r1] - movs r0, 0x6 - strb r0, [r1, 0x1] - ldr r1, =gMain - ldr r0, =CB2_ReturnToField - str r0, [r1, 0x8] - ldr r0, =sub_807AE50 - bl SetMainCallback2 - mov r0, r8 - bl sub_801807C - adds r0, r6, 0 - bl DestroyTask -_080140BC: - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8013F90 - - thumb_func_start sub_80140E0 -sub_80140E0: @ 80140E0 - push {r4-r6,lr} - lsls r0, 24 - lsrs r6, r0, 24 - ldr r1, =gTasks - lsls r0, r6, 2 - adds r0, r6 - lsls r0, 3 - adds r4, r0, r1 - movs r1, 0x8 - ldrsh r0, [r4, r1] - cmp r0, 0 - beq _08014104 - cmp r0, 0x1 - beq _0801411C - b _0801419E - .pool -_08014104: - bl GetMultiplayerId - lsls r0, 24 - cmp r0, 0 - bne _08014114 - movs r0, 0x2 - bl sub_800A4D8 -_08014114: - ldrh r0, [r4, 0x8] - adds r0, 0x1 - strh r0, [r4, 0x8] - b _0801419E -_0801411C: - bl GetBlockReceivedStatus - adds r4, r0, 0 - bl sub_800A9D8 - lsls r4, 24 - lsls r0, 24 - cmp r4, r0 - bne _0801419E - movs r4, 0 - ldr r5, =gLinkPlayers - b _08014152 - .pool -_08014138: - lsls r1, r4, 8 - ldr r0, =gBlockRecvBuffer - adds r3, r1, r0 - movs r0, 0x64 - muls r0, r4 - ldr r1, =gTrainerCards - adds r0, r1 - ldrb r2, [r5] - adds r1, r3, 0 - bl sub_80C3120 - adds r5, 0x1C - adds r4, 0x1 -_08014152: - bl GetLinkPlayerCount - lsls r0, 24 - lsrs r0, 24 - cmp r4, r0 - blt _08014138 - bl GetLinkPlayerCount - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x2 - bne _08014190 - bl GetMultiplayerId - movs r1, 0x1 - eors r0, r1 - lsls r0, 24 - lsrs r0, 16 - ldr r1, =gBlockRecvBuffer - adds r3, r0, r1 - adds r0, r3, 0 - adds r0, 0x60 - ldrh r0, [r0] - bl sub_801B94C - b _08014194 - .pool -_08014190: - bl sub_801B940 -_08014194: - bl ResetBlockReceivedFlags - adds r0, r6, 0 - bl DestroyTask -_0801419E: - pop {r4-r6} - pop {r0} - bx r0 - thumb_func_end sub_80140E0 - - thumb_func_start sub_80141A4 -sub_80141A4: @ 80141A4 - push {r4,lr} - ldr r0, =gMain - movs r1, 0x87 - lsls r1, 3 - adds r4, r0, r1 - ldrb r0, [r4] - cmp r0, 0 - beq _080141C0 - cmp r0, 0x1 - beq _080141D4 - b _080141F2 - .pool -_080141C0: - ldr r0, =sub_80140E0 - movs r1, 0x5 - bl CreateTask - ldrb r0, [r4] - adds r0, 0x1 - strb r0, [r4] - b _080141F2 - .pool -_080141D4: - ldr r0, =sub_80140E0 - bl FuncIsActiveTask - lsls r0, 24 - cmp r0, 0 - bne _080141F2 - bl GetMultiplayerId - movs r1, 0x1 - eors r0, r1 - lsls r0, 24 - lsrs r0, 24 - ldr r1, =CB2_ReturnToField - bl sub_80C4E74 -_080141F2: - bl RunTasks - bl RunTextPrinters - bl AnimateSprites - bl BuildOamBuffer - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80141A4 - - thumb_func_start sub_8014210 -sub_8014210: @ 8014210 - push {r4-r6,lr} - adds r6, r0, 0 - lsls r6, 16 - lsrs r6, 16 - bl HealPlayerParty - bl SavePlayerParty - bl LoadPlayerBag - ldr r5, =gLinkPlayers - ldr r0, =0x00002211 - str r0, [r5, 0x14] - bl GetMultiplayerId - adds r4, r0, 0 - bl GetMultiplayerId - lsls r4, 24 - lsrs r4, 24 - lsls r1, r4, 3 - subs r1, r4 - lsls r1, 2 - adds r1, r5 - lsls r0, 24 - lsrs r0, 24 - strh r0, [r1, 0x18] - bl GetMultiplayerId - adds r4, r0, 0 - bl GetMultiplayerId - movs r2, 0x1 - eors r4, r2 - lsls r4, 24 - lsrs r4, 24 - lsls r1, r4, 3 - subs r1, r4 - lsls r1, 2 - adds r1, r5 - eors r0, r2 - lsls r0, 24 - lsrs r0, 24 - strh r0, [r1, 0x18] - ldr r1, =gMain - ldr r0, =sub_80B360C - str r0, [r1, 0x8] - ldr r0, =gBattleTypeFlags - str r6, [r0] - bl PlayBattleBGM - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8014210 - - thumb_func_start sub_8014290 -sub_8014290: @ 8014290 - push {r4-r6,lr} - mov r6, r8 - push {r6} - sub sp, 0x8 - adds r3, r0, 0 - adds r4, r1, 0 - adds r5, r2, 0 - lsls r3, 16 - lsrs r3, 16 - lsls r4, 16 - lsrs r4, 16 - lsls r5, 16 - lsrs r5, 16 - ldr r0, =0x00004087 - adds r1, r3, 0 - bl VarSet - ldr r6, =gSaveBlock1Ptr - ldr r1, [r6] - movs r0, 0x4 - ldrsb r0, [r1, r0] - ldrb r1, [r1, 0x5] - lsls r1, 24 - asrs r1, 24 - movs r2, 0x1 - negs r2, r2 - mov r8, r2 - lsls r4, 24 - asrs r4, 24 - lsls r5, 24 - asrs r5, 24 - str r5, [sp] - adds r3, r4, 0 - bl Overworld_SetWarpDestination - ldr r0, [r6] - movs r1, 0x4 - ldrsb r1, [r0, r1] - movs r2, 0x5 - ldrsb r2, [r0, r2] - str r4, [sp] - str r5, [sp, 0x4] - movs r0, 0 - mov r3, r8 - bl saved_warp2_set_2 - bl warp_in - add sp, 0x8 - pop {r3} - mov r8, r3 - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8014290 - - thumb_func_start sub_8014304 -sub_8014304: @ 8014304 - push {r4-r6,lr} - mov r6, r8 - push {r6} - sub sp, 0x4 - adds r4, r0, 0 - adds r5, r1, 0 - mov r8, r2 - adds r6, r3, 0 - ldr r1, [sp, 0x18] - lsls r4, 24 - lsrs r4, 24 - lsls r5, 24 - lsrs r5, 24 - lsls r1, 16 - lsrs r1, 16 - ldr r0, =gSpecialVar_0x8004 - strh r1, [r0] - ldr r0, =0x00004087 - bl VarSet - bl GetLinkPlayerCount - ldr r1, =gFieldLinkPlayerCount - strb r0, [r1] - bl GetMultiplayerId - ldr r1, =gUnknown_03005DB4 - strb r0, [r1] - bl sub_809D2BC - lsls r4, 24 - asrs r4, 24 - lsls r5, 24 - asrs r5, 24 - movs r2, 0x1 - negs r2, r2 - mov r0, r8 - lsls r0, 24 - asrs r0, 24 - mov r8, r0 - lsls r6, 24 - asrs r6, 24 - str r6, [sp] - adds r0, r4, 0 - adds r1, r5, 0 - mov r3, r8 - bl Overworld_SetWarpDestination - bl warp_in - add sp, 0x4 - pop {r3} - mov r8, r3 - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8014304 thumb_func_start sub_8014384 sub_8014384: @ 8014384 diff --git a/include/cable_club.h b/include/cable_club.h index 44831235c..7b47c9f73 100644 --- a/include/cable_club.h +++ b/include/cable_club.h @@ -9,5 +9,6 @@ void sub_80B37D4(TaskFunc taskFunc); u8 sub_80B3050(void); +void sub_80B360C(void); #endif //GUARD_CABLE_CLUB_H diff --git a/include/field_control_avatar.h b/include/field_control_avatar.h index b915d1419..16666d457 100644 --- a/include/field_control_avatar.h +++ b/include/field_control_avatar.h @@ -37,5 +37,6 @@ bool8 sub_8068894(void); bool8 sub_8068A64(struct MapPosition *, u16); u8 sub_8068F18(void); bool8 dive_warp(struct MapPosition *position, u16 b); +void sub_809D2BC(void); #endif // GUARD_FIELDCONTROLAVATAR_H diff --git a/include/link.h b/include/link.h index 5b3cd26ca..5ef1dca4c 100644 --- a/include/link.h +++ b/include/link.h @@ -122,7 +122,7 @@ struct LinkPlayer /* 0x08 */ u8 name[11]; /* 0x13 */ u8 gender; /* 0x14 */ u32 linkType; - /* 0x18 */ u16 lp_field_18; // battle bank in battles + /* 0x18 */ u16 lp_field_18; // battler id in battles /* 0x1A */ u16 language; }; diff --git a/include/link_rfu.h b/include/link_rfu.h index b517fba17..95bae9d06 100644 --- a/include/link_rfu.h +++ b/include/link_rfu.h @@ -248,5 +248,7 @@ void sub_800E084(void); void sub_801103C(void); void sub_8011C5C(void); void sub_80106D4(void); +void sub_8011090(u8 a0, u32 a1, u32 a2); +void sub_8011FC8(u8 *a0, u16 a1); #endif //GUARD_LINK_RFU_H diff --git a/include/trade.h b/include/trade.h index 15438ff3f..af4da0015 100644 --- a/include/trade.h +++ b/include/trade.h @@ -7,6 +7,8 @@ // Exported ROM declarations -int sub_807A728(void); +s32 sub_807A728(void); +void sub_80773AC(void); +void sub_807AE50(void); #endif //GUARD_TRADE_H diff --git a/include/trainer_card.h b/include/trainer_card.h index 5cb93dba0..6afcba5b1 100644 --- a/include/trainer_card.h +++ b/include/trainer_card.h @@ -32,4 +32,7 @@ struct TrainerCard extern struct TrainerCard gTrainerCards[4]; +void sub_80C3120(struct TrainerCard *arg0, u16 *arg1, u8 gameVersion); +void sub_80C4E74(u8 arg0, void (*callback)(void)); + #endif // GUARD_TRAINER_CARD_H diff --git a/src/rom_8011DC0.c b/src/rom_8011DC0.c index e73030e75..514fd49a7 100644 --- a/src/rom_8011DC0.c +++ b/src/rom_8011DC0.c @@ -14,6 +14,16 @@ #include "script.h" #include "sound.h" #include "constants/songs.h" +#include "constants/game_stat.h" +#include "trade.h" +#include "trainer_card.h" +#include "overworld.h" +#include "battle.h" +#include "load_save.h" +#include "cable_club.h" +#include "field_control_avatar.h" + +extern void HealPlayerParty(void); struct UnkStruct_Shared { @@ -105,11 +115,30 @@ union UnkUnion_Main struct UnkStruct_Group *group; }; +struct TradeUnkStruct +{ + u16 field_0; + u16 field_2; + u32 field_4; + u32 field_8; + u16 field_A; + u16 field_C; + u16 field_E; + u16 field_10; + u16 field_12; + u32 field_14; +}; + +extern struct TradeUnkStruct gUnknown_02022C40; + extern union UnkUnion_Main gUnknown_02022C30; extern u8 gUnknown_02022C2C; extern u8 gUnknown_02022C2D; +extern u8 gFieldLinkPlayerCount; +extern u8 gUnknown_03005DB4; + // IWRAM vars IWRAM_DATA struct UnkStruct_Leader *gUnknown_03000DA0; IWRAM_DATA struct UnkStruct_Group *gUnknown_03000DA4; @@ -122,6 +151,7 @@ void sub_80173E0(u8 windowId, u8 arg1, const u8 *str, u8 arg3, u8 arg4, u8 arg5) u16 ReadAsU16(const u8 *ptr); void sub_8012780(u8 taskId); void sub_80134E8(u8 taskId); +void sub_8013C7C(u8 taskId); void sub_80175EC(struct UnkStruct_Main4 *arg0, u8 count); void sub_8017580(struct UnkStruct_Main0 *arg0, u8 count); u8 sub_8016FC0(struct UnkStruct_Main4 *arg0, u32 arg1); @@ -135,11 +165,17 @@ void sub_80149C4(void); u8 sub_80132D4(struct UnkStruct_Main0 *arg0); void sub_80178A0(u8 arg0, u8 arg1, u8 arg2, struct UnkStruct_x20 *arg3, u8 arg4, u8 id); u32 sub_80176E4(struct UnkStruct_x20 *arg0, struct UnkStruct_x1C *arg1); -void sub_8017734(struct UnkStruct_x20 *arg0, struct UnkStruct_Shared *arg1, u8 arg2); +u8 sub_8017734(struct UnkStruct_x20 *arg0, struct UnkStruct_Shared *arg1, u8 arg2); u8 sub_8013E44(void); u32 sub_8013B8C(struct UnkStruct_Group *arg0, s32 id); void sub_8013BD8(struct UnkStruct_Group *arg0, s32 id); void sub_80173D4(void); +void sub_80177B8(u8 arg0, u8 arg1, u8 arg2, struct UnkStruct_x20 *arg3, u8 arg4, u8 id); +bool32 sub_8017678(struct UnkStruct_x20 *arg0, struct UnkStruct_x1C *arg1); +u32 sub_8018120(struct TradeUnkStruct *arg0, u8 multiplayerId); +void sub_801807C(struct TradeUnkStruct *arg0); +void sub_801B940(void); +void sub_801B94C(u16); // const rom data extern const u8 *const gUnknown_082EDB60[][5]; @@ -914,7 +950,7 @@ void sub_80134E8(u8 taskId) id = ListMenuHandleInputGetItemId(data->listTaskId); if (gMain.newKeys & A_BUTTON && id != -1) { - // this unused variable is needed to match + // this unused variable along with the assignment is needed to match u32 unusedVar; unusedVar = data->field_0->arr[id].unk.field_0.unk_0a_0; @@ -1114,3 +1150,348 @@ void sub_80134E8(u8 taskId) break; } } + +u32 sub_8013B8C(struct UnkStruct_Group *arg0, s32 id) +{ + struct UnkStruct_x20 *structPtr = &arg0->field_0->arr[id]; + + if (gUnknown_02022C2C == 4 && structPtr->unk.field_0.unk_01_2 != 3) + { + if (!(gSaveBlock2Ptr->specialSaveWarp & 0x80)) + return 1; + else if (structPtr->unk.field_0.unk_00_7) + return 0; + } + else + { + return 0; + } + + return 2; +} + +void sub_8013BD8(struct UnkStruct_Group *data, s32 id) +{ + data->field_F = id; + sub_800E0E8(); + CreateWirelessStatusIndicatorSprite(0, 0); + sub_81AE70C(data->listTaskId); + sub_8018404(gStringVar1, &data->field_0->arr[data->field_F]); + sub_8011090(gUnknown_082F0530[gSpecialVar_0x8004], 0, 1); + sub_8011FC8(data->field_0->arr[data->field_F].unk.playerName, ReadAsU16(data->field_0->arr[data->field_F].unk.field_0.playerTrainerId)); +} + +u8 sub_8013C40(void) +{ + u8 taskId; + struct UnkStruct_Group *dataPtr; + + taskId = CreateTask(sub_8013C7C, 0); + gUnknown_02022C30.group = dataPtr = (void*)(gTasks[taskId].data); + + dataPtr->state = 0; + dataPtr->textState = 0; + + gUnknown_03000DA4 = dataPtr; + + return taskId; +} + +void sub_8013C7C(u8 taskId) +{ + struct UnkStruct_Group *data = gUnknown_02022C30.group; + + switch (data->state) + { + case 0: + sub_8010F84(0, 0, 0); + sub_800B488(); + OpenLink(); + sub_8011C5C(); + sub_80111B0(TRUE); + data->field_4 = AllocZeroed(0x70); + data->field_0 = AllocZeroed(0x200); + data->state = 2; + break; + case 2: + sub_80175EC(data->field_4, 4); + sub_8017580(data->field_0, 16); + data->field_11 = sub_8016FC0(data->field_4, 0xFF); + data->field_F = 0; + data->state = 3; + break; + case 3: + if (sub_8013E44() == 1) + PlaySE(SE_PC_LOGIN); + if (gTasks[taskId].data[15] == 0xFF) + data->state = 10; + break; + case 10: + DestroyTask(data->field_11); + Free(data->field_0); + Free(data->field_4); + sub_800EDD4(); + data->state++; + break; + case 11: + sub_800EDD4(); + DestroyTask(taskId); + break; + } +} + +extern const u8 *const gUnknown_082F04D8[22]; + +bool32 sub_8013D88(u32 arg0, u32 id) +{ + if (id == 0xFF) + return TRUE; + + if (id <= ARRAY_COUNT(gUnknown_082F04D8)) // UB: <= may access data outside the array + { + const u8 *bytes = gUnknown_082F04D8[id]; + + while ((*(bytes) != 0xFF)) + { + if ((*bytes) == arg0) + return TRUE; + bytes++; + } + } + + return FALSE; +} + +u8 sub_8013DBC(struct UnkStruct_Group *data, u32 id) +{ + if (data->field_0->arr[id].field_1A_0 == 1) + { + if (data->field_0->arr[id].unk.field_0.unk_0a_7 != 0) + return 3; + else if (data->field_0->arr[id].field_1A_1 != 0) + return 1; + else if (data->field_0->arr[id].field_1B != 0) + return 2; + } + + return 0; +} + +void sub_8013DF4(u8 arg0, u32 id, u8 arg2) +{ + struct UnkStruct_Group *data = gUnknown_02022C30.group; + u8 var = sub_8013DBC(data, id); + + sub_80177B8(arg0, 8, arg2, &data->field_0->arr[id], var, id); +} + +u8 sub_8013E44(void) +{ + struct UnkStruct_Group *data = gUnknown_02022C30.group; + u8 ret = 0; + u8 i; + s32 id; + + for (i = 0; i < 16; i++) + { + if (data->field_0->arr[i].field_1A_0 != 0) + { + id = sub_80176E4(&data->field_0->arr[i], data->field_4->arr); + if (id != 0xFF) + { + if (data->field_0->arr[i].field_1A_0 == 1) + { + if (sub_8017678(&data->field_0->arr[i], &data->field_4->arr[id])) + { + data->field_0->arr[i].unk = data->field_4->arr[id].unk0; + data->field_0->arr[i].field_1B = 0x40; + ret = 1; + } + else + { + if (data->field_0->arr[i].field_1B != 0) + { + data->field_0->arr[i].field_1B--; + if (data->field_0->arr[i].field_1B == 0) + ret = 2; + } + } + } + else + { + data->field_0->arr[i].field_1A_0 = 1; + data->field_0->arr[i].field_1B = 0x40; + ret = 1; + } + + data->field_0->arr[i].field_18 = 0; + } + else + { + if (data->field_0->arr[i].field_1A_0 != 2) + { + data->field_0->arr[i].field_18++; + if (data->field_0->arr[i].field_18 >= 300) + { + data->field_0->arr[i].field_1A_0 = 2; + ret = 2; + } + } + } + } + } + + for (id = 0; id < 4; id++) + { + if (sub_8017734(data->field_0->arr, &data->field_4->arr[id].unk0, 16) != 0xFF) + ret = 1; + } + + return ret; +} + +void sub_8013F60(u8 taskId) +{ + sub_80773AC(); + DestroyTask(taskId); +} + +u8 sub_8013F78(void) +{ + u8 taskId = CreateTask(sub_8013F60, 0); + + return taskId; +} + +extern struct MailStruct gUnknown_020321C0[PARTY_SIZE]; +extern u8 gUnknown_02032298[2]; + +void sub_8013F90(u8 taskId) +{ + u32 monId = sub_8018120(&gUnknown_02022C40, GetMultiplayerId()); + + switch (gTasks[taskId].data[0]) + { + case 0: + gTasks[taskId].data[0]++; + SendBlock(0, &gPlayerParty[monId], sizeof(struct Pokemon)); + break; + case 1: + if (GetBlockReceivedStatus() == 3) + { + gEnemyParty[0] = *(struct Pokemon*)(gBlockRecvBuffer[GetMultiplayerId() ^ 1]); + IncrementGameStat(GAME_STAT_50); + ResetBlockReceivedFlags(); + gTasks[taskId].data[0]++; + } + break; + case 2: + memcpy(gBlockSendBuffer, gSaveBlock1Ptr->mail, sizeof(struct MailStruct) * PARTY_SIZE + 4); + if (SendBlock(0, gBlockSendBuffer, sizeof(struct MailStruct) * PARTY_SIZE + 4)) + gTasks[taskId].data[0]++; + break; + case 3: + if (GetBlockReceivedStatus() == 3) + { + memcpy(gUnknown_020321C0, gBlockRecvBuffer[GetMultiplayerId() ^ 1], sizeof(struct MailStruct) * PARTY_SIZE); + ResetBlockReceivedFlags(); + gUnknown_02032298[0] = monId; + gUnknown_02032298[1] = 6; + gMain.savedCallback = CB2_ReturnToField; + SetMainCallback2(sub_807AE50); + sub_801807C(&gUnknown_02022C40); + DestroyTask(taskId); + } + break; + } +} + +void sub_80140E0(u8 taskId) +{ + switch (gTasks[taskId].data[0]) + { + case 0: + if (GetMultiplayerId() == 0) + sub_800A4D8(2); + gTasks[taskId].data[0]++; + break; + case 1: + if (GetBlockReceivedStatus() == sub_800A9D8()) + { + s32 i; + u16 *recvBuff; + + for (i = 0; i < GetLinkPlayerCount(); i++) + { + recvBuff = gBlockRecvBuffer[i]; + sub_80C3120(&gTrainerCards[i], recvBuff, gLinkPlayers[i].version); + } + + if (GetLinkPlayerCount() == 2) + { + recvBuff = gBlockRecvBuffer[GetMultiplayerId() ^ 1]; + sub_801B94C(recvBuff[48]); + } + else + { + sub_801B940(); + } + + ResetBlockReceivedFlags(); + DestroyTask(taskId); + } + break; + } +} + +void sub_80141A4(void) +{ + switch (gMain.state) + { + case 0: + CreateTask(sub_80140E0, 5); + gMain.state++; + break; + case 1: + if (!FuncIsActiveTask(sub_80140E0)) + sub_80C4E74(GetMultiplayerId() ^ 1, CB2_ReturnToField); + break; + } + + RunTasks(); + RunTextPrinters(); + AnimateSprites(); + BuildOamBuffer(); +} + +void sub_8014210(u16 battleFlags) +{ + HealPlayerParty(); + SavePlayerParty(); + LoadPlayerBag(); + gLinkPlayers[0].linkType = 0x2211; + gLinkPlayers[GetMultiplayerId()].lp_field_18 = GetMultiplayerId(); + gLinkPlayers[GetMultiplayerId() ^ 1].lp_field_18 = GetMultiplayerId() ^ 1; + gMain.savedCallback = sub_80B360C; + gBattleTypeFlags = battleFlags; + PlayBattleBGM(); +} + +void sub_8014290(u16 arg0, u16 x, u16 y) +{ + VarSet(VAR_0x4087, arg0); + Overworld_SetWarpDestination(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1, x, y); + saved_warp2_set_2(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1, x, y); + warp_in(); +} + +void sub_8014304(s8 mapGroup, s8 mapNum, s32 x, s32 y, u16 arg4) +{ + gSpecialVar_0x8004 = arg4; + VarSet(VAR_0x4087, arg4); + gFieldLinkPlayerCount = GetLinkPlayerCount(); + gUnknown_03005DB4 = GetMultiplayerId(); + sub_809D2BC(); + Overworld_SetWarpDestination(mapGroup, mapNum, -1, x, y); + warp_in(); +} diff --git a/src/walda_phrase.c b/src/walda_phrase.c index 0aa6f5aca..4a82be14f 100644 --- a/src/walda_phrase.c +++ b/src/walda_phrase.c @@ -13,7 +13,6 @@ extern const u8 gText_Peekaboo[]; extern u8 *GetWaldaPhrasePtr(void); extern bool32 IsWaldaPhraseEmpty(void); extern void sub_80AF168(void); -extern void CB2_ReturnToField(void); extern void SetWaldaPhrase(const u8 *src); extern void SetWaldaWallpaperPatternId(u8 patternId); extern void SetWaldaWallpaperIconId(u8 iconId);