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>
305 lines
11 KiB
C++
305 lines
11 KiB
C++
#include "classes.h"
|
|
|
|
// 0095ed70
|
|
void CutscenePart::load_subtitles()
|
|
{
|
|
char isEof;
|
|
uint uVar1;
|
|
int *file;
|
|
undefined4 timestamp;
|
|
short *lineUtf16;
|
|
undefined4 *puVar2;
|
|
void *cueArray;
|
|
byte *pbVar3;
|
|
qword *allocCounter;
|
|
undefined4 *puVar4;
|
|
int iVar5;
|
|
undefined4 newCue;
|
|
undefined4 uStack_178;
|
|
undefined4 uStack_174;
|
|
undefined4 uStack_170;
|
|
undefined8 local_16c;
|
|
undefined4 local_164;
|
|
undefined4 local_160;
|
|
undefined4 local_15c;
|
|
undefined4 local_158;
|
|
void *part;
|
|
undefined4 *cuesBegin;
|
|
undefined4 *cuesEnd;
|
|
undefined4 *cuesCapacity;
|
|
undefined4 *textLineSlot;
|
|
undefined4 *cuesCapacityCache;
|
|
int textLineCount;
|
|
undefined4 *local_138;
|
|
byte lineBuf [256];
|
|
char endTimestamp [13];
|
|
void *local_10;
|
|
undefined1 *puStack_c;
|
|
undefined4 local_8;
|
|
byte ch;
|
|
qword prevAllocatedBytes;
|
|
void *savedPart;
|
|
|
|
puStack_c = &LAB_00b0c76b;
|
|
local_10 = ExceptionList;
|
|
uVar1 = __security_cookie ^ GHIDRA_UINT((endTimestamp + 0x30));
|
|
ExceptionList = &local_10;
|
|
part = this;
|
|
if (*(void **)(GHIDRA_CAST<char *>(this) + 0x24) != (void *)0x0) {
|
|
local_8 = 0;
|
|
tracked_alloc(1,*(void **)(GHIDRA_CAST<char *>(this) + 0x24),0);
|
|
*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(this) + 0x24)) = 0;
|
|
}
|
|
local_8 = 0xffffffff;
|
|
pbVar3 = GHIDRA_CAST<byte *>((GHIDRA_INT(this) + 0xc));
|
|
*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(this) + 0x28)) = 0;
|
|
*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(this) + 0x2c)) = 0;
|
|
*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(this) + 0x30)) = 0;
|
|
if (0xf < *GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(this) + 0x20))) {
|
|
pbVar3 = *GHIDRA_CAST<byte **>(pbVar3);
|
|
}
|
|
file = (GHIDRA_CAST<FileSystem *>((&PTR_vftable_00c37a10)))->FileSystem::Open(pbVar3,GHIDRA_CAST<int *>(0x0));
|
|
if (file != GHIDRA_CAST<int *>(0x0)) {
|
|
puVar4 = GHIDRA_CAST<undefined4 *>(0x0);
|
|
local_138 = GHIDRA_CAST<undefined4 *>(0x0);
|
|
cuesBegin = GHIDRA_CAST<undefined4 *>(0x0);
|
|
cuesEnd = GHIDRA_CAST<undefined4 *>(0x0);
|
|
cuesCapacityCache = GHIDRA_CAST<undefined4 *>(0x0);
|
|
cuesCapacity = GHIDRA_CAST<undefined4 *>(0x0);
|
|
local_8 = 1;
|
|
isEof = (**(code **)(*file + 0x10))(uVar1);
|
|
if (isEof == '\0') {
|
|
do {
|
|
memset(lineBuf,0,0x100);
|
|
isEof = (**(code **)(*file + 0x10))();
|
|
while ((isEof == '\0' && (lineBuf[0] == 0))) {
|
|
(**(code **)(*file + 0x18))(lineBuf,0x100);
|
|
FUN_00684450();
|
|
isEof = (**(code **)(*file + 0x10))();
|
|
}
|
|
(**(code **)(*file + 0x18))(lineBuf,0x100);
|
|
isEof = (**(code **)(*file + 0x10))();
|
|
if (isEof == '\0') {
|
|
pbVar3 = lineBuf;
|
|
do {
|
|
ch = *pbVar3;
|
|
pbVar3 = pbVar3 + 1;
|
|
} while (ch != 0);
|
|
if (0x1c < GHIDRA_UINT((GHIDRA_INT(pbVar3) - GHIDRA_INT((lineBuf + 1))))) {
|
|
newCue = 0;
|
|
uStack_178 = 0;
|
|
uStack_174 = 0;
|
|
uStack_170 = 0;
|
|
local_164 = 0;
|
|
local_16c = 0;
|
|
if (puVar4 == cuesCapacityCache) {
|
|
FUN_00960880(puVar4,&newCue);
|
|
cuesCapacityCache = cuesCapacity;
|
|
}
|
|
else {
|
|
*puVar4 = 0;
|
|
puVar4[1] = 0;
|
|
puVar4[2] = 0;
|
|
puVar4[3] = 0;
|
|
*GHIDRA_CAST<undefined8 *>((puVar4 + 4)) = 0;
|
|
puVar4[6] = 0;
|
|
cuesEnd = puVar4 + 7;
|
|
}
|
|
puVar4 = cuesEnd;
|
|
local_138 = cuesEnd;
|
|
timestamp = FUN_0095cb80();
|
|
puVar4[-7] = timestamp;
|
|
timestamp = FUN_0095cb80();
|
|
puVar4[-6] = timestamp;
|
|
local_160 = 0;
|
|
local_15c = 0;
|
|
local_158 = 0;
|
|
local_8 = CONCAT31((*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(local_8)) + 0x1))),2);
|
|
(**(code **)(*file + 0x18))(lineBuf,0x100);
|
|
FUN_00684450();
|
|
textLineCount = 0;
|
|
isEof = (**(code **)(*file + 0x10))();
|
|
if (isEof == '\0') {
|
|
textLineSlot = puVar4 + -5;
|
|
iVar5 = textLineCount;
|
|
do {
|
|
if ((lineBuf[0] == 0) || (3 < iVar5)) break;
|
|
lineUtf16 = utf8_to_utf16_alloc(lineBuf);
|
|
iVar5 = iVar5 + 1;
|
|
*textLineSlot = lineUtf16;
|
|
textLineSlot = textLineSlot + 1;
|
|
(**(code **)(*file + 0x18))(lineBuf,0x100);
|
|
FUN_00684450();
|
|
isEof = (**(code **)(*file + 0x10))();
|
|
} while (isEof == '\0');
|
|
puVar4 = local_138;
|
|
textLineCount = iVar5;
|
|
}
|
|
puVar4[-1] = textLineCount;
|
|
local_8 = CONCAT31((*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(local_8)) + 0x1))),1);
|
|
}
|
|
}
|
|
isEof = (**(code **)(*file + 0x10))();
|
|
} while (isEof == '\0');
|
|
local_138 = cuesBegin;
|
|
puVar2 = cuesBegin;
|
|
}
|
|
else {
|
|
puVar2 = GHIDRA_CAST<undefined4 *>(0x0);
|
|
}
|
|
savedPart = part;
|
|
uVar1 = (GHIDRA_INT(puVar4) - GHIDRA_INT(puVar2)) / 0x1c;
|
|
iVar5 = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(part) + 0x24));
|
|
*GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(part) + 0x30)) = uVar1;
|
|
if (iVar5 != 0) {
|
|
if (g_mainHeap == (void *)0x0) {
|
|
allocCounter = &g_allocatedBytesNoHeap;
|
|
}
|
|
else {
|
|
allocCounter = GHIDRA_CAST<qword *>((GHIDRA_INT(g_mainHeap) + 0x30));
|
|
}
|
|
uVar1 = *GHIDRA_CAST<uint *>((iVar5 + -4));
|
|
prevAllocatedBytes = *allocCounter;
|
|
*GHIDRA_CAST<uint *>(allocCounter) = GHIDRA_UINT(*allocCounter) - uVar1;
|
|
*GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(allocCounter) + 4)) =
|
|
*GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(allocCounter) + 4)) - GHIDRA_UINT((GHIDRA_UINT(prevAllocatedBytes) < uVar1));
|
|
free((void *)(iVar5 + -4));
|
|
uVar1 = *GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(savedPart) + 0x30));
|
|
local_8 = CONCAT31((*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(local_8)) + 0x1))),1);
|
|
*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(savedPart) + 0x24)) = 0;
|
|
}
|
|
cueArray = operator_new_tracked
|
|
(-GHIDRA_UINT((GHIDRA_INT(((ulonglong)uVar1 * 0x1c >> 0x20)) != 0)) |
|
|
GHIDRA_UINT(((ulonglong)uVar1 * 0x1c)));
|
|
puVar4 = local_138;
|
|
*(void **)(GHIDRA_CAST<char *>(savedPart) + 0x24) = cueArray;
|
|
memcpy(cueArray,local_138,*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(savedPart) + 0x30)) * 0x1c);
|
|
(**(code **)*file)(1);
|
|
if (puVar4 != GHIDRA_CAST<undefined4 *>(0x0)) {
|
|
uVar1 = ((GHIDRA_INT(cuesCapacityCache) - GHIDRA_INT(puVar4)) / 0x1c) * 0x1c;
|
|
puVar2 = puVar4;
|
|
if (0xfff < uVar1) {
|
|
puVar2 = GHIDRA_CAST<undefined4 *>(puVar4[-1]);
|
|
uVar1 = uVar1 + 0x23;
|
|
if (0x1f < GHIDRA_UINT((GHIDRA_INT(puVar4) + (-4 - GHIDRA_INT(puVar2))))) {
|
|
/* WARNING: Subroutine does not return */
|
|
_invalid_parameter_noinfo_noreturn();
|
|
}
|
|
}
|
|
operator_delete(puVar2,uVar1);
|
|
}
|
|
}
|
|
ExceptionList = local_10;
|
|
return;
|
|
}
|
|
|
|
// 0095f1f0
|
|
void CutscenePart::render_subtitles()
|
|
{
|
|
float fVar1;
|
|
int iVar2;
|
|
KColor *color;
|
|
int in_ECX;
|
|
uint uVar3;
|
|
undefined4 *lineText;
|
|
float10 fVar4;
|
|
float fVar5;
|
|
double dVar6;
|
|
undefined4 drawSettings;
|
|
undefined4 local_74;
|
|
undefined4 local_70;
|
|
undefined4 local_6c;
|
|
undefined4 local_68;
|
|
undefined4 local_64;
|
|
undefined4 local_60;
|
|
KColor textColor;
|
|
int savedBlendMode0;
|
|
int savedBlendMode1;
|
|
int savedBlendMode2;
|
|
int savedBlendMode3;
|
|
int savedBlendMode4;
|
|
float lineHeight;
|
|
float centerX;
|
|
float halfLineWidth;
|
|
float local_24;
|
|
float local_20;
|
|
Font *font;
|
|
float textScale;
|
|
float local_14;
|
|
void *local_10;
|
|
undefined1 *puStack_c;
|
|
undefined4 local_8;
|
|
|
|
local_8 = 0xffffffff;
|
|
puStack_c = &LAB_00b0c7ad;
|
|
local_10 = ExceptionList;
|
|
ExceptionList = &local_10;
|
|
if (*GHIDRA_CAST<int *>(&g_manager->_stringTable) != 0) {
|
|
local_24 = *GHIDRA_CAST<float *>((in_ECX + 0x34)) * g_screenPointScale;
|
|
fVar4 = (float10)roundf();
|
|
local_24 = (float)fVar4;
|
|
textScale = local_24 / g_screenPointScale;
|
|
iVar2 = *GHIDRA_CAST<int *>((in_ECX + 0x24));
|
|
if ((((iVar2 != 0) && (uVar3 = *GHIDRA_CAST<uint *>((in_ECX + 0x2c)), uVar3 < *GHIDRA_CAST<uint *>((in_ECX + 0x30)))) &&
|
|
(*GHIDRA_CAST<uint *>((iVar2 + uVar3 * 0x1c)) <= *GHIDRA_CAST<uint *>((in_ECX + 0x28)))) &&
|
|
(*GHIDRA_CAST<uint *>((in_ECX + 0x28)) <= *GHIDRA_CAST<uint *>((iVar2 + 4 + uVar3 * 0x1c)))) {
|
|
savedBlendMode0 = g_graphicsManager_blendMode[0];
|
|
savedBlendMode1 = g_graphicsManager_blendMode[1];
|
|
savedBlendMode2 = g_graphicsManager_blendMode[2];
|
|
savedBlendMode3 = g_graphicsManager_blendMode[3];
|
|
savedBlendMode4 = g_graphicsManager_blendMode[4];
|
|
set_blend_mode(&DAT_00c798e0,1);
|
|
uVar3 = g_graphicsManager_flags & 0xfffffffd;
|
|
font = &g_manager->_font9_PFTempestaSevenCondensedAgain;
|
|
local_20 = g_screenWidth * 0.5;
|
|
local_14 = (float)(*GHIDRA_CAST<int *>((in_ECX + 0x2c)) * 7);
|
|
local_24 = *GHIDRA_CAST<float *>((in_ECX + 0x24));
|
|
g_graphicsManager_flags = uVar3;
|
|
dVar6 = floor((double)local_20);
|
|
fVar1 = local_14;
|
|
centerX = (float)dVar6;
|
|
iVar2 = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(local_24) + 0x18 + GHIDRA_INT(local_14) * 4));
|
|
local_20 = 0.0;
|
|
if (0 < iVar2) {
|
|
lineHeight = textScale * 12.0;
|
|
lineText = GHIDRA_CAST<undefined4 *>((GHIDRA_INT(local_24) + (GHIDRA_INT(local_14) + 2) * 4));
|
|
local_14 = g_screenHeight - (float)(iVar2 + 1) * 12.0 * textScale;
|
|
do {
|
|
fVar5 = textScale;
|
|
iVar2 = (GHIDRA_CAST<Font *>((font)))->Font::get_string_width_utf16(GHIDRA_CAST<short *>(*lineText),-1);
|
|
halfLineWidth =
|
|
(float)((double)iVar2 + __uint_to_double_fixup[-(iVar2 >> 0x1f)]) * fVar5 * 0.5;
|
|
dVar6 = floor((double)halfLineWidth);
|
|
halfLineWidth = (float)dVar6;
|
|
fVar5 = centerX - halfLineWidth;
|
|
drawSettings = 0;
|
|
local_74 = 0xffff;
|
|
local_70 = 0;
|
|
local_6c = 0x3f800000;
|
|
local_68 = 0xffffffff;
|
|
local_64 = 0;
|
|
local_60 = 0;
|
|
local_8 = 0;
|
|
(GHIDRA_CAST<KColor *>((&textColor)))->KColor::SetFromARGB(0xffffffff);
|
|
Font::draw_string_wide
|
|
(font,GHIDRA_CAST<short *>(*lineText),fVar5,local_14,textScale,textScale,color,&drawSettings)
|
|
;
|
|
lineText = lineText + 1;
|
|
local_14 = lineHeight + local_14;
|
|
local_20 = (float)(GHIDRA_INT(local_20) + 1);
|
|
local_8 = 0xffffffff;
|
|
} while (GHIDRA_INT(local_20) < *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(local_24) + 0x18 + GHIDRA_INT(fVar1) * 4)));
|
|
uVar3 = g_graphicsManager_flags;
|
|
}
|
|
g_graphicsManager_flags = uVar3 | 2;
|
|
g_graphicsManager_blendMode[0] = savedBlendMode0;
|
|
g_graphicsManager_blendMode[1] = savedBlendMode1;
|
|
g_graphicsManager_blendMode[2] = savedBlendMode2;
|
|
g_graphicsManager_blendMode[3] = savedBlendMode3;
|
|
g_graphicsManager_blendMode[4] = savedBlendMode4;
|
|
}
|
|
}
|
|
ExceptionList = local_10;
|
|
return;
|
|
}
|