Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

clean up handling of bad/invalid item properties by forcing sensible …

…defaults
  • Loading branch information...
commit 4ce88f0d7882128efd1d956eb1b27448217ba5db 1 parent f6907e2
@fizzet fizzet authored
View
25 gemrb/core/Interface.cpp
@@ -4808,20 +4808,25 @@ void Interface::SanitizeItem(CREItem *item) const
Item *itm = gamedata->GetItem(item->ItemResRef, true);
if (itm) {
- //This hack sets the charge counters for non-rechargeable items,
- //if their charge is zero
+ //set charge counters for non-rechargeable items if their charge is zero
+ //set charge counters for items not using charges to one
for (int i = 0; i < CHARGE_COUNTERS; i++) {
- if (item->Usages[i]) {
- continue;
- }
ITMExtHeader *h = itm->GetExtHeader(i);
- if (h && !(h->RechargeFlags&IE_ITEM_RECHARGE)) {
- //HACK: the original (bg2) allows for 0 charged gems
- if (h->Charges) {
- item->Usages[i] = h->Charges;
- } else {
+ if (h) {
+ if (item->Usages[i] == 0) {
+ if (!(h->RechargeFlags&IE_ITEM_RECHARGE)) {
+ //HACK: the original (bg2) allows for 0 charged gems
+ if (h->Charges) {
+ item->Usages[i] = h->Charges;
+ } else {
+ item->Usages[i] = 1;
+ }
+ }
+ } else if (h->Charges == 0) {
item->Usages[i] = 1;
}
+ } else {
+ item->Usages[i] = 0;
}
}
View
17 gemrb/core/Store.cpp
@@ -218,22 +218,7 @@ STOItem *Store::FindItem(CREItem *item, bool exact)
}
// Check if we have a non-stackable item with a different number of charges.
if (!item->MaxStackAmount && memcmp(temp->Usages, item->Usages, sizeof(item->Usages))) {
- Item *itm = gamedata->GetItem(item->ItemResRef);
- if (!itm) {
- continue;
- }
- bool chargesValid = false;
- for (int j = 0; j < itm->ExtHeaderCount; ++j) {
- ITMExtHeader *h = itm->GetExtHeader(j);
- if (h->Charges > 0) {
- chargesValid = true;
- break;
- }
- }
- gamedata->FreeItem(itm, item->ItemResRef, 0);
- if (chargesValid) {
- continue;
- }
+ continue;
}
}
return temp;
View
4 gemrb/core/Store.h
@@ -163,6 +163,8 @@ class GEM_EXPORT Store {
int GetRealStockSize();
/** Recharges item */
void RechargeItem(CREItem *item);
+ /** Identifies item according to store lore */
+ void IdentifyItem(CREItem *item) const;
/** Adds a new item to the store (selling) */
void AddItem(CREItem* item);
void RemoveItem(unsigned int idx);
@@ -174,8 +176,6 @@ class GEM_EXPORT Store {
void SetOwnerID(ieDword owner);
bool IsBag() const;
private:
- /** Identifies item according to store lore */
- void IdentifyItem(CREItem *item) const;
/** Finds a mergeable item in the stock, if exact is set, it checks for usage counts too */
STOItem *FindItem(CREItem *item, bool exact);
bool IsItemAvailable(unsigned int slot) const;
View
19 gemrb/plugins/STOImporter/STOImporter.cpp
@@ -166,6 +166,10 @@ void STOImporter::GetItem(STOItem *it, Store *s)
{
core->ReadItem(str, (CREItem *) it);
+ //fix item properties if necessary
+ s->IdentifyItem((CREItem *) it);
+ s->RechargeItem((CREItem *) it);
+
str->ReadDword( &it->AmountInStock );
//if there was no item on stock, how this could be 0
//we hack-fix this here so it won't cause trouble
@@ -174,20 +178,7 @@ void STOImporter::GetItem(STOItem *it, Store *s)
}
// make sure the inventory knows that it needs to update flags+weight
it->Weight = -1;
- if (!(it->Flags & IE_INV_ITEM_IDENTIFIED) && !s->IsBag()) {
- Item *item = gamedata->GetItem( it->ItemResRef );
- if (item) {
- //another hack-fix
- if (item->LoreToID <= s->Lore) {
- it->Flags |= IE_INV_ITEM_IDENTIFIED;
- }
- gamedata->FreeItem( item, it->ItemResRef, false );
- }
- }
- //make sure it has at least one charge for proper pricing purposes
- if (!it->Usages[0]) {
- it->Usages[0] = 1;
- }
+
str->ReadDword( (ieDword *) &it->InfiniteSupply );
ieDwordSigned tmp;
Please sign in to comment.
Something went wrong with that request. Please try again.