Commit 1738194a authored by alistert's avatar alistert

Fixed sprite loading issue. Introduced optional upper limit for loading of shorts.

parent b3ef0f9a
......@@ -62,7 +62,7 @@ int Bonus::loadSprites () {
file->seek(2, true);
sprites = file->loadShort();
sprites = file->loadShort(256);
spriteSet = new Sprite[sprites];
for (count = 0; count < sprites; count++) {
......@@ -71,8 +71,8 @@ int Bonus::loadSprites () {
spriteSet[count].yOffset = 0;
// Load dimensions
width = file->loadShort();
height = file->loadShort();
width = file->loadShort(SW);
height = file->loadShort(SH);
pixelsLength = file->loadShort();
maskLength = file->loadShort();
......
......@@ -169,6 +169,25 @@ unsigned short int File::loadShort () {
}
unsigned short int File::loadShort (unsigned short int max) {
unsigned short int val;
val = loadShort();
if (val > max) {
logError("Oversized value in file", filePath);
return max;
}
return val;
}
void File::storeShort (unsigned short int val) {
fputc(val & 255, file);
......
......@@ -50,6 +50,7 @@ class File {
unsigned char loadChar ();
void storeChar (unsigned char val);
unsigned short int loadShort ();
unsigned short int loadShort (unsigned short int max);
void storeShort (unsigned short int val);
signed long int loadInt ();
void storeInt (signed long int val);
......
......@@ -82,7 +82,7 @@ Font::Font (const char* fileName) {
size = file->loadShort();
if (size) {
if (size > 4) {
pixels = file->loadRLE(size);
......@@ -91,7 +91,10 @@ Font::Font (const char* fileName) {
height = pixels[2];
height += pixels[3] << 8;
if (size - 4 >= width * height)
characters[count] = createSurface(pixels + 4, width, height);
else
characters[count] = createSurface(blank, 3, 1);
delete[] pixels;
......@@ -230,7 +233,7 @@ Font::Font (bool bonus) {
fileSize = file->getSize();
nCharacters = file->loadShort();
nCharacters = file->loadShort(256);
if (bonus) {
......@@ -264,8 +267,8 @@ Font::Font (bool bonus) {
}
width = file->loadShort();
height = file->loadShort();
width = file->loadShort(SW);
height = file->loadShort(SH);
if (bonus) width = (width + 3) & ~3;
else width <<= 2;
......
......@@ -61,8 +61,8 @@ DemoLevel::DemoLevel (const char* fileName) {
if (file->loadShort() == 0) throw E_DEMOTYPE;
// Level file to load
lNum = file->loadShort();
wNum = file->loadShort();
lNum = file->loadShort(9);
wNum = file->loadShort(999);
levelFile = createFileName(F_LEVEL, lNum, wNum);
// Difficulty
......
......@@ -200,6 +200,7 @@ int Level::loadSprites (char * fileName) {
File* mainFile = NULL;
File* specFile = NULL;
int count;
bool loaded;
// Open fileName
......@@ -214,7 +215,7 @@ int Level::loadSprites (char * fileName) {
}
// This function loads all the sprites, not fust those in fileName
// This function loads all the sprites, not just those in fileName
try {
mainFile = new File(F_MAINCHAR, false);
......@@ -228,7 +229,7 @@ int Level::loadSprites (char * fileName) {
}
sprites = specFile->loadShort();
sprites = specFile->loadShort(256);
// Include space in the sprite set for the blank sprite at the end
spriteSet = new Sprite[sprites + 1];
......@@ -249,22 +250,13 @@ int Level::loadSprites (char * fileName) {
// Loop through all the sprites to be loaded
for (count = 0; count < sprites; count++) {
if (specFile->loadChar() == 0xFF) {
// Go to the next sprite/file indicator
specFile->seek(1, false);
loaded = false;
if (mainFile->loadChar() == 0xFF) {
// Go to the next sprite/file indicator
mainFile->seek(1, false);
/* Both fileName and mainchar.000 have file indicators, so
create a blank sprite */
spriteSet[count].clearPixels();
continue;
} else {
// Return to the start of the sprite
......@@ -273,21 +265,31 @@ int Level::loadSprites (char * fileName) {
// Load the individual sprite data
loadSprite(mainFile, spriteSet + count);
loaded = true;
}
if (specFile->loadChar() == 0xFF) {
// Go to the next sprite/file indicator
specFile->seek(1, false);
} else {
// Return to the start of the sprite
specFile->seek(-1, false);
// Go to the main file's next sprite/file indicator
mainFile->seek(2, false);
// Load the individual sprite data
loadSprite(specFile, spriteSet + count);
loaded = true;
}
/* If both fileName and mainchar.000 have file indicators, create a
blank sprite */
if (!loaded) spriteSet[count].clearPixels();
// Check if the next sprite exists
// If not, create blank sprites for the remainder
......@@ -848,8 +850,8 @@ int Level::load (char* fileName, unsigned char diff, bool checkpoint) {
// The players' initial coordinates
startX = file->loadShort();
startY = file->loadShort() + 1;
startX = file->loadShort(LW);
startY = file->loadShort(LH) + 1;
// Next level
......
......@@ -211,8 +211,8 @@ int loadMain (int argc, char *argv[]) {
if (file && (file->loadChar() == 3)) {
// Read video settings
screenW = file->loadShort();
screenH = file->loadShort();
screenW = file->loadShort(7680);
screenH = file->loadShort(4800);
scaleFactor = file->loadChar();
#ifndef FULLSCREEN_ONLY
......
......@@ -477,11 +477,11 @@ void Scene::loadData (File *f) {
LOG("Data Type", "Image");
LOG("Data Type Image index", loop);
unsigned short int width = f->loadShort(); // get width
unsigned short int width = f->loadShort(SW); // get width
unsigned short int height;
if (type == 3) height = f->loadChar(); // Get height
else height = f->loadShort(); // Get height
else height = f->loadShort(SH); // Get height
f->seek(-2, false);
images = new SceneImage(images);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment