Browse Source

Remove invalid items after loading heroitem data

pull/6825/head
staphen 3 years ago committed by Anders Jenbo
parent
commit
c4792be763
  1. 18
      Source/loadsave.cpp
  2. 1
      Source/pack.cpp
  3. 15
      Source/pfile.cpp

18
Source/loadsave.cpp

@ -318,7 +318,11 @@ void LoadItemData(LoadHelper &file, Item &item)
else
item._iDamAcFlags = ItemSpecialEffectHf::None;
UpdateHellfireFlag(item, item._iIName);
}
void LoadAndValidateItemData(LoadHelper &file, Item &item)
{
LoadItemData(file, item);
RemoveInvalidItem(item);
}
@ -487,10 +491,10 @@ void LoadPlayer(LoadHelper &file, Player &player)
file.Skip<uint32_t>(); // skip _pBWidth
for (Item &item : player.InvBody)
LoadItemData(file, item);
LoadAndValidateItemData(file, item);
for (Item &item : player.InvList)
LoadItemData(file, item);
LoadAndValidateItemData(file, item);
player._pNumInv = file.NextLE<int32_t>();
@ -498,9 +502,9 @@ void LoadPlayer(LoadHelper &file, Player &player)
cell = file.NextLE<int8_t>();
for (Item &item : player.SpdList)
LoadItemData(file, item);
LoadAndValidateItemData(file, item);
LoadItemData(file, player.HoldItem);
LoadAndValidateItemData(file, player.HoldItem);
player._pIMinDam = file.NextLE<int32_t>();
player._pIMaxDam = file.NextLE<int32_t>();
@ -822,13 +826,13 @@ void LoadObject(LoadHelper &file, Object &object)
void LoadItem(LoadHelper &file, Item &item)
{
LoadItemData(file, item);
LoadAndValidateItemData(file, item);
GetItemFrm(item);
}
void LoadPremium(LoadHelper &file, int i)
{
LoadItemData(file, premiumitems[i]);
LoadAndValidateItemData(file, premiumitems[i]);
}
void LoadQuest(LoadHelper *file, int i)
@ -2073,7 +2077,7 @@ void LoadStash()
auto itemCount = file.NextLE<uint32_t>();
Stash.stashList.resize(itemCount);
for (unsigned i = 0; i < itemCount; i++) {
LoadItemData(file, Stash.stashList[i]);
LoadAndValidateItemData(file, Stash.stashList[i]);
}
Stash.SetPage(file.NextLE<uint32_t>());

1
Source/pack.cpp

@ -435,7 +435,6 @@ void UnPackItem(const ItemPack &packedItem, const Player &player, Item &item, bo
item._iDurability = ClampDurability(item, packedItem.bDur);
item._iMaxCharges = std::clamp<int>(packedItem.bMCh, 0, item._iMaxCharges);
item._iCharges = std::clamp<int>(packedItem.bCh, 0, item._iMaxCharges);
RemoveInvalidItem(item);
}
}

15
Source/pfile.cpp

@ -511,6 +511,17 @@ void pfile_write_hero(SaveWriter &saveWriter, bool writeGameData)
}
}
void RemoveAllInvalidItems(Player &player)
{
for (int i = 0; i < NUM_INVLOC; i++)
RemoveInvalidItem(player.InvBody[i]);
for (int i = 0; i < player._pNumInv; i++)
RemoveInvalidItem(player.InvList[i]);
for (int i = 0; i < MaxBeltItems; i++)
RemoveInvalidItem(player.SpdList[i]);
RemoveEmptyInventory(player);
}
} // namespace
#ifdef UNPACKED_SAVES
@ -666,7 +677,7 @@ bool pfile_ui_set_hero_infos(bool (*uiAddHeroInfo)(_uiheroinfo *))
UnPackPlayer(pkplr, player);
LoadHeroItems(player);
RemoveEmptyInventory(player);
RemoveAllInvalidItems(player);
CalcPlrInv(player, false);
Game2UiPlayer(player, &uihero, hasSaveGame);
@ -753,7 +764,7 @@ void pfile_read_player_from_save(uint32_t saveNum, Player &player)
UnPackPlayer(pkplr, player);
LoadHeroItems(player);
RemoveEmptyInventory(player);
RemoveAllInvalidItems(player);
CalcPlrInv(player, false);
}

Loading…
Cancel
Save