Merge remote branch 'upstream/master'

develop
doomchild 2010-05-10 14:51:17 -05:00
commit a797933de1
19 changed files with 650 additions and 206 deletions

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

@ -36,6 +36,7 @@ depends/tinyxml/tinyxmlparser.cpp
modules/Creatures.cpp
modules/Gui.cpp
modules/Items.cpp
modules/Maps.cpp
modules/Materials.cpp
modules/Position.cpp

@ -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;

@ -265,7 +265,7 @@ namespace DFHack
bool active;
uint32_t jobId;
uint8_t jobType;
uint32_t occupationPtr;
uint32_t occupationPtr;
};
struct t_like
{
@ -315,6 +315,8 @@ namespace DFHack
t_attrib social_awareness;
};
#define MAX_COLORS 15
struct t_creature
{
uint32_t origin;
@ -349,10 +351,13 @@ namespace DFHack
t_attrib recuperation;
t_attrib disease_resistance;
int32_t squad_leader_id;
uint8_t sex; // really a caste
uint8_t sex;
uint16_t caste;
uint32_t pregnancy_timer; //Countdown timer to giving birth
bool has_default_soul;
t_soul defaultSoul;
uint32_t nbcolors;
uint32_t color[MAX_COLORS];
};
class APIPrivate;

@ -0,0 +1,88 @@
#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);
bool isConstant();
};
struct t_item
{
t_material matdesc;
int32_t quantity;
int32_t quality;
};
struct t_improvement
{
t_material matdesc;
int32_t quality;
};
class DFHACK_EXPORT 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 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;
uint32_t mainType;
std::vector<ItemImprovementDesc> improvement;
};
class DFHACK_EXPORT Items
{
public:
Items(DFHack::APIPrivate * _d);
~Items();
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;
std::map<uint32_t, ItemDesc *> descVTable;
};
}
#endif

@ -38,12 +38,28 @@ namespace DFHack
char extract_name[128];
};
struct t_bodypart
{
char id[128];
char category[128];
char single[128];
char plural[128];
};
struct t_colormodifier
{
char part[128];
std::vector<uint32_t> colorlist;
};
struct t_creaturecaste
{
char rawname[128];
char singular[128];
char plural[128];
char adjective[128];
std::vector<t_colormodifier> ColorModifier;
std::vector<t_bodypart> bodypart;
};
struct t_matglossOther
@ -74,55 +90,55 @@ namespace DFHack
struct t_material
{
int16_t itemType;
int16_t typeB;
int16_t subType;
int16_t subIndex;
int32_t index;
uint32_t flags;
};
class DFHACK_EXPORT Materials
{
public:
Materials(DFHack::APIPrivate * _d);
~Materials();
std::vector<t_matgloss> inorganic;
std::vector<t_matgloss> organic;
std::vector<t_matgloss> tree;
std::vector<t_matgloss> plant;
std::vector<t_matgloss> race;
std::vector<t_creaturetype> raceEx;
std::vector<t_descriptor_color> color;
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);
std::string getDescription(t_material & mat);
/*
bool ReadInorganicMaterials (std::vector<t_matgloss> & output);
bool ReadOrganicMaterials (std::vector<t_matgloss> & output);
bool ReadWoodMaterials (std::vector<t_matgloss> & output);
bool ReadPlantMaterials (std::vector<t_matgloss> & output);
// TODO: maybe move to creatures?
bool ReadCreatureTypes (std::vector<t_matgloss> & output);
bool ReadCreatureTypesEx (vector<t_creaturetype> & creatures);
bool ReadDescriptorColors(std::vector<t_descriptor_color> & output);
*/
private:
class Private;
Private* d;
};
public:
Materials(DFHack::APIPrivate * _d);
~Materials();
std::vector<t_matgloss> inorganic;
std::vector<t_matgloss> organic;
std::vector<t_matgloss> tree;
std::vector<t_matgloss> plant;
std::vector<t_matgloss> race;
std::vector<t_creaturetype> raceEx;
std::vector<t_descriptor_color> color;
std::vector<t_matglossOther> other;
std::vector<t_matgloss> alldesc;
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);
std::string getDescription(t_material & mat);
/*
bool ReadInorganicMaterials (std::vector<t_matgloss> & output);
bool ReadOrganicMaterials (std::vector<t_matgloss> & output);
bool ReadWoodMaterials (std::vector<t_matgloss> & output);
bool ReadPlantMaterials (std::vector<t_matgloss> & output);
// TODO: maybe move to creatures?
bool ReadCreatureTypes (std::vector<t_matgloss> & output);
bool ReadCreatureTypesEx (vector<t_creaturetype> & creatures);
bool ReadDescriptorColors(std::vector<t_descriptor_color> & output);
*/
private:
class Private;
Private* d;
};
}
#endif

@ -81,6 +81,7 @@ Creatures::Creatures(APIPrivate* _d)
creatures.flags2_offset = minfo->getOffset ("creature_flags2");
creatures.name_offset = minfo->getOffset ("creature_name");
creatures.sex_offset = minfo->getOffset ("creature_sex");
creatures.caste_offset = minfo->getOffset ("creature_caste");
creatures.id_offset = minfo->getOffset ("creature_id");
creatures.labors_offset = minfo->getOffset ("creature_labors");
creatures.happiness_offset = minfo->getOffset ("creature_happiness");
@ -97,6 +98,9 @@ Creatures::Creatures(APIPrivate* _d)
creatures.soul_mental_offset = minfo->getOffset("soul_mental");
creatures.soul_traits_offset = minfo->getOffset("soul_traits");
// appearance
creatures.appearance_vector_offset = minfo->getOffset("creature_appearance_vector");
// name offsets for the creature module
creatures.name_firstname_offset = minfo->getOffset("name_firstname");
creatures.name_nickname_offset = minfo->getOffset("name_nickname");
@ -179,6 +183,7 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
p->readDWord (temp + offs.race_offset, furball.race);
furball.civ = p->readDWord (temp + offs.civ_offset);
p->readByte (temp + offs.sex_offset, furball.sex);
p->readWord (temp + offs.caste_offset, furball.caste);
p->readDWord (temp + offs.flags1_offset, furball.flags1.whole);
p->readDWord (temp + offs.flags2_offset, furball.flags2.whole);
@ -258,6 +263,15 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
// traits as well
p->read(soul + offs.soul_traits_offset, sizeof (uint16_t) * NUM_CREATURE_TRAITS, (uint8_t *) &furball.defaultSoul.traits);
}
DfVector <uint32_t> app(p, temp + offs.appearance_vector_offset);
furball.nbcolors = app.size();
if(furball.nbcolors>MAX_COLORS)
furball.nbcolors = MAX_COLORS;
for(uint32_t i = 0; i < furball.nbcolors; i++)
{
furball.color[i] = app[i];
}
//likes
/*
DfVector <uint32_t> likes(d->p, temp + offs.creature_likes_offset);
@ -375,8 +389,8 @@ bool Creatures::ReadJob(const t_creature * furball, vector<t_material> & mat)
for(i=0;i<cmats.size();i++)
{
mat[i].itemType = p->readWord(cmats[i] + minfo->getOffset("job_material_maintype"));
mat[i].typeB = p->readWord(cmats[i] + minfo->getOffset("job_material_sectype1"));
mat[i].subType = p->readWord(cmats[i] + minfo->getOffset("job_material_sectype2"));
mat[i].subType = p->readWord(cmats[i] + minfo->getOffset("job_material_sectype1"));
mat[i].subIndex = p->readWord(cmats[i] + minfo->getOffset("job_material_sectype2"));
mat[i].index = p->readDWord(cmats[i] + minfo->getOffset("job_material_sectype3"));
mat[i].flags = p->readDWord(cmats[i] + minfo->getOffset("job_material_flags"));
}

@ -0,0 +1,266 @@
/*
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:
APIPrivate *d;
Process * owner;
/*
bool Inited;
bool Started;
*/
};
Items::Items(APIPrivate * d_)
{
d = new Private;
d->d = d_;
d->owner = d_->p;
}
Items::~Items()
{
delete d;
/* TODO : delete all item descs */
}
Accessor::Accessor(uint32_t function, Process *p)
{
this->p = p;
this->constant = 0;
this->offset1 = 0;
this->offset2 = 0;
this->type = ACCESSOR_CONSTANT;
this->dataWidth = 2;
uint64_t funcText = p->readQuad(function);
if( funcText == 0xCCCCCCCCCCC3C033LL )
{
return;
}
if( funcText == 0xCCCCCCCCC3FFC883LL )
{
/* or eax,-1; ret; */
this->constant = -1;
return;
}
if( (funcText&0xFFFFFFFFFF0000FFLL) == 0xCCCCC300000000B8LL )
{
/* mov eax, xx; ret; */
this->constant = (funcText>>8) & 0xffff;
return;
}
if( (funcText&0xFFFFFF0000FFFFFFLL) == 0xC300000000818B66LL )
{
/* mov ax, [ecx+xx]; ret; */
this->type = ACCESSOR_INDIRECT;
this->offset1 = (funcText>>24) & 0xffff;
return;
}
if( (funcText&0xFFFFFFFF0000FFFFLL) == 0x8B6600000000818BLL )
{
uint64_t funcText2 = p->readQuad(function+8);
if( (funcText2&0xFFFFFFFFFFFF00FFLL) == 0xCCCCCCCCCCC30040LL )
{
this->type = ACCESSOR_DOUBLE_INDIRECT;
this->offset1 = (funcText>>16) & 0xffff;
this->offset2 = (funcText2>>8) & 0xff;
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; */
this->type = ACCESSOR_INDIRECT;
this->offset1 = (funcText>>16) & 0xffff;
this->dataWidth = 4;
return;
}
printf("bad accessor @0x%x\n", function);
}
bool Accessor::isConstant()
{
if(this->type == ACCESSOR_CONSTANT)
return true;
else
return false;
}
int32_t Accessor::getValue(uint32_t objectPtr)
{
switch(this->type)
{
case ACCESSOR_CONSTANT:
return this->constant;
break;
case ACCESSOR_INDIRECT:
switch(this->dataWidth)
{
case 2:
return (int16_t) p->readWord(objectPtr + this->offset1);
case 4:
return p->readDWord(objectPtr + this->offset1);
default:
return -1;
}
break;
case ACCESSOR_DOUBLE_INDIRECT:
switch(this->dataWidth)
{
case 2:
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:
return -1;
}
break;
default:
return -1;
}
}
ItemDesc::ItemDesc(uint32_t VTable, Process *p)
{
uint32_t funcOffsetA = p->getDescriptor()->getOffset("item_type_accessor");
uint32_t funcOffsetB = p->getDescriptor()->getOffset("item_subtype_accessor");
uint32_t funcOffsetC = p->getDescriptor()->getOffset("item_subindex_accessor");
uint32_t funcOffsetD = p->getDescriptor()->getOffset("item_index_accessor");
uint32_t funcOffsetQuality = p->getDescriptor()->getOffset("item_quality_accessor");
this->vtable = VTable;
this->p = p;
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)
{
item.matdesc.itemType = this->AMainType->getValue(itemptr);
item.matdesc.subType = this->ASubType->getValue(itemptr);
item.matdesc.subIndex = this->ASubIndex->getValue(itemptr);
item.matdesc.index = this->AIndex->getValue(itemptr);
item.quality = this->AQuality->getValue(itemptr);
item.quantity = 1; /* TODO */
return true;
}
bool Items::getItemData(uint32_t itemptr, DFHack::t_item &item)
{
std::map<uint32_t, ItemDesc *>::iterator it;
Process * p = d->owner;
ItemDesc * desc;
it = this->descVTable.find(itemptr);
if(it==descVTable.end())
{
uint32_t vtable = p->readDWord(itemptr);
desc = new ItemDesc(vtable, p);
this->descVTable[vtable] = desc;
this->descType[desc->mainType] = desc;
}
else
desc = it->second;
return desc->getItem(itemptr, item);
}
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())
{
/* 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;
}
std::string Items::getItemDescription(uint32_t itemptr, Materials * Materials)
{
DFHack::t_item item;
std::string out;
if(!this->getItemData(itemptr, item))
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;
}

@ -282,6 +282,7 @@ bool Materials::ReadDescriptorColors (void)
col.b = p->readFloat( p_colors[i] + p->getDescriptor()->getOffset ("descriptor_color_b") );
color.push_back(col);
}
return ReadNamesOnly(d->owner, d->owner->getDescriptor()->getAddress ("descriptor_all_colors"), alldesc );
return true;
}
@ -293,8 +294,19 @@ bool Materials::ReadCreatureTypesEx (void)
uint32_t castes_vector_offset = mem->getOffset ("creature_type_caste_vector");
uint32_t extract_vector_offset = mem->getOffset ("creature_type_extract_vector");
uint32_t sizeof_string = mem->getHexValue ("sizeof_string");
uint32_t caste_colormod_offset = mem->getOffset ("caste_color_modifiers");
uint32_t caste_bodypart_offset = mem->getOffset ("caste_bodypart_vector");
uint32_t bodypart_id_offset = mem->getOffset ("bodypart_id");
uint32_t bodypart_category_offset = mem->getOffset ("bodypart_category");
uint32_t bodypart_layers_offset = mem->getOffset ("bodypart_layers_vector");
uint32_t bodypart_singular_offset = mem->getOffset ("bodypart_singular_vector");
uint32_t bodypart_plural_offset = mem->getOffset ("bodypart_plural_vector");
uint32_t color_modifier_part_offset = mem->getOffset ("color_modifier_part");
uint32_t size = p_races.size();
uint32_t sizecas = 0;
uint32_t sizecolormod;
uint32_t sizecolorlist;
uint32_t sizebp;
uint32_t tile_offset = mem->getOffset ("creature_tile");
uint32_t tile_color_offset = mem->getOffset ("creature_tile_color");
raceEx.clear();
@ -307,12 +319,40 @@ bool Materials::ReadCreatureTypesEx (void)
sizecas = p_castes.size();
for (uint32_t j = 0; j < sizecas;j++)
{
/* caste name */
t_creaturecaste caste;
uint32_t caste_start = p_castes[j];
p->readSTLString (caste_start, caste.rawname, sizeof(caste.rawname));
p->readSTLString (caste_start + sizeof_string, caste.singular, sizeof(caste.singular));
p->readSTLString (caste_start + 2 * sizeof_string, caste.plural, sizeof(caste.plural));
p->readSTLString (caste_start + 3 * sizeof_string, caste.adjective, sizeof(caste.adjective));
/* color mod reading */
DfVector <uint32_t> p_colormod(p, caste_start + caste_colormod_offset);
sizecolormod = p_colormod.size();
caste.ColorModifier.resize(sizecolormod);
for(uint32_t k = 0; k < sizecolormod;k++)
{
DfVector <uint32_t> p_colorlist(p, p_colormod[k]);
sizecolorlist = p_colorlist.size();
caste.ColorModifier[k].colorlist.resize(sizecolorlist);
for(uint32_t l = 0; l < sizecolorlist; l++)
caste.ColorModifier[k].colorlist[l] = p_colorlist[l];
p->readSTLString( p_colormod[k] + color_modifier_part_offset, caste.ColorModifier[k].part, sizeof(caste.ColorModifier[k].part));
}
/* body parts */
DfVector <uint32_t> p_bodypart(p, caste_start + caste_bodypart_offset);
caste.bodypart.empty();
sizebp = p_bodypart.size();
for(uint32_t k = 0; k < sizebp; k++)
{
t_bodypart part;
p->readSTLString (p_bodypart[k] + bodypart_id_offset, part.id, sizeof(part.id));
p->readSTLString (p_bodypart[k] + bodypart_category_offset, part.category, sizeof(part.category));
caste.bodypart.push_back(part);
}
mat.castes.push_back(caste);
}
mat.tile_character = p->readByte( p_races[i] + tile_offset );
@ -327,6 +367,8 @@ bool Materials::ReadCreatureTypesEx (void)
p->readSTLString( p_extract[j], extract.rawname, sizeof(extract.rawname));
mat.extract.push_back(extract);
}
raceEx.push_back(mat);
}
return true;
@ -347,66 +389,56 @@ void Materials::ReadAllMaterials(void)
std::string Materials::getDescription(t_material & mat)
{
std::string out;
int32_t typeC;
switch(mat.itemType)
{
case 0:
if(mat.index>=0)
{
if(uint32_t(mat.index) <= this->inorganic.size())
{
out.append(this->inorganic[mat.index].id);
out.append(" bar");
}
if ( (mat.subIndex<419) || (mat.subIndex>618) )
{
if ( (mat.subIndex<19) || (mat.subIndex>218) )
{
if (mat.subIndex)
if (mat.subIndex>0x292)
return "?";
else
{
if (mat.subIndex>=this->other.size())
{
if(mat.subIndex<0)
return "any";
if(mat.subIndex>=this->raceEx.size())
return "stuff";
return this->raceEx[mat.subIndex].rawname;
}
else
{
if (mat.index==-1)
return std::string(this->other[mat.subIndex].rawname);
else
return std::string(this->other[mat.subIndex].rawname) + " derivate";
}
}
else
if(mat.index<0)
return "any inorganic";
else
out = "invalid bar";
}
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;
}
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 this->inorganic[mat.index].id;
}
else
{
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");
}
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;
}

@ -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;

@ -44,6 +44,7 @@ typedef struct
uint32_t flags2_offset;
uint32_t name_offset;
uint32_t sex_offset;
uint32_t caste_offset;
uint32_t id_offset;
uint32_t labors_offset;
uint32_t happiness_offset;
@ -63,6 +64,7 @@ typedef struct
uint32_t name_words_offset;
uint32_t soul_mental_offset;
uint32_t soul_traits_offset;
uint32_t appearance_vector_offset;
} creature_offsets;
typedef struct

@ -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;
@ -205,6 +204,22 @@ void printCreature(DFHack::API & DF, const DFHack::t_creature & creature)
}
*/
cout << endl;
cout << "Appearance : ";
for(unsigned int i = 0; i<creature.nbcolors ; i++)
{
cout << Materials->raceEx[creature.race].castes[creature.caste].ColorModifier[i].part << " ";
uint32_t color = Materials->raceEx[creature.race].castes[creature.caste].ColorModifier[i].colorlist[creature.color[i]];
if(color<Materials->color.size())
cout << Materials->color[color].name << "["
<< (unsigned int) (Materials->color[color].r*255) << ":"
<< (unsigned int) (Materials->color[color].v*255) << ":"
<< (unsigned int) (Materials->color[color].b*255) << "]";
else
cout << Materials->alldesc[color].id;
cout << " - ";
}
cout << endl;
cout << "happiness: " << creature.happiness
<< ", strength: " << creature.strength.level
<< ", agility: " << creature.agility.level
@ -241,7 +256,7 @@ void printCreature(DFHack::API & DF, const DFHack::t_creature & creature)
{
for(unsigned int i = 0; i < mymat.size(); i++)
{
printf("\t%s(%d)\t%d %d %d - %.8x\n", Materials->getDescription(mymat[i]).c_str(), mymat[i].itemType, mymat[i].typeB, mymat[i].subType, mymat[i].index, mymat[i].flags);
printf("\t%s(%d)\t%d %d %d - %.8x\n", Materials->getDescription(mymat[i]).c_str(), mymat[i].itemType, mymat[i].subType, mymat[i].subIndex, mymat[i].index, mymat[i].flags);
}
}
}
@ -360,6 +375,8 @@ void printCreature(DFHack::API & DF, const DFHack::t_creature & creature)
string artifact_name = Tran->TranslateName(creature.artifact_name,false);
cout << "artifact: " << artifact_name << endl;
}
cout << endl;
}
@ -406,16 +423,7 @@ int main (int numargs, char ** args)
}
mem = DF.getMemoryInfo();
if(!Materials->ReadInorganicMaterials())
{
cerr << "Can't get the inorganics types." << endl;
return 1;
}
if(!Materials->ReadCreatureTypesEx())
{
cerr << "Can't get the creature types." << endl;
return 1;
}
Materials->ReadAllMaterials();
if(!Tran->Start())
{

@ -18,51 +18,11 @@ using namespace std;
#include <DFProcess.h>
#include <DFVector.h>
#include <modules/Materials.h>
#include <modules/Items.h>
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 ()
{
@ -89,6 +49,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 +76,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 )
{
@ -187,9 +151,12 @@ 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) || (quality!=itm.quality) )
printf("\tbad[%d,%d,%d,%d]", itm.matdesc.itemType, itm.matdesc.subType, itm.matdesc.subIndex, itm.matdesc.index);
if (hasDecorations)
{
bool sep = false;
@ -211,11 +178,13 @@ int main ()
uint32_t dqual = p->readWord(decoration + 20);
if ( (dtypefunct&0xFFFFFFFFFFFF00FFLL) == 0xCCCCC300000000B8LL)
dtype = (dtypefunct>>8)&0xfffffff;
else
else if ( dtypefunct == 0xCCCCCCCCCCC3C033LL)
dtype = 0;
else
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;
}
}

@ -67,6 +67,23 @@ int main (int numargs, const char ** args)
{
cout << i << ": " << Materials->plant[i].id << endl;
}
cout << endl << "----==== Color descriptors ====----" << endl;
Materials->ReadDescriptorColors();
for(uint32_t i = 0; i < Materials->color.size();i++)
{
cout << i << ": " << Materials->color[i].id << " - " << Materials->color[i].name << "["
<< (unsigned int) (Materials->color[i].r*255) << ":"
<< (unsigned int) (Materials->color[i].v*255) << ":"
<< (unsigned int) (Materials->color[i].b*255)
<< "]" << endl;
}
cout << endl << "----==== All descriptors ====----" << endl;
Materials->ReadDescriptorColors();
for(uint32_t i = 0; i < Materials->alldesc.size();i++)
{
cout << i << ": " << Materials->alldesc[i].id << endl;
}
cout << endl << "----==== Creature types ====----" << endl;
Materials->ReadCreatureTypesEx ();
for(uint32_t i = 0; i < Materials->raceEx.size();i++)
@ -81,19 +98,27 @@ int main (int numargs, const char ** args)
<< castes[j].plural << ":"
<< castes[j].adjective << "] ";
cout << endl;
for(uint32_t k = 0; k < castes[j].ColorModifier.size(); k++)
{
cout << " colormod[" << castes[j].ColorModifier[k].part << "] ";
for(uint32_t l = 0; l < castes[j].ColorModifier[k].colorlist.size(); l++)
{
if( castes[j].ColorModifier[k].colorlist[l] < Materials->color.size() )
cout << Materials->color[castes[j].ColorModifier[k].colorlist[l]].name << " ";
else
cout << Materials->alldesc[castes[j].ColorModifier[k].colorlist[l]].id << " ";
}
cout << endl;
}
cout << " body: ";
for(uint32_t k = 0; k < castes[j].bodypart.size(); k++)
{
cout << castes[j].bodypart[k].category << " ";
}
cout << endl;
}
cout << endl;
}
cout << endl << "----==== Color descriptors ====----" << endl;
Materials->ReadDescriptorColors();
for(uint32_t i = 0; i < Materials->color.size();i++)
{
cout << i << ": " << Materials->color[i].id << " - " << Materials->color[i].name << "["
<< (unsigned int) (Materials->color[i].r*255) << ":"
<< (unsigned int) (Materials->color[i].v*255) << ":"
<< (unsigned int) (Materials->color[i].b*255) << ":"
<< "]" << endl;
}
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;
cin.ignore();

@ -1413,7 +1413,8 @@ map_data_1b60_offset 0x1B9c
<Offset name="creature_position">0x90</Offset>
<Offset name="creature_flags1">0xF8</Offset>
<Offset name="creature_flags2">0xFC</Offset>
<Offset name="creature_sex">0x110</Offset>
<Offset name="creature_caste">0x110</Offset>
<Offset name="creature_sex">0x112</Offset>
<Offset name="creature_id">0x114</Offset>
<Offset name="creature_civ">0X120</Offset>
<Offset name="creature_soulskill_vector">0X1F4</Offset>
@ -1421,6 +1422,8 @@ map_data_1b60_offset 0x1B9c
<!--<Offset name="creature_mood">0x238</Offset>-->
<Offset name="creature_mood">0x288</Offset>
<Offset name="creature_birth_year">0x298</Offset>
<Offset name="creature_birth_month">0x29C</Offset>
<Offset name="creature_physical">0x464</Offset>
<!--
<Offset name="creature_strength">0x464</Offset>
@ -1432,13 +1435,27 @@ map_data_1b60_offset 0x1B9c
-->
<Offset name="creature_current_job">0x390</Offset> <!-- from chmod -->
<Offset name="creature_mood_skill">0x394</Offset> the skill that will be increased at the end of the mood (or not)
<Offset name="creature_appearance_vector">0x604</Offset> seems to be indexes in the list of possible colors defined in the raws for each group
<Offset name="creature_appearance_vector">0x604</Offset>
<Offset name="creature_artifact_name">0x6D4</Offset>
<Offset name="creature_labors">0x774</Offset>
<Offset name="creature_soul_vector">0x0740</Offset>
<Offset name="creature_default_soul">0x0758</Offset>
<Offset name="creature_happiness">0x834</Offset>
Castes
======
<Offset name="caste_bodypart_vector">0x51C</Offset>
<Offset name="caste_color_modifiers">0xACC</Offset>
<Offset name="color_modifier_part">0x70</Offset>
Body Parts
==========
<Offset name="bodypart_id">0x0</Offset>
<Offset name="bodypart_category">0x1C</Offset>
<Offset name="bodypart_layers_vector">0x44</Offset>
<Offset name="bodypart_singular_vector">0x78</Offset>
<Offset name="bodypart_plural_vector">0x90</Offset>
Materials
=========
soil, stone, metal
@ -1491,20 +1508,30 @@ map_data_1b60_offset 0x1B9c
Descriptor colors
=================
<Address name="descriptor_shape_vector">0x16B9780</Address>
<Address name="descriptor_vectors_start">0x16B9780</Address>
<Offset name="descriptor_rawname">0x0</Offset>
<Offset name="descriptor_name">0x4C</Offset>
<Address name="descriptor_colors_vector">0x16B9768</Address>
<Address name="descriptor_colors_vector">0x16B9768</Address> this includes RVB
<Offset name="descriptor_color_r">0x6C</Offset> floats !
<Offset name="descriptor_color_v">0x70</Offset>
<Offset name="descriptor_color_b">0x74</Offset>
<Address name="descriptor_all_colors">0x16B9798</Address> A list of all colors, including eyes and stuff
Items
=====
<Address name="items_vector">0x166FE00</Address>
List of offsets in the VTable :
<Offset name="item_type_accessor">0x0</Offset>
<Offset name="item_subtype_accessor">0x4</Offset>
<Offset name="item_subindex_accessor">0x8</Offset>
<Offset name="item_index_accessor">0xC</Offset>
<Offset name="item_quality_accessor">0x238</Offset>
<Offset name="item_improvement_vector">0xA0</Offset>
<Offset name="item_improvement_subindex">0x4</Offset>
<Offset name="item_improvement_index">0x8</Offset>
<Offset name="item_improvement_quality">0x14</Offset>
<Offset name="item_type_accessor">0x14</Offset> (in the vtable)
</Entry>
.-"""-.

@ -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;