Reconstruction layout: generated-src/ (generated) and src/ (curated), CMake, the first takeover: RNG

The decompiled C++ tree moves to generated-src/ (classes.h, C++20); src/ is for code written by hand. A curated function
defines the generated declaration and starts its comment with its address, and source_tree.py stops emitting that body.
src/rng.cpp takes over RNG (SetSeed, the constructor, Next, RandomInt, RandomFloat, Shuffle) with the shift table read
from the exe as a constexpr array; src/log.h names KAGE_LogMessage's levels (1 INFO, 2 NET, 4 WARN, 8 ERROR, 16 ASSERT,
from its prefix jump table). CMakeLists.txt builds src/*.cpp against generated-src/classes.h (clean with -Wall -Wextra).
structs.hpp and headers.py are retired: scripts/merge_fields.py writes the merged field list, classes.h checks the layout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-11-19 21:10:23 -05:00
1 parent 2ff2d5d87f
commit 3ce74c6e2d
331 files changed
+485 -7835

No files matched your search

+388
View File
@@ -0,0 +1,388 @@
#include "classes.h"
// 0099bad0
void GridEntity_Stairs::BeginBatches()
{
byte bVar1;
byte *curAnimName;
byte extraout_CL;
byte extraout_CL_00;
byte extraout_CL_01;
byte extraout_CL_02;
char *pcVar2;
uint uVar3;
bool isLess;
undefined4 local_3c;
undefined4 local_38;
undefined4 local_34;
undefined4 local_30;
undefined1 local_2c [8];
float local_24;
float local_20;
uint pathSize;
uint local_18;
uint local_14;
void *local_10;
undefined1 *puStack_c;
undefined4 local_8;
byte *animData;
ANM2 *sprite;
local_8 = 0xffffffff;
puStack_c = &LAB_00afcc05;
local_10 = ExceptionList;
local_14 = __security_cookie ^ GHIDRA_UINT((local_2c + 0x28));
ExceptionList = &local_10;
pathSize = 0;
if ((*GHIDRA_CAST<uint *>((*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(g_game->_room) + 4)) + 0x44)) >> 0xd & 1) == 0) {
sprite = &this->_sprite;
local_18 = 0xf;
local_2c[0] = '\0';
local_2c[1] = '\0';
local_2c[2] = '\0';
local_2c[3] = '\0';
(*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(&(local_2c)) + 0x0))) = std::_Allocate(0x30);
pathSize = 0x24;
local_18 = 0x2f;
builtin_strncpy((*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(&(GHIDRA_CAST<char *>(local_2c))) + 0x0))),"gfx/grid/door_20_secrettrapdoor.anm2",0x25);
local_8 = 0;
(GHIDRA_CAST<ANM2 *>((sprite)))->ANM2::Load(GHIDRA_CAST<std_string *>(local_2c),0);
local_8 = 0xffffffff;
bVar1 = extraout_CL;
if (0xf < local_18) {
uVar3 = local_18 + 1;
pcVar2 = (*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(&(GHIDRA_CAST<char *>(local_2c))) + 0x0)));
if (0xfff < uVar3) {
pcVar2 = *GHIDRA_CAST<char **>(((*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(&(local_2c)) + 0x0))) + -4));
uVar3 = local_18 + 0x24;
if (GHIDRA_CAST<char *>(0x1f) < GHIDRA_CAST<char *>(((*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(&(local_2c)) + 0x0))) + (-4 - GHIDRA_INT(pcVar2))))) {
/* WARNING: Subroutine does not return */
_invalid_parameter_noinfo_noreturn();
}
}
operator_delete(pcVar2,uVar3);
bVar1 = extraout_CL_00;
}
(this->_desc)._state = 0;
if ((this->_desc)._variant == 2) {
(*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(&(local_2c)) + 0x0))) = std::_Allocate(0x30);
pathSize = 0x20;
local_18 = 0x2f;
builtin_strncpy((*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(&(GHIDRA_CAST<char *>(local_2c))) + 0x0))),"gfx/grid/secretshop_trapdoor.png",0x21);
local_8 = 1;
(GHIDRA_CAST<Sprite *>((GHIDRA_CAST<Sprite *>(sprite))))->Sprite::ReplaceSpritesheet(0,GHIDRA_CAST<std_string *>(local_2c));
local_8 = 0xffffffff;
bVar1 = extraout_CL_01;
if (0xf < local_18) {
uVar3 = local_18 + 1;
pcVar2 = (*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(&(GHIDRA_CAST<char *>(local_2c))) + 0x0)));
if (0xfff < uVar3) {
pcVar2 = *GHIDRA_CAST<char **>(((*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(&(local_2c)) + 0x0))) + -4));
uVar3 = local_18 + 0x24;
if (GHIDRA_CAST<char *>(0x1f) < GHIDRA_CAST<char *>(((*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(&(local_2c)) + 0x0))) + (-4 - GHIDRA_INT(pcVar2))))) {
/* WARNING: Subroutine does not return */
_invalid_parameter_noinfo_noreturn();
}
}
operator_delete(pcVar2,uVar3);
bVar1 = extraout_CL_02;
}
}
(GHIDRA_CAST<ANM2 *>((sprite)))->ANM2::LoadGraphics(bVar1);
animData = (this->_sprite)._animState._animData;
if (animData != GHIDRA_CAST<byte *>(0x0)) {
curAnimName = animData;
if (0xf < *GHIDRA_CAST<uint *>((animData + 0x14))) {
curAnimName = *GHIDRA_CAST<byte **>(animData);
}
pcVar2 = "Closed";
do {
bVar1 = *curAnimName;
isLess = bVar1 < (byte)*pcVar2;
if (bVar1 != *pcVar2) {
LAB_0099bcf0:
uVar3 = -GHIDRA_UINT(isLess) | 1;
goto LAB_0099bcf5;
}
if (bVar1 == 0) break;
bVar1 = curAnimName[1];
isLess = bVar1 < (byte)pcVar2[1];
if (bVar1 != pcVar2[1]) goto LAB_0099bcf0;
curAnimName = curAnimName + 2;
pcVar2 = pcVar2 + 2;
} while (bVar1 != 0);
uVar3 = 0;
LAB_0099bcf5:
if (uVar3 == 0) {
if (animData[0x34] == 0) {
ExceptionList = local_10;
return;
}
if ((this->_sprite)._animState._isPlaying != 0) {
ExceptionList = local_10;
return;
}
}
}
bVar1 = (GHIDRA_CAST<ANM2 *>((sprite)))->ANM2::SetAnimation(GHIDRA_CAST<byte *>("Closed"),1);
if (bVar1 != 0) {
(GHIDRA_CAST<AnimationState *>((&(this->_sprite)._animState)))->AnimationState::Rewind();
(this->_sprite)._animState._isPlaying = 1;
}
}
else {
local_3c = 0;
local_38 = 0;
local_34 = 0;
local_30 = 0;
(*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(&(local_2c)) + 0x0))) = g_vectorZero.x;
(*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(&(local_2c)) + 0x4))) = g_vectorZero.y;
local_24 = g_vectorZero.x;
local_20 = g_vectorZero.y;
local_18 = 0;
this->Destroy(1,&local_3c,local_14);
}
ExceptionList = local_10;
return;
}
// 0099bd50
void GridEntity_Stairs::Update()
{
qword qVar1;
byte bVar2;
byte *curAnimChar;
int returnRoomIdx;
char cVar3;
uint extraout_ECX;
undefined4 extraout_ECX_00;
char *expectedName;
uint uVar4;
qword *allocatedBytes;
Game *game;
bool isLess;
float fVar5;
float deltaX;
double dVar6;
int iVar7;
EntityList_EL nearbyEntities;
Vector stairsPos;
Vector local_24;
float playerDistance;
float local_18;
char isGreedLocked;
void *local_10;
undefined1 *puStack_c;
undefined4 local_8;
int gridWidth;
local_8 = 0xffffffff;
puStack_c = &LAB_00b0d94d;
local_10 = ExceptionList;
ExceptionList = &local_10;
if ((((g_game->_difficulty != 2) && (g_game->_difficulty != 3)) ||
(*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(g_game->_room) + 8)) != 1)) ||
(isGreedLocked = '\x01', (*GHIDRA_CAST<byte *>((*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(g_game->_room) + 4)) + 0x44)) & 1) != 0)) {
isGreedLocked = '\0';
}
iVar7 = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(g_game->_room) + 0xc));
local_24.x = (float)(this->_gridIndex % iVar7) * 40.0 + 40.0;
local_24.y = (float)(this->_gridIndex / iVar7) * 40.0 + 120.0;
local_24.y = (float)Game::GetNearestPlayerEx(&local_24,1,0,0);
local_18 = (float)(extraout_ECX & 0xffffff00);
playerDistance = 1e+09;
if (GHIDRA_CAST<Entity_Player *>(local_24.y) != GHIDRA_CAST<Entity_Player *>(0x0)) {
iVar7 = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(g_game->_room) + 0xc));
deltaX = ((float)(this->_gridIndex % iVar7) * 40.0 + 40.0) -
((GHIDRA_CAST<Entity_Player *>(local_24.y))->_pos).x;
fVar5 = ((float)(this->_gridIndex / iVar7) * 40.0 + 120.0) -
((GHIDRA_CAST<Entity_Player *>(local_24.y))->_pos).y;
playerDistance = sqrtf(fVar5 * fVar5 + deltaX * deltaX);
local_18 = (float)CONCAT31((int3)(GHIDRA_UINT(extraout_ECX_00) >> 8),playerDistance < 50.0);
}
iVar7 = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(g_game->_room) + 0xc));
stairsPos.x = (float)(this->_gridIndex % iVar7) * 40.0 + 40.0;
stairsPos.y = (float)(this->_gridIndex / iVar7) * 40.0 + 120.0;
EntityList::QueryRadius
(GHIDRA_CAST<EntityList *>((GHIDRA_INT(g_game->_room) + 0x1218)),&nearbyEntities,&stairsPos,20.0,1);
game = g_game;
cVar3 = SUB41(local_18,0);
uVar4 = 0;
local_8 = 0;
fVar5 = local_18;
if (nearbyEntities._size != 0) {
do {
cVar3 = SUB41(fVar5,0);
if (cVar3 != '\0') break;
iVar7 = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(nearbyEntities._data) + uVar4 * 4));
if ((*GHIDRA_CAST<int *>((iVar7 + 0x28)) == 3) &&
(fVar5 = (float)(GHIDRA_UINT(fVar5) & 0xff), *GHIDRA_CAST<int *>((iVar7 + 0x2c)) == 900)) {
fVar5 = 1.4013e-45;
}
cVar3 = SUB41(fVar5,0);
uVar4 = uVar4 + 1;
} while (uVar4 < GHIDRA_UINT(nearbyEntities._size));
}
if (((*GHIDRA_CAST<byte *>((*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(g_game->_room) + 4)) + 0x44)) & 1) == 0) || (cVar3 != '\0')) {
if ((this->_sprite)._animState._animData != (void *)0x0) {
local_18 = (this->_sprite)._animState._animFrame;
dVar6 = floor((double)local_18);
local_18 = (float)dVar6;
if (9 < GHIDRA_INT(dVar6)) goto LAB_0099bf89;
}
LAB_0099c032:
curAnimChar = (this->_sprite)._animState._animData;
if (curAnimChar == GHIDRA_CAST<byte *>(0x0)) {
LAB_0099c083:
bVar2 = (GHIDRA_CAST<ANM2 *>((&this->_sprite)))->ANM2::SetAnimation(GHIDRA_CAST<byte *>("Closed"),1);
if (bVar2 != 0) {
(GHIDRA_CAST<AnimationState *>((&(this->_sprite)._animState)))->AnimationState::Rewind();
(this->_sprite)._animState._isPlaying = 1;
}
game = g_game;
}
else {
if (0xf < *GHIDRA_CAST<uint *>((curAnimChar + 0x14))) {
curAnimChar = *GHIDRA_CAST<byte **>(curAnimChar);
}
expectedName = "Closed";
do {
bVar2 = *curAnimChar;
isLess = bVar2 < (byte)*expectedName;
if (bVar2 != *expectedName) {
LAB_0099c068:
uVar4 = -GHIDRA_UINT(isLess) | 1;
goto LAB_0099c06d;
}
if (bVar2 == 0) break;
bVar2 = curAnimChar[1];
isLess = bVar2 < (byte)expectedName[1];
if (bVar2 != expectedName[1]) goto LAB_0099c068;
curAnimChar = curAnimChar + 2;
expectedName = expectedName + 2;
} while (bVar2 != 0);
uVar4 = 0;
LAB_0099c06d:
if ((uVar4 != 0) ||
((*GHIDRA_CAST<char *>((GHIDRA_INT((this->_sprite)._animState._animData) + 0x34)) != '\0' &&
((this->_sprite)._animState._isPlaying == 0)))) goto LAB_0099c083;
}
(this->_desc)._state = 0;
}
else {
LAB_0099bf89:
if (isGreedLocked != '\0') goto LAB_0099c032;
curAnimChar = (this->_sprite)._animState._animData;
if (curAnimChar == GHIDRA_CAST<byte *>(0x0)) {
LAB_0099bfeb:
bVar2 = (GHIDRA_CAST<ANM2 *>((&this->_sprite)))->ANM2::SetAnimation(GHIDRA_CAST<byte *>("Open Animation"),1);
if (bVar2 != 0) {
(GHIDRA_CAST<AnimationState *>((&(this->_sprite)._animState)))->AnimationState::Rewind();
(this->_sprite)._animState._isPlaying = 1;
}
game = g_game;
}
else {
if (0xf < *GHIDRA_CAST<uint *>((curAnimChar + 0x14))) {
curAnimChar = *GHIDRA_CAST<byte **>(curAnimChar);
}
expectedName = "Open Animation";
do {
bVar2 = *curAnimChar;
isLess = bVar2 < (byte)*expectedName;
if (bVar2 != *expectedName) {
LAB_0099bfd0:
uVar4 = -GHIDRA_UINT(isLess) | 1;
goto LAB_0099bfd5;
}
if (bVar2 == 0) break;
bVar2 = curAnimChar[1];
isLess = bVar2 < (byte)expectedName[1];
if (bVar2 != expectedName[1]) goto LAB_0099bfd0;
curAnimChar = curAnimChar + 2;
expectedName = expectedName + 2;
} while (bVar2 != 0);
uVar4 = 0;
LAB_0099bfd5:
if ((uVar4 != 0) ||
((*GHIDRA_CAST<char *>((GHIDRA_INT((this->_sprite)._animState._animData) + 0x34)) != '\0' &&
((this->_sprite)._animState._isPlaying == 0)))) goto LAB_0099bfeb;
}
if (((this->_sprite)._animState._animData == (void *)0x0) ||
((this->_sprite)._animState._isPlaying == 0)) {
(this->_desc)._state = 1;
}
}
if ((((GHIDRA_CAST<Entity_Player *>(local_24.y) != GHIDRA_CAST<Entity_Player *>(0x0)) && (playerDistance < 21.0)) &&
((this->_desc)._state == 1)) &&
(((*GHIDRA_CAST<byte *>((GHIDRA_CAST<char *>(local_24.y) + 0x1398)) == 0 && (*GHIDRA_CAST<byte *>((GHIDRA_CAST<char *>(local_24.y) + 0x139a)) == 0)) ||
((*GHIDRA_CAST<EntityPtr *>((GHIDRA_CAST<char *>(local_24.y) + 0x1410)) != (EntityPtr)0x0 &&
(*GHIDRA_CAST<EntityPtr *>((GHIDRA_CAST<char *>(local_24.y) + 0x1410)) == *GHIDRA_CAST<EntityPtr *>((GHIDRA_CAST<char *>(local_24.y) + 0x1e68)))))))) {
switch((this->_desc)._variant) {
case 0:
iVar7 = -4;
break;
case 1:
iVar7 = -0xb;
break;
case 2:
iVar7 = -0xd;
break;
case 3:
Game::StartRoomTransition(game,game->_startingRoomIdx,-1,2,GHIDRA_CAST<Entity_Player *>(local_24.y),-1);
goto LAB_0099c224;
default:
goto LAB_0099c12a;
}
Game::StartRoomTransition(game,iVar7,-1,2,GHIDRA_CAST<Entity_Player *>(local_24.y),-1);
game = g_game;
LAB_0099c12a:
fVar5 = g_vectorZero.y;
local_24.y = (float)game->_currentRoomIdx;
returnRoomIdx = game->_lastRoomIdx;
if (GHIDRA_INT(local_24.y) < 0) {
(game->_dungeonReturnPosition).x = g_vectorZero.x;
(game->_dungeonReturnPosition).y = fVar5;
if (returnRoomIdx < -0x13) {
returnRoomIdx = -0x14;
}
else if (0xa7 < returnRoomIdx) {
returnRoomIdx = 0xa8;
}
}
else {
iVar7 = this->_gridIndex;
gridWidth = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(game->_room) + 0xc));
returnRoomIdx = GHIDRA_INT(GHIDRA_CAST<Entity_Player *>(0xa8));
if (GHIDRA_INT(local_24.y) < 0xa8) {
returnRoomIdx = GHIDRA_INT(local_24.y);
}
(game->_dungeonReturnPosition).x = (float)(iVar7 % gridWidth) * 40.0 + 40.0;
(game->_dungeonReturnPosition).y = (float)(iVar7 / gridWidth) * 40.0 + 120.0;
}
game->_dungeonReturnRoomIndex = returnRoomIdx;
}
if ((this->_sprite)._loaded != 0) {
(GHIDRA_CAST<AnimationState *>((&(this->_sprite)._animState)))->AnimationState::Update();
(GHIDRA_CAST<AnimationState *>((&(this->_sprite)._overlayAnimState)))->AnimationState::Update();
}
LAB_0099c224:
if ((*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(nearbyEntities)) + 0x0))) == '\0') {
if (g_mainHeap == (void *)0x0) {
allocatedBytes = &g_allocatedBytesNoHeap;
}
else {
allocatedBytes = GHIDRA_CAST<qword *>((GHIDRA_INT(g_mainHeap) + 0x30));
}
if (nearbyEntities._data != (void *)0x0) {
uVar4 = *GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(nearbyEntities._data) + -4));
qVar1 = *allocatedBytes;
*GHIDRA_CAST<uint *>(allocatedBytes) = GHIDRA_UINT(*allocatedBytes) - uVar4;
*GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(allocatedBytes) + 4)) =
*GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(allocatedBytes) + 4)) - GHIDRA_UINT((GHIDRA_UINT(qVar1) < uVar4));
free((void *)(GHIDRA_INT(nearbyEntities._data) + -4));
}
}
ExceptionList = local_10;
return;
}