diff --git a/Memory.xml b/Memory.xml
index f53bcd96e..654363ca6 100644
--- a/Memory.xml
+++ b/Memory.xml
@@ -995,7 +995,7 @@
- (in the vtable)
+
@@ -2950,6 +2950,12 @@
+
+
+
+
+
+
diff --git a/library/include/dfhack/modules/Items.h b/library/include/dfhack/modules/Items.h
index 8940b6c95..871b7b01d 100644
--- a/library/include/dfhack/modules/Items.h
+++ b/library/include/dfhack/modules/Items.h
@@ -6,17 +6,29 @@
*/
#include "dfhack/DFExport.h"
#include "dfhack/DFModule.h"
+#include "dfhack/DFTypes.h"
+
namespace DFHack
{
class Context;
class DFContextShared;
+struct t_item_header
+{
+ int16_t x;
+ int16_t y;
+ int16_t z;
+ t_itemflags flags;
+};
+
struct t_item
{
+ t_item_header header;
t_material matdesc;
int32_t quantity;
int32_t quality;
+ int16_t wear_level;
};
struct t_improvement
@@ -35,6 +47,7 @@ public:
std::string getItemDescription(uint32_t itemptr, Materials * Materials);
std::string getItemClass(int32_t index);
bool getItemData(uint32_t itemptr, t_item & item);
+ void setItemFlags(uint32_t itemptr, t_itemflags new_flags);
private:
class Private;
Private* d;
diff --git a/library/modules/Items.cpp b/library/modules/Items.cpp
index dfc47962a..c1c554c73 100644
--- a/library/modules/Items.cpp
+++ b/library/modules/Items.cpp
@@ -84,6 +84,7 @@ private:
Accessor * ASubIndex;
Accessor * AIndex;
Accessor * AQuality;
+ Accessor * AWear;
Process * p;
bool hasDecoration;
public:
@@ -284,6 +285,7 @@ ItemDesc::ItemDesc(uint32_t VTable, Process *p)
uint32_t funcOffsetC = Items->getOffset("item_subindex_accessor");
uint32_t funcOffsetD = Items->getOffset("item_index_accessor");
uint32_t funcOffsetQuality = Items->getOffset("item_quality_accessor");
+ uint32_t funcOffsetWear = Items->getOffset("item_wear_accessor");
this->vtable = VTable;
this->p = p;
this->className = p->readClassName(VTable).substr(5);
@@ -293,6 +295,7 @@ ItemDesc::ItemDesc(uint32_t VTable, Process *p)
this->ASubIndex = new Accessor( p->readDWord( VTable + funcOffsetC ), p);
this->AIndex = new Accessor( p->readDWord( VTable + funcOffsetD ), p);
this->AQuality = new Accessor( p->readDWord( VTable + funcOffsetQuality ), p);
+ this->AWear = new Accessor( p->readDWord( VTable + funcOffsetWear ), p);
this->hasDecoration = false;
if(this->AMainType->isConstant())
this->mainType = this->AMainType->getValue(0);
@@ -305,12 +308,16 @@ ItemDesc::ItemDesc(uint32_t VTable, Process *p)
bool ItemDesc::getItem(uint32_t itemptr, DFHack::t_item &item)
{
+ this->p->read(itemptr+4, sizeof(t_item_header), (uint8_t*)&item.header);
item.matdesc.itemType = this->AMainType->getValue(itemptr);
item.matdesc.subType = this->ASubType->getValue(itemptr);
item.matdesc.subIndex = this->ASubIndex->getValue(itemptr);
item.matdesc.index = this->AIndex->getValue(itemptr);
item.quality = this->AQuality->getValue(itemptr);
item.quantity = 1; /* TODO */
+ // Note: this accessor returns a 32-bit value with the higher
+ // half sometimes containing garbage, so the cast is essential:
+ item.wear_level = (int16_t)this->AWear->getValue(itemptr);
return true;
}
@@ -375,6 +382,11 @@ bool Items::getItemData(uint32_t itemptr, DFHack::t_item &item)
return desc->getItem(itemptr, item);
}
+void Items::setItemFlags(uint32_t itemptr, t_itemflags new_flags)
+{
+ d->owner->writeDWord(itemptr + 0x0C, new_flags.whole);
+}
+
std::string Items::getItemClass(int32_t index)
{
std::map::iterator it;