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

331 lines
11 KiB
C++

#include "classes.h"
// 00a64a50
byte ImagePng::load(void *stream, byte *path)
{
byte bVar1;
char isBound;
undefined1 alpha;
int *piVar2;
int iVar3;
uint alpha;
uint uVar5;
uint extraout_ECX;
byte *signatureCursor;
undefined1 *paletteAlpha;
size_t texelSize;
int *piVar6;
uint uVar7;
ushort *puVar8;
void *pvVar9;
bool bVar10;
ulonglong dimensions;
size_t allocSize;
int allocSizeHigh;
void *rowPointers;
uint local_48;
int *local_44;
void *endInfo;
int *png;
byte *texels;
byte *savedPath;
void *local_30;
ushort *info;
uint local_28;
uint local_24;
char isLibraryError;
undefined4 local_1c;
uint local_14;
void *local_10;
undefined1 *puStack_c;
undefined4 local_8;
void *colorType;
char *errorMessage;
local_8 = 0xffffffff;
puStack_c = &LAB_00b131a0;
local_10 = ExceptionList;
local_14 = __security_cookie ^ GHIDRA_INT(register0x00000010) - 4U;
ExceptionList = &local_10;
local_30 = stream;
savedPath = path;
if (stream != (void *)0x0) {
texels = GHIDRA_CAST<byte *>(0x0);
isLibraryError = '\x01';
local_44 = this;
(**(code **)(*GHIDRA_CAST<int *>(stream) + 0x14))(&local_1c,1,8,local_14);
piVar2 = &local_1c;
signatureCursor = GHIDRA_CAST<byte *>(&DAT_00c12980);
uVar7 = 4;
do {
if (*piVar2 != *GHIDRA_CAST<int *>(signatureCursor)) {
bVar1 = (byte)*piVar2;
bVar10 = bVar1 < *signatureCursor;
if ((((bVar1 == *signatureCursor) &&
(bVar10 = *GHIDRA_CAST<byte *>((GHIDRA_CAST<char *>(piVar2) + 1)) < signatureCursor[1],
*GHIDRA_CAST<byte *>((GHIDRA_CAST<char *>(piVar2) + 1)) == signatureCursor[1])) &&
(bVar10 = *GHIDRA_CAST<byte *>((GHIDRA_CAST<char *>(piVar2) + 2)) < signatureCursor[2],
*GHIDRA_CAST<byte *>((GHIDRA_CAST<char *>(piVar2) + 2)) == signatureCursor[2])) &&
(bVar10 = *GHIDRA_CAST<byte *>((GHIDRA_CAST<char *>(piVar2) + 3)) < signatureCursor[3],
*GHIDRA_CAST<byte *>((GHIDRA_CAST<char *>(piVar2) + 3)) == signatureCursor[3])) {
uVar7 = 0;
}
else {
uVar7 = -GHIDRA_UINT(bVar10) | 1;
}
goto LAB_00a64af1;
}
piVar2 = piVar2 + 1;
signatureCursor = signatureCursor + 4;
bVar10 = 3 < uVar7;
uVar7 = uVar7 - 4;
} while (bVar10);
uVar7 = 0;
LAB_00a64af1:
if (uVar7 == 0) {
piVar2 = GHIDRA_CAST<int *>(FUN_00a96800());
png = piVar2;
if (piVar2 == GHIDRA_CAST<int *>(0x0)) {
puVar8 = GHIDRA_CAST<ushort *>(0x0);
}
else {
puVar8 = malloc(0xb8);
if ((puVar8 != GHIDRA_CAST<ushort *>(0x0)) && (memset(puVar8,0,0xb8), puVar8 != GHIDRA_CAST<ushort *>(0x0))) {
memset(puVar8,0,0xb8);
}
}
info = puVar8;
if (piVar2 == GHIDRA_CAST<int *>(0x0)) {
pvVar9 = (void *)0x0;
}
else {
pvVar9 = malloc(0xb8);
if ((pvVar9 != (void *)0x0) && (memset(pvVar9,0,0xb8), pvVar9 != (void *)0x0)) {
memset(pvVar9,0,0xb8);
}
}
piVar2[0x17] = GHIDRA_INT(local_30);
*GHIDRA_CAST<undefined1 *>((piVar2 + 0x49)) = 8;
endInfo = pvVar9;
png_read_info();
iVar3 = setjmp3(png,3,&DAT_00af08ab,local_8,&FuncInfo_00bb33fc);
puVar8 = info;
piVar2 = png;
if (iVar3 == 0) {
uVar7 = 0;
local_30 = (void *)0x0;
local_24 = 0;
if ((png != GHIDRA_CAST<int *>(0x0)) && (info != GHIDRA_CAST<ushort *>(0x0))) {
local_28 = GHIDRA_UINT(*info);
uVar7 = GHIDRA_UINT((byte)info[0xc]);
local_24 = GHIDRA_UINT(info[2]);
local_30 = (void *)GHIDRA_UINT(*GHIDRA_CAST<byte *>((GHIDRA_CAST<char *>(info) + 0x19)));
if (local_30 == (void *)0x3) {
uVar5 = 1;
}
else {
uVar5 = GHIDRA_UINT(local_30) & 2 | 1;
}
alpha = uVar5 + 1;
if ((*GHIDRA_CAST<byte *>((GHIDRA_CAST<char *>(info) + 0x19)) & 4) == 0) {
alpha = uVar5;
}
if (GHIDRA_UINT((0x7fffffff / (ulonglong)(alpha * uVar7 + 7 >> 3))) < local_28) {
FUN_00a64630();
}
}
if (uVar7 == 8) {
dimensions = FUN_00a976e0();
piVar6 = local_44;
local_28 = GHIDRA_UINT(((dimensions & 0xffff0000ffff) >> 0x20));
bVar1 = (GHIDRA_CAST<ImageBase *>((local_44)))->ImageBase::set_size(local_28,GHIDRA_UINT((dimensions & 0xffff0000ffff)),local_28);
if (bVar1 == 0) {
KAGE_LogMessage(8,GHIDRA_CAST<byte *>("Failed to load image \'%s\' because set_size failed\n"));
ExceptionList = local_10;
return 0;
}
if ((piVar2 == GHIDRA_CAST<int *>(0x0)) || (puVar8 == GHIDRA_CAST<ushort *>(0x0))) {
local_48 = 0;
}
else {
local_48 = *GHIDRA_CAST<uint *>((puVar8 + 6));
}
local_48 = local_48 / local_28;
if ((*GHIDRA_CAST<byte *>((piVar2 + 0x19)) & 0x40) == 0) {
png_read_start_row();
}
FUN_00a982d0();
if (puVar8 == GHIDRA_CAST<ushort *>(0x0)) {
uVar7 = 0;
}
else {
uVar7 = *GHIDRA_CAST<uint *>((puVar8 + 6));
}
local_28 = uVar7 / local_28;
texelSize = piVar6[6] * piVar6[7] * local_28;
allocSizeHigh = GHIDRA_INT(texelSize) >> 0x1f;
allocSize = texelSize;
texels = KAGE_Memory::heap_alloc(2,GHIDRA_CAST<ulonglong *>(&allocSize));
if (texels == GHIDRA_CAST<byte *>(0x0)) {
errorMessage =
"Failed to load image \'%s\' because texel buffer allocation of size %d failed\n";
LAB_00a64de8:
KAGE_LogMessage(8,GHIDRA_CAST<byte *>(errorMessage));
isLibraryError = 0;
/* WARNING: Subroutine does not return */
longjmp(piVar2,1);
}
memset(texels,0,texelSize);
pvVar9 = operator_new_tracked((local_24 & 0xffff) * 4);
uVar7 = 0;
if ((local_24 & 0xffff) != 0) {
do {
*GHIDRA_CAST<byte **>((GHIDRA_CAST<char *>(pvVar9) + uVar7 * 4)) = texels + piVar6[6] * uVar7 * local_28;
uVar7 = uVar7 + 1;
} while (uVar7 < (local_24 & 0xffff));
}
if (*GHIDRA_CAST<char *>((GHIDRA_CAST<char *>(piVar2) + 0x11b)) == '\0') {
local_24 = 1;
}
else {
piVar2[0x1a] = piVar2[0x1a] | 2;
local_24 = 7;
}
uVar7 = piVar2[0x31];
piVar2[0x32] = uVar7;
rowPointers = pvVar9;
local_28 = uVar7;
do {
if (uVar7 != 0) {
uVar5 = uVar7;
do {
png_read_row(uVar7);
uVar5 = uVar5 - 1;
uVar7 = extraout_ECX;
} while (uVar5 != 0);
uVar7 = local_28;
pvVar9 = rowPointers;
}
local_24 = local_24 - 1;
} while (local_24 != 0);
if (pvVar9 != (void *)0x0) {
local_8 = 0;
tracked_alloc(1,pvVar9,0);
local_8 = 0xffffffff;
}
colorType = local_30;
piVar6 = local_44;
local_44[10] = 0xb;
if (local_30 == (void *)0x3) {
local_44[10] = 0;
iVar3 = 0;
}
else if (local_48 == 3) {
local_44[10] = 6;
iVar3 = 6;
}
else {
if (local_48 != 4) {
errorMessage =
"Failed to load image \'%s\' because it has a unsupported number of channels (%d)\n";
goto LAB_00a64de8;
}
local_44[10] = 8;
iVar3 = 8;
}
if ((((byte)g_graphicsManager_flags & 4) != 0) && (iVar3 == 8)) {
image_premultiply_alpha(texels,local_44[6],local_44[7]);
}
isBound = (**(code **)(*piVar6 + 0x58))(&texels);
if (isBound != '\0') {
if (colorType == (void *)0x3) {
uVar7 = 0;
local_30 = (void *)0x0;
local_24 = 0;
local_28 = 0;
if (info != GHIDRA_CAST<ushort *>(0x0)) {
if ((info[4] & 8) != 0) {
local_30 = *(void **)(info + 8);
uVar7 = GHIDRA_UINT(info[10]);
}
if ((info != GHIDRA_CAST<ushort *>(0x0)) && ((info[4] & 0x10) != 0)) {
if (*GHIDRA_CAST<char *>((GHIDRA_CAST<char *>(info) + 0x19)) == '\x03') {
local_24 = *GHIDRA_CAST<uint *>((info + 0x26));
}
else {
local_24 = 0;
}
local_28 = GHIDRA_UINT(info[0xb]);
}
}
uVar7 = -GHIDRA_UINT((uVar7 != 0)) & uVar7;
uVar5 = 0x100;
if (uVar7 < 0x100) {
uVar5 = uVar7;
}
local_48 = FUN_00a66730(1,6,8);
uVar7 = 0;
if (uVar5 != 0) {
paletteAlpha = GHIDRA_CAST<undefined1 *>((local_48 + 3));
do {
if (GHIDRA_INT(uVar7) < GHIDRA_INT(local_28)) {
alpha = *GHIDRA_CAST<undefined1 *>((uVar7 + local_24));
}
else {
alpha = 0xff;
}
*paletteAlpha = alpha;
uVar7 = uVar7 + 1;
paletteAlpha = paletteAlpha + 4;
} while (uVar7 < uVar5);
piVar6 = local_44;
}
(**(code **)(*piVar6 + 0xc))(local_48,uVar5,0);
}
png_read_end();
png_destroy_read_struct(&endInfo);
ExceptionList = local_10;
return 1;
}
errorMessage = "Failed to load image \'%s\' because bind_texel_data failed\n";
}
else {
errorMessage = "Failed to load image \'%s\' because the component depth is not 8-bit.\n";
}
KAGE_LogMessage(8,GHIDRA_CAST<byte *>(errorMessage));
isLibraryError = 0;
/* WARNING: Subroutine does not return */
longjmp(piVar2,1);
}
if (isLibraryError != '\0') {
KAGE_LogMessage(8,GHIDRA_CAST<byte *>("Failed to load image \'%s\' due to an internal library error\n"));
}
if (texels != GHIDRA_CAST<byte *>(0x0)) {
KAGE_Memory::heap_free(2,texels);
}
piVar2 = png;
pvVar9 = endInfo;
png_read_destroy(endInfo);
if (info != GHIDRA_CAST<ushort *>(0x0)) {
if ((piVar2 != GHIDRA_CAST<int *>(0x0)) && (*(void **)(info + 0x1c) != (void *)0x0)) {
free(*(void **)(info + 0x1c));
}
free(info);
info = GHIDRA_CAST<ushort *>(0x0);
}
if (pvVar9 != (void *)0x0) {
if ((piVar2 != GHIDRA_CAST<int *>(0x0)) && (*(void **)(GHIDRA_CAST<char *>(pvVar9) + 0x38) != (void *)0x0)) {
free(*(void **)(GHIDRA_CAST<char *>(pvVar9) + 0x38));
}
free(pvVar9);
endInfo = (void *)0x0;
}
if (piVar2 != GHIDRA_CAST<int *>(0x0)) {
free(piVar2);
}
}
}
ExceptionList = local_10;
return 0;
}