A bit of debugging done, and the Items::getItemDescription is finally here !

develop
U-glouglou\simon 2010-05-02 12:50:51 +02:00
parent 2e61410fb4
commit f4d6836a85
5 changed files with 138 additions and 153 deletions

@ -23,6 +23,7 @@ public:
Accessor(uint32_t function, Process * p); Accessor(uint32_t function, Process * p);
Accessor(accessor_type type, int32_t constant, uint32_t offset1, uint32_t offset2, uint32_t dataWidth, Process * p); Accessor(accessor_type type, int32_t constant, uint32_t offset1, uint32_t offset2, uint32_t dataWidth, Process * p);
int32_t getValue(uint32_t objectPtr); int32_t getValue(uint32_t objectPtr);
bool isConstant();
}; };
struct t_item struct t_item
@ -47,6 +48,7 @@ public:
bool getItem(uint32_t itemptr, t_item & item); bool getItem(uint32_t itemptr, t_item & item);
std::string className; std::string className;
uint32_t vtable; uint32_t vtable;
uint32_t mainType;
}; };
class DFHACK_EXPORT Items class DFHACK_EXPORT Items
@ -54,12 +56,13 @@ class DFHACK_EXPORT Items
public: public:
Items(DFHack::APIPrivate * _d); Items(DFHack::APIPrivate * _d);
~Items(); ~Items();
std::string getItemDescription(uint32_t itemptr); std::string getItemDescription(uint32_t itemptr, Materials * Materials);
std::string getItemClass(int32_t index);
bool getItemData(uint32_t itemptr, t_item & item); bool getItemData(uint32_t itemptr, t_item & item);
private: private:
class Private; class Private;
Private* d; Private* d;
/*std::map<int32_t, ItemDesc *> descType; might be useful later */ std::map<int32_t, ItemDesc *> descType;
std::map<uint32_t, ItemDesc *> descVTable; std::map<uint32_t, ItemDesc *> descVTable;
}; };
} }

@ -82,47 +82,46 @@ namespace DFHack
class DFHACK_EXPORT Materials class DFHACK_EXPORT Materials
{ {
public: public:
Materials(DFHack::APIPrivate * _d);
Materials(DFHack::APIPrivate * _d); ~Materials();
~Materials();
std::vector<t_matgloss> inorganic; std::vector<t_matgloss> inorganic;
std::vector<t_matgloss> organic; std::vector<t_matgloss> organic;
std::vector<t_matgloss> tree; std::vector<t_matgloss> tree;
std::vector<t_matgloss> plant; std::vector<t_matgloss> plant;
std::vector<t_matgloss> race; std::vector<t_matgloss> race;
std::vector<t_creaturetype> raceEx; std::vector<t_creaturetype> raceEx;
std::vector<t_descriptor_color> color; std::vector<t_descriptor_color> color;
std::vector<t_matglossOther> other; std::vector<t_matglossOther> other;
bool ReadInorganicMaterials (void);
bool ReadOrganicMaterials (void);
bool ReadWoodMaterials (void);
bool ReadPlantMaterials (void);
bool ReadCreatureTypes (void);
bool ReadCreatureTypesEx (void);
bool ReadDescriptorColors(void);
bool ReadOthers (void);
void ReadAllMaterials(void); bool ReadInorganicMaterials (void);
bool ReadOrganicMaterials (void);
bool ReadWoodMaterials (void);
bool ReadPlantMaterials (void);
bool ReadCreatureTypes (void);
bool ReadCreatureTypesEx (void);
bool ReadDescriptorColors(void);
bool ReadOthers (void);
std::string getDescription(t_material & mat); void ReadAllMaterials(void);
/*
bool ReadInorganicMaterials (std::vector<t_matgloss> & output); std::string getDescription(t_material & mat);
bool ReadOrganicMaterials (std::vector<t_matgloss> & output); /*
bool ReadWoodMaterials (std::vector<t_matgloss> & output); bool ReadInorganicMaterials (std::vector<t_matgloss> & output);
bool ReadPlantMaterials (std::vector<t_matgloss> & output); bool ReadOrganicMaterials (std::vector<t_matgloss> & output);
bool ReadWoodMaterials (std::vector<t_matgloss> & output);
// TODO: maybe move to creatures? bool ReadPlantMaterials (std::vector<t_matgloss> & output);
bool ReadCreatureTypes (std::vector<t_matgloss> & output);
bool ReadCreatureTypesEx (vector<t_creaturetype> & creatures); // TODO: maybe move to creatures?
bool ReadDescriptorColors(std::vector<t_descriptor_color> & output); bool ReadCreatureTypes (std::vector<t_matgloss> & output);
*/ bool ReadCreatureTypesEx (vector<t_creaturetype> & creatures);
private: bool ReadDescriptorColors(std::vector<t_descriptor_color> & output);
class Private; */
Private* d; private:
}; class Private;
Private* d;
};
} }
#endif #endif

@ -116,10 +116,16 @@ Accessor::Accessor(uint32_t function, Process *p)
printf("bad accessor @0x%x\n", function); printf("bad accessor @0x%x\n", function);
} }
int32_t Accessor::getValue(uint32_t objectPtr) bool Accessor::isConstant()
{ {
int32_t sout; if(this->type == ACCESSOR_CONSTANT)
return true;
else
return false;
}
int32_t Accessor::getValue(uint32_t objectPtr)
{
switch(this->type) switch(this->type)
{ {
case ACCESSOR_CONSTANT: case ACCESSOR_CONSTANT:
@ -161,13 +167,21 @@ ItemDesc::ItemDesc(uint32_t VTable, Process *p)
uint32_t funcOffsetQuality = p->getDescriptor()->getOffset("item_quality_accessor"); uint32_t funcOffsetQuality = p->getDescriptor()->getOffset("item_quality_accessor");
this->vtable = VTable; this->vtable = VTable;
this->p = p; this->p = p;
this->className = p->readClassName(VTable); this->className = p->readClassName(VTable).substr(5);
this->className.resize(this->className.size()-2);
this->AMainType = new Accessor( p->readDWord( VTable + funcOffsetA ), p); this->AMainType = new Accessor( p->readDWord( VTable + funcOffsetA ), p);
this->ASubType = new Accessor( p->readDWord( VTable + funcOffsetB ), p); this->ASubType = new Accessor( p->readDWord( VTable + funcOffsetB ), 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->hasDecoration = false; this->hasDecoration = false;
if(this->AMainType->isConstant())
this->mainType = this->AMainType->getValue(0);
else
{
fprintf(stderr, "Bad item main type at function %p\n", (void*) p->readDWord( VTable + funcOffsetA ));
this->mainType = 0;
}
} }
bool ItemDesc::getItem(uint32_t itemptr, DFHack::t_item &item) bool ItemDesc::getItem(uint32_t itemptr, DFHack::t_item &item)
@ -176,8 +190,6 @@ bool ItemDesc::getItem(uint32_t itemptr, DFHack::t_item &item)
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);
if(item.matdesc.index == 0xffff)
printf("wtf");
item.quality = this->AQuality->getValue(itemptr); item.quality = this->AQuality->getValue(itemptr);
item.quantity = 1; /* TODO */ item.quantity = 1; /* TODO */
return true; return true;
@ -195,6 +207,7 @@ bool Items::getItemData(uint32_t itemptr, DFHack::t_item &item)
uint32_t vtable = p->readDWord(itemptr); uint32_t vtable = p->readDWord(itemptr);
desc = new ItemDesc(vtable, p); desc = new ItemDesc(vtable, p);
this->descVTable[vtable] = desc; this->descVTable[vtable] = desc;
this->descType[desc->mainType] = desc;
} }
else else
desc = it->second; desc = it->second;
@ -202,12 +215,37 @@ bool Items::getItemData(uint32_t itemptr, DFHack::t_item &item)
return desc->getItem(itemptr, item); return desc->getItem(itemptr, item);
} }
std::string Items::getItemDescription(uint32_t itemptr) std::string Items::getItemClass(int32_t index)
{
std::map<int32_t, ItemDesc *>::iterator it;
std::string out;
it = this->descType.find(index);
if(it==this->descType.end())
return "unknown";
out = it->second->className;
return out;
}
std::string Items::getItemDescription(uint32_t itemptr, Materials * Materials)
{ {
DFHack::t_item item; DFHack::t_item item;
std::string out; std::string out;
if(!this->getItemData(itemptr, item)) if(!this->getItemData(itemptr, item))
return "??"; return "??";
return "!!"; switch(item.quality)
{
case 0: break;
case 1: out.append("Well crafted "); break;
case 2: out.append("Finely crafted "); break;
case 3: out.append("Superior quality "); break;
case 4: out.append("Exceptionnal "); break;
case 5: out.append("Masterful "); break;
default: out.append("Crazy quality "); break;
}
out.append(Materials->getDescription(item.matdesc));
out.append(" ");
out.append(this->getItemClass(item.matdesc.itemType));
return out;
} }

@ -347,66 +347,52 @@ void Materials::ReadAllMaterials(void)
std::string Materials::getDescription(t_material & mat) std::string Materials::getDescription(t_material & mat)
{ {
std::string out; std::string out;
int32_t typeC;
switch(mat.itemType) if ( (mat.subIndex<419) || (mat.subIndex>618) )
{ {
case 0: if ( (mat.subIndex<19) || (mat.subIndex>218) )
if(mat.index>=0) {
{ if (mat.subIndex)
if(uint32_t(mat.index) <= this->inorganic.size()) if (mat.subIndex>0x292)
{ return "?";
out.append(this->inorganic[mat.index].id); else
out.append(" bar"); {
} if (mat.subIndex>=this->other.size())
else {
out = "invalid bar"; if(mat.subIndex>=this->raceEx.size())
} return "stuff";
else else
out = "any metal bar"; return this->raceEx[mat.subIndex].rawname;
break; }
case 1: else
out = "cut gem"; {
break; if (mat.index==-1)
case 2: return std::string(this->other[mat.subIndex].rawname);
out = "block"; else
break; return std::string(this->other[mat.subIndex].rawname) + " derivate";
case 3: }
switch(mat.subType) }
{ else
case 3: out = "raw green glass"; break; return this->inorganic[mat.index].id;
case 4: out = "raw clear glass"; break; }
case 5: out = "raw crystal glass"; break; else
default: out = "raw gems"; break; {
} if (mat.index>=this->raceEx.size())
break; return "unknown race";
case 4: typeC = mat.subIndex;
out = "raw stone"; typeC -=19;
break; if ((typeC<0) || (typeC>=this->raceEx[mat.index].extract.size()))
case 5: {
out = "wood log"; return string(this->raceEx[mat.index].rawname).append(" extract");
break; }
case 24: return std::string(this->raceEx[mat.index].rawname).append(" ").append(this->raceEx[mat.index].extract[typeC].rawname);
out = "weapon?"; }
break; }
case 26: else
out = "footwear"; {
break; return this->organic[mat.index].id;
case 28: }
out = "headwear";
break;
case 54:
out = "leather";
break;
case 57:
out = "cloth";
break;
case 71:
out = "food";
break;
default:
out = "unknown";
break;
}
return out; return out;
} }

@ -22,55 +22,13 @@ using namespace std;
DFHack::Materials * Materials; DFHack::Materials * Materials;
DFHack::Items * Items;
std::string getMatDesc(int32_t typeB, int32_t typeC, int32_t typeD)
{
if ( (typeC<419) || (typeC>618) )
{
if ( (typeC<19) || (typeC>218) )
{
if (typeC)
if (typeC>0x292)
return "?";
else
{
if (typeC>=Materials->other.size())
return "stuff";
else
{
if (typeD==-1)
return std::string(Materials->other[typeC].rawname);
else
return std::string(Materials->other[typeC].rawname) + " derivate";
}
}
else
return Materials->inorganic[typeD].id;
}
else
{
if (typeD>=Materials->raceEx.size())
return "unknown race";
typeC-=19;
if ((typeC<0) || (typeC>=Materials->raceEx[typeD].extract.size()))
{
return string(Materials->raceEx[typeD].rawname).append(" extract");
}
return std::string(Materials->raceEx[typeD].rawname).append(" ").append(Materials->raceEx[typeD].extract[typeC].rawname);
}
}
else
{
return Materials->organic[typeD].id;
}
}
int main () int main ()
{ {
DFHack::API DF("Memory.xml"); DFHack::API DF("Memory.xml");
DFHack::Process * p; DFHack::Process * p;
unsigned int i,j; unsigned int i,j;
DFHack::Items * Items;
try try
{ {
@ -193,10 +151,11 @@ int main ()
printf("bad typeD func @%p\n", (void*) funcD); printf("bad typeD func @%p\n", (void*) funcD);
// printf("%p\t%.16LX\t", (void*) func2, funct2); // printf("%p\t%.16LX\t", (void*) func2, funct2);
printf("%d\t%p\t%s\t%d\t[%d,%d,%d -> %s]", type, (void*)vtable, desc.c_str(), quality, printf("%d\t%p\t%s\t%d\t[%d,%d,%d]", type, (void*)vtable, desc.c_str(), quality,
typeB, typeC, typeD, getMatDesc(typeB, typeC, typeD).c_str()); typeB, typeC, typeD);
printf("\t%s", Items->getItemDescription(p_items[i], Materials).c_str());
// printf("\t%p\t%.16LX", (void *) funcD, funcDt); // printf("\t%p\t%.16LX", (void *) funcD, funcDt);
if( (type!=itm.matdesc.itemType) || (typeB!=itm.matdesc.subType) || (typeC!=itm.matdesc.subIndex) || (typeD!=itm.matdesc.index) ) if( (type!=itm.matdesc.itemType) || (typeB!=itm.matdesc.subType) || (typeC!=itm.matdesc.subIndex) || (typeD!=itm.matdesc.index) || (quality!=itm.quality) )
printf("\tbad[%d,%d,%d,%d]", itm.matdesc.itemType, itm.matdesc.subType, itm.matdesc.subIndex, itm.matdesc.index); printf("\tbad[%d,%d,%d,%d]", itm.matdesc.itemType, itm.matdesc.subType, itm.matdesc.subIndex, itm.matdesc.index);
if (hasDecorations) if (hasDecorations)
{ {
@ -223,7 +182,7 @@ int main ()
printf("bad decoration type function, address=%p\n", (void*) dtypefunc); printf("bad decoration type function, address=%p\n", (void*) dtypefunc);
if (sep) if (sep)
printf(","); printf(",");
printf("%s[t=%d,q=%d,%s{%d,%d}]", ddesc.c_str(), dtype, dqual, getMatDesc(-1, dtypeC, dtypeD).c_str(), dtypeC, dtypeD); //printf("%s[t=%d,q=%d,%s{%d,%d}]", ddesc.c_str(), dtype, dqual, getMatDesc(-1, dtypeC, dtypeD).c_str(), dtypeC, dtypeD);
sep = true; sep = true;
} }
} }