From a68c10edf2a950d151b8697ed344d3e58c636708 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Thu, 31 Dec 2020 04:35:15 +0100 Subject: [PATCH 01/11] Document another Hellfire bug --- Source/monster.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/monster.cpp b/Source/monster.cpp index 1f848055d..d3e60ca6f 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -2736,7 +2736,7 @@ BOOL M_DoRSpAttack(int i) monster[i]._mVar3, 0); #ifdef HELLFIRE - if (Monsters[i].Snds[3][0] != 0) + if (Monsters[i].Snds[3][0] != 0) // BUGFIX `Monsters[i].` should be `monster[i].MType->` #endif PlayEffect(i, 3); } From 043d15db66322937404d6a80a6ed31475a0d8432 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Fri, 1 Jan 2021 01:34:12 +0100 Subject: [PATCH 02/11] [hellfire] PackPlayer and frinds --- Source/multi.cpp | 4 ++++ Source/pack.cpp | 14 +++++++++++--- Source/pack.h | 4 +++- Source/pfile.cpp | 16 ++++++++++++++++ 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/Source/multi.cpp b/Source/multi.cpp index 9aa5a81e2..15de1a8d9 100644 --- a/Source/multi.cpp +++ b/Source/multi.cpp @@ -620,7 +620,11 @@ static void multi_send_pinfo(int pnum, char cmd) { PkPlayerStruct pkplr; +#ifdef HELLFIRE + PackPlayer(&pkplr, myplr); +#else PackPlayer(&pkplr, myplr, TRUE); +#endif dthread_send_delta(pnum, cmd, &pkplr, sizeof(pkplr)); } diff --git a/Source/pack.cpp b/Source/pack.cpp index 8aab48828..422a1d10d 100644 --- a/Source/pack.cpp +++ b/Source/pack.cpp @@ -40,7 +40,11 @@ static } } +#ifdef HELLFIRE +void PackPlayer(PkPlayerStruct *pPack, int pnum) +#else void PackPlayer(PkPlayerStruct *pPack, int pnum, BOOL manashield) +#endif { PlayerStruct *pPlayer; int i; @@ -73,11 +77,15 @@ void PackPlayer(PkPlayerStruct *pPack, int pnum, BOOL manashield) pPack->pMaxManaBase = pPlayer->_pMaxManaBase; pPack->pMemSpells = pPlayer->_pMemSpells; - for (i = 0; i < 37; i++) // Should be MAX_SPELLS but set to 37 to make save games compatible - pPack->pSplLvl[i] = pPlayer->_pSplLvl[i]; #ifdef HELLFIRE + for (i = 0; i <= 36; i++) // Should be MAX_SPELLS-1 but set to 36 to make save games compatible + pPack->pSplLvl[i] = pPlayer->_pSplLvl[i]; + char *p = pPack->pSplLvl2; for (i = 37; i < 47; i++) - pPack->pSplLvl2[i - 37] = pPlayer->_pSplLvl[i]; + p[i - 37] = pPlayer->_pSplLvl[i]; +#else + for (i = 0; i < MAX_SPELLS; i++) + pPack->pSplLvl[i] = pPlayer->_pSplLvl[i]; #endif pki = &pPack->InvBody[0]; diff --git a/Source/pack.h b/Source/pack.h index b9823c57a..907196c93 100644 --- a/Source/pack.h +++ b/Source/pack.h @@ -6,11 +6,13 @@ #ifndef __PACK_H__ #define __PACK_H__ -void PackPlayer(PkPlayerStruct *pPack, int pnum, BOOL manashield); void UnPackPlayer(PkPlayerStruct *pPack, int pnum, BOOL killok); #ifdef HELLFIRE +void PackPlayer(PkPlayerStruct *pPack, int pnum); void PackItem(PkItemStruct *id, ItemStruct *is); void UnPackItem(PkItemStruct *is, ItemStruct *id); +#else +void PackPlayer(PkPlayerStruct *pPack, int pnum, BOOL manashield); #endif /* rdata */ diff --git a/Source/pfile.cpp b/Source/pfile.cpp index 39cd8ced9..4f1d46a4c 100644 --- a/Source/pfile.cpp +++ b/Source/pfile.cpp @@ -250,7 +250,11 @@ void pfile_write_hero() save_num = pfile_get_save_num_from_name(plr[myplr]._pName); if (pfile_open_archive(TRUE, save_num)) { +#ifdef HELLFIRE + PackPlayer(&pkplr, myplr); +#else PackPlayer(&pkplr, myplr, gbMaxPlayers == 1); +#endif pfile_encode_hero(&pkplr); pfile_flush(gbMaxPlayers == 1, save_num); } @@ -465,12 +469,20 @@ BOOL __stdcall pfile_ui_save_create(_uiheroinfo *heroinfo) PkPlayerStruct pkplr; save_num = pfile_get_save_num_from_name(heroinfo->name); +#ifdef HELLFIRE + if (save_num >= MAX_CHARACTERS) { +#else if (save_num == MAX_CHARACTERS) { +#endif for (save_num = 0; save_num < MAX_CHARACTERS; save_num++) { if (!hero_names[save_num][0]) break; } +#ifdef HELLFIRE + if (save_num >= MAX_CHARACTERS) +#else if (save_num == MAX_CHARACTERS) +#endif return FALSE; } if (!pfile_open_archive(FALSE, save_num)) @@ -482,7 +494,11 @@ BOOL __stdcall pfile_ui_save_create(_uiheroinfo *heroinfo) CreatePlayer(0, cl); strncpy(plr[0]._pName, heroinfo->name, PLR_NAME_LEN); plr[0]._pName[PLR_NAME_LEN - 1] = '\0'; +#ifdef HELLFIRE + PackPlayer(&pkplr, 0); +#else PackPlayer(&pkplr, 0, TRUE); +#endif pfile_encode_hero(&pkplr); game_2_ui_player(&plr[0], heroinfo, FALSE); pfile_flush(TRUE, save_num); From 2de82823454c7bed3d0b531af8ea10071f85f6b1 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Fri, 1 Jan 2021 02:54:45 +0100 Subject: [PATCH 03/11] [hellfire] pfile_encode_hero --- Source/pfile.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Source/pfile.cpp b/Source/pfile.cpp index 4f1d46a4c..9de225df6 100644 --- a/Source/pfile.cpp +++ b/Source/pfile.cpp @@ -192,8 +192,14 @@ static void pfile_encode_hero(const PkPlayerStruct *pPack) DWORD packed_len; char password[16] = PASSWORD_SINGLE; +#ifdef HELLFIRE + DWORD size = 161; + if (gbMaxPlayers > 1) + GetComputerName(password, &size); +#else if (gbMaxPlayers > 1) strcpy(password, PASSWORD_MULTI); +#endif packed_len = codec_get_encoded_len(sizeof(*pPack)); packed = (BYTE *)DiabloAllocPtr(packed_len); From 6cfc2862d6c3ea77e2fdad2ff2b36d16937c2f86 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Fri, 1 Jan 2021 04:12:01 +0100 Subject: [PATCH 04/11] [hellfire] pfile_get_save_path and frinds --- Source/pfile.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 7 deletions(-) diff --git a/Source/pfile.cpp b/Source/pfile.cpp index 9de225df6..098a25a0e 100644 --- a/Source/pfile.cpp +++ b/Source/pfile.cpp @@ -99,28 +99,50 @@ static char *GetSaveDirectory(char *dst, int dst_size, DWORD save_num) return _strlwr(dst); } +#ifdef HELLFIRE +static void pfile_get_save_path(char *pszBuf, DWORD dwBufSize, DWORD save_num, BOOL hellfire) +#else static void pfile_get_save_path(char *pszBuf, DWORD dwBufSize, DWORD save_num) +#endif { + const char *fmt; DWORD plen; char *s; char path[MAX_PATH]; + #ifdef SPAWN - const char *fmt = "\\share_%d.sv"; + fmt = "\\share_%d.sv"; if (gbMaxPlayers <= 1) fmt = "\\spawn%d.sv"; +#elif defined(HELLFIRE) + if (gbMaxPlayers > 1) { + if (!hellfire) + fmt = "\\dlinfo_%d.drv"; + else + fmt = "\\hrinfo_%d.drv"; + + plen = GetWindowsDirectory(pszBuf, MAX_PATH); + } else { + if (!hellfire) + fmt = "\\single_%d.sv"; + else + fmt = "\\single_%d.hsv"; #else - const char *fmt = "\\multi_%d.sv"; + fmt = "\\multi_%d.sv"; if (gbMaxPlayers <= 1) fmt = "\\single_%d.sv"; #endif - // BUGFIX: ignores dwBufSize and uses MAX_PATH instead - plen = GetModuleFileName(ghInst, pszBuf, MAX_PATH); - s = strrchr(pszBuf, '\\'); - if (s) - *s = '\0'; + // BUGFIX: ignores dwBufSize and uses MAX_PATH instead + plen = GetModuleFileName(ghInst, pszBuf, MAX_PATH); + s = strrchr(pszBuf, '\\'); + if (s) + *s = '\0'; +#ifdef HELLFIRE + } +#endif if (!plen) app_fatal("Unable to get save directory"); @@ -213,8 +235,13 @@ static BOOL pfile_open_archive(BOOL update, DWORD save_num) { char FileName[MAX_PATH]; +#ifdef HELLFIRE + pfile_get_save_path(FileName, sizeof(FileName), save_num, TRUE); + if (OpenMPQ(FileName, gbMaxPlayers > 1, save_num)) +#else pfile_get_save_path(FileName, sizeof(FileName), save_num); if (OpenMPQ(FileName, FALSE, save_num)) +#endif return TRUE; if (update && gbMaxPlayers > 1) @@ -226,7 +253,12 @@ static void pfile_flush(BOOL is_single_player, DWORD save_num) { char FileName[MAX_PATH]; +#ifdef HELLFIRE + pfile_get_save_path(FileName, sizeof(FileName), save_num, TRUE); +#else pfile_get_save_path(FileName, sizeof(FileName), save_num); +#endif + mpqapi_flush_and_close(FileName, is_single_player, save_num); } @@ -238,7 +270,11 @@ static HANDLE pfile_open_save_archive(BOOL *showFixedMsg, DWORD save_num) char SrcStr[MAX_PATH]; HANDLE archive; +#ifdef HELLFIRE + pfile_get_save_path(SrcStr, sizeof(SrcStr), save_num, TRUE); +#else pfile_get_save_path(SrcStr, sizeof(SrcStr), save_num); +#endif if (SFileOpenArchive(SrcStr, 0x7000, FS_PC, &archive)) return archive; return NULL; @@ -405,7 +441,11 @@ BOOL __stdcall pfile_ui_set_hero_infos(BOOL(__stdcall *ui_add_hero_info)(_uihero continue; if (!SRegLoadString("Diablo\\Converted", s, 0, NewFileName, sizeof(NewFileName))) { while (save_num < MAX_CHARACTERS) { +#ifdef HELLFIRE + pfile_get_save_path(NewFileName, sizeof(NewFileName), save_num++, TRUE); +#else pfile_get_save_path(NewFileName, sizeof(NewFileName), save_num++); +#endif if (OpenFile(NewFileName, &ReOpenBuff, OF_EXIST) == HFILE_ERROR) { if (CopyFile(FileName, NewFileName, TRUE)) { DWORD attrib; @@ -544,7 +584,11 @@ BOOL __stdcall pfile_delete_save(_uiheroinfo *hero_info) save_num = pfile_get_save_num_from_name(hero_info->name); if (save_num < MAX_CHARACTERS) { hero_names[save_num][0] = '\0'; +#ifdef HELLFIRE + pfile_get_save_path(FileName, sizeof(FileName), save_num, TRUE); +#else pfile_get_save_path(FileName, sizeof(FileName), save_num); +#endif DeleteFile(FileName); } return TRUE; From e46a0bff55cafe7428b90a9f089489558539c0ca Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Fri, 1 Jan 2021 04:26:38 +0100 Subject: [PATCH 05/11] [hellfire] pfile_ui_set_hero_infos --- Source/pfile.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Source/pfile.cpp b/Source/pfile.cpp index 098a25a0e..1183aaa45 100644 --- a/Source/pfile.cpp +++ b/Source/pfile.cpp @@ -16,7 +16,11 @@ #endif /** List of character names for the character selection screen. */ +#ifdef HELLFIRE +static char hero_names[MAX_CHARACTERS + 1][PLR_NAME_LEN]; +#else static char hero_names[MAX_CHARACTERS][PLR_NAME_LEN]; +#endif BOOL gbValidSaveFile; static void pfile_check_available_space(char *pszDir) @@ -428,6 +432,7 @@ BOOL __stdcall pfile_ui_set_hero_infos(BOOL(__stdcall *ui_add_hero_info)(_uihero BOOL showFixedMsg; memset(hero_names, 0, sizeof(hero_names)); +#ifndef HELLFIRE if (gbMaxPlayers > 1) { for (i = 0, save_num = 0; i < MAX_CHARACTERS && save_num < MAX_CHARACTERS; i++) { struct _OFSTRUCT ReOpenBuff; @@ -441,11 +446,7 @@ BOOL __stdcall pfile_ui_set_hero_infos(BOOL(__stdcall *ui_add_hero_info)(_uihero continue; if (!SRegLoadString("Diablo\\Converted", s, 0, NewFileName, sizeof(NewFileName))) { while (save_num < MAX_CHARACTERS) { -#ifdef HELLFIRE - pfile_get_save_path(NewFileName, sizeof(NewFileName), save_num++, TRUE); -#else pfile_get_save_path(NewFileName, sizeof(NewFileName), save_num++); -#endif if (OpenFile(NewFileName, &ReOpenBuff, OF_EXIST) == HFILE_ERROR) { if (CopyFile(FileName, NewFileName, TRUE)) { DWORD attrib; @@ -462,6 +463,7 @@ BOOL __stdcall pfile_ui_set_hero_infos(BOOL(__stdcall *ui_add_hero_info)(_uihero } } } +#endif showFixedMsg = TRUE; for (i = 0; i < MAX_CHARACTERS; i++) { From 363c37a447695805a1718c1eb9a106eb46d34da1 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Fri, 1 Jan 2021 04:41:36 +0100 Subject: [PATCH 06/11] [hellfire] pfile_get_file_name --- Source/pfile.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/Source/pfile.cpp b/Source/pfile.cpp index 1183aaa45..d86a23fb7 100644 --- a/Source/pfile.cpp +++ b/Source/pfile.cpp @@ -114,12 +114,7 @@ static void pfile_get_save_path(char *pszBuf, DWORD dwBufSize, DWORD save_num) char *s; char path[MAX_PATH]; -#ifdef SPAWN - fmt = "\\share_%d.sv"; - - if (gbMaxPlayers <= 1) - fmt = "\\spawn%d.sv"; -#elif defined(HELLFIRE) +#ifdef HELLFIRE if (gbMaxPlayers > 1) { if (!hellfire) fmt = "\\dlinfo_%d.drv"; @@ -132,11 +127,18 @@ static void pfile_get_save_path(char *pszBuf, DWORD dwBufSize, DWORD save_num) fmt = "\\single_%d.sv"; else fmt = "\\single_%d.hsv"; +#else +#ifdef SPAWN + fmt = "\\share_%d.sv"; + + if (gbMaxPlayers <= 1) + fmt = "\\spawn%d.sv"; #else fmt = "\\multi_%d.sv"; if (gbMaxPlayers <= 1) fmt = "\\single_%d.sv"; +#endif #endif // BUGFIX: ignores dwBufSize and uses MAX_PATH instead @@ -562,14 +564,14 @@ BOOL __stdcall pfile_get_file_name(DWORD lvl, char *dst) return FALSE; fmt = "hero"; } else { - if (lvl < 17) + if (lvl < NUMLEVELS) fmt = "perml%02d"; - else if (lvl < 34) { - lvl -= 17; + else if (lvl < NUMLEVELS * 2) { + lvl -= NUMLEVELS; fmt = "perms%02d"; - } else if (lvl == 34) + } else if (lvl == NUMLEVELS * 2) fmt = "game"; - else if (lvl == 35) + else if (lvl == NUMLEVELS * 2 + 1) fmt = "hero"; else return FALSE; From 5bd15f28db8f706fe57736b805aed1eb1e5f67d2 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Fri, 1 Jan 2021 15:52:54 +0100 Subject: [PATCH 07/11] [hellfire] pfile_read_hero --- Source/pfile.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Source/pfile.cpp b/Source/pfile.cpp index d86a23fb7..7e801dd69 100644 --- a/Source/pfile.cpp +++ b/Source/pfile.cpp @@ -180,12 +180,17 @@ static BOOL pfile_read_hero(HANDLE archive, PkPlayerStruct *pPack) if (!SFileOpenFileEx(archive, "hero", 0, &file)) { return FALSE; } else { + buf = NULL; BOOL ret = FALSE; char password[16] = PASSWORD_SINGLE; nSize = 16; if (gbMaxPlayers > 1) +#ifdef HELLFIRE + GetComputerName(password, &nSize); +#else strcpy(password, PASSWORD_MULTI); +#endif dwlen = SFileGetFileSize(file, NULL); if (dwlen) { @@ -194,6 +199,7 @@ static BOOL pfile_read_hero(HANDLE archive, PkPlayerStruct *pPack) if (SFileReadFile(file, buf, dwlen, &read, NULL)) { decoded = TRUE; read = codec_decode(buf, dwlen, password); +#ifndef HELLFIRE if (!read && gbMaxPlayers > 1) { GetComputerName(password, &nSize); if (SFileSetFilePointer(file, 0, NULL, FILE_BEGIN) || !SFileReadFile(file, buf, dwlen, &read, NULL)) @@ -201,14 +207,15 @@ static BOOL pfile_read_hero(HANDLE archive, PkPlayerStruct *pPack) else read = codec_decode(buf, dwlen, password); } +#endif if (decoded && read == sizeof(*pPack)) { memcpy(pPack, buf, sizeof(*pPack)); ret = TRUE; } } - if (buf) - mem_free_dbg(buf); } + if (buf) + mem_free_dbg(buf); SFileCloseFile(file); return ret; } From 5169c054b63ffe7594726e23f093080186ad9e14 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Fri, 1 Jan 2021 19:14:01 +0100 Subject: [PATCH 08/11] [hellfire] pfile_archive_contains_game --- Source/pfile.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/Source/pfile.cpp b/Source/pfile.cpp index 7e801dd69..e38713499 100644 --- a/Source/pfile.cpp +++ b/Source/pfile.cpp @@ -497,14 +497,56 @@ BOOL pfile_archive_contains_game(HANDLE hsArchive, DWORD save_num) { HANDLE file; +#ifdef HELLFIRE + DWORD read, size; + BOOL ret = FALSE; + gbLoadGame = FALSE; +#endif + if (gbMaxPlayers != 1) return FALSE; if (!SFileOpenFileEx(hsArchive, "game", 0, &file)) return FALSE; +#ifdef HELLFIRE + DWORD dwlen = SFileGetFileSize(file, NULL); + if (!dwlen) + app_fatal("Invalid save file"); + + BYTE *ptr = DiabloAllocPtr(dwlen + 8); + BYTE *buf = ptr + 4; + + if (SFileReadFile(file, buf, dwlen, &read, NULL)) { + if (read == dwlen) { + char password[16] = PASSWORD_SINGLE; + size = 16; + if (gbMaxPlayers > 1) + GetComputerName(password, &size); + gbLoadGame = TRUE; + if (codec_decode(buf, dwlen, password)) { + int magic = *buf << 24; + buf++; + magic |= *buf << 16; + buf++; + magic |= *buf << 8; + buf++; + magic |= *buf; + if (magic == 'HELF') { + ret = TRUE; + } + } + } + } + + if (ptr) + mem_free_dbg(ptr); + SFileCloseFile(file); + return ret; +#else SFileCloseFile(file); return TRUE; +#endif } BOOL __stdcall pfile_ui_set_class_stats(unsigned int player_class_nr, _uidefaultstats *class_stats) From 87c325ef310866e2b7b35363c950cf82ca2b9a0b Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Fri, 1 Jan 2021 19:40:33 +0100 Subject: [PATCH 09/11] [hellfire] pfile_write_save_file --- Source/pfile.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Source/pfile.cpp b/Source/pfile.cpp index e38713499..2b1a28d94 100644 --- a/Source/pfile.cpp +++ b/Source/pfile.cpp @@ -777,20 +777,33 @@ void pfile_rename_temp_to_perm() void pfile_write_save_file(const char *pszName, BYTE *pbData, DWORD dwLen, DWORD qwLen) { DWORD save_num; +#ifndef HELLFIRE char FileName[MAX_PATH]; pfile_strcpy(FileName, pszName); +#endif save_num = pfile_get_save_num_from_name(plr[myplr]._pName); { char password[16] = PASSWORD_SINGLE; +#ifdef HELLFIRE + DWORD size = 16; + if (gbMaxPlayers > 1) + GetComputerName(password, &size); +#else if (gbMaxPlayers > 1) strcpy(password, PASSWORD_MULTI); +#endif codec_encode(pbData, dwLen, qwLen, password); } if (!pfile_open_archive(FALSE, save_num)) +#ifdef HELLFIRE + app_fatal("Unable to write to save file archive"); + mpqapi_write_file(pszName, pbData, qwLen); +#else app_fatal("Unable to write so save file archive"); mpqapi_write_file(FileName, pbData, qwLen); +#endif pfile_flush(TRUE, save_num); } From da908b83f24da7cb0121e9d12d097f5b982effd1 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Fri, 1 Jan 2021 20:43:27 +0100 Subject: [PATCH 10/11] [hellfire] pfile_read --- Source/pfile.cpp | 50 +++++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/Source/pfile.cpp b/Source/pfile.cpp index 2b1a28d94..b4e4faf12 100644 --- a/Source/pfile.cpp +++ b/Source/pfile.cpp @@ -819,48 +819,58 @@ BYTE *pfile_read(const char *pszName, DWORD *pdwLen) HANDLE archive, save; BYTE *buf; +#ifndef HELLFIRE pfile_strcpy(FileName, pszName); +#endif save_num = pfile_get_save_num_from_name(plr[myplr]._pName); archive = pfile_open_save_archive(NULL, save_num); if (archive == NULL) app_fatal("Unable to open save file archive"); +#ifdef HELLFIRE + if (!SFileOpenFileEx(archive, pszName, 0, &save)) +#else if (!SFileOpenFileEx(archive, FileName, 0, &save)) +#endif app_fatal("Unable to open save file"); *pdwLen = SFileGetFileSize(save, NULL); if (*pdwLen == 0) app_fatal("Invalid save file"); - buf = (BYTE *)DiabloAllocPtr(*pdwLen); + buf = DiabloAllocPtr(*pdwLen); if (!SFileReadFile(save, buf, *pdwLen, &nread, NULL)) app_fatal("Unable to read save file"); SFileCloseFile(save); pfile_SFileCloseArchive(archive); + char password[16] = PASSWORD_SINGLE; + DWORD nSize = 16; + + if (gbMaxPlayers > 1) +#ifdef HELLFIRE + GetComputerName(password, &nSize); { - char password[16] = PASSWORD_SINGLE; - DWORD nSize = 16; + { +#else + strcpy(password, PASSWORD_MULTI); - if (gbMaxPlayers > 1) - strcpy(password, PASSWORD_MULTI); + *pdwLen = codec_decode(buf, *pdwLen, password); + if (*pdwLen == 0) { + // BUGFIFX: *pdwLen has already been overwritten with zero and the savefile has been closed + // there is no way this can work correctly + if (gbMaxPlayers > 1) { + GetComputerName(password, &nSize); + if (SFileSetFilePointer(save, 0, NULL, FILE_BEGIN)) + app_fatal("Unable to read save file"); - *pdwLen = codec_decode(buf, *pdwLen, password); - if (*pdwLen == 0) { - // BUGFIFX: *pdwLen has already been overwritten with zero and the savefile has been closed - // there is no way this can work correctly - if (gbMaxPlayers > 1) { - GetComputerName(password, &nSize); - if (SFileSetFilePointer(save, 0, NULL, FILE_BEGIN)) - app_fatal("Unable to read save file"); - - if (!SFileReadFile(save, buf, *pdwLen, &nread, NULL)) - app_fatal("Unable to read save file"); - *pdwLen = codec_decode(buf, *pdwLen, password); - } - if (*pdwLen == 0) - app_fatal("Invalid save file"); + if (!SFileReadFile(save, buf, *pdwLen, &nread, NULL)) + app_fatal("Unable to read save file"); +#endif + *pdwLen = codec_decode(buf, *pdwLen, password); } + if (*pdwLen == 0) + app_fatal("Invalid save file"); } return buf; } From aa154e523116b3b2ce3af628fa1d006bf1bfac52 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Fri, 1 Jan 2021 21:09:25 +0100 Subject: [PATCH 11/11] Clean up LoadMapObjects --- Source/objects.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Source/objects.cpp b/Source/objects.cpp index b212ca42f..b428db65a 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -730,14 +730,15 @@ void AddChestTraps() void LoadMapObjects(BYTE *pMap, int startx, int starty, int x1, int y1, int w, int h, int leveridx) { - int rw, rh, i, j, oi; + int rw, rh, i, j, oi, type; BYTE *lm; long mapoff; InitObjFlag = TRUE; - lm = pMap + 2; - rw = pMap[0]; + lm = pMap; + rw = lm[0]; + lm += 2; rh = *lm; mapoff = (rw * rh + 1) * 2; rw <<= 1; @@ -748,7 +749,8 @@ void LoadMapObjects(BYTE *pMap, int startx, int starty, int x1, int y1, int w, i for (j = 0; j < rh; j++) { for (i = 0; i < rw; i++) { if (*lm) { - AddObject(ObjTypeConv[*lm], startx + 16 + i, starty + 16 + j); + type = lm[0]; + AddObject(ObjTypeConv[type], startx + 16 + i, starty + 16 + j); oi = ObjIndex(startx + 16 + i, starty + 16 + j); SetObjMapRange(oi, x1, y1, x1 + w, y1 + h, leveridx); }