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

@ -83,7 +83,6 @@ namespace DFHack
class DFHACK_EXPORT Materials
{
public:
Materials(DFHack::APIPrivate * _d);
~Materials();

@ -116,10 +116,16 @@ Accessor::Accessor(uint32_t function, Process *p)
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)
{
case ACCESSOR_CONSTANT:
@ -161,13 +167,21 @@ ItemDesc::ItemDesc(uint32_t VTable, Process *p)
uint32_t funcOffsetQuality = p->getDescriptor()->getOffset("item_quality_accessor");
this->vtable = VTable;
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->ASubType = new Accessor( p->readDWord( VTable + funcOffsetB ), p);
this->ASubIndex = new Accessor( p->readDWord( VTable + funcOffsetC ), p);
this->AIndex = new Accessor( p->readDWord( VTable + funcOffsetD ), p);
this->AQuality = new Accessor( p->readDWord( VTable + funcOffsetQuality ), p);
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)
@ -176,8 +190,6 @@ bool ItemDesc::getItem(uint32_t itemptr, DFHack::t_item &item)
item.matdesc.subType = this->ASubType->getValue(itemptr);
item.matdesc.subIndex = this->ASubIndex->getValue(itemptr);
item.matdesc.index = this->AIndex->getValue(itemptr);
if(item.matdesc.index == 0xffff)
printf("wtf");
item.quality = this->AQuality->getValue(itemptr);
item.quantity = 1; /* TODO */
return true;
@ -195,6 +207,7 @@ bool Items::getItemData(uint32_t itemptr, DFHack::t_item &item)
uint32_t vtable = p->readDWord(itemptr);
desc = new ItemDesc(vtable, p);
this->descVTable[vtable] = desc;
this->descType[desc->mainType] = desc;
}
else
desc = it->second;
@ -202,12 +215,37 @@ bool Items::getItemData(uint32_t itemptr, DFHack::t_item &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;
std::string out;
if(!this->getItemData(itemptr, item))
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,65 +347,51 @@ void Materials::ReadAllMaterials(void)
std::string Materials::getDescription(t_material & mat)
{
std::string out;
int32_t typeC;
switch(mat.itemType)
if ( (mat.subIndex<419) || (mat.subIndex>618) )
{
case 0:
if(mat.index>=0)
if ( (mat.subIndex<19) || (mat.subIndex>218) )
{
if(uint32_t(mat.index) <= this->inorganic.size())
if (mat.subIndex)
if (mat.subIndex>0x292)
return "?";
else
{
if (mat.subIndex>=this->other.size())
{
out.append(this->inorganic[mat.index].id);
out.append(" bar");
if(mat.subIndex>=this->raceEx.size())
return "stuff";
else
return this->raceEx[mat.subIndex].rawname;
}
else
out = "invalid bar";
{
if (mat.index==-1)
return std::string(this->other[mat.subIndex].rawname);
else
return std::string(this->other[mat.subIndex].rawname) + " derivate";
}
}
else
return this->inorganic[mat.index].id;
}
else
out = "any metal bar";
break;
case 1:
out = "cut gem";
break;
case 2:
out = "block";
break;
case 3:
switch(mat.subType)
{
case 3: out = "raw green glass"; break;
case 4: out = "raw clear glass"; break;
case 5: out = "raw crystal glass"; break;
default: out = "raw gems"; break;
if (mat.index>=this->raceEx.size())
return "unknown race";
typeC = mat.subIndex;
typeC -=19;
if ((typeC<0) || (typeC>=this->raceEx[mat.index].extract.size()))
{
return string(this->raceEx[mat.index].rawname).append(" extract");
}
break;
case 4:
out = "raw stone";
break;
case 5:
out = "wood log";
break;
case 24:
out = "weapon?";
break;
case 26:
out = "footwear";
break;
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 std::string(this->raceEx[mat.index].rawname).append(" ").append(this->raceEx[mat.index].extract[typeC].rawname);
}
}
else
{
return this->organic[mat.index].id;
}
return out;
}

@ -22,55 +22,13 @@ using namespace std;
DFHack::Materials * Materials;
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;
}
}
DFHack::Items * Items;
int main ()
{
DFHack::API DF("Memory.xml");
DFHack::Process * p;
unsigned int i,j;
DFHack::Items * Items;
try
{
@ -193,10 +151,11 @@ int main ()
printf("bad typeD func @%p\n", (void*) funcD);
// 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,
typeB, typeC, typeD, getMatDesc(typeB, typeC, typeD).c_str());
printf("%d\t%p\t%s\t%d\t[%d,%d,%d]", type, (void*)vtable, desc.c_str(), quality,
typeB, typeC, typeD);
printf("\t%s", Items->getItemDescription(p_items[i], Materials).c_str());
// 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);
if (hasDecorations)
{
@ -223,7 +182,7 @@ int main ()
printf("bad decoration type function, address=%p\n", (void*) dtypefunc);
if (sep)
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;
}
}