summaryrefslogtreecommitdiff
path: root/include/nw4r/snd/snd_MemorySoundArchive.h
blob: 90f389faa26407a8f12225d3927f36aae099d5e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#ifndef NW4R_SND_MEMORY_SOUND_ARCHIVE_H
#define NW4R_SND_MEMORY_SOUND_ARCHIVE_H

/*******************************************************************************
 * headers
 */

#include "common.h"

// WARNING: DO NOT REORDER these #include directives, data pooling depends on it

// clang-format off
#include "nw4r/ut/ut_FileStream.h" // This needs to be
#include "nw4r/snd/snd_SoundArchive.h" // before this
// clang-format on

#include "nw4r/snd/snd_SoundArchiveFile.h"

/*******************************************************************************
 * classes and functions
 */

namespace nw4r { namespace snd
{
	// TODO: get a specific source (name, game id)
	/* dwarfv1_megadump.txt:284789-284793
	 * This is the struct info for nw4hbm::snd::MemorySoundArchive from an
	 * older version of the HBM library that actually uses it, but it seems
	 * similar enough to the current version, so it is used as a reference here.
	 */
	class MemorySoundArchive : public SoundArchive
	{
	// nested types
	private:
		class MemoryFileStream;

	// methods
	public:
		// cdtors
		MemorySoundArchive();
		virtual ~MemorySoundArchive();

		// virtual function ordering
		// vtable SoundArchive
		virtual void const *detail_GetFileAddress(u32 fileId) const;
		virtual void const *detail_GetWaveDataFileAddress(u32 fileId) const;
		virtual int detail_GetRequiredStreamBufferSize() const;
		virtual ut::FileStream *OpenStream(void *buffer, int size, u32 begin,
		                                   u32 length) const;
		virtual ut::FileStream *OpenExtStream(void *buffer, int size,
		                                      char const *extFilePath,
		                                      u32 begin, u32 length) const;

		// methods
		bool Setup(void const *soundArchiveData);
		void Shutdown();

	// members
	private:
		/* base SoundArchive */							// size 0x108, offset 0x000
		void							const *mData;	// size 0x004, offset 0x108
		detail::SoundArchiveFileReader	mFileReader;	// size 0x044, offset 0x10c
	}; // size 0x150

	// NOTE: Must be completed after MemorySoundArchive for data ordering
	// TODO: get a specific source (name, game id)
	/* dwarfv1_megadump.txt:293462-293467
	 * This is the struct info for
	 * nw4hbm::snd::MemorySoundArchive::MemoryFileStream from an older version
	 * of the HBM library that actually uses it, but it seems similar enough to
	 * the current version, so it is used as a reference here.
	 */
	class MemorySoundArchive::MemoryFileStream : public ut::FileStream
	{
	// methods
	public:
		// cdtors
		MemoryFileStream(void const *buffer, u32 size);
		virtual ~MemoryFileStream() {}

		// virtual function ordering
		// vtable ut::IOStream
		virtual void Close();
		virtual s32 Read(void *buf, u32 length);

		// vtable ut::FileStream
		virtual void Seek(s32 offset, u32 origin);

		// For instantiation ordering (WARNING: Do not rearrange)
		virtual bool CanSeek() const { return true; }
		virtual bool CanCancel() const { return true; }
		virtual bool CanAsync() const { return false; }
		virtual bool CanRead() const { return true; }
		virtual bool CanWrite() const { return false; }
		virtual u32 Tell() const { return mPosition; }
		virtual u32 GetSize() const { return mSize; }

	// members
	private:
		/* base ut::FileStream */	// size 0x14, offset 0x00
		void	const *mBuffer;		// size 0x04, offset 0x14
		u32		mSize;				// size 0x04, offset 0x18
		u32		mPosition;			// size 0x04, offset 0x1c
	}; // size 0x20
}} // namespace nw4r::snd

#endif // NW4R_SND_MEMORY_SOUND_ARCHIVE_H