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

+334
View File
@@ -0,0 +1,334 @@
#include "classes.h"
// 0041bb50
void CellSpace::insert(Entity *entity)
{
float fVar1;
int cellY;
int minCellX;
int maxCellX;
int cellY;
int maxCellY;
float fVar3;
float cosAngle;
float fVar4;
float fVar5;
float fVar6;
float fVar7;
int cellX;
fVar3 = (entity->_sizeMulti).x;
cosAngle = (entity->_sizeMulti).y;
fVar4 = (entity->_pos).x;
fVar1 = (entity->_pos).y;
fVar6 = fVar3 * entity->_size;
fVar5 = cosAngle * entity->_size;
if (((fVar3 != g_vectorOne.x) || (cosAngle != g_vectorOne.y)) &&
(fVar3 = (entity->_sprite)._rotation, fVar3 != 0.0)) {
fVar3 = fVar3 * 0.017453292;
cosAngle = cos(fVar3);
fVar3 = sin(fVar3);
fVar7 = fVar5 * fVar3;
fVar5 = ABS(fVar5 * cosAngle) + ABS(fVar6 * fVar3);
fVar6 = ABS(fVar7) + ABS(fVar6 * cosAngle);
}
cosAngle = fVar4 - fVar6;
fVar6 = fVar6 + fVar4;
fVar3 = fVar1 - fVar5;
fVar5 = fVar5 + fVar1;
if ((fVar6 <= cosAngle) || (fVar5 <= fVar3)) {
KAGE_LogMessage(0x10,(byte *)
"Entity Teleport Detected! Type: %d, Variant: %d, Subtype: %d; Pos: %f, %f; Size: %f, %f\n"
);
}
fVar4 = *GHIDRA_CAST<float *>((GHIDRA_CAST<char *>(this) + 0x14));
cellY = GHIDRA_INT((fVar3 / fVar4));
maxCellY = GHIDRA_INT((fVar5 / fVar4));
if (((maxCellY < cellY) || (cellY + 1 <= cellY)) || (maxCellY + 1 <= maxCellY)) {
KAGE_LogMessage(0x10,GHIDRA_CAST<byte *>("CellSpace::insert: y1 > y2\n"));
fVar4 = *GHIDRA_CAST<float *>((GHIDRA_CAST<char *>(this) + 0x14));
}
minCellX = GHIDRA_INT((cosAngle / fVar4));
maxCellX = GHIDRA_INT((fVar6 / fVar4));
if (((maxCellX < minCellX) || (minCellX + 1 <= minCellX)) || (maxCellX + 1 <= maxCellX)) {
KAGE_LogMessage(0x10,GHIDRA_CAST<byte *>("CellSpace::insert: x1 > x2\n"));
}
for (; cellX = minCellX, cellY <= maxCellY; cellY = cellY + 1) {
for (; cellX <= maxCellX; cellX = cellX + 1) {
cellY = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + 0xc)) * cellY + cellX;
if ((-1 < cellY) && (cellY < (*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + 0x1c)) - *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + 0x18))) / 0xa4)
) {
cellY = cellY * 0xa4 + *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + 0x18));
if (*GHIDRA_CAST<int *>((cellY + 0xa0)) < 0x28) {
*GHIDRA_CAST<Entity **>((cellY + *GHIDRA_CAST<int *>((cellY + 0xa0)) * 4)) = entity;
*GHIDRA_CAST<int *>((cellY + 0xa0)) = *GHIDRA_CAST<int *>((cellY + 0xa0)) + 1;
}
}
}
}
return;
}
// 0041bdf0
void CellSpace::collide_entity(Entity *entity)
{
int iVar1;
Entity *this_00;
int iVar2;
uint pairWord;
int iVar3;
uint pairIndex;
float radiusY;
float cellSize;
float radiusX;
float right;
float bottom;
int row;
uint slot;
int column;
int highIndex;
int ownIndex;
int pairStride;
float posX;
float posY;
if (entity->_entityCollisionClass != 0) {
posX = (entity->_pos).x;
radiusX = entity->_size * (entity->_sizeMulti).x;
iVar1 = *GHIDRA_CAST<int *>(this);
radiusY = entity->_size * (entity->_sizeMulti).y;
cellSize = *GHIDRA_CAST<float *>((GHIDRA_CAST<char *>(this) + 0x14));
right = radiusX + posX;
pairStride = *GHIDRA_CAST<int *>((iVar1 + 0xd4));
posY = (entity->_pos).y;
bottom = radiusY + posY;
row = GHIDRA_INT(((posY - radiusY) / cellSize));
if (row <= GHIDRA_INT((bottom / cellSize))) {
do {
column = GHIDRA_INT(((posX - radiusX) / cellSize));
if (column <= GHIDRA_INT((right / cellSize))) {
do {
iVar3 = column + *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + 0xc)) * row;
if ((-1 < iVar3) &&
(iVar3 < (*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + 0x1c)) - *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + 0x18))) / 0xa4)) {
slot = 0;
iVar3 = iVar3 * 0xa4 + *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + 0x18));
if (*GHIDRA_CAST<int *>((iVar3 + 0xa0)) != 0) {
do {
this_00 = *GHIDRA_CAST<Entity **>((iVar3 + slot * 4));
ownIndex = entity->_collisionIndex;
iVar2 = this_00->_collisionIndex;
highIndex = iVar2;
if (iVar2 < ownIndex) {
highIndex = ownIndex;
}
if (ownIndex < iVar2) {
iVar2 = ownIndex;
}
pairIndex = highIndex * pairStride + iVar2;
if ((this_00 != entity) && (GHIDRA_INT(pairIndex) < *GHIDRA_CAST<int *>((iVar1 + 0xd0)))) {
pairWord = pairIndex >> 5;
if ((*GHIDRA_CAST<uint *>((*GHIDRA_CAST<int *>((iVar1 + 0xc4)) + pairWord * 4)) &
1 << (sbyte)(pairIndex & 0x1f)) == 0) {
if (((((this_00->_sizeMulti).x == g_vectorOne.x) &&
((this_00->_sizeMulti).y == g_vectorOne.y)) &&
((entity->_sizeMulti).x == g_vectorOne.x)) &&
((entity->_sizeMulti).y == g_vectorOne.y)) {
(GHIDRA_CAST<Entity *>((this_00)))->Entity::push_apart_circle(entity);
}
else {
(GHIDRA_CAST<Entity *>((this_00)))->Entity::push_apart_capsule(entity);
}
_DAT_00c71650 = _DAT_00c71650 + 1;
*GHIDRA_CAST<uint *>((*GHIDRA_CAST<int *>((iVar1 + 0xc4)) + pairWord * 4)) =
*GHIDRA_CAST<uint *>((*GHIDRA_CAST<int *>((iVar1 + 0xc4)) + pairWord * 4)) |
1 << (pairIndex & 0x1f);
}
}
slot = slot + 1;
} while (slot < *GHIDRA_CAST<uint *>((iVar3 + 0xa0)));
}
}
cellSize = *GHIDRA_CAST<float *>((GHIDRA_CAST<char *>(this) + 0x14));
column = column + 1;
} while (column <= GHIDRA_INT((right / cellSize)));
}
row = row + 1;
} while (row <= GHIDRA_INT((bottom / cellSize)));
}
}
return;
}
// 0041c070
void CellSpace::collide(void *entityB)
{
void *entityA = this;
int iVar1;
int owner;
int pairStride;
uint pairIndex;
uint otherSlot;
undefined4 *entitySlot;
uint slot;
uint cellIndex;
int cellOffset;
uint *cellEntityCount;
Entity *entityA;
Entity *entityB;
int maxIndex;
int owner;
uint pairBits;
int pairStride;
owner = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(entityA) + 0x1c));
if ((owner - *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(entityA) + 0x18))) / 0xa4 !=
(*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(entityB) + 0x1c)) - *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(entityB) + 0x18))) / 0xa4) {
KAGE_LogMessage(0x10,GHIDRA_CAST<byte *>("CellSpace::collide - cell counts don\'t match!\n"));
owner = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(entityA) + 0x1c));
}
owner = *GHIDRA_CAST<int *>(entityA);
pairStride = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(entityA) + 0x18));
cellIndex = 0;
pairStride = *GHIDRA_CAST<int *>((owner + 0xd4));
iVar1 = owner - pairStride >> 0x1f;
if ((owner - pairStride) / 0xa4 + iVar1 != iVar1) {
cellOffset = 0;
do {
entitySlot = GHIDRA_CAST<undefined4 *>((cellOffset + pairStride));
slot = 0;
owner = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(entityB) + 0x18)) + cellOffset;
cellEntityCount = entitySlot + 0x28;
if (*cellEntityCount != 0) {
do {
otherSlot = 0;
if (*GHIDRA_CAST<int *>((owner + 0xa0)) != 0) {
do {
entityA = GHIDRA_CAST<Entity *>(*entitySlot);
entityB = *GHIDRA_CAST<Entity **>((owner + otherSlot * 4));
pairStride = entityA->_collisionIndex;
iVar1 = entityB->_collisionIndex;
maxIndex = pairStride;
if (pairStride < iVar1) {
maxIndex = iVar1;
}
if (iVar1 < pairStride) {
pairStride = iVar1;
}
pairIndex = maxIndex * pairStride + pairStride;
if ((entityA != entityB) && (GHIDRA_INT(pairIndex) < *GHIDRA_CAST<int *>((owner + 0xd0)))) {
pairBits = *GHIDRA_CAST<uint *>((*GHIDRA_CAST<int *>((owner + 0xc4)) + (pairIndex >> 5) * 4));
if ((pairBits & 1 << (sbyte)(pairIndex & 0x1f)) == 0) {
*GHIDRA_CAST<uint *>((*GHIDRA_CAST<int *>((owner + 0xc4)) + (pairIndex >> 5) * 4)) =
pairBits | 1 << (pairIndex & 0x1f);
if (((((entityA->_sizeMulti).x == g_vectorOne.x) &&
((entityA->_sizeMulti).y == g_vectorOne.y)) &&
((entityB->_sizeMulti).x == g_vectorOne.x)) &&
((entityB->_sizeMulti).y == g_vectorOne.y)) {
(GHIDRA_CAST<Entity *>((entityA)))->Entity::push_apart_circle(entityB);
}
else {
(GHIDRA_CAST<Entity *>((entityA)))->Entity::push_apart_capsule(entityB);
}
_DAT_00c71650 = _DAT_00c71650 + 1;
}
}
otherSlot = otherSlot + 1;
} while (otherSlot < *GHIDRA_CAST<uint *>((owner + 0xa0)));
}
slot = slot + 1;
entitySlot = entitySlot + 1;
} while (slot < *cellEntityCount);
}
cellIndex = cellIndex + 1;
cellOffset = cellOffset + 0xa4;
pairStride = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(entityA) + 0x18));
} while (cellIndex < GHIDRA_UINT(((*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(entityA) + 0x1c)) - pairStride) / 0xa4)));
}
return;
}
// 0041c2a0
void CellSpace::collide_self()
{
void *first = this;
undefined4 *puVar1;
Entity *other;
int owner;
uint uVar3;
uint j;
int iVar4;
bool bVar5;
undefined4 *firstSlot;
int cellOffset;
uint i;
uint cellIndex;
Entity *first;
int highIndex;
int owner;
int pairStride;
uint pairWord;
cellIndex = 0;
owner = *GHIDRA_CAST<int *>(first);
iVar4 = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(first) + 0x18));
highIndex = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(first) + 0x1c)) - iVar4;
pairStride = *GHIDRA_CAST<int *>((owner + 0xd4));
owner = highIndex >> 0x1f;
if (highIndex / 0xa4 + owner != owner) {
cellOffset = 0;
do {
uVar3 = *GHIDRA_CAST<uint *>((cellOffset + 0xa0 + iVar4));
puVar1 = GHIDRA_CAST<undefined4 *>((cellOffset + iVar4));
if (uVar3 != 0) {
i = 1;
firstSlot = puVar1;
do {
j = i;
if (i < uVar3) {
do {
other = GHIDRA_CAST<Entity *>(puVar1[j]);
first = GHIDRA_CAST<Entity *>(*firstSlot);
iVar4 = other->_collisionIndex;
owner = first->_collisionIndex;
highIndex = owner;
if (owner < iVar4) {
highIndex = iVar4;
}
if (iVar4 < owner) {
owner = iVar4;
}
uVar3 = highIndex * pairStride + owner;
if ((first != other) && (GHIDRA_INT(uVar3) < *GHIDRA_CAST<int *>((owner + 0xd0)))) {
pairWord = *GHIDRA_CAST<uint *>((*GHIDRA_CAST<int *>((owner + 0xc4)) + (uVar3 >> 5) * 4));
if ((pairWord & 1 << (sbyte)(uVar3 & 0x1f)) == 0) {
*GHIDRA_CAST<uint *>((*GHIDRA_CAST<int *>((owner + 0xc4)) + (uVar3 >> 5) * 4)) =
pairWord | 1 << (uVar3 & 0x1f);
if (((((first->_sizeMulti).x == g_vectorOne.x) &&
((first->_sizeMulti).y == g_vectorOne.y)) &&
((other->_sizeMulti).x == g_vectorOne.x)) &&
((other->_sizeMulti).y == g_vectorOne.y)) {
(GHIDRA_CAST<Entity *>((first)))->Entity::push_apart_circle(other);
}
else {
(GHIDRA_CAST<Entity *>((first)))->Entity::push_apart_capsule(other);
}
_DAT_00c71650 = _DAT_00c71650 + 1;
}
}
j = j + 1;
uVar3 = puVar1[0x28];
} while (j < uVar3);
}
firstSlot = firstSlot + 1;
bVar5 = i < uVar3;
i = i + 1;
} while (bVar5);
}
cellOffset = cellOffset + 0xa4;
iVar4 = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(first) + 0x18));
cellIndex = cellIndex + 1;
} while (cellIndex < GHIDRA_UINT(((*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(first) + 0x1c)) - iVar4) / 0xa4)));
}
return;
}