snd_AnimSoundReader OK

This commit is contained in:
robojumper
2025-05-29 03:09:42 +02:00
parent 363fe5e17b
commit 79b2018642
4 changed files with 132 additions and 1 deletions
+4 -1
View File
@@ -2893,9 +2893,12 @@ nw4r/g3d/g3d_calcvtx.cpp:
.sdata2 start:0x8057EEF0 end:0x8057EEF8
nw4r/snd/snd_AnimSound.cpp:
.text start:0x80461700 end:0x804630D4 align:16
.text start:0x80461700 end:0x80462F18 align:16
.sdata2 start:0x8057EEF8 end:0x8057EF18
nw4r/snd/snd_AnimSoundReader.cpp:
.text start:0x80462F20 end:0x804630D4 align:16
nw4r/snd/snd_AxManager.cpp:
.text start:0x804630E0 end:0x80464880 align:16
.ctors start:0x804DB958 end:0x804DB95C
+1
View File
@@ -1013,6 +1013,7 @@ config.libs = [
"snd",
[
Object(NonMatching, "nw4r/snd/snd_AnimSound.cpp"),
Object(Matching, "nw4r/snd/snd_AnimSoundReader.cpp"),
Object(Matching, "nw4r/snd/snd_AxManager.cpp"),
Object(Matching, "nw4r/snd/snd_AxVoice.cpp"),
Object(Matching, "nw4r/snd/snd_AxVoiceManager.cpp"),
+53
View File
@@ -0,0 +1,53 @@
#include "nw4r/snd/snd_Util.h"
#include "nw4r/ut/ut_binaryFileFormat.h"
namespace nw4r {
namespace snd {
namespace detail {
struct AnimEvent {};
struct AnimEventRef {
u8 _0x00[0xC];
Util::DataRef<AnimEvent> event; // at 0x08
};
struct AnimSoundFile {
static u32 const SIGNATURE_FILE = NW4R_FOUR_BYTE('R', 'A', 'S', 'D');
static int const FILE_VERSION = NW4R_FILE_VERSION(1, 0);
struct Header {
ut::BinaryFileHeader fileHeader; // size 0x10, offset 0x00
u32 blockOffset; // at 0x10
};
struct EventTable {
Util::Table<AnimEventRef> eventRef; // at 0x00
};
struct Block {
ut::BinaryBlockHeader blockHeader; // at 0x00
UNKWORD _0x08; // at 0x08
Util::DataRef<EventTable> eventTable; // at 0x0C
};
};
class AnimSoundFileReader {
public:
AnimSoundFileReader();
bool Setup(const void *buf);
void Shutdown();
u32 GetEventCount() const;
const AnimSoundFile::EventTable *GetEventTable() const;
const AnimEventRef *GetEventRef(u32 id) const;
const AnimEvent *GetEvent(const AnimEventRef *ref) const;
private:
const AnimSoundFile::Header *mpHeader; // at 0x00
const AnimSoundFile::Block *mpBlock; // at 0x04
};
} // namespace detail
} // namespace snd
} // namespace nw4r
+74
View File
@@ -0,0 +1,74 @@
/* Only implemented to the extent necessary to match data sections. */
#include "nw4r/snd/snd_AnimSound.h"
#include "common.h" // nullptr
#include "nw4r/snd/snd_Util.h"
#include "nw4r/ut/ut_binaryFileFormat.h"
namespace nw4r {
namespace snd {
namespace detail {
bool IsValidFileHeader(const void *data) {
ut::BinaryFileHeader const *fileHeader = static_cast<ut::BinaryFileHeader const *>(data);
if (fileHeader->signature != AnimSoundFile::SIGNATURE_FILE) {
return false;
}
if (fileHeader->version < AnimSoundFile::FILE_VERSION) {
return false;
}
if (fileHeader->version > AnimSoundFile::FILE_VERSION) {
return false;
}
return true;
}
AnimSoundFileReader::AnimSoundFileReader() : mpHeader(NULL) {}
bool AnimSoundFileReader::Setup(const void *buf) {
if (!IsValidFileHeader(buf)) {
return false;
}
mpHeader = static_cast<const AnimSoundFile::Header *>(buf);
mpBlock = static_cast<const AnimSoundFile::Block *>(ut::AddOffsetToPtr(buf, mpHeader->blockOffset));
return true;
}
void AnimSoundFileReader::Shutdown() {
mpHeader = NULL;
mpBlock = NULL;
}
u32 AnimSoundFileReader::GetEventCount() const {
const AnimSoundFile::EventTable *event = GetEventTable();
return event->eventRef.count;
}
const AnimEventRef *AnimSoundFileReader::GetEventRef(u32 id) const {
const AnimSoundFile::EventTable *event = GetEventTable();
return &event->eventRef.item[id];
}
const AnimSoundFile::EventTable *AnimSoundFileReader::GetEventTable() const {
if (mpBlock == NULL) {
return NULL;
}
return Util::GetDataRefAddress0(mpBlock->eventTable, &mpBlock->_0x08);
}
const AnimEvent *AnimSoundFileReader::GetEvent(const AnimEventRef *ref) const {
if (ref == NULL) {
return NULL;
}
const AnimSoundFile::EventTable *event = GetEventTable(); // unused
return Util::GetDataRefAddress0(ref->event, &mpBlock->_0x08);
}
} // namespace detail
} // namespace snd
} // namespace nw4r