From e2a98b75febb23dfcbbbbc8f7720f9d8e1c9d7da Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sat, 2 Jan 2021 22:34:32 +0100 Subject: [PATCH 1/7] Clean up some magic values --- Source/mpqapi.cpp | 54 +++++++++++++++++++++++++--------------------- Source/objects.cpp | 4 ++-- Source/stores.cpp | 4 ++-- 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/Source/mpqapi.cpp b/Source/mpqapi.cpp index 931f18d31..dd01d5826 100644 --- a/Source/mpqapi.cpp +++ b/Source/mpqapi.cpp @@ -15,6 +15,10 @@ _BLOCKENTRY *sgpBlockTbl; /** Is the savegame-file currently open. */ BOOLEAN save_archive_open; +#define INDEX_ENTRIES 2048 +#define BLOCK_TABLE_SIZE (INDEX_ENTRIES * sizeof(_BLOCKENTRY)) +#define HASH_TABLE_SIZE (INDEX_ENTRIES * sizeof(_HASHENTRY)) + //note: 32872 = 32768 + 104 (sizeof(_FILEHEADER)) /* data */ @@ -159,7 +163,7 @@ static _BLOCKENTRY *mpqapi_new_block(int *block_index) { _BLOCKENTRY *blockEntry = sgpBlockTbl; - for (DWORD i = 0; i < 2048; i++, blockEntry++) { + for (DWORD i = 0; i < INDEX_ENTRIES; i++, blockEntry++) { if (blockEntry->offset != 0) continue; if (blockEntry->sizealloc != 0) @@ -185,7 +189,7 @@ static void mpqapi_alloc_block(int block_offset, int block_size) int i; block = sgpBlockTbl; - i = 2048; + i = INDEX_ENTRIES; while (i-- != 0) { if (block->offset && !block->flags && !block->sizefile) { if (block->offset + block->sizealloc == block_offset) { @@ -223,7 +227,7 @@ static int mpqapi_find_free_block(int size, int *block_size) int result; _BLOCKENTRY *pBlockTbl = sgpBlockTbl; - for (int i = 2048; i--; pBlockTbl++) { + for (int i = INDEX_ENTRIES; i--; pBlockTbl++) { if (pBlockTbl->offset == 0) continue; if (pBlockTbl->flags != 0) @@ -254,7 +258,7 @@ static int mpqapi_get_hash_index(int index, int hash_a, int hash_b, int locale) { DWORD idx, i; - i = 2048; + i = INDEX_ENTRIES; for (idx = index & 0x7FF; sgpHashTbl[idx].block != -1; idx = (idx + 1) & 0x7FF) { if (i-- == 0) break; @@ -286,8 +290,8 @@ static BOOL WriteMPQHeader() fhdr.sectorsizeid = 3; fhdr.hashoffset = 32872; fhdr.blockoffset = 104; - fhdr.hashcount = 2048; - fhdr.blockcount = 2048; + fhdr.hashcount = INDEX_ENTRIES; + fhdr.blockcount = INDEX_ENTRIES; if (SetFilePointer(sghArchive, 0, NULL, FILE_BEGIN) == -1) return FALSE; @@ -305,10 +309,10 @@ static BOOL mpqapi_write_block_table() if (SetFilePointer(sghArchive, 104, NULL, FILE_BEGIN) == -1) return FALSE; - Encrypt((DWORD *)sgpBlockTbl, 0x8000, Hash("(block table)", 3)); - success = WriteFile(sghArchive, sgpBlockTbl, 0x8000, &NumberOfBytesWritten, 0); - Decrypt((DWORD *)sgpBlockTbl, 0x8000, Hash("(block table)", 3)); - return success && NumberOfBytesWritten == 0x8000; + Encrypt((DWORD *)sgpBlockTbl, BLOCK_TABLE_SIZE, Hash("(block table)", 3)); + success = WriteFile(sghArchive, sgpBlockTbl, BLOCK_TABLE_SIZE, &NumberOfBytesWritten, 0); + Decrypt((DWORD *)sgpBlockTbl, BLOCK_TABLE_SIZE, Hash("(block table)", 3)); + return success && NumberOfBytesWritten == BLOCK_TABLE_SIZE; } static BOOL mpqapi_write_hash_table() @@ -319,10 +323,10 @@ static BOOL mpqapi_write_hash_table() if (SetFilePointer(sghArchive, 32872, NULL, FILE_BEGIN) == -1) return FALSE; - Encrypt((DWORD *)sgpHashTbl, 0x8000, Hash("(hash table)", 3)); - success = WriteFile(sghArchive, sgpHashTbl, 0x8000, &NumberOfBytesWritten, 0); - Decrypt((DWORD *)sgpHashTbl, 0x8000, Hash("(hash table)", 3)); - return success && NumberOfBytesWritten == 0x8000; + Encrypt((DWORD *)sgpHashTbl, HASH_TABLE_SIZE, Hash("(hash table)", 3)); + success = WriteFile(sghArchive, sgpHashTbl, HASH_TABLE_SIZE, &NumberOfBytesWritten, 0); + Decrypt((DWORD *)sgpHashTbl, HASH_TABLE_SIZE, Hash("(hash table)", 3)); + return success && NumberOfBytesWritten == HASH_TABLE_SIZE; } static BOOL mpqapi_can_seek() @@ -351,8 +355,8 @@ static BOOL ParseMPQHeader(_FILEHEADER *pHdr, DWORD *pdwNextFileStart) || pHdr->filesize != size || pHdr->hashoffset != 32872 || pHdr->blockoffset != 104 - || pHdr->hashcount != 2048 - || pHdr->blockcount != 2048) { + || pHdr->hashcount != INDEX_ENTRIES + || pHdr->blockcount != INDEX_ENTRIES) { if (SetFilePointer(sghArchive, 0, NULL, FILE_BEGIN) == -1) return FALSE; @@ -418,7 +422,7 @@ static _BLOCKENTRY *mpqapi_add_file(const char *pszName, _BLOCKENTRY *pBlk, int if (mpqapi_get_hash_index(h1, h2, h3, 0) != -1) app_fatal("Hash collision between \"%s\" and existing file\n", pszName); hIdx = h1 & 0x7FF; - i = 2048; + i = INDEX_ENTRIES; while (i--) { if (sgpHashTbl[hIdx].block == -1 || sgpHashTbl[hIdx].block == -2) break; @@ -602,25 +606,25 @@ BOOL OpenMPQ(const char *pszArchive, BOOL hidden, DWORD dwChar) if (ParseMPQHeader(&fhdr, &sgdwMpqOffset) == FALSE) { goto on_error; } - sgpBlockTbl = (_BLOCKENTRY *)DiabloAllocPtr(0x8000); - memset(sgpBlockTbl, 0, 0x8000); + sgpBlockTbl = (_BLOCKENTRY *)DiabloAllocPtr(BLOCK_TABLE_SIZE); + memset(sgpBlockTbl, 0, BLOCK_TABLE_SIZE); if (fhdr.blockcount) { if (SetFilePointer(sghArchive, 104, NULL, FILE_BEGIN) == -1) goto on_error; - if (!ReadFile(sghArchive, sgpBlockTbl, 0x8000, &dwTemp, NULL)) + if (!ReadFile(sghArchive, sgpBlockTbl, BLOCK_TABLE_SIZE, &dwTemp, NULL)) goto on_error; key = Hash("(block table)", 3); - Decrypt((DWORD *)sgpBlockTbl, 0x8000, key); + Decrypt((DWORD *)sgpBlockTbl, BLOCK_TABLE_SIZE, key); } - sgpHashTbl = (_HASHENTRY *)DiabloAllocPtr(0x8000); - memset(sgpHashTbl, 255, 0x8000); + sgpHashTbl = (_HASHENTRY *)DiabloAllocPtr(HASH_TABLE_SIZE); + memset(sgpHashTbl, 255, HASH_TABLE_SIZE); if (fhdr.hashcount) { if (SetFilePointer(sghArchive, 32872, NULL, FILE_BEGIN) == -1) goto on_error; - if (!ReadFile(sghArchive, sgpHashTbl, 0x8000, &dwTemp, NULL)) + if (!ReadFile(sghArchive, sgpHashTbl, HASH_TABLE_SIZE, &dwTemp, NULL)) goto on_error; key = Hash("(hash table)", 3); - Decrypt((DWORD *)sgpHashTbl, 0x8000, key); + Decrypt((DWORD *)sgpHashTbl, HASH_TABLE_SIZE, key); } return TRUE; } diff --git a/Source/objects.cpp b/Source/objects.cpp index b428db65a..f10613d15 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -737,7 +737,7 @@ void LoadMapObjects(BYTE *pMap, int startx, int starty, int x1, int y1, int w, i InitObjFlag = TRUE; lm = pMap; - rw = lm[0]; + rw = *lm; lm += 2; rh = *lm; mapoff = (rw * rh + 1) * 2; @@ -749,7 +749,7 @@ 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) { - type = lm[0]; + type = *lm; 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); diff --git a/Source/stores.cpp b/Source/stores.cpp index 23ffb0bd8..089e4029d 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -98,7 +98,7 @@ void InitStores() numpremium = 0; premiumlevel = 1; - for (i = 0; i < 6; i++) + for (i = 0; i < SMITH_PREMIUM_ITEMS; i++) premiumitem[i]._itype = ITYPE_NONE; boyitem._itype = ITYPE_NONE; @@ -592,7 +592,7 @@ BOOL S_StartSPBuy() int i; storenumh = 0; - for (i = 0; i < 6; i++) { + for (i = 0; i < SMITH_PREMIUM_ITEMS; i++) { if (premiumitem[i]._itype != ITYPE_NONE) storenumh++; } From 7aa7ee738d5745d4a98d4924e38dc21d8176d590 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sat, 2 Jan 2021 23:05:11 +0100 Subject: [PATCH 2/7] Clean up witchitem init --- Source/stores.cpp | 6 +----- Source/stores.h | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/Source/stores.cpp b/Source/stores.cpp index 089e4029d..a4995add8 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -21,11 +21,7 @@ int stextsmax; int InStoreFlag; /** current frame # for the pentagram selector */ ItemStruct storehold[48]; int gossipstart; -#ifdef HELLFIRE -ItemStruct witchitem[25]; -#else -ItemStruct witchitem[20]; -#endif +ItemStruct witchitem[WITCH_ITEMS]; BOOL stextscrl; int numpremium; ItemStruct healitem[20]; diff --git a/Source/stores.h b/Source/stores.h index 50029f924..40b619b51 100644 --- a/Source/stores.h +++ b/Source/stores.h @@ -11,11 +11,7 @@ extern ItemStruct premiumitem[SMITH_PREMIUM_ITEMS]; extern BYTE *pSTextBoxCels; extern int premiumlevel; extern int talker; -#ifdef HELLFIRE -extern ItemStruct witchitem[25]; -#else -extern ItemStruct witchitem[20]; -#endif +extern ItemStruct witchitem[WITCH_ITEMS]; extern int numpremium; extern ItemStruct healitem[20]; extern ItemStruct golditem; From bdebd5f1f5a727a5c84bd54835b8156b493896f2 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sun, 3 Jan 2021 02:35:29 +0100 Subject: [PATCH 3/7] OOB in error.cpp (#1847) --- Source/error.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/error.cpp b/Source/error.cpp index 526c6f5c1..e206a4f1f 100644 --- a/Source/error.cpp +++ b/Source/error.cpp @@ -80,7 +80,7 @@ void InitDiabloMsg(char e) return; } - msgtable[msgcnt] = e; + msgtable[msgcnt] = e; // BUGFIX: missing out-of-bounds check if (msgcnt < (BYTE)sizeof(msgtable)) msgcnt++; From a006a25b621c09d1227d7be1be7e0145e483b2d9 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sun, 3 Jan 2021 03:05:17 +0100 Subject: [PATCH 4/7] Clean up variable names --- Source/diablo.cpp | 2 +- Source/gmenu.cpp | 12 ++++++------ Source/help.cpp | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Source/diablo.cpp b/Source/diablo.cpp index a3f4f319b..3136cc02a 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -456,7 +456,7 @@ BOOL StartGame(BOOL bNewGame, BOOL bSinglePlayer) run_game_loop(uMsg); NetClose(); #ifndef HELLFIRE - pfile_create_player_description(0, 0); + pfile_create_player_description(NULL, 0); #else if (gbMaxPlayers == 1) break; diff --git a/Source/gmenu.cpp b/Source/gmenu.cpp index 863d61b96..9c74405b6 100644 --- a/Source/gmenu.cpp +++ b/Source/gmenu.cpp @@ -16,7 +16,7 @@ BYTE LogoAnim_frame; #endif int PentSpin_tick; BYTE PentSpin_frame; -void (*dword_63447C)(TMenuItem *); +void (*gmenu_current_option)(TMenuItem *); TMenuItem *sgpCurrentMenu; BYTE *option_cel; BYTE *sgpLogo; @@ -89,7 +89,7 @@ void gmenu_init_menu() #endif sgpCurrentMenu = NULL; sgpCurrItem = NULL; - dword_63447C = NULL; + gmenu_current_option = NULL; sgCurrentMenuIdx = 0; mouseNavigation = FALSE; #ifdef HELLFIRE @@ -145,9 +145,9 @@ void gmenu_set_items(TMenuItem *pItem, void (*gmFunc)(TMenuItem *)) PauseMode = 0; mouseNavigation = FALSE; sgpCurrentMenu = pItem; - dword_63447C = gmFunc; + gmenu_current_option = gmFunc; if (gmFunc) { - dword_63447C(sgpCurrentMenu); + gmenu_current_option(sgpCurrentMenu); pItem = sgpCurrentMenu; } sgCurrentMenuIdx = 0; @@ -231,8 +231,8 @@ void gmenu_draw() DWORD ticks; if (sgpCurrentMenu) { - if (dword_63447C) - dword_63447C(sgpCurrentMenu); + if (gmenu_current_option) + gmenu_current_option(sgpCurrentMenu); #ifdef HELLFIRE ticks = GetTickCount(); if ((int)(ticks - LogoAnim_tick) > 25) { diff --git a/Source/help.cpp b/Source/help.cpp index b7194e613..3a04354ff 100644 --- a/Source/help.cpp +++ b/Source/help.cpp @@ -6,7 +6,7 @@ #include "all.h" int help_select_line; -int dword_634494; +int unused_help; BOOL helpflag; int displayinghelp[22]; /* check, does nothing? */ int HelpTop; @@ -443,7 +443,7 @@ const char gszHelpText[] = { void InitHelp() { helpflag = FALSE; - dword_634494 = 0; + unused_help = 0; displayinghelp[0] = 0; } From 67923c4c6062be55de4e880724c1e82de073f587 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Mon, 4 Jan 2021 02:08:18 +0100 Subject: [PATCH 5/7] [hellfire] SyncObjectAnim --- Source/objects.cpp | 49 +++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/Source/objects.cpp b/Source/objects.cpp index f10613d15..82d85c69f 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -5210,14 +5210,15 @@ void SyncObjectAnim(int o) void GetObjectStr(int i) { switch (object[i]._otype) { + case OBJ_CRUX1: + case OBJ_CRUX2: + case OBJ_CRUX3: + strcpy(infostr, "Crucified Skeleton"); + break; case OBJ_LEVER: case OBJ_FLAMELVR: strcpy(infostr, "Lever"); break; - case OBJ_CHEST1: - case OBJ_TCHEST1: - strcpy(infostr, "Small Chest"); - break; case OBJ_L1LDOOR: case OBJ_L1RDOOR: case OBJ_L2LDOOR: @@ -5246,7 +5247,10 @@ void GetObjectStr(int i) case OBJ_BOOK2R: strcpy(infostr, "Mythical Book"); break; - + case OBJ_CHEST1: + case OBJ_TCHEST1: + strcpy(infostr, "Small Chest"); + break; case OBJ_CHEST2: case OBJ_TCHEST2: strcpy(infostr, "Chest"); @@ -5256,39 +5260,34 @@ void GetObjectStr(int i) case OBJ_SIGNCHEST: strcpy(infostr, "Large Chest"); break; - case OBJ_CRUX1: - case OBJ_CRUX2: - case OBJ_CRUX3: - strcpy(infostr, "Crucified Skeleton"); - break; case OBJ_SARC: strcpy(infostr, "Sarcophagus"); break; case OBJ_BOOKSHELF: strcpy(infostr, "Bookshelf"); break; + case OBJ_BOOKCASEL: + case OBJ_BOOKCASER: + strcpy(infostr, "Bookcase"); + break; case OBJ_BARREL: case OBJ_BARRELEX: #ifdef HELLFIRE - if (currlevel > 16 && currlevel < 21) // for hive levels - strcpy(infostr, "Pod"); //Then a barrel is called a pod - else if (currlevel > 20 && currlevel < 25) // for crypt levels - strcpy(infostr, "Urn"); //Then a barrel is called an urn + if (currlevel >= 17 && currlevel <= 20) // for hive levels + strcpy(infostr, "Pod"); //Then a barrel is called a pod + else if (currlevel >= 21 && currlevel <= 24) // for crypt levels + strcpy(infostr, "Urn"); //Then a barrel is called an urn else #endif strcpy(infostr, "Barrel"); break; - case OBJ_SKELBOOK: - strcpy(infostr, "Skeleton Tome"); - break; case OBJ_SHRINEL: case OBJ_SHRINER: sprintf(tempstr, "%s Shrine", shrinestrs[object[i]._oVar1]); strcpy(infostr, tempstr); break; - case OBJ_BOOKCASEL: - case OBJ_BOOKCASER: - strcpy(infostr, "Bookcase"); + case OBJ_SKELBOOK: + strcpy(infostr, "Skeleton Tome"); break; case OBJ_BOOKSTAND: strcpy(infostr, "Library Book"); @@ -5305,9 +5304,6 @@ void GetObjectStr(int i) case OBJ_BLOODBOOK: strcpy(infostr, "Book of Blood"); break; - case OBJ_PEDISTAL: - strcpy(infostr, "Pedestal of Blood"); - break; case OBJ_PURIFYINGFTN: strcpy(infostr, "Purifying Spring"); break; @@ -5315,6 +5311,9 @@ void GetObjectStr(int i) case OBJ_WARARMOR: strcpy(infostr, "Armor"); break; + case OBJ_WARWEAP: + strcpy(infostr, "Weapon Rack"); + break; case OBJ_GOATSHRINE: strcpy(infostr, "Goat Shrine"); break; @@ -5330,10 +5329,12 @@ void GetObjectStr(int i) case OBJ_STEELTOME: strcpy(infostr, "Steel Tome"); break; + case OBJ_PEDISTAL: + strcpy(infostr, "Pedestal of Blood"); + break; case OBJ_STORYBOOK: strcpy(infostr, StoryBookName[object[i]._oVar3]); break; - case OBJ_WARWEAP: case OBJ_WEAPONRACK: strcpy(infostr, "Weapon Rack"); break; From 201df84849b18025b33907a761448a4a15976f40 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Mon, 4 Jan 2021 18:59:26 +0100 Subject: [PATCH 6/7] Clean up OperateShrine (#2193) --- Source/objects.cpp | 95 +++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 48 deletions(-) diff --git a/Source/objects.cpp b/Source/objects.cpp index 82d85c69f..174fa208b 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -3514,7 +3514,7 @@ void OperateShrine(int pnum, int i, int sType) DWORD lv, t; int xx, yy; int v1, v2, v3, v4; - unsigned __int64 spell, spells; + unsigned __int64 spell; if (dropGoldFlag) { dropGoldFlag = FALSE; @@ -3534,8 +3534,8 @@ void OperateShrine(int pnum, int i, int sType) object[i]._oAnimFlag = 1; object[i]._oAnimDelay = 1; } else { - object[i]._oAnimFlag = 0; object[i]._oAnimFrame = object[i]._oAnimLen; + object[i]._oAnimFlag = 0; } switch (object[i]._oVar1) { case SHRINE_MYSTERIOUS: @@ -3588,10 +3588,12 @@ void OperateShrine(int pnum, int i, int sType) while (TRUE) { cnt = 0; for (j = 0; j < NUM_INVLOC; j++) { - if (plr[pnum].InvBody[j]._itype != ITYPE_NONE - && plr[pnum].InvBody[j]._iMaxDur != DUR_INDESTRUCTIBLE - && plr[pnum].InvBody[j]._iMaxDur != 0) - cnt++; + if (plr[pnum].InvBody[j]._itype != ITYPE_NONE) +#ifndef HELLFIRE + if (plr[pnum].InvBody[j]._iMaxDur != DUR_INDESTRUCTIBLE + && plr[pnum].InvBody[j]._iMaxDur != 0) +#endif + cnt++; } if (cnt == 0) break; @@ -3649,8 +3651,8 @@ void OperateShrine(int pnum, int i, int sType) plr[pnum].InvList[j]._iMaxDam = plr[pnum].InvList[j]._iMinDam; break; case ITYPE_SHIELD: - case ITYPE_LARMOR: case ITYPE_HELM: + case ITYPE_LARMOR: case ITYPE_MARMOR: case ITYPE_HARMOR: plr[pnum].InvList[j]._iAC += 2; @@ -3743,9 +3745,8 @@ void OperateShrine(int pnum, int i, int sType) return; cnt = 0; spell = 1; - spells = plr[pnum]._pMemSpells; for (j = 0; j < MAX_SPELLS; j++) { - if (spell & spells) + if (spell & plr[pnum]._pMemSpells) cnt++; spell <<= 1; } @@ -3761,10 +3762,10 @@ void OperateShrine(int pnum, int i, int sType) do { r = random_(0, MAX_SPELLS); } while (!(plr[pnum]._pMemSpells & SPELLBIT(r + 1))); - if (plr[pnum]._pSplLvl[r] >= 2) - plr[pnum]._pSplLvl[r] -= 2; + if (plr[pnum]._pSplLvl[r + 1] >= 2) + plr[pnum]._pSplLvl[r + 1] -= 2; else - plr[pnum]._pSplLvl[r] = 0; + plr[pnum]._pSplLvl[r + 1] = 0; } InitDiabloMsg(EMSG_SHRINE_ENCHANTED); break; @@ -3777,8 +3778,8 @@ void OperateShrine(int pnum, int i, int sType) || object[v1]._otype == OBJ_CHEST3) && object[v1]._oSelFlag == 0) { object[v1]._oRndSeed = GetRndSeed(); - object[v1]._oAnimFrame -= 2; object[v1]._oSelFlag = 1; + object[v1]._oAnimFrame -= 2; } } if (deltaload) @@ -3805,12 +3806,12 @@ void OperateShrine(int pnum, int i, int sType) plr[pnum]._pMaxMana -= t; plr[pnum]._pMaxManaBase -= t; if (plr[pnum]._pMana >> 6 <= 0) { - plr[pnum]._pManaBase = 0; plr[pnum]._pMana = v1; + plr[pnum]._pManaBase = 0; } if (plr[pnum]._pMaxMana >> 6 <= 0) { - plr[pnum]._pMaxManaBase = 0; plr[pnum]._pMaxMana = v2; + plr[pnum]._pMaxManaBase = 0; } InitDiabloMsg(EMSG_SHRINE_FASCINATING); break; @@ -3911,10 +3912,10 @@ void OperateShrine(int pnum, int i, int sType) do { xx = random_(159, MAXDUNX); yy = random_(159, MAXDUNY); + lv = dPiece[xx][yy]; j++; - if (j > MAXDUNX * 112) + if (j > MAXDUNX * MAXDUNY) break; - lv = dPiece[xx][yy]; } while (nSolidTable[lv] || dObject[xx][yy] != 0 || dMonster[xx][yy] != 0); AddMissile(plr[pnum]._px, plr[pnum]._py, xx, yy, plr[pnum]._pdir, MIS_RNDTELEPORT, -1, pnum, 0, 2 * leveltype); if (pnum != myplr) @@ -4120,6 +4121,9 @@ void OperateShrine(int pnum, int i, int sType) case PC_SORCERER: ModifyPlrMag(myplr, 2); break; + case PC_BARBARIAN: + ModifyPlrVit(myplr, 2); + break; case PC_MONK: ModifyPlrStr(myplr, 1); ModifyPlrDex(myplr, 1); @@ -4128,11 +4132,8 @@ void OperateShrine(int pnum, int i, int sType) ModifyPlrDex(myplr, 1); ModifyPlrMag(myplr, 1); break; - case PC_BARBARIAN: - ModifyPlrVit(myplr, 2); - break; } - CheckStats(myplr); + CheckStats(pnum); AddMissile( object[i]._ox, object[i]._oy, @@ -4158,24 +4159,25 @@ void OperateShrine(int pnum, int i, int sType) magicGain = 5; xpLoss = (signed __int64)((double)playerXP * 0.95); } else { - xpLoss = 0; magicGain = playerXP / 1000; + xpLoss = 0; } ModifyPlrMag(myplr, magicGain); plr[myplr]._pExperience = xpLoss; - CheckStats(myplr); + CheckStats(pnum); } break; - case SHRINE_MENDICANT: + case SHRINE_MENDICANT: { if (deltaload) return; if (pnum != myplr) return; InitDiabloMsg(EMSG_SHRINE_MENDICANT); - AddPlrExperience(myplr, plr[myplr]._pLevel, plr[myplr]._pGold / 2); - TakePlrsMoney(plr[myplr]._pGold / 2); - CheckStats(myplr); - break; + int gold = plr[myplr]._pGold / 2; + AddPlrExperience(myplr, plr[myplr]._pLevel, gold); + TakePlrsMoney(gold); + CheckStats(pnum); + } break; case SHRINE_SPARKLING: if (deltaload) return; @@ -4194,7 +4196,7 @@ void OperateShrine(int pnum, int i, int sType) 0, 3 * currlevel + 2, 0); - CheckStats(myplr); + CheckStats(pnum); break; case SHRINE_TOWN: if (deltaload) @@ -4220,8 +4222,8 @@ void OperateShrine(int pnum, int i, int sType) if (pnum != myplr) return; InitDiabloMsg(EMSG_SHRINE_SHIMMERING); - plr[myplr]._pMana = plr[myplr]._pMaxMana; - plr[myplr]._pManaBase = plr[myplr]._pMaxManaBase; + plr[pnum]._pMana = plr[pnum]._pMaxMana; + plr[pnum]._pManaBase = plr[pnum]._pMaxManaBase; break; case SHRINE_SOLAR: { @@ -4234,21 +4236,17 @@ void OperateShrine(int pnum, int i, int sType) if (hour > 20 || hour < 4) { InitDiabloMsg(EMSG_SHRINE_SOLAR4); ModifyPlrVit(myplr, 2); - } else if (hour <= 18) { - if (hour <= 12) { - if (hour > 4) { - InitDiabloMsg(EMSG_SHRINE_SOLAR1); - ModifyPlrDex(myplr, 2); - } - } else { - InitDiabloMsg(EMSG_SHRINE_SOLAR2); - ModifyPlrStr(myplr, 2); - } - } else { + } else if (hour > 18) { InitDiabloMsg(EMSG_SHRINE_SOLAR3); ModifyPlrMag(myplr, 2); + } else if (hour > 12) { + InitDiabloMsg(EMSG_SHRINE_SOLAR2); + ModifyPlrStr(myplr, 2); + } else if (hour > 4) { + InitDiabloMsg(EMSG_SHRINE_SOLAR1); + ModifyPlrDex(myplr, 2); } - CheckStats(myplr); + CheckStats(pnum); } break; case SHRINE_MURPHYS: @@ -4257,12 +4255,13 @@ void OperateShrine(int pnum, int i, int sType) if (pnum != myplr) return; InitDiabloMsg(EMSG_SHRINE_MURPHYS); - BOOLEAN broke = FALSE; + BOOL broke = FALSE; for (int j = 0; j < NUM_INVLOC; j++) { - if (plr[pnum].InvBody[j]._itype != ITYPE_NONE && random_(0, 3) == 0) { - if (plr[pnum].InvBody[j]._iDurability != DUR_INDESTRUCTIBLE) { - if (plr[pnum].InvBody[j]._iDurability) { - plr[pnum].InvBody[j]._iDurability /= 2; + ItemStruct *item = &plr[myplr].InvBody[j]; + if (item->_itype != ITYPE_NONE && random_(0, 3) == 0) { + if (item->_iDurability != DUR_INDESTRUCTIBLE) { + if (item->_iDurability) { + item->_iDurability /= 2; broke = TRUE; break; } From 2467a982a16800b06f98d3112e09be9d7e36b601 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Mon, 4 Jan 2021 00:41:16 +0100 Subject: [PATCH 7/7] [hellfire] SyncL1Doors --- Source/objects.cpp | 50 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/Source/objects.cpp b/Source/objects.cpp index 174fa208b..1da7f3b24 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -5040,25 +5040,49 @@ void SyncL1Doors(int i) object[i]._oMissFlag = FALSE; return; } +#ifdef HELLFIRE + else +#endif + object[i]._oMissFlag = TRUE; x = object[i]._ox; y = object[i]._oy; - object[i]._oMissFlag = TRUE; object[i]._oSelFlag = 2; - if (object[i]._otype == OBJ_L1LDOOR) { - if (object[i]._oVar1 == 214) - ObjSetMicro(x, y, 408); - else - ObjSetMicro(x, y, 393); - dSpecial[x][y] = 7; - objects_set_door_piece(x - 1, y); - y--; +#ifdef HELLFIRE + if (currlevel < 17) { +#endif + if (object[i]._otype == OBJ_L1LDOOR) { + if (object[i]._oVar1 == 214) + ObjSetMicro(x, y, 408); + else + ObjSetMicro(x, y, 393); + dSpecial[x][y] = 7; + objects_set_door_piece(x - 1, y); + y--; + } else { + ObjSetMicro(x, y, 395); +#ifdef HELLFIRE + if (currlevel < 17) +#endif + dSpecial[x][y] = 8; + objects_set_door_piece(x, y - 1); + x--; + } +#ifdef HELLFIRE } else { - ObjSetMicro(x, y, 395); - dSpecial[x][y] = 8; - objects_set_door_piece(x, y - 1); - x--; + if (object[i]._otype == OBJ_L1LDOOR) { + ObjSetMicro(x, y, 206); + dSpecial[x][y] = 1; + objects_set_door_piece(x - 1, y); + y--; + } else { + ObjSetMicro(x, y, 209); + dSpecial[x][y] = 2; + objects_set_door_piece(x, y - 1); + x--; + } } +#endif DoorSet(i, x, y); }