From 79b20186423b791b8bacb4dfbfc4ea764bbd8051 Mon Sep 17 00:00:00 2001 From: robojumper Date: Thu, 29 May 2025 03:09:42 +0200 Subject: [PATCH] snd_AnimSoundReader OK --- config/SOUE01/splits.txt | 5 +- configure.py | 1 + include/nw4r/snd/snd_AnimSoundReader.h | 53 ++++++++++++++++++ src/nw4r/snd/snd_AnimSoundReader.cpp | 74 ++++++++++++++++++++++++++ 4 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 include/nw4r/snd/snd_AnimSoundReader.h create mode 100644 src/nw4r/snd/snd_AnimSoundReader.cpp diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index a66cc63d..e2fe6784 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -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 diff --git a/configure.py b/configure.py index c7f4608c..7b6c3265 100644 --- a/configure.py +++ b/configure.py @@ -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"), diff --git a/include/nw4r/snd/snd_AnimSoundReader.h b/include/nw4r/snd/snd_AnimSoundReader.h new file mode 100644 index 00000000..4ab47f21 --- /dev/null +++ b/include/nw4r/snd/snd_AnimSoundReader.h @@ -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 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 eventRef; // at 0x00 + }; + + struct Block { + ut::BinaryBlockHeader blockHeader; // at 0x00 + UNKWORD _0x08; // at 0x08 + Util::DataRef 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 diff --git a/src/nw4r/snd/snd_AnimSoundReader.cpp b/src/nw4r/snd/snd_AnimSoundReader.cpp new file mode 100644 index 00000000..555e5e94 --- /dev/null +++ b/src/nw4r/snd/snd_AnimSoundReader.cpp @@ -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(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(buf); + mpBlock = static_cast(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