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>
165 lines
6.6 KiB
C++
165 lines
6.6 KiB
C++
#include "classes.h"
|
|
|
|
// 0092dc30
|
|
void SoundEffects::Play(int ID, float Volume, int FrameDelay, byte Loop, float Pitch, float Pan)
|
|
{
|
|
char cVar1;
|
|
uint uVar2;
|
|
SoundEffect SVar3;
|
|
SoundEffect *sound;
|
|
undefined3 in_stack_00000011;
|
|
undefined1 newInstance [8];
|
|
void *local_10;
|
|
undefined1 *puStack_c;
|
|
undefined4 local_8;
|
|
SoundEffect sampleCount;
|
|
code *trap;
|
|
float volumeModifier;
|
|
|
|
local_8 = 0xffffffff;
|
|
puStack_c = &LAB_00b0abe9;
|
|
local_10 = ExceptionList;
|
|
ExceptionList = &local_10;
|
|
if ((*GHIDRA_CAST<int *>((*GHIDRA_CAST<int *>(ThreadLocalStoragePointer) + 0xc)) < DAT_00c94050) &&
|
|
(_Init_thread_header(&DAT_00c94050,__security_cookie ^ GHIDRA_UINT((newInstance + 0x14))),
|
|
DAT_00c94050 == -1)) {
|
|
_DAT_00c5d2a4 = 0x1b00000005;
|
|
DAT_00c5d2ac = 8;
|
|
_atexit(GHIDRA_CAST<_func_4879 *>(&DAT_00b166d0));
|
|
local_8 = 0xffffffff;
|
|
_Init_thread_footer(&DAT_00c94050);
|
|
}
|
|
if ((-1 < ID) && (ID < (GHIDRA_INT((this->_sounds)._end) - GHIDRA_INT((this->_sounds)._begin)) / 0x1b8)) {
|
|
sound = GHIDRA_CAST<SoundEffect *>((ID * 0x1b8 + GHIDRA_INT((this->_sounds)._begin)));
|
|
if (sound[100] == (SoundEffect)0x0) {
|
|
KAGE_LogMessage(1,GHIDRA_CAST<byte *>("[warn] Sound %d has no samples.\n"));
|
|
ExceptionList = local_10;
|
|
return;
|
|
}
|
|
if (*GHIDRA_CAST<char *>((sound + 0x66)) == '\0') {
|
|
(GHIDRA_CAST<SoundEffect *>((sound)))->SoundEffect::Load();
|
|
KAGE_LogMessage(1,GHIDRA_CAST<byte *>("[warn] Sound %d was not preloaded.\n"));
|
|
*GHIDRA_CAST<int *>(&(*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>((this)) + 0xc)))) = *GHIDRA_CAST<int *>(&(*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>((this)) + 0xc)))) + 1;
|
|
}
|
|
SVar3 = (SoundEffect)(g_manager->_framecount >> 1);
|
|
if ((GHIDRA_INT(sound[1]) <= GHIDRA_INT(SVar3)) || (GHIDRA_INT(sound[1]) < 0)) {
|
|
sampleCount = sound[100];
|
|
sound[0x65] = (SoundEffect)Volume;
|
|
*sound = SVar3;
|
|
sound[1] = (SoundEffect)(FrameDelay + GHIDRA_INT(SVar3));
|
|
if ((DAT_00c5d2a0 == 0) &&
|
|
(KAGE_LogMessage(0x10,GHIDRA_CAST<byte *>("RNG Seed is zero!\n")), DAT_00c5d2a0 == 0)) {
|
|
trap = (code *)swi(3);
|
|
(*trap)();
|
|
return;
|
|
}
|
|
uVar2 = DAT_00c5d2a0 >> ((byte)_DAT_00c5d2a4 & 0x1f) ^ DAT_00c5d2a0;
|
|
uVar2 = uVar2 << ((byte)((ulonglong)_DAT_00c5d2a4 >> 0x20) & 0x1f) ^ uVar2;
|
|
DAT_00c5d2a0 = uVar2 >> ((byte)DAT_00c5d2ac & 0x1f) ^ uVar2;
|
|
uVar2 = 0;
|
|
if (sampleCount != (SoundEffect)0x0) {
|
|
uVar2 = DAT_00c5d2a0 % GHIDRA_UINT(sampleCount);
|
|
}
|
|
if (*GHIDRA_CAST<char *>((sound + uVar2 * 0xe + 0xe)) != '\0') {
|
|
if ((sound[uVar2 * 0xe + 8] != (SoundEffect)0x0) &&
|
|
(cVar1 = (**(code **)(*GHIDRA_CAST<int *>(sound[uVar2 * 0xe + 8]) + 0x28))(), cVar1 != '\0')) {
|
|
FUN_00a2abd0();
|
|
}
|
|
SVar3 = (SoundEffect)(sound + uVar2 * 0xe + 2);
|
|
if (0xf < GHIDRA_UINT(sound[uVar2 * 0xe + 7])) {
|
|
SVar3 = sound[uVar2 * 0xe + 2];
|
|
}
|
|
(**(code **)(PTR_vftable_00c5aaa0 + 0x24))(newInstance,SVar3,1,0);
|
|
local_8 = 1;
|
|
(GHIDRA_CAST<SoundInstance *>((sound + uVar2 * 0xe + 8)))->SoundInstance::assign(newInstance);
|
|
local_8 = 0xffffffff;
|
|
FUN_007e2740();
|
|
}
|
|
*GHIDRA_CAST<byte *>((sound + uVar2 * 0xe + 10)) = Loop;
|
|
if (sound[uVar2 * 0xe + 8] != (SoundEffect)0x0) {
|
|
(**(code **)(*GHIDRA_CAST<int *>(sound[uVar2 * 0xe + 8]) + 0x40))(_Loop);
|
|
}
|
|
sound[uVar2 * 0xe + 0xd] = (SoundEffect)Pitch;
|
|
if (sound[uVar2 * 0xe + 8] != (SoundEffect)0x0) {
|
|
(**(code **)(*GHIDRA_CAST<int *>(sound[uVar2 * 0xe + 8]) + 0x58))(Pitch);
|
|
}
|
|
volumeModifier = this->_volumeModifier;
|
|
if (volumeModifier <= 0.0) {
|
|
volumeModifier = 0.0;
|
|
}
|
|
SVar3 = (SoundEffect)(volumeModifier * Volume * (g_manager->_optionsConfig)._sfxVolume);
|
|
if (1.0 <= (float)SVar3) {
|
|
SVar3 = (SoundEffect)0x3f800000;
|
|
}
|
|
sound[uVar2 * 0xe + 0xb] = SVar3;
|
|
if (sound[uVar2 * 0xe + 8] != (SoundEffect)0x0) {
|
|
(**(code **)(*GHIDRA_CAST<int *>(sound[uVar2 * 0xe + 8]) + 0x48))(SVar3);
|
|
if (sound[uVar2 * 0xe + 8] != (SoundEffect)0x0) {
|
|
(**(code **)(*GHIDRA_CAST<int *>(sound[uVar2 * 0xe + 8]) + 0x2c))(1);
|
|
*GHIDRA_CAST<undefined2 *>(&(*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(sound[uVar2 * 0xe + 10])) + 0x1)))) = 1;
|
|
}
|
|
}
|
|
FUN_00a2ac20();
|
|
}
|
|
}
|
|
ExceptionList = local_10;
|
|
return;
|
|
}
|
|
|
|
// 0092e430
|
|
void SoundEffects::ClearVolumeModifier()
|
|
{
|
|
char isPlaying;
|
|
void *sounds;
|
|
int iVar1;
|
|
int iVar2;
|
|
float volume;
|
|
uint soundIndex;
|
|
uint voiceIndex;
|
|
int *source;
|
|
|
|
soundIndex = 0;
|
|
sounds = (this->_sounds)._begin;
|
|
iVar1 = GHIDRA_INT((this->_sounds)._end) - GHIDRA_INT(sounds);
|
|
iVar2 = iVar1 >> 0x1f;
|
|
if (iVar1 / 0x1b8 + iVar2 != iVar2) {
|
|
iVar2 = 0;
|
|
do {
|
|
voiceIndex = 0;
|
|
if (*GHIDRA_CAST<int *>((iVar2 + 400 + GHIDRA_INT(sounds))) != 0) {
|
|
iVar1 = iVar2;
|
|
do {
|
|
if ((*GHIDRA_CAST<char *>((iVar2 + 0x198 + GHIDRA_INT(sounds))) != '\0') &&
|
|
(source = *GHIDRA_CAST<int **>((iVar1 + 0x20 + GHIDRA_INT(sounds))), source != GHIDRA_CAST<int *>(0x0))) {
|
|
if ((*GHIDRA_CAST<char *>((iVar1 + 0x29 + GHIDRA_INT(sounds))) != '\0') &&
|
|
(isPlaying = (**(code **)(*source + 0x38))(), isPlaying != '\0')) {
|
|
*GHIDRA_CAST<undefined1 *>((iVar1 + 0x29 + GHIDRA_INT(sounds))) = 0;
|
|
}
|
|
isPlaying = (**(code **)(**GHIDRA_CAST<int **>((iVar1 + 0x20 + GHIDRA_INT(sounds))) + 0x38))();
|
|
if ((isPlaying != '\0') || (*GHIDRA_CAST<char *>((iVar1 + 0x29 + GHIDRA_INT(sounds))) != '\0')) {
|
|
volume = this->_volumeModifier;
|
|
sounds = (this->_sounds)._begin;
|
|
if (volume <= 0.0) {
|
|
volume = 0.0;
|
|
}
|
|
volume = volume * *GHIDRA_CAST<float *>((iVar2 + 0x194 + GHIDRA_INT(sounds))) *
|
|
(g_manager->_optionsConfig)._sfxVolume;
|
|
*GHIDRA_CAST<float *>((iVar1 + 0x2c + GHIDRA_INT(sounds))) = volume;
|
|
source = *GHIDRA_CAST<int **>((iVar1 + 0x20 + GHIDRA_INT(sounds)));
|
|
if (source != GHIDRA_CAST<int *>(0x0)) {
|
|
(**(code **)(*source + 0x48))(volume);
|
|
}
|
|
}
|
|
}
|
|
iVar1 = iVar1 + 0x38;
|
|
voiceIndex = voiceIndex + 1;
|
|
sounds = (this->_sounds)._begin;
|
|
} while (voiceIndex < *GHIDRA_CAST<uint *>((iVar2 + 400 + GHIDRA_INT(sounds))));
|
|
}
|
|
soundIndex = soundIndex + 1;
|
|
iVar2 = iVar2 + 0x1b8;
|
|
} while (soundIndex < GHIDRA_UINT(((GHIDRA_INT((this->_sounds)._end) - GHIDRA_INT(sounds)) / 0x1b8)));
|
|
}
|
|
return;
|
|
}
|