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>
244 lines
8.8 KiB
C++
244 lines
8.8 KiB
C++
#include "classes.h"
|
|
|
|
// 00a2b1e0
|
|
void * SoundManager::load_sound(void *outSound, byte *path, void *fileSource, byte isStream)
|
|
{
|
|
void *pvVar1;
|
|
char cVar2;
|
|
uint uVar3;
|
|
ReferenceCountBase *emptySourceRef;
|
|
char *pcVar4;
|
|
undefined4 *newSource;
|
|
byte *pathEnd;
|
|
undefined3 in_stack_00000011;
|
|
int pathHash;
|
|
undefined1 local_28 [4];
|
|
int *local_24;
|
|
int *sourcePtr;
|
|
int *local_1c;
|
|
void *local_18;
|
|
undefined4 local_14;
|
|
void *local_10;
|
|
undefined1 *puStack_c;
|
|
undefined4 local_8;
|
|
code *mutexInitFn;
|
|
byte pathChar;
|
|
int *soundSource;
|
|
|
|
pvVar1 = fileSource;
|
|
local_8 = 0xffffffff;
|
|
puStack_c = &LAB_00b12184;
|
|
local_10 = ExceptionList;
|
|
uVar3 = __security_cookie ^ GHIDRA_UINT((local_28 + 0x24));
|
|
ExceptionList = &local_10;
|
|
local_14 = 0;
|
|
local_18 = this;
|
|
if (((*GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(this) + 4)) & 1) == 0) &&
|
|
(KAGE_LogMessage(0x10,GHIDRA_CAST<byte *>("Sound manager has not been initialized\n")),
|
|
(*GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(this) + 4)) & 1) == 0)) {
|
|
*GHIDRA_CAST<undefined4 *>(outSound) = 0;
|
|
*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(outSound) + 4)) = 0;
|
|
emptySourceRef = operator_new(0x18);
|
|
local_8 = 1;
|
|
_isStream = emptySourceRef;
|
|
if (emptySourceRef == GHIDRA_CAST<ReferenceCountBase *>(0x0)) {
|
|
emptySourceRef = GHIDRA_CAST<ReferenceCountBase *>(0x0);
|
|
}
|
|
else {
|
|
(GHIDRA_CAST<ReferenceCountBase *>((emptySourceRef)))->ReferenceCountBase::ReferenceCountBase();
|
|
*GHIDRA_CAST<undefined ***>(emptySourceRef) = ReferenceCount<KAGE::Sound::SoundSourceBase>::vftable;
|
|
*GHIDRA_CAST<undefined4 *>((emptySourceRef + 0x14)) = 0;
|
|
}
|
|
local_8 = local_8 & 0xffffff00;
|
|
if (((*GHIDRA_CAST<int **>((GHIDRA_CAST<char *>(outSound) + 4)) != GHIDRA_CAST<int *>(0x0)) &&
|
|
(cVar2 = (**(code **)(**GHIDRA_CAST<int **>((GHIDRA_CAST<char *>(outSound) + 4)) + 0xc))(), cVar2 != '\0')) &&
|
|
(g_soundReleaseFn != (void *)0x0)) {
|
|
(*g_soundReleaseFn)(outSound);
|
|
}
|
|
*GHIDRA_CAST<ReferenceCountBase **>((GHIDRA_CAST<char *>(outSound) + 4)) = emptySourceRef;
|
|
*GHIDRA_CAST<undefined4 *>(outSound) = 0;
|
|
ExceptionList = local_10;
|
|
return outSound;
|
|
}
|
|
(**(code **)(*GHIDRA_CAST<int *>(this) + 0x28))(&sourcePtr,path,fileSource,uVar3);
|
|
local_8 = 2;
|
|
fileSource = sourcePtr;
|
|
if (sourcePtr == GHIDRA_CAST<int *>(0x0)) {
|
|
fileSource = (void *)0x0;
|
|
}
|
|
else if (isStream == 0) {
|
|
FUN_008f2d20(&sourcePtr);
|
|
local_14 = 1;
|
|
local_8 = 3;
|
|
if (local_1c == GHIDRA_CAST<int *>(0x0)) {
|
|
ExceptionList = local_10;
|
|
return outSound;
|
|
}
|
|
cVar2 = (**(code **)(*local_1c + 0xc))();
|
|
if (cVar2 == '\0') {
|
|
ExceptionList = local_10;
|
|
return outSound;
|
|
}
|
|
if (g_soundReleaseFn == (void *)0x0) {
|
|
ExceptionList = local_10;
|
|
return outSound;
|
|
}
|
|
(*g_soundReleaseFn)(&sourcePtr);
|
|
ExceptionList = local_10;
|
|
return outSound;
|
|
}
|
|
pcVar4 = strstr(GHIDRA_CAST<char *>(path),".wav");
|
|
if (pcVar4 == GHIDRA_CAST<char *>(0x0)) {
|
|
pcVar4 = strstr(GHIDRA_CAST<char *>(path),".ogg");
|
|
if (pcVar4 == GHIDRA_CAST<char *>(0x0)) {
|
|
pcVar4 = strstr(GHIDRA_CAST<char *>(path),".org");
|
|
if (pcVar4 == GHIDRA_CAST<char *>(0x0)) {
|
|
KAGE_LogMessage(8,GHIDRA_CAST<byte *>("Failed to load sound \'%s\'. Unknown sound source type\n"));
|
|
FUN_008f2d20(&sourcePtr);
|
|
FUN_007e2740();
|
|
ExceptionList = local_10;
|
|
return outSound;
|
|
}
|
|
if (pvVar1 == (void *)0x0) {
|
|
newSource = operator_new(0x4c);
|
|
(*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(local_8)) + 0x0))) = 0xb;
|
|
if (newSource == GHIDRA_CAST<undefined4 *>(0x0)) goto LAB_00a2b5b3;
|
|
FUN_00a9fa20();
|
|
newSource[0x11] = 0;
|
|
newSource[0x12] = 0;
|
|
*newSource = KAGE::Sound::SampleSourceOrg::vftable;
|
|
}
|
|
else {
|
|
if (pvVar1 != (void *)0x1) goto LAB_00a2b5c2;
|
|
newSource = operator_new(0x20740);
|
|
(*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(local_8)) + 0x0))) = 0xc;
|
|
if (newSource == GHIDRA_CAST<undefined4 *>(0x0)) goto LAB_00a2b5b3;
|
|
FUN_00aa0110();
|
|
*newSource = KAGE::Sound::StreamSourceOrg::vftable;
|
|
newSource[0x81cc] = 0;
|
|
newSource[0x81cd] = 0;
|
|
memset(newSource + 0x25,0,0x2069c);
|
|
newSource[0x81ce] = 0;
|
|
newSource[0x81cf] = 0;
|
|
}
|
|
}
|
|
else if (pvVar1 == (void *)0x0) {
|
|
newSource = operator_new(0x58);
|
|
(*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(local_8)) + 0x0))) = 6;
|
|
if (newSource == GHIDRA_CAST<undefined4 *>(0x0)) goto LAB_00a2b5b3;
|
|
FUN_00a9fa20();
|
|
newSource[0x11] = 0;
|
|
newSource[0x12] = 0;
|
|
*newSource = KAGE::Sound::SampleSourceOgg::vftable;
|
|
}
|
|
else {
|
|
if (pvVar1 != (void *)0x1) goto LAB_00a2b5c2;
|
|
newSource = operator_new(0xc4);
|
|
(*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(local_8)) + 0x0))) = 7;
|
|
if (newSource == GHIDRA_CAST<undefined4 *>(0x0)) goto LAB_00a2b5b3;
|
|
FUN_00aa0110();
|
|
*newSource = KAGE::Sound::StreamSourceOgg::vftable;
|
|
newSource[0x25] = 0;
|
|
*GHIDRA_CAST<undefined1 *>((newSource + 0x29)) = 0;
|
|
newSource[0x28] = KAGE::Mutex::vftable;
|
|
newSource[0x2a] = 0;
|
|
newSource[0x2b] = 0;
|
|
newSource[0x2f] = 0;
|
|
newSource[0x30] = 0xf;
|
|
*GHIDRA_CAST<undefined1 *>((newSource + 0x2b)) = 0;
|
|
(*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(local_8)) + 0x0))) = 10;
|
|
mutexInitFn = *(code **)(newSource[0x28] + 4);
|
|
if (mutexInitFn == FUN_00a15770) {
|
|
FUN_00a15770();
|
|
newSource[0x26] = 0;
|
|
}
|
|
else {
|
|
(*mutexInitFn)();
|
|
newSource[0x26] = 0;
|
|
}
|
|
}
|
|
}
|
|
else if (pvVar1 == (void *)0x0) {
|
|
newSource = operator_new(100);
|
|
(*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(local_8)) + 0x0))) = 4;
|
|
if (newSource == GHIDRA_CAST<undefined4 *>(0x0)) {
|
|
LAB_00a2b5b3:
|
|
newSource = GHIDRA_CAST<undefined4 *>(0x0);
|
|
}
|
|
else {
|
|
FUN_00a9fa20();
|
|
newSource[0x11] = 0;
|
|
newSource[0x12] = 0;
|
|
*newSource = KAGE::Sound::SampleSourceWav::vftable;
|
|
newSource[0x14] = 0;
|
|
newSource[0x13] = 0;
|
|
}
|
|
}
|
|
else {
|
|
if (pvVar1 != (void *)0x1) goto LAB_00a2b5c2;
|
|
newSource = operator_new(0xa8);
|
|
(*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(local_8)) + 0x0))) = 5;
|
|
if (newSource == GHIDRA_CAST<undefined4 *>(0x0)) goto LAB_00a2b5b3;
|
|
FUN_00aa0110();
|
|
*newSource = KAGE::Sound::StreamSourceWav::vftable;
|
|
}
|
|
local_8 = CONCAT31((*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(local_8)) + 0x1))),2);
|
|
KAGE::SmartPointer<SoundSourceBase>::reset(newSource);
|
|
LAB_00a2b5c2:
|
|
if ((((isStream == 0) || (fileSource == (void *)0x0)) ||
|
|
((pvVar1 != (void *)0x0 ||
|
|
(cVar2 = (**(code **)(*GHIDRA_CAST<int *>(fileSource) + 0x20))(sourcePtr), cVar2 == '\0')))) &&
|
|
(cVar2 = (**(code **)(*sourcePtr + 0x1c))(path), cVar2 == '\0')) {
|
|
KAGE::SmartPointer<SoundSourceBase>::reset(0);
|
|
KAGE_LogMessage(1,GHIDRA_CAST<byte *>("Failed to open %s \")%s\"\n");
|
|
}
|
|
else {
|
|
sourcePtr[1] = GHIDRA_INT(pvVar1);
|
|
if (path == GHIDRA_CAST<byte *>(0x0)) {
|
|
pcVar4 = GHIDRA_CAST<char *>(0x0);
|
|
}
|
|
else {
|
|
pathEnd = path;
|
|
do {
|
|
pathChar = *pathEnd;
|
|
pathEnd = pathEnd + 1;
|
|
} while (pathChar != 0);
|
|
pcVar4 = operator_new_tracked(GHIDRA_UINT((pathEnd + (1 - GHIDRA_INT((path + 1))))));
|
|
pathEnd = path;
|
|
do {
|
|
pathChar = *pathEnd;
|
|
pathEnd = pathEnd + 1;
|
|
} while (pathChar != 0);
|
|
strncpy(pcVar4,GHIDRA_CAST<char *>(path),(size_t)(pathEnd + (1 - GHIDRA_INT((path + 1)))));
|
|
}
|
|
soundSource = sourcePtr;
|
|
sourcePtr[3] = GHIDRA_INT(pcVar4);
|
|
uVar3 = KAGE_Filesys_FileManager::GetPrimaryFilePathHash(GHIDRA_CAST<byte *>(sourcePtr[3]));
|
|
pvVar1 = local_18;
|
|
soundSource[4] = uVar3;
|
|
(**(code **)(*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(local_18) + 0x10)) + 0xc))(0xffffffff);
|
|
pathHash = sourcePtr[4];
|
|
FUN_008f2d20(&sourcePtr);
|
|
(*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(local_8)) + 0x0))) = 0xd;
|
|
FUN_00a2bd60(&isStream,&pathHash);
|
|
(*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(local_8)) + 0x0))) = 0xe;
|
|
if (((local_24 != GHIDRA_CAST<int *>(0x0)) && (cVar2 = (**(code **)(*local_24 + 0xc))(), cVar2 != '\0')) &&
|
|
(g_soundReleaseFn != (void *)0x0)) {
|
|
(*g_soundReleaseFn)(local_28);
|
|
}
|
|
local_8 = CONCAT31((*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(local_8)) + 0x1))),2);
|
|
(**(code **)(*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(pvVar1) + 0x10)) + 0x10))();
|
|
}
|
|
FUN_008f2d20(&sourcePtr);
|
|
local_14 = 1;
|
|
local_8 = 0xf;
|
|
if (((local_1c == GHIDRA_CAST<int *>(0x0)) || (cVar2 = (**(code **)(*local_1c + 0xc))(), cVar2 == '\0')) ||
|
|
(g_soundReleaseFn == (void *)0x0)) {
|
|
ExceptionList = local_10;
|
|
return outSound;
|
|
}
|
|
(*g_soundReleaseFn)(&sourcePtr);
|
|
ExceptionList = local_10;
|
|
return outSound;
|
|
}
|