From d17ff9430a78f47b8a9472d1e24d8badd09d7ed6 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Fri, 27 Oct 2017 21:55:07 -0400 Subject: [PATCH] sub_80EAF80 --- asm/secret_base.s | 260 ---------------------------------------------- src/secret_base.c | 123 +++++++++++++++++++--- 2 files changed, 106 insertions(+), 277 deletions(-) diff --git a/asm/secret_base.s b/asm/secret_base.s index 2d4fd7eeb..4d940cb82 100644 --- a/asm/secret_base.s +++ b/asm/secret_base.s @@ -5,266 +5,6 @@ .text - thumb_func_start sub_80EAF80 -sub_80EAF80: @ 80EAF80 - push {r4-r7,lr} - sub sp, 0x24 - adds r6, r0, 0 - adds r5, r1, 0 - lsls r2, 24 - lsrs r7, r2, 24 - movs r0, 0x60 - bl FlagGet - lsls r0, 24 - cmp r0, 0 - bne _080EAF9A - b _080EB16A -_080EAF9A: - bl GetLinkPlayerCount - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x2 - beq _080EAFAC - cmp r0, 0x3 - beq _080EAFC8 - b _080EAFD6 -_080EAFAC: - lsls r4, r5, 1 - adds r0, r6, r4 - movs r1, 0 - adds r2, r5, 0 - bl memset - adds r4, r5 - adds r4, r6, r4 - adds r0, r4, 0 - movs r1, 0 - adds r2, r5, 0 - bl memset - b _080EAFD6 -_080EAFC8: - lsls r0, r5, 1 - adds r0, r5 - adds r0, r6, r0 - movs r1, 0 - adds r2, r5, 0 - bl memset -_080EAFD6: - cmp r7, 0x1 - beq _080EB030 - cmp r7, 0x1 - bgt _080EAFE4 - cmp r7, 0 - beq _080EAFEE - b _080EB0D4 -_080EAFE4: - cmp r7, 0x2 - beq _080EB074 - cmp r7, 0x3 - beq _080EB0A8 - b _080EB0D4 -_080EAFEE: - adds r0, r6, r5 - str r0, [sp] - ldr r4, =gLinkPlayers - movs r3, 0xFF - ldrb r0, [r4, 0x1C] - str r0, [sp, 0x4] - ldrh r0, [r4, 0x36] - str r0, [sp, 0x8] - lsls r1, r5, 1 - adds r0, r6, r1 - str r0, [sp, 0xC] - ldrh r2, [r4, 0x38] - adds r0, r3, 0 - ands r0, r2 - str r0, [sp, 0x10] - adds r0, r4, 0 - adds r0, 0x52 - ldrh r0, [r0] - str r0, [sp, 0x14] - adds r1, r5 - adds r1, r6, r1 - str r1, [sp, 0x18] - adds r0, r4, 0 - adds r0, 0x54 - ldrh r0, [r0] - ands r3, r0 - str r3, [sp, 0x1C] - adds r0, r4, 0 - adds r0, 0x6E - ldrh r0, [r0] - b _080EB0D2 - .pool -_080EB030: - lsls r2, r5, 1 - adds r0, r6, r2 - str r0, [sp] - ldr r4, =gLinkPlayers - ldrh r3, [r4, 0x38] - movs r1, 0xFF - adds r0, r1, 0 - ands r0, r3 - str r0, [sp, 0x4] - adds r0, r4, 0 - adds r0, 0x52 - ldrh r0, [r0] - str r0, [sp, 0x8] - adds r2, r5 - adds r2, r6, r2 - str r2, [sp, 0xC] - adds r0, r4, 0 - adds r0, 0x54 - ldrh r2, [r0] - adds r0, r1, 0 - ands r0, r2 - str r0, [sp, 0x10] - adds r0, r4, 0 - adds r0, 0x6E - ldrh r0, [r0] - str r0, [sp, 0x14] - str r6, [sp, 0x18] - ldrh r0, [r4] - ands r1, r0 - str r1, [sp, 0x1C] - ldrh r0, [r4, 0x1A] - b _080EB0D2 - .pool -_080EB074: - lsls r0, r5, 1 - adds r0, r5 - adds r0, r6, r0 - str r0, [sp] - ldr r1, =gLinkPlayers - adds r0, r1, 0 - adds r0, 0x54 - ldrb r0, [r0] - str r0, [sp, 0x4] - adds r0, r1, 0 - adds r0, 0x6E - ldrh r0, [r0] - str r0, [sp, 0x8] - str r6, [sp, 0xC] - ldrb r0, [r1] - str r0, [sp, 0x10] - ldrh r0, [r1, 0x1A] - str r0, [sp, 0x14] - adds r0, r6, r5 - str r0, [sp, 0x18] - ldrb r0, [r1, 0x1C] - str r0, [sp, 0x1C] - ldrh r0, [r1, 0x36] - b _080EB0D2 - .pool -_080EB0A8: - str r6, [sp] - ldr r1, =gLinkPlayers - ldrb r0, [r1] - str r0, [sp, 0x4] - ldrh r0, [r1, 0x1A] - str r0, [sp, 0x8] - adds r0, r6, r5 - str r0, [sp, 0xC] - movs r2, 0xFF - ldrb r0, [r1, 0x1C] - str r0, [sp, 0x10] - ldrh r0, [r1, 0x36] - str r0, [sp, 0x14] - lsls r0, r5, 1 - adds r0, r6, r0 - str r0, [sp, 0x18] - ldrh r0, [r1, 0x38] - ands r2, r0 - str r2, [sp, 0x1C] - adds r1, 0x52 - ldrh r0, [r1] -_080EB0D2: - str r0, [sp, 0x20] -_080EB0D4: - mov r0, sp - bl sub_80EAEF4 - movs r3, 0x1 - ldr r6, =gSaveBlock1Ptr - movs r7, 0x10 - negs r7, r7 -_080EB0E2: - ldr r0, [r6] - lsls r1, r3, 2 - adds r1, r3 - lsls r4, r1, 5 - adds r0, r4 - ldr r5, =0x00001a9d - adds r2, r0, r5 - ldrb r1, [r2] - lsls r0, r1, 28 - lsrs r0, 28 - cmp r0, 0x1 - bne _080EB112 - movs r0, 0x3F - ands r0, r1 - movs r1, 0x40 - orrs r0, r1 - strb r0, [r2] - ldr r1, [r6] - adds r1, r4 - adds r1, r5 - ldrb r2, [r1] - adds r0, r7, 0 - ands r0, r2 - strb r0, [r1] -_080EB112: - adds r0, r3, 0x1 - lsls r0, 16 - lsrs r3, r0, 16 - cmp r3, 0x13 - bls _080EB0E2 - bl sub_80EAAF4 - movs r3, 0x1 - ldr r7, =gSaveBlock1Ptr - adds r6, r7, 0 - adds r4, r5, 0 - movs r5, 0x3F -_080EB12A: - ldr r0, [r6] - lsls r1, r3, 2 - adds r1, r3 - lsls r1, 5 - adds r0, r1 - adds r2, r0, r4 - ldrb r1, [r2] - lsrs r0, r1, 6 - cmp r0, 0x2 - bne _080EB144 - adds r0, r5, 0 - ands r0, r1 - strb r0, [r2] -_080EB144: - adds r0, r3, 0x1 - lsls r0, 16 - lsrs r3, r0, 16 - cmp r3, 0x13 - bls _080EB12A - ldr r1, [r7] - ldr r2, =0x00001a9c - adds r0, r1, r2 - ldrb r0, [r0] - cmp r0, 0 - beq _080EB16A - ldr r0, =0x00001aaa - adds r2, r1, r0 - ldrh r1, [r2] - ldr r0, =0x0000ffff - cmp r1, r0 - beq _080EB16A - adds r0, r1, 0x1 - strh r0, [r2] -_080EB16A: - add sp, 0x24 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80EAF80 - thumb_func_start sub_80EB18C sub_80EB18C: @ 80EB18C push {r4,r5,lr} diff --git a/src/secret_base.c b/src/secret_base.c index 7a443e91e..d6c4786f1 100644 --- a/src/secret_base.c +++ b/src/secret_base.c @@ -35,6 +35,7 @@ #include "rom6.h" #include "decoration.h" #include "decoration_inventory.h" +#include "link.h" #include "secret_base.h" // Static type declarations @@ -1774,30 +1775,118 @@ void sub_80EAE90(struct SecretBaseRecord *base, u32 version, u32 language) } } -void sub_80EAEB4(struct SecretBaseRecordMixer *mixer) +void sub_80EAEB4(struct SecretBaseRecordMixer *mixers) { u16 i; for (i = 0; i < 20; i ++) { - sub_80EAE90(&mixer[0].records[i], mixer[0].version, mixer[0].language); - sub_80EAE90(&mixer[1].records[i], mixer[1].version, mixer[1].language); - sub_80EAE90(&mixer[2].records[i], mixer[2].version, mixer[2].language); + sub_80EAE90(&mixers[0].records[i], mixers[0].version, mixers[0].language); + sub_80EAE90(&mixers[1].records[i], mixers[1].version, mixers[1].language); + sub_80EAE90(&mixers[2].records[i], mixers[2].version, mixers[2].language); } } -void sub_80EAEF4(struct SecretBaseRecordMixer *mixer) +void sub_80EAEF4(struct SecretBaseRecordMixer *mixers) { - DeleteFirstOldBaseFromPlayerInRecordMixingFriendsRecords(mixer[0].records, mixer[1].records, mixer[2].records); - sub_80EAD94(gSaveBlock1Ptr->secretBases, mixer[0].records, mixer[1].records, mixer[2].records); - sub_80EAEB4(mixer); - sub_80EAA64(mixer[0].records, mixer[0].version, mixer[0].language); - sub_80EAA64(mixer[1].records, mixer[1].version, mixer[1].language); - sub_80EAA64(mixer[2].records, mixer[2].version, mixer[2].language); - sub_80EABA4(&mixer[0], 1); - sub_80EABA4(&mixer[1], 1); - sub_80EABA4(&mixer[2], 1); - sub_80EABA4(&mixer[0], 0); - sub_80EABA4(&mixer[1], 0); - sub_80EABA4(&mixer[2], 0); + DeleteFirstOldBaseFromPlayerInRecordMixingFriendsRecords(mixers[0].records, mixers[1].records, mixers[2].records); + sub_80EAD94(gSaveBlock1Ptr->secretBases, mixers[0].records, mixers[1].records, mixers[2].records); + sub_80EAEB4(mixers); + sub_80EAA64(mixers[0].records, mixers[0].version, mixers[0].language); + sub_80EAA64(mixers[1].records, mixers[1].version, mixers[1].language); + sub_80EAA64(mixers[2].records, mixers[2].version, mixers[2].language); + sub_80EABA4(&mixers[0], 1); + sub_80EABA4(&mixers[1], 1); + sub_80EABA4(&mixers[2], 1); + sub_80EABA4(&mixers[0], 0); + sub_80EABA4(&mixers[1], 0); + sub_80EABA4(&mixers[2], 0); +} + +void sub_80EAF80(void *records, size_t recordSize, u8 linkIdx) +{ + struct SecretBaseRecordMixer mixers[3]; + u16 i; + + if (FlagGet(0x60)) + { + switch (GetLinkPlayerCount()) + { + case 2: + memset(records + 2 * recordSize, 0, recordSize); + memset(records + 3 * recordSize, 0, recordSize); + break; + case 3: + memset(records + 3 * recordSize, 0, recordSize); + break; + } + switch (linkIdx) + { + case 0: + mixers[0].records = records + 1 * recordSize; + mixers[0].version = gLinkPlayers[1].version & 0xFF; + mixers[0].language = gLinkPlayers[1].language; + mixers[1].records = records + 2 * recordSize; + mixers[1].version = gLinkPlayers[2].version & 0xFF; + mixers[1].language = gLinkPlayers[2].language; + mixers[2].records = records + 3 * recordSize; + mixers[2].version = gLinkPlayers[3].version & 0xFF; + mixers[2].language = gLinkPlayers[3].language; + break; + case 1: + mixers[0].records = records + 2 * recordSize; + mixers[0].version = gLinkPlayers[2].version & 0xFF; + mixers[0].language = gLinkPlayers[2].language; + mixers[1].records = records + 3 * recordSize; + mixers[1].version = gLinkPlayers[3].version & 0xFF; + mixers[1].language = gLinkPlayers[3].language; + mixers[2].records = records + 0 * recordSize; + mixers[2].version = gLinkPlayers[0].version & 0xFF; + mixers[2].language = gLinkPlayers[0].language; + break; + case 2: + mixers[0].records = records + 3 * recordSize; + mixers[0].version = gLinkPlayers[3].version & 0xFF; + mixers[0].language = gLinkPlayers[3].language; + mixers[1].records = records + 0 * recordSize; + mixers[1].version = gLinkPlayers[0].version & 0xFF; + mixers[1].language = gLinkPlayers[0].language; + mixers[2].records = records + 1 * recordSize; + mixers[2].version = gLinkPlayers[1].version & 0xFF; + mixers[2].language = gLinkPlayers[1].language; + break; + case 3: + mixers[0].records = records + 0 * recordSize; + mixers[0].version = gLinkPlayers[0].version & 0xFF; + mixers[0].language = gLinkPlayers[0].language; + mixers[1].records = records + 1 * recordSize; + mixers[1].version = gLinkPlayers[1].version & 0xFF; + mixers[1].language = gLinkPlayers[1].language; + mixers[2].records = records + 2 * recordSize; + mixers[2].version = gLinkPlayers[2].version & 0xFF; + mixers[2].language = gLinkPlayers[2].language; + break; + } + sub_80EAEF4(mixers); + for (i = 1; i < 20; i ++) + { + if (gSaveBlock1Ptr->secretBases[i].sbr_field_1_0 == 1) + { + gSaveBlock1Ptr->secretBases[i].sbr_field_1_6 = 1; + gSaveBlock1Ptr->secretBases[i].sbr_field_1_0 = 0; + } + } + sub_80EAAF4(); + for (i = 1; i < 20; i ++) + { + if (gSaveBlock1Ptr->secretBases[i].sbr_field_1_6 == 2) + { + gSaveBlock1Ptr->secretBases[i].sbr_field_1_6 = 0; + } + } + if (gSaveBlock1Ptr->secretBases[0].secretBaseId != 0 && gSaveBlock1Ptr->secretBases[0].sbr_field_e != 0xFFFF) + { + gSaveBlock1Ptr->secretBases[0].sbr_field_e ++; + } + } }