Index: src/multiint.c
===================================================================
--- src/multiint.c	(revision 6653)
+++ src/multiint.c	(working copy)
@@ -230,14 +230,8 @@
 	ptr = strrchr(aFileName, '/');
 	ASSERT(ptr, "this string was supposed to contain a /");
 	strcpy(ptr, "/game.map");
-	pFileData = fileLoadBuffer;
-	if (!loadFileToBuffer(aFileName, pFileData, FILE_LOAD_BUFFER_SIZE, &fileSize))
+	if (!mapLoad(aFileName))
 	{
-		debug(LOG_ERROR, "loadMapPreview: Failed to load map file");
-		return;
-	}
-	if (!mapLoad(pFileData, fileSize))
-	{
 		debug(LOG_ERROR, "loadMapPreview: Failed to load map");
 		return;
 	}
Index: src/map.c
===================================================================
--- src/map.c	(revision 6654)
+++ src/map.c	(working copy)
@@ -171,95 +171,44 @@
 	return true;
 }
 
-/* load the map data - for version 3 */
-static BOOL mapLoadV3(char *pFileData, UDWORD fileSize)
+/* Initialise the map structure */
+BOOL mapLoad(char *filename)
 {
-	UDWORD				i,j;
-	MAP_SAVETILE		*psTileData;
-	GATEWAY_SAVEHEADER	*psGateHeader;
-	GATEWAY_SAVE		*psGate;
+	UDWORD		numGw, width, height;
+	char		aFileType[4];
+	UDWORD		version;
+	UDWORD		i, j;
+	PHYSFS_file	*fp = PHYSFS_openRead(filename);
 
-	/* Load in the map data */
-	psTileData = (MAP_SAVETILE *)(pFileData + SAVE_HEADER_SIZE);
-	for(i=0; i< mapWidth * mapHeight; i++)
+	if (!fp)
 	{
-		/* MAP_SAVETILE */
-		endian_uword(&psTileData->texture);
-
-		psMapTiles[i].texture = psTileData->texture;
-		psMapTiles[i].height = psTileData->height;
-		for (j=0; j<MAX_PLAYERS; j++)
-		{
-			psMapTiles[i].tileVisBits =(UBYTE)(( (psMapTiles[i].tileVisBits) &~ (UBYTE)(1<<j) ));
-		}
-		psTileData = (MAP_SAVETILE *)(((UBYTE *)psTileData) + SAVE_TILE_SIZE);
+		debug(LOG_ERROR, "%s not found", filename);
+		return false;
 	}
-
-	psGateHeader = (GATEWAY_SAVEHEADER*)psTileData;
-	psGate = (GATEWAY_SAVE*)(psGateHeader+1);
-
-	/* GATEWAY_SAVEHEADER */
-	endian_udword(&psGateHeader->version);
-	endian_udword(&psGateHeader->numGateways);
-
-	ASSERT( psGateHeader->version == 1,"Invalid gateway version" );
-
-	for(i=0; i<psGateHeader->numGateways; i++) {
-		if (!gwNewGateway(psGate->x0,psGate->y0, psGate->x1,psGate->y1)) {
-			debug( LOG_ERROR, "mapLoadV3: Unable to add gateway" );
-			abort();
-			return false;
-		}
-		psGate++;
-	}
-
-	return true;
-}
-
-
-/* Initialise the map structure */
-BOOL mapLoad(char *pFileData, UDWORD fileSize)
-{
-	UDWORD				width,height;
-	MAP_SAVEHEADER		*psHeader;
-
-	/* Check the file type */
-	psHeader = (MAP_SAVEHEADER *)pFileData;
-	if (psHeader->aFileType[0] != 'm' || psHeader->aFileType[1] != 'a' ||
-		psHeader->aFileType[2] != 'p' || psHeader->aFileType[3] != ' ')
+	else if (PHYSFS_read(fp, aFileType, 4, 1) != 1
+	    || !PHYSFS_readULE32(fp, &version)
+	    || !PHYSFS_readULE32(fp, &width)
+	    || !PHYSFS_readULE32(fp, &height)
+	    || aFileType[0] != 'm'
+	    || aFileType[1] != 'a'
+	    || aFileType[2] != 'p')
 	{
-		ASSERT(false, "Incorrect map type");
-		free(pFileData);
+		debug(LOG_ERROR, "Bad header in %s", filename);
 		return false;
 	}
-
-	/* MAP_SAVEHEADER */
-	endian_udword(&psHeader->version);
-	endian_udword(&psHeader->width);
-	endian_udword(&psHeader->height);
-
-	/* Check the file version */
-	if (psHeader->version <= VERSION_9)
+	else if (version <= VERSION_9)
 	{
-		ASSERT(false, "Unsupported save format version %d", psHeader->version);
-		free(pFileData);
+		debug(LOG_ERROR, "%s: Unsupported save format version %u", filename, version);
 		return false;
 	}
-	else if (psHeader->version > CURRENT_VERSION_NUM)
+	else if (version > CURRENT_VERSION_NUM)
 	{
-		ASSERT(false, "Undefined save format version %d", psHeader->version);
-		free(pFileData);
+		debug(LOG_ERROR, "%s: Undefined save format version %u", filename, version);
 		return false;
 	}
-
-	/* Get the width and height */
-	width = psHeader->width;
-	height = psHeader->height;
-
-	if (width*height > MAP_MAXAREA)
+	else if (width * height > MAP_MAXAREA)
 	{
-		debug( LOG_ERROR, "Map too large : %d %d\n", width, height );
-		free(pFileData);
+		debug(LOG_ERROR, "Map %s too large : %d %d", filename, width, height);
 		return false;
 	}
 
@@ -274,8 +223,49 @@
 	mapHeight = height;
 
 	//load in the map data itself
-	mapLoadV3(pFileData, fileSize);
 
+	/* Load in the map data */
+	for (i = 0; i < mapWidth * mapHeight; i++)
+	{
+		UWORD	texture;
+		UBYTE	height;
+
+		if (!PHYSFS_readULE16(fp, &texture) || !PHYSFS_readULE8(fp, &height))
+		{
+			debug(LOG_ERROR, "%s: Error during savegame load", filename);
+			return false;
+		}
+
+		psMapTiles[i].texture = texture;
+		psMapTiles[i].height = height;
+		for (j = 0; j < MAX_PLAYERS; j++)
+		{
+			psMapTiles[i].tileVisBits =(UBYTE)(psMapTiles[i].tileVisBits &~ (UBYTE)(1 << j));
+		}
+	}
+
+	if (!PHYSFS_readULE32(fp, &version) || !PHYSFS_readULE32(fp, &numGw) || version != 1)
+	{
+		debug(LOG_ERROR, "Bad gateway in %s", filename);
+		return false;
+	}
+
+	for (i = 0; i < numGw; i++)
+	{
+		UBYTE	x0, y0, x1, y1;
+
+		if (!PHYSFS_readULE8(fp, &x0) || !PHYSFS_readULE8(fp, &y0) || !PHYSFS_readULE8(fp, &x1) || !PHYSFS_readULE8(fp, &y1))
+		{
+			debug(LOG_ERROR, "%s: Failed to read gateway info", filename);
+			return false;
+		}
+		if (!gwNewGateway(x0, y0, x1, y1))
+		{
+			debug(LOG_ERROR, "%s: Unable to add gateway", filename);
+			return false;
+		}
+	}
+
 	environReset();
 
 	/* set up the scroll mins and maxs - set values to valid ones for any new map */
Index: src/map.h
===================================================================
--- src/map.h	(revision 6653)
+++ src/map.h	(working copy)
@@ -255,7 +255,7 @@
 extern BOOL mapNew(UDWORD width, UDWORD height);
 
 /* Load the map data */
-extern BOOL mapLoad(char *pFileData, UDWORD fileSize);
+extern BOOL mapLoad(char *filename);
 
 /* Save the map data */
 extern BOOL mapSave(char **ppFileData, UDWORD *pFileSize);
Index: src/game.c
===================================================================
--- src/game.c	(revision 6653)
+++ src/game.c	(working copy)
@@ -2724,18 +2724,14 @@
 		}
 
 		//load the map and the droids then swap pointers
+
 		//load in the map file
 		aFileName[fileExten] = '\0';
 		strcat(aFileName, "mission.map");
-		/* Load in the chosen file data */
-		pFileData = fileLoadBuffer;
-		if (loadFileToBufferNoError(aFileName, pFileData, FILE_LOAD_BUFFER_SIZE, &fileSize))
+		if (!mapLoad(aFileName))
 		{
-			if (!mapLoad(pFileData, fileSize))
-			{
-				debug( LOG_NEVER, "loadgame: Fail7\n" );
-				return(false);
-			}
+			debug(LOG_ERROR, "Failed to load map");
+			return false;
 		}
 
 		//load in the visibility file
@@ -2880,16 +2876,8 @@
 		//load in the map file
 		aFileName[fileExten] = '\0';
 		strcat(aFileName, "game.map");
-		/* Load in the chosen file data */
-		pFileData = fileLoadBuffer;
-		if (!loadFileToBuffer(aFileName, pFileData, FILE_LOAD_BUFFER_SIZE, &fileSize))
+		if (!mapLoad(aFileName))
 		{
-			debug( LOG_NEVER, "loadgame: Fail5\n" );
-			goto error;
-		}
-
-		if (!mapLoad(pFileData, fileSize))
-		{
 			debug( LOG_NEVER, "loadgame: Fail7\n" );
 			return(false);
 		}
@@ -3464,18 +3452,6 @@
 	}
 	psMapTiles = NULL;
 
-	/*if (!loadFile("blank.map", &pFileData, &fileSize))
-	{
-		return false;
-	}
-
-	if (!mapLoad(pFileData, fileSize))
-	{
-		return false;
-	}
-
-	free(pFileData);*/
-
 	/* Start the game clock */
 	gameTimeStart();
 //	if (multiPlayerInUse)
Index: lib/framework/physfs_ext.h
===================================================================
--- lib/framework/physfs_ext.h	(revision 6653)
+++ lib/framework/physfs_ext.h	(working copy)
@@ -24,6 +24,26 @@
 #define PHYSFS_APPEND 1
 #define PHYSFS_PREPEND 0
 
+static inline bool PHYSFS_writeSLE8(PHYSFS_file* file, int8_t val)
+{
+	return (PHYSFS_write(file, &val, sizeof(int8_t), 1) == 1);
+}
+
+static inline bool PHYSFS_writeULE8(PHYSFS_file* file, uint8_t val)
+{
+	return (PHYSFS_write(file, &val, sizeof(uint8_t), 1) == 1);
+}
+
+static inline bool PHYSFS_readSLE8(PHYSFS_file* file, int8_t* val)
+{
+	return (PHYSFS_read(file, val, sizeof(int8_t), 1) == 1);
+}
+
+static inline bool PHYSFS_readULE8(PHYSFS_file* file, uint8_t* val)
+{
+	return (PHYSFS_read(file, val, sizeof(uint8_t), 1) == 1);
+}
+
 static inline bool PHYSFS_writeSBE8(PHYSFS_file* file, int8_t val)
 {
 	return (PHYSFS_write(file, &val, sizeof(int8_t), 1) == 1);

