Files
isaac-port/generated-src/afterbirth_persistent_game_data.cpp
T
shweetandClaude Opus 5.5 3ce74c6e2d 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>
2026-11-19 21:10:23 -05:00

333 lines
10 KiB
C++

#include "classes.h"
// 0041d670
byte AfterbirthPersistentGameData::check_header(void *stream)
{
char isEof;
uint uVar1;
int *expectedHeader;
int *headerPtr;
void *data;
uint uVar2;
bool bVar3;
undefined4 settingValue;
undefined4 cutsceneValue;
undefined4 counter3Value;
undefined4 counterValue;
uint storedChecksum;
int sectionId;
int sectionCount;
char specialSeedByte;
char challengeByte;
char bossByte;
char minibossByte;
char collectibleByte;
char achievementByte;
uint sectionSize;
void *saveData;
uint entryCount;
int local_1c [4];
uint local_c;
undefined1 auStack_8 [4];
local_c = __security_cookie ^ GHIDRA_UINT((auStack_8 + 4));
saveData = this;
(**(code **)(*GHIDRA_CAST<int *>(stream) + 0x14))(local_1c,1,0x10);
expectedHeader = &DAT_00b1b98c;
headerPtr = local_1c;
uVar2 = 0xc;
do {
if (*expectedHeader != *headerPtr) {
expectedHeader = &DAT_00b1b9a0;
headerPtr = local_1c;
uVar2 = 0xc;
goto LAB_0041d6d1;
}
expectedHeader = expectedHeader + 1;
headerPtr = headerPtr + 1;
bVar3 = 3 < uVar2;
uVar2 = uVar2 - 4;
} while (bVar3);
uVar2 = 6;
sectionCount = 9;
goto LAB_0041d717;
LAB_0041d6d1:
if (*expectedHeader == *headerPtr) goto code_r0x0041d6d7;
expectedHeader = &DAT_00b1b9b4;
headerPtr = local_1c;
uVar2 = 0xc;
do {
if (*expectedHeader != *headerPtr) {
KAGE_LogMessage(1,GHIDRA_CAST<byte *>("AfterbirthPersistentGameData wrong file header (%.16s)\n"));
return 0;
}
expectedHeader = expectedHeader + 1;
headerPtr = headerPtr + 1;
bVar3 = 3 < uVar2;
uVar2 = uVar2 - 4;
} while (bVar3);
uVar2 = 8;
goto LAB_0041d710;
code_r0x0041d6d7:
expectedHeader = expectedHeader + 1;
headerPtr = headerPtr + 1;
bVar3 = uVar2 < 4;
uVar2 = uVar2 - 4;
if (bVar3) goto code_r0x0041d6e2;
goto LAB_0041d6d1;
code_r0x0041d6e2:
uVar2 = 7;
LAB_0041d710:
sectionCount = 10;
LAB_0041d717:
uVar1 = checksum_stream(stream,0x10,4);
(**(code **)(*GHIDRA_CAST<int *>(stream) + 0xc))(0xfffffffc,2);
storedChecksum = 0;
(**(code **)(*GHIDRA_CAST<int *>(stream) + 0x14))(&storedChecksum,4,1);
if ((7 < uVar2) && (storedChecksum != uVar1)) {
KAGE_LogMessage(1,GHIDRA_CAST<byte *>("[warn] AfterbirthPersistentGameData checksum invalid!\n"));
return 0;
}
(**(code **)(*GHIDRA_CAST<int *>(stream) + 0xc))(0x10,0);
data = saveData;
(**(code **)(*GHIDRA_CAST<int *>(stream) + 0x14))(GHIDRA_INT(saveData) + 0x6dc,4,1);
sectionId = 0;
isEof = (**(code **)(*GHIDRA_CAST<int *>(stream) + 0x10))();
joined_r0x0041d798:
if (((isEof != '\0') || (sectionId < 0)) || (sectionCount <= sectionId)) {
(**(code **)(*GHIDRA_CAST<int *>(stream) + 0x14))(GHIDRA_INT(data) + 0x6e0,4,1);
return 1;
}
(**(code **)(*GHIDRA_CAST<int *>(stream) + 0x14))(&sectionId,4,1);
sectionSize = 0;
(**(code **)(*GHIDRA_CAST<int *>(stream) + 0x14))(&sectionSize,4,1);
if (sectionSize == 0) goto switchD_0041d7f3_default;
switch(sectionId) {
case 1:
entryCount = 0;
(**(code **)(*GHIDRA_CAST<int *>(stream) + 0x14))(&entryCount,4,1);
bVar3 = entryCount == 0x115;
if (!bVar3) {
KAGE_LogMessage(1,GHIDRA_CAST<byte *>("Different number of achievements %d/%d\n"));
bVar3 = entryCount == 0x115;
}
if (0x114 < entryCount && !bVar3) {
entryCount = 0x115;
}
uVar2 = 0;
if (entryCount != 0) {
do {
if (sectionSize <= uVar2) break;
(**(code **)(*GHIDRA_CAST<int *>(stream) + 0x14))(&achievementByte,1,1);
*GHIDRA_CAST<bool *>((GHIDRA_CAST<char *>(data) + uVar2 + 0x38)) = '\0' < achievementByte;
uVar2 = uVar2 + 1;
} while (uVar2 < entryCount);
}
break;
case 2:
entryCount = 0;
(**(code **)(*GHIDRA_CAST<int *>(stream) + 0x14))(&entryCount,4,1);
bVar3 = entryCount == 0xa2;
if (!bVar3) {
KAGE_LogMessage(1,GHIDRA_CAST<byte *>("Different number of counters %d/%d\n"));
bVar3 = entryCount == 0xa2;
}
if (0xa1 < entryCount && !bVar3) {
entryCount = 0xa2;
}
uVar2 = 0;
if (entryCount != 0) {
uVar1 = 0;
do {
if (sectionSize <= uVar1) goto LAB_0041dd41;
(**(code **)(*GHIDRA_CAST<int *>(stream) + 0x14))(&counterValue,4,1);
uVar2 = uVar2 + 1;
*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(saveData) + uVar1 + 0x150)) = counterValue;
uVar1 = uVar1 + 4;
} while (uVar2 < entryCount);
goto LAB_0041d8fe;
}
LAB_0041dd49:
data = saveData;
break;
case 3:
entryCount = 0;
(**(code **)(*GHIDRA_CAST<int *>(stream) + 0x14))(&entryCount,4,1);
bVar3 = entryCount == 0xc;
if (!bVar3) {
KAGE_LogMessage(1,GHIDRA_CAST<byte *>("Different number of counters %d/%d\n"));
bVar3 = entryCount == 0xc;
}
if (0xb < entryCount && !bVar3) {
entryCount = 0xc;
}
uVar2 = 0;
if (entryCount == 0) goto LAB_0041dd49;
uVar1 = 0;
do {
if (sectionSize <= uVar1) goto LAB_0041dd41;
(**(code **)(*GHIDRA_CAST<int *>(stream) + 0x14))(&counter3Value,4,1);
uVar2 = uVar2 + 1;
*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(saveData) + uVar1 + 0x594)) = counter3Value;
uVar1 = uVar1 + 4;
} while (uVar2 < entryCount);
goto LAB_0041d8fe;
case 4:
entryCount = 0;
(**(code **)(*GHIDRA_CAST<int *>(stream) + 0x14))(&entryCount,4,1);
bVar3 = entryCount == 0x1ba;
if (!bVar3) {
KAGE_LogMessage(1,GHIDRA_CAST<byte *>("Different number of collectibles in collection %d/%d\n"));
bVar3 = entryCount == 0x1ba;
}
if (0x1b9 < entryCount && !bVar3) {
entryCount = 0x1ba;
}
uVar2 = 0;
if (entryCount != 0) {
do {
if (sectionSize <= uVar2) break;
(**(code **)(*GHIDRA_CAST<int *>(stream) + 0x14))(&collectibleByte,1,1);
*GHIDRA_CAST<bool *>((GHIDRA_CAST<char *>(data) + uVar2 + 0x3d8)) = '\0' < collectibleByte;
uVar2 = uVar2 + 1;
} while (uVar2 < entryCount);
}
break;
case 5:
entryCount = 0;
(**(code **)(*GHIDRA_CAST<int *>(stream) + 0x14))(&entryCount,4,1);
bVar3 = entryCount == 7;
if (!bVar3) {
KAGE_LogMessage(1,GHIDRA_CAST<byte *>("Different number of minibosses %d/%d\n"));
bVar3 = entryCount == 7;
}
if (6 < entryCount && !bVar3) {
entryCount = 7;
}
uVar2 = 0;
if (entryCount != 0) {
do {
if (sectionSize <= uVar2) break;
(**(code **)(*GHIDRA_CAST<int *>(stream) + 0x14))(&minibossByte,1,1);
*GHIDRA_CAST<bool *>((GHIDRA_CAST<char *>(data) + uVar2 + 0x5c4)) = '\0' < minibossByte;
uVar2 = uVar2 + 1;
} while (uVar2 < entryCount);
}
break;
case 6:
entryCount = 0;
(**(code **)(*GHIDRA_CAST<int *>(stream) + 0x14))(&entryCount,4,1);
bVar3 = entryCount == 0x43;
if (!bVar3) {
KAGE_LogMessage(1,GHIDRA_CAST<byte *>("Different number of minibosses %d/%d\n"));
bVar3 = entryCount == 0x43;
}
if (0x42 < entryCount && !bVar3) {
entryCount = 0x43;
}
uVar2 = 0;
if (entryCount != 0) {
do {
if (sectionSize <= uVar2) break;
(**(code **)(*GHIDRA_CAST<int *>(stream) + 0x14))(&bossByte,1,1);
*GHIDRA_CAST<bool *>((GHIDRA_CAST<char *>(data) + uVar2 + 0x5cb)) = '\0' < bossByte;
uVar2 = uVar2 + 1;
} while (uVar2 < entryCount);
}
break;
case 7:
entryCount = 0;
(**(code **)(*GHIDRA_CAST<int *>(stream) + 0x14))(&entryCount,4,1);
bVar3 = entryCount == 0x1f;
if (!bVar3) {
KAGE_LogMessage(1,GHIDRA_CAST<byte *>("Different number of challenges %d/%d\n"));
bVar3 = entryCount == 0x1f;
}
if (0x1e < entryCount && !bVar3) {
entryCount = 0x1f;
}
uVar2 = 0;
if (entryCount != 0) {
do {
if (sectionSize <= uVar2) break;
(**(code **)(*GHIDRA_CAST<int *>(stream) + 0x14))(&challengeByte,1,1);
*GHIDRA_CAST<bool *>((GHIDRA_CAST<char *>(data) + uVar2 + 0x60e)) = '\0' < challengeByte;
uVar2 = uVar2 + 1;
} while (uVar2 < entryCount);
}
break;
case 8:
entryCount = 0;
(**(code **)(*GHIDRA_CAST<int *>(stream) + 0x14))(&entryCount,4,1);
bVar3 = entryCount == 0x16;
if (!bVar3) {
KAGE_LogMessage(1,GHIDRA_CAST<byte *>("Different number of cutscenes %d/%d\n"));
bVar3 = entryCount == 0x16;
}
if (0x15 < entryCount && !bVar3) {
entryCount = 0x16;
}
uVar2 = 0;
if (entryCount == 0) goto LAB_0041dd49;
uVar1 = 0;
do {
if (sectionSize <= uVar1) goto LAB_0041dd41;
(**(code **)(*GHIDRA_CAST<int *>(stream) + 0x14))(&cutsceneValue,4,1);
uVar2 = uVar2 + 1;
*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(saveData) + uVar1 + 0x630)) = cutsceneValue;
uVar1 = uVar1 + 4;
} while (uVar2 < entryCount);
goto LAB_0041d8fe;
case 9:
entryCount = 0;
(**(code **)(*GHIDRA_CAST<int *>(stream) + 0x14))(&entryCount,4,1);
bVar3 = entryCount == 1;
if (!bVar3) {
KAGE_LogMessage(1,GHIDRA_CAST<byte *>("Different number of settings %d/%d\n"));
bVar3 = entryCount == 1;
}
if (entryCount != 0 && !bVar3) {
entryCount = 1;
}
uVar2 = 0;
if (entryCount == 0) goto LAB_0041dd49;
uVar1 = 0;
do {
if (sectionSize <= uVar1) goto LAB_0041dd41;
(**(code **)(*GHIDRA_CAST<int *>(stream) + 0x14))(&settingValue,4,1);
uVar2 = uVar2 + 1;
*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(saveData) + uVar1 + 0x688)) = settingValue;
uVar1 = uVar1 + 4;
} while (uVar2 < entryCount);
LAB_0041d8fe:
data = saveData;
break;
case 10:
entryCount = 0;
(**(code **)(*GHIDRA_CAST<int *>(stream) + 0x14))(&entryCount,4,1);
bVar3 = entryCount == 0x4d;
if (!bVar3) {
KAGE_LogMessage(1,GHIDRA_CAST<byte *>("Different number of special seeds %d/%d\n"));
bVar3 = entryCount == 0x4d;
}
if (0x4c < entryCount && !bVar3) {
entryCount = 0x4d;
}
uVar2 = 0;
if (entryCount != 0) {
do {
if (sectionSize <= uVar2) break;
(**(code **)(*GHIDRA_CAST<int *>(stream) + 0x14))(&specialSeedByte,1,1);
*GHIDRA_CAST<bool *>((GHIDRA_CAST<char *>(data) + uVar2 + 0x68c)) = '\0' < specialSeedByte;
uVar2 = uVar2 + 1;
} while (uVar2 < entryCount);
}
}
goto switchD_0041d7f3_default;
LAB_0041dd41:
data = saveData;
switchD_0041d7f3_default:
isEof = (**(code **)(*GHIDRA_CAST<int *>(stream) + 0x10))();
goto joined_r0x0041d798;
}