From 2cdb9ea2e40d823bd148229802350c23d79f5cf0 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Fri, 29 Nov 2024 09:56:09 +0100 Subject: [PATCH] sub_807AB38 --- asm/code_8077274_1.s | 344 ------------------------------- include/structs/dungeon_entity.h | 2 +- ld_script.txt | 1 - src/code_804267C.c | 17 +- src/code_80450F8.c | 8 +- src/code_8069E0C.c | 4 +- src/code_8077274_1.c | 114 ++++++++++ src/code_807CD9C.c | 22 +- src/dungeon_serializer.c | 4 +- 9 files changed, 140 insertions(+), 376 deletions(-) delete mode 100644 asm/code_8077274_1.s diff --git a/asm/code_8077274_1.s b/asm/code_8077274_1.s deleted file mode 100644 index 65cdb1b1b..000000000 --- a/asm/code_8077274_1.s +++ /dev/null @@ -1,344 +0,0 @@ - #include "asm/constants/gba_constants.inc" - #include "asm/macros.inc" - - .syntax unified - - .text - - thumb_func_start sub_807AB38 -sub_807AB38: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x1A8 - adds r2, r0, 0 - lsls r1, 24 - lsrs r4, r1, 24 - ldr r0, [r2, 0x70] - ldrb r0, [r0, 0x6] - cmp r0, 0 - beq _0807AB54 - b _0807ADA6 -_0807AB54: - adds r0, r2, 0 - str r2, [sp, 0x1A4] - bl GetTileAtEntitySafe - ldrh r1, [r0] - movs r0, 0x40 - ands r0, r1 - ldr r2, [sp, 0x1A4] - cmp r0, 0 - bne _0807AB6A - b _0807ADA6 -_0807AB6A: - ldr r3, _0807AC10 - ldr r0, [r3] - ldr r5, _0807AC14 - adds r1, r0, r5 - ldrb r0, [r1] - cmp r0, 0 - beq _0807AB7A - b _0807ADA6 -_0807AB7A: - movs r0, 0x1 - strb r0, [r1] - ldr r3, [r3] - ldr r1, _0807AC18 - adds r0, r3, r1 - ldrb r1, [r0] - cmp r1, 0xFF - bne _0807AB8C - b _0807ADA6 -_0807AB8C: - lsls r0, r1, 3 - subs r0, r1 - lsls r0, 2 - ldr r5, _0807AC1C - adds r0, r5 - adds r3, r0 - movs r0, 0 - mov r8, r0 - cmp r4, 0 - beq _0807AC20 - movs r1, 0x6 - ldrsh r0, [r2, r1] - subs r6, r0, 0x4 - adds r0, 0x4 - cmp r6, r0 - ble _0807ABAE - b _0807ACB4 -_0807ABAE: - movs r4, 0x4 - ldrsh r0, [r2, r4] - subs r4, r0, 0x4 - adds r0, 0x4 - adds r5, r6, 0x1 - mov r9, r5 - cmp r4, r0 - bgt _0807AC00 - mov r1, r8 - lsls r0, r1, 2 - mov r1, sp - adds r5, r0, r1 -_0807ABC6: - adds r0, r4, 0 - adds r1, r6, 0 - str r2, [sp, 0x1A4] - bl GetTileMut - adds r1, r0, 0 - ldr r0, [r1, 0x10] - ldr r2, [sp, 0x1A4] - cmp r0, 0 - bne _0807ABF4 - ldrh r1, [r1] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x1 - bne _0807ABF4 - mov r0, r8 - cmp r0, 0x63 - bgt _0807ABF4 - strh r4, [r5] - strh r6, [r5, 0x2] - adds r5, 0x4 - movs r1, 0x1 - add r8, r1 -_0807ABF4: - adds r4, 0x1 - movs r1, 0x4 - ldrsh r0, [r2, r1] - adds r0, 0x4 - cmp r4, r0 - ble _0807ABC6 -_0807AC00: - mov r6, r9 - movs r4, 0x6 - ldrsh r0, [r2, r4] - adds r0, 0x4 - cmp r6, r0 - ble _0807ABAE - b _0807ACB4 - .align 2, 0 -_0807AC10: .4byte gDungeon -_0807AC14: .4byte 0x00000671 -_0807AC18: .4byte 0x00003a0c -_0807AC1C: .4byte 0x000104c4 -_0807AC20: - movs r5, 0x4 - ldrsh r0, [r2, r5] - subs r1, r0, 0x4 - movs r5, 0x2 - ldrsh r4, [r3, r5] - mov r10, r4 - cmp r10, r1 - bge _0807AC32 - mov r10, r1 -_0807AC32: - adds r1, r0, 0x5 - movs r0, 0x6 - ldrsh r7, [r3, r0] - cmp r7, r1 - ble _0807AC3E - adds r7, r1, 0 -_0807AC3E: - movs r1, 0x6 - ldrsh r0, [r2, r1] - subs r2, r0, 0x4 - movs r4, 0x4 - ldrsh r1, [r3, r4] - cmp r1, r2 - bge _0807AC4E - adds r1, r2, 0 -_0807AC4E: - adds r0, 0x5 - movs r5, 0x8 - ldrsh r2, [r3, r5] - cmp r2, r0 - ble _0807AC5A - adds r2, r0, 0 -_0807AC5A: - adds r6, r1, 0 - cmp r6, r2 - bge _0807ACB4 -_0807AC60: - mov r4, r10 - adds r0, r6, 0x1 - mov r9, r0 - cmp r4, r7 - bge _0807ACAE - mov r1, r8 - lsls r0, r1, 2 - mov r1, sp - adds r5, r0, r1 -_0807AC72: - adds r0, r4, 0 - adds r1, r6, 0 - str r2, [sp, 0x1A4] - bl GetTileMut - adds r1, r0, 0 - ldr r0, [r1, 0x10] - ldr r2, [sp, 0x1A4] - cmp r0, 0 - bne _0807ACA8 - ldrh r1, [r1] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x1 - bne _0807ACA8 - movs r0, 0x40 - ands r0, r1 - cmp r0, 0 - beq _0807ACA8 - mov r0, r8 - cmp r0, 0x63 - bgt _0807ACA8 - strh r4, [r5] - strh r6, [r5, 0x2] - adds r5, 0x4 - movs r1, 0x1 - add r8, r1 -_0807ACA8: - adds r4, 0x1 - cmp r4, r7 - blt _0807AC72 -_0807ACAE: - mov r6, r9 - cmp r6, r2 - blt _0807AC60 -_0807ACB4: - ldr r0, _0807AD74 - movs r2, 0 - ldrsh r0, [r0, r2] - ldr r1, _0807AD78 - movs r4, 0 - ldrsh r1, [r1, r4] - bl DungeonRandRange - adds r7, r0, 0 - cmp r7, r8 - blt _0807ACCC - mov r7, r8 -_0807ACCC: - movs r6, 0 - cmp r6, r7 - bge _0807ADA0 - mov r10, r6 -_0807ACD4: - mov r0, r8 - bl DungeonRandInt - adds r2, r0, 0 - movs r3, 0 - cmp r3, r8 - bge _0807AD0C - lsls r0, r2, 2 - mov r5, sp - adds r1, r5, r0 - movs r4, 0 - ldrsh r1, [r1, r4] - adds r5, r0, 0 - cmp r1, 0 - bne _0807AD1C -_0807ACF2: - adds r2, 0x1 - cmp r2, r8 - blt _0807ACFA - movs r2, 0 -_0807ACFA: - adds r3, 0x1 - cmp r3, r8 - bge _0807AD0C - lsls r0, r2, 2 - add r0, sp - movs r5, 0 - ldrsh r0, [r0, r5] - cmp r0, 0 - beq _0807ACF2 -_0807AD0C: - lsls r0, r2, 2 - mov r2, sp - adds r1, r2, r0 - movs r4, 0 - ldrsh r1, [r1, r4] - adds r5, r0, 0 - cmp r1, 0 - beq _0807ADA0 -_0807AD1C: - movs r0, 0x1 - bl sub_803D970 - add r4, sp, 0x190 - movs r1, 0 - strh r0, [r4] - mov r0, r10 - strh r0, [r4, 0x8] - strb r1, [r4, 0x2] - mov r1, r10 - str r1, [r4, 0x4] - movs r0, 0x1 - strb r0, [r4, 0x10] - mov r2, sp - adds r1, r2, r5 - ldrh r0, [r1] - strh r0, [r4, 0xC] - ldrh r0, [r1, 0x2] - strh r0, [r4, 0xE] - movs r5, 0 - ldrsh r0, [r4, r5] - movs r1, 0x1 - bl sub_806AA0C - lsls r0, 24 - adds r6, 0x1 - mov r9, r6 - cmp r0, 0 - beq _0807AD9A - adds r0, r4, 0 - movs r1, 0 - bl sub_806B7F8 - adds r4, r0, 0 - bl EntityExists - lsls r0, 24 - cmp r0, 0 - beq _0807AD9A - movs r0, 0xC8 - lsls r0, 8 - str r0, [r4, 0x1C] - movs r5, 0 - b _0807AD84 - .align 2, 0 -_0807AD74: .4byte gUnknown_80F4DA2 -_0807AD78: .4byte gUnknown_80F4DA4 -_0807AD7C: - movs r0, 0x57 - bl sub_803E46C - adds r5, 0x1 -_0807AD84: - cmp r5, 0x63 - bgt _0807AD96 - ldr r0, [r4, 0x1C] - movs r1, 0xAA - bl s24_8_mul - str r0, [r4, 0x1C] - cmp r0, 0xFF - bgt _0807AD7C -_0807AD96: - mov r0, r10 - str r0, [r4, 0x1C] -_0807AD9A: - mov r6, r9 - cmp r6, r7 - blt _0807ACD4 -_0807ADA0: - movs r0, 0x1 - bl sub_804178C -_0807ADA6: - add sp, 0x1A8 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_807AB38 - - .align 2,0 diff --git a/include/structs/dungeon_entity.h b/include/structs/dungeon_entity.h index b1a1830b2..73c900c3d 100644 --- a/include/structs/dungeon_entity.h +++ b/include/structs/dungeon_entity.h @@ -356,7 +356,7 @@ typedef struct Entity // X = (posWorld * 24 + 16) * 256, while Y = (posWorld * 24 + 12) * 256. /* 0xC */ PixelPos pixelPos; /* 0x14 */ PixelPos prevPixelPos; - s32 unk1C; + /* 0x1C */ s24_8 unk1C; /* 0x20 */ bool8 isVisible; // Turned off when a Pokémon faints. u8 unk21; u8 unk22; diff --git a/ld_script.txt b/ld_script.txt index e37e49c00..bba096d0b 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -265,7 +265,6 @@ SECTIONS { src/move_effects_target.o(.text); src/status.o(.text); src/code_8077274_1.o(.text); - asm/code_8077274_1.o(.text); src/dungeon_ai_movement.o(.text); src/dungeon_ai_attack.o(.text); src/targeting_flags.o(.text); diff --git a/src/code_804267C.c b/src/code_804267C.c index 594b049b7..6bc3c29a2 100644 --- a/src/code_804267C.c +++ b/src/code_804267C.c @@ -279,28 +279,23 @@ void sub_8042A74(Entity *r0) void sub_8042A84(s16 param_1, Entity *entity, u32 param_3) { - s32 iVar2; s32 iVar3; s32 r6; s32 param_1_s16; param_1_s16 = param_1; - r6 = 0x200; + r6 = IntToF248_2(2).raw; if (sub_8042768(entity)) { sub_804151C(entity,param_1_s16,0); sub_803E708(param_3,0x42); do { - if (0xc7ff < entity->unk1C) break; + if (entity->unk1C.raw > IntToF248_2(199.999).raw) break; sub_803E46C(0x42); - iVar2 = entity->unk1C + r6; - entity->unk1C = iVar2; - r6 += 0x100; - iVar3 = entity->pixelPos.y - iVar2; - if (iVar3 < 0) { - iVar3 += 0xff; - } - } while (-8 <= (iVar3 >> 8) - gDungeon->unk181e8.cameraPixelPos.y); + entity->unk1C.raw += + r6; + r6 += IntToF248_2(1).raw; + iVar3 = (entity->pixelPos.y - entity->unk1C.raw) / 256; + } while (-8 <= iVar3 - gDungeon->unk181e8.cameraPixelPos.y); entity->isVisible = 0; sub_804178C(0); } diff --git a/src/code_80450F8.c b/src/code_80450F8.c index b11aead96..7da0fbab5 100644 --- a/src/code_80450F8.c +++ b/src/code_80450F8.c @@ -57,7 +57,7 @@ Entity *sub_80453AC(s32 _species) entity->axObj.unk45_orientation = 1; entity->axObj.unk47 = 1; - entity->unk1C = 0; + entity->unk1C = IntToF248(0); sub_8045ACC(); entity->axObj.info.monster->unk167 = validId; entity->axObj.info.monster->unk168 = bodySize; @@ -118,7 +118,7 @@ Entity *sub_804550C(s32 _species) entity->axObj.unk45_orientation = 1; entity->axObj.unk47 = 1; - entity->unk1C = 0; + entity->unk1C = IntToF248(0); entity->axObj.info.monster->unk167 = validId; entity->axObj.info.monster->unk168 = bodySize; @@ -152,7 +152,7 @@ Entity *SpawnTrap(u8 trapID, DungeonPos *pos, u8 c) entity->axObj.info.trap->id = trapID; entity->axObj.info.trap->unk1 = c; - entity->unk1C = 0; + entity->unk1C = IntToF248(0); entity->unk22 = 0; entity->pos = *pos; entity->spawnGenID = 0; @@ -183,7 +183,7 @@ Entity *sub_8045708(DungeonPos *pos) SetEntityPixelPos(ent, ((pos->x * 24) + 4) * 0x100, ((pos->y * 24) + 4) * 0x100); ent->spawnGenID = 0; ent->unk22 = 0; - ent->unk1C = 0; + ent->unk1C = IntToF248(0); return ent; } } diff --git a/src/code_8069E0C.c b/src/code_8069E0C.c index 4c3267ac4..1f47f7648 100644 --- a/src/code_8069E0C.c +++ b/src/code_8069E0C.c @@ -2192,7 +2192,7 @@ void sub_806C51C(Entity *entity) entity->prevPixelPos.y = entity->pixelPos.y; x = (entity->pixelPos.x / 256) - gDungeon->unk181e8.cameraPixelPos.x; - y = (((entity->pixelPos.y - entity->unk1C) - entInfo->unk174.raw) / 256) - gDungeon->unk181e8.cameraPixelPos.y; + y = (((entity->pixelPos.y - entity->unk1C.raw) - entInfo->unk174.raw) / 256) - gDungeon->unk181e8.cameraPixelPos.y; y2 = (entity->pixelPos.y / 256) - gDungeon->unk181e8.cameraPixelPos.y; y2 /= 2; if (entInfo->unk156 == 0) { @@ -2215,7 +2215,7 @@ void sub_806C51C(Entity *entity) } pos1.x = entity->pixelPos.x / 256; - pos1.y = ((entity->pixelPos.y - entity->unk1C) - entInfo->unk174.raw) / 256; + pos1.y = ((entity->pixelPos.y - entity->unk1C.raw) - entInfo->unk174.raw) / 256; sub_8005700(posArray, &entity->axObj); sub_800F958(entInfo->unk98, &pos1, posArray, gDungeon->unk181e8.unk18208); diff --git a/src/code_8077274_1.c b/src/code_8077274_1.c index a4c5d1a1b..40bab6bf6 100644 --- a/src/code_8077274_1.c +++ b/src/code_8077274_1.c @@ -26,6 +26,7 @@ #include "structs/dungeon_entity.h" #include "structs/str_dungeon.h" #include "dungeon_map_access.h" +#include "structs/str_806B7F8.h" extern u8 *gUnknown_80FA8BC[]; extern u8 *gUnknown_80FA824[]; @@ -1657,3 +1658,116 @@ _WakeUp: } } } + +extern s16 sub_803D970(u32); +extern void sub_804178C(u32); +extern const s16 gUnknown_80F4DA2; +extern const s16 gUnknown_80F4DA4; + +void sub_807AB38(Entity *entity, bool8 forcedMonsterHouse) +{ + u8 monsterHouseRoomId; + DungeonPos positions[100]; + RoomData *monsterHouseRoomData; + s32 x, y, count; + s32 randMonstersCount; + + if (GetEntInfo(entity)->isNotTeamMember) + return; + if (!(GetTileAtEntitySafe(entity)->terrainType & TERRAIN_TYPE_IN_MONSTER_HOUSE)) + return; + + if (gDungeon->unk644.monsterHouseTriggered) + return; + gDungeon->unk644.monsterHouseTriggered = TRUE; + + monsterHouseRoomId = gDungeon->monsterHouseRoom; + if (monsterHouseRoomId == CORRIDOR_ROOM) + return; + + monsterHouseRoomData = &gDungeon->roomData[monsterHouseRoomId]; + count = 0; + if (forcedMonsterHouse) { + for (y = entity->pos.y - 4; y <= entity->pos.y + 4; y++) { + for (x = entity->pos.x - 4; x <= entity->pos.x + 4; x++) { + Tile *tile = GetTileMut(x, y); + if (tile->monster == NULL && GetTerrainType(tile) == TERRAIN_TYPE_NORMAL && count < 100) { + positions[count].x = x; + positions[count].y = y; + count++; + } + } + } + } + else { + s32 xStart, xEnd; + s32 yStart, yEnd; + + xStart = max(entity->pos.x - 4, monsterHouseRoomData->bottomRightCornerX); + xEnd = min(entity->pos.x + 5, monsterHouseRoomData->topLeftCornerX); + + yStart = max(entity->pos.y - 4, monsterHouseRoomData->bottomRightCornerY); + yEnd = min(entity->pos.y + 5, monsterHouseRoomData->topLeftCornerY); + for (y = yStart; y < yEnd; y++) { + for (x = xStart; x < xEnd; x++) { + Tile *tile = GetTileMut(x, y); + if (tile->monster == NULL && GetTerrainType(tile) == TERRAIN_TYPE_NORMAL && tile->terrainType & TERRAIN_TYPE_IN_MONSTER_HOUSE && count < 100) { + positions[count].x = x; + positions[count].y = y; + count++; + } + } + } + } + + randMonstersCount = DungeonRandRange(gUnknown_80F4DA2, gUnknown_80F4DA4); + if (randMonstersCount >= count) + randMonstersCount = count; + + for (y = 0; y < randMonstersCount; y++) { + s32 i, j; + s32 rndId = DungeonRandInt(count); + for (i = 0; i < count; i++) { + if (positions[rndId].x != 0) + break; + + rndId++; + if (rndId >= count) + rndId = 0; + } + + if (positions[rndId].x == 0) { + break; + } + else + { + struct unkStruct_806B7F8 spawnStruct; + + spawnStruct.species = sub_803D970(1); + spawnStruct.level = 0; + spawnStruct.unk2 = 0; + spawnStruct.unk4 = 0; + spawnStruct.unk10 = 1; + spawnStruct.pos.x = positions[rndId].x; + spawnStruct.pos.y = positions[rndId].y; + if (sub_806AA0C(spawnStruct.species, 1)) { + Entity *newMonster = sub_806B7F8(&spawnStruct, FALSE); + if (EntityExists(newMonster)) { + newMonster->unk1C = IntToF248_2(200); + for (j = 0; j < 100; j++) { + newMonster->unk1C = s24_8_mul(newMonster->unk1C, IntToF248_2(0.665)); + if (newMonster->unk1C.raw < IntToF248_2(1).raw) { + break; + } + sub_803E46C(0x57); + } + newMonster->unk1C = IntToF248_2(0); + } + } + } + + } + + sub_804178C(1); +} + diff --git a/src/code_807CD9C.c b/src/code_807CD9C.c index 63ace1931..68ff58bb1 100644 --- a/src/code_807CD9C.c +++ b/src/code_807CD9C.c @@ -227,7 +227,7 @@ void sub_807D068(Entity *pokemon, DungeonPos *pos) pixelY += incrementY; local_34.x = pixelX; local_34.y = pixelY; - pokemon->unk1C = sin_4096(iVar8) * 0xc; + pokemon->unk1C.raw = sin_4096(iVar8) * 0xc; sub_804535C(pokemon, &local_34); if (sub_8045888(pokemon)) { sub_803E46C(0x1a); @@ -237,7 +237,7 @@ void sub_807D068(Entity *pokemon, DungeonPos *pos) _0807D11E: local_34.x = posX; local_34.y = posY; - pokemon->unk1C = 0; + pokemon->unk1C = IntToF248(0); sub_804535C(pokemon,&local_34); sub_803E46C(0x1a); } @@ -276,15 +276,15 @@ void WarpTarget(Entity *pokemon, Entity *target, u32 param_3, DungeonPos *pos) sub_80421AC(pokemon,target); if (sub_8045888(target)) { direction = (info->action).direction; - target->unk1C += + 0x800; - while ( target->unk1C < 0xa000) { + target->unk1C.raw += + 0x800; + while ( target->unk1C.raw < 0xa000) { if ((gUnknown_202EDCC & 3) == 0) { direction = (direction + 1) & DIRECTION_MASK; info->action.direction = direction & DIRECTION_MASK; sub_806CE68(target,direction); } sub_803E46C(0x22); - target->unk1C += 0x800; + target->unk1C.raw += 0x800; } } @@ -322,7 +322,7 @@ void WarpTarget(Entity *pokemon, Entity *target, u32 param_3, DungeonPos *pos) sub_803F580(1); if (sub_8045888(target)) { direction = (info->action).direction; - target->unk1C = 0x9c00; + target->unk1C.raw = 0x9c00; do { if ((gUnknown_202EDCC & 3) == 0) { direction = (direction + 1) & DIRECTION_MASK; @@ -330,10 +330,10 @@ void WarpTarget(Entity *pokemon, Entity *target, u32 param_3, DungeonPos *pos) sub_806CE68(target,direction); } sub_803E46C(0x22); - target->unk1C -= 0x400; - } while (0 < target->unk1C); + target->unk1C.raw -= 0x400; + } while (0 < target->unk1C.raw); } - target->unk1C = 0; + target->unk1C = IntToF248_2(0); sub_803E46C(0x22); if (flag) { TryDisplayDungeonLoggableMessage3(pokemon,target,*gUnknown_80FCB14); // But it dropped back at the same spot! @@ -446,7 +446,7 @@ void HandleTrawlOrbAction(Entity *user, Entity *target) currItemEntity->spawnGenID = 0; currItemEntity->isVisible = TRUE; currItemEntity->unk22 = 0; - currItemEntity->unk1C = 0; + currItemEntity->unk1C = IntToF248_2(0); itemInfo[itemsCount] = gDungeon->unk3804[i]; currItemEntity++; itemsCount++; @@ -518,7 +518,7 @@ void HandleTrawlOrbAction(Entity *user, Entity *target) for (i = 0; i < itemsCount; i++) { if (EntityExists(&itemEntities[i])) { IncreaseEntityPixelPos(&itemEntities[i], itemVelocity[i].x, itemVelocity[i].y); - itemEntities[i].unk1C = sin_4096(unkAngle) * 0xC; + itemEntities[i].unk1C.raw = sin_4096(unkAngle) * 0xC; sub_80462AC(&itemEntities[i], hallucinating, 0, var, 0); } } diff --git a/src/dungeon_serializer.c b/src/dungeon_serializer.c index 59dbcdca9..9de009126 100644 --- a/src/dungeon_serializer.c +++ b/src/dungeon_serializer.c @@ -1158,7 +1158,7 @@ static Entity* sub_80828E0(s16 id, s16 apparentID, s32 index) entity->axObj.unk45_orientation = 1; entity->axObj.unk47 = 1; - entity->unk1C = 0; + entity->unk1C = IntToF248(0); sub_8045ACC(); entity->axObj.info.monster->unk167 = r4; entity->axObj.info.monster->unk168 = apparentBodySize; @@ -1214,7 +1214,7 @@ Entity* sub_8082A08(s32 _species, s32 _apparentSpecies, s32 index) entity->axObj.unk45_orientation = 1; entity->axObj.unk47 = 1; - entity->unk1C = 0; + entity->unk1C = IntToF248(0); entity->axObj.info.monster->unk167 = validId; entity->axObj.info.monster->unk168 = apparentBodySize;