#include "classes.h" // 009addf0 byte LevelGenerator::try_add_dead_end(int unused, void *excludedGridIndices) { void *pvVar1; byte bVar2; int iVar3; LevelGenerator LVar4; undefined4 extraout_ECX; undefined4 extraout_ECX_00; undefined4 extraout_ECX_01; undefined4 extraout_ECX_02; undefined4 uVar5; int *piVar6; LevelGenerator_Room LVar7; uint uVar8; LevelGenerator_Room candidate; void *candidateGridIndex; undefined1 local_40 [8]; int local_38; int *roomOrder; int *local_30; int *roomOrderCapacityEnd; LevelGenerator_Room candidates; LevelGenerator_Room candidatesLast; int candidatesCapacityEnd; int *local_18; LevelGenerator *generator; void *local_10; undefined1 *puStack_c; undefined4 local_8; local_8 = 0xffffffff; puStack_c = &LAB_00b0e1a5; local_10 = ExceptionList; ExceptionList = &local_10; LVar4 = this[0xda]; uVar8 = (GHIDRA_INT(LVar4) - GHIDRA_INT(this[0xd9])) / 0x48; roomOrder = GHIDRA_CAST(0x0); local_18 = GHIDRA_CAST(0x0); local_30 = GHIDRA_CAST(0x0); roomOrderCapacityEnd = GHIDRA_CAST(0x0); generator = this; if (uVar8 != 0) { if (0x3fffffff < uVar8) { /* WARNING: Subroutine does not return */ std::_Xlen(); } roomOrder = std::_Allocate(uVar8 * 4); piVar6 = roomOrder + uVar8; roomOrderCapacityEnd = piVar6; local_18 = piVar6; memset(roomOrder,0,uVar8 * 4); LVar4 = this[0xda]; local_30 = piVar6; } (*GHIDRA_CAST((GHIDRA_CAST(&(local_8)) + 0x0))) = 0; (*GHIDRA_CAST((GHIDRA_CAST(&(local_8)) + 0x1))) = 0; uVar8 = 0; iVar3 = GHIDRA_INT(LVar4) - GHIDRA_INT(this[0xd9]) >> 0x1f; if ((GHIDRA_INT(LVar4) - GHIDRA_INT(this[0xd9])) / 0x48 + iVar3 != iVar3) { do { roomOrder[uVar8] = uVar8; uVar8 = uVar8 + 1; } while (uVar8 < GHIDRA_UINT(((GHIDRA_INT(this[0xda]) - GHIDRA_INT(this[0xd9])) / 0x48))); } RNG::Shuffle(GHIDRA_CAST(this),roomOrder,local_18); pvVar1 = excludedGridIndices; LVar4 = this[0xd9]; local_18 = GHIDRA_CAST(0x0); iVar3 = GHIDRA_INT(this[0xda]) - GHIDRA_INT(LVar4) >> 0x1f; if ((GHIDRA_INT(this[0xda]) - GHIDRA_INT(LVar4)) / 0x48 + iVar3 != iVar3) { do { get_neighbor_candidates (this,&candidates,*GHIDRA_CAST((GHIDRA_CAST(LVar4) + 4 + roomOrder[GHIDRA_INT(local_18)] * 0x48)),1); (*GHIDRA_CAST((GHIDRA_CAST(&(local_8)) + 0x0))) = 1; uVar5 = extraout_ECX; LVar7 = candidatesLast; candidate = candidates; if (candidates != candidatesLast) { do { if (*GHIDRA_CAST((GHIDRA_CAST(candidate) + 0x18)) == (LevelGenerator_Room)0x1) { bVar2 = can_place_room(generator,GHIDRA_CAST((GHIDRA_INT(candidate) + 8)),1); uVar5 = extraout_ECX_00; if ((bVar2 != 0) && (iVar3 = count_neighbor_rooms(generator,GHIDRA_CAST((GHIDRA_INT(candidate) + 0x28))), uVar5 = extraout_ECX_01, iVar3 < 2)) { if (pvVar1 != (void *)0x0) { LVar7 = *GHIDRA_CAST((GHIDRA_CAST(candidate) + 8)); if ((GHIDRA_UINT(LVar7) < 0xd) && (*GHIDRA_CAST((GHIDRA_CAST(candidate) + 0xc)) < 0xd)) { candidateGridIndex = (void *)(*GHIDRA_CAST((GHIDRA_CAST(candidate) + 0xc)) * 0xd + GHIDRA_INT(LVar7)); } else { candidateGridIndex = (void *)0xffffffff; } excludedGridIndices = candidateGridIndex; std::set::find_node(local_40,&excludedGridIndices); if (((*GHIDRA_CAST((local_38 + 0xd)) == '\0') && (*GHIDRA_CAST((local_38 + 0x10)) <= GHIDRA_INT(candidateGridIndex))) && (uVar5 = extraout_ECX_02, local_38 != *GHIDRA_CAST(pvVar1))) goto LAB_009adfbd; } bVar2 = place_room(generator,GHIDRA_CAST(candidate)); update_dead_end_lists(generator); vector_LevelGenerator_Room_tidy(&candidates); goto LAB_009ae06b; } LAB_009adfbd: LVar7 = candidatesLast; } candidate = (LevelGenerator_Room)(GHIDRA_INT(candidate) + 0x48); } while (candidate != LVar7); this = generator; } (*GHIDRA_CAST((GHIDRA_CAST(&(local_8)) + 0x0))) = 0; if (candidates != (LevelGenerator_Room)0x0) { FUN_00752e40(uVar5); uVar8 = ((candidatesCapacityEnd - GHIDRA_INT(candidates)) / 0x48) * 0x48; LVar7 = candidates; if (0xfff < uVar8) { LVar7 = *GHIDRA_CAST((GHIDRA_CAST(candidates) + -4)); uVar8 = uVar8 + 0x23; if (0x1f < (GHIDRA_INT(candidates) - GHIDRA_INT(LVar7)) - 4U) goto LAB_009ae094; } operator_delete((void *)LVar7,uVar8); candidates = (LevelGenerator_Room)0x0; candidatesLast = (LevelGenerator_Room)0x0; candidatesCapacityEnd = 0; } LVar4 = this[0xd9]; local_18 = GHIDRA_CAST((GHIDRA_INT(local_18) + 1)); } while (local_18 < GHIDRA_UINT(((GHIDRA_INT(this[0xda]) - GHIDRA_INT(LVar4)) / 0x48))); } bVar2 = 0; LAB_009ae06b: if (roomOrder != GHIDRA_CAST(0x0)) { uVar8 = GHIDRA_INT(roomOrderCapacityEnd) - GHIDRA_INT(roomOrder) & 0xfffffffc; piVar6 = roomOrder; if (0xfff < uVar8) { piVar6 = GHIDRA_CAST(roomOrder[-1]); uVar8 = uVar8 + 0x23; if (0x1f < GHIDRA_UINT((GHIDRA_INT(roomOrder) + (-4 - GHIDRA_INT(piVar6))))) { LAB_009ae094: /* WARNING: Subroutine does not return */ _invalid_parameter_noinfo_noreturn(); } } operator_delete(piVar6,uVar8); } ExceptionList = local_10; return bVar2; } // 009ae0e0 LevelGenerator_Room * LevelGenerator::GetNewEndRoom(int roomShape, uint *possibleDoors) { LevelGenerator_Room *room; byte isResized; int *deadEndIt; LevelGenerator nextIt; deadEndIt = *GHIDRA_CAST((this + 0xdc)); if ((LevelGenerator)deadEndIt != this[0xdd]) { do { nextIt = (LevelGenerator)(deadEndIt + 1); room = GHIDRA_CAST((GHIDRA_INT(this[0xd9]) + *deadEndIt * 0x48)); isResized = try_resize_room(this,room,roomShape,possibleDoors); if (isResized != 0) { memmove(deadEndIt,(void *)nextIt,GHIDRA_INT(this[0xdd]) - GHIDRA_INT(nextIt)); this[0xdd] = (LevelGenerator)(GHIDRA_INT(this[0xdd]) + -4); return room; } deadEndIt = GHIDRA_CAST(nextIt); } while (nextIt != this[0xdd]); } return GHIDRA_CAST(0x0); } // 009ae170 void * LevelGenerator::place_secret_room(void *excludedIndices) { code *pcVar1; uint *puVar2; void *pvVar3; uint uVar4; LevelGenerator rngState; int iVar5; int *doorTarget; uint uVar6; uint *puVar7; int iVar8; uint dir; LevelGenerator *pLVar9; int doorTargetPos [2]; undefined1 local_c0 [8]; int foundNode; uint cellIndex; int bestScore; int cellScore; uint *bestCells; uint *bestCellsEnd; uint *bestCellsCapacity; void *local_9c; uint local_98; uint *cellsCapacity; uint local_90; LevelGenerator *cellSlot; uint *cellsBegin; uint *local_84; LevelGenerator_Room newRoom [12]; void *local_50 [5]; undefined1 local_3c; int neighborOffsets [10]; void *local_10; undefined1 *puStack_c; int local_8; puStack_c = &LAB_00b0e1e8; local_10 = ExceptionList; neighborOffsets[8] = __security_cookie ^ GHIDRA_UINT((neighborOffsets + 0xd)); ExceptionList = &local_10; puVar7 = GHIDRA_CAST(0x0); neighborOffsets[0] = -1; neighborOffsets[1] = 0; neighborOffsets[2] = 0; neighborOffsets[3] = 0xffffffff; puVar2 = GHIDRA_CAST(0x0); neighborOffsets[4] = 1; neighborOffsets[5] = 0; neighborOffsets[6] = 0; neighborOffsets[7] = 1; bestScore = 0; cellsBegin = GHIDRA_CAST(0x0); bestCells = GHIDRA_CAST(0x0); local_84 = GHIDRA_CAST(0x0); bestCellsEnd = GHIDRA_CAST(0x0); cellsCapacity = GHIDRA_CAST(0x0); bestCellsCapacity = GHIDRA_CAST(0x0); local_8 = 0; cellSlot = this + 5; cellIndex = 0; do { pLVar9 = cellSlot; uVar4 = cellIndex; if (GHIDRA_INT(*cellSlot) < 0) { local_98 = cellIndex; std::set::find_node(local_c0,&local_98); if ((((*GHIDRA_CAST((foundNode + 0xd)) == '\0') && (*GHIDRA_CAST((foundNode + 0x10)) <= GHIDRA_INT(uVar4))) && (foundNode != *GHIDRA_CAST(excludedIndices))) || ((&(*GHIDRA_CAST((GHIDRA_CAST(&(this[0xae])) + 0x0))))[uVar4] != '\0')) { puVar2 = local_84; puVar7 = cellsBegin; } else { rngState = *this; local_90 = uVar4 / 0xd; local_9c = (void *)(uVar4 % 0xd); if (rngState == (LevelGenerator)0x0) { KAGE_LogMessage(0x10,GHIDRA_CAST("RNG Seed is zero!\n")); rngState = *this; if (rngState == (LevelGenerator)0x0) { pcVar1 = (code *)swi(3); pvVar3 = (void *)(*pcVar1)(); return pvVar3; } } uVar4 = GHIDRA_UINT(rngState) >> (SUB41(this[1],0) & 0x1f) ^ GHIDRA_UINT(rngState); local_98 = 0; uVar4 = uVar4 << (SUB41(this[2],0) & 0x1f) ^ uVar4; rngState = (LevelGenerator)(uVar4 >> (SUB41(this[3],0) & 0x1f) ^ uVar4); *this = rngState; iVar8 = GHIDRA_UINT(rngState) % 5 + 10; dir = 0; cellScore = iVar8; do { uVar6 = local_98; if (GHIDRA_UINT((GHIDRA_INT(local_9c) + neighborOffsets[dir * 2])) < 0xd) { if (neighborOffsets[dir * 2 + 1] + local_90 < 0xd) { iVar5 = (neighborOffsets[dir * 2 + 1] + local_90) * 0xd + GHIDRA_INT(local_9c) + neighborOffsets[dir * 2]; if (-1 < iVar5) { if (-1 < GHIDRA_INT(this[iVar5 + 5])) { iVar8 = GHIDRA_INT(this[0xd9]) + GHIDRA_INT(this[iVar5 + 5]) * 0x48; doorTarget = get_door_target_position (doorTargetPos,GHIDRA_CAST((iVar8 + 8)),*GHIDRA_CAST((iVar8 + 0x18)), dir - 2 & 3,0); if ((*doorTarget == g_levelGenInvalidPos[0]) && (doorTarget[1] == g_levelGenInvalidPos[1])) { cellScore = cellScore + -100; iVar8 = cellScore; } else { uVar6 = uVar6 + 1; iVar8 = cellScore; local_98 = uVar6; } } } } } uVar4 = cellIndex; dir = dir + 1; } while (dir < 4); if ((uVar6 != 0) && (-1 < iVar8)) { iVar5 = iVar8 + -3; if (2 < GHIDRA_INT(local_98)) { iVar5 = iVar8; } iVar8 = iVar5 + -3; if (1 < GHIDRA_INT(local_98)) { iVar8 = iVar5; } if (bestScore < iVar8) { bestCellsEnd = cellsBegin; local_90 = cellIndex; bestScore = iVar8; if (cellsBegin == cellsCapacity) { std::vector::_Emplace_reallocate(cellsBegin,&local_90); cellsCapacity = bestCellsCapacity; local_84 = bestCellsEnd; cellsBegin = bestCells; } else { bestCellsEnd = cellsBegin + 1; *cellsBegin = cellIndex; local_84 = bestCellsEnd; } } else if (iVar8 == bestScore) { local_90 = cellIndex; if (local_84 == cellsCapacity) { std::vector::_Emplace_reallocate(local_84,&local_90); cellsCapacity = bestCellsCapacity; local_84 = bestCellsEnd; cellsBegin = bestCells; } else { *local_84 = cellIndex; bestCellsEnd = local_84 + 1; local_84 = bestCellsEnd; } } } puVar2 = local_84; puVar7 = cellsBegin; pLVar9 = cellSlot; } } cellIndex = uVar4 + 1; cellSlot = pLVar9 + 1; } while (cellIndex < 0xa9); local_84 = GHIDRA_CAST((GHIDRA_INT(puVar2) - GHIDRA_INT(puVar7) >> 2)); if (local_84 == GHIDRA_CAST(0x0)) { pvVar3 = (void *)0x0; } else { rngState = *this; if (rngState == (LevelGenerator)0x0) { KAGE_LogMessage(0x10,GHIDRA_CAST("RNG Seed is zero!\n")); rngState = *this; if (rngState == (LevelGenerator)0x0) { pcVar1 = (code *)swi(3); pvVar3 = (void *)(*pcVar1)(); return pvVar3; } } uVar4 = GHIDRA_UINT(rngState) >> (SUB41(this[1],0) & 0x1f) ^ GHIDRA_UINT(rngState); uVar4 = uVar4 ^ uVar4 << (SUB41(this[2],0) & 0x1f); rngState = (LevelGenerator)(uVar4 ^ uVar4 >> (SUB41(this[3],0) & 0x1f)); *this = rngState; uVar4 = cellsBegin[GHIDRA_UINT(rngState) % GHIDRA_UINT(local_84)]; local_90 = GHIDRA_INT(uVar4) % 0xd; (GHIDRA_CAST((newRoom)))->LevelGenerator_Room::constructor(local_90,GHIDRA_INT(uVar4) / 0xd,1); local_8 = CONCAT31((*GHIDRA_CAST((GHIDRA_CAST(&(local_8)) + 0x1))),1); local_3c = 1; place_room(this,newRoom); local_9c = (void *)(GHIDRA_INT(this[0xd9]) + GHIDRA_INT(this[uVar4 + 5]) * 0x48); update_room_neighbors(this,local_9c); dir = 0; do { uVar6 = neighborOffsets[dir * 2 + 1] + GHIDRA_INT(uVar4) / 0xd; if ((((local_90 + neighborOffsets[dir * 2] < 0xd) && (uVar6 < 0xd)) && (iVar8 = uVar6 * 0xd + local_90 + neighborOffsets[dir * 2], -1 < iVar8)) && (-1 < GHIDRA_INT(this[iVar8 + 5]))) { update_room_neighbors(this,(void *)(GHIDRA_INT(this[0xd9]) + GHIDRA_INT(this[iVar8 + 5]) * 0x48)); } dir = dir + 1; } while (dir < 4); FID_conflict__Erase_tree_>_> (local_50,(fuzzer_allocator_> *)local_50, *(_Tree_node **)(GHIDRA_INT(local_50[0]) + 4)); operator_delete(local_50[0],0x14); puVar7 = cellsBegin; pvVar3 = local_9c; } if (puVar7 != GHIDRA_CAST(0x0)) { uVar4 = GHIDRA_INT(cellsCapacity) - GHIDRA_INT(puVar7) & 0xfffffffc; puVar2 = puVar7; if (0xfff < uVar4) { puVar2 = GHIDRA_CAST(puVar7[-1]); uVar4 = uVar4 + 0x23; if (0x1f < GHIDRA_UINT((GHIDRA_INT(puVar7) + (-4 - GHIDRA_INT(puVar2))))) { /* WARNING: Subroutine does not return */ _invalid_parameter_noinfo_noreturn(); } } operator_delete(puVar2,uVar4); } ExceptionList = local_10; return pvVar3; } // 009ae640 void * LevelGenerator::try_place_room(void *allowedIndices) { code *pcVar1; uint *puVar2; void *result; uint uVar3; LevelGenerator seed; int iVar4; int iVar5; uint *puVar6; uint uVar7; uint uVar8; undefined1 local_128 [8]; int local_120; undefined1 local_11c [8]; int local_114; uint doorTargetX; uint doorTargetY; uint column; LevelGenerator *local_104; uint neighborDir; uint *local_fc; uint *local_f8; uint *local_f4; void *local_f0; uint score; int offsetX; int neighborRoom; uint local_e0; uint *candidatesCapacity; uint local_d8; LevelGenerator *gridSlot; uint gridIndex; uint local_cc; uint *candidatesBegin; uint *local_c4; LevelGenerator_Room newRoom [12]; void *local_90 [5]; undefined1 local_7c; int neighborOffsets [26]; void *local_10; undefined1 *puStack_c; int local_8; puStack_c = &LAB_00b0e23b; local_10 = ExceptionList; neighborOffsets[0x18] = __security_cookie ^ GHIDRA_UINT((neighborOffsets + 0x1d)); ExceptionList = &local_10; puVar6 = GHIDRA_CAST(0x0); neighborOffsets[0x10] = 0xffffffff; neighborOffsets[0x11] = 0; neighborOffsets[0x12] = 0; neighborOffsets[0x13] = 0xffffffff; puVar2 = GHIDRA_CAST(0x0); neighborOffsets[0x14] = 1; neighborOffsets[0x15] = 0; neighborOffsets[0x16] = 0; neighborOffsets[0x17] = 1; local_e0 = 0; neighborOffsets[0] = -2; neighborOffsets[1] = 0; neighborOffsets[2] = 0xffffffff; neighborOffsets[3] = 0xffffffff; candidatesBegin = GHIDRA_CAST(0x0); neighborOffsets[4] = 0; neighborOffsets[5] = 0xfffffffe; neighborOffsets[6] = 1; neighborOffsets[7] = 0xffffffff; local_fc = GHIDRA_CAST(0x0); neighborOffsets[8] = 2; neighborOffsets[9] = 0; neighborOffsets[10] = 1; neighborOffsets[0xb] = 1; local_c4 = GHIDRA_CAST(0x0); neighborOffsets[0xc] = 0; neighborOffsets[0xd] = 2; neighborOffsets[0xe] = 0xffffffff; neighborOffsets[0xf] = 1; local_f8 = GHIDRA_CAST(0x0); candidatesCapacity = GHIDRA_CAST(0x0); local_f4 = GHIDRA_CAST(0x0); gridSlot = this + 5; local_8 = 0; gridIndex = 0; local_104 = this; do { uVar3 = gridIndex; if (GHIDRA_INT(*gridSlot) < 0) { if (*GHIDRA_CAST((GHIDRA_INT(&(*GHIDRA_CAST((GHIDRA_CAST(&(this[0xae])) + 0x0)))) + gridIndex)) == '\0') { if (allowedIndices == (void *)0x0) { LAB_009ae755: seed = *this; if (seed == (LevelGenerator)0x0) { KAGE_LogMessage(0x10,GHIDRA_CAST("RNG Seed is zero!\n")); seed = *this; if (seed == (LevelGenerator)0x0) { pcVar1 = (code *)swi(3); result = (void *)(*pcVar1)(); return result; } } uVar3 = GHIDRA_UINT(seed) >> (SUB41(this[1],0) & 0x1f) ^ GHIDRA_UINT(seed); uVar3 = uVar3 << (SUB41(this[2],0) & 0x1f) ^ uVar3; seed = (LevelGenerator)(uVar3 >> (SUB41(this[3],0) & 0x1f) ^ uVar3); *this = seed; uVar7 = GHIDRA_UINT(seed) % 5; score = uVar7 + 10; local_d8 = 0; local_f0 = (void *)(gridIndex / 0xd); column = gridIndex % 0xd; uVar3 = 0; do { if (((column + neighborOffsets[uVar3 * 2 + 0x10] < 0xd) && (GHIDRA_UINT((neighborOffsets[uVar3 * 2 + 0x11] + GHIDRA_INT(local_f0))) < 0xd)) && ((iVar4 = (neighborOffsets[uVar3 * 2 + 0x11] + GHIDRA_INT(local_f0)) * 0xd + column + neighborOffsets[uVar3 * 2 + 0x10], -1 < iVar4 && ((-1 < GHIDRA_INT(this[iVar4 + 5]) || (*GHIDRA_CAST((GHIDRA_CAST(this) + iVar4 + 0x2b8)) != '\0')))))) { score = uVar7 - 0x5a; if (GHIDRA_INT(score) < 0) goto LAB_009aeaab; break; } uVar3 = uVar3 + 1; } while (uVar3 < 4); neighborDir = 0; do { if (GHIDRA_INT(score) < 0) break; iVar4 = neighborOffsets[neighborDir * 2]; offsetX = iVar4; if ((column + iVar4 < 0xd) && (GHIDRA_UINT((neighborOffsets[neighborDir * 2 + 1] + GHIDRA_INT(local_f0))) < 0xd)) { iVar5 = (neighborOffsets[neighborDir * 2 + 1] + GHIDRA_INT(local_f0)) * 0xd + column + iVar4; if (-1 < iVar5) { if (-1 < GHIDRA_INT(this[iVar5 + 5])) { uVar3 = 0; iVar5 = GHIDRA_INT(this[0xd9]) + GHIDRA_INT(this[iVar5 + 5]) * 0x48; neighborRoom = iVar5; do { if (0 < neighborOffsets[uVar3 * 2 + 0x11] * neighborOffsets[neighborDir * 2 + 1] + neighborOffsets[uVar3 * 2 + 0x10] * iVar4) { get_door_target_position (GHIDRA_CAST(&doorTargetX),GHIDRA_CAST((iVar5 + 8)),*GHIDRA_CAST((iVar5 + 0x18)), uVar3 - 2 & 3,0); if ((doorTargetX < 0xd) && (doorTargetY < 0xd)) { uVar7 = doorTargetY * 0xd + doorTargetX; local_cc = uVar7; if ((-1 < GHIDRA_INT(uVar7)) && ((((allowedIndices == (void *)0x0 || (std::set::find_node(local_128,&local_cc), *GHIDRA_CAST((local_120 + 0xd)) != '\0')) || (GHIDRA_INT(uVar7) < *GHIDRA_CAST((local_120 + 0x10)))) || (local_120 == *GHIDRA_CAST(allowedIndices))))) { iVar5 = neighborRoom; iVar4 = offsetX; goto LAB_009ae936; } } else { local_cc = 0xffffffff; } score = score - 100; break; } LAB_009ae936: uVar3 = uVar3 + 1; } while (uVar3 < 4); local_d8 = local_d8 + 1; this = local_104; } } } neighborDir = neighborDir + 1; } while (neighborDir < 8); uVar3 = gridIndex; if ((local_d8 != 0) && (-1 < GHIDRA_INT(score))) { uVar7 = score - 3; if (2 < GHIDRA_INT(local_d8)) { uVar7 = score; } uVar8 = uVar7 - 3; if (1 < GHIDRA_INT(local_d8)) { uVar8 = uVar7; } if (GHIDRA_INT(uVar8) <= GHIDRA_INT(local_e0)) { if (uVar8 == local_e0) { local_cc = gridIndex; if (local_c4 == candidatesCapacity) { std::vector::_Emplace_reallocate(local_c4,&local_cc); candidatesCapacity = local_f4; local_c4 = local_f8; candidatesBegin = local_fc; } else { *local_c4 = gridIndex; local_f8 = local_c4 + 1; local_c4 = local_f8; } } goto LAB_009aeab1; } local_f8 = candidatesBegin; local_cc = gridIndex; local_e0 = uVar8; if (candidatesBegin == candidatesCapacity) { std::vector::_Emplace_reallocate(candidatesBegin,&local_cc); candidatesCapacity = local_f4; local_c4 = local_f8; candidatesBegin = local_fc; } else { *candidatesBegin = gridIndex; local_f8 = candidatesBegin + 1; local_c4 = local_f8; } } LAB_009aeaab: uVar3 = gridIndex; } else { local_cc = gridIndex; std::set::find_node(local_11c,&local_cc); if (((*GHIDRA_CAST((local_114 + 0xd)) != '\0') || (GHIDRA_INT(uVar3) < *GHIDRA_CAST((local_114 + 0x10)))) || (local_114 == *GHIDRA_CAST(allowedIndices))) goto LAB_009ae755; } LAB_009aeab1: puVar2 = local_c4; puVar6 = candidatesBegin; } } gridIndex = uVar3 + 1; gridSlot = gridSlot + 1; if (0xa8 < gridIndex) { local_c4 = GHIDRA_CAST((GHIDRA_INT(puVar2) - GHIDRA_INT(puVar6) >> 2)); if (local_c4 == GHIDRA_CAST(0x0)) { result = (void *)0x0; } else { seed = *this; if (seed == (LevelGenerator)0x0) { KAGE_LogMessage(0x10,GHIDRA_CAST("RNG Seed is zero!\n")); seed = *this; if (seed == (LevelGenerator)0x0) { pcVar1 = (code *)swi(3); result = (void *)(*pcVar1)(); return result; } } uVar3 = GHIDRA_UINT(seed) >> (SUB41(this[1],0) & 0x1f) ^ GHIDRA_UINT(seed); uVar3 = uVar3 ^ uVar3 << (SUB41(this[2],0) & 0x1f); seed = (LevelGenerator)(uVar3 ^ uVar3 >> (SUB41(this[3],0) & 0x1f)); *this = seed; uVar3 = candidatesBegin[GHIDRA_UINT(seed) % GHIDRA_UINT(local_c4)]; uVar7 = GHIDRA_INT(uVar3) / 0xd; local_d8 = GHIDRA_INT(uVar3) % 0xd; local_e0 = uVar7; (GHIDRA_CAST((newRoom)))->LevelGenerator_Room::constructor(local_d8,uVar7,1); local_8 = CONCAT31((*GHIDRA_CAST((GHIDRA_CAST(&(local_8)) + 0x1))),1); local_7c = 1; place_room(this,newRoom); local_f0 = (void *)(GHIDRA_INT(this[0xd9]) + GHIDRA_INT(this[uVar3 + 5]) * 0x48); update_room_neighbors(this,local_f0); local_cc = 0; uVar3 = local_d8; do { if (neighborOffsets[local_cc * 2] + uVar3 < 0xd) { if (neighborOffsets[local_cc * 2 + 1] + uVar7 < 0xd) { iVar4 = (neighborOffsets[local_cc * 2 + 1] + uVar7) * 0xd + neighborOffsets[local_cc * 2] + uVar3; if (-1 < iVar4) { if (-1 < GHIDRA_INT(this[iVar4 + 5])) { uVar3 = 0; iVar4 = GHIDRA_INT(this[0xd9]) + GHIDRA_INT(this[iVar4 + 5]) * 0x48; do { get_door_target_position (GHIDRA_CAST(&doorTargetX),GHIDRA_CAST((iVar4 + 8)),*GHIDRA_CAST((iVar4 + 0x18)),uVar3,0 ); if (((doorTargetX < 0xd) && (doorTargetY < 0xd)) && ((iVar5 = doorTargetY * 0xd + doorTargetX, -1 < iVar5 && ((GHIDRA_INT(local_104[iVar5 + 5]) < 0 && (uVar7 = GHIDRA_INT((doorTargetY - local_e0)) >> 0x1f, uVar8 = GHIDRA_INT((doorTargetX - local_d8)) >> 0x1f, ((doorTargetY - local_e0 ^ uVar7) - uVar7) + ((doorTargetX - local_d8 ^ uVar8) - uVar8) == 1)))))) { if (7 < uVar3) { /* WARNING: Subroutine does not return */ std::bitset::_Xran(); } puVar2 = GHIDRA_CAST((iVar4 + (uVar3 >> 5) * 4 + 0x1c)); *puVar2 = *puVar2 | 1 << ((byte)uVar3 & 0x1f); } uVar3 = uVar3 + 1; } while (GHIDRA_INT(uVar3) < 8); uVar7 = local_e0; uVar3 = local_d8; this = local_104; } } } } local_cc = local_cc + 1; } while (local_cc < 8); FID_conflict__Erase_tree_>_> (local_90,(fuzzer_allocator_> *)local_90, *(_Tree_node **)(GHIDRA_INT(local_90[0]) + 4)); operator_delete(local_90[0],0x14); puVar6 = candidatesBegin; result = local_f0; } if (puVar6 != GHIDRA_CAST(0x0)) { uVar3 = GHIDRA_INT(candidatesCapacity) - GHIDRA_INT(puVar6) & 0xfffffffc; puVar2 = puVar6; if (0xfff < uVar3) { puVar2 = GHIDRA_CAST(puVar6[-1]); uVar3 = uVar3 + 0x23; if (0x1f < GHIDRA_UINT((GHIDRA_INT(puVar6) + (-4 - GHIDRA_INT(puVar2))))) { /* WARNING: Subroutine does not return */ _invalid_parameter_noinfo_noreturn(); } } operator_delete(puVar2,uVar3); } ExceptionList = local_10; return result; } } while( true ); } // 009aed50 void LevelGenerator::DetermineBossRoom(int shape, uint *possibleDoors) { void *room; byte isResized; int iVar1; int *neighborOffset; bool isCandidateValid; int cellIndex; uint gridY; uint gridX; int stepsLeft; LevelGenerator candidateIter; bool isStepFree; LevelGenerator roomIndex; candidateIter = this[0xdc]; if (candidateIter == this[0xdd]) { return; } do { roomIndex = *GHIDRA_CAST(candidateIter); room = (void *)(GHIDRA_INT(this[0xd9]) + GHIDRA_INT(roomIndex) * 0x48); if (1 < *GHIDRA_CAST((GHIDRA_INT(this[0xd9]) + 0x40 + GHIDRA_INT(roomIndex) * 0x48))) { gridX = *GHIDRA_CAST((GHIDRA_CAST(room) + 0x28)); gridY = *GHIDRA_CAST((GHIDRA_CAST(room) + 0x2c)); if (*GHIDRA_CAST((this + 0xe4)) != '\0') { isCandidateValid = true; stepsLeft = 3; do { gridY = gridY + (&DAT_00c5d3e4)[*GHIDRA_CAST((GHIDRA_CAST(room) + 0x20)) * 2]; gridX = gridX + (&DAT_00c5d3e0)[*GHIDRA_CAST((GHIDRA_CAST(room) + 0x20)) * 2]; if ((((GHIDRA_INT(gridX) < 0) || (0xc < GHIDRA_INT(gridX))) || (GHIDRA_INT(gridY) < 0)) || ((0xc < GHIDRA_INT(gridY) || (iVar1 = gridY * 0xd + gridX, iVar1 < 0)))) { LAB_009aee2e: isStepFree = false; } else { if ((gridX < 0xd) && (gridY < 0xd)) { cellIndex = iVar1; } else { cellIndex = -1; } isStepFree = isCandidateValid; if (this[cellIndex + 5] != roomIndex) { if ((0xc < gridX) || (0xc < gridY)) { iVar1 = -1; } if (-1 < GHIDRA_INT(this[iVar1 + 5])) goto LAB_009aee2e; } } iVar1 = 0; neighborOffset = &DAT_00c5d3e0; do { if ((((*neighborOffset + gridX < 0xd) && (neighborOffset[1] + gridY < 0xd)) && (cellIndex = (neighborOffset[1] + gridY) * 0xd + *neighborOffset + gridX, -1 < cellIndex)) && ((-1 < GHIDRA_INT(this[cellIndex + 5]) && (this[cellIndex + 5] != roomIndex)))) { iVar1 = iVar1 + 1; } neighborOffset = neighborOffset + 2; } while (GHIDRA_INT(neighborOffset) < 0xc5d400); isCandidateValid = false; if (iVar1 < 1) { isCandidateValid = isStepFree; } stepsLeft = stepsLeft + -1; } while (stepsLeft != 0); if (!isCandidateValid) goto LAB_009aeebf; } isResized = try_resize_room(this,room,shape,possibleDoors); if (isResized != 0) { this[0xe2] = roomIndex; memmove((void *)candidateIter,GHIDRA_CAST((GHIDRA_INT(candidateIter) + 4)), GHIDRA_INT(this[0xdd]) - (GHIDRA_INT(candidateIter) + 4)); this[0xdd] = (LevelGenerator)(GHIDRA_INT(this[0xdd]) + -4); return; } } LAB_009aeebf: candidateIter = (LevelGenerator)(GHIDRA_INT(candidateIter) + 4); if (candidateIter == this[0xdd]) { return; } } while( true ); } // 009af0e0 void * LevelGenerator::get_all_rooms(void *outRooms) { LevelGenerator indexIter; int roomPtr [2]; void *local_10; undefined1 *puStack_c; undefined4 local_8; int *outEnd; puStack_c = &LAB_00b0e2be; local_10 = ExceptionList; ExceptionList = &local_10; *GHIDRA_CAST(outRooms) = 0; *GHIDRA_CAST((GHIDRA_CAST(outRooms) + 4)) = 0; *GHIDRA_CAST((GHIDRA_CAST(outRooms) + 8)) = 0; local_8 = 0; indexIter = this[0xdf]; roomPtr[1] = 1; if (indexIter != this[0xe0]) { do { roomPtr[0] = GHIDRA_INT(this[0xd9]) + *GHIDRA_CAST(indexIter) * 0x48; outEnd = *GHIDRA_CAST((GHIDRA_CAST(outRooms) + 4)); if (outEnd == *GHIDRA_CAST((GHIDRA_CAST(outRooms) + 8))) { std::vector<4byte>::_Emplace_reallocate(outEnd,roomPtr); } else { *outEnd = roomPtr[0]; *GHIDRA_CAST((GHIDRA_CAST(outRooms) + 4)) = *GHIDRA_CAST((GHIDRA_CAST(outRooms) + 4)) + 4; } indexIter = (LevelGenerator)(GHIDRA_INT(indexIter) + 4); } while (indexIter != this[0xe0]); } indexIter = this[0xdc]; if (indexIter != this[0xdd]) { do { roomPtr[0] = GHIDRA_INT(this[0xd9]) + *GHIDRA_CAST(indexIter) * 0x48; outEnd = *GHIDRA_CAST((GHIDRA_CAST(outRooms) + 4)); if (outEnd == *GHIDRA_CAST((GHIDRA_CAST(outRooms) + 8))) { std::vector<4byte>::_Emplace_reallocate(outEnd,roomPtr); } else { *outEnd = roomPtr[0]; *GHIDRA_CAST((GHIDRA_CAST(outRooms) + 4)) = *GHIDRA_CAST((GHIDRA_CAST(outRooms) + 4)) + 4; } indexIter = (LevelGenerator)(GHIDRA_INT(indexIter) + 4); } while (indexIter != this[0xdd]); } ExceptionList = local_10; return outRooms; } // 009af1e0 undefined4 LevelGenerator::add_dead_end() { byte bVar1; uint uVar2; int iVar3; LevelGenerator *in_ECX; undefined4 extraout_ECX; undefined4 extraout_ECX_00; undefined4 extraout_ECX_01; undefined4 uVar4; uint size; int iVar5; LevelGenerator LVar6; LevelGenerator_Room LVar7; LevelGenerator_Room local_24; LevelGenerator_Room local_20; int local_1c; uint local_14; void *local_10; undefined1 *puStack_c; undefined4 local_8; local_8 = 0xffffffff; puStack_c = &LAB_00b0e2ed; local_10 = ExceptionList; uVar2 = __security_cookie ^ GHIDRA_INT(register0x00000010) - 4U; ExceptionList = &local_10; LVar6 = in_ECX[0xd9]; local_14 = 0; if ((GHIDRA_INT(in_ECX[0xda]) - GHIDRA_INT(LVar6)) / 0x48 != 0) { iVar5 = 0; do { get_neighbor_candidates(in_ECX,&local_24,*GHIDRA_CAST((iVar5 + 4 + GHIDRA_INT(LVar6))),1); local_8 = 0; uVar4 = extraout_ECX; LVar7 = local_24; if (local_24 != local_20) { do { bVar1 = can_place_room(in_ECX,GHIDRA_CAST((GHIDRA_INT(LVar7) + 8)), GHIDRA_INT(*GHIDRA_CAST((GHIDRA_CAST(LVar7) + 0x18)))); uVar4 = extraout_ECX_00; if ((bVar1 != 0) && (iVar3 = count_neighbor_rooms(in_ECX,GHIDRA_CAST((GHIDRA_INT(LVar7) + 0x28))), uVar4 = extraout_ECX_01, iVar3 < 2)) { place_room(in_ECX,GHIDRA_CAST(LVar7)); vector_LevelGenerator_Room_tidy(&local_24); ExceptionList = local_10; return 1; } LVar7 = (LevelGenerator_Room)(GHIDRA_INT(LVar7) + 0x48); } while (LVar7 != local_20); } local_8 = 0xffffffff; if (local_24 != (LevelGenerator_Room)0x0) { FUN_00752e40(uVar4,uVar2); size = ((local_1c - GHIDRA_INT(local_24)) / 0x48) * 0x48; LVar7 = local_24; if (0xfff < size) { LVar7 = *GHIDRA_CAST((GHIDRA_CAST(local_24) + -4)); size = size + 0x23; if (0x1f < (GHIDRA_INT(local_24) - GHIDRA_INT(LVar7)) - 4U) { /* WARNING: Subroutine does not return */ _invalid_parameter_noinfo_noreturn(); } } operator_delete((void *)LVar7,size); local_24 = (LevelGenerator_Room)0x0; local_20 = (LevelGenerator_Room)0x0; local_1c = 0; } LVar6 = in_ECX[0xd9]; iVar5 = iVar5 + 0x48; local_14 = local_14 + 1; } while (local_14 < GHIDRA_UINT(((GHIDRA_INT(in_ECX[0xda]) - GHIDRA_INT(LVar6)) / 0x48))); } ExceptionList = local_10; return 0; } // 009af370 byte LevelGenerator::has_shape_slot(int shape, int doorSlot, byte ignoreThinShapesRestrictions) { if ((((*GHIDRA_CAST((&DAT_00c5d37c + shape * 8)) == 1) && ((doorSlot == 4 || (doorSlot == 6)))) || (((*GHIDRA_CAST((&DAT_00c5d378 + shape * 8)) == 1 && ((doorSlot == 5 || (doorSlot == 7)))) || ((((shape == 3 || (shape == 5)) && (ignoreThinShapesRestrictions == 0)) && ((((doorSlot == 0 || (doorSlot == 2)) || (doorSlot == 4)) || (doorSlot == 6)))))))) || ((((shape == 2 || (shape == 7)) && (ignoreThinShapesRestrictions == 0)) && (((doorSlot == 1 || (doorSlot == 3)) || ((doorSlot == 5 || (doorSlot == 7)))))))) { return 0; } return 1; } // 009af3f0 void * LevelGenerator::get_door_source_position(void *ret, void *position, int shape, int doorSlot) { undefined4 uVar1; int iVar2; byte isHasSlot; undefined4 extraout_ECX; int extraout_EDX; isHasSlot = has_shape_slot(shape,doorSlot,0); if (isHasSlot == 0) { switchD_009af41e_default: *GHIDRA_CAST(ret) = g_levelGenInvalidPos[0]; *GHIDRA_CAST((GHIDRA_CAST(ret) + 4)) = g_levelGenInvalidPos[1]; return ret; } switch(extraout_ECX) { case 1: case 2: case 3: break; case 4: case 5: if (((extraout_EDX == 3) || (extraout_EDX == 4)) || (extraout_EDX == 6)) { iVar2 = *GHIDRA_CAST((GHIDRA_CAST(position) + 4)); *GHIDRA_CAST(ret) = *GHIDRA_CAST(position); *GHIDRA_CAST((GHIDRA_CAST(ret) + 4)) = iVar2 + 1; return ret; } uVar1 = *GHIDRA_CAST((GHIDRA_CAST(position) + 4)); *GHIDRA_CAST(ret) = *GHIDRA_CAST(position); *GHIDRA_CAST((GHIDRA_CAST(ret) + 4)) = uVar1; return ret; case 6: case 7: if (((extraout_EDX != 2) && (extraout_EDX != 5)) && (extraout_EDX != 7)) { uVar1 = *GHIDRA_CAST(position); *GHIDRA_CAST((GHIDRA_CAST(ret) + 4)) = *GHIDRA_CAST((GHIDRA_CAST(position) + 4)); *GHIDRA_CAST(ret) = uVar1; return ret; } goto LAB_009af488; case 8: if ((extraout_EDX != 5) && (extraout_EDX != 2)) { if ((extraout_EDX != 4) && (extraout_EDX != 3)) { if ((extraout_EDX != 6) && (extraout_EDX != 7)) { *GHIDRA_CAST(ret) = *GHIDRA_CAST(position); *GHIDRA_CAST((GHIDRA_CAST(ret) + 4)) = *GHIDRA_CAST((GHIDRA_CAST(position) + 4)); return ret; } LAB_009af57c: iVar2 = *GHIDRA_CAST((GHIDRA_CAST(position) + 4)); *GHIDRA_CAST(ret) = *GHIDRA_CAST(position) + 1; *GHIDRA_CAST((GHIDRA_CAST(ret) + 4)) = iVar2 + 1; return ret; } LAB_009af5bb: iVar2 = *GHIDRA_CAST((GHIDRA_CAST(position) + 4)); *GHIDRA_CAST(ret) = *GHIDRA_CAST(position); *GHIDRA_CAST((GHIDRA_CAST(ret) + 4)) = iVar2 + 1; return ret; } goto LAB_009af488; case 9: if (((extraout_EDX != 0) && (extraout_EDX != 5)) && (extraout_EDX != 2)) { if (((extraout_EDX != 4) && (extraout_EDX != 1)) && (extraout_EDX != 3)) { iVar2 = *GHIDRA_CAST((GHIDRA_CAST(position) + 4)); *GHIDRA_CAST(ret) = *GHIDRA_CAST(position) + 1; *GHIDRA_CAST((GHIDRA_CAST(ret) + 4)) = iVar2 + 1; return ret; } goto LAB_009af5bb; } LAB_009af488: iVar2 = *GHIDRA_CAST(position); *GHIDRA_CAST((GHIDRA_CAST(ret) + 4)) = *GHIDRA_CAST((GHIDRA_CAST(position) + 4)); *GHIDRA_CAST(ret) = iVar2 + 1; return ret; case 10: if (((extraout_EDX != 0) && (extraout_EDX != 1)) && (extraout_EDX != 2)) { if ((extraout_EDX != 4) && (extraout_EDX != 3)) { iVar2 = *GHIDRA_CAST((GHIDRA_CAST(position) + 4)); *GHIDRA_CAST(ret) = *GHIDRA_CAST(position) + 1; *GHIDRA_CAST((GHIDRA_CAST(ret) + 4)) = iVar2 + 1; return ret; } goto LAB_009af5bb; } break; case 0xb: if ((extraout_EDX != 0) && ((extraout_EDX != 1 && (extraout_EDX != 3)))) { if ((extraout_EDX != 5) && (extraout_EDX != 2)) goto LAB_009af57c; goto LAB_009af488; } break; case 0xc: if ((extraout_EDX != 0) && (extraout_EDX != 1)) { if ((extraout_EDX != 5) && ((extraout_EDX != 2 && (extraout_EDX != 7)))) goto LAB_009af5bb; goto LAB_009af488; } break; default: goto switchD_009af41e_default; } *GHIDRA_CAST(ret) = *GHIDRA_CAST(position); *GHIDRA_CAST((GHIDRA_CAST(ret) + 4)) = *GHIDRA_CAST((GHIDRA_CAST(position) + 4)); return ret; } // 009af980 void LevelGenerator::update_room_neighbors(void *room) { int *neighborSet; uint uVar1; int iVar2; undefined8 *findResult; undefined4 *newNode; uint doorSlot; undefined1 findBuf [12]; undefined8 insertHint; int neighborSetRef; undefined4 local_24; uint targetX; uint targetY; undefined4 *doorMask; LevelGenerator *generator; void *local_10; undefined1 *puStack_c; undefined4 local_8; LevelGenerator *gridCell; undefined4 setHead; local_8 = 0xffffffff; puStack_c = &LAB_00b0e31d; local_10 = ExceptionList; uVar1 = __security_cookie ^ GHIDRA_UINT((findBuf + 0x3c)); ExceptionList = &local_10; doorMask = GHIDRA_CAST((GHIDRA_INT(room) + 0x1c)); neighborSet = GHIDRA_CAST((GHIDRA_INT(room) + 0x30)); *doorMask = 0; iVar2 = *neighborSet; generator = this; FID_conflict__Erase_tree_>_> (neighborSet,(fuzzer_allocator_> *)neighborSet, *(_Tree_node **)(iVar2 + 4)); *GHIDRA_CAST((iVar2 + 4)) = iVar2; *GHIDRA_CAST(iVar2) = iVar2; *GHIDRA_CAST((iVar2 + 8)) = iVar2; doorSlot = 0; *GHIDRA_CAST((GHIDRA_CAST(room) + 0x34)) = 0; do { get_door_target_position (GHIDRA_CAST(&targetX),GHIDRA_CAST((GHIDRA_INT(room) + 8)),*GHIDRA_CAST((GHIDRA_CAST(room) + 0x18)),doorSlot,0); if ((((targetX < 0xd) && (targetY < 0xd)) && (iVar2 = targetY * 0xd + targetX, -1 < iVar2)) && (gridCell = generator + iVar2 + 5, -1 < GHIDRA_INT(generator[iVar2 + 5]))) { if (7 < doorSlot) { /* WARNING: Subroutine does not return */ std::bitset::_Xran(); } doorMask[doorSlot >> 5] = doorMask[doorSlot >> 5] | 1 << ((byte)doorSlot & 0x1f); findResult = GHIDRA_CAST(std)::set::find_node(findBuf,gridCell); insertHint = *findResult; if ((*GHIDRA_CAST((*GHIDRA_CAST((findResult + 1)) + 0xd)) != '\0') || (GHIDRA_INT(*gridCell) < *GHIDRA_CAST((*GHIDRA_CAST((findResult + 1)) + 0x10)))) { if (*GHIDRA_CAST((GHIDRA_CAST(room) + 0x34)) == 0xccccccc) { /* WARNING: Subroutine does not return */ FUN_004170d0(uVar1); } setHead = *GHIDRA_CAST((GHIDRA_CAST(room) + 0x30)); neighborSetRef = GHIDRA_INT(room) + 0x30; local_8 = 0; local_24 = 0; newNode = operator_new(0x14); local_8 = 0xffffffff; *GHIDRA_CAST((newNode + 4)) = *gridCell; *newNode = setHead; newNode[1] = setHead; newNode[2] = setHead; *GHIDRA_CAST((newNode + 3)) = 0; local_24 = 0; std::_Tree::_Insert_node ((void *)(GHIDRA_INT(room) + 0x30),(void *)insertHint,(*GHIDRA_CAST((GHIDRA_CAST(&(insertHint)) + 0x4))),newNode); } } doorSlot = doorSlot + 1; } while (GHIDRA_INT(doorSlot) < 8); *GHIDRA_CAST((GHIDRA_CAST(room) + 0x38)) = *GHIDRA_CAST((GHIDRA_CAST(room) + 0x34)); ExceptionList = local_10; return; } // 009afb10 void LevelGenerator::mark_dead_ends() { int iVar1; LevelGenerator LVar2; uint uVar3; uint neighborX; uint roomIdx; LevelGenerator roomsBegin; int roomOffset; roomIdx = 0; LVar2 = this[0xda]; roomsBegin = this[0xd9]; iVar1 = GHIDRA_INT(LVar2) - GHIDRA_INT(roomsBegin) >> 0x1f; if ((GHIDRA_INT(LVar2) - GHIDRA_INT(roomsBegin)) / 0x48 + iVar1 != iVar1) { roomOffset = 0; do { if (roomIdx != 0) { iVar1 = count_neighbor_rooms(this,GHIDRA_CAST((roomOffset + 0x28 + GHIDRA_INT(roomsBegin)))); if (iVar1 < 2) { *GHIDRA_CAST((roomOffset + 0x3c + GHIDRA_INT(roomsBegin))) = 1; } } roomOffset = roomOffset + 0x48; roomsBegin = this[0xd9]; roomIdx = roomIdx + 1; } while (roomIdx < GHIDRA_UINT(((GHIDRA_INT(this[0xda]) - GHIDRA_INT(roomsBegin)) / 0x48))); LVar2 = this[0xda]; } roomIdx = 0; iVar1 = GHIDRA_INT(LVar2) - GHIDRA_INT(roomsBegin) >> 0x1f; if ((GHIDRA_INT(LVar2) - GHIDRA_INT(roomsBegin)) / 0x48 + iVar1 != iVar1) { roomOffset = 0; do { if ((roomIdx != 0) && ((iVar1 = *GHIDRA_CAST((roomOffset + 0x28 + GHIDRA_INT(roomsBegin))), iVar1 != g_levelGenInvalidPos[0] || (*GHIDRA_CAST((roomOffset + 0x2c + GHIDRA_INT(roomsBegin))) != g_levelGenInvalidPos[1])))) { uVar3 = *GHIDRA_CAST((roomOffset + 0x20 + GHIDRA_INT(roomsBegin))) + 2U & 0x80000003; if (GHIDRA_INT(uVar3) < 0) { uVar3 = (uVar3 - 1 | 0xfffffffc) + 1; } neighborX = iVar1 + (&DAT_00c5d3e0)[uVar3 * 2]; uVar3 = *GHIDRA_CAST((roomOffset + 0x2c + GHIDRA_INT(roomsBegin))) + (&DAT_00c5d3e4)[uVar3 * 2]; if ((neighborX < 0xd) && (uVar3 < 0xd)) { iVar1 = uVar3 * 0xd + neighborX; } else { iVar1 = -1; } LVar2 = this[iVar1 + 5]; if (GHIDRA_INT(LVar2) < 0) { KAGE_LogMessage(0x10,GHIDRA_CAST("invalid connecting neighbor\n")); } *GHIDRA_CAST((GHIDRA_INT(this[0xd9]) + 0x3c + GHIDRA_INT(LVar2) * 0x48)) = 0; } roomsBegin = this[0xd9]; roomOffset = roomOffset + 0x48; roomIdx = roomIdx + 1; } while (roomIdx < GHIDRA_UINT(((GHIDRA_INT(this[0xda]) - GHIDRA_INT(roomsBegin)) / 0x48))); } return; } // 009afc70 void LevelGenerator::update_dead_end_lists() { int iVar1; LevelGenerator LVar2; uint roomIndex; int roomOffset; uint indexToPush [2]; this[0xdd] = this[0xdc]; this[0xe0] = this[0xdf]; mark_dead_ends(this); LVar2 = this[0xd9]; roomIndex = 0; iVar1 = GHIDRA_INT(this[0xda]) - GHIDRA_INT(LVar2) >> 0x1f; if ((GHIDRA_INT(this[0xda]) - GHIDRA_INT(LVar2)) / 0x48 + iVar1 != iVar1) { roomOffset = 0; do { update_room_neighbors(this,(void *)(GHIDRA_INT(LVar2) + roomOffset)); indexToPush[0] = roomIndex; if (*GHIDRA_CAST((GHIDRA_CAST(LVar2) + roomOffset + 0x3c)) == '\0') { LVar2 = this[0xe0]; if (LVar2 == this[0xe1]) goto LAB_009afd26; *GHIDRA_CAST(LVar2) = roomIndex; this[0xe0] = (LevelGenerator)(GHIDRA_INT(this[0xe0]) + 4); } else { LVar2 = this[0xdd]; if (LVar2 == this[0xde]) { LAB_009afd26: std::vector::_Emplace_reallocate(LVar2,indexToPush); } else { *GHIDRA_CAST(LVar2) = roomIndex; this[0xdd] = (LevelGenerator)(GHIDRA_INT(this[0xdd]) + 4); } } LVar2 = this[0xd9]; roomIndex = roomIndex + 1; roomOffset = roomOffset + 0x48; } while (roomIndex < GHIDRA_UINT(((GHIDRA_INT(this[0xda]) - GHIDRA_INT(LVar2)) / 0x48))); } return; } // 009afdb0 int ** LevelGenerator::get_room_placement_offsets(int shape) { int threadLocals; threadLocals = *GHIDRA_CAST(ThreadLocalStoragePointer); if (*GHIDRA_CAST((threadLocals + 0xc)) < DAT_00c94338) { _Init_thread_header(&DAT_00c94338); if (DAT_00c94338 == -1) { _DAT_00c7f5f4 = g_levelGenInvalidPos[0]; _DAT_00c7f5f8 = g_levelGenInvalidPos[1]; _Init_thread_footer(&DAT_00c94338); } } if (*GHIDRA_CAST((threadLocals + 0xc)) < DAT_00c9433c) { _Init_thread_header(&DAT_00c9433c); if (DAT_00c9433c == -1) { _DAT_00c7f5ec = g_levelGenInvalidPos[0]; _DAT_00c7f5e4 = 0; _DAT_00c7f5e8 = 0; _DAT_00c7f5f0 = g_levelGenInvalidPos[1]; _Init_thread_footer(&DAT_00c9433c); } } if (*GHIDRA_CAST((threadLocals + 0xc)) < DAT_00c94340) { _Init_thread_header(&DAT_00c94340); if (DAT_00c94340 == -1) { _DAT_00c7f5dc = g_levelGenInvalidPos[0]; _DAT_00c7f5cc = 0; uRam00c7f5d0 = 0; uRam00c7f5d4 = 0; uRam00c7f5d8 = 1; _DAT_00c7f5e0 = g_levelGenInvalidPos[1]; _Init_thread_footer(&DAT_00c94340); } } if (*GHIDRA_CAST((threadLocals + 0xc)) < DAT_00c94344) { _Init_thread_header(&DAT_00c94344); if (DAT_00c94344 == -1) { _DAT_00c7f5c4 = g_levelGenInvalidPos[0]; _DAT_00c7f5b4 = 0; uRam00c7f5b8 = 0; uRam00c7f5bc = 1; uRam00c7f5c0 = 0; _DAT_00c7f5c8 = g_levelGenInvalidPos[1]; _Init_thread_footer(&DAT_00c94344); } } if (*GHIDRA_CAST((threadLocals + 0xc)) < DAT_00c94348) { _Init_thread_header(&DAT_00c94348); if (DAT_00c94348 == -1) { _DAT_00c7f58c = 0; uRam00c7f590 = 0; uRam00c7f594 = 1; uRam00c7f598 = 0; _DAT_00c7f5ac = g_levelGenInvalidPos[0]; _DAT_00c7f59c = 0; uRam00c7f5a0 = 1; uRam00c7f5a4 = 1; uRam00c7f5a8 = 1; _DAT_00c7f5b0 = g_levelGenInvalidPos[1]; _Init_thread_footer(&DAT_00c94348); } } if (*GHIDRA_CAST((threadLocals + 0xc)) < DAT_00c9434c) { _Init_thread_header(&DAT_00c9434c); if (DAT_00c9434c == -1) { _DAT_00c7f584 = g_levelGenInvalidPos[0]; _DAT_00c7f56c = 1; uRam00c7f570 = 0; uRam00c7f574 = 0; uRam00c7f578 = 1; _DAT_00c7f57c = 1; _DAT_00c7f580 = 1; _DAT_00c7f588 = g_levelGenInvalidPos[1]; _Init_thread_footer(&DAT_00c9434c); } } if (*GHIDRA_CAST((threadLocals + 0xc)) < DAT_00c94350) { _Init_thread_header(&DAT_00c94350); if (DAT_00c94350 == -1) { _DAT_00c7f564 = g_levelGenInvalidPos[0]; _DAT_00c7f54c = 0; uRam00c7f550 = 0; uRam00c7f554 = 0; uRam00c7f558 = 1; _DAT_00c7f55c = 1; _DAT_00c7f560 = 1; _DAT_00c7f568 = g_levelGenInvalidPos[1]; _Init_thread_footer(&DAT_00c94350); } } if (*GHIDRA_CAST((threadLocals + 0xc)) < DAT_00c94354) { _Init_thread_header(&DAT_00c94354); if (DAT_00c94354 == -1) { _DAT_00c7f544 = g_levelGenInvalidPos[0]; _DAT_00c7f52c = 0; uRam00c7f530 = 0; uRam00c7f534 = 1; uRam00c7f538 = 0; _DAT_00c7f53c = 1; _DAT_00c7f540 = 1; _DAT_00c7f548 = g_levelGenInvalidPos[1]; _Init_thread_footer(&DAT_00c94354); } } if (*GHIDRA_CAST((threadLocals + 0xc)) < DAT_00c94358) { _Init_thread_header(&DAT_00c94358); if (DAT_00c94358 == -1) { _DAT_00c7f524 = g_levelGenInvalidPos[0]; _DAT_00c7f50c = 0; uRam00c7f510 = 0; uRam00c7f514 = 1; uRam00c7f518 = 0; _DAT_00c7f51c = 0; _DAT_00c7f520 = 1; _DAT_00c7f528 = g_levelGenInvalidPos[1]; _Init_thread_footer(&DAT_00c94358); } } return GHIDRA_CAST((&PTR_DAT_00c5c4a0 + shape)); } // 009b0180 byte LevelGenerator::can_place_room(int *gridPos, int shape) { uint uVar1; int **shapeOffsets; int cellIndex; int *cellOffset; int lastRoomCellIndex; LevelGenerator lastRoom; lastRoom = this[0xd9]; if (lastRoom != this[0xda]) { uVar1 = *GHIDRA_CAST((GHIDRA_CAST(lastRoom) + 0xc)) - 1; if ((*GHIDRA_CAST((GHIDRA_CAST(lastRoom) + 8)) < 0xd) && (uVar1 < 0xd)) { lastRoomCellIndex = uVar1 * 0xd + *GHIDRA_CAST((GHIDRA_CAST(lastRoom) + 8)); goto LAB_009b01b5; } } lastRoomCellIndex = -1; LAB_009b01b5: shapeOffsets = get_room_placement_offsets(shape); cellOffset = *shapeOffsets + 1; while( true ) { if ((cellOffset[-1] == g_levelGenInvalidPos[0]) && (*cellOffset == g_levelGenInvalidPos[1])) { return 1; } uVar1 = *gridPos + cellOffset[-1]; if ((uVar1 < 0xd) && (GHIDRA_UINT((*cellOffset + gridPos[1])) < 0xd)) { cellIndex = (*cellOffset + gridPos[1]) * 0xd + uVar1; } else { cellIndex = -1; } if (((((*GHIDRA_CAST((GHIDRA_CAST(&(this[0xe4])) + 0x1))) != '\0') && (cellIndex == lastRoomCellIndex)) || (cellIndex < 0)) || ((-1 < GHIDRA_INT(this[cellIndex + 5]) || ((&(*GHIDRA_CAST((GHIDRA_CAST(&(this[0xae])) + 0x0))))[cellIndex] != '\0')))) break; cellOffset = cellOffset + 2; } return 0; } // 009b0240 byte LevelGenerator::is_placement_valid(uint *position, uint shape) { int iVar1; int iVar2; int *neighborDoorTarget; int doorSlot; int neighborDoorSlot; int sourceX; int sourceY; uint targetX; uint targetY; int neighborDoorPos [3]; doorSlot = 0; do { get_door_source_position(&sourceX,position,shape,doorSlot); get_door_target_position(GHIDRA_CAST(&targetX),GHIDRA_CAST(position),shape,doorSlot,1); iVar1 = sourceY; if ((((targetX < 0xd) && (targetY < 0xd)) && (iVar2 = targetY * 0xd + targetX, -1 < iVar2)) && (-1 < GHIDRA_INT(this[iVar2 + 5]))) { if ((sourceX == g_levelGenInvalidPos[0]) && (sourceY == g_levelGenInvalidPos[1])) { return 0; } neighborDoorSlot = 0; iVar2 = GHIDRA_INT(this[0xd9]) + GHIDRA_INT(this[iVar2 + 5]) * 0x48; while ((neighborDoorTarget = get_door_target_position (neighborDoorPos,GHIDRA_CAST((iVar2 + 8)),*GHIDRA_CAST((iVar2 + 0x18)), neighborDoorSlot,0), *neighborDoorTarget != sourceX || (neighborDoorTarget[1] != iVar1))) { neighborDoorSlot = neighborDoorSlot + 1; if (7 < neighborDoorSlot) { return 0; } } } doorSlot = doorSlot + 1; if (7 < doorSlot) { return 1; } } while( true ); } // 009b0330 byte LevelGenerator::place_room(LevelGenerator_Room *room) { int **offsetTable; uint cellY; uint cellX; int cellIndex; int offsetBytes; int *offsets; LevelGenerator roomIndex; LevelGenerator roomsEnd; roomsEnd = this[0xda]; roomIndex = (LevelGenerator)((GHIDRA_INT(roomsEnd) - GHIDRA_INT(this[0xd9])) / 0x48); if (roomsEnd == this[0xdb]) { std::vector::_Emplace_reallocate(roomsEnd,room); } else { (GHIDRA_CAST((GHIDRA_CAST(roomsEnd))))->LevelGenerator_Room::LevelGenerator_Room(room); this[0xda] = (LevelGenerator)(GHIDRA_INT(this[0xda]) + 0x48); } *GHIDRA_CAST((GHIDRA_INT(this[0xda]) + -0x44)) = roomIndex; offsetTable = get_room_placement_offsets(GHIDRA_INT(room[6])); if (room[6] != (LevelGenerator_Room)0x1) { KAGE_LogMessage(1,GHIDRA_CAST("place_room: shape %d\n")); } offsetBytes = 0; do { offsets = *offsetTable; if ((*GHIDRA_CAST((GHIDRA_CAST(offsets) + offsetBytes)) == g_levelGenInvalidPos[0]) && (*GHIDRA_CAST((GHIDRA_CAST(offsets) + offsetBytes + 4)) == g_levelGenInvalidPos[1])) { return SUB41(this[0xda],0) + 0xb8; } cellX = *GHIDRA_CAST((GHIDRA_CAST(offsets) + offsetBytes)) + GHIDRA_INT(room[2]); cellY = GHIDRA_INT(room[3]) + *GHIDRA_CAST((GHIDRA_CAST(offsets) + offsetBytes + 4)); if ((cellX < 0xd) && (cellY < 0xd)) { cellIndex = cellY * 0xd + cellX; if (cellIndex < 0) goto LAB_009b03fb; } else { cellIndex = -1; LAB_009b03fb: KAGE_LogMessage(0x10,GHIDRA_CAST("[LevelGenerator] place_room: invalid room\n")); } offsetBytes = offsetBytes + 8; this[cellIndex + 5] = roomIndex; } while( true ); } // 009b0440 int LevelGenerator::count_neighbor_rooms(int *gridPos) { int cellIdx; int neighborCount; int *dirOffset; LevelGenerator cellRoom; int gridX; int gridY; gridX = *gridPos; neighborCount = 0; gridY = gridPos[1]; dirOffset = &DAT_00c5d3e0; do { if ((((GHIDRA_UINT((gridX + *dirOffset)) < 0xd) && (GHIDRA_UINT((dirOffset[1] + gridY)) < 0xd)) && (cellIdx = (dirOffset[1] + gridY) * 0xd + gridX + *dirOffset, -1 < cellIdx)) && ((cellRoom = this[cellIdx + 5], -1 < GHIDRA_INT(cellRoom) && (cellIdx = FUN_009afd70(), cellRoom != this[cellIdx + 5])))) { neighborCount = neighborCount + 1; } dirOffset = dirOffset + 2; } while (GHIDRA_INT(dirOffset) < 0xc5d400); return neighborCount; } // 009b1220 byte LevelGenerator::try_resize_room(void *room, int roomShape, uint *possibleDoors) { int iVar1; uint uVar2; uint *doorTargetPos; char isPlacementValid; int *offset; uint neighborCount; int *piVar3; LevelGenerator *generator; uint uVar4; uint doorSlot; int gridIdx; undefined1 auStack_114 [7]; char isFits; LevelGenerator local_10c; int local_108; int *local_104; void *roomCopy; int shapeCopy; LevelGenerator *generatorCopy; int **newShapeOffsets; int **local_f0 [2]; int candidatePositions [4]; int spot2X; int spot2Y; int spot3X; int spot3Y; int spot4X; int spot4Y; int local_c0; int spot5Y; int spot6X; int spot6Y; int spot7X; int spot7Y; int spot8X; int spot8Y; int spot9X; int spot9Y; int spot10X; int spot10Y; int spot11X; int spot11Y; int spot12X; int spot12Y; int spot13X; int spot13Y; int candidateShapes [2]; int spotShape2; int spotShape3; int spotShape4; int spotShape5; int spotShape6; int spotShape7; int spotShape8; int spotShape9; int spotShape10; int spotShape11; int spotShape12; int spotShape13; uint candidateDoorSlots [4]; int spotDoorSlot4; uint spotDoorSlot5; int spotDoorSlot6; uint spotDoorSlot7; int spotDoorSlot8; uint spotDoorSlot9; int spotDoorSlot10; uint spotDoorSlot11; uint spotDoorSlot12; uint local_c; LevelGenerator cellRoomIdx; void *resizedRoom; undefined4 shapeSizeY; local_c = __security_cookie ^ GHIDRA_UINT(auStack_114); roomCopy = room; shapeCopy = roomShape; iVar1 = *GHIDRA_CAST((GHIDRA_CAST(room) + 0x20)); candidateDoorSlots[0] = iVar1 + 2U & 0x80000003; if (GHIDRA_INT(candidateDoorSlots[0]) < 0) { candidateDoorSlots[0] = (candidateDoorSlots[0] - 1 | 0xfffffffc) + 1; } if ((iVar1 == 2) || (iVar1 == 3)) { candidatePositions[2] = 0; candidatePositions[3] = 0; } else { candidatePositions[3] = (&DAT_00c5d3e4)[iVar1 * 2]; candidatePositions[2] = (&DAT_00c5d3e0)[iVar1 * 2]; } if ((iVar1 == 0) || (iVar1 == 2)) { local_c0 = 0; local_108 = -1; } else { local_c0 = -1; local_108 = 0; } candidatePositions[0] = *GHIDRA_CAST((GHIDRA_CAST(room) + 0x28)); candidatePositions[1] = *GHIDRA_CAST((GHIDRA_CAST(room) + 0x2c)); candidatePositions[3] = candidatePositions[3] + candidatePositions[1]; candidatePositions[2] = candidatePositions[2] + candidatePositions[0]; spot3X = local_c0 + candidatePositions[0]; spot3Y = local_108 + candidatePositions[1]; local_c0 = local_c0 + candidatePositions[2]; spot5Y = local_108 + candidatePositions[3]; candidateDoorSlots[2] = candidateDoorSlots[0] + 4; iVar1 = *GHIDRA_CAST((GHIDRA_CAST(room) + 0x20)); if ((iVar1 == 0) || (iVar1 == 2)) { local_10c = (LevelGenerator)0x4; candidateShapes[1] = 6; } else { candidateShapes[1] = 4; local_10c = (LevelGenerator)0x6; } switch(iVar1) { case 0: spotShape6 = 0xc; spotShape7 = 10; spotShape8 = 0xb; spotShape10 = 9; break; case 1: spotShape6 = 0xc; local_104 = GHIDRA_CAST(0x3); spotShape7 = 0xb; spotShape8 = 10; spotShape10 = 9; goto LAB_009b1491; case 2: spotShape6 = 0xb; spotShape7 = 9; spotShape8 = 10; spotShape10 = 0xc; break; case 3: spotShape6 = 10; local_104 = GHIDRA_CAST(0x3); spotShape7 = 9; spotShape8 = 0xb; spotShape10 = 0xc; goto LAB_009b1491; default: spotShape8 = GHIDRA_INT(local_10c); spotShape10 = GHIDRA_INT(local_10c); spotShape6 = GHIDRA_INT(local_10c); spotShape7 = GHIDRA_INT(local_10c); if ((iVar1 != 0) && (iVar1 != 2)) { local_104 = GHIDRA_CAST(0x3); goto LAB_009b1491; } } local_104 = GHIDRA_CAST(0x2); LAB_009b1491: if ((iVar1 == 0) || (local_108 = 5, iVar1 == 2)) { local_108 = 7; } spotShape2 = GHIDRA_INT(local_10c); spotShape3 = GHIDRA_INT(local_10c); spotShape12 = GHIDRA_INT(local_104); candidateShapes[0] = 1; spotShape4 = 8; spotShape5 = 8; spotShape13 = local_108; generatorCopy = this; spot2X = candidatePositions[0]; spot2Y = candidatePositions[1]; spot4X = candidatePositions[2]; spot4Y = candidatePositions[3]; spot6X = candidatePositions[2]; spot6Y = candidatePositions[3]; spot7X = local_c0; spot7Y = spot5Y; spot8X = candidatePositions[2]; spot8Y = candidatePositions[3]; spot9X = local_c0; spot9Y = spot5Y; spot10X = candidatePositions[2]; spot10Y = candidatePositions[3]; spot11X = local_c0; spot11Y = spot5Y; spot12X = candidatePositions[0]; spot12Y = candidatePositions[1]; spot13X = candidatePositions[2]; spot13Y = candidatePositions[3]; spotShape9 = spotShape8; spotShape11 = spotShape10; candidateDoorSlots[1] = candidateDoorSlots[0]; candidateDoorSlots[3] = candidateDoorSlots[0]; spotDoorSlot4 = candidateDoorSlots[2]; spotDoorSlot5 = candidateDoorSlots[0]; spotDoorSlot6 = candidateDoorSlots[2]; spotDoorSlot7 = candidateDoorSlots[0]; spotDoorSlot8 = candidateDoorSlots[2]; spotDoorSlot9 = candidateDoorSlots[0]; spotDoorSlot10 = candidateDoorSlots[2]; spotDoorSlot11 = candidateDoorSlots[0]; spotDoorSlot12 = candidateDoorSlots[0]; iVar1 = FUN_009afd70(); if (iVar1 < 0) { KAGE_LogMessage(0x10,GHIDRA_CAST("[LevelGenerator] try_resize_room: invalid room\n")); } if ((*GHIDRA_CAST((GHIDRA_CAST(room) + 0x28)) < 0xd) && (*GHIDRA_CAST((GHIDRA_CAST(room) + 0x2c)) < 0xd)) { iVar1 = *GHIDRA_CAST((GHIDRA_CAST(room) + 0x2c)) * 0xd + *GHIDRA_CAST((GHIDRA_CAST(room) + 0x28)); } else { iVar1 = -1; } local_104 = candidatePositions; local_108 = 0; local_10c = generatorCopy[iVar1 + 5]; iVar1 = shapeCopy; generator = generatorCopy; do { piVar3 = local_104; if (candidateShapes[local_108] == iVar1) { if ((possibleDoors[candidateDoorSlots[local_108] >> 5] & 1 << ((byte)candidateDoorSlots[local_108] & 0x1f)) != 0) { isFits = '\x01'; newShapeOffsets = get_room_placement_offsets(shapeCopy); for (offset = *newShapeOffsets + 1; (offset[-1] != g_levelGenInvalidPos[0] || (*offset != g_levelGenInvalidPos[1])); offset = offset + 2) { uVar4 = *piVar3 + offset[-1]; uVar2 = *offset + piVar3[1]; if (((0xc < uVar4) || ((0xc < uVar2 || (iVar1 = uVar2 * 0xd + uVar4, iVar1 < 0)))) || ((-1 < GHIDRA_INT(generator[iVar1 + 5]) && (generator[iVar1 + 5] != local_10c)))) { isFits = '\0'; } } doorSlot = 0; uVar4 = 1; uVar2 = 0; do { doorTargetPos = GHIDRA_CAST(get_door_target_position) (GHIDRA_CAST(local_f0),local_104,candidateShapes[local_108],doorSlot,0); neighborCount = uVar2; if ((((*doorTargetPos < 0xd) && (doorTargetPos[1] < 0xd)) && (iVar1 = doorTargetPos[1] * 0xd + *doorTargetPos, -1 < iVar1)) && ((cellRoomIdx = generatorCopy[iVar1 + 5], -1 < GHIDRA_INT(cellRoomIdx) && (cellRoomIdx != local_10c)))) { neighborCount = uVar2 + 1; if (*GHIDRA_CAST((GHIDRA_INT(generatorCopy[0xd9]) + 0x44 + GHIDRA_INT(cellRoomIdx) * 0x48)) != '\0') { neighborCount = uVar2; } if ((possibleDoors[doorSlot >> 5] & uVar4) == 0) { isFits = '\0'; } } doorSlot = doorSlot + 1; uVar4 = uVar4 << 1 | GHIDRA_UINT((GHIDRA_INT(uVar4) < 0)); uVar2 = neighborCount; } while (doorSlot < 8); isPlacementValid = '\0'; if (neighborCount < 2) { isPlacementValid = isFits; } if (isPlacementValid != '\0') { local_f0[0] = get_room_placement_offsets(*GHIDRA_CAST((GHIDRA_CAST(roomCopy) + 0x18))); generator = generatorCopy; iVar1 = 0; break; } generator = generatorCopy; } iVar1 = shapeCopy; } local_108 = local_108 + 1; local_104 = local_104 + 2; if (0xd < local_108) { return 0; } } while( true ); LAB_009b1700: resizedRoom = roomCopy; piVar3 = GHIDRA_CAST((GHIDRA_INT(*local_f0[0]) + iVar1)); if ((*piVar3 == g_levelGenInvalidPos[0]) && (piVar3[1] == g_levelGenInvalidPos[1])) { for (iVar1 = 0; (piVar3 = GHIDRA_CAST((GHIDRA_INT(*newShapeOffsets) + iVar1)), *piVar3 != g_levelGenInvalidPos[0] || (piVar3[1] != g_levelGenInvalidPos[1])); iVar1 = iVar1 + 8) { if ((GHIDRA_UINT((*piVar3 + candidatePositions[local_108 * 2])) < 0xd) && (GHIDRA_UINT((candidatePositions[local_108 * 2 + 1] + piVar3[1])) < 0xd)) { gridIdx = (candidatePositions[local_108 * 2 + 1] + piVar3[1]) * 0xd + *piVar3 + candidatePositions[local_108 * 2]; } else { gridIdx = -1; } generator[gridIdx + 5] = local_10c; } iVar1 = candidatePositions[local_108 * 2 + 1]; *GHIDRA_CAST((GHIDRA_CAST(roomCopy) + 8)) = candidatePositions[local_108 * 2]; *GHIDRA_CAST((GHIDRA_CAST(roomCopy) + 0xc)) = iVar1; shapeSizeY = *GHIDRA_CAST((&DAT_00c5d37c + shapeCopy * 8)); *GHIDRA_CAST((GHIDRA_CAST(roomCopy) + 0x10)) = *GHIDRA_CAST((&DAT_00c5d378 + shapeCopy * 8)); *GHIDRA_CAST((GHIDRA_CAST(roomCopy) + 0x14)) = shapeSizeY; *GHIDRA_CAST((GHIDRA_CAST(roomCopy) + 0x18)) = shapeCopy; local_10c = *GHIDRA_CAST(*GHIDRA_CAST((GHIDRA_CAST(roomCopy) + 0x30))); if (local_10c != *GHIDRA_CAST((GHIDRA_CAST(roomCopy) + 0x30))) { do { update_room_neighbors (generator,(void *)(GHIDRA_INT(generator[0xd9]) + *GHIDRA_CAST((GHIDRA_CAST(local_10c) + 0x10)) * 0x48) ); std:: _Tree_unchecked_const_iterator_>,std::_Iterator_base0> ::operator++((_Tree_unchecked_const_iterator_>,std::_Iterator_base0> *)&local_10c); } while (local_10c != *GHIDRA_CAST((GHIDRA_CAST(resizedRoom) + 0x30))); } update_room_neighbors(generator,resizedRoom); return 1; } local_104 = GHIDRA_CAST((*GHIDRA_CAST((GHIDRA_CAST(roomCopy) + 8)) + *piVar3)); uVar2 = *GHIDRA_CAST((GHIDRA_CAST(roomCopy) + 0xc)) + piVar3[1]; if ((local_104 < GHIDRA_CAST(0xd)) && (uVar2 < 0xd)) { gridIdx = uVar2 * 0xd + GHIDRA_INT(local_104); if (gridIdx < 0) goto LAB_009b1744; } else { gridIdx = -1; LAB_009b1744: KAGE_LogMessage(0x10,GHIDRA_CAST("[LevelGenerator] try_resize_endroom: invalid room\n")); } iVar1 = iVar1 + 8; generator[gridIdx + 5] = (LevelGenerator)0xffffffff; goto LAB_009b1700; } // 009b1860 void LevelGenerator::block_room_area(void *room, int unused) { int **placementOffsets; int *piVar1; uint cellY; int gridIndex; int cellOffset; uint cellX; uint neighborOffset; int *piVar2; placementOffsets = get_room_placement_offsets(*GHIDRA_CAST((GHIDRA_CAST(room) + 0x18))); piVar1 = *placementOffsets; for (cellOffset = 0; (*GHIDRA_CAST((cellOffset + GHIDRA_INT(piVar1))) != g_levelGenInvalidPos[0] || (*GHIDRA_CAST((cellOffset + 4 + GHIDRA_INT(piVar1))) != g_levelGenInvalidPos[1])); cellOffset = cellOffset + 8) { neighborOffset = 0; piVar2 = piVar1; do { cellX = *GHIDRA_CAST((cellOffset + GHIDRA_INT(piVar1))) + *GHIDRA_CAST((GHIDRA_INT(&DAT_00c35e9c) + neighborOffset)) + *GHIDRA_CAST((GHIDRA_CAST(room) + 8)); cellY = *GHIDRA_CAST((GHIDRA_CAST(room) + 0xc)) + *GHIDRA_CAST((GHIDRA_INT(&DAT_00c35ea0) + neighborOffset)) + *GHIDRA_CAST((cellOffset + 4 + GHIDRA_INT(piVar1))) ; if (((cellX < 0xd) && (cellY < 0xd)) && (gridIndex = cellY * 0xd + cellX, -1 < gridIndex)) { *GHIDRA_CAST((gridIndex + 0x2b8 + GHIDRA_INT(this))) = 1; piVar1 = *placementOffsets; piVar2 = piVar1; } neighborOffset = neighborOffset + 8; } while (neighborOffset < 0x28); piVar1 = piVar2; } return; } // 009b1910 void LevelGenerator::block_cell(int *param_1) { int iVar1; int in_ECX; if (((GHIDRA_UINT((*param_1 + DAT_00c35e9c)) < 0xd) && (GHIDRA_UINT((DAT_00c35ea0 + param_1[1])) < 0xd)) && (iVar1 = (DAT_00c35ea0 + param_1[1]) * 0xd + *param_1 + DAT_00c35e9c, -1 < iVar1)) { *GHIDRA_CAST((iVar1 + 0x2b8 + in_ECX)) = 1; } return; } // 009b1950 void LevelGenerator::block_cells_near_rooms(void *otherLayout, int unused) { uint neighbourByteOffset; uint neighbourY; int neighbourIndex; uint neighbourX; uint x; int cellIndex; int y; uint rowStart; y = 0; rowStart = 0; do { x = 0; do { if (rowStart < 0x9d) { cellIndex = rowStart + x; } else { cellIndex = -1; } neighbourByteOffset = 0; do { if ((&(*GHIDRA_CAST((GHIDRA_CAST(&(this[0xae])) + 0x0))))[cellIndex] != '\0') break; neighbourX = *GHIDRA_CAST((GHIDRA_INT(&DAT_00c35e9c) + neighbourByteOffset)) + x; neighbourY = *GHIDRA_CAST((GHIDRA_INT(&DAT_00c35ea0) + neighbourByteOffset)) + y; if ((((neighbourX < 0xd) && (neighbourY < 0xd)) && (neighbourIndex = neighbourY * 0xd + neighbourX, -1 < neighbourIndex)) && (-1 < *GHIDRA_CAST((GHIDRA_CAST(otherLayout) + neighbourIndex * 4 + 0x14)))) { (&(*GHIDRA_CAST((GHIDRA_CAST(&(this[0xae])) + 0x0))))[cellIndex] = 1; } neighbourByteOffset = neighbourByteOffset + 8; } while (neighbourByteOffset < 0x28); x = x + 1; } while (x < 0xd); y = y + 1; rowStart = rowStart + 0xd; if (0xa8 < rowStart) { return; } } while( true ); } // 009b1a00 void LevelGenerator::block_unused_door_cells(void *room, uint *doorMask) { int cellIndex; uint doorBit; uint doorSlot; int cellX; int cellY; doorSlot = 0; doorBit = 1; do { if (((doorMask[doorSlot >> 5] & doorBit) == 0) && ((get_door_target_position (&cellX,GHIDRA_CAST((GHIDRA_INT(room) + 8)),*GHIDRA_CAST((GHIDRA_CAST(room) + 0x18)),doorSlot,1), cellX != g_levelGenInvalidPos[0] || (cellY != g_levelGenInvalidPos[1])))) { if ((GHIDRA_UINT((cellX + DAT_00c35e9c)) < 0xd) && ((GHIDRA_UINT((DAT_00c35ea0 + cellY)) < 0xd && (cellIndex = (DAT_00c35ea0 + cellY) * 0xd + cellX + DAT_00c35e9c, -1 < cellIndex)))) { *GHIDRA_CAST((cellIndex + 0x2b8 + GHIDRA_INT(this))) = 1; } } doorSlot = doorSlot + 1; doorBit = doorBit << 1 | GHIDRA_UINT((GHIDRA_INT(doorBit) < 0)); } while (doorSlot < 8); return; } // 009b1a90 void LevelGenerator::queue_push_front(undefined4 *param_1) { uint uVar1; int iVar2; void *pvVar3; int in_ECX; int iVar4; uint uVar5; uVar5 = *GHIDRA_CAST((in_ECX + 0xc)); if (((uVar5 & 3) == 0) && (*GHIDRA_CAST((in_ECX + 8)) <= *GHIDRA_CAST((in_ECX + 0x10)) + 4U >> 2)) { std::deque<4byte>::_Growmap(in_ECX); uVar5 = *GHIDRA_CAST((in_ECX + 0xc)); } uVar1 = *GHIDRA_CAST((in_ECX + 8)) * 4; uVar5 = uVar1 - 1 & uVar5; *GHIDRA_CAST((in_ECX + 0xc)) = uVar5; if (uVar5 == 0) { uVar5 = uVar1; } uVar5 = uVar5 - 1; iVar2 = (*GHIDRA_CAST((in_ECX + 8)) - 1U & uVar5 >> 2) * 4; iVar4 = *GHIDRA_CAST((in_ECX + 4)); if (*GHIDRA_CAST((iVar4 + iVar2)) == 0) { pvVar3 = operator_new(0x10); *(void **)(iVar2 + *GHIDRA_CAST((in_ECX + 4))) = pvVar3; iVar4 = *GHIDRA_CAST((in_ECX + 4)); } *GHIDRA_CAST((*GHIDRA_CAST((iVar2 + iVar4)) + (uVar5 & 3) * 4)) = *param_1; *GHIDRA_CAST((in_ECX + 0x10)) = *GHIDRA_CAST((in_ECX + 0x10)) + 1; *GHIDRA_CAST((in_ECX + 0xc)) = uVar5; return; }