rodecomp/Source/Resource/Audio/WaveResource.cpp
ragnarok-clanker 81638d8434 Decompile fn_08068 (CWave::Unload)
Batch #17819 by eAthena: 0 byte-identical, 1 confirmed by peer review.

- fn_08068 CWave::Unload: logic confirmed by peer review

Peer-reviewed-by: alisonrag, cremane, bibinir
Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes).
2026-11-12 04:00:33 +00:00

96 lines
2 KiB
C++

#include "Client/Application/ErrorDialog.h"
#include "File/File.h"
#include "Render/DeviceContext/DCSurface.h"
#include "Resource/Audio/MilesRuntime.h"
#include "Resource/ResourceMgr.h"
#include "Resource/Audio/WaveResource.h"
#include <cstdlib>
#include <new>
#include <string>
// OFFSET: 0x007618D0
// FUNCTION: fn_08070
CWave::CWave() : data(nullptr), milesAllocated(0) {
}
// INLINED
CWave::~CWave() = default;
// OFFSET: 0x007613D0
// FUNCTION: fn_08066
CWave* CWave::Create() {
return new CWave;
}
// OFFSET: 0x00761470
// FUNCTION: fn_08067
bool CWave::Load(const char* name) {
CFile file;
if (!file.Open(name, 0, true, false)) {
ShowErrorDialog((std::string("Wave :: Cannot find File : ") + std::string(name)).c_str(), 0);
return false;
}
const std::uint32_t size = file.GetSize();
this->Unload();
void* raw = ::operator new(size);
file.Read(raw, size);
file.Close();
auto& miles = MilesRuntime::Get();
const int type = miles.fileType(raw, 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, 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;
}
delete[] static_cast<char*>(this->data);
}
this->milesAllocated = 0;
}
// INLINED
void RegisterWaveResource(ResourceMgr& resourceMgr, CWave& prototype) {
resourceMgr.Register("wav", "wav\\", &prototype);
}
// INLINED
CWave::CWave(const char* extension, const char* prefix) {
ResourceMgr::Instance().Register(extension, prefix, this);
}
// GLOBAL: gl_24585
CWave g_wavePrototype("wav", "wav\\");