Provide access to item header, including flags, and wear information.

Add preliminary offsets for the item data to Memory.xml
develop
Alexander Gavrilov 2011-04-10 22:42:25 +04:00
parent e3897b0f93
commit f6ae41fe49
3 changed files with 32 additions and 1 deletions

@ -995,7 +995,7 @@
<Offset name="item_improvement_subindex" /> <Offset name="item_improvement_subindex" />
<Offset name="item_improvement_index" /> <Offset name="item_improvement_index" />
<Offset name="item_improvement_quality" /> <Offset name="item_improvement_quality" />
<Offset name="item_type_accessor" /> (in the vtable) <Offset name="item_wear_accessor" />
</Group> </Group>
<Group name="World"> <Group name="World">
<Address name="current_tick" description="Current time of the year" /> <Address name="current_tick" description="Current time of the year" />
@ -2950,6 +2950,12 @@
</Group> </Group>
<Group name="Items"> <Group name="Items">
<Address name="items_vector" value="0x940b1fc" /> <Address name="items_vector" value="0x940b1fc" />
<Offset name="item_type_accessor" value="0x0" />
<Offset name="item_subtype_accessor" value="0x4" />
<Offset name="item_subindex_accessor" value="0x8" />
<Offset name="item_index_accessor" value="0xC" />
<Offset name="item_quality_accessor" value="0x25C" />
<Offset name="item_wear_accessor" value="0xCC" />
</Group> </Group>
</Offsets> </Offsets>
</Version> </Version>

@ -6,17 +6,29 @@
*/ */
#include "dfhack/DFExport.h" #include "dfhack/DFExport.h"
#include "dfhack/DFModule.h" #include "dfhack/DFModule.h"
#include "dfhack/DFTypes.h"
namespace DFHack namespace DFHack
{ {
class Context; class Context;
class DFContextShared; class DFContextShared;
struct t_item_header
{
int16_t x;
int16_t y;
int16_t z;
t_itemflags flags;
};
struct t_item struct t_item
{ {
t_item_header header;
t_material matdesc; t_material matdesc;
int32_t quantity; int32_t quantity;
int32_t quality; int32_t quality;
int16_t wear_level;
}; };
struct t_improvement struct t_improvement
@ -35,6 +47,7 @@ public:
std::string getItemDescription(uint32_t itemptr, Materials * Materials); std::string getItemDescription(uint32_t itemptr, Materials * Materials);
std::string getItemClass(int32_t index); std::string getItemClass(int32_t index);
bool getItemData(uint32_t itemptr, t_item & item); bool getItemData(uint32_t itemptr, t_item & item);
void setItemFlags(uint32_t itemptr, t_itemflags new_flags);
private: private:
class Private; class Private;
Private* d; Private* d;

@ -84,6 +84,7 @@ private:
Accessor * ASubIndex; Accessor * ASubIndex;
Accessor * AIndex; Accessor * AIndex;
Accessor * AQuality; Accessor * AQuality;
Accessor * AWear;
Process * p; Process * p;
bool hasDecoration; bool hasDecoration;
public: public:
@ -284,6 +285,7 @@ ItemDesc::ItemDesc(uint32_t VTable, Process *p)
uint32_t funcOffsetC = Items->getOffset("item_subindex_accessor"); uint32_t funcOffsetC = Items->getOffset("item_subindex_accessor");
uint32_t funcOffsetD = Items->getOffset("item_index_accessor"); uint32_t funcOffsetD = Items->getOffset("item_index_accessor");
uint32_t funcOffsetQuality = Items->getOffset("item_quality_accessor"); uint32_t funcOffsetQuality = Items->getOffset("item_quality_accessor");
uint32_t funcOffsetWear = Items->getOffset("item_wear_accessor");
this->vtable = VTable; this->vtable = VTable;
this->p = p; this->p = p;
this->className = p->readClassName(VTable).substr(5); 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->ASubIndex = new Accessor( p->readDWord( VTable + funcOffsetC ), p);
this->AIndex = new Accessor( p->readDWord( VTable + funcOffsetD ), p); this->AIndex = new Accessor( p->readDWord( VTable + funcOffsetD ), p);
this->AQuality = new Accessor( p->readDWord( VTable + funcOffsetQuality ), p); this->AQuality = new Accessor( p->readDWord( VTable + funcOffsetQuality ), p);
this->AWear = new Accessor( p->readDWord( VTable + funcOffsetWear ), p);
this->hasDecoration = false; this->hasDecoration = false;
if(this->AMainType->isConstant()) if(this->AMainType->isConstant())
this->mainType = this->AMainType->getValue(0); 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) 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.itemType = this->AMainType->getValue(itemptr);
item.matdesc.subType = this->ASubType->getValue(itemptr); item.matdesc.subType = this->ASubType->getValue(itemptr);
item.matdesc.subIndex = this->ASubIndex->getValue(itemptr); item.matdesc.subIndex = this->ASubIndex->getValue(itemptr);
item.matdesc.index = this->AIndex->getValue(itemptr); item.matdesc.index = this->AIndex->getValue(itemptr);
item.quality = this->AQuality->getValue(itemptr); item.quality = this->AQuality->getValue(itemptr);
item.quantity = 1; /* TODO */ 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; return true;
} }
@ -375,6 +382,11 @@ bool Items::getItemData(uint32_t itemptr, DFHack::t_item &item)
return desc->getItem(itemptr, 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::string Items::getItemClass(int32_t index)
{ {
std::map<int32_t, ItemDesc *>::iterator it; std::map<int32_t, ItemDesc *>::iterator it;