sub_8051438

This commit is contained in:
DizzyEggg 2024-11-18 11:22:12 +01:00
parent 5fcb028d81
commit ad8c36c679
3 changed files with 110 additions and 309 deletions

View File

@ -5,276 +5,6 @@
.text
thumb_func_start sub_8051438
sub_8051438:
push {r4-r7,lr}
mov r7, r10
mov r6, r9
mov r5, r8
push {r5-r7}
sub sp, 0x1C
mov r9, r0
ldr r0, _080515AC
ldr r0, [r0]
str r0, [sp, 0x4]
ldr r2, _080515B0
ldr r4, _080515B4
adds r3, r0, r4
ldr r0, [r3]
ldr r0, [r0, 0x4]
lsls r1, 2
adds r0, r1, r0
ldr r0, [r0]
adds r0, 0x3
str r0, [r2]
ldr r2, _080515B8
movs r0, 0
strb r0, [r2]
ldr r0, [r3]
ldr r0, [r0, 0x4]
adds r1, r0
ldr r0, [r1]
ldrb r1, [r0, 0x2]
movs r0, 0x1
ands r0, r1
cmp r0, 0
bne _0805147A
b _080515D8
_0805147A:
ldr r5, [sp, 0x4]
ldr r0, _080515BC
adds r1, r5, r0
mov r2, r9
movs r3, 0
ldrsh r0, [r2, r3]
str r0, [r1]
ldr r4, _080515C0
adds r1, r5, r4
movs r5, 0x2
ldrsh r0, [r2, r5]
str r0, [r1]
ldr r0, [sp, 0x4]
ldr r2, _080515C4
adds r1, r0, r2
mov r3, r9
movs r4, 0x4
ldrsh r0, [r3, r4]
str r0, [r1]
ldr r5, [sp, 0x4]
ldr r0, _080515C8
adds r1, r5, r0
movs r2, 0x6
ldrsh r0, [r3, r2]
str r0, [r1]
movs r3, 0
str r3, [sp, 0x8]
mov r4, r9
movs r5, 0x2
ldrsh r4, [r4, r5]
mov r8, r4
mov r1, r9
movs r2, 0x6
ldrsh r0, [r1, r2]
cmp r8, r0
blt _080514C4
b _08051640
_080514C4:
mov r3, r9
movs r4, 0
ldrsh r7, [r3, r4]
movs r5, 0x4
ldrsh r0, [r3, r5]
ldr r1, [sp, 0x8]
adds r1, 0x1
str r1, [sp, 0x10]
mov r2, r8
adds r2, 0x1
str r2, [sp, 0xC]
cmp r7, r0
bge _08051598
ldr r4, _080515CC
ldr r3, [sp, 0x4]
adds r4, r3, r4
str r4, [sp, 0x14]
movs r5, 0
str r5, [sp, 0x18]
ldr r0, [sp, 0x8]
mov r10, r0
_080514EE:
bl sub_80511F0
adds r5, r0, 0
lsls r5, 24
lsrs r5, 24
adds r0, r7, 0
mov r1, r8
bl GetTileSafe
adds r6, r0, 0
ldr r1, [sp, 0x4]
ldr r2, _080515D0
adds r0, r1, r2
add r0, r10
strb r5, [r0]
ldr r3, [sp, 0x8]
lsls r4, r3, 1
adds r4, r3
lsls r4, 3
ldr r1, [sp, 0x14]
adds r0, r1, r4
movs r2, 0
str r2, [sp]
adds r1, r5, 0
adds r2, r7, 0
mov r3, r8
bl sub_805124C
ldrb r1, [r6, 0x9]
ldr r3, [sp, 0x18]
adds r4, r3
ldr r5, [sp, 0x4]
adds r4, r5, r4
adds r0, r6, 0
ldr r2, _080515CC
adds r4, r2
ldm r4!, {r2,r3,r5}
stm r0!, {r2,r3,r5}
ldm r4!, {r2,r3,r5}
stm r0!, {r2,r3,r5}
mov r3, r9
movs r4, 0
ldrsh r0, [r3, r4]
adds r0, 0x2
cmp r7, r0
blt _08051572
movs r5, 0x4
ldrsh r0, [r3, r5]
subs r0, 0x2
cmp r7, r0
bge _08051572
movs r2, 0x2
ldrsh r0, [r3, r2]
adds r0, 0x2
cmp r8, r0
blt _08051572
movs r4, 0x6
ldrsh r0, [r3, r4]
subs r0, 0x2
cmp r8, r0
bge _08051572
movs r0, 0x88
lsls r0, 1
strh r0, [r6]
movs r0, 0xE
strb r0, [r6, 0xE]
_08051572:
strb r1, [r6, 0x9]
ldr r5, [sp, 0x4]
ldr r2, _080515D4
adds r0, r5, r2
strb r1, [r0]
ldr r3, [sp, 0x14]
adds r3, 0xC0
str r3, [sp, 0x14]
ldr r4, [sp, 0x18]
adds r4, 0xC0
str r4, [sp, 0x18]
movs r5, 0x8
add r10, r5
adds r7, 0x1
mov r1, r9
movs r2, 0x4
ldrsh r0, [r1, r2]
cmp r7, r0
blt _080514EE
_08051598:
ldr r3, [sp, 0x10]
str r3, [sp, 0x8]
ldr r4, [sp, 0xC]
mov r8, r4
mov r5, r9
movs r1, 0x6
ldrsh r0, [r5, r1]
cmp r8, r0
blt _080514C4
b _08051640
.align 2, 0
_080515AC: .4byte gDungeon
_080515B0: .4byte gUnknown_202F1DC
_080515B4: .4byte 0x00013568
_080515B8: .4byte gUnknown_202F1E1
_080515BC: .4byte 0x0000e250
_080515C0: .4byte 0x0000e254
_080515C4: .4byte 0x0000e258
_080515C8: .4byte 0x0000e25c
_080515CC: .4byte 0x0000e27c
_080515D0: .4byte 0x0000e87c
_080515D4: .4byte 0x0000e8bc
_080515D8:
mov r2, r9
movs r3, 0x2
ldrsh r2, [r2, r3]
mov r8, r2
b _08051636
_080515E2:
mov r0, r9
movs r1, 0
ldrsh r7, [r0, r1]
movs r2, 0x4
ldrsh r0, [r0, r2]
mov r3, r8
adds r3, 0x1
str r3, [sp, 0xC]
cmp r7, r0
bge _08051632
_080515F6:
bl sub_80511F0
adds r4, r0, 0
lsls r4, 24
lsrs r4, 24
adds r0, r7, 0
mov r1, r8
bl GetTileSafe
adds r5, r0, 0
ldrb r6, [r5, 0x9]
movs r0, 0x1
str r0, [sp]
adds r0, r5, 0
adds r1, r4, 0
adds r2, r7, 0
mov r3, r8
bl sub_805124C
strb r6, [r5, 0x9]
ldr r4, [sp, 0x4]
ldr r5, _08051650
adds r0, r4, r5
strb r6, [r0]
adds r7, 0x1
mov r1, r9
movs r2, 0x4
ldrsh r0, [r1, r2]
cmp r7, r0
blt _080515F6
_08051632:
ldr r3, [sp, 0xC]
mov r8, r3
_08051636:
mov r4, r9
movs r5, 0x6
ldrsh r0, [r4, r5]
cmp r8, r0
blt _080515E2
_08051640:
add sp, 0x1C
pop {r3-r5}
mov r8, r3
mov r9, r4
mov r10, r5
pop {r4-r7}
pop {r0}
bx r0
.align 2, 0
_08051650: .4byte 0x0000e8bc
thumb_func_end sub_8051438
thumb_func_start sub_8051654
sub_8051654:
push {r4-r7,lr}

View File

@ -363,13 +363,12 @@ typedef struct Dungeon
Position stairsSpawn; // stairs location
Position unkE220[8];
struct MinMaxPosition kecleonShopPos;
u32 unkE250;
u8 fillE254[0xE260 - 0xE254];
struct MinMaxPosition unkE250;
Position unkE260;
/* 0xE264 */ Weather weather; // Uses the weather constants in weather.h.
/* 0xE27C */ Tile unkE27C[8][8];
/* 0xE87C */ u8 unkE87C[8][8];
u32 fillE8BC;
/* 0xE8BC */ u8 unkE8BC; // Seems to be some tile's room index;
/* 0xE8C0 */ Tile *tilePointers[DUNGEON_MAX_SIZE_Y][DUNGEON_MAX_SIZE_X];
u8 unk104C0;
/* 0x104C4 */ RoomData roomData[MAX_ROOM_COUNT];

View File

@ -102,7 +102,7 @@ void GenerateLineFloor(UnkDungeonGlobal_unk1C574 *a0);
void GenerateCrossFloor(UnkDungeonGlobal_unk1C574 *a0);
void GenerateBeetleFloor(UnkDungeonGlobal_unk1C574 *a0);
void GenerateOuterRoomsFloor(s32 gridSizeX_, s32 gridSizeY_, UnkDungeonGlobal_unk1C574 *unkPtr);
void sub_8051654(UnkDungeonGlobal_unk1C574 *a0);
void sub_8051654(UnkDungeonGlobal_unk1C574 *unkPtr);
void GenerateSecondaryTerrainFormations(u32 flag, UnkDungeonGlobal_unk1C574 *unkPtr);
void SpawnNonEnemies(UnkDungeonGlobal_unk1C574 *unkPtr, bool8 isEmptyMonsterHouse);
void SpawnEnemies(UnkDungeonGlobal_unk1C574 *unkPtr, bool8 isEmptyMonsterHouse);
@ -125,12 +125,6 @@ EWRAM_DATA s32 gUnknown_202F1D0 = 0;
static EWRAM_DATA s32 sNumTilesReachableFromStairs = 0;
static EWRAM_DATA Position sKecleonShopMiddlePos = {0};
struct PositionU8
{
u8 x;
u8 y;
};
// Helper functions for terrain flags
static inline void SetTerrainType(Tile *tile, u32 terrainType)
{
@ -158,6 +152,14 @@ static inline u32 GetTerrainType(Tile *tile)
return tile->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY);
}
struct FixedRoomsData
{
u8 x;
u8 y;
u8 unk2;
u8 unk3[0]; // Not sure about the size;
};
// Some weird-ass regswap prevents the function from being matched - https://decomp.me/scratch/9SUV3
#ifdef NONMATCHING
void sub_804AFAC(void)
@ -1647,9 +1649,8 @@ void GenerateOuterRoomsFloor(s32 gridSizeX_, s32 gridSizeY_, UnkDungeonGlobal_un
bool8 GenerateFixedFloor(s32 fixedRoomId, UnkDungeonGlobal_unk1C574 *unkPtr)
{
struct PositionU8 **fileData = (void *) gDungeon->unk13568->data;
s32 fixedRoomSizeX = fileData[fixedRoomId]->x;
s32 fixedRoomSizeY = fileData[fixedRoomId]->y;
s32 fixedRoomSizeX = ((struct FixedRoomsData **)(gDungeon->unk13568->data))[fixedRoomId]->x;
s32 fixedRoomSizeY = ((struct FixedRoomsData **)(gDungeon->unk13568->data))[fixedRoomId]->y;
s32 gridSizeX, gridSizeY;
if (fixedRoomSizeX == 0 || fixedRoomSizeY == 0) {
@ -4577,6 +4578,12 @@ void ResetFloor(void)
}
}
struct PositionU8
{
u8 x;
u8 y;
};
/*
* ShuffleSpawnPositions - Randomly shuffle an array of spawn positions
*/
@ -6426,48 +6433,52 @@ void sub_8051288(s32 fixedRoomId)
{
s32 x, y;
Dungeon *dungeon = gDungeon;
struct PositionU8 **fileData = (void *) dungeon->unk13568->data;
s32 fixedRoomSizeX = fileData[fixedRoomId]->x;
s32 fixedRoomSizeY = fileData[fixedRoomId]->y;
s32 fixedRoomSizeX = ((struct FixedRoomsData **)(dungeon->unk13568->data))[fixedRoomId]->x;
s32 fixedRoomSizeY = ((struct FixedRoomsData **)(dungeon->unk13568->data))[fixedRoomId]->y;
dungeon->unkE260.x = fixedRoomSizeX;
dungeon->unkE260.y = fixedRoomSizeY;
// FIX ME
gUnknown_202F1DC = ((u8 **)(dungeon->unk13568->data))[fixedRoomId] + 3;
gUnknown_202F1DC = ((struct FixedRoomsData **)(dungeon->unk13568->data))[fixedRoomId]->unk3;
gUnknown_202F1E1 = 0;
for (x = 5; x < fixedRoomSizeX + 5; x++) {
for (y = 5; y < fixedRoomSizeY + 5; y++) {
for (y = 5; y < fixedRoomSizeY + 5; y++) {
for (x = 5; x < fixedRoomSizeX + 5; x++) {
u8 unk = sub_80511F0();
if (sub_805124C(GetTileSafe(x, y), unk, x, y, 1)) {
dungeon->unkE260.x = x;
dungeon->unkE260.y = y;
dungeon->stairsSpawn.x = x;
dungeon->stairsSpawn.y = y;
}
}
}
for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) {
for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) {
if (y > 4)
Tile *tile = GetTileSafe(x, y);
if (GetTerrainType(tile) == TERRAIN_TYPE_WALL) {
tile->terrainType |= TERRAIN_TYPE_IMPASSABLE_WALL;
}
}
}
if (fixedRoomId != 4) {
for (x = 0; x < 17; x++) {
for (y = 0; y < 5; y++) {
for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) {
for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) {
if (x <= 4 || x >= fixedRoomSizeX + 5 || y <= 4 || y >= fixedRoomSizeY + 5) {
Tile *tile = GetTileSafe(x, y);
tile->terrainType |= TERRAIN_TYPE_IMPASSABLE_WALL;
if (gUnknown_202F1A8 != 0) {
SetTerrainType(tile, TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY);
}
else {
SetTerrainWall(tile);
}
}
}
}
if (gDungeon->tileset < 64) {
for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) {
for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) {
if (fixedRoomId == 4) {
for (y = 5; y < 17; y++) {
for (x = 2; x < 5; x++) {
Tile *tile = GetTileSafe(x, y);
tile->terrainType |= TERRAIN_TYPE_IMPASSABLE_WALL;
SetTerrainWall(tile);
}
}
}
if (gDungeon->tileset >= 64) {
for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) {
for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) {
Tile *tile = GetTileSafe(x, y);
if (GetTerrainType(tile) == TERRAIN_TYPE_WALL) {
tile->terrainType |= TERRAIN_TYPE_IMPASSABLE_WALL;
@ -6479,4 +6490,65 @@ void sub_8051288(s32 fixedRoomId)
sub_804E9DC();
}
void sub_8051438(struct GridCell *gridCell, s32 fixedRoomId)
{
s32 x, y;
Dungeon *dungeon = gDungeon;
gUnknown_202F1DC = ((struct FixedRoomsData **)(dungeon->unk13568->data))[fixedRoomId]->unk3;
gUnknown_202F1E1 = 0;
if (((struct FixedRoomsData **)(dungeon->unk13568->data))[fixedRoomId]->unk2 & 1) {
s32 yIndex;
dungeon->unkE250.minX = gridCell->start.x;
dungeon->unkE250.minY = gridCell->start.y;
dungeon->unkE250.maxX = gridCell->end.x;
dungeon->unkE250.maxY = gridCell->end.y;
yIndex = 0;
for (y = gridCell->start.y; y < gridCell->end.y; y++) {
s32 xIndex = 0;
for (x = gridCell->start.x; x < gridCell->end.x; x++) {
u8 roomId;
u8 unk = sub_80511F0();
Tile *tile = GetTileSafe(x, y);
dungeon->unkE87C[xIndex][yIndex] = unk;
sub_805124C(&dungeon->unkE27C[xIndex][yIndex], unk, x, y, 0);
roomId = tile->room;
*tile = dungeon->unkE27C[xIndex][yIndex];
if (x >= gridCell->start.x + 2 && x < gridCell->end.x - 2 && y >= gridCell->start.y + 2 && y < gridCell->end.y - 2) {
tile->terrainType = TERRAIN_TYPE_IMPASSABLE_WALL | TERRAIN_TYPE_UNBREAKABLE;
tile->unkE = 0xE;
}
tile->room = roomId;
dungeon->unkE8BC = roomId;
xIndex++;
}
yIndex++;
}
}
else {
for (y = gridCell->start.y; y < gridCell->end.y; y++) {
for (x = gridCell->start.x; x < gridCell->end.x; x++) {
u8 unk = sub_80511F0();
Tile *tile = GetTileSafe(x, y);
u8 roomId = tile->room;
sub_805124C(tile, unk, x, y, 1);
tile->room = roomId;
dungeon->unkE8BC = roomId;
}
}
}
}
/*
void sub_8051654(UnkDungeonGlobal_unk1C574 *unkPtr)
{
}
*/
//