Files
isaac-port/generated-src/kage_filesys_file_manager.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

317 lines
10 KiB
C++

#include "classes.h"
// 005ca5a0
bool KAGE_Filesys_FileManager::OpenRead(int param_2, int param_3)
{
byte isHasFlags;
int iVar1;
int totalCharge;
if (-1 < param_3) {
iVar1 = (GHIDRA_CAST<Entity_Player *>((GHIDRA_CAST<Entity_Player *>(this))))->Entity_Player::GetActiveMaxCharge(param_3);
totalCharge = (GHIDRA_CAST<Entity_Player *>((GHIDRA_CAST<Entity_Player *>(this))))->Entity_Player::GetTotalActiveCharge(param_3);
if (totalCharge < iVar1) {
return false;
}
}
if (0x244 < param_2) {
switch(param_2) {
case 0x248:
if ((this[0x5f1] != (KAGE_Filesys_FileManager)0x0) && (*GHIDRA_CAST<int *>(this[0x5f1]) == 3)) {
return false;
}
default:
return true;
case 0x26f:
return 0 < GHIDRA_INT(this[0x4d7]);
case 0x27b:
iVar1 = FUN_005c92f0();
if (iVar1 != 0) {
iVar1 = (GHIDRA_CAST<Room *>((g_game->_room)))->Room::GetGridCollisionAtPos(*GHIDRA_CAST<Vector *>((iVar1 + 0x33c)));
if (*GHIDRA_CAST<char *>((this + 0x55c)) != '\0') {
return iVar1 != 4;
}
if (iVar1 == 0) {
return true;
}
if (iVar1 == 5) {
return true;
}
}
break;
case 0x282:
iVar1 = (GHIDRA_CAST<Entity_Player *>((GHIDRA_CAST<Entity_Player *>(this))))->Entity_Player::GetEffectiveMaxHearts();
return 0 < iVar1 + GHIDRA_INT(this[0x4d3]);
case 0x2c5:
if ((this[0x7cb] == (KAGE_Filesys_FileManager)0x0) &&
(1.0 < (float)this[0xd8] * (float)this[0xd8] + (float)this[0xd9] * (float)this[0xd9])) {
return true;
}
break;
case 0x2ca:
isHasFlags = (GHIDRA_CAST<Entity *>((GHIDRA_CAST<Entity *>(this))))->Entity::HasEntityFlags(0x600000000000000);
if ((isHasFlags == 0) && ((float)this[0xd4] == 0.0)) {
return true;
}
}
return false;
}
if (param_2 == 0x244) {
iVar1 = FUN_00827180(this + 0xcf);
return iVar1 != -1;
}
if (0x127 < param_2) {
if (param_2 != 0x1e7) {
if (param_2 == 0x22b) {
return 4 < GHIDRA_INT(this[0x4da]);
}
return true;
}
LAB_005ca662:
return 1 < GHIDRA_INT(this[0x4d0]);
}
if (param_2 == 0x127) {
return 0 < GHIDRA_INT(this[0x4da]);
}
if (param_2 != 0x82) {
if (param_2 == 0x85) goto LAB_005ca662;
if (param_2 != 0xb5) {
return true;
}
}
return 1.0 < (float)this[0xd8] * (float)this[0xd8] + (float)this[0xd9] * (float)this[0xd9];
}
// 00a159d0
uint KAGE_Filesys_FileManager::GetPrimaryFilePathHash(byte *filePath)
{
uint hash;
uint normalizedCh;
byte lowerCh;
byte ch;
if (filePath == GHIDRA_CAST<byte *>(0x0)) {
return 0;
}
hash = 0x1505;
ch = *filePath;
while (ch != 0) {
filePath = filePath + 1;
lowerCh = ch + 0x20;
if (0x19 < (byte)(ch + 0xbf)) {
lowerCh = ch;
}
normalizedCh = GHIDRA_UINT(lowerCh);
if (lowerCh == 0x5c) {
normalizedCh = 0x2f;
}
hash = hash * 0x21 + normalizedCh;
ch = *filePath;
}
return hash;
}
// 00a179c0
void KAGE_Filesys_FileManager::LoadArchiveFile(byte *param_1, uint *param_2, ushort param_3)
{
undefined1 isExpectedChecksum;
uint uVar1;
byte *resolvedPath;
byte *loadedPathChar;
uint isExpectedChecksum;
uint *fileEntry;
byte *extraout_ECX;
byte *resolvedPathChar;
int iVar3;
int *piVar4;
uint uVar5;
int dwordCount;
bool isLess;
char *format;
uint archiveIndex;
undefined4 fileCount;
byte *archivePath;
int local_e58;
int *stream;
undefined1 archiveType;
uint local_e4c;
int archivedFile [3];
int archivedFileRecord;
int chunkBuffer [128];
undefined1 headerMagic [7];
undefined1 local_15;
uint local_14;
void *local_10;
undefined1 *puStack_c;
undefined4 local_8;
byte ch;
local_8 = 0xffffffff;
puStack_c = &LAB_00b11020;
local_10 = ExceptionList;
uVar1 = __security_cookie ^ GHIDRA_UINT((headerMagic + 0x18));
ExceptionList = &local_10;
archivePath = param_1;
local_14 = uVar1;
resolvedPath = FileSystem::ResolvePath(param_1);
if (resolvedPath == GHIDRA_CAST<byte *>(0x0)) {
KAGE_LogMessage(8,GHIDRA_CAST<byte *>("Failed to open archive file \'%s\'\n"));
}
else {
uVar5 = 0;
archiveIndex = 0;
resolvedPathChar = extraout_ECX;
if (DAT_00c37b14 != 0) {
do {
loadedPathChar = GHIDRA_CAST<byte *>((&DAT_00c37a14)[uVar5 * 2]);
resolvedPathChar = resolvedPath;
do {
ch = *loadedPathChar;
isLess = ch < *resolvedPathChar;
if (ch != *resolvedPathChar) {
LAB_00a17a60:
isExpectedChecksum = -GHIDRA_UINT(isLess) | 1;
goto LAB_00a17a65;
}
if (ch == 0) break;
ch = loadedPathChar[1];
isLess = ch < resolvedPathChar[1];
if (ch != resolvedPathChar[1]) goto LAB_00a17a60;
loadedPathChar = loadedPathChar + 2;
resolvedPathChar = resolvedPathChar + 2;
} while (ch != 0);
isExpectedChecksum = 0;
LAB_00a17a65:
} while ((isExpectedChecksum != 0) && (uVar5 = uVar5 + 1, uVar5 < DAT_00c37b14));
archiveIndex = uVar5;
if (0x1f < uVar5) {
KAGE_LogMessage(8,(byte *)
"Cannot load archive file \'%s\', maximum number of archive files exceeded\n"
);
local_8 = 0;
tracked_alloc(1,resolvedPath,0);
ExceptionList = local_10;
return;
}
}
(&DAT_00c37a14)[archiveIndex * 2] = resolvedPath;
stream = GHIDRA_CAST<int *>(0x0);
(GHIDRA_CAST<FileSystem *>((resolvedPathChar)))->FileSystem::open_disk_file(resolvedPath,&stream);
if ((stream == GHIDRA_CAST<int *>(0x0)) &&
(FileSystem::open_archive_file
(&PTR_vftable_00c37a10,GHIDRA_CAST<byte *>((&DAT_00c37a14)[archiveIndex * 2]),&stream),
stream == GHIDRA_CAST<int *>(0x0))) {
KAGE_LogMessage(8,GHIDRA_CAST<byte *>("Failed to open archive file \'%s\'\n"));
if ((void *)(&DAT_00c37a14)[archiveIndex * 2] == (void *)0x0) {
ExceptionList = local_10;
return;
}
local_8 = 1;
tracked_alloc(1,(void *)(&DAT_00c37a14)[archiveIndex * 2],0);
(&DAT_00c37a14)[archiveIndex * 2] = 0;
ExceptionList = local_10;
return;
}
piVar4 = stream;
(**(code **)(*stream + 0x14))(headerMagic,1,7,uVar1);
local_15 = 0;
archiveType = 0;
(**(code **)(*piVar4 + 0x14))(&archiveType,1,1);
(&DAT_00c37a18)[archiveIndex * 8] = archiveType;
local_e58 = 0;
(**(code **)(*piVar4 + 0x14))(&local_e58,4,1);
fileCount = 0;
(**(code **)(*piVar4 + 0x14))(&fileCount,2,1);
(**(code **)(*piVar4 + 0xc))(local_e58,0);
local_e58 = 0;
if ((ushort)fileCount != 0) {
do {
fileEntry = operator_new(0x1c);
piVar4 = stream;
local_e4c = 0;
*fileEntry = archiveIndex;
(**(code **)(*stream + 0x14))(&local_e4c,4,1);
fileEntry[1] = local_e4c;
local_e4c = 0;
(**(code **)(*piVar4 + 0x14))(&local_e4c,4,1);
fileEntry[2] = local_e4c;
local_e4c = 0;
(**(code **)(*piVar4 + 0x14))(&local_e4c,4,1);
fileEntry[3] = local_e4c;
local_e4c = 0;
(**(code **)(*piVar4 + 0x14))(&local_e4c,4,1);
fileEntry[4] = local_e4c;
local_e4c = 0;
(**(code **)(*piVar4 + 0x14))(&local_e4c,4,1);
fileEntry[5] = local_e4c;
if (((ushort)local_e58 < param_3) && (*param_2 == local_e4c)) {
isExpectedChecksum = 1;
}
else {
isExpectedChecksum = 0;
}
*GHIDRA_CAST<undefined1 *>((fileEntry + 6)) = isExpectedChecksum;
FUN_00a68a50(fileEntry);
local_8 = 2;
uVar1 = 0xababeb98;
memset(chunkBuffer,0,0x200);
local_e4c = *GHIDRA_CAST<uint *>((archivedFileRecord + 0x10));
do {
uVar5 = local_e4c;
if (0x200 < GHIDRA_INT(local_e4c)) {
uVar5 = 0x200;
}
isExpectedChecksum = (**(code **)(archivedFile[0] + 0x14))(chunkBuffer,1,uVar5);
iVar3 = 0;
dwordCount = GHIDRA_INT(((GHIDRA_INT((isExpectedChecksum + 3)) >> 0x1f & 3U) + isExpectedChecksum + 3)) >> 2;
if (0 < dwordCount) {
do {
piVar4 = chunkBuffer + iVar3;
iVar3 = iVar3 + 1;
uVar1 = uVar1 * -0x80000000 + *piVar4 + (uVar1 >> 1);
} while (iVar3 < dwordCount);
}
local_e4c = local_e4c - uVar5;
} while ((0 < GHIDRA_INT(local_e4c)) && (isExpectedChecksum == uVar5));
if (uVar1 == *GHIDRA_CAST<uint *>((archivedFileRecord + 0x14))) {
uVar5 = fileEntry[1] & 0x7fff;
iVar3 = *GHIDRA_CAST<int *>((&DAT_00c37b18 + uVar5 * 4));
uVar1 = 0;
if (iVar3 != 0) {
do {
if (((*GHIDRA_CAST<uint *>((iVar3 + 4)) == fileEntry[1]) &&
(isExpectedChecksum = uVar1, *GHIDRA_CAST<uint *>((iVar3 + 8)) == fileEntry[2])) ||
(isExpectedChecksum = uVar1 + 1, 0x7fff < uVar1)) break;
uVar5 = uVar5 + 1 & 0x7fff;
iVar3 = *GHIDRA_CAST<int *>((&DAT_00c37b18 + uVar5 * 4));
uVar1 = isExpectedChecksum;
} while (iVar3 != 0);
if (0x7fff < isExpectedChecksum) {
format = "Failed to load file %x%x from \'%s\', hash table is full\n";
goto LAB_00a17dad;
}
}
*GHIDRA_CAST<uint **>((&DAT_00c37b18 + uVar5 * 4)) = fileEntry;
}
else {
format = "Failed to load file %x%x from \'%s\', checksum is invalid\n";
LAB_00a17dad:
KAGE_LogMessage(8,GHIDRA_CAST<byte *>(format));
operator_delete(fileEntry,0x1c);
}
local_8 = 0xffffffff;
(GHIDRA_CAST<KAGE::Filesys::ArchivedFile *>((archivedFile)))->KAGE::Filesys::ArchivedFile::~ArchivedFile();
param_2 = param_2 + 1;
local_e58 = local_e58 + 1;
} while ((ushort)local_e58 < (ushort)fileCount);
piVar4 = stream;
}
(**(code **)*piVar4)(1);
if (DAT_00c37b14 < archiveIndex + 1) {
DAT_00c37b14 = archiveIndex + 1;
}
}
ExceptionList = local_10;
return;
}