From 7841c4731ef70c4e1a38584cbdbbd0afc3ec3faf Mon Sep 17 00:00:00 2001 From: Juliano Leal Goncalves Date: Mon, 30 Aug 2021 01:36:48 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=9A=20Rename=20'PkItemStruct'=20to=20'?= =?UTF-8?q?ItemPack'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/items.cpp | 10 ++++----- Source/options.h | 2 +- Source/pack.cpp | 6 +++--- Source/pack.h | 12 +++++------ test/pack_test.cpp | 46 ++++++++++++++++++++--------------------- test/writehero_test.cpp | 18 ++++++++-------- 6 files changed, 47 insertions(+), 47 deletions(-) diff --git a/Source/items.cpp b/Source/items.cpp index b7d2aef56..5a5ad8c22 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -3557,10 +3557,10 @@ void CornerstoneSave() if (!CornerStone.activated) return; if (!CornerStone.item.isEmpty()) { - PkItemStruct id; + ItemPack id; PackItem(&id, &CornerStone.item); const auto *buffer = reinterpret_cast(&id); - for (size_t i = 0; i < sizeof(PkItemStruct); i++) { + for (size_t i = 0; i < sizeof(ItemPack); i++) { sprintf(&sgOptions.Hellfire.szItem[i * 2], "%02X", buffer[i]); } } else { @@ -3570,7 +3570,7 @@ void CornerstoneSave() void CornerstoneLoad(Point position) { - PkItemStruct pkSItem; + ItemPack pkSItem; if (CornerStone.activated || position.x == 0 || position.y == 0) { return; @@ -3589,10 +3589,10 @@ void CornerstoneLoad(Point position) dItem[position.x][position.y] = 0; } - if (strlen(sgOptions.Hellfire.szItem) < sizeof(PkItemStruct) * 2) + if (strlen(sgOptions.Hellfire.szItem) < sizeof(ItemPack) * 2) return; - Hex2bin(sgOptions.Hellfire.szItem, sizeof(PkItemStruct), reinterpret_cast(&pkSItem)); + Hex2bin(sgOptions.Hellfire.szItem, sizeof(ItemPack), reinterpret_cast(&pkSItem)); int ii = AllocateItem(); auto &item = Items[ii]; diff --git a/Source/options.h b/Source/options.h index aed0d6e44..b77fa7cef 100644 --- a/Source/options.h +++ b/Source/options.h @@ -17,7 +17,7 @@ struct HellfireOptions { /** @brief Play game intro video on startup. */ bool bIntro; /** @brief Cornerstone of the world item. */ - char szItem[sizeof(PkItemStruct) * 2 + 1]; + char szItem[sizeof(ItemPack) * 2 + 1]; }; struct AudioOptions { diff --git a/Source/pack.cpp b/Source/pack.cpp index a581e101c..badc66086 100644 --- a/Source/pack.cpp +++ b/Source/pack.cpp @@ -35,7 +35,7 @@ void VerifyGoldSeeds(Player &player) } // namespace -void PackItem(PkItemStruct *id, const Item *is) +void PackItem(ItemPack *id, const Item *is) { memset(id, 0, sizeof(*id)); if (is->isEmpty()) { @@ -137,14 +137,14 @@ void PackPlayer(PlayerPack *pPack, const Player &player, bool manashield) } /** - * Expand a PkItemStruct in to a Item + * Expand a ItemPack in to a Item * * Note: last slot of item[MAXITEMS+1] used as temporary buffer * find real name reference below, possibly [sizeof(item[])/sizeof(Item)] * @param is The source packed item * @param id The distination item */ -void UnPackItem(const PkItemStruct *is, Item *id, bool isHellfire) +void UnPackItem(const ItemPack *is, Item *id, bool isHellfire) { auto &item = Items[MAXITEMS]; auto idx = static_cast<_item_indexes>(SDL_SwapLE16(is->idx)); diff --git a/Source/pack.h b/Source/pack.h index 0a83e142b..4eaf85dbe 100644 --- a/Source/pack.h +++ b/Source/pack.h @@ -14,7 +14,7 @@ namespace devilution { #pragma pack(push, 1) -struct PkItemStruct { +struct ItemPack { uint32_t iSeed; uint16_t iCreateInfo; uint16_t idx; @@ -54,11 +54,11 @@ struct PlayerPack { int32_t pMaxManaBase; int8_t pSplLvl[37]; // Should be MAX_SPELLS but set to 37 to make save games compatible uint64_t pMemSpells; - PkItemStruct InvBody[NUM_INVLOC]; - PkItemStruct InvList[NUM_INV_GRID_ELEM]; + ItemPack InvBody[NUM_INVLOC]; + ItemPack InvList[NUM_INV_GRID_ELEM]; int8_t InvGrid[NUM_INV_GRID_ELEM]; uint8_t _pNumInv; - PkItemStruct SpdList[MAXBELTITEMS]; + ItemPack SpdList[MAXBELTITEMS]; int8_t pTownWarps; int8_t pDungMsgs; int8_t pLvlLoad; @@ -81,7 +81,7 @@ struct PlayerPack { void PackPlayer(PlayerPack *pPack, const Player &player, bool manashield); void UnPackPlayer(const PlayerPack *pPack, Player &player, bool netSync); -void PackItem(PkItemStruct *id, const Item *is); -void UnPackItem(const PkItemStruct *is, Item *id, bool isHellfire); +void PackItem(ItemPack *id, const Item *is); +void UnPackItem(const ItemPack *is, Item *id, bool isHellfire); } // namespace devilution diff --git a/test/pack_test.cpp b/test/pack_test.cpp index fa6e89ee0..355f7c0ab 100644 --- a/test/pack_test.cpp +++ b/test/pack_test.cpp @@ -5,9 +5,9 @@ using namespace devilution; -static void ComparePackedItems(const PkItemStruct *item1, const PkItemStruct *item2) +static void ComparePackedItems(const ItemPack *item1, const ItemPack *item2) { - // `PkItemStruct` is packed, so we copy the unaligned values out before comparing them. + // `ItemPack` is packed, so we copy the unaligned values out before comparing them. // This avoids the following UBSAN error such as this one: // runtime error: load of misaligned address for type 'const unsigned int', which requires 4 byte alignment { @@ -132,7 +132,7 @@ static void CompareItems(const Item *item1, const TestItemStruct *item2) EXPECT_EQ(item1->IDidx, item2->IDidx); } -const PkItemStruct PackedDiabloItems[] = { +const ItemPack PackedDiabloItems[] = { // clang-format off // iSeed, iCreateInfo, idx, bId, bDur, bMDur, bCh, bMCh, wValue, dwBuff { 2082213289, 0x119, 53, 3, 60, 60, 0, 0, 0, 0 }, // Amber Helm of harmony @@ -329,7 +329,7 @@ const TestItemStruct DiabloItems[] = { TEST(pack, UnPackItem_diablo) { Item id; - PkItemStruct is; + ItemPack is; gbIsHellfire = false; gbIsMultiplayer = false; @@ -349,8 +349,8 @@ TEST(pack, UnPackItem_diablo) TEST(pack, UnPackItem_diablo_unique_bug) { - PkItemStruct pkItemBug = { 6, 911, 14, 5, 60, 60, 0, 0, 0, 0 }; // Veil of Steel - with morph bug - PkItemStruct pkItem = { 6, 655, 14, 5, 60, 60, 0, 0, 0, 0 }; // Veil of Steel - fixed + ItemPack pkItemBug = { 6, 911, 14, 5, 60, 60, 0, 0, 0, 0 }; // Veil of Steel - with morph bug + ItemPack pkItem = { 6, 655, 14, 5, 60, 60, 0, 0, 0, 0 }; // Veil of Steel - fixed gbIsHellfire = false; gbIsMultiplayer = false; @@ -376,12 +376,12 @@ TEST(pack, UnPackItem_diablo_unique_bug) ASSERT_EQ(id._iUid, 6); ASSERT_EQ(id.IDidx, IDI_STEELVEIL); - PkItemStruct is; + ItemPack is; PackItem(&is, &id); ComparePackedItems(&is, &pkItem); } -const PkItemStruct PackedSpawnItems[] = { +const ItemPack PackedSpawnItems[] = { // clang-format off // iSeed, iCreateInfo, idx, bId, bDur, bMDur, bCh, bMCh, wValue, dwBuff { 2060036013, 257, 131, 0, 11, 25, 50, 50, 0, 0 }, // Staff of Firebolt @@ -400,7 +400,7 @@ const TestItemStruct SpawnItems[] = { TEST(pack, UnPackItem_spawn) { Item id; - PkItemStruct is; + ItemPack is; gbIsHellfire = false; gbIsMultiplayer = false; @@ -418,7 +418,7 @@ TEST(pack, UnPackItem_spawn) } } -const PkItemStruct PackedDiabloMPItems[] = { +const ItemPack PackedDiabloMPItems[] = { // clang-format off // iSeed, iCreateInfo, idx, bId, bDur, bMDur, bCh, bMCh, wValue, dwBuff { 309674341, 193, 109, 0, 0, 0, 0, 0, 0, 0 }, // Book of Firebolt @@ -444,7 +444,7 @@ const TestItemStruct DiabloMPItems[] = { TEST(pack, UnPackItem_diablo_multiplayer) { Item id; - PkItemStruct is; + ItemPack is; gbIsHellfire = false; gbIsMultiplayer = true; @@ -462,7 +462,7 @@ TEST(pack, UnPackItem_diablo_multiplayer) } } -const PkItemStruct PackedHellfireItems[] = { +const ItemPack PackedHellfireItems[] = { // clang-format off // iSeed, iCreateInfo, idx, bId, bDur, bMDur, bCh, bMCh, wValue, dwBuff { 1717442367, 266, 156, 3, 0, 0, 0, 0, 0, 0 }, // Ring of stability @@ -653,7 +653,7 @@ const TestItemStruct HellfireItems[] = { TEST(pack, UnPackItem_hellfire) { Item id; - PkItemStruct is; + ItemPack is; gbIsHellfire = true; gbIsMultiplayer = false; @@ -674,7 +674,7 @@ TEST(pack, UnPackItem_hellfire) TEST(pack, UnPackItem_diablo_strip_hellfire_items) { - PkItemStruct is = { 1478792102, 259, 92, 0, 0, 0, 0, 0, 0, 0 }; // Scroll of Search + ItemPack is = { 1478792102, 259, 92, 0, 0, 0, 0, 0, 0, 0 }; // Scroll of Search Item id; gbIsHellfire = false; @@ -688,7 +688,7 @@ TEST(pack, UnPackItem_diablo_strip_hellfire_items) TEST(pack, UnPackItem_empty) { - PkItemStruct is = { 0, 0, 0xFFFF, 0, 0, 0, 0, 0, 0, 0 }; + ItemPack is = { 0, 0, 0xFFFF, 0, 0, 0, 0, 0, 0, 0 }; Item id; UnPackItem(&is, &id, false); @@ -698,7 +698,7 @@ TEST(pack, UnPackItem_empty) TEST(pack, PackItem_empty) { - PkItemStruct is; + ItemPack is; Item id; id._itype = ITYPE_NONE; @@ -708,7 +708,7 @@ TEST(pack, PackItem_empty) ASSERT_EQ(is.idx, 0xFFFF); } -static void compareGold(const PkItemStruct *is, int iCurs) +static void compareGold(const ItemPack *is, int iCurs) { Item id; UnPackItem(is, &id, false); @@ -718,39 +718,39 @@ static void compareGold(const PkItemStruct *is, int iCurs) ASSERT_EQ(id._itype, ITYPE_GOLD); ASSERT_EQ(id._iClass, ICLASS_GOLD); - PkItemStruct is2; + ItemPack is2; PackItem(&is2, &id); ComparePackedItems(is, &is2); } TEST(pack, UnPackItem_gold_small) { - PkItemStruct is = { 0, 0, IDI_GOLD, 0, 0, 0, 0, 0, 1000, 0 }; + ItemPack is = { 0, 0, IDI_GOLD, 0, 0, 0, 0, 0, 1000, 0 }; compareGold(&is, ICURS_GOLD_SMALL); } TEST(pack, UnPackItem_gold_medium) { - PkItemStruct is = { 0, 0, IDI_GOLD, 0, 0, 0, 0, 0, 1001, 0 }; + ItemPack is = { 0, 0, IDI_GOLD, 0, 0, 0, 0, 0, 1001, 0 }; compareGold(&is, ICURS_GOLD_MEDIUM); } TEST(pack, UnPackItem_gold_large) { - PkItemStruct is = { 0, 0, IDI_GOLD, 0, 0, 0, 0, 0, 2500, 0 }; + ItemPack is = { 0, 0, IDI_GOLD, 0, 0, 0, 0, 0, 2500, 0 }; compareGold(&is, ICURS_GOLD_LARGE); } TEST(pack, UnPackItem_ear) { - PkItemStruct is = { 1633955154, 17509, 23, 111, 103, 117, 101, 68, 19843, 0 }; + ItemPack is = { 1633955154, 17509, 23, 111, 103, 117, 101, 68, 19843, 0 }; Item id; UnPackItem(&is, &id, false); ASSERT_STREQ(id._iName, "Ear of Dead-RogueDM"); ASSERT_EQ(id._ivalue, 3); - PkItemStruct is2; + ItemPack is2; PackItem(&is2, &id); ComparePackedItems(&is, &is2); } diff --git a/test/writehero_test.cpp b/test/writehero_test.cpp index c7fee2068..7adf21ee9 100644 --- a/test/writehero_test.cpp +++ b/test/writehero_test.cpp @@ -21,7 +21,7 @@ int spelldat_vanilla[] = { -1, -1, -1, 8, 1, 1, -1, 2, 1, 14, 9 }; -static void PackItemUnique(PkItemStruct *id, int idx) +static void PackItemUnique(ItemPack *id, int idx) { id->idx = idx; id->iCreateInfo = 0x2DE; @@ -33,7 +33,7 @@ static void PackItemUnique(PkItemStruct *id, int idx) id->iSeed = 0x1C0C44B0; } -static void PackItemStaff(PkItemStruct *id) +static void PackItemStaff(ItemPack *id) { id->idx = 150; id->iCreateInfo = 0x2010; @@ -45,7 +45,7 @@ static void PackItemStaff(PkItemStruct *id) id->iSeed = 0x2A15243F; } -static void PackItemBow(PkItemStruct *id) +static void PackItemBow(ItemPack *id) { id->idx = 145; id->iCreateInfo = 0x0814; @@ -57,7 +57,7 @@ static void PackItemBow(PkItemStruct *id) id->iSeed = 0x449D8992; } -static void PackItemSword(PkItemStruct *id) +static void PackItemSword(ItemPack *id) { id->idx = 122; id->iCreateInfo = 0x081E; @@ -69,7 +69,7 @@ static void PackItemSword(PkItemStruct *id) id->iSeed = 0x680FAC02; } -static void PackItemRing1(PkItemStruct *id) +static void PackItemRing1(ItemPack *id) { id->idx = 153; id->iCreateInfo = 0xDE; @@ -81,7 +81,7 @@ static void PackItemRing1(PkItemStruct *id) id->iSeed = 0x5B41AFA8; } -static void PackItemRing2(PkItemStruct *id) +static void PackItemRing2(ItemPack *id) { id->idx = 153; id->iCreateInfo = 0xDE; @@ -93,7 +93,7 @@ static void PackItemRing2(PkItemStruct *id) id->iSeed = 0x1E41FEFC; } -static void PackItemAmulet(PkItemStruct *id) +static void PackItemAmulet(ItemPack *id) { id->idx = 155; id->iCreateInfo = 0xDE; @@ -105,7 +105,7 @@ static void PackItemAmulet(PkItemStruct *id) id->iSeed = 0x70A0383A; } -static void PackItemArmor(PkItemStruct *id) +static void PackItemArmor(ItemPack *id) { id->idx = 70; id->iCreateInfo = 0xDE; @@ -117,7 +117,7 @@ static void PackItemArmor(PkItemStruct *id) id->iSeed = 0x63AAC49B; } -static void PackItemFullRejuv(PkItemStruct *id, int i) +static void PackItemFullRejuv(ItemPack *id, int i) { const uint32_t seeds[] = { 0x7C253335, 0x3EEFBFF8, 0x76AFB1A9, 0x38EB45FE, 0x1154E197, 0x5964B644, 0x76B58BEB, 0x002A6E5A }; id->idx = ItemMiscIdIdx(IMISC_FULLREJUV);