From 5dce900d908c57a4ca46b0e9dff4e8713bc4e671 Mon Sep 17 00:00:00 2001 From: Seth Barberee Date: Sat, 2 Dec 2023 22:27:56 -0800 Subject: [PATCH] Match sub_8075680 and sub_8096EEC thanks to @Eebit --- asm/code_8073CF0.s | 65 ------------------------------ include/code_80958E8.h | 3 +- src/code_8075708.c | 34 ++++++++++++++++ src/code_80958E8.c | 6 +-- src/code_80972F4.c | 91 +++++------------------------------------- 5 files changed, 47 insertions(+), 152 deletions(-) diff --git a/asm/code_8073CF0.s b/asm/code_8073CF0.s index bdac9b709..97bdd09f3 100644 --- a/asm/code_8073CF0.s +++ b/asm/code_8073CF0.s @@ -3135,69 +3135,4 @@ _0807566C: _0807567C: .4byte gDungeon thumb_func_end UseAttack - thumb_func_start sub_8075680 -sub_8075680: - push {r4-r7,lr} - movs r7, 0 -_08075684: - ldr r0, _080756FC - ldr r0, [r0] - lsls r1, r7, 2 - ldr r2, _08075700 - adds r0, r2 - adds r0, r1 - ldr r5, [r0] - adds r0, r5, 0 - bl EntityExists - lsls r0, 24 - cmp r0, 0 - beq _080756EE - ldr r6, [r5, 0x70] - ldrb r0, [r6, 0x7] - cmp r0, 0 - bne _080756EE - movs r0, 0xB6 - lsls r0, 1 - adds r4, r6, r0 - ldr r1, [r4] - cmp r1, 0 - beq _080756EE - ldr r0, [r5, 0x4] - cmp r1, r0 - beq _080756EE - adds r0, r5, 0 - movs r1, 0x1 - bl CannotMove - lsls r0, 24 - cmp r0, 0 - bne _080756EE - adds r0, r5, 0x4 - adds r1, r4, 0 - bl GetDirectionTowardsPosition - adds r4, r0, 0 - movs r1, 0x7 - ands r0, r1 - adds r1, r6, 0 - adds r1, 0x46 - strb r0, [r1] - adds r0, r5, 0 - bl sub_806CEBC - adds r1, r0, 0 - lsls r1, 24 - lsrs r1, 24 - adds r0, r5, 0 - adds r2, r4, 0 - bl sub_806CDD4 -_080756EE: - adds r7, 0x1 - cmp r7, 0x13 - ble _08075684 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_080756FC: .4byte gDungeon -_08075700: .4byte 0x000135cc - thumb_func_end sub_8075680 - .align 2,0 diff --git a/include/code_80958E8.h b/include/code_80958E8.h index 761106a0a..84189f860 100644 --- a/include/code_80958E8.h +++ b/include/code_80958E8.h @@ -7,8 +7,7 @@ // size: 0xC typedef struct subStruct_203B490 { - /* 0x0 */ DungeonLocation dungeon; - /* 0x4 */ u32 seed; + WonderMailSub sub; /* 0x8 */ s32 checksum; // really dumb checksum that just adds all the fields of WonderMail struct } subStruct_203B490; diff --git a/src/code_8075708.c b/src/code_8075708.c index 7806225f8..e599f96a7 100644 --- a/src/code_8075708.c +++ b/src/code_8075708.c @@ -5,17 +5,51 @@ #include "constants/item.h" #include "constants/status.h" #include "constants/type.h" +#include "code_806CD90.h" +#include "dungeon_capabilities.h" #include "dungeon_items.h" #include "dungeon_map_access.h" #include "dungeon_pokemon_attributes.h" #include "dungeon_util.h" #include "dungeon_visibility.h" +#include "structs/str_dungeon.h" #include "tile_types.h" +#include "position_util.h" extern void sub_8049ED4(void); extern void sub_8073D14(Entity *); extern void sub_807FE9C(Entity *, Position *, u32, u32); +void sub_8075680(void) +{ + u32 direction; + Position *targetPos; + Entity *entity; + EntityInfo *info; + int index; + + for(index = 0; index < DUNGEON_MAX_POKEMON; index++) + { + entity = gDungeon->allPokemon[index]; + if ((EntityExists(entity)) && (info = entity->info, !info->isTeamLeader)) { + targetPos = &(info->targetPos); + + if (targetPos->x == 0 && targetPos->y == 0) + continue; + + if (targetPos->x == entity->pos.x && targetPos->y == entity->pos.y) + continue; + + if (CannotMove(entity, TRUE)) + continue; + + direction = GetDirectionTowardsPosition(&entity->pos, targetPos); + info->action.direction = direction & DIRECTION_MASK; + sub_806CDD4(entity, sub_806CEBC(entity), direction); + } + } +} + void nullsub_97(Entity *entity) {} diff --git a/src/code_80958E8.c b/src/code_80958E8.c index 0e91b0f51..b07f99369 100644 --- a/src/code_80958E8.c +++ b/src/code_80958E8.c @@ -55,9 +55,9 @@ void InitializeMailJobsNews(void) MemoryClear8(gUnknown_203B490->unk1B8, sizeof(gUnknown_203B490->unk1B8)); for(index = 0; index < 16; index++) { - gUnknown_203B490->unk230[index].dungeon.id = 99; - gUnknown_203B490->unk230[index].dungeon.floor = 1; - gUnknown_203B490->unk230[index].seed = 0; + gUnknown_203B490->unk230[index].sub.dungeon.id = 99; + gUnknown_203B490->unk230[index].sub.dungeon.floor = 1; + gUnknown_203B490->unk230[index].sub.seed = 0; gUnknown_203B490->unk230[index].checksum = 0; } } diff --git a/src/code_80972F4.c b/src/code_80972F4.c index 5f99ae88b..d83670381 100644 --- a/src/code_80972F4.c +++ b/src/code_80972F4.c @@ -132,90 +132,17 @@ s32 CalculateMailChecksum(WonderMail *mail) return sum; } -// 100 (97.92% matching - Seth) -// https://decomp.me/scratch/gl6SB -#ifdef NONMATCHING void sub_8096EEC(WonderMail *mail) { - register WonderMail *temp1 asm("ip"); s32 index; - temp1 = mail; - for(index = 15; index > 0; index--) { gUnknown_203B490->unk230[index] = gUnknown_203B490->unk230[index - 1]; } - { - register DungeonLocation temp; - register subStruct_203B490 *org; - register s32 seed; - - org = &gUnknown_203B490->unk230[0]; - temp = temp1->unk4.dungeon; - seed = temp1->unk4.seed; - org->dungeon = temp; - org->seed = seed; - } - gUnknown_203B490->unk230[0].checksum = CalculateMailChecksum(temp1); + gUnknown_203B490->unk230[0].sub = mail->unk4; + gUnknown_203B490->unk230[0].checksum = CalculateMailChecksum(mail); } -#else -NAKED -void sub_8096EEC(WonderMail *mail) -{ - asm_unified( - "\tpush {r4-r7,lr}\n" - "\tmov r7, r8\n" - "\tpush {r7}\n" - "\tmov r12, r0\n" - "\tmovs r3, 0xF\n" - "\tldr r5, _08096F4C\n" - "\tmov r8, r5\n" - "\tmovs r4, 0x8C\n" - "\tlsls r4, 2\n" -"_08096EFE:\n" - "\tmov r0, r8\n" - "\tldr r2, [r0]\n" - "\tlsls r1, r3, 1\n" - "\tadds r1, r3\n" - "\tlsls r1, 2\n" - "\tadds r1, r2, r1\n" - "\tsubs r3, 0x1\n" - "\tlsls r0, r3, 1\n" - "\tadds r0, r3\n" - "\tlsls r0, 2\n" - "\tadds r2, r0\n" - "\tadds r1, r4\n" - "\tadds r2, r4\n" - "\tldm r2!, {r0,r6,r7}\n" - "\tstm r1!, {r0,r6,r7}\n" - "\tcmp r3, 0\n" - "\tbgt _08096EFE\n" - "\tldr r2, [r5]\n" - "\tmovs r3, 0x8C\n" - "\tlsls r3, 2\n" - "\tadds r2, r3\n" - "\tmov r6, r12\n" - "\tldr r0, [r6, 0x4]\n" - "\tldr r1, [r6, 0x8]\n" - "\tstr r0, [r2]\n" - "\tstr r1, [r2, 0x4]\n" - "\tmov r0, r12\n" - "\tbl CalculateMailChecksum\n" - "\tldr r1, [r5]\n" - "\tmovs r7, 0x8E\n" - "\tlsls r7, 2\n" - "\tadds r1, r7\n" - "\tstr r0, [r1]\n" - "\tpop {r3}\n" - "\tmov r8, r3\n" - "\tpop {r4-r7}\n" - "\tpop {r0}\n" - "\tbx r0\n" - "\t.align 2, 0\n" -"_08096F4C: .4byte gUnknown_203B490"); -} -#endif bool8 sub_8096F50(WonderMail *mail) { @@ -227,9 +154,9 @@ bool8 sub_8096F50(WonderMail *mail) for (index = 0; index < 0x10; index++) { temp = &gUnknown_203B490->unk230[index]; - if (temp->dungeon.id == mail->unk4.dungeon.id) - if (temp->dungeon.floor == mail->unk4.dungeon.floor) - if (temp->seed == mail->unk4.seed) + if (temp->sub.dungeon.id == mail->unk4.dungeon.id) + if (temp->sub.dungeon.floor == mail->unk4.dungeon.floor) + if (temp->sub.seed == mail->unk4.seed) if (temp->checksum == checksum) return TRUE; } @@ -275,8 +202,8 @@ u32 RestoreMailInfo(u8 *r0, u32 size) for(index = 0; index < 0x10; index++) { RestoreIntegerBits(&backup, &gUnknown_203B490->unk230[index].checksum, 0x20); - RestoreIntegerBits(&backup, &gUnknown_203B490->unk230[index].seed, 0x18); - RestoreDungeonLocation(&backup, &gUnknown_203B490->unk230[index].dungeon); + RestoreIntegerBits(&backup, &gUnknown_203B490->unk230[index].sub.seed, 0x18); + RestoreDungeonLocation(&backup, &gUnknown_203B490->unk230[index].sub.dungeon); } nullsub_102(&backup); return backup.unk8; @@ -319,8 +246,8 @@ u32 SaveMailInfo(u8 *r0, u32 size) for(index = 0; index < 0x10; index++) { SaveIntegerBits(&backup, &gUnknown_203B490->unk230[index].checksum, 0x20); - SaveIntegerBits(&backup, &gUnknown_203B490->unk230[index].seed, 0x18); - SaveDungeonLocation(&backup, &gUnknown_203B490->unk230[index].dungeon); + SaveIntegerBits(&backup, &gUnknown_203B490->unk230[index].sub.seed, 0x18); + SaveDungeonLocation(&backup, &gUnknown_203B490->unk230[index].sub.dungeon); } nullsub_102(&backup); return backup.unk8;