From 2fb9f490fbf961ff737c897c025ce1f5a54b2639 Mon Sep 17 00:00:00 2001 From: Diegoisawesome Date: Sat, 29 Dec 2018 12:46:15 -0600 Subject: [PATCH] Almost done with trade --- asm/trade.s | 1720 +----------------- data/maps/BattleFrontier_Lounge6/scripts.inc | 8 +- data/maps/FortreeCity_House1/scripts.inc | 8 +- data/maps/PacifidlogTown_House3/scripts.inc | 8 +- data/maps/RustboroCity_House1/scripts.inc | 8 +- data/specials.inc | 8 +- data/trade.s | 4 +- include/gba/defines.h | 2 - include/gba/io_reg.h | 3 + include/strings.h | 2 +- src/trade.c | 606 +++++- 11 files changed, 629 insertions(+), 1748 deletions(-) diff --git a/asm/trade.s b/asm/trade.s index 88ba38cdb..c601f9afa 100644 --- a/asm/trade.s +++ b/asm/trade.s @@ -6,1718 +6,6 @@ .text - thumb_func_start c2_08053788 -c2_08053788: @ 807E414 - push {r4-r7,lr} - mov r7, r8 - push {r7} - ldr r0, =gMain - movs r2, 0x87 - lsls r2, 3 - adds r1, r0, r2 - ldrb r0, [r1] - cmp r0, 0 - beq _0807E434 - cmp r0, 0x4 - beq _0807E444 - b _0807E4B4 - .pool -_0807E434: - movs r0, 0x4 - strb r0, [r1] - ldr r1, =gSoftResetDisabled - movs r0, 0x1 - b _0807E4B2 - .pool -_0807E444: - ldr r0, =gCB2_AfterEvolution - ldr r1, =sub_807EB50 - mov r8, r1 - str r1, [r0] - ldr r7, =gUnknown_02032298 - ldrb r0, [r7] - movs r6, 0x64 - muls r0, r6 - ldr r5, =gPlayerParty - adds r0, r5 - movs r1, 0x1 - movs r2, 0 - bl GetEvolutionTargetSpecies - lsls r0, 16 - lsrs r4, r0, 16 - cmp r4, 0 - beq _0807E494 - ldrb r3, [r7] - adds r0, r3, 0 - muls r0, r6 - adds r0, r5 - ldr r1, =gUnknown_020322A0 - ldr r1, [r1] - adds r1, 0x8F - ldrb r2, [r1] - adds r1, r4, 0 - bl TradeEvolutionScene - b _0807E4AE - .pool -_0807E494: - bl sub_8077260 - cmp r0, 0 - beq _0807E4A8 - ldr r0, =sub_807F464 - bl SetMainCallback2 - b _0807E4AE - .pool -_0807E4A8: - mov r0, r8 - bl SetMainCallback2 -_0807E4AE: - ldr r1, =gUnknown_02032298 - movs r0, 0xFF -_0807E4B2: - strb r0, [r1] -_0807E4B4: - bl HasLinkErrorOccurred - lsls r0, 24 - cmp r0, 0 - bne _0807E4C2 - bl RunTasks -_0807E4C2: - bl AnimateSprites - bl BuildOamBuffer - bl UpdatePaletteFade - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end c2_08053788 - - thumb_func_start sub_807E4DC -sub_807E4DC: @ 807E4DC - push {r4-r6,lr} - bl sub_807ACDC - bl GetBlockReceivedStatus - lsls r0, 24 - lsrs r5, r0, 24 - movs r6, 0x1 - adds r0, r5, 0 - ands r0, r6 - cmp r0, 0 - beq _0807E51A - ldr r4, =gBlockRecvBuffer - ldrh r1, [r4] - ldr r0, =0x0000dcba - cmp r1, r0 - bne _0807E504 - ldr r0, =c2_08053788 - bl SetMainCallback2 -_0807E504: - ldrh r1, [r4] - ldr r0, =0x0000abcd - cmp r1, r0 - bne _0807E514 - ldr r0, =gUnknown_020322A0 - ldr r0, [r0] - adds r0, 0x72 - strb r6, [r0] -_0807E514: - movs r0, 0 - bl ResetBlockReceivedFlag -_0807E51A: - movs r0, 0x2 - ands r0, r5 - cmp r0, 0 - beq _0807E542 - ldr r0, =gBlockRecvBuffer - movs r1, 0x80 - lsls r1, 1 - adds r0, r1 - ldrh r1, [r0] - ldr r0, =0x0000abcd - cmp r1, r0 - bne _0807E53C - ldr r0, =gUnknown_020322A0 - ldr r0, [r0] - adds r0, 0x73 - movs r1, 0x1 - strb r1, [r0] -_0807E53C: - movs r0, 0x1 - bl ResetBlockReceivedFlag -_0807E542: - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_807E4DC - - thumb_func_start sub_807E55C -sub_807E55C: @ 807E55C - push {r4,r5,lr} - adds r5, r0, 0 - movs r1, 0x2E - ldrsh r0, [r5, r1] - movs r1, 0xA - bl __divsi3 - ldrh r4, [r5, 0x22] - adds r4, r0 - strh r4, [r5, 0x22] - ldrh r0, [r5, 0x30] - ldrh r2, [r5, 0x38] - adds r0, r2 - strh r0, [r5, 0x38] - movs r1, 0x38 - ldrsh r0, [r5, r1] - movs r1, 0xA - bl __divsi3 - strh r0, [r5, 0x20] - lsls r4, 16 - asrs r4, 16 - cmp r4, 0x4C - ble _0807E5AA - movs r0, 0x4C - strh r0, [r5, 0x22] - movs r2, 0x2E - ldrsh r1, [r5, r2] - movs r2, 0x32 - ldrsh r0, [r5, r2] - muls r0, r1 - negs r0, r0 - movs r1, 0x64 - bl __divsi3 - strh r0, [r5, 0x2E] - ldrh r0, [r5, 0x34] - adds r0, 0x1 - strh r0, [r5, 0x34] -_0807E5AA: - movs r1, 0x20 - ldrsh r0, [r5, r1] - cmp r0, 0x78 - bne _0807E5B6 - movs r0, 0 - strh r0, [r5, 0x30] -_0807E5B6: - ldrh r0, [r5, 0x36] - ldrh r2, [r5, 0x2E] - adds r0, r2 - strh r0, [r5, 0x2E] - movs r1, 0x34 - ldrsh r0, [r5, r1] - cmp r0, 0x4 - bne _0807E5CE - movs r0, 0x1 - strh r0, [r5, 0x3C] - ldr r0, =SpriteCallbackDummy - str r0, [r5, 0x1C] -_0807E5CE: - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_807E55C - - thumb_func_start sub_807E5D8 -sub_807E5D8: @ 807E5D8 - push {r4,lr} - sub sp, 0x4 - adds r4, r0, 0 - ldr r1, =gUnknown_08339024 - movs r2, 0x2E - ldrsh r0, [r4, r2] - adds r0, r1 - ldrb r0, [r0] - lsls r0, 24 - asrs r0, 24 - ldrh r1, [r4, 0x26] - adds r0, r1 - strh r0, [r4, 0x26] - movs r2, 0x2E - ldrsh r0, [r4, r2] - cmp r0, 0x16 - bne _0807E600 - movs r0, 0x38 - bl PlaySE -_0807E600: - ldrh r0, [r4, 0x2E] - adds r0, 0x1 - strh r0, [r4, 0x2E] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0x2C - bne _0807E636 - movs r0, 0x8C - bl PlaySE - ldr r0, =sub_807E64C - str r0, [r4, 0x1C] - movs r0, 0 - strh r0, [r4, 0x2E] - ldrb r1, [r4, 0x5] - lsrs r1, 4 - adds r1, 0x10 - movs r0, 0x1 - lsls r0, r1 - movs r1, 0x1 - negs r1, r1 - ldr r2, =0x0000ffff - str r2, [sp] - movs r2, 0 - movs r3, 0x10 - bl BeginNormalPaletteFade -_0807E636: - add sp, 0x4 - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_807E5D8 - - thumb_func_start sub_807E64C -sub_807E64C: @ 807E64C - push {r4,lr} - adds r4, r0, 0 - movs r1, 0x30 - ldrsh r0, [r4, r1] - cmp r0, 0x14 - bne _0807E660 - adds r0, r4, 0 - movs r1, 0x1 - bl StartSpriteAffineAnim -_0807E660: - ldrh r0, [r4, 0x30] - adds r0, 0x1 - strh r0, [r4, 0x30] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0x14 - ble _0807E69E - ldr r1, =gUnknown_08339024 - movs r2, 0x2E - ldrsh r0, [r4, r2] - adds r0, r1 - movs r1, 0 - ldrsb r1, [r0, r1] - ldrh r0, [r4, 0x26] - subs r0, r1 - strh r0, [r4, 0x26] - ldrh r0, [r4, 0x2E] - adds r0, 0x1 - strh r0, [r4, 0x2E] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0x17 - bne _0807E69E - adds r0, r4, 0 - bl DestroySprite - ldr r0, =gUnknown_020322A0 - ldr r0, [r0] - adds r0, 0x94 - movs r1, 0xE - strh r1, [r0] -_0807E69E: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_807E64C - - thumb_func_start sub_807E6AC -sub_807E6AC: @ 807E6AC - push {r4,lr} - adds r4, r0, 0 - ldrh r2, [r4, 0x32] - movs r1, 0x32 - ldrsh r0, [r4, r1] - cmp r0, 0 - bne _0807E6DC - ldrh r0, [r4, 0x22] - adds r0, 0x4 - strh r0, [r4, 0x22] - lsls r0, 16 - asrs r0, 16 - movs r3, 0x34 - ldrsh r1, [r4, r3] - cmp r0, r1 - ble _0807E72C - adds r0, r2, 0x1 - strh r0, [r4, 0x32] - movs r0, 0x16 - strh r0, [r4, 0x2E] - movs r0, 0x38 - bl PlaySE - b _0807E72C -_0807E6DC: - movs r1, 0x2E - ldrsh r0, [r4, r1] - cmp r0, 0x42 - bne _0807E6EA - movs r0, 0x39 - bl PlaySE -_0807E6EA: - movs r2, 0x2E - ldrsh r0, [r4, r2] - cmp r0, 0x5C - bne _0807E6F8 - movs r0, 0x3A - bl PlaySE -_0807E6F8: - movs r3, 0x2E - ldrsh r0, [r4, r3] - cmp r0, 0x6B - bne _0807E706 - movs r0, 0x3B - bl PlaySE -_0807E706: - ldr r1, =gUnknown_08339024 - movs r2, 0x2E - ldrsh r0, [r4, r2] - adds r0, r1 - ldrb r0, [r0] - lsls r0, 24 - asrs r0, 24 - ldrh r3, [r4, 0x26] - adds r0, r3 - strh r0, [r4, 0x26] - ldrh r0, [r4, 0x2E] - adds r0, 0x1 - strh r0, [r4, 0x2E] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0x6C - bne _0807E72C - ldr r0, =SpriteCallbackDummy - str r0, [r4, 0x1C] -_0807E72C: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_807E6AC - - thumb_func_start sub_807E73C -sub_807E73C: @ 807E73C - push {r4-r6,lr} - ldr r0, =gSpecialVar_0x8004 - ldrh r0, [r0] - lsls r4, r0, 4 - subs r4, r0 - lsls r4, 2 - ldr r0, =gIngameTrades - adds r4, r0 - ldr r0, =gStringVar1 - ldrh r1, [r4, 0x38] - movs r6, 0xB - muls r1, r6 - ldr r5, =gSpeciesNames - adds r1, r5 - bl StringCopy - ldr r0, =gStringVar2 - ldrh r1, [r4, 0xC] - muls r1, r6 - adds r1, r5 - bl StringCopy - ldrh r0, [r4, 0x38] - pop {r4-r6} - pop {r1} - bx r1 - .pool - thumb_func_end sub_807E73C - - thumb_func_start sub_807E784 -sub_807E784: @ 807E784 - push {r4,lr} - sub sp, 0x20 - ldr r0, =gSpecialVar_0x8004 - ldrh r0, [r0] - lsls r4, r0, 4 - subs r4, r0 - lsls r4, 2 - ldr r0, =gIngameTrades - adds r4, r0 - ldr r0, =gSpecialVar_0x8005 - ldrh r1, [r0] - movs r0, 0x64 - muls r0, r1 - ldr r1, =gPlayerParty - adds r0, r1 - movs r1, 0x2 - mov r2, sp - bl GetMonData - ldr r0, =gStringVar1 - mov r1, sp - bl StringCopy10 - ldr r0, =gStringVar2 - ldrh r2, [r4, 0xC] - movs r1, 0xB - muls r1, r2 - ldr r2, =gSpeciesNames - adds r1, r2 - bl StringCopy - add sp, 0x20 - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_807E784 - - thumb_func_start sub_807E7E8 -sub_807E7E8: @ 807E7E8 - push {r4-r7,lr} - sub sp, 0x38 - lsls r0, 24 - lsrs r0, 24 - lsls r1, 24 - lsrs r1, 24 - lsls r2, r1, 4 - subs r2, r1 - lsls r2, 2 - ldr r1, =gIngameTrades - adds r5, r2, r1 - movs r1, 0x64 - muls r0, r1 - ldr r1, =gPlayerParty - adds r0, r1 - movs r1, 0x38 - bl GetMonData - adds r2, r0, 0 - lsls r2, 24 - lsrs r2, 24 - add r4, sp, 0x34 - movs r0, 0xFE - strb r0, [r4] - ldr r6, =gEnemyParty - ldrh r1, [r5, 0xC] - movs r3, 0x1 - str r3, [sp] - ldr r0, [r5, 0x24] - str r0, [sp, 0x4] - str r3, [sp, 0x8] - ldr r0, [r5, 0x18] - str r0, [sp, 0xC] - adds r0, r6, 0 - movs r3, 0x20 - bl CreateMon - adds r2, r5, 0 - adds r2, 0xE - adds r0, r6, 0 - movs r1, 0x27 - bl SetMonData - adds r2, r5, 0 - adds r2, 0xF - adds r0, r6, 0 - movs r1, 0x28 - bl SetMonData - adds r2, r5, 0 - adds r2, 0x10 - adds r0, r6, 0 - movs r1, 0x29 - bl SetMonData - adds r2, r5, 0 - adds r2, 0x11 - adds r0, r6, 0 - movs r1, 0x2A - bl SetMonData - adds r2, r5, 0 - adds r2, 0x12 - adds r0, r6, 0 - movs r1, 0x2B - bl SetMonData - adds r2, r5, 0 - adds r2, 0x13 - adds r0, r6, 0 - movs r1, 0x2C - bl SetMonData - adds r0, r6, 0 - movs r1, 0x2 - adds r2, r5, 0 - bl SetMonData - adds r2, r5, 0 - adds r2, 0x2B - adds r0, r6, 0 - movs r1, 0x7 - bl SetMonData - adds r2, r5, 0 - adds r2, 0x36 - adds r0, r6, 0 - movs r1, 0x31 - bl SetMonData - adds r2, r5, 0 - adds r2, 0x14 - adds r0, r6, 0 - movs r1, 0x2E - bl SetMonData - adds r2, r5, 0 - adds r2, 0x1D - adds r0, r6, 0 - movs r1, 0x17 - bl SetMonData - adds r2, r5, 0 - adds r2, 0x1E - adds r0, r6, 0 - movs r1, 0x18 - bl SetMonData - adds r2, r5, 0 - adds r2, 0x1C - adds r0, r6, 0 - movs r1, 0x16 - bl SetMonData - adds r2, r5, 0 - adds r2, 0x1F - adds r0, r6, 0 - movs r1, 0x21 - bl SetMonData - adds r2, r5, 0 - adds r2, 0x20 - adds r0, r6, 0 - movs r1, 0x2F - bl SetMonData - adds r2, r5, 0 - adds r2, 0x37 - adds r0, r6, 0 - movs r1, 0x30 - bl SetMonData - adds r0, r6, 0 - movs r1, 0x23 - adds r2, r4, 0 - bl SetMonData - mov r4, sp - adds r4, 0x35 - movs r0, 0 - strb r0, [r4] - ldrh r0, [r5, 0x28] - cmp r0, 0 - beq _0807E960 - bl ItemIsMail - lsls r0, 24 - cmp r0, 0 - beq _0807E954 - add r0, sp, 0x10 - adds r1, r5, 0 - bl sub_807E974 - ldr r0, =gUnknown_020321C0 - add r1, sp, 0x10 - ldm r1!, {r2,r3,r7} - stm r0!, {r2,r3,r7} - ldm r1!, {r2,r3,r7} - stm r0!, {r2,r3,r7} - ldm r1!, {r2,r3,r7} - stm r0!, {r2,r3,r7} - adds r0, r6, 0 - movs r1, 0x40 - adds r2, r4, 0 - bl SetMonData - adds r2, r5, 0 - adds r2, 0x28 - adds r0, r6, 0 - movs r1, 0xC - bl SetMonData - b _0807E960 - .pool -_0807E954: - adds r2, r5, 0 - adds r2, 0x28 - adds r0, r6, 0 - movs r1, 0xC - bl SetMonData -_0807E960: - ldr r0, =gEnemyParty - bl CalculateMonStats - add sp, 0x38 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_807E7E8 - - thumb_func_start sub_807E974 -sub_807E974: @ 807E974 - push {r4-r6,lr} - adds r5, r0, 0 - adds r6, r1, 0 - ldr r2, =gUnknown_08338FC0 - adds r0, r6, 0 - adds r0, 0x2A - ldrb r1, [r0] - lsls r0, r1, 2 - adds r0, r1 - lsls r0, 2 - adds r2, r0, r2 - adds r1, r5, 0 - movs r3, 0x8 -_0807E98E: - ldrh r0, [r2] - strh r0, [r1] - adds r2, 0x2 - adds r1, 0x2 - subs r3, 0x1 - cmp r3, 0 - bge _0807E98E - adds r4, r5, 0 - adds r4, 0x12 - adds r1, r6, 0 - adds r1, 0x2B - adds r0, r4, 0 - bl StringCopy - adds r0, r4, 0 - movs r1, 0 - bl PadNameString - ldr r1, [r6, 0x18] - lsrs r0, r1, 24 - strb r0, [r5, 0x1A] - lsrs r0, r1, 16 - strb r0, [r5, 0x1B] - lsrs r0, r1, 8 - strb r0, [r5, 0x1C] - strb r1, [r5, 0x1D] - ldrh r0, [r6, 0xC] - strh r0, [r5, 0x1E] - ldrh r0, [r6, 0x28] - strh r0, [r5, 0x20] - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_807E974 - - thumb_func_start sub_807E9D4 -sub_807E9D4: @ 807E9D4 - push {r4-r6,lr} - ldr r6, =gSpecialVar_0x8005 - ldrh r0, [r6] - movs r5, 0x64 - muls r0, r5 - ldr r4, =gPlayerParty - adds r0, r4 - movs r1, 0x2D - bl GetMonData - cmp r0, 0 - bne _0807EA08 - ldrh r0, [r6] - muls r0, r5 - adds r0, r4 - movs r1, 0xB - bl GetMonData - lsls r0, 16 - lsrs r0, 16 - b _0807EA0A - .pool -_0807EA08: - movs r0, 0 -_0807EA0A: - pop {r4-r6} - pop {r1} - bx r1 - thumb_func_end sub_807E9D4 - - thumb_func_start sub_807EA10 -sub_807EA10: @ 807EA10 - push {lr} - ldr r0, =gSpecialVar_0x8005 - ldrb r0, [r0] - ldr r1, =gSpecialVar_0x8004 - ldrb r1, [r1] - bl sub_807E7E8 - pop {r0} - bx r0 - .pool - thumb_func_end sub_807EA10 - - thumb_func_start sub_807EA2C -sub_807EA2C: @ 807EA2C - push {r4-r6,lr} - bl sub_807BBC8 - lsls r0, 24 - lsrs r6, r0, 24 - cmp r6, 0x1 - bne _0807EA96 - ldr r5, =gUnknown_020322A0 - ldr r0, [r5] - adds r0, 0x8E - ldrb r1, [r0] - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - ldr r4, =gSprites - adds r0, r4 - bl DestroySprite - ldr r0, [r5] - adds r0, 0x8F - ldrb r1, [r0] - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - adds r0, r4 - bl FreeSpriteOamMatrix - ldr r0, =gUnknown_02032298 - ldrb r4, [r0] - ldrb r0, [r0, 0x1] - movs r1, 0x6 - bl __umodsi3 - adds r1, r0, 0 - lsls r1, 24 - lsrs r1, 24 - adds r0, r4, 0 - bl sub_807B4D0 - bl sub_8077260 - cmp r0, 0 - bne _0807EA90 - ldr r0, [r5] - adds r2, r0, 0 - adds r2, 0x74 - ldr r1, =0x0000abcd - strh r1, [r2] - adds r0, 0x93 - strb r6, [r0] -_0807EA90: - ldr r0, =sub_807EACC - bl SetMainCallback2 -_0807EA96: - bl sub_807B5B8 - bl sub_807E4DC - bl RunTasks - bl RunTextPrinters - bl AnimateSprites - bl BuildOamBuffer - bl UpdatePaletteFade - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_807EA2C - - thumb_func_start sub_807EACC -sub_807EACC: @ 807EACC - push {r4,lr} - bl sub_807ACDC - lsls r0, 24 - lsrs r4, r0, 24 - bl sub_8077260 - cmp r0, 0 - beq _0807EAEC - ldr r0, =c2_08053788 - bl SetMainCallback2 - b _0807EB2C - .pool -_0807EAEC: - bl sub_807E4DC - cmp r4, 0 - bne _0807EB2C - ldr r4, =gUnknown_020322A0 - ldr r2, [r4] - adds r0, r2, 0 - adds r0, 0x72 - ldrh r1, [r0] - ldr r0, =0x00000101 - cmp r1, r0 - bne _0807EB2C - adds r1, r2, 0 - adds r1, 0x74 - ldr r0, =0x0000dcba - strh r0, [r1] - bl bitmask_all_link_players_but_self - lsls r0, 24 - lsrs r0, 24 - ldr r1, [r4] - adds r1, 0x74 - movs r2, 0x14 - bl SendBlock - ldr r0, [r4] - adds r0, 0x72 - movs r1, 0x2 - strb r1, [r0] - ldr r0, [r4] - adds r0, 0x73 - strb r1, [r0] -_0807EB2C: - bl RunTasks - bl AnimateSprites - bl BuildOamBuffer - bl UpdatePaletteFade - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_807EACC - - thumb_func_start sub_807EB50 -sub_807EB50: @ 807EB50 - push {r4,lr} - sub sp, 0x4 - ldr r1, =gMain - movs r2, 0x87 - lsls r2, 3 - adds r0, r1, r2 - ldrb r0, [r0] - adds r2, r1, 0 - cmp r0, 0x65 - bls _0807EB66 - b _0807F03A -_0807EB66: - lsls r0, 2 - ldr r1, =_0807EB78 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_0807EB78: - .4byte _0807ED10 - .4byte _0807ED2C - .4byte _0807ED98 - .4byte _0807F03A - .4byte _0807EE78 - .4byte _0807EF3C - .4byte _0807EF64 - .4byte _0807EF7E - .4byte _0807EFA4 - .4byte _0807EFF0 - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807EE9C - .4byte _0807EEEC - .4byte _0807EF1A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807EDC0 - .4byte _0807EE1C - .4byte _0807EE38 - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807F03A - .4byte _0807ED44 - .4byte _0807ED7C -_0807ED10: - movs r0, 0x87 - lsls r0, 3 - adds r1, r2, r0 - ldrb r0, [r1] - adds r0, 0x1 - strb r0, [r1] - ldr r4, =gStringVar4 - ldr r1, =gText_CommunicationStandby5 - b _0807EDA6 - .pool -_0807ED2C: - movs r0, 0 - bl sub_8077288 - ldr r0, =gMain - movs r1, 0x87 - lsls r1, 3 - adds r0, r1 - movs r2, 0 - movs r1, 0x64 - b _0807EE88 - .pool -_0807ED44: - ldr r0, =gUnknown_020322A0 - ldr r3, [r0] - ldr r0, [r3, 0x64] - adds r0, 0x1 - str r0, [r3, 0x64] - cmp r0, 0xB4 - bls _0807ED60 - movs r1, 0x87 - lsls r1, 3 - adds r0, r2, r1 - movs r2, 0 - movs r1, 0x65 - strb r1, [r0] - str r2, [r3, 0x64] -_0807ED60: - bl sub_8077294 - cmp r0, 0 - bne _0807ED6A - b _0807F03A -_0807ED6A: - ldr r0, =gMain - movs r2, 0x87 - lsls r2, 3 - adds r0, r2 - b _0807ED8E - .pool -_0807ED7C: - bl sub_8077294 - cmp r0, 0 - bne _0807ED86 - b _0807F03A -_0807ED86: - ldr r0, =gMain - movs r1, 0x87 - lsls r1, 3 - adds r0, r1 -_0807ED8E: - movs r1, 0x2 - strb r1, [r0] - b _0807F03A - .pool -_0807ED98: - movs r0, 0x87 - lsls r0, 3 - adds r1, r2, r0 - movs r0, 0x32 - strb r0, [r1] - ldr r4, =gStringVar4 - ldr r1, =gText_SavingDontTurnOffPower -_0807EDA6: - adds r0, r4, 0 - bl StringExpandPlaceholders - movs r0, 0 - adds r1, r4, 0 - movs r2, 0 - bl sub_807F1A8 - b _0807F03A - .pool -_0807EDC0: - bl InUnionRoom - cmp r0, 0 - bne _0807EDCE - movs r0, 0x15 - bl IncrementGameStat -_0807EDCE: - ldr r0, =gWirelessCommType - ldrb r0, [r0] - cmp r0, 0 - beq _0807EDF6 - ldr r4, =gLinkPlayers - bl GetMultiplayerId - movs r1, 0x1 - eors r0, r1 - lsls r0, 24 - lsrs r0, 24 - lsls r1, r0, 3 - subs r1, r0 - lsls r1, 2 - adds r4, 0x4 - adds r1, r4 - ldr r1, [r1] - movs r0, 0x2 - bl sub_801B990 -_0807EDF6: - bl sub_8076D5C - bl sub_8153380 - ldr r1, =gMain - movs r2, 0x87 - lsls r2, 3 - adds r1, r2 - ldrb r0, [r1] - adds r0, 0x1 - movs r2, 0 - strb r0, [r1] - b _0807EE8A - .pool -_0807EE1C: - ldr r0, =gUnknown_020322A0 - ldr r1, [r0] - ldr r0, [r1, 0x64] - adds r0, 0x1 - str r0, [r1, 0x64] - cmp r0, 0x5 - beq _0807EE2C - b _0807F03A -_0807EE2C: - movs r0, 0x87 - lsls r0, 3 - adds r1, r2, r0 - b _0807EFE4 - .pool -_0807EE38: - bl sub_81533AC - lsls r0, 24 - lsrs r1, r0, 24 - cmp r1, 0 - beq _0807EE5C - bl sav2_gender2_inplace_and_xFE - ldr r0, =gMain - movs r1, 0x87 - lsls r1, 3 - adds r0, r1 - movs r1, 0x4 - strb r1, [r0] - b _0807F03A - .pool -_0807EE5C: - ldr r0, =gUnknown_020322A0 - ldr r0, [r0] - str r1, [r0, 0x64] - ldr r0, =gMain - movs r2, 0x87 - lsls r2, 3 - adds r0, r2 - movs r1, 0x33 - strb r1, [r0] - b _0807F03A - .pool -_0807EE78: - bl sub_81533E0 - ldr r0, =gMain - movs r1, 0x87 - lsls r1, 3 - adds r0, r1 - movs r2, 0 - movs r1, 0x28 -_0807EE88: - strb r1, [r0] -_0807EE8A: - ldr r0, =gUnknown_020322A0 - ldr r0, [r0] - str r2, [r0, 0x64] - b _0807F03A - .pool -_0807EE9C: - ldr r4, =gUnknown_020322A0 - ldr r1, [r4] - ldr r0, [r1, 0x64] - adds r0, 0x1 - str r0, [r1, 0x64] - cmp r0, 0x32 - bhi _0807EEAC - b _0807F03A -_0807EEAC: - bl GetMultiplayerId - lsls r0, 24 - cmp r0, 0 - bne _0807EED4 - bl Random - ldr r4, [r4] - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x1E - bl __umodsi3 - lsls r0, 16 - lsrs r0, 16 - str r0, [r4, 0x64] - b _0807EEDA - .pool -_0807EED4: - ldr r1, [r4] - movs r0, 0 - str r0, [r1, 0x64] -_0807EEDA: - ldr r0, =gMain - movs r2, 0x87 - lsls r2, 3 - adds r0, r2 - movs r1, 0x29 - strb r1, [r0] - b _0807F03A - .pool -_0807EEEC: - ldr r0, =gUnknown_020322A0 - ldr r1, [r0] - ldr r0, [r1, 0x64] - cmp r0, 0 - bne _0807EF14 - movs r0, 0x1 - bl sub_8077288 - ldr r0, =gMain - movs r1, 0x87 - lsls r1, 3 - adds r0, r1 - movs r1, 0x2A - strb r1, [r0] - b _0807F03A - .pool -_0807EF14: - subs r0, 0x1 - str r0, [r1, 0x64] - b _0807F03A -_0807EF1A: - bl sub_8077294 - cmp r0, 0 - bne _0807EF24 - b _0807F03A -_0807EF24: - bl sub_8153408 - ldr r0, =gMain - movs r2, 0x87 - lsls r2, 3 - adds r0, r2 - movs r1, 0x5 - strb r1, [r0] - b _0807F03A - .pool -_0807EF3C: - ldr r0, =gUnknown_020322A0 - ldr r1, [r0] - ldr r0, [r1, 0x64] - adds r0, 0x1 - str r0, [r1, 0x64] - cmp r0, 0x3C - bls _0807F03A - movs r0, 0x87 - lsls r0, 3 - adds r1, r2, r0 - ldrb r0, [r1] - adds r0, 0x1 - strb r0, [r1] - movs r0, 0x2 - bl sub_8077288 - b _0807F03A - .pool -_0807EF64: - bl sub_8077294 - cmp r0, 0 - beq _0807F03A - movs r0, 0x1 - negs r0, r0 - movs r1, 0 - str r1, [sp] - movs r2, 0 - movs r3, 0x10 - bl BeginNormalPaletteFade - b _0807EFDC -_0807EF7E: - ldr r0, =gPaletteFade - ldrb r1, [r0, 0x7] - movs r0, 0x80 - ands r0, r1 - cmp r0, 0 - bne _0807F03A - movs r0, 0x3 - bl FadeOutBGM - ldr r1, =gMain - movs r0, 0x87 - lsls r0, 3 - adds r1, r0 - b _0807EFE4 - .pool -_0807EFA4: - bl IsBGMStopped - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1 - bne _0807F03A - ldr r0, =gWirelessCommType - ldrb r0, [r0] - cmp r0, 0 - beq _0807EFD8 - ldr r0, =gMain - ldr r1, [r0, 0x8] - ldr r0, =sub_80773AC - cmp r1, r0 - bne _0807EFD8 - movs r0, 0x3 - bl sub_8077288 - b _0807EFDC - .pool -_0807EFD8: - bl sub_800AC34 -_0807EFDC: - ldr r1, =gMain - movs r2, 0x87 - lsls r2, 3 - adds r1, r2 -_0807EFE4: - ldrb r0, [r1] - adds r0, 0x1 - strb r0, [r1] - b _0807F03A - .pool -_0807EFF0: - ldr r0, =gWirelessCommType - ldrb r0, [r0] - cmp r0, 0 - beq _0807F028 - ldr r1, [r2, 0x8] - ldr r0, =sub_80773AC - cmp r1, r0 - bne _0807F028 - bl sub_8077294 - cmp r0, 0 - beq _0807F03A - ldr r0, =gSoftResetDisabled - movs r1, 0 - strb r1, [r0] - ldr r0, =c2_080543C4 - bl SetMainCallback2 - b _0807F03A - .pool -_0807F028: - ldr r0, =gReceivedRemoteLinkPlayers - ldrb r1, [r0] - cmp r1, 0 - bne _0807F03A - ldr r0, =gSoftResetDisabled - strb r1, [r0] - ldr r0, =c2_080543C4 - bl SetMainCallback2 -_0807F03A: - bl HasLinkErrorOccurred - lsls r0, 24 - cmp r0, 0 - bne _0807F048 - bl RunTasks -_0807F048: - bl AnimateSprites - bl BuildOamBuffer - bl UpdatePaletteFade - add sp, 0x4 - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_807EB50 - - thumb_func_start c2_080543C4 -c2_080543C4: @ 807F068 - push {r4,r5,lr} - ldr r0, =gPaletteFade - ldrb r1, [r0, 0x7] - movs r0, 0x80 - ands r0, r1 - lsls r0, 24 - lsrs r5, r0, 24 - cmp r5, 0 - bne _0807F0BE - bl FreeAllWindowBuffers - movs r0, 0x3 - bl GetBgTilemapBuffer - bl Free - movs r0, 0x1 - bl GetBgTilemapBuffer - bl Free - movs r0, 0 - bl GetBgTilemapBuffer - bl Free - bl FreeMonSpritesGfx - ldr r4, =gUnknown_020322A0 - ldr r0, [r4] - bl Free - str r5, [r4] - ldr r0, =gWirelessCommType - ldrb r0, [r0] - cmp r0, 0 - beq _0807F0B6 - bl sub_800E084 -_0807F0B6: - ldr r0, =gMain - ldr r0, [r0, 0x8] - bl SetMainCallback2 -_0807F0BE: - bl RunTasks - bl AnimateSprites - bl BuildOamBuffer - bl UpdatePaletteFade - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end c2_080543C4 - - thumb_func_start sub_807F0E4 -sub_807F0E4: @ 807F0E4 - push {lr} - sub sp, 0x4 - bl ScriptContext2_Enable - ldr r0, =sub_807F110 - movs r1, 0xA - bl CreateTask - movs r0, 0x1 - negs r0, r0 - movs r1, 0 - str r1, [sp] - movs r2, 0 - movs r3, 0x10 - bl BeginNormalPaletteFade - add sp, 0x4 - pop {r0} - bx r0 - .pool - thumb_func_end sub_807F0E4 - - thumb_func_start sub_807F110 -sub_807F110: @ 807F110 - push {r4,lr} - lsls r0, 24 - lsrs r4, r0, 24 - ldr r0, =gPaletteFade - ldrb r1, [r0, 0x7] - movs r0, 0x80 - ands r0, r1 - cmp r0, 0 - bne _0807F134 - ldr r0, =sub_807B270 - bl SetMainCallback2 - ldr r1, =gFieldCallback - ldr r0, =sub_80AF168 - str r0, [r1] - adds r0, r4, 0 - bl DestroyTask -_0807F134: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_807F110 - - thumb_func_start sub_807F14C -sub_807F14C: @ 807F14C - push {r4,r5,lr} - movs r5, 0 - movs r4, 0 -_0807F152: - ldr r0, =gUnknown_02032298 - ldrb r0, [r0, 0x1] - movs r1, 0x6 - bl __umodsi3 - lsls r0, 24 - lsrs r0, 24 - movs r1, 0x64 - muls r0, r1 - ldr r1, =gEnemyParty - adds r0, r1 - adds r1, r4, 0 - adds r1, 0x43 - bl GetMonData - adds r0, r5, r0 - lsls r0, 24 - lsrs r5, r0, 24 - adds r0, r4, 0x1 - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0xB - bls _0807F152 - cmp r5, 0 - beq _0807F18A - ldr r0, =0x0000089b - bl FlagSet -_0807F18A: - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_807F14C - - thumb_func_start sub_807F19C -sub_807F19C: @ 807F19C - push {lr} - bl sub_807B170 - pop {r0} - bx r0 - thumb_func_end sub_807F19C - - thumb_func_start sub_807F1A8 -sub_807F1A8: @ 807F1A8 - push {r4-r6,lr} - sub sp, 0x14 - adds r5, r0, 0 - adds r6, r1, 0 - adds r4, r2, 0 - lsls r5, 24 - lsrs r5, 24 - lsls r4, 24 - lsrs r4, 24 - adds r0, r5, 0 - movs r1, 0xFF - bl FillWindowPixelBuffer - ldr r2, =gUnknown_020322A0 - ldr r0, [r2] - adds r0, 0xF6 - movs r3, 0 - movs r1, 0xF - strb r1, [r0] - ldr r0, [r2] - adds r0, 0xF7 - movs r1, 0x1 - strb r1, [r0] - ldr r0, [r2] - adds r0, 0xF8 - movs r1, 0x6 - strb r1, [r0] - str r3, [sp] - str r3, [sp, 0x4] - ldr r0, [r2] - adds r0, 0xF6 - str r0, [sp, 0x8] - lsls r4, 24 - asrs r4, 24 - str r4, [sp, 0xC] - str r6, [sp, 0x10] - adds r0, r5, 0 - movs r1, 0x1 - movs r2, 0 - movs r3, 0x2 - bl AddTextPrinterParameterized4 - adds r0, r5, 0 - movs r1, 0x3 - bl CopyWindowToVram - add sp, 0x14 - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_807F1A8 - - thumb_func_start c3_08054588 -c3_08054588: @ 807F210 - push {r4,r5,lr} - lsls r0, 24 - lsrs r5, r0, 24 - lsls r0, r5, 2 - adds r0, r5 - lsls r0, 3 - ldr r1, =gTasks + 0x8 - adds r4, r0, r1 - ldr r1, =gUnknown_08339090 - movs r2, 0 - ldrsh r0, [r4, r2] - lsls r0, 1 - adds r0, r1 - ldrb r0, [r0] - lsls r1, r0, 4 - adds r2, r1, 0 - movs r3, 0x4 - ldrsh r0, [r4, r3] - cmp r0, 0 - bne _0807F254 - movs r0, 0x80 - lsls r0, 1 - cmp r1, r0 - beq _0807F25C - lsls r0, r1, 1 - ldr r1, =gUnknown_08337AA0 - adds r0, r1 - b _0807F25E - .pool -_0807F254: - movs r0, 0x80 - lsls r0, 1 - cmp r1, r0 - bne _0807F26C -_0807F25C: - ldr r0, =gUnknown_08337EA0 -_0807F25E: - movs r1, 0x30 - movs r2, 0x20 - bl LoadPalette - b _0807F27A - .pool -_0807F26C: - lsls r0, r2, 1 - ldr r1, =gUnknown_08337CA0 - adds r0, r1 - movs r1, 0x30 - movs r2, 0x20 - bl LoadPalette -_0807F27A: - ldr r0, =gUnknown_08339090 - movs r2, 0 - ldrsh r1, [r4, r2] - lsls r1, 1 - adds r1, r0 - ldrb r0, [r1] - cmp r0, 0 - bne _0807F298 - movs r3, 0x2 - ldrsh r0, [r4, r3] - cmp r0, 0 - bne _0807F298 - movs r0, 0xC3 - bl PlaySE -_0807F298: - movs r0, 0x2 - ldrsh r2, [r4, r0] - ldr r1, =gUnknown_08339090 - movs r3, 0 - ldrsh r0, [r4, r3] - lsls r0, 1 - adds r1, 0x1 - adds r0, r1 - ldrb r0, [r0] - cmp r2, r0 - bne _0807F2D8 - ldrh r0, [r4] - adds r0, 0x1 - strh r0, [r4] - movs r0, 0 - strh r0, [r4, 0x2] - movs r2, 0 - ldrsh r0, [r4, r2] - lsls r0, 1 - adds r0, r1 - ldrb r0, [r0] - cmp r0, 0xFF - bne _0807F2DE - adds r0, r5, 0 - bl DestroyTask - b _0807F2DE - .pool -_0807F2D8: - ldrh r0, [r4, 0x2] - adds r0, 0x1 - strh r0, [r4, 0x2] -_0807F2DE: - pop {r4,r5} - pop {r0} - bx r0 - thumb_func_end c3_08054588 - - thumb_func_start c3_0805465C -c3_0805465C: @ 807F2E4 - push {r4-r6,lr} - lsls r0, 24 - lsrs r0, 24 - adds r6, r0, 0 - lsls r0, r6, 2 - adds r0, r6 - lsls r0, 3 - ldr r1, =gTasks + 0x8 - adds r5, r0, r1 - movs r0, 0 - ldrsh r4, [r5, r0] - cmp r4, 0 - bne _0807F336 - ldr r2, =gUnknown_020322A0 - ldr r0, [r2] - adds r3, r0, 0 - adds r3, 0xFD - movs r1, 0x78 - strb r1, [r3] - adds r0, 0xFB - strb r1, [r0] - ldr r0, [r2] - adds r0, 0xFC - strb r4, [r0] - ldr r0, [r2] - adds r0, 0xFE - movs r1, 0xA0 - strb r1, [r0] - movs r1, 0x80 - lsls r1, 6 - movs r0, 0 - bl SetGpuRegBits - movs r0, 0x4A - movs r1, 0x10 - bl SetGpuReg - movs r0, 0x48 - movs r1, 0x13 - bl SetGpuReg -_0807F336: - ldr r4, =gUnknown_020322A0 - ldr r0, [r4] - adds r1, r0, 0 - adds r1, 0xFD - ldrb r1, [r1] - adds r0, 0xFB - ldrb r0, [r0] - lsls r0, 8 - orrs r1, r0 - movs r0, 0x40 - bl SetGpuReg - ldr r0, [r4] - adds r1, r0, 0 - adds r1, 0xFE - ldrb r1, [r1] - adds r0, 0xFC - ldrb r0, [r0] - lsls r0, 8 - orrs r1, r0 - movs r0, 0x44 - bl SetGpuReg - ldrh r0, [r5] - adds r0, 0x1 - strh r0, [r5] - ldr r1, [r4] - adds r1, 0xFB - ldrb r0, [r1] - subs r0, 0x5 - strb r0, [r1] - ldr r1, [r4] - adds r1, 0xFD - ldrb r0, [r1] - adds r0, 0x5 - strb r0, [r1] - ldr r0, [r4] - adds r0, 0xFB - ldrb r0, [r0] - cmp r0, 0x4F - bhi _0807F38E - adds r0, r6, 0 - bl DestroyTask -_0807F38E: - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end c3_0805465C - thumb_func_start sub_807F39C sub_807F39C: @ 807F39C push {r4-r6,lr} @@ -1875,7 +163,7 @@ _0807F4E8: b _0807F5BC .pool _0807F500: - bl sub_8077294 + bl IsLinkTaskFinished cmp r0, 0 bne _0807F50A b _0807F70C @@ -2020,7 +308,7 @@ _0807F648: str r0, [r1, 0x64] b _0807F70C _0807F64E: - bl sub_8077294 + bl IsLinkTaskFinished cmp r0, 0 beq _0807F70C bl sub_8153408 @@ -2051,7 +339,7 @@ _0807F66C: b _0807F70C .pool _0807F694: - bl sub_8077294 + bl IsLinkTaskFinished cmp r0, 0 beq _0807F70C movs r0, 0x3 @@ -2094,7 +382,7 @@ _0807F6C4: b _0807F70C .pool _0807F6F8: - bl sub_8077294 + bl IsLinkTaskFinished cmp r0, 0 beq _0807F70C ldr r0, =gSoftResetDisabled diff --git a/data/maps/BattleFrontier_Lounge6/scripts.inc b/data/maps/BattleFrontier_Lounge6/scripts.inc index 3c1852283..411291e7d 100644 --- a/data/maps/BattleFrontier_Lounge6/scripts.inc +++ b/data/maps/BattleFrontier_Lounge6/scripts.inc @@ -7,7 +7,7 @@ BattleFrontier_Lounge6_EventScript_264FED:: @ 8264FED goto_if_set FLAG_0x09C, BattleFrontier_Lounge6_EventScript_265083 setvar VAR_0x8008, 3 copyvar VAR_0x8004, VAR_0x8008 - specialvar VAR_RESULT, sub_807E73C + specialvar VAR_RESULT, GetInGameTradeSpeciesInfo copyvar VAR_0x8009, VAR_RESULT msgbox BattleFrontier_Lounge6_Text_26508D, MSGBOX_YESNO compare VAR_RESULT, 0 @@ -18,14 +18,14 @@ BattleFrontier_Lounge6_EventScript_264FED:: @ 8264FED compare VAR_0x8004, 255 goto_if_eq BattleFrontier_Lounge6_EventScript_26506B copyvar VAR_0x8005, VAR_0x800A - specialvar VAR_RESULT, sub_807E9D4 + specialvar VAR_RESULT, GetTradeSpecies copyvar VAR_0x800B, VAR_RESULT compare VAR_RESULT, VAR_0x8009 goto_if_ne BattleFrontier_Lounge6_EventScript_265075 copyvar VAR_0x8004, VAR_0x8008 copyvar VAR_0x8005, VAR_0x800A - special sub_807EA10 - special sub_807F0E4 + special CreateInGameTradePokemon + special DoInGameTradeScene waitstate msgbox BattleFrontier_Lounge6_Text_265128, MSGBOX_DEFAULT setflag FLAG_0x09C diff --git a/data/maps/FortreeCity_House1/scripts.inc b/data/maps/FortreeCity_House1/scripts.inc index 44651ae0d..a1fe9b0d3 100644 --- a/data/maps/FortreeCity_House1/scripts.inc +++ b/data/maps/FortreeCity_House1/scripts.inc @@ -7,7 +7,7 @@ FortreeCity_House1_EventScript_2162BB:: @ 82162BB goto_if_set FLAG_0x09B, FortreeCity_House1_EventScript_216355 setvar VAR_0x8008, 1 copyvar VAR_0x8004, VAR_0x8008 - specialvar VAR_RESULT, sub_807E73C + specialvar VAR_RESULT, GetInGameTradeSpeciesInfo copyvar VAR_0x8009, VAR_RESULT msgbox FortreeCity_House1_Text_21637B, MSGBOX_YESNO compare VAR_RESULT, 0 @@ -18,14 +18,14 @@ FortreeCity_House1_EventScript_2162BB:: @ 82162BB compare VAR_0x8004, 255 goto_if_eq FortreeCity_House1_EventScript_21633D copyvar VAR_0x8005, VAR_0x800A - specialvar VAR_RESULT, sub_807E9D4 + specialvar VAR_RESULT, GetTradeSpecies copyvar VAR_0x800B, VAR_RESULT compare VAR_RESULT, VAR_0x8009 goto_if_ne FortreeCity_House1_EventScript_216347 copyvar VAR_0x8004, VAR_0x8008 copyvar VAR_0x8005, VAR_0x800A - special sub_807EA10 - special sub_807F0E4 + special CreateInGameTradePokemon + special DoInGameTradeScene waitstate bufferspeciesname 0, VAR_0x8009 msgbox FortreeCity_House1_Text_216440, MSGBOX_DEFAULT diff --git a/data/maps/PacifidlogTown_House3/scripts.inc b/data/maps/PacifidlogTown_House3/scripts.inc index fb5bf8cb1..05c38216d 100644 --- a/data/maps/PacifidlogTown_House3/scripts.inc +++ b/data/maps/PacifidlogTown_House3/scripts.inc @@ -7,7 +7,7 @@ PacifidlogTown_House3_EventScript_203C11:: @ 8203C11 goto_if_set FLAG_0x09A, PacifidlogTown_House3_EventScript_203CAB setvar VAR_0x8008, 2 copyvar VAR_0x8004, VAR_0x8008 - specialvar VAR_RESULT, sub_807E73C + specialvar VAR_RESULT, GetInGameTradeSpeciesInfo copyvar VAR_0x8009, VAR_RESULT msgbox PacifidlogTown_House3_Text_203CBE, MSGBOX_YESNO compare VAR_RESULT, 0 @@ -18,14 +18,14 @@ PacifidlogTown_House3_EventScript_203C11:: @ 8203C11 compare VAR_0x8004, 255 goto_if_eq PacifidlogTown_House3_EventScript_203C93 copyvar VAR_0x8005, VAR_0x800A - specialvar VAR_RESULT, sub_807E9D4 + specialvar VAR_RESULT, GetTradeSpecies copyvar VAR_0x800B, VAR_RESULT compare VAR_RESULT, VAR_0x8009 goto_if_ne PacifidlogTown_House3_EventScript_203C9D copyvar VAR_0x8004, VAR_0x8008 copyvar VAR_0x8005, VAR_0x800A - special sub_807EA10 - special sub_807F0E4 + special CreateInGameTradePokemon + special DoInGameTradeScene waitstate bufferspeciesname 0, VAR_0x8009 msgbox PacifidlogTown_House3_Text_203D87, MSGBOX_DEFAULT diff --git a/data/maps/RustboroCity_House1/scripts.inc b/data/maps/RustboroCity_House1/scripts.inc index 26a406675..effe69665 100644 --- a/data/maps/RustboroCity_House1/scripts.inc +++ b/data/maps/RustboroCity_House1/scripts.inc @@ -7,7 +7,7 @@ RustboroCity_House1_EventScript_21593F:: @ 821593F goto_if_set FLAG_0x099, RustboroCity_House1_EventScript_2159D5 setvar VAR_0x8008, 0 copyvar VAR_0x8004, VAR_0x8008 - specialvar VAR_RESULT, sub_807E73C + specialvar VAR_RESULT, GetInGameTradeSpeciesInfo copyvar VAR_0x8009, VAR_RESULT msgbox RustboroCity_House1_Text_2159E8, MSGBOX_YESNO compare VAR_RESULT, 0 @@ -18,14 +18,14 @@ RustboroCity_House1_EventScript_21593F:: @ 821593F compare VAR_0x8004, 255 goto_if_eq RustboroCity_House1_EventScript_2159BD copyvar VAR_0x8005, VAR_0x800A - specialvar VAR_RESULT, sub_807E9D4 + specialvar VAR_RESULT, GetTradeSpecies copyvar VAR_0x800B, VAR_RESULT compare VAR_RESULT, VAR_0x8009 goto_if_ne RustboroCity_House1_EventScript_2159C7 copyvar VAR_0x8004, VAR_0x8008 copyvar VAR_0x8005, VAR_0x800A - special sub_807EA10 - special sub_807F0E4 + special CreateInGameTradePokemon + special DoInGameTradeScene waitstate msgbox RustboroCity_House1_Text_215A77, MSGBOX_DEFAULT setflag FLAG_0x099 diff --git a/data/specials.inc b/data/specials.inc index 318d272d5..5e7c5a3d3 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -263,10 +263,10 @@ gSpecials:: @ 81DBA64 def_special BedroomPC def_special PlayerPC def_special FieldShowRegionMap - def_special sub_807E73C - def_special sub_807EA10 - def_special sub_807F0E4 - def_special sub_807E9D4 + def_special GetInGameTradeSpeciesInfo + def_special CreateInGameTradePokemon + def_special DoInGameTradeScene + def_special GetTradeSpecies def_special GetWeekCount def_special RetrieveLotteryNumber def_special PickLotteryCornerTicket diff --git a/data/trade.s b/data/trade.s index b96c5adb3..cd8ada86b 100644 --- a/data/trade.s +++ b/data/trade.s @@ -617,7 +617,7 @@ gIngameTrades:: @ 8338ED0 .2byte SPECIES_SKITTY .align 2 -gUnknown_08338FC0:: @ 8338FC0 +gIngameTradeMail:: @ 8338FC0 .2byte 0x1006, 0x1232, 0x102f, 0x0161, 0x0c00, 0x0182, 0x1000, 0x1006, 0x0e3b, 0x0000, 0x0a01, 0x1000, 0x161e, 0x018b, 0x0433, 0x1611 .2byte 0x180f, 0x0074, 0x1440, 0x0000, 0x0811, 0x102b, 0x013b, 0x2a34, 0x0c16, 0x1037, 0x1020, 0x0418, 0x0c23, 0x0000 @@ -634,7 +634,7 @@ gUnknown_0833900C:: @ 833900C gUnknown_08339014:: @ 8339014 .4byte 0x000001fc, 0x00002051, 0x00002326, 0x00003063 -gUnknown_08339024:: @ 8339024 +gTradeBallVerticalVelocityTable:: @ 8339024 .byte 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x04, 0xfc, 0xfc, 0xfc, 0xfd, 0xfd, 0xfd, 0xfd, 0xfe, 0xfe, 0xfe .byte 0xfe, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x04, 0x04 .byte 0x04, 0x04, 0xfc, 0xfd, 0xfd, 0xfe, 0xfe, 0xff, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x04, 0xfc, 0xfd, 0xfe, 0xff diff --git a/include/gba/defines.h b/include/gba/defines.h index 16f1315d0..b68a2ad1e 100644 --- a/include/gba/defines.h +++ b/include/gba/defines.h @@ -66,6 +66,4 @@ #define TOTAL_OBJ_TILE_COUNT 1024 -#define WIN_RANGE(a, b) (((a) << 8) | (b)) - #endif // GUARD_GBA_DEFINES diff --git a/include/gba/io_reg.h b/include/gba/io_reg.h index c20b69886..df79b084d 100644 --- a/include/gba/io_reg.h +++ b/include/gba/io_reg.h @@ -576,6 +576,9 @@ #define WINOUT_WINOBJ_OBJ (1 << 12) #define WINOUT_WINOBJ_CLR (1 << 13) +#define WIN_RANGE(a, b) (((a) << 8) | (b)) +#define WIN_RANGE2(a, b) ((b) | ((a) << 8)) + // BLDCNT // Bits 0-5 select layers for the 1st target #define BLDCNT_TGT1_BG0 (1 << 0) diff --git a/include/strings.h b/include/strings.h index 528990bfe..7c6ca14ba 100644 --- a/include/strings.h +++ b/include/strings.h @@ -1893,7 +1893,6 @@ extern const u8 gText_PkmnTransferredSomeonesPC[]; extern const u8 gText_PkmnTransferredLanettesPC[]; // hall of fame -extern const u8 gText_SavingDontTurnOffPower[]; extern const u8 gText_LeagueChamp[]; extern const u8 gText_HOFNumber[]; extern const u8 gText_PickNextCancel[]; @@ -1989,5 +1988,6 @@ extern const u8 gText_XWillBeSentToY[]; extern const u8 gText_ByeByeVar1[]; extern const u8 gText_XSentOverY[]; extern const u8 gText_TakeGoodCareOfX[]; +extern const u8 gText_CommunicationStandby5[]; #endif //GUARD_STRINGS_H diff --git a/src/trade.c b/src/trade.c index ebcbf8534..dedd29c12 100644 --- a/src/trade.c +++ b/src/trade.c @@ -9,12 +9,14 @@ #include "decompress.h" #include "event_data.h" #include "evolution_scene.h" +#include "field_screen_effect.h" #include "gpu_regs.h" #include "graphics.h" #include "international_string_util.h" #include "librfu.h" #include "link.h" #include "link_rfu.h" +#include "load_save.h" #include "mail.h" #include "main.h" #include "overworld.h" @@ -24,6 +26,10 @@ #include "pokedex.h" #include "pokemon_icon.h" #include "pokemon_summary_screen.h" +#include "random.h" +#include "rom_8011DC0.h" +#include "save.h" +#include "script.h" #include "sound.h" #include "string_util.h" #include "strings.h" @@ -40,6 +46,8 @@ #include "constants/songs.h" #include "constants/rgb.h" +#define Trade_SendData(ptr) (SendBlock(bitmask_all_link_players_but_self(), ptr->linkData, 20)) + struct InGameTrade { /*0x00*/ u8 name[11]; /*0x0C*/ u16 species; @@ -107,7 +115,7 @@ extern struct { /*0x70*/ u8 filler_70[2]; /*0x72*/ u8 unk_72; /*0x73*/ u8 unk_73; - /*0x74*/ u8 unk_74[20]; + /*0x74*/ u16 linkData[10]; /*0x88*/ u8 unk_88; /*0x89*/ u8 unk_89; /*0x8A*/ u16 unk_8A; @@ -138,9 +146,13 @@ extern struct { /*0xEF*/ u8 filler_EF; /*0xF0*/ u16 tradeSpecies[2]; /*0xF4*/ u16 unk_F4; - /*0xF6*/ u8 filler_F6[0xFA - 0xF6]; + /*0xF6*/ u8 unk_F6[3]; + /*0xF9*/ u8 filler_F9; /*0xFA*/ u8 unk_FA; - /*0xFB*/ u8 filler_FB[0x100 - 0xFB]; + /*0xFB*/ u8 unk_FB; + /*0xFC*/ u8 unk_FC; + /*0xFD*/ u8 unk_FD; + /*0xFE*/ u8 unk_FE; } *gUnknown_020322A0; extern u8 gUnknown_0203CF20; @@ -201,6 +213,11 @@ extern const struct SpriteTemplate gSpriteTemplate_8338DC8; extern const union AffineAnimCmd *const gSpriteAffineAnimTable_8338ECC[]; extern const struct SpriteTemplate gSpriteTemplate_8338E74; extern const struct SpriteTemplate gSpriteTemplate_8338E8C; +extern const s8 gTradeBallVerticalVelocityTable[]; +extern const u16 gIngameTradeMail[][10]; +extern const u8 gUnknown_08339090[][2]; +extern const u16 gUnknown_08337AA0[]; +extern const u16 gUnknown_08337CA0[]; // external to this file extern const struct CompressedSpriteSheet gMonFrontPicTable[]; @@ -246,7 +263,7 @@ void sub_807B60C(void); u8 sub_807BBC8(void); u8 sub_807CFC8(void); u8 sub_807BBEC(void); -void sub_807F1A8(u8, u8 *, u8); +void sub_807F1A8(u8, const u8 *, u8); void sub_807E5D8(struct Sprite *); void sub_807AAE0(struct Sprite *); void sub_807E6AC(struct Sprite *); @@ -255,6 +272,13 @@ void sub_807E784(void); void c3_08054588(u8); void c3_0805465C(u8); void sub_807F39C(u8); +void sub_807EB50(void); +void sub_807F464(void); +void sub_807E64C(struct Sprite *); +void sub_807E974(struct MailStruct *mail, const struct InGameTrade *trade); +void sub_807EACC(void); +void c2_080543C4(void); +void sub_807F110(u8); bool8 sub_8077170(const void *a0, u32 a1) { @@ -334,12 +358,12 @@ bool32 sub_8077260(void) } } -void sub_8077288(void) +void sub_8077288(u8 unused) { sub_800ADF8(); } -bool8 sub_8077294(void) +bool32 IsLinkTaskFinished(void) { return sub_800A520(); } @@ -3443,7 +3467,7 @@ void sub_807B5B8(void) case 1: if (sub_800A520()) { - SendBlock(bitmask_all_link_players_but_self(), gUnknown_020322A0->unk_74, sizeof(gUnknown_020322A0->unk_74)); + Trade_SendData(gUnknown_020322A0); gUnknown_020322A0->unk_93++; } case 2: @@ -4679,3 +4703,571 @@ bool8 sub_807CFC8(void) } return FALSE; } + +void c2_08053788(void) +{ + u16 evoTarget; + switch (gMain.state) + { + case 0: + gMain.state = 4; + gSoftResetDisabled = TRUE; + break; + case 4: + gCB2_AfterEvolution = sub_807EB50; + evoTarget = GetEvolutionTargetSpecies(&gPlayerParty[gUnknown_02032298[0]], TRUE, ITEM_NONE); + if (evoTarget != SPECIES_NONE) + TradeEvolutionScene(&gPlayerParty[gUnknown_02032298[0]], evoTarget, gUnknown_020322A0->pokePicSpriteIdxs[1], gUnknown_02032298[0]); + else if (sub_8077260()) + SetMainCallback2(sub_807F464); + else + SetMainCallback2(sub_807EB50); + gUnknown_02032298[0] = 255; + break; + } + if (!HasLinkErrorOccurred()) + RunTasks(); + AnimateSprites(); + BuildOamBuffer(); + UpdatePaletteFade(); +} + +void sub_807E4DC(void) +{ + u8 blockReceivedStatus; + sub_807ACDC(); + blockReceivedStatus = GetBlockReceivedStatus(); + if (blockReceivedStatus & 0x01) + { + if (gBlockRecvBuffer[0][0] == 0xDCBA) + { + SetMainCallback2(c2_08053788); + } + if (gBlockRecvBuffer[0][0] == 0xABCD) + { + gUnknown_020322A0->unk_72 = 1; + } + ResetBlockReceivedFlag(0); + } + if (blockReceivedStatus & 0x02) + { + if (gBlockRecvBuffer[1][0] == 0xABCD) + { + gUnknown_020322A0->unk_73 = 1; + } + ResetBlockReceivedFlag(1); + } +} + +void sub_807E55C(struct Sprite *sprite) +{ + sprite->pos1.y += sprite->data[0] / 10; + sprite->data[5] += sprite->data[1]; + sprite->pos1.x = sprite->data[5] / 10; + if (sprite->pos1.y > 0x4c) + { + sprite->pos1.y = 0x4c; + sprite->data[0] = -(sprite->data[0] * sprite->data[2]) / 100; + sprite->data[3] ++; + } + if (sprite->pos1.x == 0x78) + sprite->data[1] = 0; + sprite->data[0] += sprite->data[4]; + if (sprite->data[3] == 4) + { + sprite->data[7] = 1; + sprite->callback = SpriteCallbackDummy; + } +} + +void sub_807E5D8(struct Sprite *sprite) +{ + sprite->pos2.y += gTradeBallVerticalVelocityTable[sprite->data[0]]; + if (sprite->data[0] == 22) + PlaySE(SE_KON); + if (++ sprite->data[0] == 44) + { + PlaySE(SE_W025); + sprite->callback = sub_807E64C; + sprite->data[0] = 0; + BeginNormalPaletteFade(1 << (16 + sprite->oam.paletteNum), -1, 0, 16, RGB_WHITEALPHA); + } +} + +void sub_807E64C(struct Sprite *sprite) +{ + if (sprite->data[1] == 20) + StartSpriteAffineAnim(sprite, 1); + if (++ sprite->data[1] > 20) + { + sprite->pos2.y -= gTradeBallVerticalVelocityTable[sprite->data[0]]; + if (++ sprite->data[0] == 23) + { + DestroySprite(sprite); + gUnknown_020322A0->unk_94 = 14; // Resume the master trade animation + } + } +} + +void sub_807E6AC(struct Sprite *sprite) +{ + if (sprite->data[2] == 0) + { + if ((sprite->pos1.y += 4) > sprite->data[3]) + { + sprite->data[2] ++; + sprite->data[0] = 0x16; + PlaySE(SE_KON); + } + } + else + { + if (sprite->data[0] == 0x42) + PlaySE(SE_KON2); + if (sprite->data[0] == 0x5c) + PlaySE(SE_KON3); + if (sprite->data[0] == 0x6b) + PlaySE(SE_KON4); + sprite->pos2.y += gTradeBallVerticalVelocityTable[sprite->data[0]]; + if (++sprite->data[0] == 0x6c) + sprite->callback = SpriteCallbackDummy; + } +} + +u16 GetInGameTradeSpeciesInfo(void) +{ + const struct InGameTrade *inGameTrade = &gIngameTrades[gSpecialVar_0x8004]; + StringCopy(gStringVar1, gSpeciesNames[inGameTrade->playerSpecies]); + StringCopy(gStringVar2, gSpeciesNames[inGameTrade->species]); + return inGameTrade->playerSpecies; +} + +void sub_807E784(void) +{ + u8 nickname[32]; + const struct InGameTrade *inGameTrade = &gIngameTrades[gSpecialVar_0x8004]; + GetMonData(&gPlayerParty[gSpecialVar_0x8005], MON_DATA_NICKNAME, nickname); + StringCopy10(gStringVar1, nickname); + StringCopy(gStringVar2, gSpeciesNames[inGameTrade->species]); +} + +void _CreateInGameTradePokemon(u8 whichPlayerMon, u8 whichInGameTrade) +{ + const struct InGameTrade *inGameTrade = &gIngameTrades[whichInGameTrade]; + u8 level = GetMonData(&gPlayerParty[whichPlayerMon], MON_DATA_LEVEL); + + struct MailStruct mail; + u8 metLocation = 0xFE; + u8 isMail; + struct Pokemon *pokemon = &gEnemyParty[0]; + + CreateMon(pokemon, inGameTrade->species, level, 32, TRUE, inGameTrade->personality, TRUE, inGameTrade->otId); + + SetMonData(pokemon, MON_DATA_HP_IV, &inGameTrade->ivs[0]); + SetMonData(pokemon, MON_DATA_ATK_IV, &inGameTrade->ivs[1]); + SetMonData(pokemon, MON_DATA_DEF_IV, &inGameTrade->ivs[2]); + SetMonData(pokemon, MON_DATA_SPEED_IV, &inGameTrade->ivs[3]); + SetMonData(pokemon, MON_DATA_SPATK_IV, &inGameTrade->ivs[4]); + SetMonData(pokemon, MON_DATA_SPDEF_IV, &inGameTrade->ivs[5]); + SetMonData(pokemon, MON_DATA_NICKNAME, inGameTrade->name); + SetMonData(pokemon, MON_DATA_OT_NAME, inGameTrade->otName); + SetMonData(pokemon, MON_DATA_OT_GENDER, &inGameTrade->otGender); + SetMonData(pokemon, MON_DATA_ALT_ABILITY, &inGameTrade->secondAbility); + SetMonData(pokemon, MON_DATA_BEAUTY, &inGameTrade->stats[1]); + SetMonData(pokemon, MON_DATA_CUTE, &inGameTrade->stats[2]); + SetMonData(pokemon, MON_DATA_COOL, &inGameTrade->stats[0]); + SetMonData(pokemon, MON_DATA_SMART, &inGameTrade->stats[3]); + SetMonData(pokemon, MON_DATA_TOUGH, &inGameTrade->stats[4]); + SetMonData(pokemon, MON_DATA_SHEEN, &inGameTrade->sheen); + SetMonData(pokemon, MON_DATA_MET_LOCATION, &metLocation); + + isMail = FALSE; + if (inGameTrade->heldItem != ITEM_NONE) + { + if (ItemIsMail(inGameTrade->heldItem)) + { + sub_807E974(&mail, inGameTrade); + gUnknown_020321C0[0] = mail; + SetMonData(pokemon, MON_DATA_MAIL, &isMail); + SetMonData(pokemon, MON_DATA_HELD_ITEM, &inGameTrade->heldItem); + } + else + { + SetMonData(pokemon, MON_DATA_HELD_ITEM, &inGameTrade->heldItem); + } + } + CalculateMonStats(&gEnemyParty[0]); +} + +void sub_807E974(struct MailStruct *mail, const struct InGameTrade *trade) { + s32 i; + + for (i = 0; i < 9; i++) + { + mail->words[i] = gIngameTradeMail[trade->mailNum][i]; + } + + StringCopy(mail->playerName, trade->otName); + PadNameString(mail->playerName, CHAR_SPACE); + + mail->trainerId[0] = trade->otId >> 24; + mail->trainerId[1] = trade->otId >> 16; + mail->trainerId[2] = trade->otId >> 8; + mail->trainerId[3] = trade->otId; + mail->species = trade->species; + mail->itemId = trade->heldItem; +} + +u16 GetTradeSpecies(void) +{ + if (GetMonData(&gPlayerParty[gSpecialVar_0x8005], MON_DATA_IS_EGG)) + return SPECIES_NONE; + return GetMonData(&gPlayerParty[gSpecialVar_0x8005], MON_DATA_SPECIES); +} + +void CreateInGameTradePokemon(void) +{ + _CreateInGameTradePokemon(gSpecialVar_0x8005, gSpecialVar_0x8004); +} + +void sub_807EA2C(void) +{ + if (sub_807BBC8() == TRUE) + { + DestroySprite(&gSprites[gUnknown_020322A0->pokePicSpriteIdxs[0]]); + FreeSpriteOamMatrix(&gSprites[gUnknown_020322A0->pokePicSpriteIdxs[1]]); + sub_807B4D0(gUnknown_02032298[0], gUnknown_02032298[1] % 6); + if (!sub_8077260()) + { + gUnknown_020322A0->linkData[0] = 0xABCD; + gUnknown_020322A0->unk_93 = 1; + } + SetMainCallback2(sub_807EACC); + } + sub_807B5B8(); + sub_807E4DC(); + RunTasks(); + RunTextPrinters(); + AnimateSprites(); + BuildOamBuffer(); + UpdatePaletteFade(); +} + +void sub_807EACC(void) +{ + u8 mpId = sub_807ACDC(); + if (sub_8077260()) + { + SetMainCallback2(c2_08053788); + } + else + { + sub_807E4DC(); + if (mpId == 0 && gUnknown_020322A0->unk_72 == 1 && gUnknown_020322A0->unk_73 == 1) + { + gUnknown_020322A0->linkData[0] = 0xDCBA; + Trade_SendData(gUnknown_020322A0); + gUnknown_020322A0->unk_72 = 2; + gUnknown_020322A0->unk_73 = 2; + } + } + RunTasks(); + AnimateSprites(); + BuildOamBuffer(); + UpdatePaletteFade(); +} + +void sub_807EB50(void) +{ + switch (gMain.state) + { + case 0: + gMain.state++; + StringExpandPlaceholders(gStringVar4, gText_CommunicationStandby5); + sub_807F1A8(0, gStringVar4, 0); + break; + case 1: + sub_8077288(0); + gMain.state = 100; + gUnknown_020322A0->unk_64 = 0; + break; + case 100: + if (++gUnknown_020322A0->unk_64 > 180) + { + gMain.state = 101; + gUnknown_020322A0->unk_64 = 0; + } + if (IsLinkTaskFinished()) + { + gMain.state = 2; + } + break; + case 101: + if (IsLinkTaskFinished()) + { + gMain.state = 2; + } + break; + case 2: + gMain.state = 50; + StringExpandPlaceholders(gStringVar4, gText_SavingDontTurnOffPower); + sub_807F1A8(0, gStringVar4, 0); + break; + case 50: + if (!InUnionRoom()) + IncrementGameStat(GAME_STAT_POKEMON_TRADES); + if (gWirelessCommType) + { + sub_801B990(2, gLinkPlayers[GetMultiplayerId() ^ 1].trainerId); + } + sub_8076D5C(); + sub_8153380(); + gMain.state++; + gUnknown_020322A0->unk_64 = 0; + break; + case 51: + if (++gUnknown_020322A0->unk_64 == 5) + { + gMain.state++; + } + break; + case 52: + if (sub_81533AC()) + { + sav2_gender2_inplace_and_xFE(); + gMain.state = 4; + } + else + { + gUnknown_020322A0->unk_64 = 0; + gMain.state = 51; + } + break; + case 4: + sub_81533E0(); + gMain.state = 40; + gUnknown_020322A0->unk_64 = 0; + break; + case 40: + if (++gUnknown_020322A0->unk_64 > 50) + { + if (GetMultiplayerId() == 0) + { + gUnknown_020322A0->unk_64 = Random() % 30; + } + else + { + gUnknown_020322A0->unk_64 = 0; + } + gMain.state = 41; + } + break; + case 41: + if (gUnknown_020322A0->unk_64 == 0) + { + sub_8077288(1); + gMain.state = 42; + } + else + { + gUnknown_020322A0->unk_64--; + } + break; + case 42: + if (IsLinkTaskFinished()) + { + sub_8153408(); + gMain.state = 5; + } + break; + case 5: + if (++gUnknown_020322A0->unk_64 > 60) + { + gMain.state++; + sub_8077288(2); + } + break; + case 6: + if (IsLinkTaskFinished()) + { + BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK); + gMain.state ++; + } + break; + case 7: + if (!gPaletteFade.active) + { + FadeOutBGM(3); + gMain.state++; + } + break; + case 8: + if (IsBGMStopped() == TRUE) + { + if (gWirelessCommType && gMain.savedCallback == sub_80773AC) + { + sub_8077288(3); + } + else + { + sub_800AC34(); + } + gMain.state++; + } + break; + case 9: + if (gWirelessCommType && gMain.savedCallback == sub_80773AC) + { + if (IsLinkTaskFinished()) + { + gSoftResetDisabled = FALSE; + SetMainCallback2(c2_080543C4); + } + } + else if (!gReceivedRemoteLinkPlayers) + { + gSoftResetDisabled = FALSE; + SetMainCallback2(c2_080543C4); + } + break; + } + if (!HasLinkErrorOccurred()) + { + RunTasks(); + } + AnimateSprites(); + BuildOamBuffer(); + UpdatePaletteFade(); +} + +void c2_080543C4(void) +{ + if (!gPaletteFade.active) + { + FreeAllWindowBuffers(); + Free(GetBgTilemapBuffer(3)); + Free(GetBgTilemapBuffer(1)); + Free(GetBgTilemapBuffer(0)); + FreeMonSpritesGfx(); + FREE_AND_SET_NULL(gUnknown_020322A0); + if (gWirelessCommType) + sub_800E084(); + SetMainCallback2(gMain.savedCallback); + } + RunTasks(); + AnimateSprites(); + BuildOamBuffer(); + UpdatePaletteFade(); +} + +void DoInGameTradeScene(void) +{ + ScriptContext2_Enable(); + CreateTask(sub_807F110, 10); + BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK); +} + +void sub_807F110(u8 taskId) +{ + if (!gPaletteFade.active) + { + SetMainCallback2(sub_807B270); + gFieldCallback = sub_80AF168; + DestroyTask(taskId); + } +} + +void sub_807F14C(void) +{ + u8 i; + u8 numRibbons = 0; + for (i = 0; i < 12; i ++) + { + numRibbons += GetMonData(&gEnemyParty[gUnknown_02032298[1] % 6], MON_DATA_CHAMPION_RIBBON + i); + } + if (numRibbons != 0) + FlagSet(FLAG_SYS_RIBBON_GET); +} + +void sub_807F19C(void) +{ + sub_807B170(); +} + +void sub_807F1A8(u8 windowId, const u8 *str, u8 speed) +{ + FillWindowPixelBuffer(windowId, 0xFF); + gUnknown_020322A0->unk_F6[0] = 15; + gUnknown_020322A0->unk_F6[1] = 1; + gUnknown_020322A0->unk_F6[2] = 6; + AddTextPrinterParameterized4(windowId, 1, 0, 2, 0, 0, gUnknown_020322A0->unk_F6, speed, str); + CopyWindowToVram(windowId, 3); +} + +void c3_08054588(u8 taskId) +{ + s16 *data = gTasks[taskId].data; + + u16 unk = gUnknown_08339090[data[0]][0] * 16; + + if (!data[2]) + { + if (unk == 0x100) + LoadPalette(gUnknown_08337EA0, 0x30, 32); + else + LoadPalette(&gUnknown_08337AA0[unk], 0x30, 32); + } + else + { + if (unk == 0x100) + LoadPalette(gUnknown_08337EA0, 0x30, 32); + else + LoadPalette(&gUnknown_08337CA0[unk], 0x30, 32); + } + + if (gUnknown_08339090[data[0]][0] == 0 && data[1] == 0) + PlaySE(SE_W215); + + if (data[1] == gUnknown_08339090[data[0]][1]) + { + data[0]++; + data[1] = 0; + if (gUnknown_08339090[data[0]][1] == 0xFF) + { + DestroyTask(taskId); + } + } + else + { + data[1]++; + } +} + +void c3_0805465C(u8 taskId) +{ + s16 *data = gTasks[taskId].data; + + if (data[0] == 0) + { + gUnknown_020322A0->unk_FB = gUnknown_020322A0->unk_FD = 120; + gUnknown_020322A0->unk_FC = 0; + gUnknown_020322A0->unk_FE = 160; + SetGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON); + SetGpuReg(REG_OFFSET_WINOUT, WINOUT_WIN01_OBJ); + SetGpuReg(REG_OFFSET_WININ, WININ_WIN0_BG0 | + WININ_WIN0_BG1 | + WININ_WIN0_OBJ); + } + + SetGpuReg(REG_OFFSET_WIN0H, WIN_RANGE2(gUnknown_020322A0->unk_FB, gUnknown_020322A0->unk_FD)); + SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE2(gUnknown_020322A0->unk_FC, gUnknown_020322A0->unk_FE)); + + data[0]++; + gUnknown_020322A0->unk_FB -= 5; + gUnknown_020322A0->unk_FD += 5; + + if (gUnknown_020322A0->unk_FB < 80) + { + DestroyTask(taskId); + } +}