rodecomp/Source/Resource/Audio/WaveResource.cpp
ragnarok-clanker e168b4e4a6 Restore translation-unit ownership and publish verified source corrections
Owner-authorized source migration: 31 helper-only translation units were merged into their callers or existing inline headers; both build manifests updated. Includes the preserved source payload, Lua configuration matching wowdecomp, and exact malloca expansion without diagnostic pragmas.

449 native units compiled locally and 449 staged units compiled by the pinned server toolchain. No previously byte-matched function regressed. Compiler mapping diagnostics remain recorded as needs_cleanup, not accepted or peer-confirmed. Existing independent review records are preserved. README.md is intentionally unchanged.
2026-10-25 15:42:21 +00:00

90 lines
2 KiB
C++

#include "Client/Application/ErrorDialog.h"
#include "Resource/Bitmap/BitmapResource.h"
#include "Resource/Audio/MilesRuntime.h"
#include "Resource/ResourceMgr.h"
#include "Resource/Audio/WaveResource.h"
#include <cstdlib>
#include <cstring>
#include <string>
// OFFSET: 0x007618D0
// FUNCTION: fn_08070
CWave::CWave(WaveResourceContext& context) : data(nullptr), milesAllocated(0), m_context(&context) {
}
// INLINED
CWave::~CWave() = default;
// OFFSET: 0x007613D0
// FUNCTION: fn_08066
CWave* CWave::Create() {
return new CWave(*this->m_context);
}
// OFFSET: 0x00761470
// FUNCTION: fn_08067
bool CWave::Load(const char* name) {
auto& context = *this->m_context;
auto& file = context.file;
if (!file.Open(name)) {
const std::string message = std::string("Wave :: Cannot find File : ") + name;
ShowErrorDialog(context.renderSystem, message.c_str(), 0);
file.Close();
return false;
}
const std::size_t size = static_cast<std::size_t>(file.Size());
this->Unload();
void* raw = std::malloc(size);
std::memcpy(raw, file.Data(), size);
file.Close();
auto& miles = MilesRuntime::Get();
const int type = miles.fileType(raw, static_cast<unsigned>(size));
if (type == 2) {
MilesSoundInfo info{};
this->milesAllocated = 1;
miles.wavInfo(raw, &info);
miles.decompressADPCM(&info, &this->data, nullptr);
std::free(raw);
return true;
}
if (type == 13) {
this->milesAllocated = 1;
miles.decompressASI(raw, static_cast<unsigned>(size), name, &this->data, nullptr, nullptr);
std::free(raw);
return true;
}
this->data = raw;
return true;
}
// OFFSET: 0x00761830
// FUNCTION: fn_08068
void CWave::Unload() {
if (this->data != nullptr) {
if (this->milesAllocated != 0) {
MilesRuntime::Get().freeLocked(this->data);
this->milesAllocated = 0;
return;
}
std::free(this->data);
}
this->milesAllocated = 0;
}
// INLINED
void RegisterWaveResource(ResourceMgr& resourceMgr, CWave& prototype) {
resourceMgr.Register("wav", "wav\\", &prototype);
}