diff --git a/library/DFHackAPI.cpp b/library/DFHackAPI.cpp
index 503e44d42..62f51368e 100644
--- a/library/DFHackAPI.cpp
+++ b/library/DFHackAPI.cpp
@@ -86,6 +86,7 @@ class API::Private
bool vegetationInited;
bool creaturesInited;
bool cursorWindowInited;
+ bool itemsInited;
bool nameTablesInited;
@@ -98,6 +99,8 @@ class API::Private
DfVector *p_trans;
DfVector *p_generic;
DfVector *p_dwarf_names;
+
+ DfVector *p_itm;
/*
string getLastNameByAddress(const uint32_t &address, bool use_generic=false);
string getSquadNameByAddress(const uint32_t &address, bool use_generic=false);
@@ -120,6 +123,7 @@ API::API(const string path_to_xml)
d->buildingsInited = false;
d->vegetationInited = false;
d->cursorWindowInited = false;
+ d->itemsInited = false;
d->pm = NULL;
}
@@ -1206,4 +1210,45 @@ memory_info API::getMemoryInfo()
Process * API::getProcess()
{
return d->p;
+}
+
+uint32_t API::InitReadItems()
+{
+ int items = d->offset_descriptor->getAddress("items");
+ assert(items);
+ d->p_itm = new DfVector( d->dm->readVector(items,4));
+ d->itemsInited = true;
+ return d->p_itm->getSize();
+}
+bool API::ReadItem(const uint32_t &index, t_item & item)
+{
+ assert(d->buildingsInited && d->itemsInited); //should change to the generic init rather than buildings
+
+ t_item_df40d item_40d;
+
+ // read pointer from vector at position
+ uint32_t temp = *(uint32_t *) d->p_itm->at(index);
+
+ //read building from memory
+ Mread(temp, sizeof(t_item_df40d), (uint8_t *)&item_40d);
+
+ // transform
+ int32_t type = -1;
+ d->offset_descriptor->resolveClassId(temp, type);
+ item.origin = temp;
+ item.vtable = item_40d.vtable;
+ item.x = item_40d.x;
+ item.y = item_40d.y;
+ item.z = item_40d.z;
+ item.type = type;
+ item.ID = item_40d.ID;
+ item.flags = item_40d.flags;
+
+ return true;
+}
+void API::FinishReadItems()
+{
+ delete d->p_itm;
+ d->p_itm = NULL;
+ d->itemsInited = false;
}
\ No newline at end of file
diff --git a/library/DFHackAPI.h b/library/DFHackAPI.h
index 516b45264..2de87ed4e 100644
--- a/library/DFHackAPI.h
+++ b/library/DFHackAPI.h
@@ -185,6 +185,10 @@ namespace DFHack
*/
void InitReadNameTables();
void FinishReadNameTables();
+
+ uint32_t InitReadItems();
+ bool ReadItem(const uint32_t &index, t_item & item);
+ void FinishReadItems();
memory_info getMemoryInfo();
Process * getProcess();
diff --git a/library/DFTypes.h b/library/DFTypes.h
index 44f7aa9a3..8fee3b18b 100644
--- a/library/DFTypes.h
+++ b/library/DFTypes.h
@@ -511,6 +511,36 @@ struct t_creature
uint8_t sex;
};
+//raw
+struct t_item_df40d
+{
+ uint32_t vtable;
+ uint16_t x;
+ uint16_t y;
+ uint16_t z;
+ uint32_t unk1;
+ uint32_t flags;
+ uint32_t unk2;
+ uint32_t ID;
+ // not complete
+};
+
+//cooked
+struct t_item
+{
+ uint32_t origin;
+ uint32_t vtable;
+
+ uint32_t x;
+ uint32_t y;
+ uint32_t z;
+
+ uint32_t flags;
+ uint32_t ID;
+ uint32_t type;
+ // FIXME: not complete, we need building presence bitmaps for stuff like farm plots and stockpiles, orientation (N,E,S,W) and state (open/closed)
+};
+
// TODO: research this further? consult DF hacker wizards?
union t_designation
{
diff --git a/output/Memory.xml b/output/Memory.xml
index 3e230d9a3..ecb9ef360 100644
--- a/output/Memory.xml
+++ b/output/Memory.xml
@@ -920,6 +920,97 @@