Skip to content

Commit f4e8687

Browse files
authored
Merge branch 'MBU-Team:master' into master
2 parents 5320b0f + 9aa8b39 commit f4e8687

File tree

359 files changed

+1985
-129424
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

359 files changed

+1985
-129424
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ A reverse engineered version of Marble Blast Ultra that is based on Torque Shade
1616

1717
# Contributors
1818
- [HumanGamer](https://github.com/HumanGamer) - Leader
19-
- [NeoLightning](https://github.com/neolightning) - Website Maintainer
19+
- [NeoTheLynx](https://github.com/neolightning) - Developer & Discord Maintainer
2020
- [thearst3rd](https://github.com/thearst3rd) - Developer
2121
- [RandomityGuy](https://github.com/RandomityGuy) - Developer
2222
- [AJ Ferguson](https://github.com/AJ-Ferguson) - Developer
2323
- [polyrain](https://github.com/polyrain) - Developer
24-
- [Hailey Eira](https://github.com/HaileyEira) - Tester & Contributed Official Dev Builds
24+
- [Hailey Eira](https://github.com/HaileyEira) - Designer & Contributed Official Dev Builds
2525

2626
# License
2727
You may use this to make mods, but your mods must be released for free.
File renamed without changes.

assets/graphics/fpsbg.pdn

28.9 KB
Binary file not shown.

engine/source/core/MemoryStream.cpp

+340
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,340 @@
1+
#include "MemoryStream.h"
2+
#include <stdlib.h>
3+
#include <stdio.h>
4+
#include <cstring>
5+
#include <exception>
6+
#include <stdexcept>
7+
#include <platform/platform.h>
8+
MemoryStream::MemoryStream()
9+
{
10+
this->buffer = (U8*) dMalloc(256);
11+
this->bufferSize = 256;
12+
this->properSize = 0;
13+
this->position = 0;
14+
}
15+
16+
MemoryStream::~MemoryStream()
17+
{
18+
if (this->buffer != NULL)
19+
dFree(this->buffer);
20+
// delete[] this->buffer;
21+
}
22+
23+
void MemoryStream::createFromBuffer(U8* buffer, U32 count)
24+
{
25+
dFree(this->buffer);
26+
this->buffer = (U8*)dMalloc(count);
27+
this->bufferSize = count;
28+
this->properSize = count;
29+
this->position = 0;
30+
dMemcpy(this->buffer, buffer, count);
31+
}
32+
33+
void MemoryStream::useBuffer(U8* buffer, U32 count)
34+
{
35+
dFree(this->buffer);
36+
this->buffer = buffer;
37+
this->bufferSize = count;
38+
this->properSize = count;
39+
this->position = 0;
40+
}
41+
42+
char MemoryStream::readChar()
43+
{
44+
unsigned char chr = readUChar();
45+
return *(char*)&chr;
46+
}
47+
48+
S8 MemoryStream::readInt8()
49+
{
50+
U8 n = readUInt8();
51+
return *(S8*)&n;
52+
}
53+
54+
S16 MemoryStream::readInt16()
55+
{
56+
S16 n = readUInt16();
57+
return *(S16*)&n;
58+
}
59+
60+
S32 MemoryStream::readInt32()
61+
{
62+
S32 n = readUInt32();
63+
return *(S32*)&n;
64+
}
65+
66+
S64 MemoryStream::readInt64()
67+
{
68+
S64 n = readUInt64();
69+
return *(S64*)&n;
70+
}
71+
72+
unsigned char MemoryStream::readUChar()
73+
{
74+
return readUInt8();
75+
}
76+
77+
bool MemoryStream::readBool()
78+
{
79+
return readUInt8();
80+
}
81+
82+
U8 MemoryStream::readUInt8()
83+
{
84+
checkEos();
85+
U8 ret = this->buffer[this->position];
86+
this->position++;
87+
return ret;
88+
}
89+
90+
U16 MemoryStream::readUInt16()
91+
{
92+
checkEos();
93+
U16 num = 0;
94+
for (int i = 0; i < sizeof(U16); i++)
95+
{
96+
U8 byte = readUInt8();
97+
num += (static_cast<U16>(byte) << (8 * i));
98+
}
99+
return num;
100+
}
101+
102+
U32 MemoryStream::readUInt32()
103+
{
104+
checkEos();
105+
U32 num = 0;
106+
for (int i = 0; i < sizeof(U32); i++)
107+
{
108+
U8 byte = readUInt8();
109+
num += (static_cast<U32>(byte) << (8 * i));
110+
}
111+
return num;
112+
}
113+
114+
U64 MemoryStream::readUInt64()
115+
{
116+
checkEos();
117+
U64 num = 0;
118+
for (int i = 0; i < sizeof(U64); i++)
119+
{
120+
U8 byte = readUInt8();
121+
num += (static_cast<U64>(byte) << (8 * i));
122+
}
123+
return num;
124+
}
125+
126+
float MemoryStream::readFloat()
127+
{
128+
checkEos();
129+
U8 bytes[] = { readUInt8(), readUInt8(), readUInt8(), readUInt8() };
130+
float ret;
131+
dMemcpy(&ret, bytes, 4);
132+
return ret;
133+
}
134+
135+
double MemoryStream::readDouble()
136+
{
137+
checkEos();
138+
U64 bytes = readUInt64();
139+
double ret = *reinterpret_cast<double*>(&bytes);
140+
return ret;
141+
}
142+
143+
std::string MemoryStream::readString()
144+
{
145+
int len = readChar();
146+
char* str = new char[len + 1];
147+
for (int i = 0; i < len; i++)
148+
str[i] = readChar();
149+
str[len] = '\0';
150+
return std::string(str);
151+
}
152+
153+
void MemoryStream::reallocate()
154+
{
155+
while (this->position >= this->bufferSize)
156+
{
157+
this->bufferSize *= 1.5;
158+
this->buffer = (U8*)dRealloc(this->buffer, this->bufferSize);
159+
//U8* newBuffer = new U8[this->bufferSize]();
160+
//memcpy(newBuffer, this->buffer, this->bufferSize - this->REALLOCATE_SIZE);
161+
//delete[] this->buffer;
162+
//this->buffer = newBuffer;
163+
}
164+
}
165+
166+
void MemoryStream::writeChar(char chr)
167+
{
168+
if (this->position == this->properSize) {
169+
reallocate();
170+
this->properSize++;
171+
}
172+
this->buffer[this->position] = chr;
173+
this->position++;
174+
}
175+
176+
void MemoryStream::writeInt8(S8 i8)
177+
{
178+
writeChar(i8);
179+
}
180+
181+
void MemoryStream::writeBool(bool b)
182+
{
183+
writeUInt8(b);
184+
}
185+
186+
void MemoryStream::writeUChar(unsigned char chr)
187+
{
188+
if (this->position == this->properSize) {
189+
reallocate();
190+
this->properSize++;
191+
}
192+
this->buffer[this->position] = chr;
193+
this->position++;
194+
}
195+
196+
void MemoryStream::writeInt16(S16 i16)
197+
{
198+
reallocate();
199+
200+
for (int i = 0; i < sizeof(S16); i++)
201+
{
202+
U8 byte = (i16 >> (8 * i)) & 0xFF;
203+
writeUInt8(byte);
204+
}
205+
}
206+
207+
void MemoryStream::writeInt32(S32 i32)
208+
{
209+
reallocate();
210+
for (int i = 0; i < sizeof(S32); i++)
211+
{
212+
U8 byte = (i32 >> (8 * i)) & 0xFF;
213+
writeUInt8(byte);
214+
}
215+
}
216+
217+
void MemoryStream::writeInt64(S64 i64)
218+
{
219+
reallocate();
220+
for (int i = 0; i < sizeof(S64); i++)
221+
{
222+
U8 byte = (i64 >> (8 * i)) & 0xFF;
223+
writeUInt8(byte);
224+
}
225+
}
226+
227+
void MemoryStream::writeUInt8(U8 i8)
228+
{
229+
writeUChar(i8);
230+
}
231+
232+
void MemoryStream::writeUInt16(U16 i16)
233+
{
234+
reallocate();
235+
for (int i = 0; i < sizeof(U16); i++)
236+
{
237+
U8 byte = (i16 >> (8 * i)) & 0xFF;
238+
writeUInt8(byte);
239+
}
240+
}
241+
242+
void MemoryStream::writeUInt32(U32 i32)
243+
{
244+
reallocate();
245+
for (int i = 0; i < sizeof(U32); i++)
246+
{
247+
U8 byte = (i32 >> (8 * i)) & 0xFF;
248+
writeUInt8(byte);
249+
}
250+
}
251+
252+
void MemoryStream::writeUInt64(U64 i64)
253+
{
254+
reallocate();
255+
for (int i = 0; i < sizeof(U64); i++)
256+
{
257+
U8 byte = (i64 >> (8 * i)) & 0xFF;
258+
writeUInt8(byte);
259+
}
260+
}
261+
262+
void MemoryStream::writeFloat(float f)
263+
{
264+
reallocate();
265+
union {
266+
float a;
267+
U8 bytes[4];
268+
} floatbytes;
269+
floatbytes.a = f;
270+
writeUInt8(floatbytes.bytes[0]);
271+
writeUInt8(floatbytes.bytes[1]);
272+
writeUInt8(floatbytes.bytes[2]);
273+
writeUInt8(floatbytes.bytes[3]);
274+
}
275+
276+
void MemoryStream::writeDouble(double d)
277+
{
278+
reallocate();
279+
U64 reinterpreted = *reinterpret_cast<U64*>(&d);
280+
writeUInt64(reinterpreted);
281+
}
282+
283+
void MemoryStream::writeString(std::string s)
284+
{
285+
reallocate();
286+
int len = s.length();
287+
writeUInt32(len);
288+
for (int i = 0; i < s.length(); i++)
289+
{
290+
writeChar(s[i]);
291+
}
292+
}
293+
294+
void MemoryStream::writeBuffer(const char* buf, U32 size)
295+
{
296+
int curpos = this->position;
297+
this->position += size;
298+
this->reallocate();
299+
dMemcpy(&this->buffer[curpos], buf, size);
300+
301+
if (curpos <= this->properSize && curpos + size >= this->properSize) {
302+
this->properSize = curpos + size;
303+
}
304+
}
305+
306+
bool MemoryStream::seek(U32 position)
307+
{
308+
U32 oldPos = this->position;
309+
this->position = position;
310+
bool didEos = checkEos(false);
311+
if (didEos)
312+
this->position = oldPos;
313+
return !didEos;
314+
}
315+
316+
U32 MemoryStream::tell()
317+
{
318+
return this->position;
319+
}
320+
321+
U32 MemoryStream::length()
322+
{
323+
return this->properSize;
324+
}
325+
326+
U8* MemoryStream::getBuffer()
327+
{
328+
return this->buffer;
329+
}
330+
331+
bool MemoryStream::checkEos(bool error)
332+
{
333+
if (this->position > this->properSize || this->position < 0)
334+
if (error)
335+
throw std::runtime_error("End of stream!");
336+
else
337+
return true;
338+
else
339+
return false;
340+
}

0 commit comments

Comments
 (0)