Browse Source

Make header checks portable

pull/1095/head
Anders Jenbo 5 years ago
parent
commit
d37fb68809
  1. 2
      CMakeLists.txt
  2. 1
      Source/engine.h
  3. 16
      Source/loadsave.cpp
  4. 5
      Source/mainmenu.cpp
  5. 6
      Source/mpqapi.cpp
  6. 11
      Source/multi.cpp
  7. 2
      Source/multi.h
  8. 2
      defs.h

2
CMakeLists.txt

@ -626,7 +626,7 @@ if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
target_compile_options(devilution PUBLIC $<${DEBUG_GENEX}:-fno-omit-frame-pointer>)
# Warnings for devilution
target_compile_options(devilution PRIVATE -Wno-multichar -Wno-int-to-pointer-cast)
target_compile_options(devilution PRIVATE -Wno-int-to-pointer-cast)
# Warnings for devilutionX
target_compile_options(${BIN_TARGET} PRIVATE -Wall -Wextra -Wno-unused-parameter -Wno-format-security)

1
Source/engine.h

@ -33,6 +33,7 @@ inline BYTE *CelGetFrameStart(BYTE *pCelBuff, int nCel)
}
#define LOAD_LE32(b) (((DWORD)(b)[3] << 24) | ((DWORD)(b)[2] << 16) | ((DWORD)(b)[1] << 8) | (DWORD)(b)[0])
#define LOAD_BE32(b) (((DWORD)(b)[0] << 24) | ((DWORD)(b)[1] << 16) | ((DWORD)(b)[2] << 8) | (DWORD)(b)[3])
inline BYTE *CelGetFrame(BYTE *pCelBuff, int nCel, int *nDataSize)
{
DWORD nCellStart;

16
Source/loadsave.cpp

@ -748,14 +748,14 @@ int RemapItemIdxToDiablo(int i)
bool IsHeaderValid(int magicNumber)
{
gbIsHellfireSaveGame = false;
if (magicNumber == 'SHAR') {
if (magicNumber == LOAD_BE32("SHAR")) {
return true;
} else if (magicNumber == 'SHLF') {
} else if (magicNumber == LOAD_BE32("SHLF")) {
gbIsHellfireSaveGame = true;
return true;
} else if (!gbIsSpawn && magicNumber == 'RETL') {
} else if (!gbIsSpawn && magicNumber == LOAD_BE32("RETL")) {
return true;
} else if (!gbIsSpawn && magicNumber == 'HELF') {
} else if (!gbIsSpawn && magicNumber == LOAD_BE32("HELF")) {
gbIsHellfireSaveGame = true;
return true;
}
@ -1642,13 +1642,13 @@ void SaveGame()
tbuff = SaveBuff;
if (gbIsSpawn && !gbIsHellfire)
ISave('SHAR');
ISave(LOAD_BE32("SHAR"));
else if (gbIsSpawn && gbIsHellfire)
ISave('SHLF');
ISave(LOAD_BE32("SHLF"));
else if (!gbIsSpawn && gbIsHellfire)
ISave('HELF');
ISave(LOAD_BE32("HELF"));
else if (!gbIsSpawn && !gbIsHellfire)
ISave('RETL');
ISave(LOAD_BE32("RETL"));
else
app_fatal("Invalid game state");

5
Source/mainmenu.cpp

@ -126,10 +126,7 @@ BOOL mainmenu_select_hero_dialog(
pfile_create_player_description(cdesc, cdlen);
if (multi) {
if (mode == 'BNET')
*multi = hero_is_created || !plr[myplr].pBattleNet;
else
*multi = hero_is_created;
*multi = hero_is_created;
}
if (cname && clen)
SStrCopy(cname, gszHero, clen);

6
Source/mpqapi.cpp

@ -262,7 +262,7 @@ private:
_FILEHEADER fhdr;
memset(&fhdr, 0, sizeof(fhdr));
fhdr.signature = SDL_SwapLE32('\x1AQPM');
fhdr.signature = LOAD_LE32("MPQ\x1A");
fhdr.headersize = SDL_SwapLE32(32);
fhdr.filesize = SDL_SwapLE32(static_cast<uint32_t>(size));
fhdr.version = SDL_SwapLE16(0);
@ -312,7 +312,7 @@ void ByteSwapHdr(_FILEHEADER *hdr)
void InitDefaultMpqHeader(Archive *archive, _FILEHEADER *hdr)
{
std::memset(hdr, 0, sizeof(*hdr));
hdr->signature = '\x1AQPM';
hdr->signature = LOAD_LE32("MPQ\x1A");
hdr->headersize = 32;
hdr->sectorsizeid = 3;
hdr->version = 0;
@ -322,7 +322,7 @@ void InitDefaultMpqHeader(Archive *archive, _FILEHEADER *hdr)
bool IsValidMPQHeader(const Archive &archive, _FILEHEADER *hdr)
{
return hdr->signature == '\x1AQPM'
return hdr->signature == LOAD_LE32("MPQ\x1A")
&& hdr->headersize == 32
&& hdr->version <= 0
&& hdr->sectorsizeid == 3

11
Source/multi.cpp

@ -105,7 +105,7 @@ static BYTE *multi_recv_packet(TBuffer *pBuf, BYTE *body, DWORD *size)
static void NetRecvPlrData(TPkt *pkt)
{
pkt->hdr.wCheck = 'ip';
pkt->hdr.wCheck = LOAD_BE32("\0\0ip");
pkt->hdr.px = plr[myplr]._px;
pkt->hdr.py = plr[myplr]._py;
pkt->hdr.targx = plr[myplr]._ptargx;
@ -457,7 +457,7 @@ void multi_process_network_packets()
continue;
if (dwID >= MAX_PLRS)
continue;
if (pkt->wCheck != 'ip')
if (pkt->wCheck != LOAD_BE32("\0\0ip"))
continue;
if (pkt->wLen != dwMsgSize)
continue;
@ -522,7 +522,7 @@ void multi_send_zero_packet(int pnum, BYTE bCmd, BYTE *pbSrc, DWORD dwLen)
dwOffset = 0;
while (dwLen != 0) {
pkt.hdr.wCheck = 'ip';
pkt.hdr.wCheck = LOAD_BE32("\0\0ip");
pkt.hdr.px = 0;
pkt.hdr.py = 0;
pkt.hdr.targx = 0;
@ -851,8 +851,6 @@ BOOL multi_init_multi(_SNETPROGRAMDATA *client_info, _SNETPLAYERDATA *user_info,
&& (!first || SErrGetLastError() != STORM_ERROR_REQUIRES_UPGRADE || !multi_upgrade(pfExitProgram))) {
return FALSE;
}
if (type == 'BNET')
plr[0].pBattleNet = 1;
}
multi_event_handler(TRUE);
@ -870,9 +868,6 @@ BOOL multi_init_multi(_SNETPROGRAMDATA *client_info, _SNETPLAYERDATA *user_info,
pfile_read_player_from_save();
if (type == 'BNET')
plr[myplr].pBattleNet = 1;
return TRUE;
}
}

2
Source/multi.h

@ -15,7 +15,7 @@ extern "C" {
typedef struct GameData {
Sint32 size;
Sint32 dwSeed;
Sint32 programid;
Uint32 programid;
Uint8 versionMajor;
Uint8 versionMinor;
Uint8 versionPatch;

2
defs.h

@ -92,7 +92,7 @@
#define PMSG_COUNT 8
#define GAME_ID (gbIsHellfire ? (gbIsSpawn ? 'HSHR' : 'HRTL') : (gbIsSpawn ? 'DSHR' : 'DRTL'))
#define GAME_ID (gbIsHellfire ? (gbIsSpawn ? LOAD_BE32("HSHR") : LOAD_BE32("HRTL")) : (gbIsSpawn ? LOAD_BE32("DSHR") : LOAD_BE32("DRTL")))
// Diablo uses a 256 color palette
// Entry 0-127 (0x00-0x7F) are level specific

Loading…
Cancel
Save