Files
isaac-port/generated-src/level_generator.cpp
T
shweetandClaude Opus 5.5 9d4d4f5c64 Build 29: zero-length placeholder structs, generated-src with standard types
--check: 938/3256 method bodies compile for x86_64 (28.8%), 32-bit layout asserts hold; boot path 3/626 curated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 21:41:34 -05:00

2058 lines
79 KiB
C++

#include "classes.h"
// 009addf0
uint8_t LevelGenerator::try_add_dead_end(int unused, void *excludedGridIndices)
{
int iVar1;
void *pvVar2;
uint8_t bVar3;
int iVar4;
int iVar5;
uint32_t extraout_ECX;
uint32_t extraout_ECX_00;
uint32_t extraout_ECX_01;
uint32_t extraout_ECX_02;
uint32_t uVar6;
int *piVar7;
LevelGenerator_Room *pLVar8;
uint32_t uVar9;
LevelGenerator_Room *candidate;
void *candidateGridIndex;
uint8_t 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;
uint8_t *puStack_c;
uint32_t local_8;
local_8 = 0xffffffff;
puStack_c = &LAB_00b0e1a5;
local_10 = ExceptionList;
ExceptionList = &local_10;
iVar4 = *GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x122])) + 0x2))));
uVar9 = (iVar4 - *GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x121])) + 0x1))))) / 0x48;
roomOrder = GHIDRA_CAST<int *>(0x0);
local_18 = GHIDRA_CAST<int *>(0x0);
local_30 = GHIDRA_CAST<int *>(0x0);
roomOrderCapacityEnd = GHIDRA_CAST<int *>(0x0);
generator = this;
if (uVar9 != 0) {
if (0x3fffffff < uVar9) {
/* WARNING: Subroutine does not return */
msvc::_Xlen();
}
roomOrder = msvc::_Allocate(uVar9 * 4);
piVar7 = roomOrder + uVar9;
roomOrderCapacityEnd = piVar7;
local_18 = piVar7;
memset(roomOrder,0,uVar9 * 4);
iVar4 = *GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x122])) + 0x2))));
local_30 = piVar7;
}
(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(local_8)) + 0x0))) = 0;
(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(local_8)) + 0x1))) = 0;
iVar4 = iVar4 - *GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x121])) + 0x1))));
uVar9 = 0;
iVar1 = iVar4 >> 0x1f;
if (iVar4 / 0x48 + iVar1 != iVar1) {
do {
roomOrder[uVar9] = uVar9;
uVar9 = uVar9 + 1;
} while (uVar9 < GHIDRA_UINT(((*GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x122])) + 0x2)))) - *GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x121])) + 0x1))))) / 0x48
)));
}
RNG::Shuffle(GHIDRA_CAST<RNG *>(this),roomOrder,local_18);
pvVar2 = excludedGridIndices;
iVar4 = *GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x121])) + 0x1))));
iVar5 = *GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x122])) + 0x2)))) - iVar4;
local_18 = GHIDRA_CAST<int *>(0x0);
iVar1 = iVar5 >> 0x1f;
if (iVar5 / 0x48 + iVar1 != iVar1) {
do {
get_neighbor_candidates
(this,&candidates,*GHIDRA_CAST<uint32_t *>((iVar4 + 4 + roomOrder[GHIDRA_INT(local_18)] * 0x48)),1);
(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(local_8)) + 0x0))) = 1;
uVar6 = extraout_ECX;
pLVar8 = candidatesLast;
candidate = candidates;
if (candidates != candidatesLast) {
do {
if (*GHIDRA_CAST<int *>((candidate + 8)) == 1) {
bVar3 = can_place_room(generator,GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(candidate[2])) + 0x2)))),1);
uVar6 = extraout_ECX_00;
if ((bVar3 != 0) &&
(iVar4 = count_neighbor_rooms(generator,GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(candidate[0xd])) + 0x1))))),
uVar6 = extraout_ECX_01, iVar4 < 2)) {
if (pvVar2 != (void *)0x0) {
uVar9 = *GHIDRA_CAST<uint32_t *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(candidate[2])) + 0x2))));
if ((uVar9 < 0xd) && (*GHIDRA_CAST<uint32_t *>((candidate + 4)) < 0xd)) {
candidateGridIndex = (void *)(*GHIDRA_CAST<uint32_t *>((candidate + 4)) * 0xd + uVar9);
}
else {
candidateGridIndex = (void *)0xffffffff;
}
excludedGridIndices = candidateGridIndex;
msvc::set<int>::find_node(local_40,&excludedGridIndices);
if (((*GHIDRA_CAST<char *>((local_38 + 0xd)) == '\0') &&
(*GHIDRA_CAST<int *>((local_38 + 0x10)) <= GHIDRA_INT(candidateGridIndex))) &&
(uVar6 = extraout_ECX_02, local_38 != *GHIDRA_CAST<int *>(pvVar2))) goto LAB_009adfbd;
}
bVar3 = place_room(generator,candidate);
update_dead_end_lists(generator);
vector_LevelGenerator_Room_tidy(&candidates);
goto LAB_009ae06b;
}
LAB_009adfbd:
pLVar8 = candidatesLast;
}
candidate = candidate + 0x18;
} while (candidate != pLVar8);
this = generator;
}
(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(local_8)) + 0x0))) = 0;
if (candidates != GHIDRA_CAST<LevelGenerator_Room *>(0x0)) {
FUN_00752e40(uVar6);
uVar9 = ((candidatesCapacityEnd - GHIDRA_INT(candidates)) / 0x48) * 0x48;
pLVar8 = candidates;
if (0xfff < uVar9) {
pLVar8 = *GHIDRA_CAST<LevelGenerator_Room **>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(candidates[-2])) + 0x2))));
uVar9 = uVar9 + 0x23;
if (0x1f < GHIDRA_UINT((GHIDRA_INT(candidates) + (-4 - GHIDRA_INT(pLVar8))))) goto LAB_009ae094;
}
operator_delete(pLVar8,uVar9);
candidates = GHIDRA_CAST<LevelGenerator_Room *>(0x0);
candidatesLast = GHIDRA_CAST<LevelGenerator_Room *>(0x0);
candidatesCapacityEnd = 0;
}
iVar4 = *GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x121])) + 0x1))));
local_18 = GHIDRA_CAST<int *>((GHIDRA_INT(local_18) + 1));
} while (local_18 < GHIDRA_UINT(((*GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x122])) + 0x2)))) - iVar4) / 0x48)));
}
bVar3 = 0;
LAB_009ae06b:
if (roomOrder != GHIDRA_CAST<int *>(0x0)) {
uVar9 = GHIDRA_INT(roomOrderCapacityEnd) - GHIDRA_INT(roomOrder) & 0xfffffffc;
piVar7 = roomOrder;
if (0xfff < uVar9) {
piVar7 = GHIDRA_CAST<int *>(roomOrder[-1]);
uVar9 = uVar9 + 0x23;
if (0x1f < GHIDRA_UINT((GHIDRA_INT(roomOrder) + (-4 - GHIDRA_INT(piVar7))))) {
LAB_009ae094:
/* WARNING: Subroutine does not return */
_invalid_parameter_noinfo_noreturn();
}
}
operator_delete(piVar7,uVar9);
}
ExceptionList = local_10;
return bVar3;
}
// 009ae0e0
LevelGenerator_Room * LevelGenerator::GetNewEndRoom(int roomShape, uint32_t *possibleDoors)
{
LevelGenerator_Room *room;
uint8_t isResized;
int *deadEndIt;
int *nextIt;
deadEndIt = *GHIDRA_CAST<int **>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x125])) + 0x1))));
if (deadEndIt != *GHIDRA_CAST<int **>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x126])) + 0x2))))) {
do {
nextIt = deadEndIt + 1;
room = GHIDRA_CAST<LevelGenerator_Room *>((*GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x121])) + 0x1)))) + *deadEndIt * 0x48));
isResized = try_resize_room(this,room,roomShape,possibleDoors);
if (isResized != 0) {
memmove(deadEndIt,nextIt,*GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x126])) + 0x2)))) - GHIDRA_INT(nextIt));
*GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x126])) + 0x2)))) = *GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x126])) + 0x2)))) + -4;
return room;
}
deadEndIt = nextIt;
} while (nextIt != *GHIDRA_CAST<int **>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x126])) + 0x2)))));
}
return GHIDRA_CAST<LevelGenerator_Room *>(0x0);
}
// 009ae170
void * LevelGenerator::place_secret_room(void *excludedIndices)
{
code *pcVar1;
uint32_t *puVar2;
void *pvVar3;
int iVar4;
int *doorTarget;
uint32_t uVar5;
uint32_t *puVar6;
int iVar7;
uint32_t dir;
uint32_t uVar8;
int doorTargetPos [2];
uint8_t local_c0 [8];
int foundNode;
uint32_t cellIndex;
int bestScore;
int cellScore;
uint32_t *bestCells;
uint32_t *bestCellsEnd;
uint32_t *bestCellsCapacity;
void *local_9c;
uint32_t local_98;
uint32_t *cellsCapacity;
uint32_t local_90;
int *cellSlot;
uint32_t *cellsBegin;
uint32_t *local_84;
LevelGenerator_Room newRoom [16];
void *local_50 [5];
uint8_t local_3c;
int neighborOffsets [10];
void *local_10;
uint8_t *puStack_c;
int local_8;
puStack_c = &LAB_00b0e1e8;
local_10 = ExceptionList;
neighborOffsets[8] = __security_cookie ^ GHIDRA_UINT((neighborOffsets + 0xd));
ExceptionList = &local_10;
puVar6 = GHIDRA_CAST<uint32_t *>(0x0);
neighborOffsets[0] = -1;
neighborOffsets[1] = 0;
neighborOffsets[2] = 0;
neighborOffsets[3] = 0xffffffff;
puVar2 = GHIDRA_CAST<uint32_t *>(0x0);
neighborOffsets[4] = 1;
neighborOffsets[5] = 0;
neighborOffsets[6] = 0;
neighborOffsets[7] = 1;
bestScore = 0;
cellsBegin = GHIDRA_CAST<uint32_t *>(0x0);
bestCells = GHIDRA_CAST<uint32_t *>(0x0);
local_84 = GHIDRA_CAST<uint32_t *>(0x0);
bestCellsEnd = GHIDRA_CAST<uint32_t *>(0x0);
cellsCapacity = GHIDRA_CAST<uint32_t *>(0x0);
bestCellsCapacity = GHIDRA_CAST<uint32_t *>(0x0);
local_8 = 0;
cellSlot = GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[6])) + 0x2))));
cellIndex = 0;
do {
doorTarget = cellSlot;
uVar8 = cellIndex;
if (*cellSlot < 0) {
local_98 = cellIndex;
msvc::set<int>::find_node(local_c0,&local_98);
if ((((*GHIDRA_CAST<char *>((foundNode + 0xd)) == '\0') && (*GHIDRA_CAST<int *>((foundNode + 0x10)) <= GHIDRA_INT(uVar8))) &&
(foundNode != *GHIDRA_CAST<int *>(excludedIndices))) || ((&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0xe8])) + 0x0))))[uVar8] != '\0')) {
puVar2 = local_84;
puVar6 = cellsBegin;
}
else {
dir = *GHIDRA_CAST<uint32_t *>(this);
local_90 = uVar8 / 0xd;
local_9c = (void *)(uVar8 % 0xd);
if (dir == 0) {
KAGE_LogMessage(0x10,GHIDRA_CAST<uint8_t *>("RNG Seed is zero!\n"));
dir = *GHIDRA_CAST<uint32_t *>(this);
if (dir == 0) {
pcVar1 = (code *)swi(3);
pvVar3 = (void *)(*pcVar1)();
return pvVar3;
}
}
dir = dir >> ((uint8_t)*GHIDRA_CAST<uint32_t *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[1])) + 0x1)))) & 0x1f) ^ dir;
local_98 = 0;
dir = dir << ((uint8_t)*GHIDRA_CAST<uint32_t *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[2])) + 0x2)))) & 0x1f) ^ dir;
dir = dir >> ((uint8_t)*GHIDRA_CAST<uint32_t *>((this + 4)) & 0x1f) ^ dir;
*GHIDRA_CAST<uint32_t *>(this) = dir;
iVar7 = dir % 5 + 10;
dir = 0;
cellScore = iVar7;
do {
uVar5 = local_98;
if (GHIDRA_UINT((GHIDRA_INT(local_9c) + neighborOffsets[dir * 2])) < 0xd) {
if (neighborOffsets[dir * 2 + 1] + local_90 < 0xd) {
iVar4 = (neighborOffsets[dir * 2 + 1] + local_90) * 0xd +
GHIDRA_INT(local_9c) + neighborOffsets[dir * 2];
if (-1 < iVar4) {
iVar4 = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + iVar4 * 4 + 0x14));
if (-1 < iVar4) {
iVar7 = *GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x121])) + 0x1)))) + iVar4 * 0x48;
doorTarget = get_door_target_position
(doorTargetPos,GHIDRA_CAST<int *>((iVar7 + 8)),*GHIDRA_CAST<int *>((iVar7 + 0x18)),
dir - 2 & 3,0);
if ((*doorTarget == g_levelGenInvalidPos[0]) &&
(doorTarget[1] == g_levelGenInvalidPos[1])) {
cellScore = cellScore + -100;
iVar7 = cellScore;
}
else {
uVar5 = uVar5 + 1;
iVar7 = cellScore;
local_98 = uVar5;
}
}
}
}
}
uVar8 = cellIndex;
dir = dir + 1;
} while (dir < 4);
if ((uVar5 != 0) && (-1 < iVar7)) {
iVar4 = iVar7 + -3;
if (2 < GHIDRA_INT(local_98)) {
iVar4 = iVar7;
}
iVar7 = iVar4 + -3;
if (1 < GHIDRA_INT(local_98)) {
iVar7 = iVar4;
}
if (bestScore < iVar7) {
bestCellsEnd = cellsBegin;
local_90 = cellIndex;
bestScore = iVar7;
if (cellsBegin == cellsCapacity) {
msvc::vector<unsigned_int>::_Emplace_reallocate(cellsBegin,&local_90);
cellsCapacity = bestCellsCapacity;
local_84 = bestCellsEnd;
cellsBegin = bestCells;
}
else {
bestCellsEnd = cellsBegin + 1;
*cellsBegin = cellIndex;
local_84 = bestCellsEnd;
}
}
else if (iVar7 == bestScore) {
local_90 = cellIndex;
if (local_84 == cellsCapacity) {
msvc::vector<unsigned_int>::_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;
puVar6 = cellsBegin;
doorTarget = cellSlot;
}
}
cellIndex = uVar8 + 1;
cellSlot = doorTarget + 1;
} while (cellIndex < 0xa9);
local_84 = GHIDRA_CAST<uint32_t *>((GHIDRA_INT(puVar2) - GHIDRA_INT(puVar6) >> 2));
if (local_84 == GHIDRA_CAST<uint32_t *>(0x0)) {
pvVar3 = (void *)0x0;
}
else {
uVar8 = *GHIDRA_CAST<uint32_t *>(this);
if (uVar8 == 0) {
KAGE_LogMessage(0x10,GHIDRA_CAST<uint8_t *>("RNG Seed is zero!\n"));
uVar8 = *GHIDRA_CAST<uint32_t *>(this);
if (uVar8 == 0) {
pcVar1 = (code *)swi(3);
pvVar3 = (void *)(*pcVar1)();
return pvVar3;
}
}
uVar8 = uVar8 >> ((uint8_t)*GHIDRA_CAST<uint32_t *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[1])) + 0x1)))) & 0x1f) ^ uVar8;
uVar8 = uVar8 ^ uVar8 << ((uint8_t)*GHIDRA_CAST<uint32_t *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[2])) + 0x2)))) & 0x1f);
uVar8 = uVar8 ^ uVar8 >> ((uint8_t)*GHIDRA_CAST<uint32_t *>((this + 4)) & 0x1f);
*GHIDRA_CAST<uint32_t *>(this) = uVar8;
uVar8 = cellsBegin[uVar8 % GHIDRA_UINT(local_84)];
local_90 = GHIDRA_INT(uVar8) % 0xd;
(GHIDRA_CAST<LevelGenerator_Room *>((newRoom)))->LevelGenerator_Room::constructor(local_90,GHIDRA_INT(uVar8) / 0xd,1);
local_8 = CONCAT31((*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(local_8)) + 0x1))),1);
local_3c = 1;
place_room(this,newRoom);
local_9c = (void *)(*GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x121])) + 0x1)))) +
*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + uVar8 * 4 + 0x14)) * 0x48);
update_room_neighbors(this,local_9c);
dir = 0;
do {
uVar5 = neighborOffsets[dir * 2 + 1] + GHIDRA_INT(uVar8) / 0xd;
if ((((local_90 + neighborOffsets[dir * 2] < 0xd) && (uVar5 < 0xd)) &&
(iVar7 = uVar5 * 0xd + local_90 + neighborOffsets[dir * 2], -1 < iVar7)) &&
(iVar7 = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + iVar7 * 4 + 0x14)), -1 < iVar7)) {
update_room_neighbors(this,(void *)(*GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x121])) + 0x1)))) + iVar7 * 0x48));
}
dir = dir + 1;
} while (dir < 4);
FID_conflict__Erase_tree<fuzzer::fuzzer_allocator<msvc::_Tree_node<fuzzer::TracePC::PCTableEntry_const*,void*>_>_>
(local_50,(fuzzer_allocator<msvc::_Tree_node<unsigned_int,void*>_> *)local_50,
*(_Tree_node<unsigned_int,void*> **)(GHIDRA_INT(local_50[0]) + 4));
operator_delete(local_50[0],0x14);
puVar6 = cellsBegin;
pvVar3 = local_9c;
}
if (puVar6 != GHIDRA_CAST<uint32_t *>(0x0)) {
uVar8 = GHIDRA_INT(cellsCapacity) - GHIDRA_INT(puVar6) & 0xfffffffc;
puVar2 = puVar6;
if (0xfff < uVar8) {
puVar2 = GHIDRA_CAST<uint32_t *>(puVar6[-1]);
uVar8 = uVar8 + 0x23;
if (0x1f < GHIDRA_UINT((GHIDRA_INT(puVar6) + (-4 - GHIDRA_INT(puVar2))))) {
/* WARNING: Subroutine does not return */
_invalid_parameter_noinfo_noreturn();
}
}
operator_delete(puVar2,uVar8);
}
ExceptionList = local_10;
return pvVar3;
}
// 009ae640
void * LevelGenerator::try_place_room(void *allowedIndices)
{
code *pcVar1;
uint32_t *puVar2;
void *result;
uint32_t seed;
int iVar3;
int iVar4;
uint32_t *puVar5;
uint32_t uVar6;
uint32_t uVar7;
uint8_t local_128 [8];
int local_120;
uint8_t local_11c [8];
int local_114;
uint32_t doorTargetX;
uint32_t doorTargetY;
uint32_t column;
LevelGenerator *local_104;
uint32_t neighborDir;
uint32_t *local_fc;
uint32_t *local_f8;
uint32_t *local_f4;
void *local_f0;
uint32_t score;
int offsetX;
int neighborRoom;
uint32_t local_e0;
uint32_t *candidatesCapacity;
uint32_t local_d8;
int *gridSlot;
uint32_t gridIndex;
uint32_t local_cc;
uint32_t *candidatesBegin;
uint32_t *local_c4;
LevelGenerator_Room newRoom [16];
void *local_90 [5];
uint8_t local_7c;
int neighborOffsets [26];
void *local_10;
uint8_t *puStack_c;
int local_8;
puStack_c = &LAB_00b0e23b;
local_10 = ExceptionList;
neighborOffsets[0x18] = __security_cookie ^ GHIDRA_UINT((neighborOffsets + 0x1d));
ExceptionList = &local_10;
puVar5 = GHIDRA_CAST<uint32_t *>(0x0);
neighborOffsets[0x10] = 0xffffffff;
neighborOffsets[0x11] = 0;
neighborOffsets[0x12] = 0;
neighborOffsets[0x13] = 0xffffffff;
puVar2 = GHIDRA_CAST<uint32_t *>(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<uint32_t *>(0x0);
neighborOffsets[4] = 0;
neighborOffsets[5] = 0xfffffffe;
neighborOffsets[6] = 1;
neighborOffsets[7] = 0xffffffff;
local_fc = GHIDRA_CAST<uint32_t *>(0x0);
neighborOffsets[8] = 2;
neighborOffsets[9] = 0;
neighborOffsets[10] = 1;
neighborOffsets[0xb] = 1;
local_c4 = GHIDRA_CAST<uint32_t *>(0x0);
neighborOffsets[0xc] = 0;
neighborOffsets[0xd] = 2;
neighborOffsets[0xe] = 0xffffffff;
neighborOffsets[0xf] = 1;
local_f8 = GHIDRA_CAST<uint32_t *>(0x0);
candidatesCapacity = GHIDRA_CAST<uint32_t *>(0x0);
local_f4 = GHIDRA_CAST<uint32_t *>(0x0);
gridSlot = GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[6])) + 0x2))));
local_8 = 0;
gridIndex = 0;
local_104 = this;
do {
seed = gridIndex;
if (*gridSlot < 0) {
if (*GHIDRA_CAST<char *>((GHIDRA_INT(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0xe8])) + 0x0)))) + gridIndex)) == '\0') {
if (allowedIndices == (void *)0x0) {
LAB_009ae755:
seed = *GHIDRA_CAST<uint32_t *>(this);
if (seed == 0) {
KAGE_LogMessage(0x10,GHIDRA_CAST<uint8_t *>("RNG Seed is zero!\n"));
seed = *GHIDRA_CAST<uint32_t *>(this);
if (seed == 0) {
pcVar1 = (code *)swi(3);
result = (void *)(*pcVar1)();
return result;
}
}
seed = seed >> ((uint8_t)*GHIDRA_CAST<uint32_t *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[1])) + 0x1)))) & 0x1f) ^ seed;
seed = seed << ((uint8_t)*GHIDRA_CAST<uint32_t *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[2])) + 0x2)))) & 0x1f) ^ seed;
seed = seed >> ((uint8_t)*GHIDRA_CAST<uint32_t *>((this + 4)) & 0x1f) ^ seed;
*GHIDRA_CAST<uint32_t *>(this) = seed;
seed = seed % 5;
score = seed + 10;
local_d8 = 0;
local_f0 = (void *)(gridIndex / 0xd);
column = gridIndex % 0xd;
uVar6 = 0;
do {
if (((column + neighborOffsets[uVar6 * 2 + 0x10] < 0xd) &&
(GHIDRA_UINT((neighborOffsets[uVar6 * 2 + 0x11] + GHIDRA_INT(local_f0))) < 0xd)) &&
((iVar3 = (neighborOffsets[uVar6 * 2 + 0x11] + GHIDRA_INT(local_f0)) * 0xd +
column + neighborOffsets[uVar6 * 2 + 0x10], -1 < iVar3 &&
((-1 < *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + iVar3 * 4 + 0x14)) ||
(*GHIDRA_CAST<char *>((GHIDRA_CAST<char *>(this) + iVar3 + 0x2b8)) != '\0')))))) {
score = seed - 0x5a;
if (GHIDRA_INT(score) < 0) goto LAB_009aeaab;
break;
}
uVar6 = uVar6 + 1;
} while (uVar6 < 4);
neighborDir = 0;
do {
if (GHIDRA_INT(score) < 0) break;
iVar3 = neighborOffsets[neighborDir * 2];
offsetX = iVar3;
if ((column + iVar3 < 0xd) &&
(GHIDRA_UINT((neighborOffsets[neighborDir * 2 + 1] + GHIDRA_INT(local_f0))) < 0xd)) {
iVar4 = (neighborOffsets[neighborDir * 2 + 1] + GHIDRA_INT(local_f0)) * 0xd + column + iVar3;
if (-1 < iVar4) {
iVar4 = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + iVar4 * 4 + 0x14));
if (-1 < iVar4) {
seed = 0;
iVar4 = *GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x121])) + 0x1)))) + iVar4 * 0x48;
neighborRoom = iVar4;
do {
if (0 < neighborOffsets[seed * 2 + 0x11] * neighborOffsets[neighborDir * 2 + 1]
+ neighborOffsets[seed * 2 + 0x10] * iVar3) {
get_door_target_position
(GHIDRA_CAST<int *>(&doorTargetX),GHIDRA_CAST<int *>((iVar4 + 8)),*GHIDRA_CAST<int *>((iVar4 + 0x18)),
seed - 2 & 3,0);
if ((doorTargetX < 0xd) && (doorTargetY < 0xd)) {
uVar6 = doorTargetY * 0xd + doorTargetX;
local_cc = uVar6;
if ((-1 < GHIDRA_INT(uVar6)) &&
((((allowedIndices == (void *)0x0 ||
(msvc::set<int>::find_node(local_128,&local_cc),
*GHIDRA_CAST<char *>((local_120 + 0xd)) != '\0')) ||
(GHIDRA_INT(uVar6) < *GHIDRA_CAST<int *>((local_120 + 0x10)))) ||
(local_120 == *GHIDRA_CAST<int *>(allowedIndices))))) {
iVar4 = neighborRoom;
iVar3 = offsetX;
goto LAB_009ae936;
}
}
else {
local_cc = 0xffffffff;
}
score = score - 100;
break;
}
LAB_009ae936:
seed = seed + 1;
} while (seed < 4);
local_d8 = local_d8 + 1;
this = local_104;
}
}
}
neighborDir = neighborDir + 1;
} while (neighborDir < 8);
seed = gridIndex;
if ((local_d8 != 0) && (-1 < GHIDRA_INT(score))) {
uVar6 = score - 3;
if (2 < GHIDRA_INT(local_d8)) {
uVar6 = score;
}
uVar7 = uVar6 - 3;
if (1 < GHIDRA_INT(local_d8)) {
uVar7 = uVar6;
}
if (GHIDRA_INT(uVar7) <= GHIDRA_INT(local_e0)) {
if (uVar7 == local_e0) {
local_cc = gridIndex;
if (local_c4 == candidatesCapacity) {
msvc::vector<unsigned_int>::_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 = uVar7;
if (candidatesBegin == candidatesCapacity) {
msvc::vector<unsigned_int>::_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:
seed = gridIndex;
}
else {
local_cc = gridIndex;
msvc::set<int>::find_node(local_11c,&local_cc);
if (((*GHIDRA_CAST<char *>((local_114 + 0xd)) != '\0') || (GHIDRA_INT(seed) < *GHIDRA_CAST<int *>((local_114 + 0x10)))) ||
(local_114 == *GHIDRA_CAST<int *>(allowedIndices))) goto LAB_009ae755;
}
LAB_009aeab1:
puVar2 = local_c4;
puVar5 = candidatesBegin;
}
}
gridIndex = seed + 1;
gridSlot = gridSlot + 1;
if (0xa8 < gridIndex) {
local_c4 = GHIDRA_CAST<uint32_t *>((GHIDRA_INT(puVar2) - GHIDRA_INT(puVar5) >> 2));
if (local_c4 == GHIDRA_CAST<uint32_t *>(0x0)) {
result = (void *)0x0;
}
else {
seed = *GHIDRA_CAST<uint32_t *>(this);
if (seed == 0) {
KAGE_LogMessage(0x10,GHIDRA_CAST<uint8_t *>("RNG Seed is zero!\n"));
seed = *GHIDRA_CAST<uint32_t *>(this);
if (seed == 0) {
pcVar1 = (code *)swi(3);
result = (void *)(*pcVar1)();
return result;
}
}
seed = seed >> ((uint8_t)*GHIDRA_CAST<uint32_t *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[1])) + 0x1)))) & 0x1f) ^ seed;
seed = seed ^ seed << ((uint8_t)*GHIDRA_CAST<uint32_t *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[2])) + 0x2)))) & 0x1f);
seed = seed ^ seed >> ((uint8_t)*GHIDRA_CAST<uint32_t *>((this + 4)) & 0x1f);
*GHIDRA_CAST<uint32_t *>(this) = seed;
seed = candidatesBegin[seed % GHIDRA_UINT(local_c4)];
uVar6 = GHIDRA_INT(seed) / 0xd;
local_d8 = GHIDRA_INT(seed) % 0xd;
local_e0 = uVar6;
(GHIDRA_CAST<LevelGenerator_Room *>((newRoom)))->LevelGenerator_Room::constructor(local_d8,uVar6,1);
local_8 = CONCAT31((*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(local_8)) + 0x1))),1);
local_7c = 1;
place_room(this,newRoom);
local_f0 = (void *)(*GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x121])) + 0x1)))) +
*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + seed * 4 + 0x14)) * 0x48);
update_room_neighbors(this,local_f0);
local_cc = 0;
seed = local_d8;
do {
if (neighborOffsets[local_cc * 2] + seed < 0xd) {
if (neighborOffsets[local_cc * 2 + 1] + uVar6 < 0xd) {
iVar3 = (neighborOffsets[local_cc * 2 + 1] + uVar6) * 0xd +
neighborOffsets[local_cc * 2] + seed;
if (-1 < iVar3) {
iVar3 = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + iVar3 * 4 + 0x14));
if (-1 < iVar3) {
seed = 0;
iVar3 = *GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x121])) + 0x1)))) + iVar3 * 0x48;
do {
get_door_target_position
(GHIDRA_CAST<int *>(&doorTargetX),GHIDRA_CAST<int *>((iVar3 + 8)),*GHIDRA_CAST<int *>((iVar3 + 0x18)),seed,0)
;
if (((doorTargetX < 0xd) && (doorTargetY < 0xd)) &&
((iVar4 = doorTargetY * 0xd + doorTargetX, -1 < iVar4 &&
((*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(local_104) + iVar4 * 4 + 0x14)) < 0 &&
(uVar6 = GHIDRA_INT((doorTargetY - local_e0)) >> 0x1f,
uVar7 = GHIDRA_INT((doorTargetX - local_d8)) >> 0x1f,
((doorTargetY - local_e0 ^ uVar6) - uVar6) +
((doorTargetX - local_d8 ^ uVar7) - uVar7) == 1)))))) {
if (7 < seed) {
/* WARNING: Subroutine does not return */
msvc::bitset::_Xran();
}
puVar2 = GHIDRA_CAST<uint32_t *>((iVar3 + (seed >> 5) * 4 + 0x1c));
*puVar2 = *puVar2 | 1 << ((uint8_t)seed & 0x1f);
}
seed = seed + 1;
} while (GHIDRA_INT(seed) < 8);
uVar6 = local_e0;
seed = local_d8;
this = local_104;
}
}
}
}
local_cc = local_cc + 1;
} while (local_cc < 8);
FID_conflict__Erase_tree<fuzzer::fuzzer_allocator<msvc::_Tree_node<fuzzer::TracePC::PCTableEntry_const*,void*>_>_>
(local_90,(fuzzer_allocator<msvc::_Tree_node<unsigned_int,void*>_> *)local_90,
*(_Tree_node<unsigned_int,void*> **)(GHIDRA_INT(local_90[0]) + 4));
operator_delete(local_90[0],0x14);
puVar5 = candidatesBegin;
result = local_f0;
}
if (puVar5 != GHIDRA_CAST<uint32_t *>(0x0)) {
seed = GHIDRA_INT(candidatesCapacity) - GHIDRA_INT(puVar5) & 0xfffffffc;
puVar2 = puVar5;
if (0xfff < seed) {
puVar2 = GHIDRA_CAST<uint32_t *>(puVar5[-1]);
seed = seed + 0x23;
if (0x1f < GHIDRA_UINT((GHIDRA_INT(puVar5) + (-4 - GHIDRA_INT(puVar2))))) {
/* WARNING: Subroutine does not return */
_invalid_parameter_noinfo_noreturn();
}
}
operator_delete(puVar2,seed);
}
ExceptionList = local_10;
return result;
}
} while( true );
}
// 009aed50
void LevelGenerator::DetermineBossRoom(int shape, uint32_t *possibleDoors)
{
void *room;
uint8_t isResized;
int iVar1;
int *neighborOffset;
bool isCandidateValid;
int cellIndex;
uint32_t gridY;
uint32_t gridX;
int stepsLeft;
int *candidateIter;
bool isStepFree;
int roomIndex;
candidateIter = *GHIDRA_CAST<int **>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x125])) + 0x1))));
if (candidateIter == *GHIDRA_CAST<int **>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x126])) + 0x2))))) {
return;
}
do {
roomIndex = *candidateIter;
room = (void *)(*GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x121])) + 0x1)))) + roomIndex * 0x48);
if (1 < *GHIDRA_CAST<int *>((*GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x121])) + 0x1)))) + 0x40 + roomIndex * 0x48))) {
gridX = *GHIDRA_CAST<uint32_t *>((GHIDRA_CAST<char *>(room) + 0x28));
gridY = *GHIDRA_CAST<uint32_t *>((GHIDRA_CAST<char *>(room) + 0x2c));
if (*GHIDRA_CAST<char *>((this + 0x130)) != '\0') {
isCandidateValid = true;
stepsLeft = 3;
do {
gridY = gridY + (&DAT_00c5d3e4)[*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(room) + 0x20)) * 2];
gridX = gridX + (&DAT_00c5d3e0)[*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(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 (*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + cellIndex * 4 + 0x14)) != roomIndex) {
if ((0xc < gridX) || (0xc < gridY)) {
iVar1 = -1;
}
if (-1 < *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + iVar1 * 4 + 0x14))) 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)) &&
((cellIndex = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + cellIndex * 4 + 0x14)), -1 < cellIndex &&
(cellIndex != 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) {
*GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x12d])) + 0x1)))) = roomIndex;
memmove(candidateIter,candidateIter + 1,
*GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x126])) + 0x2)))) - GHIDRA_INT((candidateIter + 1)));
*GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x126])) + 0x2)))) = *GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x126])) + 0x2)))) + -4;
return;
}
}
LAB_009aeebf:
candidateIter = candidateIter + 1;
if (candidateIter == *GHIDRA_CAST<int **>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x126])) + 0x2))))) {
return;
}
} while( true );
}
// 009af0e0
void * LevelGenerator::get_all_rooms(void *outRooms)
{
int *indexIter;
int roomPtr [2];
void *local_10;
uint8_t *puStack_c;
uint32_t local_8;
int *outEnd;
puStack_c = &LAB_00b0e2be;
local_10 = ExceptionList;
ExceptionList = &local_10;
*GHIDRA_CAST<uint32_t *>(outRooms) = 0;
*GHIDRA_CAST<uint32_t *>((GHIDRA_CAST<char *>(outRooms) + 4)) = 0;
*GHIDRA_CAST<uint32_t *>((GHIDRA_CAST<char *>(outRooms) + 8)) = 0;
local_8 = 0;
indexIter = *GHIDRA_CAST<int **>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x129])) + 0x1))));
roomPtr[1] = 1;
if (indexIter != *GHIDRA_CAST<int **>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x12a])) + 0x2))))) {
do {
roomPtr[0] = *GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x121])) + 0x1)))) + *indexIter * 0x48;
outEnd = *GHIDRA_CAST<int **>((GHIDRA_CAST<char *>(outRooms) + 4));
if (outEnd == *GHIDRA_CAST<int **>((GHIDRA_CAST<char *>(outRooms) + 8))) {
msvc::vector<4byte>::_Emplace_reallocate(outEnd,roomPtr);
}
else {
*outEnd = roomPtr[0];
*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(outRooms) + 4)) = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(outRooms) + 4)) + 4;
}
indexIter = indexIter + 1;
} while (indexIter != *GHIDRA_CAST<int **>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x12a])) + 0x2)))));
}
indexIter = *GHIDRA_CAST<int **>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x125])) + 0x1))));
if (indexIter != *GHIDRA_CAST<int **>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x126])) + 0x2))))) {
do {
roomPtr[0] = *GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x121])) + 0x1)))) + *indexIter * 0x48;
outEnd = *GHIDRA_CAST<int **>((GHIDRA_CAST<char *>(outRooms) + 4));
if (outEnd == *GHIDRA_CAST<int **>((GHIDRA_CAST<char *>(outRooms) + 8))) {
msvc::vector<4byte>::_Emplace_reallocate(outEnd,roomPtr);
}
else {
*outEnd = roomPtr[0];
*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(outRooms) + 4)) = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(outRooms) + 4)) + 4;
}
indexIter = indexIter + 1;
} while (indexIter != *GHIDRA_CAST<int **>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x126])) + 0x2)))));
}
ExceptionList = local_10;
return outRooms;
}
// 009af1e0
uint32_t LevelGenerator::add_dead_end()
{
uint8_t bVar1;
uint32_t uVar2;
int iVar3;
LevelGenerator *in_ECX;
uint32_t extraout_ECX;
uint32_t extraout_ECX_00;
uint32_t extraout_ECX_01;
uint32_t uVar4;
uint32_t size;
int iVar5;
LevelGenerator_Room *pLVar6;
LevelGenerator_Room *local_24;
LevelGenerator_Room *local_20;
int local_1c;
uint32_t local_14;
void *local_10;
uint8_t *puStack_c;
uint32_t local_8;
local_8 = 0xffffffff;
puStack_c = &LAB_00b0e2ed;
local_10 = ExceptionList;
uVar2 = __security_cookie ^ GHIDRA_INT(register0x00000010) - 4U;
ExceptionList = &local_10;
iVar3 = *GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(in_ECX[0x121])) + 0x1))));
local_14 = 0;
if ((*GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(in_ECX[0x122])) + 0x2)))) - iVar3) / 0x48 != 0) {
iVar5 = 0;
do {
get_neighbor_candidates(in_ECX,&local_24,*GHIDRA_CAST<uint32_t *>((iVar5 + 4 + iVar3)),1);
local_8 = 0;
uVar4 = extraout_ECX;
pLVar6 = local_24;
if (local_24 != local_20) {
do {
bVar1 = can_place_room(in_ECX,GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(pLVar6[2])) + 0x2)))),*GHIDRA_CAST<int *>((pLVar6 + 8)));
uVar4 = extraout_ECX_00;
if ((bVar1 != 0) &&
(iVar3 = count_neighbor_rooms(in_ECX,GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(pLVar6[0xd])) + 0x1))))),
uVar4 = extraout_ECX_01, iVar3 < 2)) {
place_room(in_ECX,pLVar6);
vector_LevelGenerator_Room_tidy(&local_24);
ExceptionList = local_10;
return 1;
}
pLVar6 = pLVar6 + 0x18;
} while (pLVar6 != local_20);
}
local_8 = 0xffffffff;
if (local_24 != GHIDRA_CAST<LevelGenerator_Room *>(0x0)) {
FUN_00752e40(uVar4,uVar2);
size = ((local_1c - GHIDRA_INT(local_24)) / 0x48) * 0x48;
pLVar6 = local_24;
if (0xfff < size) {
pLVar6 = *GHIDRA_CAST<LevelGenerator_Room **>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(local_24[-2])) + 0x2))));
size = size + 0x23;
if (0x1f < GHIDRA_UINT((GHIDRA_INT(local_24) + (-4 - GHIDRA_INT(pLVar6))))) {
/* WARNING: Subroutine does not return */
_invalid_parameter_noinfo_noreturn();
}
}
operator_delete(pLVar6,size);
local_24 = GHIDRA_CAST<LevelGenerator_Room *>(0x0);
local_20 = GHIDRA_CAST<LevelGenerator_Room *>(0x0);
local_1c = 0;
}
iVar3 = *GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(in_ECX[0x121])) + 0x1))));
iVar5 = iVar5 + 0x48;
local_14 = local_14 + 1;
} while (local_14 < GHIDRA_UINT(((*GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(in_ECX[0x122])) + 0x2)))) - iVar3) / 0x48)));
}
ExceptionList = local_10;
return 0;
}
// 009af370
uint8_t LevelGenerator::has_shape_slot(int shape, int doorSlot, uint8_t ignoreThinShapesRestrictions)
{
if ((((*GHIDRA_CAST<int *>((&DAT_00c5d37c + shape * 8)) == 1) && ((doorSlot == 4 || (doorSlot == 6)))) ||
(((*GHIDRA_CAST<int *>((&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)
{
uint32_t uVar1;
int iVar2;
uint8_t isHasSlot;
uint32_t extraout_ECX;
int extraout_EDX;
isHasSlot = has_shape_slot(shape,doorSlot,0);
if (isHasSlot == 0) {
switchD_009af41e_default:
*GHIDRA_CAST<int *>(ret) = g_levelGenInvalidPos[0];
*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(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<int *>((GHIDRA_CAST<char *>(position) + 4));
*GHIDRA_CAST<uint32_t *>(ret) = *GHIDRA_CAST<uint32_t *>(position);
*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(ret) + 4)) = iVar2 + 1;
return ret;
}
uVar1 = *GHIDRA_CAST<uint32_t *>((GHIDRA_CAST<char *>(position) + 4));
*GHIDRA_CAST<uint32_t *>(ret) = *GHIDRA_CAST<uint32_t *>(position);
*GHIDRA_CAST<uint32_t *>((GHIDRA_CAST<char *>(ret) + 4)) = uVar1;
return ret;
case 6:
case 7:
if (((extraout_EDX != 2) && (extraout_EDX != 5)) && (extraout_EDX != 7)) {
uVar1 = *GHIDRA_CAST<uint32_t *>(position);
*GHIDRA_CAST<uint32_t *>((GHIDRA_CAST<char *>(ret) + 4)) = *GHIDRA_CAST<uint32_t *>((GHIDRA_CAST<char *>(position) + 4));
*GHIDRA_CAST<uint32_t *>(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<uint32_t *>(ret) = *GHIDRA_CAST<uint32_t *>(position);
*GHIDRA_CAST<uint32_t *>((GHIDRA_CAST<char *>(ret) + 4)) = *GHIDRA_CAST<uint32_t *>((GHIDRA_CAST<char *>(position) + 4));
return ret;
}
LAB_009af57c:
iVar2 = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(position) + 4));
*GHIDRA_CAST<int *>(ret) = *GHIDRA_CAST<int *>(position) + 1;
*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(ret) + 4)) = iVar2 + 1;
return ret;
}
LAB_009af5bb:
iVar2 = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(position) + 4));
*GHIDRA_CAST<uint32_t *>(ret) = *GHIDRA_CAST<uint32_t *>(position);
*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(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<int *>((GHIDRA_CAST<char *>(position) + 4));
*GHIDRA_CAST<int *>(ret) = *GHIDRA_CAST<int *>(position) + 1;
*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(ret) + 4)) = iVar2 + 1;
return ret;
}
goto LAB_009af5bb;
}
LAB_009af488:
iVar2 = *GHIDRA_CAST<int *>(position);
*GHIDRA_CAST<uint32_t *>((GHIDRA_CAST<char *>(ret) + 4)) = *GHIDRA_CAST<uint32_t *>((GHIDRA_CAST<char *>(position) + 4));
*GHIDRA_CAST<int *>(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<int *>((GHIDRA_CAST<char *>(position) + 4));
*GHIDRA_CAST<int *>(ret) = *GHIDRA_CAST<int *>(position) + 1;
*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(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<uint32_t *>(ret) = *GHIDRA_CAST<uint32_t *>(position);
*GHIDRA_CAST<uint32_t *>((GHIDRA_CAST<char *>(ret) + 4)) = *GHIDRA_CAST<uint32_t *>((GHIDRA_CAST<char *>(position) + 4));
return ret;
}
// 009af980
void LevelGenerator::update_room_neighbors(void *room)
{
uint32_t uVar1;
int iVar2;
uint64_t *findResult;
uint32_t *newNode;
uint32_t doorSlot;
uint8_t findBuf [12];
uint64_t insertHint;
int neighborSetRef;
uint32_t local_24;
uint32_t targetX;
uint32_t targetY;
uint32_t *doorMask;
LevelGenerator *generator;
void *local_10;
uint8_t *puStack_c;
uint32_t local_8;
int *gridCell;
uint32_t setHead;
local_8 = 0xffffffff;
puStack_c = &LAB_00b0e31d;
local_10 = ExceptionList;
uVar1 = __security_cookie ^ GHIDRA_UINT((findBuf + 0x3c));
ExceptionList = &local_10;
doorMask = GHIDRA_CAST<uint32_t *>((GHIDRA_INT(room) + 0x1c));
gridCell = GHIDRA_CAST<int *>((GHIDRA_INT(room) + 0x30));
*doorMask = 0;
iVar2 = *gridCell;
generator = this;
FID_conflict__Erase_tree<fuzzer::fuzzer_allocator<msvc::_Tree_node<fuzzer::TracePC::PCTableEntry_const*,void*>_>_>
(gridCell,(fuzzer_allocator<msvc::_Tree_node<unsigned_int,void*>_> *)gridCell,
*(_Tree_node<unsigned_int,void*> **)(iVar2 + 4));
*GHIDRA_CAST<int *>((iVar2 + 4)) = iVar2;
*GHIDRA_CAST<int *>(iVar2) = iVar2;
*GHIDRA_CAST<int *>((iVar2 + 8)) = iVar2;
doorSlot = 0;
*GHIDRA_CAST<uint32_t *>((GHIDRA_CAST<char *>(room) + 0x34)) = 0;
do {
get_door_target_position
(GHIDRA_CAST<int *>(&targetX),GHIDRA_CAST<int *>((GHIDRA_INT(room) + 8)),*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(room) + 0x18)),doorSlot,0);
if ((((targetX < 0xd) && (targetY < 0xd)) && (iVar2 = targetY * 0xd + targetX, -1 < iVar2)) &&
(gridCell = GHIDRA_CAST<int *>((GHIDRA_INT(generator) + iVar2 * 4 + 0x14)),
-1 < *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(generator) + iVar2 * 4 + 0x14)))) {
if (7 < doorSlot) {
/* WARNING: Subroutine does not return */
msvc::bitset::_Xran();
}
doorMask[doorSlot >> 5] = doorMask[doorSlot >> 5] | 1 << ((uint8_t)doorSlot & 0x1f);
findResult = GHIDRA_CAST<uint64_t *>(std)::set<int>::find_node(findBuf,gridCell);
insertHint = *findResult;
if ((*GHIDRA_CAST<char *>((*GHIDRA_CAST<int *>((findResult + 1)) + 0xd)) != '\0') ||
(*gridCell < *GHIDRA_CAST<int *>((*GHIDRA_CAST<int *>((findResult + 1)) + 0x10)))) {
if (*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(room) + 0x34)) == 0xccccccc) {
/* WARNING: Subroutine does not return */
FUN_004170d0(uVar1);
}
setHead = *GHIDRA_CAST<uint32_t *>((GHIDRA_CAST<char *>(room) + 0x30));
neighborSetRef = GHIDRA_INT(room) + 0x30;
local_8 = 0;
local_24 = 0;
newNode = operator_new(0x14);
local_8 = 0xffffffff;
newNode[4] = *gridCell;
*newNode = setHead;
newNode[1] = setHead;
newNode[2] = setHead;
*GHIDRA_CAST<uint16_t *>((newNode + 3)) = 0;
local_24 = 0;
msvc::_Tree::_Insert_node
((void *)(GHIDRA_INT(room) + 0x30),(void *)insertHint,(*GHIDRA_CAST<uint32_t *>((GHIDRA_CAST<char *>(&(insertHint)) + 0x4))),newNode);
}
}
doorSlot = doorSlot + 1;
} while (GHIDRA_INT(doorSlot) < 8);
*GHIDRA_CAST<uint32_t *>((GHIDRA_CAST<char *>(room) + 0x38)) = *GHIDRA_CAST<uint32_t *>((GHIDRA_CAST<char *>(room) + 0x34));
ExceptionList = local_10;
return;
}
// 009afb10
void LevelGenerator::mark_dead_ends()
{
int iVar1;
int iVar2;
uint32_t uVar3;
uint32_t neighborX;
uint32_t roomIdx;
int roomsBegin;
int roomOffset;
roomIdx = 0;
iVar2 = *GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x122])) + 0x2))));
roomsBegin = *GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x121])) + 0x1))));
iVar1 = iVar2 - roomsBegin >> 0x1f;
if ((iVar2 - roomsBegin) / 0x48 + iVar1 != iVar1) {
roomOffset = 0;
do {
if (roomIdx != 0) {
iVar2 = count_neighbor_rooms(this,GHIDRA_CAST<int *>((roomOffset + 0x28 + roomsBegin)));
if (iVar2 < 2) {
*GHIDRA_CAST<uint8_t *>((roomOffset + 0x3c + roomsBegin)) = 1;
}
}
roomOffset = roomOffset + 0x48;
roomsBegin = *GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x121])) + 0x1))));
roomIdx = roomIdx + 1;
} while (roomIdx < GHIDRA_UINT(((*GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x122])) + 0x2)))) - roomsBegin) / 0x48)));
iVar2 = *GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x122])) + 0x2))));
}
roomIdx = 0;
iVar1 = iVar2 - roomsBegin >> 0x1f;
if ((iVar2 - roomsBegin) / 0x48 + iVar1 != iVar1) {
roomOffset = 0;
do {
if ((roomIdx != 0) &&
((iVar2 = *GHIDRA_CAST<int *>((roomOffset + 0x28 + roomsBegin)), iVar2 != g_levelGenInvalidPos[0] ||
(*GHIDRA_CAST<int *>((roomOffset + 0x2c + roomsBegin)) != g_levelGenInvalidPos[1])))) {
uVar3 = *GHIDRA_CAST<int *>((roomOffset + 0x20 + roomsBegin)) + 2U & 0x80000003;
if (GHIDRA_INT(uVar3) < 0) {
uVar3 = (uVar3 - 1 | 0xfffffffc) + 1;
}
neighborX = iVar2 + (&DAT_00c5d3e0)[uVar3 * 2];
uVar3 = *GHIDRA_CAST<int *>((roomOffset + 0x2c + roomsBegin)) + (&DAT_00c5d3e4)[uVar3 * 2];
if ((neighborX < 0xd) && (uVar3 < 0xd)) {
iVar2 = uVar3 * 0xd + neighborX;
}
else {
iVar2 = -1;
}
iVar2 = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + iVar2 * 4 + 0x14));
if (iVar2 < 0) {
KAGE_LogMessage(0x10,GHIDRA_CAST<uint8_t *>("invalid connecting neighbor\n"));
}
*GHIDRA_CAST<uint8_t *>((*GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x121])) + 0x1)))) + 0x3c + iVar2 * 0x48)) = 0;
}
roomsBegin = *GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x121])) + 0x1))));
roomOffset = roomOffset + 0x48;
roomIdx = roomIdx + 1;
} while (roomIdx < GHIDRA_UINT(((*GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x122])) + 0x2)))) - roomsBegin) / 0x48)));
}
return;
}
// 009afc70
void LevelGenerator::update_dead_end_lists()
{
int iVar1;
uint32_t *puVar2;
int iVar3;
uint32_t roomIndex;
int iVar4;
int roomOffset;
uint32_t indexToPush [2];
*GHIDRA_CAST<uint32_t *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x126])) + 0x2)))) = *GHIDRA_CAST<uint32_t *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x125])) + 0x1))));
*GHIDRA_CAST<uint32_t *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x12a])) + 0x2)))) = *GHIDRA_CAST<uint32_t *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x129])) + 0x1))));
mark_dead_ends(this);
iVar4 = *GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x121])) + 0x1))));
roomIndex = 0;
iVar3 = *GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x122])) + 0x2)))) - iVar4;
iVar1 = iVar3 >> 0x1f;
if (iVar3 / 0x48 + iVar1 != iVar1) {
roomOffset = 0;
do {
update_room_neighbors(this,(void *)(iVar4 + roomOffset));
indexToPush[0] = roomIndex;
if (*GHIDRA_CAST<char *>((iVar4 + roomOffset + 0x3c)) == '\0') {
puVar2 = *GHIDRA_CAST<uint32_t **>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x12a])) + 0x2))));
if (puVar2 == *GHIDRA_CAST<uint32_t **>((this + 300))) goto LAB_009afd26;
*puVar2 = roomIndex;
*GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x12a])) + 0x2)))) = *GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x12a])) + 0x2)))) + 4;
}
else {
puVar2 = *GHIDRA_CAST<uint32_t **>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x126])) + 0x2))));
if (puVar2 == *GHIDRA_CAST<uint32_t **>((this + 0x128))) {
LAB_009afd26:
msvc::vector<unsigned_int>::_Emplace_reallocate(puVar2,indexToPush);
}
else {
*puVar2 = roomIndex;
*GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x126])) + 0x2)))) = *GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x126])) + 0x2)))) + 4;
}
}
iVar4 = *GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x121])) + 0x1))));
roomIndex = roomIndex + 1;
roomOffset = roomOffset + 0x48;
} while (roomIndex < GHIDRA_UINT(((*GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x122])) + 0x2)))) - iVar4) / 0x48)));
}
return;
}
// 009afdb0
int ** LevelGenerator::get_room_placement_offsets(int shape)
{
int threadLocals;
threadLocals = *GHIDRA_CAST<int *>(ThreadLocalStoragePointer);
if (*GHIDRA_CAST<int *>((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<int *>((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<int *>((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<int *>((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<int *>((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<int *>((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<int *>((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<int *>((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<int *>((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<int **>((&PTR_DAT_00c5c4a0 + shape));
}
// 009b0180
uint8_t LevelGenerator::can_place_room(int *gridPos, int shape)
{
uint32_t uVar1;
int **shapeOffsets;
int cellIndex;
int *cellOffset;
int lastRoomCellIndex;
lastRoomCellIndex = *GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x121])) + 0x1))));
if (lastRoomCellIndex != *GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x122])) + 0x2))))) {
uVar1 = *GHIDRA_CAST<int *>((lastRoomCellIndex + 0xc)) - 1;
if ((*GHIDRA_CAST<uint32_t *>((lastRoomCellIndex + 8)) < 0xd) && (uVar1 < 0xd)) {
lastRoomCellIndex = uVar1 * 0xd + *GHIDRA_CAST<uint32_t *>((lastRoomCellIndex + 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<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x130])) + 0x1))) != '\0') && (cellIndex == lastRoomCellIndex)) || (cellIndex < 0))
|| ((-1 < *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + cellIndex * 4 + 0x14)) ||
((&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0xe8])) + 0x0))))[cellIndex] != '\0')))) break;
cellOffset = cellOffset + 2;
}
return 0;
}
// 009b0240
uint8_t LevelGenerator::is_placement_valid(uint32_t *position, uint32_t shape)
{
int iVar1;
int iVar2;
int *neighborDoorTarget;
int doorSlot;
int neighborDoorSlot;
int sourceX;
int sourceY;
uint32_t targetX;
uint32_t targetY;
int neighborDoorPos [3];
doorSlot = 0;
do {
get_door_source_position(&sourceX,position,shape,doorSlot);
get_door_target_position(GHIDRA_CAST<int *>(&targetX),GHIDRA_CAST<int *>(position),shape,doorSlot,1);
iVar1 = sourceY;
if ((((targetX < 0xd) && (targetY < 0xd)) && (iVar2 = targetY * 0xd + targetX, -1 < iVar2)) &&
(iVar2 = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + iVar2 * 4 + 0x14)), -1 < iVar2)) {
if ((sourceX == g_levelGenInvalidPos[0]) && (sourceY == g_levelGenInvalidPos[1])) {
return 0;
}
neighborDoorSlot = 0;
iVar2 = *GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x121])) + 0x1)))) + iVar2 * 0x48;
while ((neighborDoorTarget =
get_door_target_position
(neighborDoorPos,GHIDRA_CAST<int *>((iVar2 + 8)),*GHIDRA_CAST<int *>((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
uint8_t LevelGenerator::place_room(LevelGenerator_Room *room)
{
int **offsetTable;
uint32_t cellY;
uint32_t cellX;
int cellIndex;
int offsetBytes;
int *offsets;
int roomIndex;
LevelGenerator_Room *roomsEnd;
roomsEnd = *GHIDRA_CAST<LevelGenerator_Room **>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x122])) + 0x2))));
roomIndex = (GHIDRA_INT(roomsEnd) - *GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x121])) + 0x1))))) / 0x48;
if (roomsEnd == *GHIDRA_CAST<LevelGenerator_Room **>((this + 0x124))) {
msvc::vector<LevelGenerator_Room>::_Emplace_reallocate(roomsEnd,room);
}
else {
(GHIDRA_CAST<LevelGenerator_Room *>((roomsEnd)))->LevelGenerator_Room::LevelGenerator_Room(room);
*GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x122])) + 0x2)))) = *GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x122])) + 0x2)))) + 0x48;
}
*GHIDRA_CAST<int *>((*GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x122])) + 0x2)))) + -0x44)) = roomIndex;
offsetTable = get_room_placement_offsets(*GHIDRA_CAST<int *>((room + 8)));
if (*GHIDRA_CAST<int *>((room + 8)) != 1) {
KAGE_LogMessage(1,GHIDRA_CAST<uint8_t *>("place_room: shape %d\n"));
}
offsetBytes = 0;
do {
offsets = *offsetTable;
if ((*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(offsets) + offsetBytes)) == g_levelGenInvalidPos[0]) &&
(*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(offsets) + offsetBytes + 4)) == g_levelGenInvalidPos[1])) {
return (char)*GHIDRA_CAST<uint32_t *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0x122])) + 0x2)))) + 0xb8;
}
cellX = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(offsets) + offsetBytes)) + *GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(room[2])) + 0x2))));
cellY = *GHIDRA_CAST<int *>((room + 4)) + *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(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<uint8_t *>("[LevelGenerator] place_room: invalid room\n"));
}
offsetBytes = offsetBytes + 8;
*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + cellIndex * 4 + 0x14)) = roomIndex;
} while( true );
}
// 009b0440
int LevelGenerator::count_neighbor_rooms(int *gridPos)
{
int cellIdx;
int gridX;
int neighborCount;
int *dirOffset;
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)) &&
((cellIdx = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + cellIdx * 4 + 0x14)), -1 < cellIdx &&
(gridX = FUN_009afd70(), cellIdx != *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + gridX * 4 + 0x14)))))) {
neighborCount = neighborCount + 1;
}
dirOffset = dirOffset + 2;
} while (GHIDRA_INT(dirOffset) < 0xc5d400);
return neighborCount;
}
// 009b1220
uint8_t LevelGenerator::try_resize_room(void *room, int roomShape, uint32_t *possibleDoors)
{
uint32_t shapeSizeY;
uint32_t *doorTargetPos;
char isPlacementValid;
int *offset;
uint32_t neighborCount;
int *piVar2;
LevelGenerator *generator;
uint32_t uVar3;
uint32_t doorSlot;
int gridIdx;
uint8_t auStack_114 [7];
char isFits;
int 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;
uint32_t candidateDoorSlots [4];
int spotDoorSlot4;
uint32_t spotDoorSlot5;
int spotDoorSlot6;
uint32_t spotDoorSlot7;
int spotDoorSlot8;
uint32_t spotDoorSlot9;
int spotDoorSlot10;
uint32_t spotDoorSlot11;
uint32_t spotDoorSlot12;
uint32_t local_c;
int cellRoomIdx;
void *resizedRoom;
uint32_t shapeSizeY;
local_c = __security_cookie ^ GHIDRA_UINT(auStack_114);
roomCopy = room;
shapeCopy = roomShape;
cellRoomIdx = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(room) + 0x20));
candidateDoorSlots[0] = cellRoomIdx + 2U & 0x80000003;
if (GHIDRA_INT(candidateDoorSlots[0]) < 0) {
candidateDoorSlots[0] = (candidateDoorSlots[0] - 1 | 0xfffffffc) + 1;
}
if ((cellRoomIdx == 2) || (cellRoomIdx == 3)) {
candidatePositions[2] = 0;
candidatePositions[3] = 0;
}
else {
candidatePositions[3] = (&DAT_00c5d3e4)[cellRoomIdx * 2];
candidatePositions[2] = (&DAT_00c5d3e0)[cellRoomIdx * 2];
}
if ((cellRoomIdx == 0) || (cellRoomIdx == 2)) {
local_c0 = 0;
local_108 = -1;
}
else {
local_c0 = -1;
local_108 = 0;
}
candidatePositions[0] = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(room) + 0x28));
candidatePositions[1] = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(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;
cellRoomIdx = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(room) + 0x20));
if ((cellRoomIdx == 0) || (cellRoomIdx == 2)) {
local_10c = 4;
candidateShapes[1] = 6;
}
else {
candidateShapes[1] = 4;
local_10c = 6;
}
switch(cellRoomIdx) {
case 0:
spotShape6 = 0xc;
spotShape7 = 10;
spotShape8 = 0xb;
spotShape10 = 9;
break;
case 1:
spotShape6 = 0xc;
local_104 = GHIDRA_CAST<int *>(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<int *>(0x3);
spotShape7 = 9;
spotShape8 = 0xb;
spotShape10 = 0xc;
goto LAB_009b1491;
default:
spotShape8 = local_10c;
spotShape10 = local_10c;
spotShape6 = local_10c;
spotShape7 = local_10c;
if ((cellRoomIdx != 0) && (cellRoomIdx != 2)) {
local_104 = GHIDRA_CAST<int *>(0x3);
goto LAB_009b1491;
}
}
local_104 = GHIDRA_CAST<int *>(0x2);
LAB_009b1491:
if ((cellRoomIdx == 0) || (local_108 = 5, cellRoomIdx == 2)) {
local_108 = 7;
}
spotShape2 = local_10c;
spotShape3 = 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];
cellRoomIdx = FUN_009afd70();
if (cellRoomIdx < 0) {
KAGE_LogMessage(0x10,GHIDRA_CAST<uint8_t *>("[LevelGenerator] try_resize_room: invalid room\n"));
}
if ((*GHIDRA_CAST<uint32_t *>((GHIDRA_CAST<char *>(room) + 0x28)) < 0xd) && (*GHIDRA_CAST<uint32_t *>((GHIDRA_CAST<char *>(room) + 0x2c)) < 0xd)) {
cellRoomIdx = *GHIDRA_CAST<uint32_t *>((GHIDRA_CAST<char *>(room) + 0x2c)) * 0xd + *GHIDRA_CAST<uint32_t *>((GHIDRA_CAST<char *>(room) + 0x28));
}
else {
cellRoomIdx = -1;
}
local_104 = candidatePositions;
local_108 = 0;
local_10c = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(generatorCopy) + cellRoomIdx * 4 + 0x14));
cellRoomIdx = shapeCopy;
generator = generatorCopy;
do {
piVar2 = local_104;
if (candidateShapes[local_108] == cellRoomIdx) {
if ((possibleDoors[candidateDoorSlots[local_108] >> 5] &
1 << ((uint8_t)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) {
uVar3 = *piVar2 + offset[-1];
shapeSizeY = *offset + piVar2[1];
if (((0xc < uVar3) ||
((0xc < shapeSizeY || (cellRoomIdx = shapeSizeY * 0xd + uVar3, cellRoomIdx < 0)))) ||
((cellRoomIdx = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(generator) + cellRoomIdx * 4 + 0x14)), -1 < cellRoomIdx &&
(cellRoomIdx != local_10c)))) {
isFits = '\0';
}
}
doorSlot = 0;
uVar3 = 1;
shapeSizeY = 0;
do {
doorTargetPos =
GHIDRA_CAST<uint32_t *>(get_door_target_position)
(GHIDRA_CAST<int *>(local_f0),local_104,candidateShapes[local_108],doorSlot,0);
neighborCount = shapeSizeY;
if ((((*doorTargetPos < 0xd) && (doorTargetPos[1] < 0xd)) &&
(cellRoomIdx = doorTargetPos[1] * 0xd + *doorTargetPos, -1 < cellRoomIdx)) &&
((cellRoomIdx = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(generatorCopy) + cellRoomIdx * 4 + 0x14)), -1 < cellRoomIdx
&& (cellRoomIdx != local_10c)))) {
neighborCount = shapeSizeY + 1;
if (*GHIDRA_CAST<char *>((*GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(generatorCopy[0x121])) + 0x1)))) + 0x44 + cellRoomIdx * 0x48)) !=
'\0') {
neighborCount = shapeSizeY;
}
if ((possibleDoors[doorSlot >> 5] & uVar3) == 0) {
isFits = '\0';
}
}
doorSlot = doorSlot + 1;
uVar3 = uVar3 << 1 | GHIDRA_UINT((GHIDRA_INT(uVar3) < 0));
shapeSizeY = neighborCount;
} while (doorSlot < 8);
isPlacementValid = '\0';
if (neighborCount < 2) {
isPlacementValid = isFits;
}
if (isPlacementValid != '\0') {
local_f0[0] = get_room_placement_offsets(*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(roomCopy) + 0x18)));
generator = generatorCopy;
cellRoomIdx = 0;
break;
}
generator = generatorCopy;
}
cellRoomIdx = shapeCopy;
}
local_108 = local_108 + 1;
local_104 = local_104 + 2;
if (0xd < local_108) {
return 0;
}
} while( true );
LAB_009b1700:
resizedRoom = roomCopy;
piVar2 = GHIDRA_CAST<int *>((GHIDRA_INT(*local_f0[0]) + cellRoomIdx));
if ((*piVar2 == g_levelGenInvalidPos[0]) && (piVar2[1] == g_levelGenInvalidPos[1])) {
for (cellRoomIdx = 0;
(piVar2 = GHIDRA_CAST<int *>((GHIDRA_INT(*newShapeOffsets) + cellRoomIdx)), *piVar2 != g_levelGenInvalidPos[0]
|| (piVar2[1] != g_levelGenInvalidPos[1])); cellRoomIdx = cellRoomIdx + 8) {
if ((GHIDRA_UINT((*piVar2 + candidatePositions[local_108 * 2])) < 0xd) &&
(GHIDRA_UINT((candidatePositions[local_108 * 2 + 1] + piVar2[1])) < 0xd)) {
gridIdx = (candidatePositions[local_108 * 2 + 1] + piVar2[1]) * 0xd +
*piVar2 + candidatePositions[local_108 * 2];
}
else {
gridIdx = -1;
}
*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(generator) + gridIdx * 4 + 0x14)) = local_10c;
}
cellRoomIdx = candidatePositions[local_108 * 2 + 1];
*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(roomCopy) + 8)) = candidatePositions[local_108 * 2];
*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(roomCopy) + 0xc)) = cellRoomIdx;
shapeSizeY = *GHIDRA_CAST<uint32_t *>((&DAT_00c5d37c + shapeCopy * 8));
*GHIDRA_CAST<uint32_t *>((GHIDRA_CAST<char *>(roomCopy) + 0x10)) = *GHIDRA_CAST<uint32_t *>((&DAT_00c5d378 + shapeCopy * 8));
*GHIDRA_CAST<uint32_t *>((GHIDRA_CAST<char *>(roomCopy) + 0x14)) = shapeSizeY;
*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(roomCopy) + 0x18)) = shapeCopy;
local_10c = **GHIDRA_CAST<int **>((GHIDRA_CAST<char *>(roomCopy) + 0x30));
if (GHIDRA_CAST<int *>(local_10c) != *GHIDRA_CAST<int **>((GHIDRA_CAST<char *>(roomCopy) + 0x30))) {
do {
update_room_neighbors
(generator,
(void *)(*GHIDRA_CAST<int *>(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(generator[0x121])) + 0x1)))) + *GHIDRA_CAST<int *>((local_10c + 0x10)) * 0x48)
);
msvc::
_Tree_unchecked_const_iterator<msvc::_Tree_val<msvc::_Tree_simple_types<unsigned_int>_>,msvc::_Iterator_base0>
::operator++((_Tree_unchecked_const_iterator<msvc::_Tree_val<msvc::_Tree_simple_types<unsigned_int>_>,msvc::_Iterator_base0>
*)&local_10c);
} while (local_10c != *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(resizedRoom) + 0x30)));
}
update_room_neighbors(generator,resizedRoom);
return 1;
}
local_104 = GHIDRA_CAST<int *>((*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(roomCopy) + 8)) + *piVar2));
shapeSizeY = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(roomCopy) + 0xc)) + piVar2[1];
if ((local_104 < GHIDRA_CAST<int *>(0xd)) && (shapeSizeY < 0xd)) {
gridIdx = shapeSizeY * 0xd + GHIDRA_INT(local_104);
if (gridIdx < 0) goto LAB_009b1744;
}
else {
gridIdx = -1;
LAB_009b1744:
KAGE_LogMessage(0x10,GHIDRA_CAST<uint8_t *>("[LevelGenerator] try_resize_endroom: invalid room\n"));
}
cellRoomIdx = cellRoomIdx + 8;
*GHIDRA_CAST<uint32_t *>((GHIDRA_CAST<char *>(generator) + gridIdx * 4 + 0x14)) = 0xffffffff;
goto LAB_009b1700;
}
// 009b1860
void LevelGenerator::block_room_area(void *room, int unused)
{
int **placementOffsets;
int *piVar1;
uint32_t cellY;
int gridIndex;
int cellOffset;
uint32_t cellX;
uint32_t neighborOffset;
int *piVar2;
placementOffsets = get_room_placement_offsets(*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(room) + 0x18)));
piVar1 = *placementOffsets;
for (cellOffset = 0;
(*GHIDRA_CAST<int *>((cellOffset + GHIDRA_INT(piVar1))) != g_levelGenInvalidPos[0] ||
(*GHIDRA_CAST<int *>((cellOffset + 4 + GHIDRA_INT(piVar1))) != g_levelGenInvalidPos[1]));
cellOffset = cellOffset + 8) {
neighborOffset = 0;
piVar2 = piVar1;
do {
cellX = *GHIDRA_CAST<int *>((cellOffset + GHIDRA_INT(piVar1))) +
*GHIDRA_CAST<int *>((GHIDRA_INT(&DAT_00c35e9c) + neighborOffset)) + *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(room) + 8));
cellY = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(room) + 0xc)) +
*GHIDRA_CAST<int *>((GHIDRA_INT(&DAT_00c35ea0) + neighborOffset)) + *GHIDRA_CAST<int *>((cellOffset + 4 + GHIDRA_INT(piVar1)))
;
if (((cellX < 0xd) && (cellY < 0xd)) && (gridIndex = cellY * 0xd + cellX, -1 < gridIndex)) {
*GHIDRA_CAST<uint8_t *>((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<uint8_t *>((iVar1 + 0x2b8 + in_ECX)) = 1;
}
return;
}
// 009b1950
void LevelGenerator::block_cells_near_rooms(void *otherLayout, int unused)
{
uint32_t neighbourByteOffset;
uint32_t neighbourY;
int neighbourIndex;
uint32_t neighbourX;
uint32_t x;
int cellIndex;
int y;
uint32_t rowStart;
y = 0;
rowStart = 0;
do {
x = 0;
do {
if (rowStart < 0x9d) {
cellIndex = rowStart + x;
}
else {
cellIndex = -1;
}
neighbourByteOffset = 0;
do {
if ((&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0xe8])) + 0x0))))[cellIndex] != '\0') break;
neighbourX = *GHIDRA_CAST<int *>((GHIDRA_INT(&DAT_00c35e9c) + neighbourByteOffset)) + x;
neighbourY = *GHIDRA_CAST<int *>((GHIDRA_INT(&DAT_00c35ea0) + neighbourByteOffset)) + y;
if ((((neighbourX < 0xd) && (neighbourY < 0xd)) &&
(neighbourIndex = neighbourY * 0xd + neighbourX, -1 < neighbourIndex)) &&
(-1 < *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(otherLayout) + neighbourIndex * 4 + 0x14)))) {
(&(*GHIDRA_CAST<uint8_t *>((GHIDRA_CAST<char *>(&(this[0xe8])) + 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, uint32_t *doorMask)
{
int cellIndex;
uint32_t doorBit;
uint32_t doorSlot;
int cellX;
int cellY;
doorSlot = 0;
doorBit = 1;
do {
if (((doorMask[doorSlot >> 5] & doorBit) == 0) &&
((get_door_target_position
(&cellX,GHIDRA_CAST<int *>((GHIDRA_INT(room) + 8)),*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(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<uint8_t *>((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(uint32_t *param_1)
{
uint32_t uVar1;
int iVar2;
void *pvVar3;
int in_ECX;
int iVar4;
uint32_t uVar5;
uVar5 = *GHIDRA_CAST<uint32_t *>((in_ECX + 0xc));
if (((uVar5 & 3) == 0) && (*GHIDRA_CAST<uint32_t *>((in_ECX + 8)) <= *GHIDRA_CAST<int *>((in_ECX + 0x10)) + 4U >> 2)) {
msvc::deque<4byte>::_Growmap(in_ECX);
uVar5 = *GHIDRA_CAST<uint32_t *>((in_ECX + 0xc));
}
uVar1 = *GHIDRA_CAST<int *>((in_ECX + 8)) * 4;
uVar5 = uVar1 - 1 & uVar5;
*GHIDRA_CAST<uint32_t *>((in_ECX + 0xc)) = uVar5;
if (uVar5 == 0) {
uVar5 = uVar1;
}
uVar5 = uVar5 - 1;
iVar2 = (*GHIDRA_CAST<int *>((in_ECX + 8)) - 1U & uVar5 >> 2) * 4;
iVar4 = *GHIDRA_CAST<int *>((in_ECX + 4));
if (*GHIDRA_CAST<int *>((iVar4 + iVar2)) == 0) {
pvVar3 = operator_new(0x10);
*(void **)(iVar2 + *GHIDRA_CAST<int *>((in_ECX + 4))) = pvVar3;
iVar4 = *GHIDRA_CAST<int *>((in_ECX + 4));
}
*GHIDRA_CAST<uint32_t *>((*GHIDRA_CAST<int *>((iVar2 + iVar4)) + (uVar5 & 3) * 4)) = *param_1;
*GHIDRA_CAST<int *>((in_ECX + 0x10)) = *GHIDRA_CAST<int *>((in_ECX + 0x10)) + 1;
*GHIDRA_CAST<uint32_t *>((in_ECX + 0xc)) = uVar5;
return;
}