Isle
Loading...
Searching...
No Matches
mxramstreamprovider.cpp
Go to the documentation of this file.
2
3#include "decomp.h"
4#include "mxdsbuffer.h"
5#include "mxdsfile.h"
6#include "mxomni.h"
8
11
12// FUNCTION: LEGO1 0x100d0730
14{
15 m_bufferSize = 0;
16 m_fileSize = 0;
17 m_pBufferOfFileSize = NULL;
18 m_lengthInDWords = 0;
19 m_bufferForDWords = NULL;
20}
21
22// FUNCTION: LEGO1 0x100d0930
24{
25 return m_fileSize;
26}
27
28// FUNCTION: LEGO1 0x100d0940
30{
31 return 1;
32}
33
34// FUNCTION: LEGO1 0x100d0950
36{
37 return m_lengthInDWords;
38}
39
40// FUNCTION: LEGO1 0x100d0960
42{
43 return m_bufferForDWords;
44}
45
46// FUNCTION: LEGO1 0x100d0a50
48{
49 m_bufferSize = 0;
50 m_fileSize = 0;
51
52 delete[] m_pBufferOfFileSize;
54
56
57 delete[] m_bufferForDWords;
59}
60
61// FUNCTION: LEGO1 0x100d0ae0
63{
64 MxResult result = FAILURE;
65 MxString path;
66 m_pLookup = p_resource;
67
68 path = (MxString(MxOmni::GetHD()) + p_resource->GetAtom().GetInternal() + ".si");
69
70 m_pFile = new MxDSFile(path.GetData(), 0);
71 if (m_pFile != NULL) {
72 if (m_pFile->Open(OF_READ) != 0) {
73 path = MxString(MxOmni::GetCD()) + p_resource->GetAtom().GetInternal() + ".si";
75
76 if (m_pFile->Open(OF_READ) != 0) {
77 goto done;
78 }
79 }
80
82 if (m_fileSize != 0) {
86 m_pFile->Read((unsigned char*) m_pBufferOfFileSize, m_fileSize) == SUCCESS) {
89
90 if (m_bufferForDWords != NULL) {
92 result = SUCCESS;
93 }
94 }
95 }
96 }
97
98done:
99 delete m_pFile;
100 m_pFile = NULL;
101 return result;
102}
103
104// FUNCTION: LEGO1 0x100d0d80
105// FUNCTION: BETA10 0x1016492f
106MxU32 ReadData(MxU8* p_buffer, MxU32 p_size)
107{
108 MxU32 id;
109 MxU8* data = p_buffer;
110 MxU8* data2;
111
112#define IntoType(p) ((MxU32*) (p))
113
114 while (data < p_buffer + p_size) {
115 if (*IntoType(data) == FOURCC('M', 'x', 'O', 'b')) {
116 data2 = data;
117 data = data2 + 8;
118
120 id = obj->GetObjectId();
121 delete obj;
122
123 data = MxDSChunk::End(data2);
124 while (data < p_buffer + p_size) {
125 if (*IntoType(data) == FOURCC('M', 'x', 'C', 'h')) {
126 MxU8* data3 = data;
127 data = MxDSChunk::End(data3);
128
129 if ((*IntoType(data2) == FOURCC('M', 'x', 'C', 'h')) &&
134 MxDSBuffer::Append(data2, data3);
135 continue;
136 }
137 else {
138 *MxStreamChunk::IntoFlags(data2) &= ~DS_CHUNK_SPLIT;
139 }
140 }
141
142 data2 = MxDSChunk::End(data2);
143 memcpy(data2, data3, MxDSChunk::Size(data3));
144
145 if (*MxStreamChunk::IntoObjectId(data2) == id &&
147 break;
148 }
149 }
150 else {
151 data++;
152 }
153 }
154 }
155 else {
156 data++;
157 }
158 }
159
160 *MxStreamChunk::IntoFlags(data2) &= ~DS_CHUNK_SPLIT;
161 return MxDSChunk::Size(data2) + (MxU32) (data2 - p_buffer);
162
163#undef IntoType
164}
const char * GetInternal() const
[AI] Returns a pointer to the internal string, or nullptr if not set.
Definition: mxatom.h:194
static MxResult Append(MxU8 *p_buffer1, MxU8 *p_buffer2)
[AI] Appends one chunk/data stream buffer to another, adjusting sizes/headers.
Definition: mxdsbuffer.cpp:509
static MxU32 Size(MxU8 *p_buffer)
[AI] Returns the total size (header + data) of a chunk from a raw buffer pointer.
Definition: mxdschunk.h:68
static MxU8 * End(MxU8 *p_buffer)
[AI] Returns a pointer to the end of this chunk for sequential iteration through a chunked buffer.
Definition: mxdschunk.h:73
[AI] Represents a source file handler for SI (Streamer Interface) files, providing buffered access fo...
Definition: mxdsfile.h:20
void SetFileName(const char *p_filename)
[AI] Sets the SI file's name.
Definition: mxdsfile.h:102
MxResult Read(unsigned char *, MxULong) override
[AI] Reads up to the specified number of bytes from the file into a buffer.
Definition: mxdsfile.cpp:108
MxS32 CalcFileSize()
[AI] Calculates and returns the file size by querying the system (Windows GetFileSize).
Definition: mxdsfile.h:108
MxResult Open(MxULong) override
[AI] Opens the SI file for reading or writing with the specified style flags.
Definition: mxdsfile.cpp:25
MxULong GetBufferSize() override
[AI] Returns the SI chunk's buffer size, as obtained from the SI file header.
Definition: mxdsfile.cpp:132
[AI] Base class for any object deserialized from an SI (script/data) file in the LEGO Island engine.
Definition: mxdsobject.h:44
MxU32 GetObjectId()
[AI] Returns the object id numeric value.
Definition: mxdsobject.h:130
virtual MxU32 * GetBuffer()
[AI] Returns a pointer to the internal buffer as a DWORD (32-bit) pointer.
Definition: mxdssource.h:116
virtual MxLong GetLengthInDWords()
[AI] Gets the length of the data in DWORDs (32-bit units).
Definition: mxdssource.h:109
static const char * GetCD()
[AI] Retrieves the configured CD-ROM media path string used for resource location.
Definition: mxomni.cpp:375
static const char * GetHD()
[AI] Retrieves the configured hard disk media path string used for resource location.
Definition: mxomni.cpp:363
[AI] Provides RAM-backed stream data access.
MxU32 m_fileSize
[AI] Size in bytes of the loaded resource file.
MxU32 m_lengthInDWords
[AI] Number of DWORD (4 byte) entries in buffer.
MxS32 GetStreamBuffersNum() override
[AI] Returns number of stream buffers contained (always 1 for RAM provider).
MxU32 * GetBufferForDWords() override
[AI] Returns pointer to the buffer as array of 32bit values (DWORDs), for data accessing aligned to 4...
MxU8 * m_pBufferOfFileSize
[AI] Pointer to full byte buffer with loaded SI file contents.
MxU32 * m_bufferForDWords
[AI] Pointer to DWORD buffer for 4-byte-aligned access to SI chunk data.
MxU32 GetFileSize() override
[AI] Returns the loaded file's full byte size.
MxU32 GetLengthInDWords() override
[AI] Returns length (number) of 32-bit words in buffer (DWORD units).
MxU32 m_bufferSize
[AI] Actual size in bytes of the buffer allocated for file (may match or exceed file size).
~MxRAMStreamProvider() override
[AI] Destroys the MxRAMStreamProvider, releasing all memory buffers.
MxResult SetResourceToGet(MxStreamController *p_resource) override
[AI] Loads the requested resource (SI file) fully into memory, prepares internal buffers for fast acc...
static MxLong * IntoTime(MxU8 *p_buffer)
[AI] Utility to cast a chunk header buffer into the time field pointer, facilitating direct parsing.
static MxU32 * IntoObjectId(MxU8 *p_buffer)
[AI] Utility to cast a chunk header buffer into the objectId field pointer, facilitating direct parsi...
static MxU16 * IntoFlags(MxU8 *p_buffer)
[AI] Utility to cast a chunk header buffer into the flags field pointer, facilitating direct parsing.
[AI] Controller for streaming and managing multimedia resources and actions during gameplay.
MxAtomId & GetAtom()
[AI] Retrieves the atom ID (unique logical identifier) for this stream controller.
[AI] Abstract base class for stream resource providers in the LEGO Island engine.
MxDSFile * m_pFile
[AI] Pointer to the loaded SI file associated with this provider. [AI]
MxStreamController * m_pLookup
[AI] The stream controller using this provider as its data source. [AI]
Mindscape custom string class for managing dynamic C-strings within the game engine.
Definition: mxstring.h:14
char * GetData() const
Returns a pointer to the internal character buffer.
Definition: mxstring.h:110
#define DECOMP_SIZE_ASSERT(T, S)
Definition: decomp.h:19
#define NULL
[AI] Null pointer value (C/C++ semantics).
Definition: legotypes.h:26
#define FAILURE
[AI] Used to indicate a failed operation in result codes.
Definition: legotypes.h:34
#define SUCCESS
[AI] Used to indicate a successful operation in result codes.
Definition: legotypes.h:30
#define DS_CHUNK_END_OF_STREAM
[AI] Flag bit indicating this chunk is the last in its stream.
Definition: mxdschunk.h:14
#define DS_CHUNK_SPLIT
[AI] Flag indicating this chunk is split (i.e., fragmented and needs reassembling).
Definition: mxdschunk.h:22
MxDSObject * DeserializeDSObjectDispatch(MxU8 *&, MxS16)
[AI] Reads and deserializes a DS object of the specific type from an SI buffer.
Definition: mxdsobject.cpp:210
#define IntoType(p)
MxU32 ReadData(MxU8 *p_buffer, MxU32 p_size)
[AI] Rearranges split and unordered chunks within a memory buffer for SI resource files,...
MxLong MxResult
[AI]
Definition: mxtypes.h:106
#define FOURCC(a, b, c, d)
[AI] Macro to compose a 32-bit code from four 8-bit characters (e.g., for resource and chunk IDs).
Definition: mxtypes.h:162
unsigned char MxU8
[AI]
Definition: mxtypes.h:8
signed int MxS32
[AI]
Definition: mxtypes.h:38
unsigned int MxU32
[AI]
Definition: mxtypes.h:32