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

+487
View File
@@ -0,0 +1,487 @@
#include "classes.h"
// 009f24b0
void RichTextIcon::render(Vector *pos, int iconType, int iconId, float alpha)
{
void *imageMap = this;
float r;
Vector *pVVar1;
int *imageSlot;
undefined *shader;
ColorMod *color;
undefined4 *imagePtr;
ColorMod *color_00;
LayerState *layer;
int layerId;
uint size;
float fVar2;
float in_XMM2_Da;
undefined1 auStackY_1a8 [128];
void *pvVar3;
Vector *image;
void *imageRefCount;
undefined1 quad [112];
Color local_a0;
KColor tintColor;
Vector local_60;
void *savedImageMap;
Vector *local_54;
undefined1 local_50 [40];
float local_28;
uint local_24;
undefined1 *puStack_20;
void *local_1c;
undefined1 *puStack_18;
undefined4 local_14;
void *imageMap;
puStack_20 = local_50 + 0x4c;
local_14 = 0xffffffff;
puStack_18 = &LAB_00b100ed;
local_1c = ExceptionList;
local_24 = __security_cookie ^ GHIDRA_UINT((local_50 + 0x40));
ExceptionList = &local_1c;
local_54 = pos;
set_icon();
if (iconType == 2) {
imageMap = (void *)(GHIDRA_INT(imageMap) + 0x120);
pvVar3 = (void *)0x9f2522;
savedImageMap = imageMap;
imageSlot = map_int_ImagePtr_subscript(imageMap,&iconId);
if (*imageSlot != 0) {
shader = &g_shaders;
if ((DAT_00c7911c & 1) == 0) {
shader = g_currentShader;
}
g_currentShader = shader;
if (0.0 < *GHIDRA_CAST<float *>((GHIDRA_CAST<char *>(imageMap) + 0x114))) {
pvVar3 = (void *)0x9f2563;
imageSlot = map_int_ImagePtr_subscript(imageMap,&iconId);
fVar2 = (float)((double)*GHIDRA_CAST<int *>((*imageSlot + 0x14)) +
__uint_to_double_fixup[-(*GHIDRA_CAST<int *>((*imageSlot + 0x14)) >> 0x1f)]);
if (*GHIDRA_CAST<float *>((GHIDRA_CAST<char *>(imageMap) + 0x114)) <= fVar2 && fVar2 != *GHIDRA_CAST<float *>((GHIDRA_CAST<char *>(imageMap) + 0x114))) {
imageSlot = map_int_ImagePtr_subscript(imageMap,&iconId);
local_60.y = (*GHIDRA_CAST<float *>((GHIDRA_CAST<char *>(imageMap) + 0x114)) /
(float)((double)*GHIDRA_CAST<int *>((*imageSlot + 0x14)) +
__uint_to_double_fixup[-(*GHIDRA_CAST<int *>((*imageSlot + 0x14)) >> 0x1f)])) * 1.5
;
(GHIDRA_CAST<KColor *>((&tintColor)))->KColor::SetFromARGB(0xffffffff);
imageSlot = map_int_ImagePtr_subscript(imageMap,&iconId);
pVVar1 = local_54;
local_54 = (Vector *)
((float)((double)*GHIDRA_CAST<int *>((*imageSlot + 0x14)) +
__uint_to_double_fixup[-(*GHIDRA_CAST<int *>((*imageSlot + 0x14)) >> 0x1f)]) *
local_60.y + local_54->y);
imageSlot = map_int_ImagePtr_subscript(imageMap,&iconId);
fVar2 = pVVar1->x;
image = local_54;
render_quad_set_uniform_color
(quad,fVar2,pVVar1->y,
(float)((double)*GHIDRA_CAST<int *>((*imageSlot + 0x10)) +
__uint_to_double_fixup[-(*GHIDRA_CAST<int *>((*imageSlot + 0x10)) >> 0x1f)]) *
local_60.y + fVar2,(float)local_54,&tintColor);
pvVar3 = (void *)0x9f266e;
(GHIDRA_CAST<Color *>((GHIDRA_CAST<Color *>(local_50))))->Color::Color();
imageMap = map_int_ImagePtr_subscript(savedImageMap,&iconId);
(GHIDRA_CAST<KAGE::SmartPointer *>((auStackY_1a8 + 0x84)))->KAGE::SmartPointer::operator_assign(imageMap);
apply_sprite_shader_params(color,1,image,pvVar3);
imagePtr = map_int_ImagePtr_subscript(savedImageMap,&iconId);
tintColor._unk = 0;
tintColor._red = 1.0;
tintColor._green = 1.0;
tintColor._blue = 1.0;
tintColor._alpha = alpha;
(**(code **)(*GHIDRA_CAST<int *>(*imagePtr) + 0x1c))();
ExceptionList = local_1c;
return;
}
}
imageRefCount = (void *)0x9f26e3;
(GHIDRA_CAST<Color *>((GHIDRA_CAST<Color *>(local_50))))->Color::Color();
imageMap = map_int_ImagePtr_subscript(savedImageMap,&iconId);
(GHIDRA_CAST<KAGE::SmartPointer *>((auStackY_1a8 + 0x84)))->KAGE::SmartPointer::operator_assign(imageMap);
apply_sprite_shader_params(color_00,1,pvVar3,imageRefCount);
imagePtr = map_int_ImagePtr_subscript(savedImageMap,&iconId);
tintColor._unk = 0;
tintColor._red = 1.0;
tintColor._green = 1.0;
tintColor._blue = 1.0;
tintColor._alpha = alpha;
(**(code **)(*GHIDRA_CAST<int *>(*imagePtr) + 0x20))();
}
}
else {
get_animation_name(GHIDRA_CAST<std_string *>((local_50 + 0x14)),iconType);
local_14 = 0;
layer = (GHIDRA_CAST<ANM2 *>((imageMap)))->ANM2::get_layer_by_string(GHIDRA_CAST<std_string *>((local_50 + 0x14)));
if (layer != GHIDRA_CAST<LayerState *>(0x0)) {
if (layer->_layerData == GHIDRA_CAST<int *>(0x0)) {
layerId = -1;
}
else {
layerId = *GHIDRA_CAST<int *>(layer->_layerData);
}
imageMap = (GHIDRA_CAST<AnimationState *>((GHIDRA_CAST<AnimationState *>((GHIDRA_INT(imageMap) + 0x30)))))->AnimationState::GetLayerFrame(layerId);
fVar2 = *GHIDRA_CAST<float *>((GHIDRA_CAST<char *>(imageMap) + 0x114));
local_60.y = 0.0;
r = *GHIDRA_CAST<float *>((GHIDRA_CAST<char *>(imageMap) + 0xc));
if ((0.0 < fVar2) && (fVar2 < r)) {
*GHIDRA_CAST<float *>((GHIDRA_CAST<char *>(imageMap) + 0x9c)) = fVar2 / r;
*GHIDRA_CAST<float *>((GHIDRA_CAST<char *>(imageMap) + 0xa0)) = fVar2 / r;
}
tintColor._unk = 0;
tintColor._red = 1.0;
tintColor._green = 1.0;
tintColor._blue = 1.0;
tintColor._alpha = alpha;
(GHIDRA_CAST<Color *>((&local_a0)))->Color::Color(r,in_XMM2_Da,0.0,(float)&tintColor);
if (GHIDRA_CAST<Color *>((GHIDRA_INT(imageMap) + 0xa8)) != &local_a0) {
(GHIDRA_CAST<Color *>((GHIDRA_INT(imageMap) + 0xa8)))->_tint[0] = local_a0._tint[0];
*GHIDRA_CAST<float *>((GHIDRA_CAST<char *>(imageMap) + 0xac)) = local_a0._tint[1];
*GHIDRA_CAST<float *>((GHIDRA_CAST<char *>(imageMap) + 0xb0)) = local_a0._tint[2];
*GHIDRA_CAST<float *>((GHIDRA_CAST<char *>(imageMap) + 0xb4)) = local_a0._tint[3];
*GHIDRA_CAST<float *>((GHIDRA_CAST<char *>(imageMap) + 0xb8)) = local_a0._colorize[0];
*GHIDRA_CAST<float *>((GHIDRA_CAST<char *>(imageMap) + 0xbc)) = local_a0._colorize[1];
*GHIDRA_CAST<float *>((GHIDRA_CAST<char *>(imageMap) + 0xc0)) = local_a0._colorize[2];
*GHIDRA_CAST<float *>((GHIDRA_CAST<char *>(imageMap) + 0xc4)) = local_a0._colorize[3];
*GHIDRA_CAST<undefined8 *>((GHIDRA_CAST<char *>(imageMap) + 200)) = (*GHIDRA_CAST<undefined8 *>((GHIDRA_CAST<char *>(&(local_a0._offset)) + 0x0)));
*GHIDRA_CAST<float *>((GHIDRA_CAST<char *>(imageMap) + 0xd0)) = local_a0._offset[2];
}
local_60.x = local_54->x + local_60.y;
local_60.y = local_54->y + local_60.y;
(GHIDRA_CAST<ANM2 *>((imageMap)))->ANM2::Render(&local_60,&g_vectorZero,&g_vectorZero);
}
if (0xf < GHIDRA_UINT(local_28)) {
size = GHIDRA_INT(local_28) + 1;
imageMap = (*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(&((void *)local_50)) + 0x14)));
if (0xfff < size) {
imageMap = *(void **)((*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(&(local_50)) + 0x14))) + -4);
size = GHIDRA_INT(local_28) + 0x24;
if (0x1f < GHIDRA_UINT(((*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(&(local_50)) + 0x14))) + (-4 - GHIDRA_INT(imageMap))))) {
/* WARNING: Subroutine does not return */
_invalid_parameter_noinfo_noreturn();
}
}
operator_delete(imageMap,size);
}
}
ExceptionList = local_1c;
return;
}
// 009f28b0
Vector * RichTextIcon::get_size(Vector *outSize)
{
int *piVar1;
int *piVar2;
LayerState *layer;
int iVar3;
void *pvVar4;
uint size;
float fVar5;
float scaledHeight;
std_string animName;
uint local_18;
void *local_10;
undefined1 *puStack_c;
undefined4 local_8;
float frameHeight;
double heightFixup;
float maxHeight;
local_8 = 0xffffffff;
puStack_c = &LAB_00af85cd;
local_10 = ExceptionList;
local_18 = __security_cookie ^ GHIDRA_INT(&animName) + 0x2cU;
ExceptionList = &local_10;
outSize->y = 0.0;
outSize->x = 0.0;
if (*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + 0x118)) == 2) {
piVar2 = GHIDRA_CAST<int *>((GHIDRA_INT(this) + 0x11c));
piVar1 = map_int_ImagePtr_subscript((void *)(GHIDRA_INT(this) + 0x120),piVar2);
if (*piVar1 == 0) {
ExceptionList = local_10;
return outSize;
}
piVar1 = map_int_ImagePtr_subscript((void *)(GHIDRA_INT(this) + 0x120),piVar2);
iVar3 = *GHIDRA_CAST<int *>((*piVar1 + 0x14));
heightFixup = __uint_to_double_fixup[-(iVar3 >> 0x1f)];
piVar1 = map_int_ImagePtr_subscript((void *)(GHIDRA_INT(this) + 0x120),piVar2);
outSize->x = (float)((double)*GHIDRA_CAST<int *>((*piVar1 + 0x10)) +
__uint_to_double_fixup[-(*GHIDRA_CAST<int *>((*piVar1 + 0x10)) >> 0x1f)]);
outSize->y = (float)((double)iVar3 + heightFixup);
if (*GHIDRA_CAST<float *>((GHIDRA_CAST<char *>(this) + 0x114)) <= 0.0) {
ExceptionList = local_10;
return outSize;
}
piVar1 = map_int_ImagePtr_subscript((void *)(GHIDRA_INT(this) + 0x120),piVar2);
fVar5 = (float)((double)*GHIDRA_CAST<int *>((*piVar1 + 0x14)) +
__uint_to_double_fixup[-(*GHIDRA_CAST<int *>((*piVar1 + 0x14)) >> 0x1f)]);
if (fVar5 < *GHIDRA_CAST<float *>((GHIDRA_CAST<char *>(this) + 0x114)) || fVar5 == *GHIDRA_CAST<float *>((GHIDRA_CAST<char *>(this) + 0x114))) {
ExceptionList = local_10;
return outSize;
}
piVar2 = map_int_ImagePtr_subscript((void *)(GHIDRA_INT(this) + 0x120),piVar2);
fVar5 = (*GHIDRA_CAST<float *>((GHIDRA_CAST<char *>(this) + 0x114)) /
(float)((double)*GHIDRA_CAST<int *>((*piVar2 + 0x14)) +
__uint_to_double_fixup[-(*GHIDRA_CAST<int *>((*piVar2 + 0x14)) >> 0x1f)])) * 1.5;
scaledHeight = fVar5 * outSize->y;
outSize->x = fVar5 * outSize->x;
}
else {
if (*(void **)(GHIDRA_CAST<char *>(this) + 0x34) == (void *)0x0) {
animName._capacity = 0xf;
animName._size = 0;
(*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(&(animName._buf)) + 0x0))) = (void *)0x0;
}
else {
(GHIDRA_CAST<std::string *>((animName._buf)))->std::string::string(*(void **)(GHIDRA_CAST<char *>(this) + 0x34));
}
local_8 = 0;
layer = this->ANM2::get_layer_by_string(&animName);
local_8 = 0xffffffff;
if (0xf < animName._capacity) {
size = animName._capacity + 1;
pvVar4 = (*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(&((void *)animName._buf)) + 0x0)));
if (0xfff < size) {
pvVar4 = *(void **)((*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(&(animName._buf)) + 0x0))) + -4);
size = animName._capacity + 0x24;
if (0x1f < GHIDRA_UINT(((*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(&(animName._buf)) + 0x0))) + (-4 - GHIDRA_INT(pvVar4))))) {
/* WARNING: Subroutine does not return */
_invalid_parameter_noinfo_noreturn();
}
}
operator_delete(pvVar4,size);
}
if (layer == GHIDRA_CAST<LayerState *>(0x0)) {
ExceptionList = local_10;
return outSize;
}
if (layer->_layerData == GHIDRA_CAST<int *>(0x0)) {
iVar3 = -1;
}
else {
iVar3 = *GHIDRA_CAST<int *>(layer->_layerData);
}
pvVar4 = (GHIDRA_CAST<AnimationState *>((GHIDRA_CAST<AnimationState *>((GHIDRA_INT(this) + 0x30)))))->AnimationState::GetLayerFrame(iVar3);
fVar5 = *GHIDRA_CAST<float *>((GHIDRA_CAST<char *>(pvVar4) + 8));
outSize->x = fVar5;
frameHeight = *GHIDRA_CAST<float *>((GHIDRA_CAST<char *>(pvVar4) + 0xc));
outSize->y = frameHeight;
maxHeight = *GHIDRA_CAST<float *>((GHIDRA_CAST<char *>(this) + 0x114));
if (maxHeight <= 0.0) {
ExceptionList = local_10;
return outSize;
}
if (frameHeight <= maxHeight) {
ExceptionList = local_10;
return outSize;
}
scaledHeight = frameHeight * (maxHeight / frameHeight);
outSize->x = fVar5 * (maxHeight / frameHeight);
}
outSize->y = scaledHeight;
ExceptionList = local_10;
return outSize;
}
// 009f2b10
std_string * RichTextIcon::get_animation_name(std_string *outName, int iconType)
{
if (iconType == 0) {
outName->_buf[0] = '\0';
outName->_buf[1] = '\0';
outName->_buf[2] = '\0';
outName->_buf[3] = '\0';
outName->_size = 0;
outName->_capacity = 0xf;
outName->_buf[0] = '\0';
outName->_size = 7;
memmove(outName,"players",7);
outName->_buf[7] = '\0';
return outName;
}
if (iconType == 1) {
outName->_buf[0] = '\0';
outName->_buf[1] = '\0';
outName->_buf[2] = '\0';
outName->_buf[3] = '\0';
outName->_size = 0;
outName->_capacity = 0xf;
outName->_buf[0] = '\0';
outName->_size = 7;
memmove(outName,"pickups",7);
outName->_buf[7] = '\0';
return outName;
}
if (iconType == 3) {
outName->_buf[0] = '\0';
outName->_buf[1] = '\0';
outName->_buf[2] = '\0';
outName->_buf[3] = '\0';
outName->_size = 0;
outName->_capacity = 0xf;
outName->_buf[0] = '\0';
outName->_size = 5;
memmove(outName,"rooms",5);
outName->_buf[5] = '\0';
return outName;
}
KAGE_LogMessage(8,GHIDRA_CAST<byte *>("Invalid icon type (%d) for get_animation_name() \n"));
outName->_buf[0] = '\0';
outName->_buf[1] = '\0';
outName->_buf[2] = '\0';
outName->_buf[3] = '\0';
outName->_size = 0;
outName->_capacity = 0xf;
outName->_buf[0] = '\0';
outName->_size = 0;
outName->_buf[0] = '\0';
return outName;
}
// 009f2c10
void RichTextIcon::set_icon(int param_1, int param_2)
{
byte bVar1;
char isLastRef;
std_string *psVar2;
byte *currentAnimChar;
uint uVar3;
ItemConfig_Item *pIVar4;
int *imageSlot;
void *pvVar5;
void *imageSlotRef;
ANM2 *in_ECX;
std_string *newAnimChar;
int iVar6;
bool isLess;
undefined1 loadedImage [4];
int *loadedImageRef;
void *animName [5];
uint animNameCapacity;
uint local_14;
void *local_10;
undefined1 *puStack_c;
void *local_8;
byte *animData;
ANM2 *iconData;
Manager *manager;
iVar6 = param_2;
manager = g_manager;
local_8 = (void *)0xffffffff;
puStack_c = &LAB_00b10135;
local_10 = ExceptionList;
local_14 = __security_cookie ^ GHIDRA_UINT((animName + 10));
ExceptionList = &local_10;
if (param_1 == 2) {
iconData = in_ECX + 1;
(iconData->_filename)._buf[4] = '\x02';
(iconData->_filename)._buf[5] = '\0';
(iconData->_filename)._buf[6] = '\0';
(iconData->_filename)._buf[7] = '\0';
pIVar4 = (GHIDRA_CAST<ItemConfig *>((&manager->_itemConfig)))->ItemConfig::GetCollectible(param_2);
if (pIVar4 != GHIDRA_CAST<ItemConfig_Item *>(0x0)) {
imageSlot = map_int_ImagePtr_subscript(in_ECX[1]._filename._buf + 0xc,&param_2);
if (*imageSlot == 0) {
psVar2 = &pIVar4->gfxFilename;
if (0xf < (pIVar4->gfxFilename)._capacity) {
psVar2 = *GHIDRA_CAST<std_string **>(psVar2->_buf);
}
pvVar5 = Manager::LoadImage(loadedImage,GHIDRA_CAST<byte *>(psVar2));
local_8 = (void *)0x1;
imageSlotRef = map_int_ImagePtr_subscript(in_ECX[1]._filename._buf + 0xc,&param_2);
(GHIDRA_CAST<KAGE::SmartPointer *>((imageSlotRef)))->KAGE::SmartPointer::operator_assign(pvVar5);
local_8 = (void *)0x2;
if (loadedImageRef != GHIDRA_CAST<int *>(0x0)) {
isLastRef = (**(code **)(*loadedImageRef + 0xc))();
if ((isLastRef != '\0') && (g_imageReleaseFn != (void *)0x0)) {
(*g_imageReleaseFn)(loadedImage);
}
}
}
LAB_009f2dec:
iVar6 = param_2;
}
LAB_009f2def:
*GHIDRA_CAST<int *>((in_ECX[1]._filename._buf + 8)) = iVar6;
}
else {
psVar2 = get_animation_name(GHIDRA_CAST<std_string *>(animName),param_1);
local_8 = (void *)0x0;
if (0xf < psVar2->_capacity) {
psVar2 = *GHIDRA_CAST<std_string **>(psVar2->_buf);
}
animData = (in_ECX->_animState)._animData;
if (animData == GHIDRA_CAST<byte *>(0x0)) {
LAB_009f2caa:
bVar1 = (GHIDRA_CAST<ANM2 *>((in_ECX)))->ANM2::SetAnimation(GHIDRA_CAST<byte *>(psVar2),1);
if (bVar1 != 0) {
(GHIDRA_CAST<AnimationState *>((&in_ECX->_animState)))->AnimationState::Rewind();
(in_ECX->_animState)._isPlaying = 1;
}
}
else {
currentAnimChar = animData;
if (0xf < *GHIDRA_CAST<uint *>((animData + 0x14))) {
currentAnimChar = *GHIDRA_CAST<byte **>(animData);
}
newAnimChar = psVar2;
do {
bVar1 = *currentAnimChar;
isLess = bVar1 < (byte)newAnimChar->_buf[0];
if (bVar1 != newAnimChar->_buf[0]) {
LAB_009f2c97:
uVar3 = -GHIDRA_UINT(isLess) | 1;
goto LAB_009f2c9c;
}
if (bVar1 == 0) break;
bVar1 = currentAnimChar[1];
isLess = bVar1 < (byte)newAnimChar->_buf[1];
if (bVar1 != newAnimChar->_buf[1]) goto LAB_009f2c97;
currentAnimChar = currentAnimChar + 2;
newAnimChar = GHIDRA_CAST<std_string *>((newAnimChar->_buf + 2));
} while (bVar1 != 0);
uVar3 = 0;
LAB_009f2c9c:
if ((uVar3 != 0) || ((animData[0x34] != 0 && ((in_ECX->_animState)._isPlaying == 0))))
goto LAB_009f2caa;
}
local_8 = (void *)0xffffffff;
if (0xf < animNameCapacity) {
uVar3 = animNameCapacity + 1;
pvVar5 = animName[0];
if (0xfff < uVar3) {
pvVar5 = *(void **)(GHIDRA_INT(animName[0]) + -4);
uVar3 = animNameCapacity + 0x24;
if (0x1f < GHIDRA_UINT((GHIDRA_INT(animName[0]) + (-4 - GHIDRA_INT(pvVar5))))) {
/* WARNING: Subroutine does not return */
_invalid_parameter_noinfo_noreturn();
}
}
operator_delete(pvVar5,uVar3);
}
*GHIDRA_CAST<int *>((in_ECX[1]._filename._buf + 4)) = param_1;
if (-1 < param_2) {
pvVar5 = (in_ECX->_animState)._animData;
if (pvVar5 == (void *)0x0) {
iVar6 = 0;
}
else {
iVar6 = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(pvVar5) + 0x30));
}
if (param_2 <= iVar6) {
iVar6 = param_2;
if (pvVar5 != (void *)0x0) {
(GHIDRA_CAST<AnimationState *>((&in_ECX->_animState)))->AnimationState::SetFrameFloat((float)param_2);
goto LAB_009f2dec;
}
goto LAB_009f2def;
}
}
KAGE_LogMessage(8,GHIDRA_CAST<byte *>("Invalid icon id (%d) for Icon Type %d \n"));
}
ExceptionList = local_10;
return;
}