#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((GHIDRA_CAST(this) + 4)) & 1) == 0) && (KAGE_LogMessage(0x10,GHIDRA_CAST("Sound manager has not been initialized\n")), (*GHIDRA_CAST((GHIDRA_CAST(this) + 4)) & 1) == 0)) { *GHIDRA_CAST(outSound) = 0; *GHIDRA_CAST((GHIDRA_CAST(outSound) + 4)) = 0; emptySourceRef = operator_new(0x18); local_8 = 1; _isStream = emptySourceRef; if (emptySourceRef == GHIDRA_CAST(0x0)) { emptySourceRef = GHIDRA_CAST(0x0); } else { (GHIDRA_CAST((emptySourceRef)))->ReferenceCountBase::ReferenceCountBase(); *GHIDRA_CAST(emptySourceRef) = ReferenceCount::vftable; *GHIDRA_CAST((emptySourceRef + 0x14)) = 0; } local_8 = local_8 & 0xffffff00; if (((*GHIDRA_CAST((GHIDRA_CAST(outSound) + 4)) != GHIDRA_CAST(0x0)) && (cVar2 = (**(code **)(**GHIDRA_CAST((GHIDRA_CAST(outSound) + 4)) + 0xc))(), cVar2 != '\0')) && (g_soundReleaseFn != (void *)0x0)) { (*g_soundReleaseFn)(outSound); } *GHIDRA_CAST((GHIDRA_CAST(outSound) + 4)) = emptySourceRef; *GHIDRA_CAST(outSound) = 0; ExceptionList = local_10; return outSound; } (**(code **)(*GHIDRA_CAST(this) + 0x28))(&sourcePtr,path,fileSource,uVar3); local_8 = 2; fileSource = sourcePtr; if (sourcePtr == GHIDRA_CAST(0x0)) { fileSource = (void *)0x0; } else if (isStream == 0) { FUN_008f2d20(&sourcePtr); local_14 = 1; local_8 = 3; if (local_1c == GHIDRA_CAST(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(path),".wav"); if (pcVar4 == GHIDRA_CAST(0x0)) { pcVar4 = strstr(GHIDRA_CAST(path),".ogg"); if (pcVar4 == GHIDRA_CAST(0x0)) { pcVar4 = strstr(GHIDRA_CAST(path),".org"); if (pcVar4 == GHIDRA_CAST(0x0)) { KAGE_LogMessage(8,GHIDRA_CAST("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((GHIDRA_CAST(&(local_8)) + 0x0))) = 0xb; if (newSource == GHIDRA_CAST(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((GHIDRA_CAST(&(local_8)) + 0x0))) = 0xc; if (newSource == GHIDRA_CAST(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((GHIDRA_CAST(&(local_8)) + 0x0))) = 6; if (newSource == GHIDRA_CAST(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((GHIDRA_CAST(&(local_8)) + 0x0))) = 7; if (newSource == GHIDRA_CAST(0x0)) goto LAB_00a2b5b3; FUN_00aa0110(); *newSource = KAGE::Sound::StreamSourceOgg::vftable; newSource[0x25] = 0; *GHIDRA_CAST((newSource + 0x29)) = 0; newSource[0x28] = KAGE::Mutex::vftable; newSource[0x2a] = 0; newSource[0x2b] = 0; newSource[0x2f] = 0; newSource[0x30] = 0xf; *GHIDRA_CAST((newSource + 0x2b)) = 0; (*GHIDRA_CAST((GHIDRA_CAST(&(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((GHIDRA_CAST(&(local_8)) + 0x0))) = 4; if (newSource == GHIDRA_CAST(0x0)) { LAB_00a2b5b3: newSource = GHIDRA_CAST(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((GHIDRA_CAST(&(local_8)) + 0x0))) = 5; if (newSource == GHIDRA_CAST(0x0)) goto LAB_00a2b5b3; FUN_00aa0110(); *newSource = KAGE::Sound::StreamSourceWav::vftable; } local_8 = CONCAT31((*GHIDRA_CAST((GHIDRA_CAST(&(local_8)) + 0x1))),2); KAGE::SmartPointer::reset(newSource); LAB_00a2b5c2: if ((((isStream == 0) || (fileSource == (void *)0x0)) || ((pvVar1 != (void *)0x0 || (cVar2 = (**(code **)(*GHIDRA_CAST(fileSource) + 0x20))(sourcePtr), cVar2 == '\0')))) && (cVar2 = (**(code **)(*sourcePtr + 0x1c))(path), cVar2 == '\0')) { KAGE::SmartPointer::reset(0); KAGE_LogMessage(1,GHIDRA_CAST("Failed to open %s \")%s\"\n"); } else { sourcePtr[1] = GHIDRA_INT(pvVar1); if (path == GHIDRA_CAST(0x0)) { pcVar4 = GHIDRA_CAST(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(path),(size_t)(pathEnd + (1 - GHIDRA_INT((path + 1))))); } soundSource = sourcePtr; sourcePtr[3] = GHIDRA_INT(pcVar4); uVar3 = KAGE_Filesys_FileManager::GetPrimaryFilePathHash(GHIDRA_CAST(sourcePtr[3])); pvVar1 = local_18; soundSource[4] = uVar3; (**(code **)(*GHIDRA_CAST((GHIDRA_CAST(local_18) + 0x10)) + 0xc))(0xffffffff); pathHash = sourcePtr[4]; FUN_008f2d20(&sourcePtr); (*GHIDRA_CAST((GHIDRA_CAST(&(local_8)) + 0x0))) = 0xd; FUN_00a2bd60(&isStream,&pathHash); (*GHIDRA_CAST((GHIDRA_CAST(&(local_8)) + 0x0))) = 0xe; if (((local_24 != GHIDRA_CAST(0x0)) && (cVar2 = (**(code **)(*local_24 + 0xc))(), cVar2 != '\0')) && (g_soundReleaseFn != (void *)0x0)) { (*g_soundReleaseFn)(local_28); } local_8 = CONCAT31((*GHIDRA_CAST((GHIDRA_CAST(&(local_8)) + 0x1))),2); (**(code **)(*GHIDRA_CAST((GHIDRA_CAST(pvVar1) + 0x10)) + 0x10))(); } FUN_008f2d20(&sourcePtr); local_14 = 1; local_8 = 0xf; if (((local_1c == GHIDRA_CAST(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; }