diff --git a/Source/drlg_l1.cpp b/Source/drlg_l1.cpp index 4868be6d6f8..07ce6036635 100644 --- a/Source/drlg_l1.cpp +++ b/Source/drlg_l1.cpp @@ -207,13 +207,15 @@ void DRLG_L1Pass3() { int i, j, xx, yy; long v1, v2, v3, v4, lv; + WORD *MegaTiles; lv = 22 - 1; - v1 = *((WORD *)&pMegaTiles[lv * 8]) + 1; - v2 = *((WORD *)&pMegaTiles[lv * 8] + 1) + 1; - v3 = *((WORD *)&pMegaTiles[lv * 8] + 2) + 1; - v4 = *((WORD *)&pMegaTiles[lv * 8] + 3) + 1; + MegaTiles = (WORD *)&pMegaTiles[lv * 8]; + v1 = SDL_SwapLE16(*(MegaTiles + 0)) + 1; + v2 = SDL_SwapLE16(*(MegaTiles + 1)) + 1; + v3 = SDL_SwapLE16(*(MegaTiles + 2)) + 1; + v4 = SDL_SwapLE16(*(MegaTiles + 3)) + 1; for (j = 0; j < MAXDUNY; j += 2) { @@ -231,10 +233,11 @@ void DRLG_L1Pass3() for (i = 0; i < DMAXX; i++) { lv = dungeon[i][j] - 1; /// ASSERT: assert(lv >= 0); - v1 = *((WORD *)&pMegaTiles[lv * 8]) + 1; - v2 = *((WORD *)&pMegaTiles[lv * 8] + 1) + 1; - v3 = *((WORD *)&pMegaTiles[lv * 8] + 2) + 1; - v4 = *((WORD *)&pMegaTiles[lv * 8] + 3) + 1; + MegaTiles = (WORD *)&pMegaTiles[lv * 8]; + v1 = SDL_SwapLE16(*(MegaTiles + 0)) + 1; + v2 = SDL_SwapLE16(*(MegaTiles + 1)) + 1; + v3 = SDL_SwapLE16(*(MegaTiles + 2)) + 1; + v4 = SDL_SwapLE16(*(MegaTiles + 3)) + 1; dPiece[xx][yy] = v1; dPiece[xx + 1][yy] = v2; dPiece[xx][yy + 1] = v3; diff --git a/Source/drlg_l2.cpp b/Source/drlg_l2.cpp index b2848c7165f..d1235898651 100644 --- a/Source/drlg_l2.cpp +++ b/Source/drlg_l2.cpp @@ -424,13 +424,15 @@ void DRLG_L2Pass3() { int i, j, xx, yy; long v1, v2, v3, v4, lv; + WORD *MegaTiles; lv = 12 - 1; - v1 = *((WORD *)&pMegaTiles[lv * 8]) + 1; - v2 = *((WORD *)&pMegaTiles[lv * 8] + 1) + 1; - v3 = *((WORD *)&pMegaTiles[lv * 8] + 2) + 1; - v4 = *((WORD *)&pMegaTiles[lv * 8] + 3) + 1; + MegaTiles = (WORD *)&pMegaTiles[lv * 8]; + v1 = SDL_SwapLE16(*(MegaTiles + 0)) + 1; + v2 = SDL_SwapLE16(*(MegaTiles + 1)) + 1; + v3 = SDL_SwapLE16(*(MegaTiles + 2)) + 1; + v4 = SDL_SwapLE16(*(MegaTiles + 3)) + 1; for (j = 0; j < MAXDUNY; j += 2) { @@ -447,10 +449,11 @@ void DRLG_L2Pass3() xx = 16; for (i = 0; i < DMAXX; i++) { lv = dungeon[i][j] - 1; - v1 = *((WORD *)&pMegaTiles[lv * 8]) + 1; - v2 = *((WORD *)&pMegaTiles[lv * 8] + 1) + 1; - v3 = *((WORD *)&pMegaTiles[lv * 8] + 2) + 1; - v4 = *((WORD *)&pMegaTiles[lv * 8] + 3) + 1; + MegaTiles = (WORD *)&pMegaTiles[lv * 8]; + v1 = SDL_SwapLE16(*(MegaTiles + 0)) + 1; + v2 = SDL_SwapLE16(*(MegaTiles + 1)) + 1; + v3 = SDL_SwapLE16(*(MegaTiles + 2)) + 1; + v4 = SDL_SwapLE16(*(MegaTiles + 3)) + 1; dPiece[xx][yy] = v1; dPiece[xx + 1][yy] = v2; dPiece[xx][yy + 1] = v3; diff --git a/Source/drlg_l3.cpp b/Source/drlg_l3.cpp index c877cd68e43..5b0a51d2913 100644 --- a/Source/drlg_l3.cpp +++ b/Source/drlg_l3.cpp @@ -1640,13 +1640,15 @@ void DRLG_L3Pass3() { int i, j, xx, yy; long v1, v2, v3, v4, lv; + WORD *MegaTiles; lv = 8 - 1; - v1 = *((WORD *)&pMegaTiles[lv * 8]) + 1; - v2 = *((WORD *)&pMegaTiles[lv * 8] + 1) + 1; - v3 = *((WORD *)&pMegaTiles[lv * 8] + 2) + 1; - v4 = *((WORD *)&pMegaTiles[lv * 8] + 3) + 1; + MegaTiles = (WORD *)&pMegaTiles[lv * 8]; + v1 = SDL_SwapLE16(*(MegaTiles + 0)) + 1; + v2 = SDL_SwapLE16(*(MegaTiles + 1)) + 1; + v3 = SDL_SwapLE16(*(MegaTiles + 2)) + 1; + v4 = SDL_SwapLE16(*(MegaTiles + 3)) + 1; for (j = 0; j < MAXDUNY; j += 2) { @@ -1664,10 +1666,11 @@ void DRLG_L3Pass3() for (i = 0; i < DMAXX; i++) { lv = dungeon[i][j] - 1; if (lv >= 0) { - v1 = *((WORD *)&pMegaTiles[lv * 8]) + 1; - v2 = *((WORD *)&pMegaTiles[lv * 8] + 1) + 1; - v3 = *((WORD *)&pMegaTiles[lv * 8] + 2) + 1; - v4 = *((WORD *)&pMegaTiles[lv * 8] + 3) + 1; + MegaTiles = (WORD *)&pMegaTiles[lv * 8]; + v1 = SDL_SwapLE16(*(MegaTiles + 0)) + 1; + v2 = SDL_SwapLE16(*(MegaTiles + 1)) + 1; + v3 = SDL_SwapLE16(*(MegaTiles + 2)) + 1; + v4 = SDL_SwapLE16(*(MegaTiles + 3)) + 1; } else { v1 = 0; v2 = 0; diff --git a/Source/drlg_l4.cpp b/Source/drlg_l4.cpp index ae5f7edcd3f..55520b88069 100644 --- a/Source/drlg_l4.cpp +++ b/Source/drlg_l4.cpp @@ -1900,13 +1900,15 @@ void DRLG_L4Pass3() { int i, j, xx, yy; long v1, v2, v3, v4, lv; + WORD *MegaTiles; lv = 30 - 1; - v1 = *((WORD *)&pMegaTiles[lv * 8]) + 1; - v2 = *((WORD *)&pMegaTiles[lv * 8] + 1) + 1; - v3 = *((WORD *)&pMegaTiles[lv * 8] + 2) + 1; - v4 = *((WORD *)&pMegaTiles[lv * 8] + 3) + 1; + MegaTiles = (WORD *)&pMegaTiles[lv * 8]; + v1 = SDL_SwapLE16(*(MegaTiles + 0)) + 1; + v2 = SDL_SwapLE16(*(MegaTiles + 1)) + 1; + v3 = SDL_SwapLE16(*(MegaTiles + 2)) + 1; + v4 = SDL_SwapLE16(*(MegaTiles + 3)) + 1; for (j = 0; j < MAXDUNY; j += 2) { @@ -1924,10 +1926,11 @@ void DRLG_L4Pass3() for (i = 0; i < DMAXX; i++) { lv = dungeon[i][j] - 1; if (lv >= 0) { - v1 = *((WORD *)&pMegaTiles[lv * 8]) + 1; - v2 = *((WORD *)&pMegaTiles[lv * 8] + 1) + 1; - v3 = *((WORD *)&pMegaTiles[lv * 8] + 2) + 1; - v4 = *((WORD *)&pMegaTiles[lv * 8] + 3) + 1; + MegaTiles = (WORD *)&pMegaTiles[lv * 8]; + v1 = SDL_SwapLE16(*(MegaTiles + 0)) + 1; + v2 = SDL_SwapLE16(*(MegaTiles + 1)) + 1; + v3 = SDL_SwapLE16(*(MegaTiles + 2)) + 1; + v4 = SDL_SwapLE16(*(MegaTiles + 3)) + 1; } else { v1 = 0; v2 = 0; diff --git a/Source/mpqapi.cpp b/Source/mpqapi.cpp index a143901c613..beb8a85c56b 100644 --- a/Source/mpqapi.cpp +++ b/Source/mpqapi.cpp @@ -584,15 +584,15 @@ BOOL WriteMPQHeader() DWORD NumberOfBytesWritten; memset(&fhdr, 0, sizeof(fhdr)); - fhdr.signature = '\x1AQPM'; - fhdr.headersize = 32; - fhdr.filesize = GetFileSize(sghArchive, 0); - fhdr.version = 0; - fhdr.sectorsizeid = 3; - fhdr.hashoffset = 32872; - fhdr.blockoffset = 104; - fhdr.hashcount = 2048; - fhdr.blockcount = 2048; + fhdr.signature = SDL_SwapLE32('\x1AQPM'); + fhdr.headersize = SDL_SwapLE32(32); + fhdr.filesize = SDL_SwapLE32(GetFileSize(sghArchive, 0)); + fhdr.version = SDL_SwapLE16(0); + fhdr.sectorsizeid = SDL_SwapLE16(3); + fhdr.hashoffset = SDL_SwapLE32(32872); + fhdr.blockoffset = SDL_SwapLE32(104); + fhdr.hashcount = SDL_SwapLE32(2048); + fhdr.blockcount = SDL_SwapLE32(2048); if (SetFilePointer(sghArchive, 0, NULL, FILE_BEGIN) == -1) return 0; diff --git a/Source/town.cpp b/Source/town.cpp index 4f70ce41a78..17de9a5de50 100644 --- a/Source/town.cpp +++ b/Source/town.cpp @@ -1007,7 +1007,7 @@ void SetTownMicros() lv--; pPiece = (WORD *)&pLevelPieces[32 * lv]; for (i = 0; i < 16; i++) { - pMap->mt[i] = pPiece[(i & 1) + 14 - (i & 0xE)]; + pMap->mt[i] = SDL_SwapLE16(pPiece[(i & 1) + 14 - (i & 0xE)]); } } else { for (i = 0; i < 16; i++) { @@ -1032,8 +1032,9 @@ void SetTownMicros() void T_FillSector(BYTE *P3Tiles, BYTE *pSector, int xi, int yi, int w, int h) { - int i, j, xx, yy; + int i, j, xx, yy, nMap; long v1, v2, v3, v4, ii; + WORD *Sector; ii = 4; yy = yi; @@ -1043,11 +1044,14 @@ void T_FillSector(BYTE *P3Tiles, BYTE *pSector, int xi, int yi, int w, int h) WORD *Map; Map = (WORD *)&pSector[ii]; - if (*Map) { - v1 = *((WORD *)&P3Tiles[(*Map - 1) * 8]) + 1; - v2 = *((WORD *)&P3Tiles[(*Map - 1) * 8] + 1) + 1; - v3 = *((WORD *)&P3Tiles[(*Map - 1) * 8] + 2) + 1; - v4 = *((WORD *)&P3Tiles[(*Map - 1) * 8] + 3) + 1; + nMap = SDL_SwapLE16(*Map); + if (nMap) { + Sector = (((WORD *)&P3Tiles[(nMap - 1) * 8])); + v1 = SDL_SwapLE16(*(Sector + 0)) + 1; + v2 = SDL_SwapLE16(*(Sector + 1)) + 1; + v3 = SDL_SwapLE16(*(Sector + 2)) + 1; + v4 = SDL_SwapLE16(*(Sector + 3)) + 1; + } else { v1 = 0; v2 = 0; @@ -1068,11 +1072,13 @@ void T_FillSector(BYTE *P3Tiles, BYTE *pSector, int xi, int yi, int w, int h) void T_FillTile(BYTE *P3Tiles, int xx, int yy, int t) { long v1, v2, v3, v4; + WORD *Tiles; - v1 = *((WORD *)&P3Tiles[(t - 1) * 8]) + 1; - v2 = *((WORD *)&P3Tiles[(t - 1) * 8] + 1) + 1; - v3 = *((WORD *)&P3Tiles[(t - 1) * 8] + 2) + 1; - v4 = *((WORD *)&P3Tiles[(t - 1) * 8] + 3) + 1; + Tiles = ((WORD *)&P3Tiles[(t - 1) * 8]); + v1 = SDL_SwapLE16(*(Tiles + 0)) + 1; + v2 = SDL_SwapLE16(*(Tiles + 1)) + 1; + v3 = SDL_SwapLE16(*(Tiles + 2)) + 1; + v4 = SDL_SwapLE16(*(Tiles + 3)) + 1; dPiece[xx][yy] = v1; dPiece[xx + 1][yy] = v2;