Kill item variable accessors. YES.

develop
Petr Mrázek 2011-10-25 04:48:06 +02:00
parent 452ddd3e2c
commit 04495a304c
10 changed files with 259 additions and 476 deletions

@ -543,7 +543,7 @@ namespace DFHack
int16_t unk_280;
int32_t unk_284;
std::vector<t_item *> inventory; // 288 - vector of item pointers
std::vector<df_item *> inventory; // 288 - vector of item pointers
std::vector<int32_t> owned_items; // 298 - vector of item IDs
std::vector<uint32_t> unk_2a8;
std::vector<uint32_t> unk_2b8;
@ -763,8 +763,8 @@ namespace DFHack
bool ReadJob(const df_creature * unit, std::vector<t_material> & mat);
bool ReadInventoryByIdx(const uint32_t index, std::vector<t_item *> & item);
bool ReadInventoryByPtr(const df_creature * unit, std::vector<t_item *> & item);
bool ReadInventoryByIdx(const uint32_t index, std::vector<df_item *> & item);
bool ReadInventoryByPtr(const df_creature * unit, std::vector<df_item *> & item);
bool ReadOwnedItemsByIdx(const uint32_t index, std::vector<int32_t> & item);
bool ReadOwnedItemsByPtr(const df_creature * unit, std::vector<int32_t> & item);

@ -109,21 +109,221 @@ struct t_itemref : public t_virtual
};
/**
* Basic item data, read as a single chunk
* A partial mirror of a DF base type for items
* \ingroup grp_items
*/
struct t_item : public t_virtual
class df_item
{
// vptr 0x0 + 4
int16_t x; // 0x4 + 2
int16_t y; // 0x6 + 2
int16_t z; // 0x8 + 2
// 2B padding 0xA + 2
t_itemflags flags; // 0xC + 4
uint32_t age ; // 0x10 + 4
uint32_t id; // 0x14 + 4
std::vector<void *> unk1;// Used by tasked items.
public:
int16_t x;
int16_t y;
int16_t z;
t_itemflags flags;
uint32_t age;
uint32_t id;
std::vector<void *> unk1;
std::vector<t_itemref *> itemrefs;
public:
// 0x0
virtual int32_t getType();
virtual int32_t getSubtype();
virtual int32_t getSubMaterial();
virtual int16_t getMaterial();
// 0x10
/*
hm, [4] looks complicated *
takes a parameter
looks like 0x017081A4 is a vector of something
this one sets an item property at offset 0xA0
(0.31.25 Windows SDL)
*/
virtual void fn4(void);
virtual void setMaterial(int16_t mat);
virtual void setSubMaterial (int32_t submat);
// another one? really?
virtual int16_t getMaterial2();
// 0x20
// more of the same?
virtual int32_t getSubMaterial2();
virtual void fn9(void);
virtual void fn10(void);
virtual void fn11(void);
// 0x30
virtual void fn12(void);
virtual void fn13(void);
virtual void fn14(void);
virtual void fn15(void);
// 0x40
virtual void fn16(void);
virtual void fn17(void);
virtual void fn18(void);
virtual void fn19(void);
// 0x50
virtual void fn20(void);
virtual void fn21(void);
virtual void fn22(void);
virtual void fn23(void);
// 0x60
virtual void fn24(void);
virtual void fn25(void);
virtual void fn26(void);
virtual void fn27(void);
// 0x70
virtual void fn28(void);
virtual void fn29(void);
virtual void fn30(void);
virtual void fn31(void);
// 0x80
virtual void fn32(void);
virtual void fn33(void);
virtual void fn34(void);
virtual void fn35(void);
// 0x90
virtual void fn36(void);
virtual void fn37(void);
virtual void fn38(void);
virtual void fn39(void);
// 0xA0
virtual void fn40(void);
virtual void fn41(void);
virtual void fn42(void);
virtual void fn43(void);
// 0xB0
virtual void fn44(void);
virtual void fn45(void);
virtual void fn46(void);
virtual void fn47(void);
// 0xC0
virtual void fn48(void);
virtual void fn49(void);
virtual void fn50(void);
virtual int16_t getWear(void); // 0 = normal, 1 = x, 2 = X, 3 = XX
// 0xD0
virtual void setWear(int16_t wear); // also zeroes wear timer?
virtual void fn53(void);
virtual void fn54(void);
virtual void fn55(void);
// 0xE0
virtual void fn56(void);
virtual void fn57(void);
virtual void fn58(void);
virtual void fn59(void);
// 0xF0
virtual void fn60(void);
virtual void fn61(void);
virtual void fn62(void);
virtual void fn63(void);
// 0x100
virtual void fn64(void);
virtual void fn65(void);
virtual void fn66(void);
virtual void fn67(void);
// 0x110
virtual void fn68(void);
virtual void fn69(void);
virtual void fn70(void);
virtual void fn71(void);
// 0x120
virtual void fn72(void);
virtual void fn73(void);
virtual void fn74(void);
virtual void fn75(void);
// 0x130
virtual void fn76(void);
virtual void fn77(void);
virtual void fn78(void);
virtual void fn79(void);
// 0x140
virtual void fn80(void);
virtual void fn81(void);
virtual void fn82(void);
virtual void fn83(void);
// 0x150
virtual void fn84(void);
virtual void fn85(void);
virtual void fn86(void);
virtual void fn87(void);
// 0x160
virtual void fn88(void);
virtual void fn89(void);
virtual void fn90(void);
virtual void fn91(void);
// 0x170
virtual void fn92(void);
virtual void fn93(void);
virtual void fn94(void);
virtual void fn95(void);
// 0x180
virtual void fn96(void);
virtual void fn97(void);
virtual void fn98(void);
virtual void fn99(void);
// 0x190
virtual void fn100(void);
virtual void fn101(void);
virtual void fn102(void);
virtual void fn103(void);
// 0x1A0
virtual void fn104(void);
virtual void fn105(void);
virtual void fn106(void);
virtual void fn107(void);
// 0x1B0
virtual void fn108(void);
virtual void fn109(void);
virtual void fn110(void);
virtual void fn111(void);
// 0x1C0
virtual void fn112(void);
virtual void fn113(void);
virtual void fn114(void);
virtual void fn115(void);
// 0x1D0
virtual void fn116(void);
virtual void fn117(void);
virtual void fn118(void);
virtual void fn119(void);
// 0x1E0
virtual void fn120(void);
virtual void fn121(void);
virtual void fn122(void);
virtual void fn123(void);
// 0x1F0
virtual void fn124(void);
virtual void fn125(void);
virtual void fn126(void);
virtual void fn127(void);
// 0x200
virtual void fn128(void);
virtual void fn129(void);
virtual void fn130(void);
virtual void fn131(void);
// 0x210
virtual void fn132(void);
virtual int32_t getStackSize( void );
virtual void fn134(void);
virtual void fn135(void);
// 0x220
virtual void fn136(void);
virtual void fn137(void);
virtual void fn138(void);
virtual void fn139(void);
// 0x230
virtual void fn140(void);
virtual void fn141(void);
virtual void fn142(void);
virtual void fn143(void);
// 0x240
virtual void fn144(void);
virtual void fn145(void);
virtual void fn146(void);
virtual void fn147(void);
// 0x250
virtual void fn148(void);
virtual void fn149(void);
virtual void fn150(void);
virtual int16_t getQuality( void );
// more follows for sure... bleh.
};
/**
@ -132,13 +332,14 @@ struct t_item : public t_virtual
*/
struct dfh_item
{
t_item * base;
df_item * base;
t_material matdesc;
int32_t quantity;
int32_t quality;
int16_t wear_level;
};
/**
* Type for holding item improvements. broken/unused.
* \ingroup grp_items
@ -162,20 +363,17 @@ public:
bool Start();
bool Finish();
bool readItemVector(std::vector<t_item *> &items);
t_item * findItemByID(int32_t id);
bool readItemVector(std::vector<df_item *> &items);
df_item * findItemByID(int32_t id);
/// get a string describing an item
std::string getItemDescription(const dfh_item & item, Materials * Materials);
/// get a short name for an item
std::string getItemClass(int32_t index);
std::string getItemClass(const dfh_item & item);
/// read an item, including the extra attributes
bool readItem(t_item * itembase, dfh_item & item);
bool readItem(df_item * itembase, dfh_item & item);
/// write item base (position and flags only = t_item part of dfh_item)
bool writeItem(const dfh_item & item);
/// dump offsets used by accessors to a string
std::string dumpAccessors(const dfh_item & item);
/// who owns this item we already read?
int32_t getItemOwnerID(const dfh_item & item);

@ -551,7 +551,7 @@ bool Creatures::ReadJob(const t_creature * furball, vector<t_material> & mat)
return true;
}
*/
bool Creatures::ReadInventoryByIdx(const uint32_t index, std::vector<t_item *> & item)
bool Creatures::ReadInventoryByIdx(const uint32_t index, std::vector<df_item *> & item)
{
if(!d->Started) return false;
if(index >= creatures->size()) return false;
@ -559,7 +559,7 @@ bool Creatures::ReadInventoryByIdx(const uint32_t index, std::vector<t_item *> &
return this->ReadInventoryByPtr(temp, item);
}
bool Creatures::ReadInventoryByPtr(const df_creature * temp, std::vector<t_item *> & items)
bool Creatures::ReadInventoryByPtr(const df_creature * temp, std::vector<df_item *> & items)
{
if(!d->Started) return false;
items = temp->inventory;

@ -42,6 +42,7 @@ using namespace std;
#include "dfhack/modules/Creatures.h"
#include "ModuleFactory.h"
#include <dfhack/Core.h>
#include <dfhack/Virtual.h>
using namespace DFHack;
@ -50,381 +51,11 @@ Module* DFHack::createItems()
return new Items();
}
enum accessor_type {ACCESSOR_CONSTANT, ACCESSOR_INDIRECT, ACCESSOR_DOUBLE_INDIRECT};
/* this is used to store data about the way accessors work */
class Accessor
{
public:
enum DataWidth {
Data32 = 0,
DataSigned16,
DataUnsigned16
};
private:
accessor_type type;
int32_t constant;
int32_t offset1;
int32_t offset2;
Process * p;
DataWidth dataWidth;
uint32_t method;
public:
Accessor(uint32_t function, Process * p);
Accessor(accessor_type type, int32_t constant, uint32_t offset1, uint32_t offset2, uint32_t dataWidth, Process * p);
std::string dump();
int32_t getValue(t_item * objectPtr);
bool isConstant();
};
class ItemImprovementDesc
{
private:
Accessor * AType;
Process * p;
public:
ItemImprovementDesc(uint32_t VTable, Process * p);
bool getImprovement(uint32_t descptr, t_improvement & imp);
uint32_t vtable;
uint32_t maintype;
};
class ItemDesc
{
private:
Accessor * AMainType;
Accessor * ASubType;
Accessor * ASubIndex;
Accessor * AIndex;
Accessor * AQuality;
Accessor * AQuantity;
Accessor * AWear;
Process * p;
bool hasDecoration;
int idFieldOffset;
public:
ItemDesc(void * VTable, Process * p);
bool readItem(t_item * itemptr, dfh_item & item);
std::string dumpAccessors();
std::string className;
void * vtable;
uint32_t mainType;
std::vector<ItemImprovementDesc> improvement;
};
inline bool do_match(uint32_t &ptr, uint64_t val, int size, uint64_t mask, uint64_t check)
{
if ((val & mask) == check) {
ptr += size;
return true;
}
return false;
}
static bool match_MEM_ACCESS(uint32_t &ptr, uint64_t v, int isize, int in_reg, int &out_reg, int &offset)
{
// ESP & EBP are hairy
if (in_reg == 4 || in_reg == 5)
return false;
if ((v & 7) != in_reg)
return false;
out_reg = (v>>3) & 7;
switch ((v>>6)&3) {
case 0: // MOV REG2, [REG]
offset = 0;
ptr += isize+1;
return true;
case 1: // MOV REG2, [REG+offset8]
offset = (signed char)(v >> 8);
ptr += isize+2;
return true;
case 2: // MOV REG2, [REG+offset32]
offset = (signed int)(v >> 8);
ptr += isize+5;
return true;
default:
return false;
}
}
static bool match_MOV_MEM(uint32_t &ptr, uint64_t v, int in_reg, int &out_reg, int &offset, Accessor::DataWidth &size)
{
int prefix = 0;
size = Accessor::Data32;
if ((v & 0xFF) == 0x8B) { // MOV
v >>= 8;
prefix = 1;
}
else if ((v & 0xFFFF) == 0x8B66) { // MOV 16-bit
v >>= 16;
prefix = 2;
size = Accessor::DataUnsigned16;
}
else if ((v & 0xFFFF) == 0xBF0F) { // MOVSX
v >>= 16;
prefix = 2;
size = Accessor::DataSigned16;
}
else if ((v & 0xFFFF) == 0xB70F) { // MOVZ
v >>= 16;
prefix = 2;
size = Accessor::DataUnsigned16;
}
else
return false;
return match_MEM_ACCESS(ptr, v, prefix, in_reg, out_reg, offset);
}
Accessor::Accessor(uint32_t function, Process *p)
{
this->p = p;
this->type = ACCESSOR_CONSTANT;
if(!p)
{
this->constant = 0;
return;
}
method = function;
uint32_t temp = function;
int data_reg = -1;
uint64_t v = p->readQuad(temp);
if (do_match(temp, v, 2, 0xFFFF, 0xC033) ||
do_match(temp, v, 2, 0xFFFF, 0xC031)) // XOR EAX, EAX
{
data_reg = 0;
this->constant = 0;
}
else if (do_match(temp, v, 3, 0xFFFFFF, 0xFFC883)) // OR EAX, -1
{
data_reg = 0;
this->constant = -1;
}
else if (do_match(temp, v, 5, 0xFF, 0xB8)) // MOV EAX,imm
{
data_reg = 0;
this->constant = (v>>8) & 0xFFFFFFFF;
}
else
{
DataWidth xsize;
int ptr_reg = 1, tmp; // ECX
// MOV REG,[ESP+4]
if (do_match(temp, v, 4, 0xFFFFC7FFU, 0x0424448B))
{
ptr_reg = (v>>11)&7;
v = p->readQuad(temp);
}
if (match_MOV_MEM(temp, v, ptr_reg, tmp, this->offset1, xsize)) {
data_reg = tmp;
this->type = ACCESSOR_INDIRECT;
this->dataWidth = xsize;
if (xsize == Data32)
{
v = p->readQuad(temp);
if (match_MOV_MEM(temp, v, data_reg, tmp, this->offset2, xsize)) {
data_reg = tmp;
this->type = ACCESSOR_DOUBLE_INDIRECT;
this->dataWidth = xsize;
}
}
}
}
v = p->readQuad(temp);
if (data_reg == 0 && do_match(temp, v, 1, 0xFF, 0xC3)) // RET
return;
else
{
this->type = ACCESSOR_CONSTANT;
this->constant = 0;
printf("bad accessor @0x%x\n", function);
}
}
bool Accessor::isConstant()
{
if(this->type == ACCESSOR_CONSTANT)
return true;
else
return false;
}
string Accessor::dump()
{
stringstream sstr;
sstr << hex << "method @0x" << method << dec << " ";
switch(type)
{
case ACCESSOR_CONSTANT:
sstr << "Constant: " << dec << constant;
break;
case ACCESSOR_INDIRECT:
switch(dataWidth)
{
case Data32:
sstr << "int32_t ";
break;
case DataSigned16:
sstr << "int16_t ";
break;
case DataUnsigned16:
sstr << "uint16_t ";
break;
default:
sstr << "unknown ";
break;
}
sstr << hex << "[obj + 0x" << offset1 << " ]";
break;
case ACCESSOR_DOUBLE_INDIRECT:
switch(dataWidth)
{
case Data32:
sstr << "int32_t ";
break;
case DataSigned16:
sstr << "int16_t ";
break;
case DataUnsigned16:
sstr << "uint16_t ";
break;
default:
sstr << "unknown ";
break;
}
sstr << hex << "[ [obj + 0x" << offset1 << " ] + 0x" << offset2 << " ]";
break;
}
return sstr.str();
}
int32_t Accessor::getValue(t_item * objectPtr)
{
int32_t offset = this->offset1;
switch(this->type)
{
case ACCESSOR_CONSTANT:
return this->constant;
break;
case ACCESSOR_DOUBLE_INDIRECT:
objectPtr = (t_item *) p->readDWord((uint32_t)objectPtr + this->offset1);
offset = this->offset2;
// fallthrough
case ACCESSOR_INDIRECT:
switch(this->dataWidth)
{
case Data32:
return p->readDWord((uint32_t)objectPtr + offset);
case DataSigned16:
return (int16_t) p->readWord((uint32_t)objectPtr + offset);
case DataUnsigned16:
return (uint16_t) p->readWord((uint32_t)objectPtr + offset);
default:
return -1;
}
break;
default:
return -1;
}
}
// FIXME: turn into a proper factory with caching
Accessor * buildAccessor (OffsetGroup * I, Process * p, const char * name, void * vtable)
{
int32_t offset;
if(I->getSafeOffset(name,offset))
{
return new Accessor( p->readDWord( (uint32_t)vtable + offset ), p);
}
else
{
fprintf(stderr,"Missing offset for item accessor \"%s\"\n", name);
return new Accessor(-1,0); // dummy accessor. always returns -1
}
}
ItemDesc::ItemDesc(void * VTable, Process *p)
{
OffsetGroup * Items = p->getDescriptor()->getGroup("Items");
/*
* FIXME: and what about types, different sets of methods depending on class?
* what about more complex things than constants and integers?
* If this is to be generally useful, it needs much more power.
*/
AMainType = buildAccessor(Items, p, "item_type_accessor", VTable);
ASubType = buildAccessor(Items, p, "item_subtype_accessor", VTable);
ASubIndex = buildAccessor(Items, p, "item_subindex_accessor", VTable);
AIndex = buildAccessor(Items, p, "item_index_accessor", VTable);
AQuality = buildAccessor(Items, p, "item_quality_accessor", VTable);
AWear = buildAccessor(Items, p, "item_wear_accessor", VTable);
AQuantity = buildAccessor(Items, p, "item_quantity_accessor", VTable);
idFieldOffset = Items->getOffset("id");
this->vtable = VTable;
this->p = p;
this->className = p->readClassName((void *) VTable).substr(5);
this->className.resize(this->className.size()-2);
this->hasDecoration = false;
if(AMainType->isConstant())
mainType = this->AMainType->getValue(0);
else
{
cerr << "Bad item main type accessor: " << AMainType->dump() << endl;
mainType = 0;
}
}
string ItemDesc::dumpAccessors()
{
std::stringstream outss;
outss << "MainType :" << AMainType->dump() << endl;
outss << "ASubType :" << ASubType->dump() << endl;
outss << "ASubIndex :" << ASubIndex->dump() << endl;
outss << "AIndex :" << AIndex->dump() << endl;
outss << "AQuality :" << AQuality->dump() << endl;
outss << "AQuantity :" << AQuantity->dump() << endl;
outss << "AWear :" << AWear->dump() << endl;
return outss.str();
}
bool ItemDesc::readItem(t_item * itemptr, DFHack::dfh_item &item)
{
item.base = itemptr;
item.matdesc.itemType = AMainType->getValue(itemptr);
item.matdesc.subType = ASubType->getValue(itemptr);
item.matdesc.subIndex = ASubIndex->getValue(itemptr);
item.matdesc.index = AIndex->getValue(itemptr);
item.quality = AQuality->getValue(itemptr);
item.quantity = AQuantity->getValue(itemptr);
// FIXME: use templates. seriously.
// 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;
}
class Items::Private
{
public:
DFContextShared *d;
Process * owner;
std::map<int32_t, ItemDesc *> descType;
std::map<void *, ItemDesc *> descVTable;
std::map<int32_t, t_item *> idLookupTable;
std::map<int32_t, df_item *> idLookupTable;
uint32_t refVectorOffset;
uint32_t idFieldOffset;
uint32_t itemVectorAddress;
@ -519,16 +150,16 @@ bool Items::Finish()
return true;
}
bool Items::readItemVector(std::vector<t_item *> &items)
bool Items::readItemVector(std::vector<df_item *> &items)
{
std::vector <t_item *> *p_items = (std::vector <t_item *> *) d->itemVectorAddress;
std::vector <df_item *> *p_items = (std::vector <df_item *> *) d->itemVectorAddress;
d->idLookupTable.clear();
items.resize(p_items->size());
for (unsigned i = 0; i < p_items->size(); i++)
{
t_item * ptr = p_items->at(i);
df_item * ptr = p_items->at(i);
items[i] = ptr;
d->idLookupTable[ptr->id] = ptr;
}
@ -536,14 +167,14 @@ bool Items::readItemVector(std::vector<t_item *> &items)
return true;
}
t_item * Items::findItemByID(int32_t id)
df_item * Items::findItemByID(int32_t id)
{
if (id < 0)
return 0;
if (d->idLookupTable.empty())
{
std::vector<t_item *> tmp;
std::vector<df_item *> tmp;
readItemVector(tmp);
}
@ -553,36 +184,23 @@ t_item * Items::findItemByID(int32_t id)
Items::~Items()
{
Finish();
std::map<void *, ItemDesc *>::iterator it;
it = d->descVTable.begin();
while (it != d->descVTable.end())
{
delete (*it).second;
++it;
}
d->descType.clear();
d->descVTable.clear();
delete d;
}
bool Items::readItem(t_item * itembase, DFHack::dfh_item &item)
bool Items::readItem(df_item * itembase, DFHack::dfh_item &item)
{
std::map<void *, ItemDesc *>::iterator it;
Process * p = d->owner;
ItemDesc * desc;
void * vtable = itembase->vptr;
it = d->descVTable.find(vtable);
if(it == d->descVTable.end())
{
desc = new ItemDesc(vtable, p);
d->descVTable[vtable] = desc;
d->descType[desc->mainType] = desc;
}
else
desc = it->second;
return desc->readItem(itembase, item);
if(!itembase)
return false;
df_item * itreal = (df_item *) itembase;
item.base = itembase;
item.matdesc.itemType = itreal->getType();
item.matdesc.subType = itreal->getSubtype();
item.matdesc.index = itreal->getMaterial();
item.matdesc.subIndex = itreal->getSubMaterial();
item.wear_level = itreal->getWear();
item.quality = itreal->getQuality();
item.quantity = itreal->getStackSize();
return true;
}
int32_t Items::getItemOwnerID(const DFHack::dfh_item &item)
@ -670,34 +288,9 @@ bool Items::removeItemOwner(dfh_item &item, Creatures *creatures)
std::string Items::getItemClass(const dfh_item & item)
{
return getItemClass(item.matdesc.itemType);
}
std::string Items::getItemClass(int32_t index)
{
std::map<int32_t, ItemDesc *>::iterator it;
std::string out;
it = d->descType.find(index);
if(it == d->descType.end())
{
/* these are dummy values for mood decoding */
switch(index)
{
case 0: return "bar";
case 1: return "cut gem";
case 2: return "block";
case 3: return "raw gem";
case 4: return "raw stone";
case 5: return "log";
case 54: return "leather";
case 57: return "cloth";
case -1: return "probably bone or shell, but I really don't know";
default: return "unknown";
}
}
out = it->second->className;
return out;
t_virtual * virt = (t_virtual *) item.base;
return virt->getClassName();
//return getItemClass(item.matdesc.itemType);
}
std::string Items::getItemDescription(const dfh_item & item, Materials * Materials)
@ -725,15 +318,6 @@ std::string Items::getItemDescription(const dfh_item & item, Materials * Materia
break;
default: outss << "Crazy quality " << item.quality << " "; break;
}
outss << Materials->getDescription(item.matdesc) << " " << getItemClass(item.matdesc.itemType);
outss << Materials->getDescription(item.matdesc) << " " << getItemClass(item);
return outss.str();
}
/// dump offsets used by accessors of a valid item to a string
std::string Items::dumpAccessors(const dfh_item & item)
{
std::map< void *, ItemDesc* >::const_iterator it = d->descVTable.find(item.base->vptr);
if(it != d->descVTable.end())
return it->second->dumpAccessors();
return "crud";
}

@ -396,8 +396,10 @@ std::string Materials::getDescription(const t_material & mat)
else
if(mat.index<0)
return "any inorganic";
else
else if (mat.index < inorganic.size())
return this->inorganic[mat.index].id;
else
return "INDEX OUT OF BOUNDS!";
}
else
{

@ -78,7 +78,7 @@ DFhackCExport command_result df_autodump (Core * c, vector <string> & parameters
DFHack::Items * Items = c->getItems();
DFHack::Maps *Maps = c->getMaps();
vector <t_item*> p_items;
vector <df_item*> p_items;
if(!Items->readItemVector(p_items))
{
c->con.printerr("Can't access the item vector.\n");
@ -130,7 +130,7 @@ DFhackCExport command_result df_autodump (Core * c, vector <string> & parameters
// proceed with the dumpification operation
for(std::size_t i=0; i< numItems; i++)
{
t_item * itm = p_items[i];
df_item * itm = p_items[i];
DFCoord pos_item(itm->x, itm->y, itm->z);
// keep track how many items are at places. all items.

@ -99,7 +99,7 @@ DFhackCExport command_result df_cleanowned (Core * c, vector <string> & paramete
ok &= Creatures->Start(num_creatures);
ok &= Tran->Start();
vector<t_item *> p_items;
vector<df_item *> p_items;
ok &= Items->readItemVector(p_items);
if(!ok)
{
@ -111,7 +111,7 @@ DFhackCExport command_result df_cleanowned (Core * c, vector <string> & paramete
for (std::size_t i=0; i < p_items.size(); i++)
{
t_item * curItem = p_items[i];
df_item * curItem = p_items[i];
DFHack::dfh_item itm;
Items->readItem(curItem, itm);
@ -132,7 +132,7 @@ DFhackCExport command_result df_cleanowned (Core * c, vector <string> & paramete
}
}
std::string name = Items->getItemClass(itm.matdesc.itemType);
std::string name = Items->getItemClass(itm);
if (itm.base->flags.rotten)
{

@ -187,7 +187,7 @@ DFhackCExport command_result df_dumpitems (Core * c, vector <string> & parameter
int32_t x,y,z;
Gui->getCursorCoords(x,y,z);
std::vector<t_item *> p_items;
std::vector<df_item *> p_items;
Items->readItemVector(p_items);
uint32_t size = p_items.size();
@ -231,13 +231,12 @@ DFhackCExport command_result df_dumpitems (Core * c, vector <string> & parameter
c->con.print(
"%5d: addr:0x%08x %6d %08x (%s) vptr:0x%08x [%d]\n"
" *%d %s - %s\n",
" %d %s\n",
i, itm.base, itm.base->id, itm.base->flags.whole,
location,
itm.base->vptr,
((t_virtual *)itm.base)->vptr,
itm.wear_level,
itm.quantity,
Items->getItemClass(itm.matdesc.itemType).c_str(),
Items->getItemDescription(itm, Materials).c_str()
);
chooser->postPrint(&itm);

@ -109,7 +109,7 @@ DFhackCExport command_result plugin_onupdate ( Core * c )
DFhackCExport command_result mapitems (Core * c, vector <string> & parameters)
{
c->Suspend();
vector <t_item *> vec_items;
vector <df_item *> vec_items;
Gui * g = c-> getGui();
Maps* m = c->getMaps();
Items* it = c->getItems();
@ -141,7 +141,7 @@ DFhackCExport command_result mapitems (Core * c, vector <string> & parameters)
auto iter_it = vec_items.begin();
while (iter_it != vec_items.end())
{
t_item * itm = *iter_it;
df_item * itm = *iter_it;
if(itm->x == cx && itm->y == cy && itm->z == cz)
{
c->con.print("%d\n",itm->id);

@ -94,7 +94,7 @@ int main (int argc, char *argv[])
itm.base.vtable,
itm.wear_level,
itm.quantity,
Items->getItemClass(itm.matdesc.itemType).c_str(),
Items->getItemClass(itm).c_str(),
Items->getItemDescription(itm, Materials).c_str()
);