From 14f291d53986e95da65c0f4e2253004ff1ddeca2 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Mon, 9 May 2011 14:04:39 +0400 Subject: [PATCH] Support reading the item ID field, which is used for cross-referencing. --- Memory.xml | 3 +++ library/include/dfhack/modules/Items.h | 1 + library/modules/Items.cpp | 5 +++++ tools/examples/dfitemdump.cpp | 8 ++++---- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Memory.xml b/Memory.xml index 19c9e1d9a..25df466d4 100644 --- a/Memory.xml +++ b/Memory.xml @@ -997,6 +997,7 @@
+ List of offsets in the VTable : @@ -2236,6 +2237,7 @@
+ @@ -3025,6 +3027,7 @@
+ diff --git a/library/include/dfhack/modules/Items.h b/library/include/dfhack/modules/Items.h index 3e1dcac1c..b164ff287 100644 --- a/library/include/dfhack/modules/Items.h +++ b/library/include/dfhack/modules/Items.h @@ -78,6 +78,7 @@ struct t_item struct dfh_item { + int32_t id; t_item base; t_material matdesc; int32_t quantity; diff --git a/library/modules/Items.cpp b/library/modules/Items.cpp index 20108c32e..238352c08 100644 --- a/library/modules/Items.cpp +++ b/library/modules/Items.cpp @@ -96,6 +96,7 @@ private: Accessor * AWear; Process * p; bool hasDecoration; + int idFieldOffset; public: ItemDesc(uint32_t VTable, Process * p); bool readItem(uint32_t itemptr, dfh_item & item); @@ -365,6 +366,8 @@ ItemDesc::ItemDesc(uint32_t VTable, Process *p) AQuality = buildAccessor(Items, p, "item_quality_accessor", VTable); AWear = buildAccessor(Items, p, "item_wear_accessor", VTable); + idFieldOffset = Items->getOffset("id"); + this->vtable = VTable; this->p = p; this->className = p->readClassName(VTable).substr(5); @@ -395,6 +398,7 @@ string ItemDesc::dumpAccessors() bool ItemDesc::readItem(uint32_t itemptr, DFHack::dfh_item &item) { + item.id = p->readDWord(itemptr+idFieldOffset); p->read(itemptr, sizeof(t_item), (uint8_t*)&item.base); item.matdesc.itemType = AMainType->getValue(itemptr); item.matdesc.subType = ASubType->getValue(itemptr); @@ -419,6 +423,7 @@ class Items::Private std::map descVTable; uint32_t refVectorOffset; uint32_t refIDOffset; + uint32_t idFieldOffset; ClassNameCheck isOwnerRefClass; }; diff --git a/tools/examples/dfitemdump.cpp b/tools/examples/dfitemdump.cpp index bbae94883..d9d60bd84 100644 --- a/tools/examples/dfitemdump.cpp +++ b/tools/examples/dfitemdump.cpp @@ -60,8 +60,8 @@ int main () if(itm.base.x == x && itm.base.y == y && itm.base.z == z) { printf( - "%5d: %08x %08x (%d,%d,%d) #%08x [%d] %s - %s\n", - i, itm.origin, itm.base.flags.whole, + "%5d: %08x %6d %08x (%d,%d,%d) #%08x [%d] %s - %s\n", + i, itm.origin, itm.id, itm.base.flags.whole, itm.base.x, itm.base.y, itm.base.z, itm.base.vtable, itm.wear_level, @@ -75,8 +75,8 @@ int main () else { printf( - "%5d: %08x %08x (%d,%d,%d) #%08x [%d] %s - %s\n", - i, itm.origin, itm.base.flags.whole, + "%5d: %08x %6d %08x (%d,%d,%d) #%08x [%d] %s - %s\n", + i, itm.origin, itm.id, itm.base.flags.whole, itm.base.x, itm.base.y, itm.base.z, itm.base.vtable, itm.wear_level,