From 3a7ae732cdb49d614e3e7716f67c8b9e70463368 Mon Sep 17 00:00:00 2001 From: ephphatha Date: Sat, 6 May 2023 17:14:03 +1000 Subject: [PATCH] use unsigned types for item seeds --- Source/inv.cpp | 6 +++--- Source/inv.h | 6 +++--- Source/items.cpp | 12 ++++++------ Source/items.h | 16 ++++++++-------- Source/loadsave.cpp | 4 ++-- Source/msg.cpp | 8 ++++---- Source/msg.h | 6 +++--- 7 files changed, 29 insertions(+), 29 deletions(-) diff --git a/Source/inv.cpp b/Source/inv.cpp index 28c6c725a..0d42872ac 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -1669,7 +1669,7 @@ void AutoGetItem(Player &player, Item *itemPointer, int ii) NetSendCmdPItem(true, CMD_RESPAWNITEM, item.position, item); } -int FindGetItem(int32_t iseed, _item_indexes idx, uint16_t createInfo) +int FindGetItem(uint32_t iseed, _item_indexes idx, uint16_t createInfo) { for (uint8_t i = 0; i < ActiveItemCount; i++) { auto &item = Items[ActiveItems[i]]; @@ -1681,7 +1681,7 @@ int FindGetItem(int32_t iseed, _item_indexes idx, uint16_t createInfo) return -1; } -void SyncGetItem(Point position, int32_t iseed, _item_indexes idx, uint16_t ci) +void SyncGetItem(Point position, uint32_t iseed, _item_indexes idx, uint16_t ci) { // Check what the local client has at the target position int ii = dItem[position.x][position.y] - 1; @@ -1801,7 +1801,7 @@ int SyncDropItem(Point position, _item_indexes idx, uint16_t icreateinfo, int is return ii; } -int SyncDropEar(Point position, uint16_t icreateinfo, int iseed, uint8_t cursval, string_view heroname) +int SyncDropEar(Point position, uint16_t icreateinfo, uint32_t iseed, uint8_t cursval, string_view heroname) { if (ActiveItemCount >= MAXITEMS) return -1; diff --git a/Source/inv.h b/Source/inv.h index 9ac4f7973..972806aa5 100644 --- a/Source/inv.h +++ b/Source/inv.h @@ -208,8 +208,8 @@ void AutoGetItem(Player &player, Item *itemPointer, int ii); * @param ci Flags used to describe the specific subtype of the target item * @return An index into ActiveItems or -1 if no matching item was found */ -int FindGetItem(int32_t iseed, _item_indexes idx, uint16_t ci); -void SyncGetItem(Point position, int32_t iseed, _item_indexes idx, uint16_t ci); +int FindGetItem(uint32_t iseed, _item_indexes idx, uint16_t ci); +void SyncGetItem(Point position, uint32_t iseed, _item_indexes idx, uint16_t ci); /** * @brief Checks if the tile has room for an item @@ -220,7 +220,7 @@ bool CanPut(Point position); int InvPutItem(const Player &player, Point position, const Item &item); int SyncDropItem(Point position, _item_indexes idx, uint16_t icreateinfo, int iseed, int id, int dur, int mdur, int ch, int mch, int ivalue, uint32_t ibuff, int toHit, int maxDam, int minStr, int minMag, int minDex, int ac); -int SyncDropEar(Point position, uint16_t icreateinfo, int iseed, uint8_t cursval, string_view heroname); +int SyncDropEar(Point position, uint16_t icreateinfo, uint32_t iseed, uint8_t cursval, string_view heroname); int8_t CheckInvHLight(); bool CanUseScroll(Player &player, SpellID spell); void ConsumeStaffCharge(Player &player); diff --git a/Source/items.cpp b/Source/items.cpp index bd67a9a80..8ea29bb73 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -1517,7 +1517,7 @@ int GetItemBLevel(int lvl, item_misc_id miscId, bool onlygood, bool uper15) return iblvl; } -void SetupAllItems(const Player &player, Item &item, _item_indexes idx, int iseed, int lvl, int uper, bool onlygood, bool recreate, bool pregen) +void SetupAllItems(const Player &player, Item &item, _item_indexes idx, uint32_t iseed, int lvl, int uper, bool onlygood, bool recreate, bool pregen) { item._iSeed = iseed; SetRndSeed(iseed); @@ -3301,7 +3301,7 @@ void CreateTypeItem(Point position, bool onlygood, ItemType itemType, int imisc, SetupBaseItem(position, idx, onlygood, sendmsg, delta); } -void RecreateItem(const Player &player, Item &item, _item_indexes idx, uint16_t icreateinfo, int iseed, int ivalue, bool isHellfire) +void RecreateItem(const Player &player, Item &item, _item_indexes idx, uint16_t icreateinfo, uint32_t iseed, int ivalue, bool isHellfire) { bool tmpIsHellfire = gbIsHellfire; gbIsHellfire = isHellfire; @@ -3353,7 +3353,7 @@ void RecreateItem(const Player &player, Item &item, _item_indexes idx, uint16_t gbIsHellfire = tmpIsHellfire; } -void RecreateEar(Item &item, uint16_t ic, int iseed, uint8_t bCursval, string_view heroName) +void RecreateEar(Item &item, uint16_t ic, uint32_t iseed, uint8_t bCursval, string_view heroName) { InitializeItem(item, IDI_EAR); @@ -4509,7 +4509,7 @@ void CreateMagicWeapon(Point position, ItemType itemType, int icurs, bool sendms CreateMagicItem(position, curlv, itemType, imid, icurs, sendmsg, delta); } -bool GetItemRecord(int nSeed, uint16_t wCI, int nIndex) +bool GetItemRecord(uint32_t nSeed, uint16_t wCI, int nIndex) { uint32_t ticks = SDL_GetTicks(); @@ -4526,7 +4526,7 @@ bool GetItemRecord(int nSeed, uint16_t wCI, int nIndex) return true; } -void SetItemRecord(int nSeed, uint16_t wCI, int nIndex) +void SetItemRecord(uint32_t nSeed, uint16_t wCI, int nIndex) { uint32_t ticks = SDL_GetTicks(); @@ -4541,7 +4541,7 @@ void SetItemRecord(int nSeed, uint16_t wCI, int nIndex) gnNumGetRecords++; } -void PutItemRecord(int nSeed, uint16_t wCI, int nIndex) +void PutItemRecord(uint32_t nSeed, uint16_t wCI, int nIndex) { uint32_t ticks = SDL_GetTicks(); diff --git a/Source/items.h b/Source/items.h index 832fcc0c9..d991d6aeb 100644 --- a/Source/items.h +++ b/Source/items.h @@ -177,7 +177,7 @@ struct Player; struct Item { /** Randomly generated identifier */ - int32_t _iSeed = 0; + uint32_t _iSeed = 0; uint16_t _iCreateInfo = 0; ItemType _itype = ItemType::None; bool _iAnimFlag = false; @@ -416,7 +416,7 @@ struct Item { [[nodiscard]] bool isUsable() const; - [[nodiscard]] bool keyAttributesMatch(int32_t seed, _item_indexes itemIndex, uint16_t createInfo) const + [[nodiscard]] bool keyAttributesMatch(uint32_t seed, _item_indexes itemIndex, uint16_t createInfo) const { return _iSeed == seed && IDidx == itemIndex && _iCreateInfo == createInfo; } @@ -457,7 +457,7 @@ struct Item { }; struct ItemGetRecordStruct { - int32_t nSeed; + uint32_t nSeed; uint16_t wCI; int nIndex; uint32_t dwTimestamp; @@ -507,8 +507,8 @@ void SpawnItem(Monster &monster, Point position, bool sendmsg); void CreateRndItem(Point position, bool onlygood, bool sendmsg, bool delta); void CreateRndUseful(Point position, bool sendmsg); void CreateTypeItem(Point position, bool onlygood, ItemType itemType, int imisc, bool sendmsg, bool delta); -void RecreateItem(const Player &player, Item &item, _item_indexes idx, uint16_t icreateinfo, int iseed, int ivalue, bool isHellfire); -void RecreateEar(Item &item, uint16_t ic, int iseed, uint8_t bCursval, string_view heroName); +void RecreateItem(const Player &player, Item &item, _item_indexes idx, uint16_t icreateinfo, uint32_t iseed, int ivalue, bool isHellfire); +void RecreateEar(Item &item, uint16_t ic, uint32_t iseed, uint8_t bCursval, string_view heroName); void CornerstoneSave(); void CornerstoneLoad(Point position); void SpawnQuestItem(_item_indexes itemid, Point position, int randarea, int selflag, bool sendmsg); @@ -544,9 +544,9 @@ void CreateSpellBook(Point position, SpellID ispell, bool sendmsg, bool delta); void CreateMagicArmor(Point position, ItemType itemType, int icurs, bool sendmsg, bool delta); void CreateAmulet(Point position, int lvl, bool sendmsg, bool delta); void CreateMagicWeapon(Point position, ItemType itemType, int icurs, bool sendmsg, bool delta); -bool GetItemRecord(int nSeed, uint16_t wCI, int nIndex); -void SetItemRecord(int nSeed, uint16_t wCI, int nIndex); -void PutItemRecord(int nSeed, uint16_t wCI, int nIndex); +bool GetItemRecord(uint32_t nSeed, uint16_t wCI, int nIndex); +void SetItemRecord(uint32_t nSeed, uint16_t wCI, int nIndex); +void PutItemRecord(uint32_t nSeed, uint16_t wCI, int nIndex); /** * @brief Resets item get records. diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index c895f598b..12f220daa 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -231,7 +231,7 @@ public: void LoadItemData(LoadHelper &file, Item &item) { - item._iSeed = file.NextLE(); + item._iSeed = file.NextLE(); item._iCreateInfo = file.NextLE(); file.Skip(2); // Alignment item._itype = static_cast(file.NextLE()); @@ -1000,7 +1000,7 @@ void SaveItem(SaveHelper &file, const Item &item) iType = ItemType::None; } - file.WriteLE(item._iSeed); + file.WriteLE(item._iSeed); file.WriteLE(item._iCreateInfo); file.Skip(2); // Alignment file.WriteLE(static_cast(iType)); diff --git a/Source/msg.cpp b/Source/msg.cpp index fc3202116..7b9cfa3ef 100644 --- a/Source/msg.cpp +++ b/Source/msg.cpp @@ -1136,7 +1136,7 @@ size_t OnRequestGetItem(const TCmd *pCmd, Player &player) if (gbBufferMsgs != 1 && IOwnLevel(player) && IsGItemValid(message)) { const Point position { message.x, message.y }; - const int32_t dwSeed = SDL_SwapLE32(message.def.dwSeed); + const uint32_t dwSeed = SDL_SwapLE32(message.def.dwSeed); const uint16_t wCI = SDL_SwapLE16(message.def.wCI); const _item_indexes wIndx = static_cast<_item_indexes>(SDL_SwapLE16(message.def.wIndx)); if (GetItemRecord(dwSeed, wCI, wIndx)) { @@ -1180,7 +1180,7 @@ size_t OnGetItem(const TCmd *pCmd, size_t pnum) SendPacket(pnum, &message, sizeof(message)); } else if (IsGItemValid(message)) { const Point position { message.x, message.y }; - const int32_t dwSeed = SDL_SwapLE32(message.def.dwSeed); + const uint32_t dwSeed = SDL_SwapLE32(message.def.dwSeed); const uint16_t wCI = SDL_SwapLE16(message.def.wCI); const _item_indexes wIndx = static_cast<_item_indexes>(SDL_SwapLE16(message.def.wIndx)); if (DeltaGetItem(message, message.bLevel)) { @@ -1228,7 +1228,7 @@ size_t OnRequestAutoGetItem(const TCmd *pCmd, Player &player) if (gbBufferMsgs != 1 && IOwnLevel(player) && IsGItemValid(message)) { const Point position { message.x, message.y }; - const int32_t dwSeed = SDL_SwapLE32(message.def.dwSeed); + const uint32_t dwSeed = SDL_SwapLE32(message.def.dwSeed); const uint16_t wCI = SDL_SwapLE16(message.def.wCI); const _item_indexes wIndx = static_cast<_item_indexes>(SDL_SwapLE16(message.def.wIndx)); if (GetItemRecord(dwSeed, wCI, wIndx)) { @@ -2577,7 +2577,7 @@ void DeltaAddItem(int ii) if (item.bCmd != CMD_INVALID && static_cast<_item_indexes>(SDL_SwapLE16(item.def.wIndx)) == Items[ii].IDidx && SDL_SwapLE16(item.def.wCI) == Items[ii]._iCreateInfo - && static_cast(SDL_SwapLE32(item.def.dwSeed)) == Items[ii]._iSeed + && static_cast(SDL_SwapLE32(item.def.dwSeed)) == Items[ii]._iSeed && IsAnyOf(item.bCmd, TCmdPItem::PickedUpItem, TCmdPItem::FloorItem)) { return; } diff --git a/Source/msg.h b/Source/msg.h index 3fe6d290a..756633869 100644 --- a/Source/msg.h +++ b/Source/msg.h @@ -532,13 +532,13 @@ struct TCmdQuest { struct TItemDef { _item_indexes wIndx; uint16_t wCI; - int32_t dwSeed; + uint32_t dwSeed; }; struct TItem { _item_indexes wIndx; uint16_t wCI; - int32_t dwSeed; + uint32_t dwSeed; uint8_t bId; uint8_t bDur; uint8_t bMDur; @@ -557,7 +557,7 @@ struct TItem { struct TEar { _item_indexes wIndx; uint16_t wCI; - int32_t dwSeed; + uint32_t dwSeed; uint8_t bCursval; char heroname[17]; };