SLUDGE: Replace sludge stream reading functions by scummvm ones

This commit is contained in:
yinsimei 2017-05-30 09:59:56 +02:00 committed by Eugene Sandulenko
parent b920f61a11
commit 8c59f8deac
21 changed files with 363 additions and 419 deletions

View file

@ -107,10 +107,10 @@ void nosnapshot() {
void saveSnapshot(Common::WriteStream *stream) { void saveSnapshot(Common::WriteStream *stream) {
#if 0 #if 0
if (snapshotTextureName) { if (snapshotTextureName) {
putch(1, stream); // 1 for snapshot follows stream->writeByte(1); // 1 for snapshot follows
saveCoreHSI(stream, snapshotTextureName, winWidth, winHeight); saveCoreHSI(stream, snapshotTextureName, winWidth, winHeight);
} else { } else {
putch(0, stream); stream->writeByte(0);
} }
#endif #endif
} }
@ -167,8 +167,8 @@ bool snapshot() {
} }
bool restoreSnapshot(Common::SeekableReadStream *stream) { bool restoreSnapshot(Common::SeekableReadStream *stream) {
unsigned int picWidth = get2bytes(stream); unsigned int picWidth = stream->readUint16BE();
unsigned int picHeight = get2bytes(stream); unsigned int picHeight = stream->readUint16BE();
if ((picWidth != winWidth) || (picHeight != winHeight)) if ((picWidth != winWidth) || (picHeight != winHeight))
return false; return false;
@ -190,9 +190,9 @@ bool restoreSnapshot(Common::SeekableReadStream *stream) {
for (t2 = 0; t2 < winHeight; t2++) { for (t2 = 0; t2 < winHeight; t2++) {
t1 = 0; t1 = 0;
while (t1 < winWidth) { while (t1 < winWidth) {
c = (unsigned short) get2bytes(stream); c = (unsigned short)stream->readUint16BE();
if (c & 32) { if (c & 32) {
n = getch(stream) + 1; n = stream->readByte() + 1;
c -= 32; c -= 32;
} else { } else {
n = 1; n = 1;
@ -653,8 +653,8 @@ bool loadLightMap(int v) {
fileIsPNG = false; fileIsPNG = false;
fseek(bigDataFile, file_pointer, SEEK_SET); fseek(bigDataFile, file_pointer, SEEK_SET);
newPicWidth = lightMap.w = get2bytes(bigDataFile); newPicWidth = lightMap.w = bigDataFile->readUint16BE();
newPicHeight = lightMap.h = get2bytes(bigDataFile); newPicHeight = lightMap.h = bigDataFile->readUint16BE();
} else { } else {
// Read the PNG header // Read the PNG header
@ -745,7 +745,7 @@ bool loadLightMap(int v) {
for (t2 = 0; t2 < lightMap.h; t2 ++) { for (t2 = 0; t2 < lightMap.h; t2 ++) {
t1 = 0; t1 = 0;
while (t1 < lightMap.w) { while (t1 < lightMap.w) {
c = (unsigned short) get2bytes(bigDataFile); c = (unsigned short)bigDataFile->readUint16BE();
if (c & 32) { if (c & 32) {
n = fgetc(bigDataFile) + 1; n = fgetc(bigDataFile) + 1;
c -= 32; c -= 32;
@ -859,8 +859,8 @@ bool loadParallax(unsigned short v, unsigned short fracX,
fileIsPNG = false; fileIsPNG = false;
fseek(bigDataFile, file_pointer, SEEK_SET); fseek(bigDataFile, file_pointer, SEEK_SET);
picWidth = nP->width = get2bytes(bigDataFile); picWidth = nP->width = bigDataFile->readUint16BE();
picHeight = nP->height = get2bytes(bigDataFile); picHeight = nP->height = bigDataFile->readUint16BE();
} else { } else {
// Read the PNG header // Read the PNG header
@ -955,7 +955,7 @@ bool loadParallax(unsigned short v, unsigned short fracX,
for (t2 = 0; t2 < nP->height; t2 ++) { for (t2 = 0; t2 < nP->height; t2 ++) {
t1 = 0; t1 = 0;
while (t1 < nP->width) { while (t1 < nP->width) {
c = (unsigned short) get2bytes(bigDataFile); c = (unsigned short)bigDataFile->readUint16BE();
if (c & 32) { if (c & 32) {
n = fgetc(bigDataFile) + 1; n = fgetc(bigDataFile) + 1;
c -= 32; c -= 32;
@ -1111,8 +1111,8 @@ bool loadByteArray(int &picWidth, int &picHeight, int &realPicWidth, int &realPi
int32_t transCol = reserve ? -1 : 63519; int32_t transCol = reserve ? -1 : 63519;
int t1, t2, n; int t1, t2, n;
unsigned short c; unsigned short c;
picWidth = realPicWidth = get2bytes(stream); picWidth = realPicWidth = stream->readUint16BE();
picHeight = realPicHeight = get2bytes(stream); picHeight = realPicHeight = stream->readUint16BE();
if (reserve) { if (reserve) {
if (!resizeBackdrop(realPicWidth, realPicHeight)) return false; if (!resizeBackdrop(realPicWidth, realPicHeight)) return false;
@ -1121,9 +1121,9 @@ bool loadByteArray(int &picWidth, int &picHeight, int &realPicWidth, int &realPi
for (t2 = 0; t2 < realPicHeight; t2 ++) { for (t2 = 0; t2 < realPicHeight; t2 ++) {
t1 = 0; t1 = 0;
while (t1 < realPicWidth) { while (t1 < realPicWidth) {
c = (unsigned short) get2bytes(stream); c = (unsigned short)stream->readUint16BE();
if (c & 32) { if (c & 32) {
n = getch(stream) + 1; n = stream->readByte() + 1;
c -= 32; c -= 32;
} else { } else {
n = 1; n = 1;
@ -1337,8 +1337,8 @@ bool mixHSI(Common::SeekableReadStream *stream, int x, int y) {
fileIsPNG = false; fileIsPNG = false;
stream->seek(file_pointer, SEEK_SET); stream->seek(file_pointer, SEEK_SET);
picWidth = realPicWidth = get2bytes(stream); picWidth = realPicWidth = stream->readUint16BE();
picHeight = realPicHeight = get2bytes(stream); picHeight = realPicHeight = stream->readUint16BE();
} else { } else {
// Read the PNG header // Read the PNG header
@ -1446,9 +1446,9 @@ bool mixHSI(Common::SeekableReadStream *stream, int x, int y) {
for (t2 = 0; t2 < realPicHeight; t2 ++) { for (t2 = 0; t2 < realPicHeight; t2 ++) {
t1 = 0; t1 = 0;
while (t1 < realPicWidth) { while (t1 < realPicWidth) {
c = (unsigned short) get2bytes(stream); c = (unsigned short)stream->readUint16BE();
if (c & 32) { if (c & 32) {
n = getch(stream) + 1; n = stream->readByte() + 1;
c -= 32; c -= 32;
} else { } else {
n = 1; n = 1;
@ -1701,8 +1701,8 @@ void saveCoreHSI(Common::WriteStream *stream, GLuint texture, int w, int h) {
int x, y, lookAhead; int x, y, lookAhead;
unsigned short int *fromHere, * lookPointer; unsigned short int *fromHere, * lookPointer;
put2bytes(w, stream); stream->writeUint16BE(w);
put2bytes(h, stream); stream->writeUint16BE(h);
for (y = 0; y < h; y ++) { for (y = 0; y < h; y ++) {
fromHere = image + (y * tw); fromHere = image + (y * tw);
@ -1717,8 +1717,8 @@ void saveCoreHSI(Common::WriteStream *stream, GLuint texture, int w, int h) {
if (lookAhead == x + 1) { if (lookAhead == x + 1) {
put2bytes((* fromHere) & 65503, stream); put2bytes((* fromHere) & 65503, stream);
} else { } else {
put2bytes(* fromHere | 32, stream); stream->writeUint16BE(* fromHere | 32);
putch(lookAhead - x - 1, stream); stream->writeByte(lookAhead - x - 1);
} }
fromHere = lookPointer; fromHere = lookPointer;
x = lookAhead; x = lookAhead;
@ -1738,10 +1738,10 @@ void saveHSI(Common::WriteStream *stream) {
void saveParallaxRecursive(parallaxLayer *me, Common::WriteStream *stream) { void saveParallaxRecursive(parallaxLayer *me, Common::WriteStream *stream) {
if (me) { if (me) {
saveParallaxRecursive(me->next, stream); saveParallaxRecursive(me->next, stream);
putch(1, stream); stream->writeByte(1);
put2bytes(me->fileNum, stream); stream->writeUint16BE(me->fileNum);
put2bytes(me->fractionX, stream); stream->writeUint16BE(me->fractionX);
put2bytes(me->fractionY, stream); stream->writeUint16BE(me->fractionY);
} }
} }

View file

@ -118,16 +118,16 @@ static int s_matrixEffectBase = 0;
void blur_saveSettings(Common::WriteStream *stream) { void blur_saveSettings(Common::WriteStream *stream) {
if (s_matrixEffectData) { if (s_matrixEffectData) {
put4bytes(s_matrixEffectDivide, stream); stream->writeUint32LE(s_matrixEffectDivide);
put4bytes(s_matrixEffectWidth, stream); stream->writeUint32LE(s_matrixEffectWidth);
put4bytes(s_matrixEffectHeight, stream); stream->writeUint32LE(s_matrixEffectHeight);
put4bytes(s_matrixEffectBase, stream); stream->writeUint32LE(s_matrixEffectBase);
stream->write(s_matrixEffectData, sizeof(int) * s_matrixEffectWidth * s_matrixEffectHeight); stream->write(s_matrixEffectData, sizeof(int) * s_matrixEffectWidth * s_matrixEffectHeight);
} else { } else {
put4bytes(0, stream); stream->writeUint32LE(0);
put4bytes(0, stream); stream->writeUint32LE(0);
put4bytes(0, stream); stream->writeUint32LE(0);
put4bytes(0, stream); stream->writeUint32LE(0);
} }
} }
@ -143,10 +143,10 @@ static int *blur_allocateMemoryForEffect() {
} }
void blur_loadSettings(Common::SeekableReadStream *stream) { void blur_loadSettings(Common::SeekableReadStream *stream) {
s_matrixEffectDivide = get4bytes(stream); s_matrixEffectDivide = stream->readUint32LE();
s_matrixEffectWidth = get4bytes(stream); s_matrixEffectWidth = stream->readUint32LE();
s_matrixEffectHeight = get4bytes(stream); s_matrixEffectHeight = stream->readUint32LE();
s_matrixEffectBase = get4bytes(stream); s_matrixEffectBase = stream->readUint32LE();
if (blur_allocateMemoryForEffect()) { if (blur_allocateMemoryForEffect()) {
size_t bytes_read = stream->read(s_matrixEffectData, sizeof(int) * s_matrixEffectWidth * s_matrixEffectHeight); size_t bytes_read = stream->read(s_matrixEffectData, sizeof(int) * s_matrixEffectWidth * s_matrixEffectHeight);

View file

@ -35,6 +35,8 @@
#include "CommonCode/version.h" #include "CommonCode/version.h"
#include "common/file.h" #include "common/file.h"
#include "common/debug.h"
#include "sludge.h"
namespace Sludge { namespace Sludge {
@ -56,7 +58,7 @@ bool openSubSlice(int num) {
} }
// fprintf (dbug, "Going to position %li\n", startOfSubIndex + (num << 2)); // fprintf (dbug, "Going to position %li\n", startOfSubIndex + (num << 2));
bigDataFile->seek(startOfSubIndex + (num << 2), 0); bigDataFile->seek(startOfSubIndex + (num << 2), 0);
bigDataFile->seek(get4bytes(bigDataFile), 0); bigDataFile->seek(bigDataFile->readUint32LE(), 0);
// fprintf (dbug, "Told to skip forward to %li\n", ftell (bigDataFile)); // fprintf (dbug, "Told to skip forward to %li\n", ftell (bigDataFile));
// fclose (dbug); // fclose (dbug);
@ -75,7 +77,7 @@ bool openObjectSlice(int num) {
// fprintf (dbug, "Going to position %li\n", startOfObjectIndex + (num << 2)); // fprintf (dbug, "Going to position %li\n", startOfObjectIndex + (num << 2));
bigDataFile->seek(startOfObjectIndex + (num << 2), 0); bigDataFile->seek(startOfObjectIndex + (num << 2), 0);
bigDataFile->seek(get4bytes(bigDataFile), 0); bigDataFile->seek(bigDataFile->readUint32LE(), 0);
// fprintf (dbug, "Told to skip forward to %li\n", ftell (bigDataFile)); // fprintf (dbug, "Told to skip forward to %li\n", ftell (bigDataFile));
// fclose (dbug); // fclose (dbug);
return sliceBusy = true; return sliceBusy = true;
@ -92,12 +94,12 @@ unsigned int openFileFromNum(int num) {
// fprintf (dbug, "\nTrying to open file %i\n", num); // fprintf (dbug, "\nTrying to open file %i\n", num);
// fprintf (dbug, "Jumping to %li (for index) \n", startOfDataIndex + (num << 2)); // fprintf (dbug, "Jumping to %li (for index) \n", startOfDataIndex + (num << 2));
bigDataFile->seek(startOfDataIndex + (num << 2), 0); bigDataFile->seek(startOfDataIndex + (num << 2), 0);
bigDataFile->seek(get4bytes(bigDataFile), 1); bigDataFile->seek(bigDataFile->readUint32LE(), 1);
// fprintf (dbug, "Jumping to %li (for data) \n", ftell (bigDataFile)); // fprintf (dbug, "Jumping to %li (for data) \n", ftell (bigDataFile));
sliceBusy = true; sliceBusy = true;
// fclose (dbug); // fclose (dbug);
return get4bytes(bigDataFile); return bigDataFile->readUint32LE();
} }
// Converts a string from Windows CP-1252 to UTF-8. // Converts a string from Windows CP-1252 to UTF-8.
@ -173,7 +175,7 @@ char *getNumberedString(int value) {
} }
bigDataFile->seek((value << 2) + startOfTextIndex, 0); bigDataFile->seek((value << 2) + startOfTextIndex, 0);
value = get4bytes(bigDataFile); value = bigDataFile->readUint32LE();
bigDataFile->seek(value, 0); bigDataFile->seek(value, 0);
char *s = readString(bigDataFile); char *s = readString(bigDataFile);
@ -218,26 +220,30 @@ void setFileIndices(Common::File *fp, int numLanguages,
// STRINGS // STRINGS
int skipAfter = numLanguages - skipBefore; int skipAfter = numLanguages - skipBefore;
while (skipBefore) { while (skipBefore) {
fp->seek(get4bytes(fp), SEEK_SET); fp->seek(fp->readUint32LE(), SEEK_SET);
skipBefore--; skipBefore--;
} }
startOfTextIndex = fp->pos() + 4; startOfTextIndex = fp->pos() + 4;
debug(kSludgeDebugDataLoad, "startOfTextIndex: %i", startOfTextIndex);
fp->seek(get4bytes(fp), SEEK_SET); fp->seek(fp->readUint32LE(), SEEK_SET);
while (skipAfter) { while (skipAfter) {
fp->seek(get4bytes(fp), SEEK_SET); fp->seek(fp->readUint32LE(), SEEK_SET);
skipAfter--; skipAfter--;
} }
startOfSubIndex = fp->pos() + 4; startOfSubIndex = fp->pos() + 4;
fp->seek(get4bytes(fp), SEEK_CUR); fp->seek(fp->readUint32LE(), SEEK_CUR);
debug(kSludgeDebugDataLoad, "startOfSubIndex: %i", startOfTextIndex);
startOfObjectIndex = fp->pos() + 4; startOfObjectIndex = fp->pos() + 4;
fp->seek(get4bytes(fp), SEEK_CUR); fp->seek(fp->readUint32LE(), SEEK_CUR);
debug(kSludgeDebugDataLoad, "startOfObjectIndex: %i", startOfTextIndex);
// Remember that the data section starts here // Remember that the data section starts here
startOfDataIndex = fp->pos(); startOfDataIndex = fp->pos();
debug(kSludgeDebugDataLoad, "startOfDataIndex: %i", startOfTextIndex);
} }
} // End of namespace Sludge } // End of namespace Sludge

View file

@ -135,7 +135,7 @@ bool setFloor(int fileNum) {
// Find out how many polygons there are and reserve memory // Find out how many polygons there are and reserve memory
currentFloor->originalNum = fileNum; currentFloor->originalNum = fileNum;
currentFloor->numPolygons = getch(bigDataFile); currentFloor->numPolygons = bigDataFile->readByte();
currentFloor->polygon = new floorPolygon[currentFloor->numPolygons]; currentFloor->polygon = new floorPolygon[currentFloor->numPolygons];
if (!checkNew(currentFloor->polygon)) if (!checkNew(currentFloor->polygon))
return false; return false;
@ -146,7 +146,7 @@ bool setFloor(int fileNum) {
// Find out how many vertex IDs there are and reserve memory // Find out how many vertex IDs there are and reserve memory
currentFloor->polygon[i].numVertices = getch(bigDataFile); currentFloor->polygon[i].numVertices = bigDataFile->readByte();
currentFloor->polygon[i].vertexID = currentFloor->polygon[i].vertexID =
new int[currentFloor->polygon[i].numVertices]; new int[currentFloor->polygon[i].numVertices];
if (!checkNew(currentFloor->polygon[i].vertexID)) if (!checkNew(currentFloor->polygon[i].vertexID))
@ -155,21 +155,21 @@ bool setFloor(int fileNum) {
// Read in each vertex ID // Read in each vertex ID
for (j = 0; j < currentFloor->polygon[i].numVertices; j++) { for (j = 0; j < currentFloor->polygon[i].numVertices; j++) {
currentFloor->polygon[i].vertexID[j] = get2bytes(bigDataFile); currentFloor->polygon[i].vertexID[j] = bigDataFile->readUint16BE();
} }
} }
// Find out how many vertices there are and reserve memory // Find out how many vertices there are and reserve memory
i = get2bytes(bigDataFile); i = bigDataFile->readUint16BE();
currentFloor->vertex = new POINT[i]; currentFloor->vertex = new POINT[i];
if (!checkNew(currentFloor->vertex)) if (!checkNew(currentFloor->vertex))
return false; return false;
for (j = 0; j < i; j++) { for (j = 0; j < i; j++) {
currentFloor->vertex[j].x = get2bytes(bigDataFile); currentFloor->vertex[j].x = bigDataFile->readUint16BE();
currentFloor->vertex[j].y = get2bytes(bigDataFile); currentFloor->vertex[j].y = bigDataFile->readUint16BE();
} }
finishAccess(); finishAccess();

View file

@ -115,7 +115,7 @@ void readIniFile(char *filename) {
bool doingSecond = false; bool doingSecond = false;
do { do {
readChar = getch(&fd); readChar = fd.readByte();
if (fd.eos()) { if (fd.eos()) {
readChar = '\n'; readChar = '\n';
keepGoing = false; keepGoing = false;
@ -193,7 +193,7 @@ void makeLanguageTable(Common::File *table) {
return; return;
for (unsigned int i = 0; i <= gameSettings.numLanguages; i++) { for (unsigned int i = 0; i <= gameSettings.numLanguages; i++) {
languageTable[i] = i ? get2bytes(table) : 0; languageTable[i] = i ? table->readUint16BE() : 0;
debug(kSludgeDebugDataLoad, "languageTable %i: %i", i, debug(kSludgeDebugDataLoad, "languageTable %i: %i", i,
languageTable[i]); languageTable[i]);
languageName[i] = 0; languageName[i] = 0;

View file

@ -105,7 +105,7 @@ void saveStack(variableStack *vs, Common::WriteStream *stream) {
stackDebug((stackfp, " stack contains %d elements\n", elements)); stackDebug((stackfp, " stack contains %d elements\n", elements));
put2bytes(elements, stream); stream->writeUint16BE(elements);
search = vs; search = vs;
for (a = 0; a < elements; ++a) { for (a = 0; a < elements; ++a) {
saveVariable(&search->thisVar, stream); saveVariable(&search->thisVar, stream);
@ -115,7 +115,7 @@ void saveStack(variableStack *vs, Common::WriteStream *stream) {
variableStack *loadStack(Common::SeekableReadStream *stream, variableStack *loadStack(Common::SeekableReadStream *stream,
variableStack **last) { variableStack **last) {
int elements = get2bytes(stream); int elements = stream->readUint16BE();
int a; int a;
variableStack *first = NULL; variableStack *first = NULL;
variableStack * * changeMe = &first; variableStack * * changeMe = &first;
@ -142,14 +142,14 @@ bool saveStackRef(stackHandler *vs, Common::WriteStream *stream) {
int a = 0; int a = 0;
while (s) { while (s) {
if (s->stack == vs) { if (s->stack == vs) {
putch(1, stream); stream->writeByte(1);
put2bytes(stackLibTotal - a, stream); stream->writeUint16BE(stackLibTotal - a);
return true; return true;
} }
s = s->next; s = s->next;
++a; ++a;
} }
putch(0, stream); stream->writeByte(0);
saveStack(vs->first, stream); saveStack(vs->first, stream);
s = new stackLibrary; s = new stackLibrary;
stackLibTotal++; stackLibTotal++;
@ -183,10 +183,10 @@ stackHandler *getStackFromLibrary(int n) {
stackHandler *loadStackRef(Common::SeekableReadStream *stream) { stackHandler *loadStackRef(Common::SeekableReadStream *stream) {
stackHandler *nsh; stackHandler *nsh;
if (getch(stream)) { // It's one we've loaded already... if (stream->readByte()) { // It's one we've loaded already...
stackDebug((stackfp, "loadStackRef (duplicate, get from library)\n")); stackDebug((stackfp, "loadStackRef (duplicate, get from library)\n"));
nsh = getStackFromLibrary(get2bytes(stream)); nsh = getStackFromLibrary(stream->readUint16BE());
nsh->timesUsed++; nsh->timesUsed++;
} else { } else {
stackDebug((stackfp, "loadStackRef (new one)\n")); stackDebug((stackfp, "loadStackRef (new one)\n"));
@ -231,14 +231,14 @@ bool saveVariable(variable *from, Common::WriteStream *stream) {
} }
#endif #endif
putch(from->varType, stream); stream->writeByte(from->varType);
switch (from->varType) { switch (from->varType) {
case SVT_INT: case SVT_INT:
case SVT_FUNC: case SVT_FUNC:
case SVT_BUILT: case SVT_BUILT:
case SVT_FILE: case SVT_FILE:
case SVT_OBJTYPE: case SVT_OBJTYPE:
put4bytes(from->varData.intValue, stream); stream->writeUint32LE(from->varData.intValue);
return true; return true;
case SVT_STRING: case SVT_STRING:
@ -268,14 +268,14 @@ bool saveVariable(variable *from, Common::WriteStream *stream) {
} }
bool loadVariable(variable *to, Common::SeekableReadStream *stream) { bool loadVariable(variable *to, Common::SeekableReadStream *stream) {
to->varType = (variableType) getch(stream); to->varType = (variableType)stream->readByte();
switch (to->varType) { switch (to->varType) {
case SVT_INT: case SVT_INT:
case SVT_FUNC: case SVT_FUNC:
case SVT_BUILT: case SVT_BUILT:
case SVT_FILE: case SVT_FILE:
case SVT_OBJTYPE: case SVT_OBJTYPE:
to->varData.intValue = get4bytes(stream); to->varData.intValue = stream->readUint32LE();
return true; return true;
case SVT_STRING: case SVT_STRING:
@ -318,18 +318,18 @@ bool loadVariable(variable *to, Common::SeekableReadStream *stream) {
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void saveFunction(loadedFunction *fun, Common::WriteStream *stream) { void saveFunction(loadedFunction *fun, Common::WriteStream *stream) {
int a; int a;
put2bytes(fun->originalNumber, stream); stream->writeUint16BE(fun->originalNumber);
if (fun->calledBy) { if (fun->calledBy) {
putch(1, stream); stream->writeByte(1);
saveFunction(fun->calledBy, stream); saveFunction(fun->calledBy, stream);
} else { } else {
putch(0, stream); stream->writeByte(0);
} }
put4bytes(fun->timeLeft, stream); stream->writeUint32LE(fun->timeLeft);
put2bytes(fun->runThisLine, stream); stream->writeUint16BE(fun->runThisLine);
putch(fun->cancelMe, stream); stream->writeByte(fun->cancelMe);
putch(fun->returnSomething, stream); stream->writeByte(fun->returnSomething);
putch(fun->isSpeech, stream); stream->writeByte(fun->isSpeech);
saveVariable(&(fun->reg), stream); saveVariable(&(fun->reg), stream);
if (fun->freezerLevel) { if (fun->freezerLevel) {
@ -352,20 +352,20 @@ loadedFunction *loadFunction(Common::SeekableReadStream *stream) {
// See what it was called by and load if we need to... // See what it was called by and load if we need to...
buildFunc->originalNumber = get2bytes(stream); buildFunc->originalNumber = stream->readUint16BE();
buildFunc->calledBy = NULL; buildFunc->calledBy = NULL;
if (getch(stream)) { if (stream->readByte()) {
buildFunc->calledBy = loadFunction(stream); buildFunc->calledBy = loadFunction(stream);
if (!buildFunc->calledBy) if (!buildFunc->calledBy)
return NULL; return NULL;
} }
buildFunc->timeLeft = get4bytes(stream); buildFunc->timeLeft = stream->readUint32LE();
buildFunc->runThisLine = get2bytes(stream); buildFunc->runThisLine = stream->readUint16BE();
buildFunc->freezerLevel = 0; buildFunc->freezerLevel = 0;
buildFunc->cancelMe = getch(stream); buildFunc->cancelMe = stream->readByte();
buildFunc->returnSomething = getch(stream); buildFunc->returnSomething = stream->readByte();
buildFunc->isSpeech = getch(stream); buildFunc->isSpeech = stream->readByte();
loadVariable(&(buildFunc->reg), stream); loadVariable(&(buildFunc->reg), stream);
loadFunctionCode(buildFunc); loadFunctionCode(buildFunc);
@ -407,15 +407,15 @@ bool saveGame(char *fname) {
fputc(fontTableSize > 0, fp); fputc(fontTableSize > 0, fp);
if (fontTableSize > 0) { if (fontTableSize > 0) {
put2bytes(loadedFontNum, fp); fp->writeUint16BE(loadedFontNum);
put2bytes(fontHeight, fp); fp->writeUint16BE(fontHeight);
writeString(fontOrderString, fp); writeString(fontOrderString, fp);
} }
putSigned(fontSpace, fp); putSigned(fontSpace, fp);
// Save backdrop // Save backdrop
put2bytes(cameraX, fp); fp->writeUint16BE(cameraX);
put2bytes(cameraY, fp); fp->writeUint16BE(cameraY);
putFloat(cameraZoom, fp); putFloat(cameraZoom, fp);
fputc(brightnessLevel, fp); fputc(brightnessLevel, fp);
@ -428,7 +428,7 @@ bool saveGame(char *fname) {
saveRegions(fp); saveRegions(fp);
saveAnim(mouseCursorAnim, fp); saveAnim(mouseCursorAnim, fp);
put2bytes(mouseCursorFrameNum, fp); fp->writeUint16BE(mouseCursorFrameNum);
// Save functions // Save functions
loadedFunction *thisFunction = allRunningFunctions; loadedFunction *thisFunction = allRunningFunctions;
@ -437,7 +437,7 @@ bool saveGame(char *fname) {
countFunctions ++; countFunctions ++;
thisFunction = thisFunction->next; thisFunction = thisFunction->next;
} }
put2bytes(countFunctions, fp); fp->writeUint16BE(countFunctions);
thisFunction = allRunningFunctions; thisFunction = allRunningFunctions;
while (thisFunction) { while (thisFunction) {
@ -453,17 +453,17 @@ bool saveGame(char *fname) {
if (currentFloor->numPolygons) { if (currentFloor->numPolygons) {
fputc(1, fp); fputc(1, fp);
put2bytes(currentFloor->originalNum, fp); fp->writeUint16BE(currentFloor->originalNum);
} else fputc(0, fp); } else fputc(0, fp);
if (zBuffer.tex) { if (zBuffer.tex) {
fputc(1, fp); fputc(1, fp);
put2bytes(zBuffer.originalNum, fp); fp->writeUint16BE(zBuffer.originalNum);
} else fputc(0, fp); } else fputc(0, fp);
if (lightMap.data) { if (lightMap.data) {
fputc(1, fp); fputc(1, fp);
put2bytes(lightMapNumber, fp); fp->writeUint16BE(lightMapNumber);
} else fputc(0, fp); } else fputc(0, fp);
fputc(lightMapMode, fp); fputc(lightMapMode, fp);
@ -473,11 +473,11 @@ bool saveGame(char *fname) {
saveStatusBars(fp); saveStatusBars(fp);
saveSounds(fp); saveSounds(fp);
put2bytes(saveEncoding, fp); fp->writeUint16BE(saveEncoding);
blur_saveSettings(fp); blur_saveSettings(fp);
put2bytes(currentBlankColour, fp); fp->writeUint16BE(currentBlankColour);
fputc(currentBurnR, fp); fputc(currentBurnR, fp);
fputc(currentBurnG, fp); fputc(currentBurnG, fp);
fputc(currentBurnB, fp); fputc(currentBurnB, fp);
@ -538,8 +538,8 @@ bool loadGame(char *fname) {
int fontNum; int fontNum;
char *charOrder; char *charOrder;
if (fontLoaded) { if (fontLoaded) {
fontNum = get2bytes(fp); fontNum = fp->readUint16BE();
fontHeight = get2bytes(fp); fontHeight = fp->readUint16BE();
if (ssgVersion < VERSION(2, 2)) { if (ssgVersion < VERSION(2, 2)) {
int x; int x;
@ -563,8 +563,8 @@ bool loadGame(char *fname) {
killAllPeople(); killAllPeople();
killAllRegions(); killAllRegions();
int camerX = get2bytes(fp); int camerX = fp->readUint16BE();
int camerY = get2bytes(fp); int camerY = fp->readUint16BE();
float camerZ; float camerZ;
if (ssgVersion >= VERSION(2, 0)) { if (ssgVersion >= VERSION(2, 0)) {
camerZ = getFloat(fp); camerZ = getFloat(fp);
@ -581,12 +581,12 @@ bool loadGame(char *fname) {
mouseCursorAnim = new personaAnimation; mouseCursorAnim = new personaAnimation;
if (! checkNew(mouseCursorAnim)) return false; if (! checkNew(mouseCursorAnim)) return false;
if (! loadAnim(mouseCursorAnim, fp)) return false; if (! loadAnim(mouseCursorAnim, fp)) return false;
mouseCursorFrameNum = get2bytes(fp); mouseCursorFrameNum = fp->readUint16BE();
loadedFunction *rFunc; loadedFunction *rFunc;
loadedFunction * * buildList = &allRunningFunctions; loadedFunction * * buildList = &allRunningFunctions;
int countFunctions = get2bytes(fp); int countFunctions = fp->readUint16BE();
while (countFunctions --) { while (countFunctions --) {
rFunc = loadFunction(fp); rFunc = loadFunction(fp);
rFunc->next = NULL; rFunc->next = NULL;
@ -602,15 +602,15 @@ bool loadGame(char *fname) {
loadPeople(fp); loadPeople(fp);
if (fgetc(fp)) { if (fgetc(fp)) {
if (! setFloor(get2bytes(fp))) return false; if (! setFloor(fp->readUint16BE())) return false;
} else setFloorNull(); } else setFloorNull();
if (fgetc(fp)) { if (fgetc(fp)) {
if (! setZBuffer(get2bytes(fp))) return false; if (! setZBuffer(fp->readUint16BE())) return false;
} }
if (fgetc(fp)) { if (fgetc(fp)) {
if (! loadLightMap(get2bytes(fp))) return false; if (! loadLightMap(fp->readUint16BE())) return false;
} }
if (ssgVersion >= VERSION(1, 4)) { if (ssgVersion >= VERSION(1, 4)) {
@ -623,7 +623,7 @@ bool loadGame(char *fname) {
loadStatusBars(fp); loadStatusBars(fp);
loadSounds(fp); loadSounds(fp);
saveEncoding = get2bytes(fp); saveEncoding = fp->readUint16BE();
if (ssgVersion >= VERSION(1, 6)) { if (ssgVersion >= VERSION(1, 6)) {
if (ssgVersion < VERSION(2, 0)) { if (ssgVersion < VERSION(2, 0)) {
@ -637,16 +637,16 @@ bool loadGame(char *fname) {
} }
if (ssgVersion >= VERSION(1, 3)) { if (ssgVersion >= VERSION(1, 3)) {
currentBlankColour = get2bytes(fp); currentBlankColour = fp->readUint16BE();
currentBurnR = fgetc(fp); currentBurnR = fgetc(fp);
currentBurnG = fgetc(fp); currentBurnG = fgetc(fp);
currentBurnB = fgetc(fp); currentBurnB = fgetc(fp);
// Read parallax layers // Read parallax layers
while (fgetc(fp)) { while (fgetc(fp)) {
int im = get2bytes(fp); int im = fp->readUint16BE();
int fx = get2bytes(fp); int fx = fp->readUint16BE();
int fy = get2bytes(fp); int fy = fp->readUint16BE();
if (! loadParallax(im, fx, fy)) return false; if (! loadParallax(im, fx, fy)) return false;
} }

View file

@ -40,44 +40,22 @@ namespace Sludge {
bool allowAnyFilename = true; bool allowAnyFilename = true;
int getch(Common::SeekableReadStream *stream) {
return stream->readByte();
}
void putch(int c, Common::WriteStream *stream) {
stream->writeByte(c);
}
int get2bytes(Common::SeekableReadStream *stream) {
int f1, f2;
f1 = getch(stream);
f2 = getch(stream);
return (f1 * 256 + f2);
}
void put2bytes(int numtoput, Common::WriteStream *stream) {
putch((char) (numtoput / 256), stream);
putch((char) (numtoput % 256), stream);
}
void writeString(char *s, Common::WriteStream *stream) { void writeString(char *s, Common::WriteStream *stream) {
int a, len = strlen(s); int a, len = strlen(s);
put2bytes(len, stream); stream->writeUint16BE(len);
for (a = 0; a < len; ++a) { for (a = 0; a < len; ++a) {
putch(s[a] + 1, stream); stream->writeByte(s[a] + 1);
} }
} }
char *readString(Common::SeekableReadStream *stream) { char *readString(Common::SeekableReadStream *stream) {
int a, len = get2bytes(stream); int a, len = stream->readUint16BE();
char *s = new char[len + 1]; char *s = new char[len + 1];
if (!checkNew(s)) { if (!checkNew(s)) {
return NULL; return NULL;
} }
for (a = 0; a < len; ++a) { for (a = 0; a < len; ++a) {
s[a] = (char) (getch(stream) - 1); s[a] = (char)(stream->readByte() - 1);
} }
s[len] = 0; s[len] = 0;
debug(kSludgeDebugDataLoad, "Read string of length %i: %s", len, s); debug(kSludgeDebugDataLoad, "Read string of length %i: %s", len, s);
@ -101,7 +79,6 @@ float floatSwap(float f) {
float getFloat(Common::SeekableReadStream *stream) { float getFloat(Common::SeekableReadStream *stream) {
float f; float f;
size_t bytes_read = stream->read(&f, sizeof(float)); size_t bytes_read = stream->read(&f, sizeof(float));
//fread(& f, sizeof(float), 1, fp);
if (bytes_read != sizeof(float) && stream->err()) { if (bytes_read != sizeof(float) && stream->err()) {
debug("Reading error in getFloat.\n"); debug("Reading error in getFloat.\n");
} }
@ -118,7 +95,6 @@ void putFloat(float f, Common::WriteStream *stream) {
f = floatSwap(f); f = floatSwap(f);
#endif #endif
stream->write(&f, sizeof(float)); stream->write(&f, sizeof(float));
//fwrite(& f, sizeof(float), 1, fp);
} }
short shortSwap(short s) { short shortSwap(short s) {
@ -149,38 +125,6 @@ void putSigned(short f, Common::WriteStream *stream) {
stream->write(&f, sizeof(short)); stream->write(&f, sizeof(short));
} }
// The following two functions treat signed integers as unsigned.
// That's done on purpose.
int32_t get4bytes(Common::SeekableReadStream *stream) {
int f1, f2, f3, f4;
f1 = getch(stream);
f2 = getch(stream);
f3 = getch(stream);
f4 = getch(stream);
unsigned int x = f1 + f2 * 256 + f3 * 256 * 256 + f4 * 256 * 256 * 256;
return x;
}
void put4bytes(unsigned int i, Common::WriteStream *stream) {
unsigned char f1, f2, f3, f4;
f4 = i / (256 * 256 * 256);
i = i % (256 * 256 * 256);
f3 = i / (256 * 256);
i = i % (256 * 256);
f2 = i / 256;
f1 = i % 256;
putch(f1, stream);
putch(f2, stream);
putch(f3, stream);
putch(f4, stream);
}
char *encodeFilename(char *nameIn) { char *encodeFilename(char *nameIn) {
if (!nameIn) if (!nameIn)
return NULL; return NULL;

View file

@ -27,20 +27,14 @@
namespace Sludge { namespace Sludge {
// Read // Read
int getch(Common::SeekableReadStream *stream);
int get2bytes(Common::SeekableReadStream *stream);
char *readString(Common::SeekableReadStream *stream); char *readString(Common::SeekableReadStream *stream);
float getFloat(Common::SeekableReadStream *stream); float getFloat(Common::SeekableReadStream *stream);
short getSigned(Common::SeekableReadStream *stream); short getSigned(Common::SeekableReadStream *stream);
int32_t get4bytes(Common::SeekableReadStream *stream);
// Write // Write
void putch(int c, Common::WriteStream *stream);
void put2bytes(int numtoput, Common::WriteStream *stream);
void writeString(char *s, Common::WriteStream *stream); void writeString(char *s, Common::WriteStream *stream);
void putFloat(float f, Common::WriteStream *stream); void putFloat(float f, Common::WriteStream *stream);
void putSigned(short f, Common::WriteStream *stream); void putSigned(short f, Common::WriteStream *stream);
void put4bytes(uint32_t f, Common::WriteStream *stream);
char *encodeFilename(char *nameIn); char *encodeFilename(char *nameIn);
char *decodeFilename(char *nameIn); char *decodeFilename(char *nameIn);

View file

@ -56,29 +56,29 @@ objectType *loadObjectType(int i) {
if (checkNew(newType)) { if (checkNew(newType)) {
if (openObjectSlice(i)) { if (openObjectSlice(i)) {
nameNum = get2bytes(bigDataFile); nameNum = bigDataFile->readUint16BE();
newType->r = (byte) getch(bigDataFile); newType->r = (byte)bigDataFile->readByte();
newType->g = (byte) getch(bigDataFile); newType->g = (byte)bigDataFile->readByte();
newType->b = (byte) getch(bigDataFile); newType->b = (byte)bigDataFile->readByte();
newType->speechGap = getch(bigDataFile); newType->speechGap = bigDataFile->readByte();
newType->walkSpeed = getch(bigDataFile); newType->walkSpeed = bigDataFile->readByte();
newType->wrapSpeech = get4bytes(bigDataFile); newType->wrapSpeech = bigDataFile->readUint32LE();
newType->spinSpeed = get2bytes(bigDataFile); newType->spinSpeed = bigDataFile->readUint16BE();
if (gameVersion >= VERSION(1, 6)) { if (gameVersion >= VERSION(1, 6)) {
// aaLoad // aaLoad
getch(bigDataFile); bigDataFile->readByte();
getFloat(bigDataFile); getFloat(bigDataFile);
getFloat(bigDataFile); getFloat(bigDataFile);
} }
if (gameVersion >= VERSION(1, 4)) { if (gameVersion >= VERSION(1, 4)) {
newType->flags = get2bytes(bigDataFile); newType->flags = bigDataFile->readUint16BE();
} else { } else {
newType->flags = 0; newType->flags = 0;
} }
newType->numCom = get2bytes(bigDataFile); newType->numCom = bigDataFile->readUint16BE();
newType->allCombis = newType->allCombis =
(newType->numCom) ? new combination[newType->numCom] : NULL; (newType->numCom) ? new combination[newType->numCom] : NULL;
@ -90,8 +90,8 @@ objectType *loadObjectType(int i) {
#endif #endif
for (a = 0; a < newType->numCom; a++) { for (a = 0; a < newType->numCom; a++) {
newType->allCombis[a].withObj = get2bytes(bigDataFile); newType->allCombis[a].withObj = bigDataFile->readUint16BE();
newType->allCombis[a].funcNum = get2bytes(bigDataFile); newType->allCombis[a].funcNum = bigDataFile->readUint16BE();
#if DEBUG_COMBINATIONS #if DEBUG_COMBINATIONS
if (callEventLog) { if (callEventLog) {
fprintf(callEventLog, "%d(%d) ", newType -> allCombis[a].withObj, newType -> allCombis[a].funcNum); fprintf(callEventLog, "%d(%d) ", newType -> allCombis[a].withObj, newType -> allCombis[a].funcNum);
@ -117,14 +117,14 @@ objectType *loadObjectType(int i) {
} }
objectType *loadObjectRef(Common::SeekableReadStream *stream) { objectType *loadObjectRef(Common::SeekableReadStream *stream) {
objectType *r = loadObjectType(get2bytes(stream)); objectType *r = loadObjectType(stream->readUint16BE());
delete r->screenName; delete r->screenName;
r->screenName = readString(stream); r->screenName = readString(stream);
return r; return r;
} }
void saveObjectRef(objectType *r, Common::WriteStream *stream) { void saveObjectRef(objectType *r, Common::WriteStream *stream) {
put2bytes(r->objectNum, stream); stream->writeUint16BE(r->objectNum);
writeString(r->screenName, stream); writeString(r->screenName, stream);
} }

View file

@ -1009,34 +1009,34 @@ void removeOneCharacter(int i) {
} }
bool saveAnim(personaAnimation *p, Common::WriteStream *stream) { bool saveAnim(personaAnimation *p, Common::WriteStream *stream) {
put2bytes(p->numFrames, stream); stream->writeUint16BE(p->numFrames);
if (p->numFrames) { if (p->numFrames) {
put4bytes(p->theSprites->ID, stream); stream->writeUint32LE(p->theSprites->ID);
for (int a = 0; a < p->numFrames; ++a) { for (int a = 0; a < p->numFrames; ++a) {
put4bytes(p->frames[a].frameNum, stream); stream->writeUint32LE(p->frames[a].frameNum);
put4bytes(p->frames[a].howMany, stream); stream->writeUint32LE(p->frames[a].howMany);
put4bytes(p->frames[a].noise, stream); stream->writeUint32LE(p->frames[a].noise);
} }
} }
return true; return true;
} }
bool loadAnim(personaAnimation *p, Common::SeekableReadStream *stream) { bool loadAnim(personaAnimation *p, Common::SeekableReadStream *stream) {
p->numFrames = get2bytes(stream); p->numFrames = stream->readUint16BE();
if (p->numFrames) { if (p->numFrames) {
int a = get4bytes(stream); int a = stream->readUint32LE();
p->frames = new animFrame[p->numFrames]; p->frames = new animFrame[p->numFrames];
if (!checkNew(p->frames)) if (!checkNew(p->frames))
return false; return false;
p->theSprites = loadBankForAnim(a); p->theSprites = loadBankForAnim(a);
for (a = 0; a < p->numFrames; ++a) { for (a = 0; a < p->numFrames; ++a) {
p->frames[a].frameNum = get4bytes(stream); p->frames[a].frameNum = stream->readUint32LE();
p->frames[a].howMany = get4bytes(stream); p->frames[a].howMany = stream->readUint32LE();
if (ssgVersion >= VERSION(2, 0)) { if (ssgVersion >= VERSION(2, 0)) {
p->frames[a].noise = get4bytes(stream); p->frames[a].noise = stream->readUint32LE();
} else { } else {
p->frames[a].noise = 0; p->frames[a].noise = 0;
} }
@ -1064,7 +1064,7 @@ bool loadAnim(personaAnimation *p, Common::SeekableReadStream *stream) {
*/ */
bool saveCostume(persona *cossy, Common::WriteStream *stream) { bool saveCostume(persona *cossy, Common::WriteStream *stream) {
int a; int a;
put2bytes(cossy->numDirections, stream); stream->writeUint16BE(cossy->numDirections);
for (a = 0; a < cossy->numDirections * 3; ++a) { for (a = 0; a < cossy->numDirections * 3; ++a) {
if (!saveAnim(cossy->animation[a], stream)) if (!saveAnim(cossy->animation[a], stream))
return false; return false;
@ -1075,7 +1075,7 @@ bool saveCostume(persona *cossy, Common::WriteStream *stream) {
bool loadCostume(persona *cossy, Common::SeekableReadStream *stream) { bool loadCostume(persona *cossy, Common::SeekableReadStream *stream) {
int a; int a;
cossy->numDirections = get2bytes(stream); cossy->numDirections = stream->readUint16BE();
cossy->animation = new personaAnimation *[cossy->numDirections * 3]; cossy->animation = new personaAnimation *[cossy->numDirections * 3];
if (!checkNew(cossy->animation)) if (!checkNew(cossy->animation))
return false; return false;
@ -1103,7 +1103,7 @@ bool savePeople(Common::WriteStream *stream) {
me = me->next; me = me->next;
} }
put2bytes(countPeople, stream); stream->writeUint16BE(countPeople);
me = allPeople; me = allPeople;
for (a = 0; a < countPeople; ++a) { for (a = 0; a < countPeople; ++a) {
@ -1113,43 +1113,43 @@ bool savePeople(Common::WriteStream *stream) {
saveCostume(me->myPersona, stream); saveCostume(me->myPersona, stream);
saveAnim(me->myAnim, stream); saveAnim(me->myAnim, stream);
putch(me->myAnim == me->lastUsedAnim, stream); stream->writeByte(me->myAnim == me->lastUsedAnim);
putFloat(me->scale, stream); putFloat(me->scale, stream);
put2bytes(me->extra, stream); stream->writeUint16BE(me->extra);
put2bytes(me->height, stream); stream->writeUint16BE(me->height);
put2bytes(me->walkToX, stream); stream->writeUint16BE(me->walkToX);
put2bytes(me->walkToY, stream); stream->writeUint16BE(me->walkToY);
put2bytes(me->thisStepX, stream); stream->writeUint16BE(me->thisStepX);
put2bytes(me->thisStepY, stream); stream->writeUint16BE(me->thisStepY);
put2bytes(me->frameNum, stream); stream->writeUint16BE(me->frameNum);
put2bytes(me->frameTick, stream); stream->writeUint16BE(me->frameTick);
put2bytes(me->walkSpeed, stream); stream->writeUint16BE(me->walkSpeed);
put2bytes(me->spinSpeed, stream); stream->writeUint16BE(me->spinSpeed);
putSigned(me->floaty, stream); putSigned(me->floaty, stream);
putch(me->show, stream); stream->writeByte(me->show);
putch(me->walking, stream); stream->writeByte(me->walking);
putch(me->spinning, stream); stream->writeByte(me->spinning);
if (me->continueAfterWalking) { if (me->continueAfterWalking) {
putch(1, stream); stream->writeByte(1);
saveFunction(me->continueAfterWalking, stream); saveFunction(me->continueAfterWalking, stream);
} else { } else {
putch(0, stream); stream->writeByte(0);
} }
put2bytes(me->direction, stream); stream->writeUint16BE(me->direction);
put2bytes(me->angle, stream); stream->writeUint16BE(me->angle);
put2bytes(me->angleOffset, stream); stream->writeUint16BE(me->angleOffset);
put2bytes(me->wantAngle, stream); stream->writeUint16BE(me->wantAngle);
putSigned(me->directionWhenDoneWalking, stream); putSigned(me->directionWhenDoneWalking, stream);
putSigned(me->inPoly, stream); putSigned(me->inPoly, stream);
putSigned(me->walkToPoly, stream); putSigned(me->walkToPoly, stream);
putch(me->r, stream); stream->writeByte(me->r);
putch(me->g, stream); stream->writeByte(me->g);
putch(me->b, stream); stream->writeByte(me->b);
putch(me->colourmix, stream); stream->writeByte(me->colourmix);
putch(me->transparency, stream); stream->writeByte(me->transparency);
saveObjectRef(me->thisType, stream); saveObjectRef(me->thisType, stream);
@ -1165,7 +1165,7 @@ bool loadPeople(Common::SeekableReadStream *stream) {
scaleHorizon = getSigned(stream); scaleHorizon = getSigned(stream);
scaleDivide = getSigned(stream); scaleDivide = getSigned(stream);
int countPeople = get2bytes(stream); int countPeople = stream->readUint16BE();
int a; int a;
allPeople = NULL; allPeople = NULL;
@ -1188,50 +1188,50 @@ bool loadPeople(Common::SeekableReadStream *stream) {
loadCostume(me->myPersona, stream); loadCostume(me->myPersona, stream);
loadAnim(me->myAnim, stream); loadAnim(me->myAnim, stream);
me->lastUsedAnim = getch(stream) ? me->myAnim : NULL; me->lastUsedAnim = stream->readByte() ? me->myAnim : NULL;
me->scale = getFloat(stream); me->scale = getFloat(stream);
me->extra = get2bytes(stream); me->extra = stream->readUint16BE();
me->height = get2bytes(stream); me->height = stream->readUint16BE();
me->walkToX = get2bytes(stream); me->walkToX = stream->readUint16BE();
me->walkToY = get2bytes(stream); me->walkToY = stream->readUint16BE();
me->thisStepX = get2bytes(stream); me->thisStepX = stream->readUint16BE();
me->thisStepY = get2bytes(stream); me->thisStepY = stream->readUint16BE();
me->frameNum = get2bytes(stream); me->frameNum = stream->readUint16BE();
me->frameTick = get2bytes(stream); me->frameTick = stream->readUint16BE();
me->walkSpeed = get2bytes(stream); me->walkSpeed = stream->readUint16BE();
me->spinSpeed = get2bytes(stream); me->spinSpeed = stream->readUint16BE();
me->floaty = getSigned(stream); me->floaty = getSigned(stream);
me->show = getch(stream); me->show = stream->readByte();
me->walking = getch(stream); me->walking = stream->readByte();
me->spinning = getch(stream); me->spinning = stream->readByte();
if (getch(stream)) { if (stream->readByte()) {
me->continueAfterWalking = loadFunction(stream); me->continueAfterWalking = loadFunction(stream);
if (!me->continueAfterWalking) if (!me->continueAfterWalking)
return false; return false;
} else { } else {
me->continueAfterWalking = NULL; me->continueAfterWalking = NULL;
} }
me->direction = get2bytes(stream); me->direction = stream->readUint16BE();
me->angle = get2bytes(stream); me->angle = stream->readUint16BE();
if (ssgVersion >= VERSION(2, 0)) { if (ssgVersion >= VERSION(2, 0)) {
me->angleOffset = get2bytes(stream); me->angleOffset = stream->readUint16BE();
} else { } else {
me->angleOffset = 0; me->angleOffset = 0;
} }
me->wantAngle = get2bytes(stream); me->wantAngle = stream->readUint16BE();
me->directionWhenDoneWalking = getSigned(stream); me->directionWhenDoneWalking = getSigned(stream);
me->inPoly = getSigned(stream); me->inPoly = getSigned(stream);
me->walkToPoly = getSigned(stream); me->walkToPoly = getSigned(stream);
if (ssgVersion >= VERSION(2, 0)) { if (ssgVersion >= VERSION(2, 0)) {
me->r = getch(stream); me->r = stream->readByte();
me->g = getch(stream); me->g = stream->readByte();
me->b = getch(stream); me->b = stream->readByte();
me->colourmix = getch(stream); me->colourmix = stream->readByte();
me->transparency = getch(stream); me->transparency = stream->readByte();
} else { } else {
setMyDrawMode(me, get2bytes(stream)); setMyDrawMode(me, stream->readUint16BE());
} }
me->thisType = loadObjectRef(stream); me->thisType = loadObjectRef(stream);
@ -1239,7 +1239,7 @@ bool loadPeople(Common::SeekableReadStream *stream) {
if (ssgVersion >= VERSION(1, 6)) { if (ssgVersion >= VERSION(1, 6)) {
if (ssgVersion < VERSION(2, 0)) { if (ssgVersion < VERSION(2, 0)) {
// aaLoad // aaLoad
getch(stream); stream->readByte();
getFloat(stream); getFloat(stream);
getFloat(stream); getFloat(stream);
} }

View file

@ -72,16 +72,16 @@ void saveRegions(Common::WriteStream *stream) {
thisRegion = thisRegion->next; thisRegion = thisRegion->next;
numRegions++; numRegions++;
} }
put2bytes(numRegions, stream); stream->writeUint16BE(numRegions);
thisRegion = allScreenRegions; thisRegion = allScreenRegions;
while (thisRegion) { while (thisRegion) {
put2bytes(thisRegion->x1, stream); stream->writeUint16BE(thisRegion->x1);
put2bytes(thisRegion->y1, stream); stream->writeUint16BE(thisRegion->y1);
put2bytes(thisRegion->x2, stream); stream->writeUint16BE(thisRegion->x2);
put2bytes(thisRegion->y2, stream); stream->writeUint16BE(thisRegion->y2);
put2bytes(thisRegion->sX, stream); stream->writeUint16BE(thisRegion->sX);
put2bytes(thisRegion->sY, stream); stream->writeUint16BE(thisRegion->sY);
put2bytes(thisRegion->di, stream); stream->writeUint16BE(thisRegion->di);
saveObjectRef(thisRegion->thisType, stream); saveObjectRef(thisRegion->thisType, stream);
thisRegion = thisRegion->next; thisRegion = thisRegion->next;
@ -89,7 +89,7 @@ void saveRegions(Common::WriteStream *stream) {
} }
void loadRegions(Common::SeekableReadStream *stream) { void loadRegions(Common::SeekableReadStream *stream) {
int numRegions = get2bytes(stream); int numRegions = stream->readUint16BE();
screenRegion *newRegion; screenRegion *newRegion;
screenRegion * * pointy = &allScreenRegions; screenRegion * * pointy = &allScreenRegions;
@ -99,13 +99,13 @@ void loadRegions(Common::SeekableReadStream *stream) {
*pointy = newRegion; *pointy = newRegion;
pointy = &(newRegion->next); pointy = &(newRegion->next);
newRegion->x1 = get2bytes(stream); newRegion->x1 = stream->readUint16BE();
newRegion->y1 = get2bytes(stream); newRegion->y1 = stream->readUint16BE();
newRegion->x2 = get2bytes(stream); newRegion->x2 = stream->readUint16BE();
newRegion->y2 = get2bytes(stream); newRegion->y2 = stream->readUint16BE();
newRegion->sX = get2bytes(stream); newRegion->sX = stream->readUint16BE();
newRegion->sY = get2bytes(stream); newRegion->sY = stream->readUint16BE();
newRegion->di = get2bytes(stream); newRegion->di = stream->readUint16BE();
newRegion->thisType = loadObjectRef(stream); newRegion->thisType = loadObjectRef(stream);
} }
*pointy = NULL; *pointy = NULL;

View file

@ -64,20 +64,20 @@ extern char *gamePath;
void writeStringEncoded(const char *s, Common::WriteStream *stream) { void writeStringEncoded(const char *s, Common::WriteStream *stream) {
int a, len = strlen(s); int a, len = strlen(s);
put2bytes(len, stream); stream->writeUint16BE(len);
for (a = 0; a < len; a++) { for (a = 0; a < len; a++) {
putch(s[a] ^ encode1, stream); stream->writeByte(s[a] ^ encode1);
encode1 += encode2; encode1 += encode2;
} }
} }
char *readStringEncoded(Common::File *fp) { char *readStringEncoded(Common::File *fp) {
int a, len = get2bytes(fp); int a, len = fp->readUint16BE();
char *s = new char[len + 1]; char *s = new char[len + 1];
if (!checkNew(s)) if (!checkNew(s))
return NULL; return NULL;
for (a = 0; a < len; a++) { for (a = 0; a < len; a++) {
s[a] = (char) (getch(fp) ^ encode1); s[a] = (char) (fp->readByte() ^ encode1);
encode1 += encode2; encode1 += encode2;
} }
s[len] = 0; s[len] = 0;
@ -95,7 +95,7 @@ char *readTextPlain(Common::File *fp) {
startPos = fp->pos(); startPos = fp->pos();
while (keepGoing) { while (keepGoing) {
gotChar = (char) getch(fp); gotChar = (char) fp->readByte();
if ((gotChar == '\n') || (fp->eos())) { if ((gotChar == '\n') || (fp->eos())) {
keepGoing = false; keepGoing = false;
} else { } else {
@ -114,7 +114,7 @@ char *readTextPlain(Common::File *fp) {
if (bytes_read != stringSize && fp->err()) { if (bytes_read != stringSize && fp->err()) {
debugOut("Reading error in readTextPlain.\n"); debugOut("Reading error in readTextPlain.\n");
} }
getch(fp); // Skip the newline character fp->readByte(); // Skip the newline character
reply[stringSize] = 0; reply[stringSize] = 0;
} }
@ -157,7 +157,7 @@ bool fileToStack(char *filename, stackHandler *sH) {
encode2 = (unsigned char) (saveEncoding >> 8); encode2 = (unsigned char) (saveEncoding >> 8);
while (*checker) { while (*checker) {
if (getch(&fd) != *checker) { if (fd.readByte() != *checker) {
fd.close(); fd.close();
return fatal(LOAD_ERROR "This isn't a SLUDGE custom data file:", return fatal(LOAD_ERROR "This isn't a SLUDGE custom data file:",
filename); filename);
@ -179,7 +179,7 @@ bool fileToStack(char *filename, stackHandler *sH) {
for (;;) { for (;;) {
if (saveEncoding) { if (saveEncoding) {
char i = getch(&fd) ^ encode1; char i = fd.readByte() ^ encode1;
if (fd.eos()) if (fd.eos())
break; break;
@ -192,11 +192,11 @@ bool fileToStack(char *filename, stackHandler *sH) {
break; break;
case 1: case 1:
setVariable(stringVar, SVT_INT, get4bytes(&fd)); setVariable(stringVar, SVT_INT, fd.readUint32LE());
break; break;
case 2: case 2:
setVariable(stringVar, SVT_INT, getch(&fd)); setVariable(stringVar, SVT_INT, fd.readByte());
break; break;
default: default:
@ -260,7 +260,7 @@ bool stackToFile(char *filename, const variable &from) {
fputc(hereWeAre -> thisVar.varData.intValue, fp); fputc(hereWeAre -> thisVar.varData.intValue, fp);
} else { } else {
fputc(1 ^ encode1, fp); fputc(1 ^ encode1, fp);
put4bytes(hereWeAre -> thisVar.varData.intValue, fp); fp->writeUint32LE(hereWeAre -> thisVar.varData.intValue);
} }
break; break;

View file

@ -127,23 +127,23 @@ const char *sludgeText[] = { "?????", "RETURN", "BRANCH", "BR_ZERO",
"INDEXGET", "INC_INDEX", "DEC_INDEX", "QUICK_PUSH" }; "INDEXGET", "INC_INDEX", "DEC_INDEX", "QUICK_PUSH" };
void loadHandlers(Common::SeekableReadStream *stream) { void loadHandlers(Common::SeekableReadStream *stream) {
currentEvents->leftMouseFunction = get2bytes(stream); currentEvents->leftMouseFunction = stream->readUint16BE();
currentEvents->leftMouseUpFunction = get2bytes(stream); currentEvents->leftMouseUpFunction = stream->readUint16BE();
currentEvents->rightMouseFunction = get2bytes(stream); currentEvents->rightMouseFunction = stream->readUint16BE();
currentEvents->rightMouseUpFunction = get2bytes(stream); currentEvents->rightMouseUpFunction = stream->readUint16BE();
currentEvents->moveMouseFunction = get2bytes(stream); currentEvents->moveMouseFunction = stream->readUint16BE();
currentEvents->focusFunction = get2bytes(stream); currentEvents->focusFunction = stream->readUint16BE();
currentEvents->spaceFunction = get2bytes(stream); currentEvents->spaceFunction = stream->readUint16BE();
} }
void saveHandlers(Common::WriteStream *stream) { void saveHandlers(Common::WriteStream *stream) {
put2bytes(currentEvents->leftMouseFunction, stream); stream->writeUint16BE(currentEvents->leftMouseFunction);
put2bytes(currentEvents->leftMouseUpFunction, stream); stream->writeUint16BE(currentEvents->leftMouseUpFunction);
put2bytes(currentEvents->rightMouseFunction, stream); stream->writeUint16BE(currentEvents->rightMouseFunction);
put2bytes(currentEvents->rightMouseUpFunction, stream); stream->writeUint16BE(currentEvents->rightMouseUpFunction);
put2bytes(currentEvents->moveMouseFunction, stream); stream->writeUint16BE(currentEvents->moveMouseFunction);
put2bytes(currentEvents->focusFunction, stream); stream->writeUint16BE(currentEvents->focusFunction);
put2bytes(currentEvents->spaceFunction, stream); stream->writeUint16BE(currentEvents->spaceFunction);
} }
Common::File *openAndVerify(char *filename, char extra1, char extra2, Common::File *openAndVerify(char *filename, char extra1, char extra2,
@ -154,32 +154,32 @@ Common::File *openAndVerify(char *filename, char extra1, char extra2,
return NULL; return NULL;
} }
bool headerBad = false; bool headerBad = false;
if (getch(fp) != 'S') if (fp->readByte() != 'S')
headerBad = true; headerBad = true;
if (getch(fp) != 'L') if (fp->readByte() != 'L')
headerBad = true; headerBad = true;
if (getch(fp) != 'U') if (fp->readByte() != 'U')
headerBad = true; headerBad = true;
if (getch(fp) != 'D') if (fp->readByte() != 'D')
headerBad = true; headerBad = true;
if (getch(fp) != extra1) if (fp->readByte() != extra1)
headerBad = true; headerBad = true;
if (getch(fp) != extra2) if (fp->readByte() != extra2)
headerBad = true; headerBad = true;
if (headerBad) { if (headerBad) {
fatal(er, filename); fatal(er, filename);
return NULL; return NULL;
} }
char c; char c;
c = getch(fp); c = fp->readByte();
debug("%c", c); debug("%c", c);
while ((c = getch(fp))) { while ((c = fp->readByte())) {
debug("%c", c); debug("%c", c);
} }
int majVersion = getch(fp); int majVersion = fp->readByte();
debug(kSludgeDebugDataLoad, "majVersion %i", majVersion); debug(kSludgeDebugDataLoad, "majVersion %i", majVersion);
int minVersion = getch(fp); int minVersion = fp->readByte();
debug(kSludgeDebugDataLoad, "minVersion %i", minVersion); debug(kSludgeDebugDataLoad, "minVersion %i", minVersion);
fileVersion = majVersion * 256 + minVersion; fileVersion = majVersion * 256 + minVersion;
@ -206,9 +206,9 @@ bool initSludge(char *filename) {
if (!fp) if (!fp)
return false; return false;
char c = getch(fp); char c = fp->readByte();
if (c) { if (c) {
numBIFNames = get2bytes(fp); numBIFNames = fp->readUint16BE();
debug(kSludgeDebugDataLoad, "numBIFNames %i", numBIFNames); debug(kSludgeDebugDataLoad, "numBIFNames %i", numBIFNames);
allBIFNames = new char *[numBIFNames]; allBIFNames = new char *[numBIFNames];
if (!checkNew(allBIFNames)) if (!checkNew(allBIFNames))
@ -217,7 +217,7 @@ bool initSludge(char *filename) {
for (int fn = 0; fn < numBIFNames; fn++) { for (int fn = 0; fn < numBIFNames; fn++) {
allBIFNames[fn] = readString(fp); allBIFNames[fn] = readString(fp);
} }
numUserFunc = get2bytes(fp); numUserFunc = fp->readUint16BE();
debug(kSludgeDebugDataLoad, "numUserFunc %i", numUserFunc); debug(kSludgeDebugDataLoad, "numUserFunc %i", numUserFunc);
allUserFunc = new char *[numUserFunc]; allUserFunc = new char *[numUserFunc];
if (!checkNew(allUserFunc)) if (!checkNew(allUserFunc))
@ -227,7 +227,7 @@ bool initSludge(char *filename) {
allUserFunc[fn] = readString(fp); allUserFunc[fn] = readString(fp);
} }
if (gameVersion >= VERSION(1, 3)) { if (gameVersion >= VERSION(1, 3)) {
numResourceNames = get2bytes(fp); numResourceNames = fp->readUint16BE();
debug(kSludgeDebugDataLoad, "numResourceNames %i", debug(kSludgeDebugDataLoad, "numResourceNames %i",
numResourceNames); numResourceNames);
allResourceNames = new char *[numResourceNames]; allResourceNames = new char *[numResourceNames];
@ -240,13 +240,13 @@ bool initSludge(char *filename) {
} }
} }
winWidth = get2bytes(fp); winWidth = fp->readUint16BE();
debug(kSludgeDebugDataLoad, "winWidth : %i", winWidth); debug(kSludgeDebugDataLoad, "winWidth : %i", winWidth);
winHeight = get2bytes(fp); winHeight = fp->readUint16BE();
debug(kSludgeDebugDataLoad, "winHeight : %i", winHeight); debug(kSludgeDebugDataLoad, "winHeight : %i", winHeight);
specialSettings = getch(fp); specialSettings = fp->readByte();
debug(kSludgeDebugDataLoad, "specialSettings : %i", specialSettings); debug(kSludgeDebugDataLoad, "specialSettings : %i", specialSettings);
desiredfps = 1000 / getch(fp); desiredfps = 1000 / fp->readByte();
delete[] readString(fp); // Unused - was used for registration purposes. delete[] readString(fp); // Unused - was used for registration purposes.
@ -261,14 +261,14 @@ bool initSludge(char *filename) {
debug(kSludgeDebugDataLoad, "dataFol : %s", dataFol); debug(kSludgeDebugDataLoad, "dataFol : %s", dataFol);
gameSettings.numLanguages = gameSettings.numLanguages =
(gameVersion >= VERSION(1, 3)) ? (getch(fp)) : 0; (gameVersion >= VERSION(1, 3)) ? (fp->readByte()) : 0;
debug(kSludgeDebugDataLoad, "numLanguages : %c", gameSettings.numLanguages); debug(kSludgeDebugDataLoad, "numLanguages : %c", gameSettings.numLanguages);
makeLanguageTable(fp); makeLanguageTable(fp);
if (gameVersion >= VERSION(1, 6)) { if (gameVersion >= VERSION(1, 6)) {
getch(fp); fp->readByte();
// aaLoad // aaLoad
getch(fp); fp->readByte();
getFloat(fp); getFloat(fp);
getFloat(fp); getFloat(fp);
} }
@ -281,7 +281,7 @@ bool initSludge(char *filename) {
delete checker; delete checker;
checker = NULL; checker = NULL;
unsigned char customIconLogo = getch(fp); unsigned char customIconLogo = fp->readByte();
debug(kSludgeDebugDataLoad, "Game icon type: %i", customIconLogo); debug(kSludgeDebugDataLoad, "Game icon type: %i", customIconLogo);
if (customIconLogo & 1) { if (customIconLogo & 1) {
@ -309,8 +309,8 @@ bool initSludge(char *filename) {
fileIsPNG = false; fileIsPNG = false;
fseek(fp, file_pointer, SEEK_SET); fseek(fp, file_pointer, SEEK_SET);
iconW = get2bytes(fp); iconW = fp->readUint16BE();
iconH = get2bytes(fp); iconH = fp->readUint16BE();
} else { } else {
// Read the PNG header // Read the PNG header
@ -373,7 +373,7 @@ bool initSludge(char *filename) {
for (int t2 = 0; t2 < iconH; t2 ++) { for (int t2 = 0; t2 < iconH; t2 ++) {
int t1 = 0; int t1 = 0;
while (t1 < iconW) { while (t1 < iconW) {
unsigned short c = (unsigned short) get2bytes(fp); unsigned short c = (unsigned short) fp->readUint16BE();
if (c & 32) { if (c & 32) {
n = fgetc(fp) + 1; n = fgetc(fp) + 1;
c -= 32; c -= 32;
@ -418,8 +418,8 @@ bool initSludge(char *filename) {
fileIsPNG = false; fileIsPNG = false;
fseek(fp, file_pointer, SEEK_SET); fseek(fp, file_pointer, SEEK_SET);
logoW = get2bytes(fp); logoW = fp->readUint16BE();
logoH = get2bytes(fp); logoH = fp->readUint16BE();
} else { } else {
// Read the PNG header // Read the PNG header
@ -490,7 +490,7 @@ bool initSludge(char *filename) {
for (int t2 = 0; t2 < logoH; t2 ++) { for (int t2 = 0; t2 < logoH; t2 ++) {
int t1 = 0; int t1 = 0;
while (t1 < logoW) { while (t1 < logoW) {
unsigned short c = (unsigned short) get2bytes(fp); unsigned short c = (unsigned short) fp->readUint16BE();
if (c & 32) { if (c & 32) {
n = fgetc(fp) + 1; n = fgetc(fp) + 1;
c -= 32; c -= 32;
@ -518,7 +518,7 @@ bool initSludge(char *filename) {
#endif #endif
} }
numGlobals = get2bytes(fp); numGlobals = fp->readUint16BE();
debug("numGlobals : %i", numGlobals); debug("numGlobals : %i", numGlobals);
globalVars = new variable[numGlobals]; globalVars = new variable[numGlobals];
@ -1398,21 +1398,20 @@ bool loadFunctionCode(loadedFunction *newFunc) {
debug(kSludgeDebugDataLoad, "Load function code"); debug(kSludgeDebugDataLoad, "Load function code");
newFunc->unfreezable = getch(bigDataFile); newFunc->unfreezable = bigDataFile->readByte();
numLines = get2bytes(bigDataFile); numLines = bigDataFile->readUint16BE();
debug(kSludgeDebugDataLoad, "numLines: %i", numLines); debug(kSludgeDebugDataLoad, "numLines: %i", numLines);
newFunc->numArgs = get2bytes(bigDataFile); newFunc->numArgs = bigDataFile->readUint16BE();
debug(kSludgeDebugDataLoad, "numArgs: %i", newFunc->numArgs); debug(kSludgeDebugDataLoad, "numArgs: %i", newFunc->numArgs);
newFunc->numLocals = get2bytes(bigDataFile); newFunc->numLocals = bigDataFile->readUint16BE();
debug(kSludgeDebugDataLoad, "numLocals: %i", newFunc->numLocals); debug(kSludgeDebugDataLoad, "numLocals: %i", newFunc->numLocals);
newFunc->compiledLines = new lineOfCode[numLines]; newFunc->compiledLines = new lineOfCode[numLines];
if (!checkNew(newFunc->compiledLines)) if (!checkNew(newFunc->compiledLines))
return false; return false;
for (numLinesRead = 0; numLinesRead < numLines; numLinesRead++) { for (numLinesRead = 0; numLinesRead < numLines; numLinesRead++) {
newFunc->compiledLines[numLinesRead].theCommand = (sludgeCommand) getch( newFunc->compiledLines[numLinesRead].theCommand = (sludgeCommand) bigDataFile->readByte();
bigDataFile); newFunc->compiledLines[numLinesRead].param = bigDataFile->readUint16BE();
newFunc->compiledLines[numLinesRead].param = get2bytes(bigDataFile);
debug(kSludgeDebugDataLoad, "command line %i: %i", numLinesRead, debug(kSludgeDebugDataLoad, "command line %i: %i", numLinesRead,
newFunc->compiledLines[numLinesRead].theCommand); newFunc->compiledLines[numLinesRead].theCommand);
} }

View file

@ -379,29 +379,29 @@ void saveSounds(Common::WriteStream *stream) {
if (soundOK) { if (soundOK) {
for (int i = 0; i < MAX_SAMPLES; i++) { for (int i = 0; i < MAX_SAMPLES; i++) {
if (soundCache[i].looping) { if (soundCache[i].looping) {
putch(1, stream); stream->writeByte(1);
put2bytes(soundCache[i].fileLoaded, stream); stream->writeUint16BE(soundCache[i].fileLoaded);
put2bytes(soundCache[i].vol, stream); stream->writeUint16BE(soundCache[i].vol);
} }
} }
} }
putch(0, stream); stream->writeByte(0);
put2bytes(defSoundVol, stream); stream->writeUint16BE(defSoundVol);
put2bytes(defVol, stream); stream->writeUint16BE(defVol);
} }
void loadSounds(Common::SeekableReadStream *stream) { void loadSounds(Common::SeekableReadStream *stream) {
for (int i = 0; i < MAX_SAMPLES; i++) for (int i = 0; i < MAX_SAMPLES; i++)
freeSound(i); freeSound(i);
while (getch(stream)) { while (stream->readByte()) {
int fileLoaded = get2bytes(stream); int fileLoaded = stream->readUint16BE();
defSoundVol = get2bytes(stream); defSoundVol = stream->readUint16BE();
startSound(fileLoaded, 1); startSound(fileLoaded, 1);
} }
defSoundVol = get2bytes(stream); defSoundVol = stream->readUint16BE();
defVol = get2bytes(stream); defVol = stream->readUint16BE();
} }
bool getSoundCacheStack(stackHandler *sH) { bool getSoundCacheStack(stackHandler *sH) {

View file

@ -113,19 +113,19 @@ bool startSound(int f, bool loopy) {
} }
void saveSounds(Common::WriteStream *stream) { void saveSounds(Common::WriteStream *stream) {
putch(0, stream); stream->writeByte(0);
put2bytes(defSoundVol, stream); stream->writeUint16BE(defSoundVol);
put2bytes(defVol, stream); stream->writeUint16BE(defVol);
} }
void loadSounds(Common::SeekableReadStream *stream) { void loadSounds(Common::SeekableReadStream *stream) {
while (getch(stream)) { while (stream->readByte()) {
get2bytes(stream); stream->readUint16BE();
get2bytes(stream); stream->readUint16BE();
} }
defSoundVol = get2bytes(stream); defSoundVol = stream->readUint16BE();
defVol = get2bytes(stream); defVol = stream->readUint16BE();
} }
bool getSoundCacheStack(stackHandler *sH) { bool getSoundCacheStack(stackHandler *sH) {

View file

@ -606,29 +606,29 @@ void saveSounds(Common::WriteStream *stream) {
if (soundOK) { if (soundOK) {
for (int i = 0; i < MAX_SAMPLES; i++) { for (int i = 0; i < MAX_SAMPLES; i++) {
if (soundCache[i].looping) { if (soundCache[i].looping) {
putch(1, stream); stream->writeByte(1);
put2bytes(soundCache[i].fileLoaded, stream); stream->writeUint16BE(soundCache[i].fileLoaded);
put2bytes(soundCache[i].vol, stream); stream->writeUint16BE(soundCache[i].vol);
} }
} }
} }
putch(0, stream); stream->writeByte(0);
put2bytes(defSoundVol, stream); stream->writeUint16BE(defSoundVol);
put2bytes(defVol, stream); stream->writeUint16BE(defVol);
} }
void loadSounds(Common::SeekableReadStream *stream) { void loadSounds(Common::SeekableReadStream *stream) {
for (int i = 0; i < MAX_SAMPLES; i++) for (int i = 0; i < MAX_SAMPLES; i++)
freeSound(i); freeSound(i);
while (getch(stream)) { while (stream->readByte()) {
int fileLoaded = get2bytes(stream); int fileLoaded = stream->readUint16BE();
defSoundVol = get2bytes(stream); defSoundVol = stream->readUint16BE();
startSound(fileLoaded, 1); startSound(fileLoaded, 1);
} }
defSoundVol = get2bytes(stream); defSoundVol = stream->readUint16BE();
defVol = get2bytes(stream); defVol = stream->readUint16BE();
} }
bool getSoundCacheStack(stackHandler *sH) { bool getSoundCacheStack(stackHandler *sH) {

View file

@ -130,13 +130,13 @@ bool loadSpriteBank(int fileNum, spriteBank &loadhere, bool isFont) {
loadhere.isFont = isFont; loadhere.isFont = isFont;
total = get2bytes(bigDataFile); total = bigDataFile->readUint16BE();
if (! total) { if (! total) {
spriteBankVersion = fgetc(bigDataFile); spriteBankVersion = fgetc(bigDataFile);
if (spriteBankVersion == 1) { if (spriteBankVersion == 1) {
total = 0; total = 0;
} else { } else {
total = get2bytes(bigDataFile); total = bigDataFile->readUint16BE();
} }
} }
@ -223,8 +223,8 @@ bool loadSpriteBank(int fileNum, spriteBank &loadhere, bool isFont) {
break; break;
} }
case 2: case 2:
picwidth = get2bytes(bigDataFile); picwidth = bigDataFile->readUint16BE();
picheight = get2bytes(bigDataFile); picheight = bigDataFile->readUint16BE();
loadhere.sprites[i].xhot = getSigned(bigDataFile); loadhere.sprites[i].xhot = getSigned(bigDataFile);
loadhere.sprites[i].yhot = getSigned(bigDataFile); loadhere.sprites[i].yhot = getSigned(bigDataFile);
break; break;

View file

@ -29,6 +29,7 @@
#include "stringy.h" #include "stringy.h"
#include "newfatal.h" #include "newfatal.h"
#include "statusba.h" #include "statusba.h"
#include "common/file.h"
namespace Sludge { namespace Sludge {
@ -176,48 +177,48 @@ const char *statusBarText() {
void saveStatusBars(Common::WriteStream *stream) { void saveStatusBars(Common::WriteStream *stream) {
statusBar *viewLine = nowStatus->firstStatusBar; statusBar *viewLine = nowStatus->firstStatusBar;
put2bytes(nowStatus->alignStatus, stream); stream->writeUint16BE(nowStatus->alignStatus);
putSigned(nowStatus->litStatus, stream); putSigned(nowStatus->litStatus, stream);
put2bytes(nowStatus->statusX, stream); stream->writeUint16BE(nowStatus->statusX);
put2bytes(nowStatus->statusY, stream); stream->writeUint16BE(nowStatus->statusY);
putch(nowStatus->statusR, stream); stream->writeByte(nowStatus->statusR);
putch(nowStatus->statusG, stream); stream->writeByte(nowStatus->statusG);
putch(nowStatus->statusB, stream); stream->writeByte(nowStatus->statusB);
putch(nowStatus->statusLR, stream); stream->writeByte(nowStatus->statusLR);
putch(nowStatus->statusLG, stream); stream->writeByte(nowStatus->statusLG);
putch(nowStatus->statusLB, stream); stream->writeByte(nowStatus->statusLB);
// Write what's being said // Write what's being said
while (viewLine) { while (viewLine) {
putch(1, stream); stream->writeByte(1);
writeString(viewLine->text, stream); writeString(viewLine->text, stream);
viewLine = viewLine->next; viewLine = viewLine->next;
} }
putch(0, stream); stream->writeByte(0);
} }
bool loadStatusBars(Common::SeekableReadStream *stream) { bool loadStatusBars(Common::SeekableReadStream *stream) {
clearStatusBar(); clearStatusBar();
nowStatus->alignStatus = get2bytes(stream); nowStatus->alignStatus = stream->readUint16BE();
nowStatus->litStatus = getSigned(stream); nowStatus->litStatus = getSigned(stream);
nowStatus->statusX = get2bytes(stream); nowStatus->statusX = stream->readUint16BE();
nowStatus->statusY = get2bytes(stream); nowStatus->statusY = stream->readUint16BE();
nowStatus->statusR = getch(stream); nowStatus->statusR = stream->readByte();
nowStatus->statusG = getch(stream); nowStatus->statusG = stream->readByte();
nowStatus->statusB = getch(stream); nowStatus->statusB = stream->readByte();
nowStatus->statusLR = getch(stream); nowStatus->statusLR = stream->readByte();
nowStatus->statusLG = getch(stream); nowStatus->statusLG = stream->readByte();
nowStatus->statusLB = getch(stream); nowStatus->statusLB = stream->readByte();
setFontColour(verbLinePalette, nowStatus->statusR, nowStatus->statusG, nowStatus->statusB); setFontColour(verbLinePalette, nowStatus->statusR, nowStatus->statusG, nowStatus->statusB);
setFontColour(litVerbLinePalette, nowStatus->statusLR, nowStatus->statusLG, nowStatus->statusLB); setFontColour(litVerbLinePalette, nowStatus->statusLR, nowStatus->statusLG, nowStatus->statusLB);
// Read what's being said // Read what's being said
statusBar * * viewLine = & (nowStatus->firstStatusBar); statusBar * * viewLine = & (nowStatus->firstStatusBar);
statusBar *newOne; statusBar *newOne;
while (getch(stream)) { while (stream->readByte()) {
newOne = new statusBar; newOne = new statusBar;
if (! checkNew(newOne)) return false; if (! checkNew(newOne)) return false;
newOne->text = readString(stream); newOne->text = readString(stream);

View file

@ -219,32 +219,32 @@ void saveSpeech(speechStruct *sS, Common::WriteStream *stream) {
#if 0 #if 0
speechLine *viewLine = sS->allSpeech; speechLine *viewLine = sS->allSpeech;
putch(sS->talkCol.originalRed, stream); stream->writeByte(sS->talkCol.originalRed);
putch(sS->talkCol.originalGreen, stream); stream->writeByte(sS->talkCol.originalGreen);
putch(sS->talkCol.originalBlue, stream); stream->writeByte(sS->talkCol.originalBlue);
putFloat(speechSpeed, stream); putFloat(speechSpeed, stream);
// Write y co-ordinate // Write y co-ordinate
put2bytes(sS->speechY, stream); stream->writeUint16BE(sS->speechY);
// Write which character's talking // Write which character's talking
put2bytes(sS->lookWhosTalking, stream); stream->writeUint16BE(sS->lookWhosTalking);
if (sS->currentTalker) { if (sS->currentTalker) {
putch(1, stream); stream->writeByte(1);
put2bytes(sS->currentTalker->thisType->objectNum, stream); stream->writeUint16BE(sS->currentTalker->thisType->objectNum);
} else { } else {
putch(0, stream); stream->writeByte(0);
} }
// Write what's being said // Write what's being said
while (viewLine) { while (viewLine) {
putch(1, stream); stream->writeByte(1);
writeString(viewLine->textLine, stream); writeString(viewLine->textLine, stream);
put2bytes(viewLine->x, stream); stream->writeUint16BE(viewLine->x);
viewLine = viewLine->next; viewLine = viewLine->next;
} }
putch(0, stream); stream->writeByte(0);
#endif #endif
} }
@ -252,21 +252,21 @@ bool loadSpeech(speechStruct *sS, Common::SeekableReadStream *stream) {
#if 0 #if 0
speech->currentTalker = NULL; speech->currentTalker = NULL;
killAllSpeech(); killAllSpeech();
byte r = getch(stream); byte r = stream->readByte();
byte g = getch(stream); byte g = stream->readByte();
byte b = getch(stream); byte b = stream->readByte();
setFontColour(sS->talkCol, r, g, b); setFontColour(sS->talkCol, r, g, b);
speechSpeed = getFloat(stream); speechSpeed = getFloat(stream);
// Read y co-ordinate // Read y co-ordinate
sS->speechY = get2bytes(stream); sS->speechY = stream->readUint16BE();
// Read which character's talking // Read which character's talking
sS->lookWhosTalking = get2bytes(stream); sS->lookWhosTalking = stream->readUint16BE();
if (getch(stream)) { if (stream->readByte()) {
sS->currentTalker = findPerson(get2bytes(stream)); sS->currentTalker = findPerson(stream->readUint16BE());
} else { } else {
sS->currentTalker = NULL; sS->currentTalker = NULL;
} }
@ -275,11 +275,11 @@ bool loadSpeech(speechStruct *sS, Common::SeekableReadStream *stream) {
speechLine * * viewLine = &sS->allSpeech; speechLine * * viewLine = &sS->allSpeech;
speechLine *newOne; speechLine *newOne;
speech->lastFile = -1; speech->lastFile = -1;
while (getch(stream)) { while (stream->readByte()) {
newOne = new speechLine; newOne = new speechLine;
if (! checkNew(newOne)) return false; if (! checkNew(newOne)) return false;
newOne->textLine = readString(stream); newOne->textLine = readString(stream);
newOne->x = get2bytes(stream); newOne->x = stream->readUint16BE();
newOne->next = NULL; newOne->next = NULL;
(* viewLine) = newOne; (* viewLine) = newOne;
viewLine = &(newOne->next); viewLine = &(newOne->next);

View file

@ -44,8 +44,8 @@ bool saveThumbnail(Common::WriteStream *stream) {
#if 0 #if 0
GLuint thumbnailTextureName = 0; GLuint thumbnailTextureName = 0;
put4bytes(thumbWidth, fp); fp->writeUint32LE(thumbWidth);
put4bytes(thumbHeight, fp); fp->writeUint32LE(thumbHeight);
if (thumbWidth && thumbHeight) { if (thumbWidth && thumbHeight) {
if (! freeze()) return false; if (! freeze()) return false;
@ -148,8 +148,8 @@ void showThumbnail(char *filename, int atX, int atY) {
FILE *fp = openAndVerify(filename, 'S', 'A', ERROR_GAME_LOAD_NO, ssgVersion); FILE *fp = openAndVerify(filename, 'S', 'A', ERROR_GAME_LOAD_NO, ssgVersion);
if (ssgVersion >= VERSION(1, 4)) { if (ssgVersion >= VERSION(1, 4)) {
if (fp == NULL) return; if (fp == NULL) return;
int fileWidth = get4bytes(fp); int fileWidth = fp->readUint32LE();
int fileHeight = get4bytes(fp); int fileHeight = fp->readUint32LE();
int picWidth = fileWidth; int picWidth = fileWidth;
int picHeight = fileHeight; int picHeight = fileHeight;
@ -170,7 +170,7 @@ void showThumbnail(char *filename, int atX, int atY) {
for (t2 = 0; t2 < fileHeight; t2 ++) { for (t2 = 0; t2 < fileHeight; t2 ++) {
t1 = 0; t1 = 0;
while (t1 < fileWidth) { while (t1 < fileWidth) {
c = (unsigned short) get2bytes(fp); c = (unsigned short) fp->readUint16BE();
target = thumbnailTexture + 4 * picWidth * t2 + t1 * 4; target = thumbnailTexture + 4 * picWidth * t2 + t1 * 4;
target[0] = (GLubyte) redValue(c); target[0] = (GLubyte) redValue(c);
target[1] = (GLubyte) greenValue(c); target[1] = (GLubyte) greenValue(c);
@ -252,12 +252,12 @@ void showThumbnail(char *filename, int atX, int atY) {
} }
bool skipThumbnail(Common::SeekableReadStream *stream) { bool skipThumbnail(Common::SeekableReadStream *stream) {
thumbWidth = get4bytes(stream); thumbWidth = stream->readUint32LE();
thumbHeight = get4bytes(stream); thumbHeight = stream->readUint32LE();
uint32_t skippy = thumbWidth; uint32_t skippy = thumbWidth;
skippy *= thumbHeight << 1; skippy *= thumbHeight << 1;
stream->seek(skippy, 1); stream->seek(skippy, 1);
return (getch(stream) == '!'); return (stream->readByte() == '!');
} }
} // End of namespace Sludge } // End of namespace Sludge

View file

@ -87,8 +87,8 @@ bool setZBuffer(int y) {
break; break;
case 1: case 1:
zBuffer.width = get2bytes(bigDataFile); zBuffer.width = bigDataFile->readUint16BE();
zBuffer.height = get2bytes(bigDataFile); zBuffer.height = bigDataFile->readUint16BE();
break; break;
default: default:
@ -102,7 +102,7 @@ bool setZBuffer(int y) {
zBuffer.numPanels = fgetc(bigDataFile); zBuffer.numPanels = fgetc(bigDataFile);
for (y = 0; y < zBuffer.numPanels; y ++) { for (y = 0; y < zBuffer.numPanels; y ++) {
yPalette[y] = get2bytes(bigDataFile); yPalette[y] = bigDataFile->readUint16BE();
} }
sortZPal(yPalette, sorted, zBuffer.numPanels); sortZPal(yPalette, sorted, zBuffer.numPanels);
for (y = 0; y < zBuffer.numPanels; y ++) { for (y = 0; y < zBuffer.numPanels; y ++) {
@ -124,7 +124,7 @@ bool setZBuffer(int y) {
if (stillToGo == 0) { if (stillToGo == 0) {
n = fgetc(bigDataFile); n = fgetc(bigDataFile);
stillToGo = n >> 4; stillToGo = n >> 4;
if (stillToGo == 15) stillToGo = get2bytes(bigDataFile) + 16l; if (stillToGo == 15) stillToGo = bigDataFile->readUint16BE() + 16l;
else stillToGo ++; else stillToGo ++;
n &= 15; n &= 15;
} }