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
{
@ -103,6 +104,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;

@ -1,66 +1,66 @@
#ifndef CL_MOD_ITEMS
#define CL_MOD_ITEMS
/*
* Creatures
*/
#include "Export.h"
namespace DFHack
{
enum accessor_type {ACCESSOR_CONSTANT, ACCESSOR_INDIRECT, ACCESSOR_DOUBLE_INDIRECT};
/* this is used to store data about the way accessors work */
class DFHACK_EXPORT Accessor
{
private:
accessor_type type;
int32_t constant;
uint32_t offset1;
uint32_t offset2;
Process * p;
uint32_t dataWidth;
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);
};
struct t_item
{
t_material matdesc;
int32_t quantity;
int32_t quality;
};
class DFHACK_EXPORT ItemDesc
{
private:
Accessor * AMainType;
Accessor * ASubType;
Accessor * ASubIndex;
Accessor * AIndex;
Accessor * AQuality;
Process * p;
bool hasDecoration;
public:
ItemDesc(uint32_t VTable, Process * p);
bool getItem(uint32_t itemptr, t_item & item);
std::string className;
uint32_t vtable;
};
class DFHACK_EXPORT Items
{
public:
Items(DFHack::APIPrivate * _d);
~Items();
std::string getItemDescription(uint32_t itemptr);
bool getItemData(uint32_t itemptr, t_item & item);
#ifndef CL_MOD_ITEMS
#define CL_MOD_ITEMS
/*
* Creatures
*/
#include "Export.h"
namespace DFHack
{
enum accessor_type {ACCESSOR_CONSTANT, ACCESSOR_INDIRECT, ACCESSOR_DOUBLE_INDIRECT};
/* this is used to store data about the way accessors work */
class DFHACK_EXPORT Accessor
{
private:
accessor_type type;
int32_t constant;
uint32_t offset1;
uint32_t offset2;
Process * p;
uint32_t dataWidth;
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);
};
struct t_item
{
t_material matdesc;
int32_t quantity;
int32_t quality;
};
class DFHACK_EXPORT ItemDesc
{
private:
Accessor * AMainType;
Accessor * ASubType;
Accessor * ASubIndex;
Accessor * AIndex;
Accessor * AQuality;
Process * p;
bool hasDecoration;
public:
ItemDesc(uint32_t VTable, Process * p);
bool getItem(uint32_t itemptr, t_item & item);
std::string className;
uint32_t vtable;
};
class DFHACK_EXPORT Items
{
public:
Items(DFHack::APIPrivate * _d);
~Items();
std::string getItemDescription(uint32_t itemptr);
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<uint32_t, ItemDesc *> descVTable;
};
}
#endif
Private* d;
/*std::map<int32_t, ItemDesc *> descType; might be useful later */
std::map<uint32_t, ItemDesc *> descVTable;
};
}
#endif

@ -1,37 +1,37 @@
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#include "DFCommonInternal.h"
#include "../private/APIPrivate.h"
#include "modules/Materials.h"
#include "modules/Items.h"
#include "DFMemInfo.h"
#include "DFProcess.h"
#include "DFVector.h"
using namespace DFHack;
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#include "DFCommonInternal.h"
#include "../private/APIPrivate.h"
#include "modules/Materials.h"
#include "modules/Items.h"
#include "DFMemInfo.h"
#include "DFProcess.h"
#include "DFVector.h"
using namespace DFHack;
class Items::Private
{
public:
@ -41,8 +41,8 @@ class Items::Private
bool Inited;
bool Started;
*/
};
};
Items::Items(APIPrivate * d_)
{
d = new Private;
@ -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;