[Scummvm-git-logs] scummvm master -> 73f29ee3d5431def7e66f4c363aa0fd11e7554c5

aquadran noreply at scummvm.org
Sat Jul 30 09:05:10 UTC 2022


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
73f29ee3d5 ICB: Work in endian code safe, avoid casting pxBitmap class to memory.


Commit: 73f29ee3d5431def7e66f4c363aa0fd11e7554c5
    https://github.com/scummvm/scummvm/commit/73f29ee3d5431def7e66f4c363aa0fd11e7554c5
Author: Paweł Kołodziejski (aquadran at gmail.com)
Date: 2022-07-30T11:05:03+02:00

Commit Message:
ICB: Work in endian code safe, avoid casting pxBitmap class to memory.

Changed paths:
    engines/icb/common/px_bitmap_pc.h
    engines/icb/common/px_common.h
    engines/icb/function.cpp
    engines/icb/graphic_prims_pc.cpp
    engines/icb/icon_menu_pc.cpp
    engines/icb/options_manager_pc.cpp
    engines/icb/remora_pc.cpp
    engines/icb/remora_sprite.cpp
    engines/icb/remora_sprite_pc.cpp
    engines/icb/res_man_pc.cpp
    engines/icb/route_manager.cpp
    engines/icb/set_pc.cpp
    engines/icb/set_pc.h
    engines/icb/sound/fx_manager.cpp
    engines/icb/sound/sound_common.cpp
    engines/icb/sound_lowlevel_pc.cpp
    engines/icb/stagedraw_pc_poly.cpp
    engines/icb/text_sprites.cpp
    engines/icb/text_sprites_pc.cpp


diff --git a/engines/icb/common/px_bitmap_pc.h b/engines/icb/common/px_bitmap_pc.h
index 56c7b484c48..f41272ea540 100644
--- a/engines/icb/common/px_bitmap_pc.h
+++ b/engines/icb/common/px_bitmap_pc.h
@@ -48,6 +48,17 @@ typedef struct {
 
 } _pxPCSprite;
 
+typedef struct _pxPCBitmap {
+	char id[4];    // "PCB" Pc bitmap
+	uint32 schema; // The current schema number
+
+	uint8 palette[4 * 256];         // RGB but padded with 0 to 32-bits.
+	uint32 num_sprites;             // Number of sprites in this file.
+	uint32 sprite_offsets[1];       // Offsets to sprite data for each sprite.
+
+} _pxPCBitmap;
+
+/*
 // This holds information about a bitmap (which may contain a number of frames).
 class _pxPCBitmap {
 public:
@@ -80,7 +91,7 @@ inline _pxPCSprite *_pxPCBitmap::Fetch_item_by_number(uint32 nNumber) {
 
 	// Return the pointer.
 	return ((_pxPCSprite *)(((uint8 *)this) + sprite_offsets[nNumber]));
-}
+}*/
 
 } // End of namespace ICB
 
diff --git a/engines/icb/common/px_common.h b/engines/icb/common/px_common.h
index f2f534f3343..4d9d8f71e22 100644
--- a/engines/icb/common/px_common.h
+++ b/engines/icb/common/px_common.h
@@ -226,6 +226,16 @@ inline uint32 READ_LE_U32(const void *p) {
 	return (uint32)(((uint32)data[3] << 24) | ((uint32)data[2] << 16) | ((uint32)data[1] << 8) | (uint32)data[0]);
 }
 
+#if defined(SCUMM_LITTLE_ENDIAN)
+
+#define FROM_LE_FLOAT32(a) ((float)(a))
+
+#else
+
+#define FROM_LE_FLOAT32(a) ((float)(SWAP_BYTES_32(a)))
+
+#endif
+
 #define MKTAG(a0, a1, a2, a3) ((uint32)((a3) | ((a2) << 8) | ((a1) << 16) | ((a0) << 24)))
 
 } // End of namespace ICB
diff --git a/engines/icb/function.cpp b/engines/icb/function.cpp
index bebd5ea6488..532be187b62 100644
--- a/engines/icb/function.cpp
+++ b/engines/icb/function.cpp
@@ -496,23 +496,23 @@ mcodeFunctionReturnCodes _game_session::fn_init_from_nico_file(int32 &, int32 *
 	}
 
 	// set coordinates
-	logic_structs[cur_id]->prop_xyz.x = start_pos->x;
+	logic_structs[cur_id]->prop_xyz.x = FROM_LE_FLOAT32(start_pos->x);
 
-	if (start_pos->y < start_pos->floor_y) // nico is under the floor!
-		logic_structs[cur_id]->prop_xyz.y = start_pos->floor_y;
+	if (FROM_LE_FLOAT32(start_pos->y) < FROM_LE_FLOAT32(start_pos->floor_y)) // nico is under the floor!
+		logic_structs[cur_id]->prop_xyz.y = FROM_LE_FLOAT32(start_pos->floor_y);
 
 	else
-		logic_structs[cur_id]->prop_xyz.y = start_pos->y;
+		logic_structs[cur_id]->prop_xyz.y = FROM_LE_FLOAT32(start_pos->y);
 
-	logic_structs[cur_id]->prop_xyz.z = start_pos->z;
+	logic_structs[cur_id]->prop_xyz.z = FROM_LE_FLOAT32(start_pos->z);
 
 	// set pan
-	logic_structs[cur_id]->pan = start_pos->direction; // is this right?
+	logic_structs[cur_id]->pan = FROM_LE_FLOAT32(start_pos->direction); // is this right?
 
-	logic_structs[cur_id]->prop_interact_pan = start_pos->direction; // this might be more sensible
+	logic_structs[cur_id]->prop_interact_pan = FROM_LE_FLOAT32(start_pos->direction); // this might be more sensible
 
 	// set owner floor for things lile fn_on_screen
-	logic_structs[cur_id]->owner_floor_rect = floor_def->Return_floor_rect(start_pos->x, start_pos->z, start_pos->floor_y, 0);
+	logic_structs[cur_id]->owner_floor_rect = floor_def->Return_floor_rect(FROM_LE_FLOAT32(start_pos->x), FROM_LE_FLOAT32(start_pos->z), FROM_LE_FLOAT32(start_pos->floor_y), 0);
 
 	if (logic_structs[cur_id]->owner_floor_rect == PXNULL) {
 		Message_box("fn_init_from_nico_file - %s nico not on a legal floor position - object has been shutdown", object->GetName());
@@ -566,12 +566,12 @@ mcodeFunctionReturnCodes _game_session::fn_init_from_marker_file(int32 &, int32
 		return IR_STOP;
 	}
 
-	logic_structs[cur_id]->mega->actor_xyz.x = start_pos->x;
-	logic_structs[cur_id]->mega->actor_xyz.y = start_pos->y;
-	logic_structs[cur_id]->mega->actor_xyz.z = start_pos->z;
+	logic_structs[cur_id]->mega->actor_xyz.x = FROM_LE_FLOAT32(start_pos->x);
+	logic_structs[cur_id]->mega->actor_xyz.y = FROM_LE_FLOAT32(start_pos->y);
+	logic_structs[cur_id]->mega->actor_xyz.z = FROM_LE_FLOAT32(start_pos->z);
 
 	// set pan
-	logic_structs[cur_id]->pan = start_pos->pan;
+	logic_structs[cur_id]->pan = FROM_LE_FLOAT32(start_pos->pan);
 
 	// has coords
 	logic_structs[cur_id]->prop_coords_set = TRUE8;
@@ -602,12 +602,12 @@ mcodeFunctionReturnCodes _game_session::fn_init_mega_from_nico(int32 &, int32 *)
 	}
 
 	// set coordinates
-	logic_structs[cur_id]->mega->actor_xyz.x = start_pos->x;
-	logic_structs[cur_id]->mega->actor_xyz.y = start_pos->floor_y;
-	logic_structs[cur_id]->mega->actor_xyz.z = start_pos->z;
+	logic_structs[cur_id]->mega->actor_xyz.x = FROM_LE_FLOAT32(start_pos->x);
+	logic_structs[cur_id]->mega->actor_xyz.y = FROM_LE_FLOAT32(start_pos->floor_y);
+	logic_structs[cur_id]->mega->actor_xyz.z = FROM_LE_FLOAT32(start_pos->z);
 
 	// set pan
-	logic_structs[cur_id]->pan = start_pos->direction;
+	logic_structs[cur_id]->pan = FROM_LE_FLOAT32(start_pos->direction);
 
 	// has coords
 	logic_structs[cur_id]->prop_coords_set = TRUE8;
@@ -636,12 +636,12 @@ mcodeFunctionReturnCodes _game_session::fn_teleport_to_nico(int32 &, int32 *para
 		Fatal_error("no NICO marker (fn_teleport_to_nico) ob %s, nico %s", object->GetName(), nico_name);
 
 	// set coordinates
-	logic_structs[cur_id]->mega->actor_xyz.x = start_pos->x;
-	logic_structs[cur_id]->mega->actor_xyz.y = start_pos->floor_y; // Gravitise_y(start_pos->y);
-	logic_structs[cur_id]->mega->actor_xyz.z = start_pos->z;
+	logic_structs[cur_id]->mega->actor_xyz.x = FROM_LE_FLOAT32(start_pos->x);
+	logic_structs[cur_id]->mega->actor_xyz.y = FROM_LE_FLOAT32(start_pos->floor_y); // Gravitise_y(start_pos->y);
+	logic_structs[cur_id]->mega->actor_xyz.z = FROM_LE_FLOAT32(start_pos->z);
 
 	// set pan
-	logic_structs[cur_id]->pan = start_pos->direction;
+	logic_structs[cur_id]->pan = FROM_LE_FLOAT32(start_pos->direction);
 
 	// for safety
 	logic_structs[cur_id]->cur_anim_type = __STAND;
@@ -671,9 +671,9 @@ mcodeFunctionReturnCodes _game_session::fn_panless_teleport_to_nico(int32 &, int
 		Fatal_error("no NICO marker (fn_panless_teleport_to_nico_) ob %s, nico %s", object->GetName(), nico_name);
 
 	// set coordinates
-	logic_structs[cur_id]->mega->actor_xyz.x = start_pos->x;
-	logic_structs[cur_id]->mega->actor_xyz.y = start_pos->floor_y; // Gravitise_y(start_pos->y);
-	logic_structs[cur_id]->mega->actor_xyz.z = start_pos->z;
+	logic_structs[cur_id]->mega->actor_xyz.x = FROM_LE_FLOAT32(start_pos->x);
+	logic_structs[cur_id]->mega->actor_xyz.y = FROM_LE_FLOAT32(start_pos->floor_y); // Gravitise_y(start_pos->y);
+	logic_structs[cur_id]->mega->actor_xyz.z = FROM_LE_FLOAT32(start_pos->z);
 
 	// for safety
 	logic_structs[cur_id]->cur_anim_type = __STAND;
@@ -703,7 +703,7 @@ mcodeFunctionReturnCodes _game_session::fn_teleport_to_nico_y(int32 &, int32 *pa
 		Fatal_error("no NICO marker (fn_teleport_to_nico_y) ob %s, nico %s", object->GetName(), nico_name);
 
 	// set coordinates
-	logic_structs[cur_id]->mega->actor_xyz.y = start_pos->floor_y; // Gravitise_y(start_pos->y);
+	logic_structs[cur_id]->mega->actor_xyz.y = FROM_LE_FLOAT32(start_pos->floor_y); // Gravitise_y(start_pos->y);
 
 	// for safety
 	logic_structs[cur_id]->cur_anim_type = __STAND;
@@ -736,7 +736,7 @@ mcodeFunctionReturnCodes _game_session::fn_snap_to_nico_y(int32 &, int32 *params
 		Fatal_error("no NICO marker (fn_snap_to_nico_y) ob %s, nico %s", object->GetName(), nico_name);
 
 	// set coordinates
-	logic_structs[cur_id]->mega->actor_xyz.y = start_pos->floor_y;
+	logic_structs[cur_id]->mega->actor_xyz.y = FROM_LE_FLOAT32(start_pos->floor_y);
 
 	return IR_CONT;
 }
@@ -764,7 +764,7 @@ mcodeFunctionReturnCodes _game_session::fn_get_pan_from_nico(int32 &, int32 *par
 	}
 
 	// set pan
-	logic_structs[cur_id]->pan = start_pos->direction;
+	logic_structs[cur_id]->pan = FROM_LE_FLOAT32(start_pos->direction);
 
 	return IR_CONT;
 }
diff --git a/engines/icb/graphic_prims_pc.cpp b/engines/icb/graphic_prims_pc.cpp
index ffc902328fd..802be40a13b 100644
--- a/engines/icb/graphic_prims_pc.cpp
+++ b/engines/icb/graphic_prims_pc.cpp
@@ -854,10 +854,10 @@ void SpriteFrameDraw(uint8 *pSurfaceBitmap,     // IN:  Pointer to the surface's
 	_pxSprite *pSprite;
 
 	// Get to the sprite frame.
-	pSprite = pBitmap->Fetch_item_by_number(nFrameNumber);
+	pSprite = (_pxSprite *)((byte *)pBitmap + FROM_LE_32(pBitmap->sprite_offsets[nFrameNumber]));
 
 	// Get the palette pointer.
-	pPalette = pBitmap->Fetch_palette_pointer();
+	pPalette = &pBitmap->palette[0];
 
 	// Now do the actual drawing.
 	RawSpriteDraw(pSurfaceBitmap, nPitch, nSurfaceWidth, nSurfaceHeight, pSprite, pPalette, pSprite->x, pSprite->y, pnTransparencyRef, nOpacity);
@@ -879,7 +879,7 @@ void SpriteXYFrameDraw(uint8 *pSurfaceBitmap,     // IN:  Pointer to the surface
 	_pxSprite *pSprite;
 
 	// Get to the sprite frame.
-	pSprite = pBitmap->Fetch_item_by_number(nFrameNumber);
+	pSprite = (_pxSprite *)((byte *)pBitmap + FROM_LE_32(pBitmap->sprite_offsets[nFrameNumber]));
 
 	// Work out a new plotting position if it is to be centred.
 	if (bCenter) {
@@ -888,7 +888,7 @@ void SpriteXYFrameDraw(uint8 *pSurfaceBitmap,     // IN:  Pointer to the surface
 	}
 
 	// Get the palette pointer.
-	pPalette = pBitmap->Fetch_palette_pointer();
+	pPalette = &pBitmap->palette[0];
 
 	// Now do the actual drawing.
 	RawSpriteDraw(pSurfaceBitmap, nPitch, nSurfaceWidth, nSurfaceHeight, pSprite, pPalette, nX, nY, pnTransparencyRef, nOpacity);
diff --git a/engines/icb/icon_menu_pc.cpp b/engines/icb/icon_menu_pc.cpp
index ed867c1d7f7..056bf60f41d 100644
--- a/engines/icb/icon_menu_pc.cpp
+++ b/engines/icb/icon_menu_pc.cpp
@@ -417,7 +417,7 @@ void _icon_menu::SetTransparencyColourKey() {
 	if (psTransparentBitmap->schema != PC_BITMAP_SCHEMA)
 		Fatal_error("Incorrect versions loading [%s] (engine has %d, data has %d", strFullIconName.c_str(), PC_BITMAP_SCHEMA, psTransparentBitmap->schema);
 
-	uint8 *pnPalette = psTransparentBitmap->Fetch_palette_pointer();
+	uint8 *pnPalette = &psTransparentBitmap->palette[0];
 	m_nTransparentKey = ((uint32 *)pnPalette)[0];
 }
 
diff --git a/engines/icb/options_manager_pc.cpp b/engines/icb/options_manager_pc.cpp
index f02a92e4b1e..890eff6f9da 100644
--- a/engines/icb/options_manager_pc.cpp
+++ b/engines/icb/options_manager_pc.cpp
@@ -300,10 +300,14 @@ void LoadThumbnail(uint32 slot_id, uint32 to_surface_id) {
 	uint8 *surface_address = surface_manager->Lock_surface(to_surface_id);
 	uint32 pitch = surface_manager->Get_pitch(to_surface_id);
 
+	uint32 *u32surfPtr = (uint32 *)surface_address;
 	// Now we need to read the 64 by 48 image data into the surface
 	for (uint32 i = 0; i < 48; i++) {
-		if (stream->read(surface_address, sizeof(uint32) * 64) != 64 * sizeof(uint32))
-			Fatal_error("LoadThumbnail() failed reading");
+		for (uint32 j = 0; j < 64; j++) {
+			u32surfPtr[j] = stream->readUint32LE();
+			if (stream->err())
+				Fatal_error("LoadThumbnail() failed reading");
+		}
 
 		surface_address += pitch;
 	}
@@ -5568,7 +5572,7 @@ void OptionsManager::LoadBitmapFont() {
 	if (m_font_file->schema != PC_BITMAP_SCHEMA)
 		Fatal_error("Incorrect versions loading [%s] (engine has %d, data has %d", m_fontName, PC_BITMAP_SCHEMA, m_font_file->schema);
 
-	m_fontPalette = (uint32 *)m_font_file->Fetch_palette_pointer();
+	m_fontPalette = (uint32 *)&m_font_file->palette[0];
 }
 
 void OptionsManager::LoadGlobalTextFile() {
@@ -5602,10 +5606,10 @@ bool8 OptionsManager::SetCharacterSprite(char c) {
 		index += 256;
 
 	// Catch ernoeous characters and make them apostrophes
-	if ((uint)index >= m_font_file->Fetch_number_of_items())
+	if ((uint)index >= m_font_file->num_sprites)
 		index = 7;
 
-	m_currentSprite = m_font_file->Fetch_item_by_number(index);
+	m_currentSprite = (_pxSprite *)((byte *)m_font_file + FROM_LE_32(m_font_file->sprite_offsets[index]));
 
 	if (!m_currentSprite)
 		return FALSE8;
diff --git a/engines/icb/remora_pc.cpp b/engines/icb/remora_pc.cpp
index 507b4b37e90..ddfdfbaa68b 100644
--- a/engines/icb/remora_pc.cpp
+++ b/engines/icb/remora_pc.cpp
@@ -1583,7 +1583,7 @@ void _remora::SetUpSurfaceForBitmap(const char *pcBitmapName, DXrect &sSourceRec
 	if (pBitmap->schema != PC_BITMAP_SCHEMA)
 		Fatal_error("Incorrect versions loading [%s] (engine has %d, data has %d", pcFullBitmapName, PC_BITMAP_SCHEMA, pBitmap->schema);
 
-	pSprite = pBitmap->Fetch_item_by_number(0);
+	pSprite = (_pxSprite *)((byte *)pBitmap + FROM_LE_32(pBitmap->sprite_offsets[0]));
 
 	// Prepare the source/target rectangles for blitting later.
 	sSourceRect = MakeRECTFromSpriteSizes(0, 0, pSprite->width, pSprite->height);
diff --git a/engines/icb/remora_sprite.cpp b/engines/icb/remora_sprite.cpp
index 9ee4a38bf55..d8035bce8e4 100644
--- a/engines/icb/remora_sprite.cpp
+++ b/engines/icb/remora_sprite.cpp
@@ -44,7 +44,7 @@ void _remora_sprite::InitialiseFromBitmapName(const char *pcBitmapName, const ch
 	// Get the number of frames (don't forget to check schema number is correct).
 	psBitmap = (_pxBitmap *)rs_remora->Res_open(m_pcName, m_nNameHash, m_pcClusterName, m_nClusterHash);
 
-	m_nNumFrames = psBitmap->Fetch_number_of_items();
+	m_nNumFrames = FROM_LE_32(psBitmap->num_sprites);
 
 	if (m_nNumFrames == 0)
 		Fatal_error("Bitmap %s has no frames.", pcBitmapName);
@@ -52,7 +52,7 @@ void _remora_sprite::InitialiseFromBitmapName(const char *pcBitmapName, const ch
 	// Here we work out half the sprite's width and height so we can avoid plotting it in positions where it
 	// would run off the edge of a surface.  Note that this is based on the first frame; it would need to be
 	// made more sophisticated to deal with sprites that change in size as they are played.
-	psSprite = psBitmap->Fetch_item_by_number(0);
+	psSprite = (_pxSprite *)((byte *)psBitmap + FROM_LE_32(psBitmap->sprite_offsets[0]));
 
 	m_nHalfSpriteWidth = psSprite->width / 2;
 	m_nHalfSpriteHeight = psSprite->height / 2;
diff --git a/engines/icb/remora_sprite_pc.cpp b/engines/icb/remora_sprite_pc.cpp
index f2e10e79b74..b530f1eee48 100644
--- a/engines/icb/remora_sprite_pc.cpp
+++ b/engines/icb/remora_sprite_pc.cpp
@@ -95,7 +95,7 @@ uint32 _remora_sprite::GetHeight() {
 	psBitmap = (_pxBitmap *)rs_remora->Res_open(m_pcName, m_nNameHash, m_pcClusterName, m_nClusterHash);
 
 	// Get the first frame and return its height.
-	psSprite = psBitmap->Fetch_item_by_number(0);
+	psSprite = (_pxSprite *)((byte *)psBitmap + FROM_LE_32(psBitmap->sprite_offsets[0]));
 	return (psSprite->height);
 }
 
@@ -111,7 +111,7 @@ uint32 _remora_sprite::GetWidth() {
 	psBitmap = (_pxBitmap *)rs_remora->Res_open(m_pcName, m_nNameHash, m_pcClusterName, m_nClusterHash);
 
 	// Get the first frame and return its height.
-	psSprite = psBitmap->Fetch_item_by_number(0);
+	psSprite = (_pxSprite *)((byte *)psBitmap + FROM_LE_32(psBitmap->sprite_offsets[0]));
 	return (psSprite->width);
 }
 
diff --git a/engines/icb/res_man_pc.cpp b/engines/icb/res_man_pc.cpp
index 645eef7a38b..cd903b5b4f4 100644
--- a/engines/icb/res_man_pc.cpp
+++ b/engines/icb/res_man_pc.cpp
@@ -245,16 +245,13 @@ const char *res_man::OpenFile(int32 &cluster_search, RMParams *params) {
 		if (params->_stream == nullptr)
 			Fatal_error("Res_open cannot *OPEN* cluster file %s", clusterPath.c_str());
 
-		// Read in 16 bytes, part of which is the cluster header length
-
-		uint32 data[4];
-
-		if (params->_stream->read(&data, 16) != 16) {
+		if (params->_stream->size() < 16) {
 			Fatal_error("res_man::OpenFile cannot read 16 bytes from cluster %s %d", clusterPath.c_str(), params->cluster_hash);
 		}
 
 		params->seekpos = 0;
-		params->len = data[2];
+		params->_stream->skip(8);
+		params->len = params->_stream->readSint32LE();
 		return params->cluster;
 	}
 
@@ -274,14 +271,14 @@ const char *res_man::OpenFile(int32 &cluster_search, RMParams *params) {
 	if (params->_stream == nullptr)
 		Fatal_error("Res_open cannot *OPEN* cluster file %s", clusterPath.c_str());
 
-	params->seekpos = hn->offset;
+	params->seekpos = FROM_LE_32(hn->offset);
 
 	// Set the length of the data
 	if (params->zipped) {
 		params->_stream->seek(params->seekpos, SEEK_SET);
 		params->len = fileGetZipLength2(params->_stream); // TODO: Use wrapCompressedStream to solve?
 	} else
-		params->len = hn->size;
+		params->len = FROM_LE_32(hn->size);
 
 	return nullptr;
 }
@@ -313,12 +310,12 @@ HEADER_NORMAL *res_man::GetFileHeader(int32 &cluster_search, RMParams *params) {
 	// and get the position and length to get the data from
 
 	// Check the schema value and the ID
-	if ((clu->schema != CLUSTER_API_SCHEMA) || (*(int32 *)clu->ID != *(int32 *)const_cast<char *>(CLUSTER_API_ID))) {
+	if ((FROM_LE_32(clu->schema) != CLUSTER_API_SCHEMA) || (READ_LE_U32((uint32 *)clu->ID) != *(uint32 *)const_cast<char *>(CLUSTER_API_ID))) {
 		// Big error unknown cluster filetype
 		Fatal_error("res_man::GetFileHeader unknown cluster schema or ID %d %s for %s::0x%X", clu->schema, clu->ID, params->cluster, params->url_hash);
 	}
 
-	if (clu->ho.cluster_hash != params->cluster_hash) {
+	if (FROM_LE_32(clu->ho.cluster_hash) != params->cluster_hash) {
 		// Big error this cluster has a different internal hash value to the one
 		// we are looking for
 //		Fatal_error("res_man::GetFileHeader different internal cluster_hash value %x file %x for %s::0x%X", params->cluster_hash, clu->ho.cluster_hash, params->cluster,
@@ -327,14 +324,14 @@ HEADER_NORMAL *res_man::GetFileHeader(int32 &cluster_search, RMParams *params) {
 
 	HEADER_NORMAL *hn = clu->hn;
 	uint32 i;
-	for (i = 0; i < clu->ho.noFiles; hn++, i++) {
+	for (i = 0; i < FROM_LE_32(clu->ho.noFiles); hn++, i++) {
 		// Hey it has been found
-		if (hn->hash == params->url_hash)
+		if (FROM_LE_32(hn->hash) == params->url_hash)
 			break;
 	}
 
 	// Check that the file was actually found
-	if (i == clu->ho.noFiles) {
+	if (i == FROM_LE_32(clu->ho.noFiles)) {
 		return nullptr;
 	}
 
@@ -349,7 +346,7 @@ void res_man::Res_open_mini_cluster(const char *cluster_url, uint32 &cluster_has
 	uint32 zeroHash = 0;
 	Cluster_API *clu = (Cluster_API *)Res_open(nullptr, zeroHash, cluster_url, cluster_hash);
 
-	int32 numFiles = clu->ho.noFiles;
+	int32 numFiles = FROM_LE_32(clu->ho.noFiles);
 
 	// check none of the fake files exist
 	// also find total size required
@@ -359,14 +356,14 @@ void res_man::Res_open_mini_cluster(const char *cluster_url, uint32 &cluster_has
 
 	for (i = 0; i < numFiles; i++) {
 		HEADER_NORMAL *hn = clu->hn + i;
-		uint32 check_hash = hn->hash;
+		uint32 check_hash = FROM_LE_32(hn->hash);
 
 		if (FindFile(check_hash, fake_cluster_hash, MAKE_TOTAL_HASH(fake_cluster_hash, check_hash)) != -1) {
 			warning("File %s::%08x exists in res_man so can't load my mini-cluster!", fake_cluster_url, check_hash);
 			return;
 		}
 
-		int32 fileSize = (hn->size + 7) & (~7);
+		int32 fileSize = (FROM_LE_32(hn->size) + 7) & (~7);
 		mem_needed += fileSize;
 	}
 
@@ -407,7 +404,7 @@ void res_man::Res_open_mini_cluster(const char *cluster_url, uint32 &cluster_has
 	stream = openDiskFileForBinaryStreamRead(clusterPath.c_str());
 
 	// seek
-	stream->seek((clu->hn)->offset, SEEK_SET);
+	stream->seek(FROM_LE_32((clu->hn)->offset), SEEK_SET);
 
 	// read
 	stream->read(mem_list[mem_block].ad, mem_needed);
@@ -443,9 +440,9 @@ void res_man::Res_open_mini_cluster(const char *cluster_url, uint32 &cluster_has
 			mem_list[current_child].parent = mem_block;
 		}
 
-		mem_list[mem_block].url_hash = hn->hash;
+		mem_list[mem_block].url_hash = FROM_LE_32(hn->hash);
 		mem_list[mem_block].cluster_hash = fake_cluster_hash;
-		mem_list[mem_block].total_hash = MAKE_TOTAL_HASH(fake_cluster_hash, hn->hash);
+		mem_list[mem_block].total_hash = MAKE_TOTAL_HASH(fake_cluster_hash, FROM_LE_32(hn->hash));
 
 		mem_list[mem_block].ad = ad;
 
@@ -454,7 +451,7 @@ void res_man::Res_open_mini_cluster(const char *cluster_url, uint32 &cluster_has
 		mem_list[mem_block].age = current_time_frame;
 
 		// adjusted size
-		int32 fileSize = (hn->size + 7) & (~7);
+		int32 fileSize = (FROM_LE_32(hn->size) + 7) & (~7);
 
 		mem_list[mem_block].size = fileSize;
 
diff --git a/engines/icb/route_manager.cpp b/engines/icb/route_manager.cpp
index f693ebef96b..0cb4329618b 100644
--- a/engines/icb/route_manager.cpp
+++ b/engines/icb/route_manager.cpp
@@ -898,7 +898,7 @@ mcodeFunctionReturnCodes _game_session::fn_route_to_marker(int32 &result, int32
 			Fatal_error("fn_route_to_marker - object [%s] cant find marker [%s]", object->GetName(), marker_name);
 
 		// build route
-		if (!Setup_route(result, (int32)marker->x, (int32)marker->z, params[1], __FULL, TRUE8)) {
+		if (!Setup_route(result, (int32)FROM_LE_FLOAT32(marker->x), (int32)FROM_LE_FLOAT32(marker->z), params[1], __FULL, TRUE8)) {
 			L->looping = 0;
 			return (IR_CONT);
 		}
diff --git a/engines/icb/set_pc.cpp b/engines/icb/set_pc.cpp
index 29b019f6bb7..76605216488 100644
--- a/engines/icb/set_pc.cpp
+++ b/engines/icb/set_pc.cpp
@@ -613,8 +613,8 @@ bool8 _set::Init(const char *camera_name, const char *clustered_camera_name) {
 
 	// Load this camera
 	m_currentCamera = (_pcSetHeader *)rs_bg->Res_open(p_rcvf, p_rcvf_hash, set_cluster, set_cluster_hash);
-	if (m_currentCamera->id != PCSETFILE_ID)
-		Fatal_error("Unsupported set files. Set id is %d.  should be %d", m_currentCamera->id, PCSETFILE_ID);
+	if (FROM_LE_32(m_currentCamera->id) != PCSETFILE_ID)
+		Fatal_error("Unsupported set files. Set id is %d.  should be %d", FROM_LE_32(m_currentCamera->id), PCSETFILE_ID);
 
 	// Hack the camera into the format we want.
 	HackMakeCamera();
@@ -687,7 +687,7 @@ void _set::Init_base_bitmap_buffers() {
 	bgPtr = GetBackground();
 
 	// Check this is a valid support set type
-	if ((*(uint32 *)bgPtr) != 7)
+	if (READ_LE_UINT32(bgPtr) != 7)
 		Fatal_error("Camera %s is out of date.", set_url);
 
 	// Find the shadow table
@@ -700,7 +700,7 @@ void _set::Init_base_bitmap_buffers() {
 	surface_manager->Fill_surface(bg_buffer_id, 0x008080ff);
 
 	// Find the start of this shadow data
-	uint8 *ptr = bgPtr + shadowTable[0];
+	uint8 *ptr = bgPtr + FROM_LE_32(shadowTable[0]);
 
 	// Decode the jpeg background
 	Graphics::Surface *jpegSurf = JpegDecode(ptr, 1024 * 1024);
@@ -719,9 +719,9 @@ void _set::Init_base_bitmap_buffers() {
 	delete jpegSurf;
 
 	// find the start of the weather data
-	int32 *weatherPtr = (int32 *)(bgPtr + shadowTable[1]);
+	int32 *weatherPtr = (int32 *)(bgPtr + FROM_LE_32(shadowTable[1]));
 
-	InitWeather(*(weatherPtr), *(weatherPtr + 1), *(weatherPtr + 2), *(weatherPtr + 3), *(weatherPtr + 4), *(weatherPtr + 5));
+	InitWeather(READ_LE_INT32(weatherPtr), READ_LE_INT32(weatherPtr + 1), READ_LE_INT32(weatherPtr + 2), READ_LE_INT32(weatherPtr + 3), READ_LE_INT32(weatherPtr + 4), READ_LE_INT32(weatherPtr + 5));
 
 	// Flush the actor z buffer
 	if (pZ)
@@ -748,7 +748,7 @@ void _set::Load_props() {
 	delete m_props;
 
 	// Load the prop file
-	m_props = new pcPropFile(((uint8 *)m_currentCamera) + m_currentCamera->propOffset);
+	m_props = new pcPropFile(((uint8 *)m_currentCamera) + FROM_LE_32(m_currentCamera->propOffset));
 
 	pcPropFile *propFile = GetProps();
 	// Which version are we using ?
@@ -1695,8 +1695,8 @@ void _set::DrawWeather() {
 
 void _set::HackMakeCamera() {
 	float *oldCameraData;
-	if (m_currentCamera->id == PCSETFILE_ID)
-		oldCameraData = (float *)(((uint8 *)m_currentCamera) + m_currentCamera->cameraOffset);
+	if (FROM_LE_32(m_currentCamera->id) == PCSETFILE_ID)
+		oldCameraData = (float *)(((uint8 *)m_currentCamera) + FROM_LE_32(m_currentCamera->cameraOffset));
 	else
 		oldCameraData = (float *)rs_bg->Res_open(rvcam_file_name, rvcam_file_hash, set_cluster, set_cluster_hash, 0);
 	/*   Old Camera Format
@@ -1732,15 +1732,15 @@ void _set::HackMakeCamera() {
 
 	// Find scalings in the input matrix
 	float matrix[3][3];
-	matrix[0][0] = *(oldCameraData + 4);
-	matrix[0][1] = *(oldCameraData + 5);
-	matrix[0][2] = *(oldCameraData + 6);
-	matrix[1][0] = *(oldCameraData + 7);
-	matrix[1][1] = *(oldCameraData + 8);
-	matrix[1][2] = *(oldCameraData + 9);
-	matrix[2][0] = *(oldCameraData + 10);
-	matrix[2][1] = *(oldCameraData + 11);
-	matrix[2][2] = *(oldCameraData + 12);
+	matrix[0][0] = READ_LE_FLOAT32(oldCameraData + 4);
+	matrix[0][1] = READ_LE_FLOAT32(oldCameraData + 5);
+	matrix[0][2] = READ_LE_FLOAT32(oldCameraData + 6);
+	matrix[1][0] = READ_LE_FLOAT32(oldCameraData + 7);
+	matrix[1][1] = READ_LE_FLOAT32(oldCameraData + 8);
+	matrix[1][2] = READ_LE_FLOAT32(oldCameraData + 9);
+	matrix[2][0] = READ_LE_FLOAT32(oldCameraData + 10);
+	matrix[2][1] = READ_LE_FLOAT32(oldCameraData + 11);
+	matrix[2][2] = READ_LE_FLOAT32(oldCameraData + 12);
 	float scalex = (float)sqrt(matrix[0][0] * matrix[0][0] + matrix[1][0] * matrix[1][0] + matrix[2][0] * matrix[2][0]);
 	float scaley = (float)sqrt(matrix[0][1] * matrix[0][1] + matrix[1][1] * matrix[1][1] + matrix[2][1] * matrix[2][1]);
 	float scalez = (float)sqrt(matrix[0][2] * matrix[0][2] + matrix[1][2] * matrix[1][2] + matrix[2][2] * matrix[2][2]);
@@ -1799,9 +1799,9 @@ void _set::HackMakeCamera() {
 	m_camera.view.m[2][1] = (int16)(-matrix[2][1] * 4 * ONE);
 	m_camera.view.m[2][2] = (int16)(-matrix[2][2] * 4 * ONE);
 
-	int32 TR2vx = (int32)(-(*(oldCameraData + 1)) * m_camera.view.m[0][0] - (*(oldCameraData + 2)) * m_camera.view.m[0][1] - (*(oldCameraData + 3)) * m_camera.view.m[0][2]);
-	int32 TR2vy = (int32)(-(*(oldCameraData + 1)) * m_camera.view.m[1][0] - (*(oldCameraData + 2)) * m_camera.view.m[1][1] - (*(oldCameraData + 3)) * m_camera.view.m[1][2]);
-	int32 TR2vz = (int32)(-(*(oldCameraData + 1)) * m_camera.view.m[2][0] - (*(oldCameraData + 2)) * m_camera.view.m[2][1] - (*(oldCameraData + 3)) * m_camera.view.m[2][2]);
+	int32 TR2vx = (int32)(-(READ_LE_FLOAT32(oldCameraData + 1)) * m_camera.view.m[0][0] - (READ_LE_FLOAT32(oldCameraData + 2)) * m_camera.view.m[0][1] - (READ_LE_FLOAT32(oldCameraData + 3)) * m_camera.view.m[0][2]);
+	int32 TR2vy = (int32)(-(READ_LE_FLOAT32(oldCameraData + 1)) * m_camera.view.m[1][0] - (READ_LE_FLOAT32(oldCameraData + 2)) * m_camera.view.m[1][1] - (READ_LE_FLOAT32(oldCameraData + 3)) * m_camera.view.m[1][2]);
+	int32 TR2vz = (int32)(-(READ_LE_FLOAT32(oldCameraData + 1)) * m_camera.view.m[2][0] - (READ_LE_FLOAT32(oldCameraData + 2)) * m_camera.view.m[2][1] - (READ_LE_FLOAT32(oldCameraData + 3)) * m_camera.view.m[2][2]);
 
 	// Multiply the translation by rotation matrix
 	// to get into how PSX does the projection
@@ -1810,7 +1810,7 @@ void _set::HackMakeCamera() {
 	m_camera.view.t[1] = TR2vy >> 12;
 	m_camera.view.t[2] = TR2vz >> 12;
 
-	m_camera.focLen = (uint16)((*(oldCameraData + 13)) * -4.0);
+	m_camera.focLen = (uint16)((READ_LE_FLOAT32(oldCameraData + 13)) * -4.0);
 
 	gte_SetRotMatrix(&m_camera.view);
 	gte_SetTransMatrix(&m_camera.view);
diff --git a/engines/icb/set_pc.h b/engines/icb/set_pc.h
index cec132e2f11..2c751d2f2df 100644
--- a/engines/icb/set_pc.h
+++ b/engines/icb/set_pc.h
@@ -33,6 +33,8 @@
 #include "engines/icb/common/pc_props.h"
 #include "engines/icb/common/px_staticlayers.h"
 
+#include "common/endian.h"
+
 namespace ICB {
 
 #define WEATHER_SCREEN_WIDTH SCREEN_WIDTH
@@ -150,13 +152,13 @@ public: /* Prop Surfaces */
 	int32 m_TotalPropSurfaces;
 };
 
-inline rlp_API *_set::GetPRig() { return (rlp_API *)(((uint8 *)m_currentCamera) + m_currentCamera->lightOffset); }
+inline rlp_API *_set::GetPRig() { return (rlp_API *)(((uint8 *)m_currentCamera) + FROM_LE_32(m_currentCamera->lightOffset)); }
 
-inline pcStaticLayers *_set::GetStaticLayers() { return (pcStaticLayers *)(((uint8 *)m_currentCamera) + m_currentCamera->layerOffset); }
+inline pcStaticLayers *_set::GetStaticLayers() { return (pcStaticLayers *)(((uint8 *)m_currentCamera) + FROM_LE_32(m_currentCamera->layerOffset)); }
 
 inline pcPropFile *_set::GetProps() { return m_props; }
 
-inline uint8 *_set::GetBackground() { return (uint8 *)(((uint8 *)m_currentCamera) + m_currentCamera->backgroundOffset); }
+inline uint8 *_set::GetBackground() { return (uint8 *)(((uint8 *)m_currentCamera) + FROM_LE_32(m_currentCamera->backgroundOffset)); }
 
 inline PXcamera &_set::GetCamera() { return m_camera; }
 
diff --git a/engines/icb/sound/fx_manager.cpp b/engines/icb/sound/fx_manager.cpp
index cdf8414e2b8..cfb835137d3 100644
--- a/engines/icb/sound/fx_manager.cpp
+++ b/engines/icb/sound/fx_manager.cpp
@@ -271,7 +271,7 @@ int32 FxManager::GetDefaultRateByName(const char * /*name*/, uint32 byteOffsetIn
 	delete stream;
 
 	// Return the wavs sampling rate
-	return (header.samplesPerSec);
+	return (FROM_LE_32(header.samplesPerSec));
 }
 
 bool8 FxManager::Load(int32 id, const char * /*name*/, uint32 byteOffsetInCluster) {
@@ -294,11 +294,11 @@ bool8 FxManager::Load(int32 id, const char * /*name*/, uint32 byteOffsetInCluste
 	}
 
 	// Straighten out the block align. (someties it's per second and sometime per sample)
-	if (header.blockAlign > 16)
-		header.blockAlign = (uint16)(header.channels * header.bitsPerSample / 8);
+	if (FROM_LE_16(header.blockAlign) > 16)
+		header.blockAlign = TO_LE_16((uint16)(FROM_LE_16(header.channels) * FROM_LE_16(header.bitsPerSample) / 8));
 
 	// Store buffer sampling rate for easy access later
-	m_effects[id].rate = header.samplesPerSec;
+	m_effects[id].rate = FROM_LE_32(header.samplesPerSec);
 	m_effects[id]._stream = Audio::makeWAVStream(stream, DisposeAfterUse::YES);
 
 	if (m_effects[id].rate != 0)
diff --git a/engines/icb/sound/sound_common.cpp b/engines/icb/sound/sound_common.cpp
index da71287b0f5..b828c82c523 100644
--- a/engines/icb/sound/sound_common.cpp
+++ b/engines/icb/sound/sound_common.cpp
@@ -45,7 +45,7 @@ bool8 openWav(Common::SeekableReadStream *stream, _wavHeader &header, uint32 &le
 	if (stream->read(&header, sizeof(_wavHeader)) != sizeof(_wavHeader))
 		return FALSE8;
 
-	if (header.formatTag != 1) {
+	if (FROM_LE_16(header.formatTag) != 1) {
 		warning("Only supports PCM uncompressed wav files");
 		return FALSE8;
 	}
@@ -76,7 +76,7 @@ bool8 openWav(Common::SeekableReadStream *stream, _wavHeader &header, uint32 &le
 	byteOffsetInCluster = (uint32)stream->pos();
 
 	// Expected number of cycles this sample reguires to completely playback
-	lengthInCycles = (int32)ceil(((double)length / (double)header.avgBytesPerSec) * 12.0f * 1.215f);
+	lengthInCycles = (int32)ceil(((double)length / (double)FROM_LE_32(header.avgBytesPerSec)) * 12.0f * 1.215f);
 
 	stream->seek(pos);
 
diff --git a/engines/icb/sound_lowlevel_pc.cpp b/engines/icb/sound_lowlevel_pc.cpp
index 9bd91873876..6e923c5d9b6 100644
--- a/engines/icb/sound_lowlevel_pc.cpp
+++ b/engines/icb/sound_lowlevel_pc.cpp
@@ -46,12 +46,9 @@ bool8 DoesClusterContainFile(pxString clustername, uint32 hash_to_find, uint32 &
 	if (stream == nullptr)
 		Fatal_error(pxVString("Failed to open cluster: %s", clustername.c_str()));
 
-	// Read in first 16 bytes so we can get the header size
-	uint32 data[4];
-	stream->read(data, sizeof(uint32) * 4);
-
 	// Get the size in bytes of the cluster header
-	uint32 clustersize = data[2];
+	stream->skip(8);
+	uint32 clustersize = stream->readUint32LE();
 
 	// Seek to beginning of file
 	stream->seek(0, SEEK_SET);
@@ -70,12 +67,12 @@ bool8 DoesClusterContainFile(pxString clustername, uint32 hash_to_find, uint32 &
 	Cluster_API *clu = (Cluster_API *)memory;
 
 	// Look for the file in the cluster
-	int32 nFiles = (int32)clu->ho.noFiles;
+	int32 nFiles = (int32)FROM_LE_32(clu->ho.noFiles);
 
 	int32 i;
 	for (i = 0; i < nFiles; i++) {
 		// Have we found it
-		if (hash_to_find == clu->hn[i].hash)
+		if (hash_to_find == FROM_LE_32(clu->hn[i].hash))
 			break;
 	}
 
@@ -88,8 +85,8 @@ bool8 DoesClusterContainFile(pxString clustername, uint32 hash_to_find, uint32 &
 	}
 
 	// Get the figures we need for streaming
-	filesize = clu->hn[i].size;
-	fileoffset = clu->hn[i].offset;
+	filesize = FROM_LE_32(clu->hn[i].size);
+	fileoffset = FROM_LE_32(clu->hn[i].offset);
 
 	// Tidy up
 	delete[] memory;
diff --git a/engines/icb/stagedraw_pc_poly.cpp b/engines/icb/stagedraw_pc_poly.cpp
index 750481dfa9c..bb2b9bd9e99 100644
--- a/engines/icb/stagedraw_pc_poly.cpp
+++ b/engines/icb/stagedraw_pc_poly.cpp
@@ -891,15 +891,15 @@ void StageDrawPoly(SDactor *actors, uint32 actorQty) {
 									uint16 *ptr = rowAd;
 									for (int32 x = 0; x < TILE_WIDTH;) {
 										// read the rle counters (trans/solid)
-										int32 trans = ((int32)*zPtr) & 0xff;
-										int32 solid = ((int32)*zPtr) >> 8;
+										int32 trans = ((int32)READ_LE_U16(zPtr)) & 0xff;
+										int32 solid = ((int32)READ_LE_U16(zPtr)) >> 8;
 										zPtr++;
 
 										x += trans + solid;
 										ptr += trans;
 
 										while (solid--) {
-											if (*ptr > *zPtr)
+											if (*ptr > READ_LE_U16(zPtr))
 												*ptr = 0xffff;
 											++ptr;
 											++zPtr;
@@ -921,14 +921,14 @@ void StageDrawPoly(SDactor *actors, uint32 actorQty) {
 									uint16 *aZ = bufZ;
 									for (int32 x = 0; x < TILE_WIDTH;) {
 										// read the rle counters (trans/solid)
-										int32 trans = ((int32)*tPtr) & 0xff;
-										int32 solid = ((int32)*tPtr) >> 8;
+										int32 trans = ((int32)READ_LE_U16(tPtr)) & 0xff;
+										int32 solid = ((int32)READ_LE_U16(tPtr)) >> 8;
 										tPtr++;
 										aRGB += trans;
 										aZ += trans;
 										x += trans + solid;
 										while (solid--) {
-											if (*tPtr++ <= *aZ) {
+											if (READ_LE_U16(tPtr++) <= *aZ) {
 												uint8 *pix = (uint8 *)aRGB;
 												uint8 *t = (uint8 *)tPtr;
 												for (int32 i = 0; i < 3; i++) {
@@ -1061,14 +1061,14 @@ void StageDrawPoly(SDactor *actors, uint32 actorQty) {
 								uint16 *aZ = bufZ;
 								for (int32 x = 0; x < TILE_WIDTH;) {
 									// read the rle counters (trans/solid)
-									int32 trans = ((int32)*tPtr) & 0xff;
-									int32 solid = ((int32)*tPtr) >> 8;
+									int32 trans = ((int32)READ_LE_U16(tPtr)) & 0xff;
+									int32 solid = ((int32)READ_LE_U16(tPtr)) >> 8;
 									tPtr++;
 									aRGB += trans;
 									aZ += trans;
 									x += trans + solid;
 									while (solid--) {
-										if (*tPtr++ <= *aZ) {
+										if (READ_LE_U16(tPtr++) <= *aZ) {
 											uint8 *pix = (uint8 *)aRGB;
 											uint8 *t = (uint8 *)tPtr;
 											for (int32 i = 0; i < 3; i++) {
@@ -1202,8 +1202,8 @@ void StageDrawPoly(SDactor *actors, uint32 actorQty) {
 								uint32 *rgbDst = rgbS32;
 								for (int32 x = 0; x < TILE_WIDTH;) {
 									// read the rle counters (trans/solid)
-									int32 trans = ((int32)*zPtr) & 0xff;
-									int32 solid = ((int32)*zPtr) >> 8;
+									int32 trans = ((int32)READ_LE_U16(zPtr)) & 0xff;
+									int32 solid = ((int32)READ_LE_U16(zPtr)) >> 8;
 									zPtr++;
 
 									x += trans + solid;
@@ -1297,7 +1297,7 @@ void StageDrawPoly(SDactor *actors, uint32 actorQty) {
 									}
 
 									while (solid--) {
-										if (*zDst < *zPtr) {
+										if (*zDst < READ_LE_U16(zPtr)) {
 											switch ((*rgbSrc) >> 30) {
 											case 0:
 												*rgbDst = *rgbSrc;
@@ -1620,8 +1620,8 @@ void StageDrawPoly(SDactor *actors, uint32 actorQty) {
 										uint32 *rgbDst = rgbS32;
 										for (int32 x = 0; x < TILE_WIDTH;) {
 											// read the rle counters (trans/solid)
-											int32 trans = ((int32)*zPtr) & 0xff;
-											int32 solid = ((int32)*zPtr) >> 8;
+											int32 trans = ((int32)READ_LE_U16(zPtr)) & 0xff;
+											int32 solid = ((int32)READ_LE_U16(zPtr)) >> 8;
 											zPtr++;
 
 											x += trans + solid;
@@ -1715,7 +1715,7 @@ void StageDrawPoly(SDactor *actors, uint32 actorQty) {
 											}
 
 											while (solid--) {
-												if ((*zDst < *zPtr) && (*zDst < *(zDst + (ZBUFFERSIZE >> 1)))) {
+												if ((*zDst < READ_LE_U16(zPtr)) && (*zDst < *(zDst + (ZBUFFERSIZE >> 1)))) {
 													switch ((*rgbSrc) >> 30) {
 													case 0:
 														*rgbDst = *rgbSrc;
diff --git a/engines/icb/text_sprites.cpp b/engines/icb/text_sprites.cpp
index 344d7c573ee..e5e532e298b 100644
--- a/engines/icb/text_sprites.cpp
+++ b/engines/icb/text_sprites.cpp
@@ -294,17 +294,25 @@ _TSrtn text_sprite::AnalyseSentence() {
 
 uint32 text_sprite::CharWidth(const uint8 ch, const char *fontRes, uint32 fontRes_hash) {
 	_pxBitmap *charSet = LoadFont(fontRes, fontRes_hash);
-	_pxSprite *spr = (_pxSprite *)charSet->Fetch_item_by_number(ch - ' ');
+
+	uint32 nNumber = ch - ' ';
+	assert(nNumber < FROM_LE_32(charSet->num_sprites));
+
+	_pxSprite *spr = (_pxSprite *)((byte *)charSet + FROM_LE_32(charSet->sprite_offsets[nNumber]));
 	return (spr->width);
 }
 
 uint32 text_sprite::CharHeight(const char *fontRes, uint32 fontRes_hash) { // assume all chars the same height!
 	_pxBitmap *charSet = LoadFont(fontRes, fontRes_hash);
-	_pxSprite *spr = (_pxSprite *)charSet->Fetch_item_by_number(0);
+	_pxSprite *spr = (_pxSprite *)((byte *)charSet + FROM_LE_32(charSet->sprite_offsets[0]));
 	return spr->height;
 }
 
-_pxSprite *text_sprite::FindChar(uint8 ch, _pxBitmap *charSet) { return ((_pxSprite *)charSet->Fetch_item_by_number(ch - ' ')); }
+_pxSprite *text_sprite::FindChar(uint8 ch, _pxBitmap *charSet) {
+	uint32 nNumber = ch - ' ';
+	assert(nNumber < FROM_LE_32(charSet->num_sprites));
+	return ((_pxSprite *)((byte *)charSet + FROM_LE_32(charSet->sprite_offsets[nNumber])));
+}
 
 void text_sprite::CopyChar(_pxSprite *charPtr, uint8 *spritePtr, uint8 *pal) { // copy character into sprite, based on params
 	uint8 *rowPtr;
diff --git a/engines/icb/text_sprites_pc.cpp b/engines/icb/text_sprites_pc.cpp
index f558d9d5402..55f16956cb0 100644
--- a/engines/icb/text_sprites_pc.cpp
+++ b/engines/icb/text_sprites_pc.cpp
@@ -86,7 +86,7 @@ _TSrtn text_sprite::BuildTextSprite(int32 stopAtLine, bool8 bRemoraLeftFormattin
 	if (charSet->schema != PC_BITMAP_SCHEMA)
 		Fatal_error("Incorrect versions loading [%s] (engine has %d, data has %d", const_cast<char *>(params.fontResource), PC_BITMAP_SCHEMA, charSet->schema);
 
-	pal = (uint8 *)charSet->Fetch_palette_pointer();
+	pal = (uint8 *)&charSet->palette[0];
 
 	// If the temporary text colour is set, copy it into palette entry 1.  NB: This code assumes a 32-bit
 	// palette.  If this ever changes then this code needs to change.  This should be done with schema numbers.




More information about the Scummvm-git-logs mailing list