Beta matching LegoCacheSound (#1379)

This commit is contained in:
MS
2025-01-29 10:41:50 -05:00
committed by GitHub
parent 29bf588870
commit dad44535bd
2 changed files with 72 additions and 39 deletions

View File

@@ -7,6 +7,7 @@
#include "mxstring.h" #include "mxstring.h"
// VTABLE: LEGO1 0x100d4718 // VTABLE: LEGO1 0x100d4718
// VTABLE: BETA10 0x101bb6f0
// SIZE 0x88 // SIZE 0x88
class LegoCacheSound : public MxCore { class LegoCacheSound : public MxCore {
public: public:
@@ -49,12 +50,13 @@ public:
void MuteStop(MxBool p_mute); void MuteStop(MxBool p_mute);
// SYNTHETIC: LEGO1 0x10006610 // SYNTHETIC: LEGO1 0x10006610
// SYNTHETIC: BETA10 0x100675b0
// LegoCacheSound::`scalar deleting destructor' // LegoCacheSound::`scalar deleting destructor'
private: private:
void Init(); void Init();
void CopyData(MxU8* p_data, MxU32 p_dataSize); void CopyData(MxU8* p_data, MxU32 p_dataSize);
MxString FUN_10006d80(const MxString& p_str); MxString GetBaseFilename(MxString& p_path);
LPDIRECTSOUNDBUFFER m_dsBuffer; // 0x08 LPDIRECTSOUNDBUFFER m_dsBuffer; // 0x08
undefined m_unk0x0c[4]; // 0x0c undefined m_unk0x0c[4]; // 0x0c

View File

@@ -4,31 +4,36 @@
#include "misc.h" #include "misc.h"
#include "mxomni.h" #include "mxomni.h"
#include <assert.h>
DECOMP_SIZE_ASSERT(LegoCacheSound, 0x88) DECOMP_SIZE_ASSERT(LegoCacheSound, 0x88)
// FUNCTION: LEGO1 0x100064d0 // FUNCTION: LEGO1 0x100064d0
// FUNCTION: BETA10 0x10066340
LegoCacheSound::LegoCacheSound() LegoCacheSound::LegoCacheSound()
{ {
Init(); Init();
} }
// FUNCTION: LEGO1 0x10006630 // FUNCTION: LEGO1 0x10006630
// FUNCTION: BETA10 0x100663f3
LegoCacheSound::~LegoCacheSound() LegoCacheSound::~LegoCacheSound()
{ {
Destroy(); Destroy();
} }
// FUNCTION: LEGO1 0x100066d0 // FUNCTION: LEGO1 0x100066d0
// FUNCTION: BETA10 0x10066498
void LegoCacheSound::Init() void LegoCacheSound::Init()
{ {
m_dsBuffer = NULL; m_dsBuffer = NULL;
m_data = NULL; m_data = NULL;
m_unk0x58 = FALSE; m_unk0x58 = FALSE;
memset(&m_wfx, 0, sizeof(m_wfx)); memset(&m_wfx, 0, sizeof(m_wfx));
m_unk0x6a = FALSE;
m_unk0x70 = FALSE;
m_looping = TRUE; m_looping = TRUE;
m_unk0x6a = FALSE;
m_volume = 79; m_volume = 79;
m_unk0x70 = FALSE;
m_muted = FALSE; m_muted = FALSE;
} }
@@ -42,6 +47,8 @@ MxResult LegoCacheSound::Create(
MxU32 p_dataSize MxU32 p_dataSize
) )
{ {
assert(p_pwfx);
WAVEFORMATEX wfx; WAVEFORMATEX wfx;
wfx.wFormatTag = p_pwfx->wf.wFormatTag; wfx.wFormatTag = p_pwfx->wf.wFormatTag;
wfx.nChannels = p_pwfx->wf.nChannels; wfx.nChannels = p_pwfx->wf.nChannels;
@@ -86,7 +93,7 @@ MxResult LegoCacheSound::Create(
CopyData(p_data, p_dataSize); CopyData(p_data, p_dataSize);
} }
m_unk0x48 = FUN_10006d80(p_mediaSrcPath); m_unk0x48 = GetBaseFilename(p_mediaSrcPath);
m_wfx = *p_pwfx; m_wfx = *p_pwfx;
return SUCCESS; return SUCCESS;
} }
@@ -95,6 +102,9 @@ MxResult LegoCacheSound::Create(
// FUNCTION: BETA10 0x100667a0 // FUNCTION: BETA10 0x100667a0
void LegoCacheSound::CopyData(MxU8* p_data, MxU32 p_dataSize) void LegoCacheSound::CopyData(MxU8* p_data, MxU32 p_dataSize)
{ {
assert(p_data);
assert(p_dataSize);
delete[] m_data; delete[] m_data;
m_dataSize = p_dataSize; m_dataSize = p_dataSize;
m_data = new MxU8[m_dataSize]; m_data = new MxU8[m_dataSize];
@@ -102,6 +112,7 @@ void LegoCacheSound::CopyData(MxU8* p_data, MxU32 p_dataSize)
} }
// FUNCTION: LEGO1 0x10006920 // FUNCTION: LEGO1 0x10006920
// FUNCTION: BETA10 0x1006685b
void LegoCacheSound::Destroy() void LegoCacheSound::Destroy()
{ {
if (m_dsBuffer) { if (m_dsBuffer) {
@@ -119,19 +130,24 @@ void LegoCacheSound::Destroy()
LegoCacheSound* LegoCacheSound::Clone() LegoCacheSound* LegoCacheSound::Clone()
{ {
LegoCacheSound* pnew = new LegoCacheSound(); LegoCacheSound* pnew = new LegoCacheSound();
assert(pnew);
if (pnew->Create(&m_wfx, m_unk0x48, m_volume, m_data, m_dataSize) == SUCCESS) { MxResult result = pnew->Create(&m_wfx, m_unk0x48, m_volume, m_data, m_dataSize);
if (result == SUCCESS) {
return pnew; return pnew;
} }
else {
delete pnew; delete pnew;
return NULL; return NULL;
} }
}
// FUNCTION: LEGO1 0x10006a30 // FUNCTION: LEGO1 0x10006a30
// FUNCTION: BETA10 0x10066a23 // FUNCTION: BETA10 0x10066a23
MxResult LegoCacheSound::Play(const char* p_name, MxBool p_looping) MxResult LegoCacheSound::Play(const char* p_name, MxBool p_looping)
{ {
assert(m_dsBuffer);
if (m_data == NULL || m_dataSize == 0) { if (m_data == NULL || m_dataSize == 0) {
return FAILURE; return FAILURE;
} }
@@ -162,11 +178,20 @@ MxResult LegoCacheSound::Play(const char* p_name, MxBool p_looping)
memcpy(pvAudioPtr2, m_data + dwAudioBytes1, dwAudioBytes2); memcpy(pvAudioPtr2, m_data + dwAudioBytes1, dwAudioBytes2);
} }
m_dsBuffer->Unlock(pvAudioPtr1, dwAudioBytes1, pvAudioPtr2, dwAudioBytes2); DWORD sts = m_dsBuffer->Unlock(pvAudioPtr1, dwAudioBytes1, pvAudioPtr2, dwAudioBytes2);
assert(!sts);
m_dsBuffer->SetCurrentPosition(0); m_dsBuffer->SetCurrentPosition(0);
m_dsBuffer->Play(0, 0, p_looping); if (m_dsBuffer->Play(0, 0, p_looping)) {
assert(0);
} }
} }
else {
assert(0);
}
}
else {
assert(0);
}
if (p_looping == FALSE) { if (p_looping == FALSE) {
m_looping = FALSE; m_looping = FALSE;
@@ -181,6 +206,7 @@ MxResult LegoCacheSound::Play(const char* p_name, MxBool p_looping)
} }
// FUNCTION: LEGO1 0x10006b80 // FUNCTION: LEGO1 0x10006b80
// FUNCTION: BETA10 0x10066ca3
void LegoCacheSound::Stop() void LegoCacheSound::Stop()
{ {
DWORD dwStatus; DWORD dwStatus;
@@ -200,6 +226,7 @@ void LegoCacheSound::Stop()
} }
// FUNCTION: LEGO1 0x10006be0 // FUNCTION: LEGO1 0x10006be0
// FUNCTION: BETA10 0x10066d23
void LegoCacheSound::FUN_10006be0() void LegoCacheSound::FUN_10006be0()
{ {
if (!m_looping) { if (!m_looping) {
@@ -226,15 +253,17 @@ void LegoCacheSound::FUN_10006be0()
} }
} }
if (m_unk0x74.GetLength() != 0 && !m_muted) { if (m_unk0x74.GetLength() == 0) {
if (!m_sound.UpdatePosition(m_dsBuffer)) {
if (m_unk0x6a) {
return; return;
} }
if (!m_muted) {
if (!m_sound.UpdatePosition(m_dsBuffer)) {
if (!m_unk0x6a) {
m_dsBuffer->Stop(); m_dsBuffer->Stop();
m_unk0x6a = TRUE; m_unk0x6a = TRUE;
} }
}
else if (m_unk0x6a) { else if (m_unk0x6a) {
m_dsBuffer->Play(0, 0, m_looping); m_dsBuffer->Play(0, 0, m_looping);
m_unk0x6a = FALSE; m_unk0x6a = FALSE;
@@ -243,12 +272,14 @@ void LegoCacheSound::FUN_10006be0()
} }
// FUNCTION: LEGO1 0x10006cb0 // FUNCTION: LEGO1 0x10006cb0
// FUNCTION: BETA10 0x10066e85
void LegoCacheSound::SetDistance(MxS32 p_min, MxS32 p_max) void LegoCacheSound::SetDistance(MxS32 p_min, MxS32 p_max)
{ {
m_sound.SetDistance(p_min, p_max); m_sound.SetDistance(p_min, p_max);
} }
// FUNCTION: LEGO1 0x10006cd0 // FUNCTION: LEGO1 0x10006cd0
// FUNCTION: BETA10 0x10066eb0
void LegoCacheSound::FUN_10006cd0(undefined4, undefined4) void LegoCacheSound::FUN_10006cd0(undefined4, undefined4)
{ {
} }
@@ -288,33 +319,33 @@ void LegoCacheSound::MuteStop(MxBool p_muted)
// FUNCTION: LEGO1 0x10006d80 // FUNCTION: LEGO1 0x10006d80
// FUNCTION: BETA10 0x100670e7 // FUNCTION: BETA10 0x100670e7
MxString LegoCacheSound::FUN_10006d80(const MxString& p_str) MxString LegoCacheSound::GetBaseFilename(MxString& p_path)
{ {
// TODO: Clean up code // Get the base filename from the given path
char* str = p_str.GetData(); // e.g. "Z:\Lego\Audio\test.wav" --> "test"
MxU32 length = strlen(str); char* str = p_path.GetData();
char* local28 = str + length; // Start at the end of the string and work backwards.
char* local14 = local28; char* p = str + strlen(str);
char* pVar1 = local28; char* end = p;
do { while (str != p--) {
local14 = pVar1; // If the file has an extension, we want to exclude it from the output.
pVar1 = local14 + -1; // Set this as our new end position.
if (*p == '.') {
end = p;
}
if (str == local14) { // Stop if we hit a directory or drive letter.
if (*p == '\\') {
break; break;
} }
if (*pVar1 == '.') {
local28 = pVar1;
} }
} while (*pVar1 != '\\');
local14 = pVar1; MxString output;
// Increment by one to shift p to the start of the filename.
MxString local24; char* x = ++p;
local14++; // If end points to the dot in filename, change it to a null terminator.
*local28 = '\0'; x[end - p] = '\0';
return local24 = local14; return output = x;
} }