Debugging the material access system : seems to work now

develop
U-glouglou\simon 2010-05-02 11:27:16 +02:00
parent 663d5894b8
commit 2e61410fb4
11 changed files with 143 additions and 134 deletions

@ -31,6 +31,7 @@ APIPrivate::APIPrivate()
vegetation = 0;
buildings = 0;
constructions = 0;
items = 0;
}
APIPrivate::~APIPrivate()

@ -37,6 +37,7 @@ distribution.
#include "modules/Maps.h"
#include "modules/Materials.h"
#include "modules/Items.h"
#include "modules/Position.h"
#include "modules/Gui.h"
#include "modules/Creatures.h"
@ -148,6 +149,11 @@ bool API::Detach()
delete d->materials;
d->materials = 0;
}
if(d->items)
{
delete d->items;
d->items = 0;
}
if(d->gui)
{
delete d->gui;
@ -265,6 +271,13 @@ Materials * API::getMaterials()
return d->materials;
}
Items * API::getItems()
{
if(!d->items)
d->items = new Items(d);
return d->items;
}
Translation * API::getTranslation()
{
if(!d->translation)

@ -52,6 +52,7 @@ namespace DFHack
class Vegetation;
class Buildings;
class Constructions;
class Items;
class DFHACK_EXPORT API
{
@ -104,6 +105,9 @@ namespace DFHack
// get the materials module
Materials * getMaterials();
// get the items module
Items * getItems();
// get the translation module
Translation * getTranslation();

@ -169,34 +169,6 @@ union t_itemflags
};
//cooked
struct t_item
{
uint32_t origin;
uint32_t vtable;
uint32_t x;
uint32_t y;
uint32_t z;
t_itemflags flags;
uint32_t ID;
uint32_t type;
t_matglossPair material;
/*
uint8_t matType;
uint8_t material;
*/
// vector<uint8_t> bytes; used for item research
// FIXME: not complete, we need building presence bitmaps for stuff like farm plots and stockpiles, orientation (N,E,S,W) and state (open/closed)
};
// can add more here later, but this is fine for now
struct t_itemType
{
char id[128];
char name[128];
};
struct t_viewscreen
{
int32_t type;

@ -98,6 +98,13 @@ Accessor::Accessor(uint32_t function, Process *p)
return;
}
}
if( (funcText&0xFFFFFF0000FFFFFFLL) == 0xC30000000081BF0FLL )
{
/* movsx eax, word ptr [ecx+xx]; ret */
this->type = ACCESSOR_INDIRECT;
this->offset1 = (funcText>>24) & 0xffff;
return;
}
if( (funcText&0xFFFFFFFF0000FFFFLL) == 0xCCC300000000818BLL )
{
/* mov eax, [ecx+xx]; ret; */
@ -111,6 +118,8 @@ Accessor::Accessor(uint32_t function, Process *p)
int32_t Accessor::getValue(uint32_t objectPtr)
{
int32_t sout;
switch(this->type)
{
case ACCESSOR_CONSTANT:
@ -120,7 +129,7 @@ int32_t Accessor::getValue(uint32_t objectPtr)
switch(this->dataWidth)
{
case 2:
return p->readWord(objectPtr + this->offset1);
return (int16_t) p->readWord(objectPtr + this->offset1);
case 4:
return p->readDWord(objectPtr + this->offset1);
default:
@ -131,7 +140,7 @@ int32_t Accessor::getValue(uint32_t objectPtr)
switch(this->dataWidth)
{
case 2:
return p->readWord(p->readDWord(objectPtr + this->offset1) + this->offset2);
return (int16_t) p->readWord(p->readDWord(objectPtr + this->offset1) + this->offset2);
case 4:
return p->readDWord(p->readDWord(objectPtr + this->offset1) + this->offset2);
default:
@ -167,6 +176,8 @@ 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;

@ -36,6 +36,7 @@ namespace DFHack
class Position;
class Maps;
class Creatures;
class Items;
class Translation;
class Buildings;
class ProcessEnumerator;
@ -71,6 +72,7 @@ namespace DFHack
Position * position;
Gui * gui;
Materials * materials;
Items * items;
Translation * translation;
Vegetation * vegetation;
Buildings * buildings;

@ -148,12 +148,12 @@ static PyObject* BuildAttribute(DFHack::t_attrib& at)
return attrObj;
}
/*
static PyObject* BuildItemType(DFHack::t_itemType& item)
{
return Py_BuildValue("ss", item.id, item.name);
}
*/
static PyObject* BuildLike(DFHack::t_like& like)
{
PyObject* item;

@ -27,7 +27,6 @@ enum likeType
};
DFHack::Materials * Materials;
vector< vector <DFHack::t_itemType> > itemTypes;
DFHack::memory_info *mem;
vector< vector<string> > englishWords;
vector< vector<string> > foreignWords;

@ -18,6 +18,7 @@ using namespace std;
#include <DFProcess.h>
#include <DFVector.h>
#include <modules/Materials.h>
#include <modules/Items.h>
DFHack::Materials * Materials;
@ -69,6 +70,7 @@ int main ()
DFHack::API DF("Memory.xml");
DFHack::Process * p;
unsigned int i,j;
DFHack::Items * Items;
try
{
@ -89,6 +91,7 @@ int main ()
p = DF.getProcess();
DFHack::DfVector <uint32_t> p_items (p, p->getDescriptor()->getAddress ("items_vector"));
uint32_t size = p_items.size();
Items = DF.getItems();
printf("type\tvtable\tname\tquality\tdecorate\n");
@ -115,6 +118,9 @@ int main ()
uint32_t quality = 0;
bool hasDecorations;
string desc = p->readClassName(vtable);
DFHack::t_item itm;
Items->getItemData(p_items[i], itm);
if ( (funct0&0xFFFFFFFFFF000000LL) != 0xCCCCC30000000000LL )
{
@ -190,6 +196,8 @@ int main ()
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("\t%p\t%.16LX", (void *) funcD, funcDt);
if( (type!=itm.matdesc.itemType) || (typeB!=itm.matdesc.subType) || (typeC!=itm.matdesc.subIndex) || (typeD!=itm.matdesc.index) )
printf("\tbad[%d,%d,%d,%d]", itm.matdesc.itemType, itm.matdesc.subType, itm.matdesc.subIndex, itm.matdesc.index);
if (hasDecorations)
{
bool sep = false;

@ -16,7 +16,6 @@ using namespace std;
#include <modules/Translation.h>
DFHack::Materials * Materials;
vector< vector <DFHack::t_itemType> > itemTypes;
DFHack::memory_info *mem;
vector< vector<string> > englishWords;
vector< vector<string> > foreignWords;