Skip to content

Commit

Permalink
Fixed hiring of new mercenary to properly save items.
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterCouto committed Mar 11, 2022
1 parent 22f443a commit 5e9111b
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 31 deletions.
Binary file modified D2Editor.exe
Binary file not shown.
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Check the following site for updates at https://github.com/WalterCouto/D2CE<br>
**Version 2.14 (Mar 7, 2022)**
- Updated: Updated jewel alternate images.<br>
- Updated: Updated item context menus across forms showing items.<br>
- Updated: Fixed hiring of new mercenary to properly save items.<br>
<br>

- Added: Shared Stash support. Users can now view and edit items in the shared stash if the file is present in the same location as their character.<br>
Expand Down
3 changes: 2 additions & 1 deletion source/D2Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
Revision History
================
Version 2.14 (Mar 7, 2022)
Version 2.14 (Mar 11, 2022)
- Updated: Updated jewel alternate images.
- Updated: Updated item context menus across forms showing
items.
- Updated: Fixed hiring of new mercenary to properly save items.
- Added: Shared Stash support. Users can now view and edit
items in the shared stash if the file is present in the
Expand Down
62 changes: 41 additions & 21 deletions source/D2ItemToolTipCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,29 +91,49 @@ CSize CD2ItemToolTipCtrl::OnDrawLabel(CDC* pDC, CRect rect, BOOL bCalcOnly)
enum { WHITE = 0, BLUE, GREEN, RARE, UNIQUE, CRAFT, RED, GRAY };

// Get color of top text
COLORREF color = CurrItem->isIdentified() ? (CurrItem->isEthereal() ? colors[GRAY] : colors[WHITE]) : colors[RED];
switch (CurrItem->getQuality())
COLORREF color = colors[WHITE];
if (CurrItem->isIdentified())
{
case d2ce::EnumItemQuality::MAGIC:
color = colors[BLUE];
break;

case d2ce::EnumItemQuality::SET:
color = colors[GREEN];
break;

case d2ce::EnumItemQuality::RARE:
color = colors[RARE];
break;

case d2ce::EnumItemQuality::UNIQUE:
color = colors[UNIQUE];
break;
if (CurrItem->isEthereal())
{
color = colors[GRAY];
}
else if (CurrItem->isQuestItem())
{
color = colors[UNIQUE];
}
else if (CurrItem->isRune())
{
color = colors[CRAFT];
}

case d2ce::EnumItemQuality::CRAFT:
case d2ce::EnumItemQuality::TEMPERED:
color = colors[CRAFT];
break;
switch (CurrItem->getQuality())
{
case d2ce::EnumItemQuality::MAGIC:
color = colors[BLUE];
break;

case d2ce::EnumItemQuality::SET:
color = colors[GREEN];
break;

case d2ce::EnumItemQuality::RARE:
color = colors[RARE];
break;

case d2ce::EnumItemQuality::UNIQUE:
color = colors[UNIQUE];
break;

case d2ce::EnumItemQuality::CRAFT:
case d2ce::EnumItemQuality::TEMPERED:
color = colors[CRAFT];
break;
}
}
else
{
color = colors[RED];
}
pDC->SetTextColor(color);

Expand Down
9 changes: 7 additions & 2 deletions source/d2ce/Character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1727,7 +1727,7 @@ bool d2ce::Character::writeStats()
//---------------------------------------------------------------------------
bool d2ce::Character::writeItems()
{
return m_items.writeItems(m_charfile, isExpansionCharacter());
return m_items.writeItems(m_charfile, isExpansionCharacter(), hasMercenary());
}
//---------------------------------------------------------------------------
/*
Expand Down Expand Up @@ -1758,7 +1758,7 @@ void d2ce::Character::writeTempFile()
Cs.writeStats(tempfile);

// Write Character, Corpse, Mercenary and Golem m_items
m_items.writeItems(tempfile, isExpansionCharacter());
m_items.writeItems(tempfile, isExpansionCharacter(), hasMercenary());
std::fclose(tempfile);
}
//---------------------------------------------------------------------------
Expand Down Expand Up @@ -2098,6 +2098,11 @@ std::uint32_t d2ce::Character::getFileSize() const
return FileSize;
}
//---------------------------------------------------------------------------
bool d2ce::Character::hasMercenary() const
{
return Merc.isHired();
}
//---------------------------------------------------------------------------
d2ce::Mercenary& d2ce::Character::getMercenaryInfo()
{
return Merc;
Expand Down
1 change: 1 addition & 0 deletions source/d2ce/Character.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ namespace d2ce
std::uint32_t getFileSize() const;

// Mercenary Info
bool hasMercenary() const;
Mercenary& getMercenaryInfo();
const std::list<d2ce::Item>& getMercItems() const;

Expand Down
16 changes: 12 additions & 4 deletions source/d2ce/Item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11862,7 +11862,7 @@ void d2ce::Items::readMercItems(std::FILE* charfile)
}
}

// lock ahead for no merc case
// look ahead for no merc case
bool bHasMercId = true;
if (!feof(charfile))
{
Expand All @@ -11884,6 +11884,7 @@ void d2ce::Items::readMercItems(std::FILE* charfile)
{
return;
}
isMercHired = true;
}

readGolemItem(charfile);
Expand Down Expand Up @@ -11982,6 +11983,7 @@ void d2ce::Items::readMercItems(const Json::Value& root, bool bSerializedFormat,
std::fwrite(ITEM_MARKER.data(), ITEM_MARKER.size(), 1, charfile);
std::fwrite(&NumOfMercItems, sizeof(NumOfMercItems), 1, charfile);
merc_location = std::ftell(charfile);
isMercHired = true;
for (auto& item : MercItems)
{
if (!item.writeItem(charfile))
Expand Down Expand Up @@ -12179,11 +12181,11 @@ bool d2ce::Items::writeMercItems(std::FILE* charfile)

std::fwrite(MERC_ITEM_MARKER.data(), MERC_ITEM_MARKER.size(), 1, charfile);
NumOfMercItems = (std::uint16_t)MercItems.size();
if (merc_location != 0)
if (NumOfMercItems > 0 || isMercHired)
{
isMercHired = true;
std::fwrite(ITEM_MARKER.data(), ITEM_MARKER.size(), 1, charfile);
std::fwrite(&NumOfMercItems, sizeof(NumOfMercItems), 1, charfile);
merc_location = std::ftell(charfile);
for (auto& item : MercItems)
{
if (!item.writeItem(charfile))
Expand Down Expand Up @@ -12215,6 +12217,7 @@ bool d2ce::Items::readItems(EnumCharVersion version, std::FILE* charfile, bool i
Version = version;
update_locations = items_location == 0 ? true : false;
isFileExpansionCharacter = isExpansion;
isMercHired = false;
GPSs.clear();
Stackables.clear();
Armor.clear();
Expand All @@ -12241,6 +12244,7 @@ bool d2ce::Items::readSharedStashPage(EnumCharVersion version, std::FILE* charfi
Version = version;
update_locations = items_location == 0 ? true : false;
isFileExpansionCharacter = false;
isMercHired = false;
GPSs.clear();
Stackables.clear();
Armor.clear();
Expand All @@ -12261,6 +12265,7 @@ bool d2ce::Items::readItems(const Json::Value& root, bool bSerializedFormat, Enu
Version = version;
update_locations = true;
isFileExpansionCharacter = isExpansion;
isMercHired = false;
if (!readItems(root, bSerializedFormat, charfile, items_location, NumOfItems, Inventory) || items_location == 0)
{
return false;
Expand All @@ -12279,9 +12284,10 @@ bool d2ce::Items::readItems(const Json::Value& root, bool bSerializedFormat, Enu
}
//---------------------------------------------------------------------------
// write items in place at offset saved from reasding
bool d2ce::Items::writeItems(std::FILE* charfile, bool isExpansion)
bool d2ce::Items::writeItems(std::FILE* charfile, bool isExpansion, bool hasMercID)
{
isFileExpansionCharacter = isExpansion;
isMercHired = !MercItems.empty() | hasMercID;

// Write Items
std::fwrite(ITEM_MARKER.data(), ITEM_MARKER.size(), 1, charfile);
Expand Down Expand Up @@ -12551,6 +12557,7 @@ d2ce::Items& d2ce::Items::operator=(const Items& other)

update_locations = other.update_locations;
isFileExpansionCharacter = other.isFileExpansionCharacter;
isMercHired = other.isMercHired;

// refetch references to items
GPSs.clear();
Expand Down Expand Up @@ -12605,6 +12612,7 @@ d2ce::Items& d2ce::Items::operator=(Items&& other) noexcept

update_locations = std::exchange(other.update_locations, true);
isFileExpansionCharacter = std::exchange(other.isFileExpansionCharacter, false);
isMercHired = std::exchange(other.isMercHired, false);
return *this;
}
//---------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion source/d2ce/Item.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ namespace d2ce

bool update_locations = true;
bool isFileExpansionCharacter = false;
bool isMercHired = false;

private:
void findItems();
Expand Down Expand Up @@ -348,7 +349,7 @@ namespace d2ce
bool readItems(EnumCharVersion version, std::FILE* charfile, bool isExpansion = false);
bool readSharedStashPage(EnumCharVersion version, std::FILE* charfile);
bool readItems(const Json::Value& root, bool bSerializedFormat, EnumCharVersion version, std::FILE* charfile, bool isExpansion = false);
bool writeItems(std::FILE* charfile, bool isExpansion = false);
bool writeItems(std::FILE* charfile, bool isExpansion = false, bool hasMercID = false);
bool writeSharedStashPage(std::FILE* charfile);

void itemsAsJson(Json::Value& parent, std::uint32_t charLevel, bool bSerializedFormat = false) const;
Expand Down
2 changes: 1 addition & 1 deletion source/d2ce/helpers/ItemHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@ namespace d2ce
{"bbb", {"Lam Esen's Tome", {{ 0, 0 }, false, false, { 0, 0 }}, {0, 0}, {2, 2}, false, "invbbb", 0, {"Quest"}}},
{"mbr", {"Mephisto's Brain", {{ 0, 0 }, false, false, { 0, 0 }}, {0, 0}, {1, 1}, false, "invbrnz", 0, {"Quest"}}},
{"luv", {"Mephisto's Key", {{ 0, 0 }, false, false, { 0, 0 }}, {0, 0}, {1, 2}, false, "invmph", 0, {"Key", "Miscellaneous", "Quest"}}},
{"mss", {"Mephisto's Soul Stone", {{ 0, 0 }, false, false, { 0, 0 }}, {0, 0}, {1, 1}, false, "invmss", 0, {"Quest"}}},
{"mss", {"Mephisto's Soulstone", {{ 0, 0 }, false, false, { 0, 0 }}, {0, 0}, {1, 1}, false, "invmss", 0, {"Quest"}}},
{"ass", {"Book of Skill", {{ 0, 0 }, false, false, { 0, 0 }}, {0, 0}, {2, 2}, false, "invsbk", 0, {"Quest"}}},
{"rin", {"Ring", {{ 0, 0 }, false, false, { 0, 0 }}, {0, 0}, {1, 1}, false, "invrin", 0, {"Ring", "Miscellaneous"}}},
{"xyz", {"Potion of Life", {{ 0, 0 }, false, false, { 0, 0 }}, {0, 0}, {1, 1}, false, "invxyz", 0, {"Quest"}}},
Expand Down
2 changes: 1 addition & 1 deletion source/examples/chars/97/MfBowzon.json
Original file line number Diff line number Diff line change
Expand Up @@ -9657,7 +9657,7 @@
"type_id": 4,
"quest_difficulty": 1,
"nr_of_items_in_sockets": 0,
"type_name": "Mephisto's Soul Stone",
"type_name": "Mephisto's Soulstone",
"inv_file": "invmss",
"inv_height": 1,
"inv_width": 1
Expand Down

0 comments on commit 5e9111b

Please sign in to comment.