Skip to content

Commit 176819a

Browse files
authored
Make RecreateItem() take whole dwBuff flag as argument (diasurgical#7870)
1 parent 92e6d36 commit 176819a

6 files changed

Lines changed: 9 additions & 10 deletions

File tree

Source/inv.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,7 +1875,7 @@ int SyncDropItem(Point position, _item_indexes idx, uint16_t icreateinfo, int is
18751875

18761876
Item item;
18771877

1878-
RecreateItem(*MyPlayer, item, idx, icreateinfo, iseed, ivalue, (ibuff & CF_HELLFIRE) != 0);
1878+
RecreateItem(*MyPlayer, item, idx, icreateinfo, iseed, ivalue, ibuff);
18791879
if (id != 0)
18801880
item._iIdentified = true;
18811881
item._iMaxDur = mdur;
@@ -1886,7 +1886,6 @@ int SyncDropItem(Point position, _item_indexes idx, uint16_t icreateinfo, int is
18861886
item._iPLToHit = ClampToHit(item, toHit);
18871887
item._iMaxDam = ClampMaxDam(item, maxDam);
18881888
}
1889-
item.dwBuff = ibuff;
18901889

18911890
return PlaceItemInWorld(std::move(item), position);
18921891
}

Source/items.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3509,10 +3509,11 @@ void CreateTypeItem(Point position, bool onlygood, ItemType itemType, int imisc,
35093509
SetupBaseItem(position, idx, onlygood, sendmsg, delta, spawn);
35103510
}
35113511

3512-
void RecreateItem(const Player &player, Item &item, _item_indexes idx, uint16_t icreateinfo, uint32_t iseed, int ivalue, bool isHellfire)
3512+
void RecreateItem(const Player &player, Item &item, _item_indexes idx, uint16_t icreateinfo, uint32_t iseed, int ivalue, uint32_t dwBuff)
35133513
{
35143514
bool tmpIsHellfire = gbIsHellfire;
3515-
gbIsHellfire = isHellfire;
3515+
item.dwBuff = dwBuff;
3516+
gbIsHellfire = (item.dwBuff & CF_HELLFIRE) != 0;
35163517

35173518
if (idx == IDI_GOLD) {
35183519
InitializeItem(item, IDI_GOLD);

Source/items.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ void SpawnItem(Monster &monster, Point position, bool sendmsg, bool spawn = fals
531531
void CreateRndItem(Point position, bool onlygood, bool sendmsg, bool delta);
532532
void CreateRndUseful(Point position, bool sendmsg);
533533
void CreateTypeItem(Point position, bool onlygood, ItemType itemType, int imisc, bool sendmsg, bool delta, bool spawn = false);
534-
void RecreateItem(const Player &player, Item &item, _item_indexes idx, uint16_t icreateinfo, uint32_t iseed, int ivalue, bool isHellfire);
534+
void RecreateItem(const Player &player, Item &item, _item_indexes idx, uint16_t icreateinfo, uint32_t iseed, int ivalue, uint32_t dwBuff);
535535
void RecreateEar(Item &item, uint16_t ic, uint32_t iseed, uint8_t bCursval, std::string_view heroName);
536536
void CornerstoneSave();
537537
void CornerstoneLoad(Point position);

Source/loadsave.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ void LoadMatchingItems(LoadHelper &file, const Player &player, const int n, Item
10091009
// game's item generation logic before attempting to use it for validation
10101010
if ((heroItem.dwBuff & CF_HELLFIRE) != (unpackedItem.dwBuff & CF_HELLFIRE)) {
10111011
unpackedItem = {};
1012-
RecreateItem(player, unpackedItem, heroItem.IDidx, heroItem._iCreateInfo, heroItem._iSeed, heroItem._ivalue, (heroItem.dwBuff & CF_HELLFIRE) != 0);
1012+
RecreateItem(player, unpackedItem, heroItem.IDidx, heroItem._iCreateInfo, heroItem._iSeed, heroItem._ivalue, heroItem.dwBuff);
10131013
unpackedItem._iIdentified = heroItem._iIdentified;
10141014
unpackedItem._iMaxDur = heroItem._iMaxDur;
10151015
unpackedItem._iDurability = ClampDurability(unpackedItem, heroItem._iDurability);

Source/msg.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2429,10 +2429,9 @@ void PrepareEarForNetwork(const Item &item, TEar &ear)
24292429
void RecreateItem(const Player &player, const TItem &messageItem, Item &item)
24302430
{
24312431
const uint32_t dwBuff = SDL_SwapLE32(messageItem.dwBuff);
2432-
item.dwBuff = dwBuff;
24332432
RecreateItem(player, item,
24342433
static_cast<_item_indexes>(SDL_SwapLE16(messageItem.wIndx)), SDL_SwapLE16(messageItem.wCI),
2435-
SDL_SwapLE32(messageItem.dwSeed), SDL_SwapLE16(messageItem.wValue), (dwBuff & CF_HELLFIRE) != 0);
2434+
SDL_SwapLE32(messageItem.dwSeed), SDL_SwapLE16(messageItem.wValue), dwBuff);
24362435
if (messageItem.bId != 0)
24372436
item._iIdentified = true;
24382437
item._iMaxDur = messageItem.bMDur;

Source/pack.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,8 @@ void UnPackItem(const ItemPack &packedItem, const Player &player, Item &item, bo
334334
item = {};
335335
// Item generation logic will assign CF_HELLFIRE based on isHellfire
336336
// so if we carry it over from packedItem, it may be incorrect
337-
item.dwBuff = SDL_SwapLE32(packedItem.dwBuff) & ~CF_HELLFIRE;
338-
RecreateItem(player, item, idx, SDL_SwapLE16(packedItem.iCreateInfo), SDL_SwapLE32(packedItem.iSeed), SDL_SwapLE16(packedItem.wValue), isHellfire);
337+
const uint32_t dwBuff = SDL_SwapLE32(packedItem.dwBuff) | (isHellfire ? CF_HELLFIRE : 0);
338+
RecreateItem(player, item, idx, SDL_SwapLE16(packedItem.iCreateInfo), SDL_SwapLE32(packedItem.iSeed), SDL_SwapLE16(packedItem.wValue), dwBuff);
339339
item._iIdentified = (packedItem.bId & 1) != 0;
340340
item._iMaxDur = packedItem.bMDur;
341341
item._iDurability = ClampDurability(item, packedItem.bDur);

0 commit comments

Comments
 (0)