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

+370
View File
@@ -0,0 +1,370 @@
#include "classes.h"
// 00a14620
byte Shader::load(byte *name, void *attributes, void *params)
{
int iVar1;
char cVar2;
uint uVar3;
uint attribCount;
void *attribCopies;
char *attribNameCursor;
byte *nameCursor;
char *attribNameCopy;
char *pcVar4;
uint attribIndex;
void *local_10;
undefined1 *puStack_c;
undefined4 local_8;
byte ch;
puStack_c = &LAB_00af0cf0;
local_10 = ExceptionList;
uVar3 = __security_cookie ^ GHIDRA_INT(register0x00000010) - 4U;
ExceptionList = &local_10;
if (*(void **)(GHIDRA_CAST<char *>(this) + 8) != (void *)0x0) {
local_8 = 0;
tracked_alloc(1,*(void **)(GHIDRA_CAST<char *>(this) + 8),0);
*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(this) + 8)) = 0;
}
local_8 = 0xffffffff;
if (name == GHIDRA_CAST<byte *>(0x0)) {
pcVar4 = GHIDRA_CAST<char *>(0x0);
}
else {
nameCursor = name;
do {
ch = *nameCursor;
nameCursor = nameCursor + 1;
} while (ch != 0);
pcVar4 = operator_new_tracked(GHIDRA_UINT((nameCursor + (1 - GHIDRA_INT((name + 1))))));
nameCursor = name;
do {
ch = *nameCursor;
nameCursor = nameCursor + 1;
} while (ch != 0);
strncpy(pcVar4,GHIDRA_CAST<char *>(name),(size_t)(nameCursor + (1 - GHIDRA_INT((name + 1)))));
}
attribCount = 0;
*GHIDRA_CAST<char **>((GHIDRA_CAST<char *>(this) + 8)) = pcVar4;
*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(this) + 0x10)) = 0;
iVar1 = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(attributes) + 4));
while (iVar1 != 0) {
attribCount = attribCount + 1;
*GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(this) + 0x10)) = attribCount;
iVar1 = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(attributes) + attribCount * 8 + 4));
}
attribCopies = tracked_alloc(0,(void *)0x0,
(ulonglong)
(-GHIDRA_UINT((GHIDRA_INT(((ulonglong)attribCount * 8 >> 0x20)) != 0)) |
GHIDRA_UINT(((ulonglong)attribCount * 8))));
*(void **)(GHIDRA_CAST<char *>(this) + 0xc) = attribCopies;
attribIndex = 0;
if (*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + 0x10)) != 0) {
do {
iVar1 = attribIndex * 8;
pcVar4 = *GHIDRA_CAST<char **>((iVar1 + GHIDRA_INT(attributes)));
if (pcVar4 == GHIDRA_CAST<char *>(0x0)) {
attribNameCopy = GHIDRA_CAST<char *>(0x0);
}
else {
attribNameCursor = pcVar4;
do {
cVar2 = *attribNameCursor;
attribNameCursor = attribNameCursor + 1;
} while (cVar2 != '\0');
attribNameCopy = operator_new_tracked(GHIDRA_UINT((attribNameCursor + (1 - GHIDRA_INT((pcVar4 + 1))))));
attribNameCursor = pcVar4;
do {
cVar2 = *attribNameCursor;
attribNameCursor = attribNameCursor + 1;
} while (cVar2 != '\0');
strncpy(attribNameCopy,pcVar4,(size_t)(attribNameCursor + (1 - GHIDRA_INT((pcVar4 + 1)))));
}
*GHIDRA_CAST<char **>((iVar1 + *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + 0xc)))) = attribNameCopy;
*GHIDRA_CAST<undefined4 *>((iVar1 + 4 + *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + 0xc)))) =
*GHIDRA_CAST<undefined4 *>((iVar1 + 4 + GHIDRA_INT(attributes)));
attribIndex = attribIndex + 1;
} while (attribIndex < *GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(this) + 0x10)));
}
cVar2 = (**(code **)(*GHIDRA_CAST<int *>(this) + 8))(params,uVar3);
if (cVar2 == '\0') {
(**(code **)(*GHIDRA_CAST<int *>(this) + 4))();
ExceptionList = local_10;
return 0;
}
*GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(this) + 4)) = *GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(this) + 4)) | 1;
(**(code **)(*GHIDRA_CAST<int *>(this) + 0x28))(name);
ExceptionList = local_10;
return 1;
}
// 00a14c00
void Shader::set_uniform(byte *name, int type, void *data, int unused)
{
int iVar1;
uint byteSize;
byte *nameCursor;
int iVar2;
int *piVar3;
int iVar4;
int *newValueCursor;
undefined4 *puVar5;
undefined4 local_48;
undefined4 uStack_44;
undefined4 uStack_40;
undefined4 *puStack_3c;
undefined8 local_38;
char *local_30;
byte *local_2c;
undefined4 *local_28;
void *local_24;
undefined1 *puStack_20;
void *local_1c;
undefined1 *puStack_18;
undefined4 *local_14;
uint bytesLeft;
uint bytesLeftNext;
byte ch;
char *errorMessage;
puStack_20 = GHIDRA_CAST<undefined1 *>((GHIDRA_INT(register0x00000010) + -4));
local_14 = GHIDRA_CAST<undefined4 *>(0xffffffff);
puStack_18 = &LAB_00b10dbd;
local_1c = ExceptionList;
ExceptionList = &local_1c;
local_24 = this;
local_28 = find_uniform(this,name,GHIDRA_INT(this));
if (local_28 == GHIDRA_CAST<undefined4 *>(0x0)) {
local_48 = 0;
uStack_44 = 0;
uStack_40 = 0;
local_38 = 0;
puStack_3c = local_28;
local_14 = local_28;
std::vector<24byte>::push_back(&local_48);
local_14 = GHIDRA_CAST<undefined4 *>(0xffffffff);
if (puStack_3c != GHIDRA_CAST<undefined4 *>(0x0)) {
byteSize = (*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(&(local_38)) + 0x4))) - GHIDRA_INT(puStack_3c) & 0xfffffffc;
puVar5 = puStack_3c;
if (0xfff < byteSize) {
puVar5 = GHIDRA_CAST<undefined4 *>(puStack_3c[-1]);
byteSize = byteSize + 0x23;
if (0x1f < GHIDRA_UINT((GHIDRA_INT(puStack_3c) + (-4 - GHIDRA_INT(puVar5))))) {
/* WARNING: Subroutine does not return */
_invalid_parameter_noinfo_noreturn();
}
}
operator_delete(puVar5,byteSize);
}
iVar2 = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + 0x34)) +
((*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + 0x38)) - *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + 0x34))) / 0x18) * 0x18;
puVar5 = GHIDRA_CAST<undefined4 *>((iVar2 + -0x18));
local_28 = puVar5;
if (name == GHIDRA_CAST<byte *>(0x0)) {
*puVar5 = 0;
*GHIDRA_CAST<undefined4 *>((iVar2 + -0x14)) = 1;
*GHIDRA_CAST<int *>((iVar2 + -0x10)) = type;
}
else {
nameCursor = name;
do {
ch = *nameCursor;
nameCursor = nameCursor + 1;
} while (ch != 0);
local_30 = operator_new_tracked(GHIDRA_UINT((nameCursor + (1 - GHIDRA_INT((name + 1))))));
local_2c = name + 1;
nameCursor = name;
do {
ch = *nameCursor;
nameCursor = nameCursor + 1;
} while (ch != 0);
strncpy(local_30,GHIDRA_CAST<char *>(name),(size_t)(nameCursor + (1 - GHIDRA_INT(local_2c))));
*puVar5 = local_30;
*GHIDRA_CAST<undefined4 *>((iVar2 + -0x14)) = 1;
*GHIDRA_CAST<int *>((iVar2 + -0x10)) = type;
}
}
switch(type) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
errorMessage = "Getting the type size of a shader uniform texture is not supported";
goto LAB_00a14da7;
case 8:
case 0xc:
case 0x10:
byteSize = 4;
break;
case 9:
case 0xd:
case 0x11:
byteSize = 8;
break;
case 10:
case 0xe:
case 0x12:
byteSize = 0xc;
break;
case 0xb:
case 0xf:
case 0x13:
case 0x14:
byteSize = 0x10;
break;
case 0x15:
case 0x17:
byteSize = 0x18;
break;
case 0x16:
case 0x1a:
byteSize = 0x20;
break;
case 0x18:
byteSize = 0x24;
break;
case 0x19:
case 0x1b:
byteSize = 0x30;
break;
case 0x1c:
byteSize = 0x40;
break;
default:
errorMessage = "Unknown shader uniform type \'%d\' specified";
LAB_00a14da7:
KAGE_LogMessage(0x10,GHIDRA_CAST<byte *>(errorMessage));
byteSize = 0;
}
iVar2 = GHIDRA_INT((local_28[4] - local_28[3])) >> 2;
if (iVar2 != 0) {
piVar3 = *GHIDRA_CAST<int **>((local_28[3] + -4 + iVar2 * 4));
newValueCursor = data;
bytesLeft = byteSize;
while (bytesLeftNext = bytesLeft - 4, 3 < bytesLeft) {
if (*piVar3 != *newValueCursor) goto LAB_00a14ded;
piVar3 = piVar3 + 1;
newValueCursor = newValueCursor + 1;
bytesLeft = bytesLeftNext;
}
if (bytesLeftNext == 0xfffffffc) {
ExceptionList = local_1c;
return;
}
LAB_00a14ded:
if ((char)*piVar3 == (char)*newValueCursor) {
if (bytesLeftNext == 0xfffffffd) {
ExceptionList = local_1c;
return;
}
if (*GHIDRA_CAST<char *>((GHIDRA_CAST<char *>(piVar3) + 1)) == *GHIDRA_CAST<char *>((GHIDRA_CAST<char *>(newValueCursor) + 1))) {
if (bytesLeftNext == 0xfffffffe) {
ExceptionList = local_1c;
return;
}
if (*GHIDRA_CAST<char *>((GHIDRA_CAST<char *>(piVar3) + 2)) == *GHIDRA_CAST<char *>((GHIDRA_CAST<char *>(newValueCursor) + 2))) {
if (bytesLeftNext == 0xffffffff) {
ExceptionList = local_1c;
return;
}
if (*GHIDRA_CAST<char *>((GHIDRA_CAST<char *>(piVar3) + 3)) == *GHIDRA_CAST<char *>((GHIDRA_CAST<char *>(newValueCursor) + 3))) {
ExceptionList = local_1c;
return;
}
}
}
}
this = local_24;
}
local_2c = operator_new_tracked(byteSize);
memcpy(local_2c,data,byteSize);
puVar5 = GHIDRA_CAST<undefined4 *>(local_28[4]);
if (puVar5 == GHIDRA_CAST<undefined4 *>(local_28[5])) {
std::vector<unsigned_int>::_Emplace_reallocate(puVar5,&local_2c);
}
else {
*puVar5 = local_2c;
local_28[4] = local_28[4] + 4;
}
*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(this) + 0x44)) = *GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(this) + 0x40));
iVar2 = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + 0x34));
local_28 = GHIDRA_CAST<undefined4 *>(0x0);
iVar4 = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(local_24) + 0x38)) - iVar2;
iVar1 = iVar4 >> 0x1f;
if (iVar4 / 0x18 + iVar1 != iVar1) {
local_2c = GHIDRA_CAST<byte *>(0x0);
do {
local_30 = GHIDRA_CAST<char *>(((*GHIDRA_CAST<int *>((local_2c + iVar2 + 0x10)) - *GHIDRA_CAST<int *>((local_2c + iVar2 + 0xc)) >> 2
) + -1));
piVar3 = *GHIDRA_CAST<int **>((GHIDRA_CAST<char *>(local_24) + 0x44));
if (piVar3 == *GHIDRA_CAST<int **>((GHIDRA_CAST<char *>(local_24) + 0x48))) {
std::vector<unsigned_int>::_Emplace_reallocate(piVar3,&local_30);
}
else {
*piVar3 = GHIDRA_INT(local_30);
*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + 0x44)) = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + 0x44)) + 4;
}
iVar2 = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(local_24) + 0x34));
local_28 = GHIDRA_CAST<undefined4 *>((GHIDRA_INT(local_28) + 1));
local_2c = local_2c + 0x18;
} while (local_28 < GHIDRA_UINT(((*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(local_24) + 0x38)) - iVar2) / 0x18)));
}
ExceptionList = local_1c;
return;
}
// 00a15040
void * Shader::find_uniform(byte *name, int unused)
{
int iVar1;
byte *uniformName;
uint cmpResult;
int iVar2;
byte *searchName;
undefined4 *puVar3;
uint i;
bool isLess;
byte ch;
undefined4 *uniforms;
uniforms = *GHIDRA_CAST<undefined4 **>((GHIDRA_CAST<char *>(this) + 0x34));
iVar2 = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + 0x38)) - GHIDRA_INT(uniforms);
iVar1 = iVar2 >> 0x1f;
iVar2 = iVar2 / 0x18 + iVar1;
i = 0;
puVar3 = uniforms;
if (iVar2 != iVar1) {
do {
uniformName = GHIDRA_CAST<byte *>(*puVar3);
searchName = name;
do {
ch = *searchName;
isLess = ch < *uniformName;
if (ch != *uniformName) {
LAB_00a15090:
cmpResult = -GHIDRA_UINT(isLess) | 1;
goto LAB_00a15095;
}
if (ch == 0) break;
ch = searchName[1];
isLess = ch < uniformName[1];
if (ch != uniformName[1]) goto LAB_00a15090;
searchName = searchName + 2;
uniformName = uniformName + 2;
} while (ch != 0);
cmpResult = 0;
LAB_00a15095:
if ((cmpResult == 0) && (puVar3[1] == 1)) {
return uniforms + i * 6;
}
i = i + 1;
puVar3 = puVar3 + 6;
} while (i < GHIDRA_UINT((iVar2 - iVar1)));
}
return (void *)0x0;
}