Merge branch 'master' of git://bigbox.banquise.net/dfhack

Conflicts:
	tools/examples/creaturedump.cpp
	tools/supported/dumpoffsets.cpp
develop
Petr Mrázek 2010-08-28 04:39:03 +02:00
commit e762f1caea
8 changed files with 60 additions and 15 deletions

@ -1698,6 +1698,7 @@ map_data_1b60_offset 0x1B9c
<Address name="creature_vector">0x168E73C</Address> <Address name="creature_vector">0x168E73C</Address>
<Address name="dwarf_race_index">0x014b9f1c</Address> <Address name="dwarf_race_index">0x014b9f1c</Address>
<Offset name="creature_soulskill_vector">0X1F4</Offset> <Offset name="creature_soulskill_vector">0X1F4</Offset>
<Offset name="creature_inventory_vector">0x2FC</Offset>
<Offset name="creature_physical">0x4AC</Offset> <Offset name="creature_physical">0x4AC</Offset>
<Offset name="creature_appearance_vector">0x64c</Offset> <!-- Maybe slightly wrong --> <Offset name="creature_appearance_vector">0x64c</Offset> <!-- Maybe slightly wrong -->
<Offset name="creature_artifact_name">0x71c</Offset> <Offset name="creature_artifact_name">0x71c</Offset>

@ -127,8 +127,8 @@ void OffsetGroup::createString(const string & key)
void OffsetGroup::setOffset (const string & key, const string & value) void OffsetGroup::setOffset (const string & key, const string & value)
{ {
int32_Iter it; int32_Iter it = OGd->offsets.find(key);
if((it = OGd->offsets.find(key)) != OGd->offsets.end()) if(it != OGd->offsets.end())
{ {
int32_t offset = strtol(value.c_str(), NULL, 16); int32_t offset = strtol(value.c_str(), NULL, 16);
(*it).second.second = offset; (*it).second.second = offset;
@ -140,8 +140,8 @@ void OffsetGroup::setOffset (const string & key, const string & value)
void OffsetGroup::setAddress (const string & key, const string & value) void OffsetGroup::setAddress (const string & key, const string & value)
{ {
uint32_Iter it; uint32_Iter it = OGd->addresses.find(key);
if((it = OGd->addresses.find(key)) != OGd->addresses.end()) if(it != OGd->addresses.end())
{ {
int32_t address = strtol(value.c_str(), NULL, 16); int32_t address = strtol(value.c_str(), NULL, 16);
(*it).second.second = address; (*it).second.second = address;
@ -153,8 +153,8 @@ void OffsetGroup::setAddress (const string & key, const string & value)
void OffsetGroup::setHexValue (const string & key, const string & value) void OffsetGroup::setHexValue (const string & key, const string & value)
{ {
uint32_Iter it; uint32_Iter it = OGd->hexvals.find(key);
if((it = OGd->hexvals.find(key)) != OGd->hexvals.end()) if(it != OGd->hexvals.end())
{ {
(*it).second.second = strtol(value.c_str(), NULL, 16); (*it).second.second = strtol(value.c_str(), NULL, 16);
(*it).second.first = true; (*it).second.first = true;
@ -165,8 +165,8 @@ void OffsetGroup::setHexValue (const string & key, const string & value)
void OffsetGroup::setString (const string & key, const string & value) void OffsetGroup::setString (const string & key, const string & value)
{ {
strings_Iter it; strings_Iter it = OGd->strings.find(key);
if((it = OGd->strings.find(key)) != OGd->strings.end()) if(it != OGd->strings.end())
{ {
(*it).second.second = value; (*it).second.second = value;
(*it).second.first = true; (*it).second.first = true;

@ -118,7 +118,7 @@ void VersionInfoFactory::ParseOffsets(TiXmlElement * parent, VersionInfo* target
// work variables // work variables
OffsetGroup * currentGroup = 0; OffsetGroup * currentGroup = 0;
TiXmlElement * currentElem = 0; TiXmlElement * currentElem = 0;
cerr << "<Offsets>"<< endl; //cerr << "<Offsets>"<< endl;
while(1) while(1)
{ {
// get current work variables // get current work variables
@ -137,7 +137,7 @@ void VersionInfoFactory::ParseOffsets(TiXmlElement * parent, VersionInfo* target
} }
else else
{ {
cerr << "</group>" << endl; //cerr << "</group>" << endl;
continue; continue;
} }
} }
@ -178,10 +178,10 @@ void VersionInfoFactory::ParseOffsets(TiXmlElement * parent, VersionInfo* target
og = currentGroup->createGroup(cstr_name); og = currentGroup->createGroup(cstr_name);
else else
og = currentGroup->getGroup(cstr_name); og = currentGroup->getGroup(cstr_name);
cerr << "<group name=\"" << cstr_name << "\">" << endl; //cerr << "<group name=\"" << cstr_name << "\">" << endl;
// advance this level to the next element // advance this level to the next element
groupPair & gp = breadcrumbs.back(); groupPair & gp = breadcrumbs.back();
gp.first = gp.first->NextSiblingElement(); gp.first = currentElem->NextSiblingElement();
// add a new level that will be processed next // add a new level that will be processed next
breadcrumbs.push_back(groupPair(currentElem->FirstChildElement(), og)); breadcrumbs.push_back(groupPair(currentElem->FirstChildElement(), og));
@ -250,10 +250,10 @@ void VersionInfoFactory::ParseOffsets(TiXmlElement * parent, VersionInfo* target
// advance to next element // advance to next element
groupPair & gp = breadcrumbs.back(); groupPair & gp = breadcrumbs.back();
gp.first = gp.first->NextSiblingElement(); gp.first = currentElem->NextSiblingElement();
continue; continue;
} }
cerr << "</Offsets>"<< endl; //cerr << "</Offsets>"<< endl;
} }
void VersionInfoFactory::ParseBase (TiXmlElement* entry, VersionInfo* mem) void VersionInfoFactory::ParseBase (TiXmlElement* entry, VersionInfo* mem)

@ -5,6 +5,7 @@
*/ */
#include "dfhack/DFExport.h" #include "dfhack/DFExport.h"
#include "dfhack/DFModule.h" #include "dfhack/DFModule.h"
#include "dfhack/modules/Items.h"
namespace DFHack namespace DFHack
{ {
/* /*
@ -374,6 +375,8 @@ namespace DFHack
const uint16_t x2, const uint16_t y2,const uint16_t z2); const uint16_t x2, const uint16_t y2,const uint16_t z2);
bool ReadCreature(const int32_t index, t_creature & furball); bool ReadCreature(const int32_t index, t_creature & furball);
bool ReadJob(const t_creature * furball, std::vector<t_material> & mat); bool ReadJob(const t_creature * furball, std::vector<t_material> & mat);
bool ReadInventoryIdx(const uint32_t index, std::vector<uint32_t> & item);
bool ReadInventoryPtr(const uint32_t index, std::vector<uint32_t> & item);
/* Getters */ /* Getters */
uint32_t GetDwarfRaceIndex ( void ); uint32_t GetDwarfRaceIndex ( void );

@ -109,6 +109,9 @@ Creatures::Creatures(DFContextShared* _d)
creatures.name_firstname_offset = minfo->getOffset("name_firstname"); creatures.name_firstname_offset = minfo->getOffset("name_firstname");
creatures.name_nickname_offset = minfo->getOffset("name_nickname"); creatures.name_nickname_offset = minfo->getOffset("name_nickname");
creatures.name_words_offset = minfo->getOffset("name_words"); creatures.name_words_offset = minfo->getOffset("name_words");
creatures.inventory_offset = minfo->getOffset("creature_inventory_vector");
d->dwarf_race_index_addr = minfo->getAddress("dwarf_race_index"); d->dwarf_race_index_addr = minfo->getAddress("dwarf_race_index");
d->dwarf_civ_id_addr = minfo->getAddress("dwarf_civ_id"); d->dwarf_civ_id_addr = minfo->getAddress("dwarf_civ_id");
/* /*
@ -609,3 +612,26 @@ bool Creatures::ReadJob(const t_creature * furball, vector<t_material> & mat)
} }
return true; return true;
} }
bool Creatures::ReadInventoryIdx(const uint32_t index, std::vector<uint32_t> & item)
{
if(!d->Started) return false;
Process * p = d->owner;
uint32_t temp = d->p_cre->at (index);
return this->ReadInventoryPtr(temp, item);
}
bool Creatures::ReadInventoryPtr(const uint32_t temp, std::vector<uint32_t> & item)
{
unsigned int i;
if(!d->Started) return false;
Process * p = d->owner;
DfVector <uint32_t> citem(p, temp + d->creatures.inventory_offset);
if(citem.size() == 0)
return false;
item.resize(citem.size());
for(i=0;i<citem.size();i++)
item[i] = p->readDWord(citem[i]);
return true;
}

@ -67,6 +67,7 @@ typedef struct
uint32_t appearance_vector_offset; uint32_t appearance_vector_offset;
uint32_t birth_year_offset; uint32_t birth_year_offset;
uint32_t birth_time_offset; uint32_t birth_time_offset;
uint32_t inventory_offset;
} creature_offsets; } creature_offsets;
typedef struct typedef struct

@ -271,6 +271,17 @@ void printCreature(DFHack::Context * DF, const DFHack::t_creature & creature)
} }
} }
std::vector<uint32_t> inventory;
if( Creatures->ReadInventoryPtr(creature.origin, inventory) )
{
printf("\tInventory:\n");
for(unsigned int i = 0; i < inventory.size(); i++)
{
printf("\t\t%s\n", Items->getItemDescription(inventory[i], Materials).c_str());
}
}
/* /*
if(creature.pregnancy_timer > 0) if(creature.pregnancy_timer > 0)
cout << "gives birth in " << creature.pregnancy_timer/1200 << " days. "; cout << "gives birth in " << creature.pregnancy_timer/1200 << " days. ";
@ -415,6 +426,7 @@ int main (int numargs, char ** args)
Creatures = DF->getCreatures(); Creatures = DF->getCreatures();
Materials = DF->getMaterials(); Materials = DF->getMaterials();
Items = DF->getItems();
World = DF->getWorld(); World = DF->getWorld();
current_year = World->ReadCurrentYear(); current_year = World->ReadCurrentYear();
current_tick = World->ReadCurrentTick(); current_tick = World->ReadCurrentTick();
@ -450,6 +462,7 @@ int main (int numargs, char ** args)
//DF.InitViewAndCursor(); //DF.InitViewAndCursor();
for(uint32_t i = 0; i < numCreatures; i++) for(uint32_t i = 0; i < numCreatures; i++)
{ {
printf("%d/%d\n", i, numCreatures);
DFHack::t_creature temp; DFHack::t_creature temp;
Creatures->ReadCreature(i,temp); Creatures->ReadCreature(i,temp);
if(check.empty() || string(Materials->raceEx[temp.race].rawname) == check) if(check.empty() || string(Materials->raceEx[temp.race].rawname) == check)
@ -459,6 +472,7 @@ int main (int numargs, char ** args)
printCreature(DF,temp); printCreature(DF,temp);
addrs.push_back(temp.origin); addrs.push_back(temp.origin);
} }
printf("!\n");
} }
if(addrs.size() <= 10) if(addrs.size() <= 10)
{ {
@ -473,6 +487,7 @@ int main (int numargs, char ** args)
DF.ReadCreature(currentIdx, currentCreature); DF.ReadCreature(currentIdx, currentCreature);
printCreature(DF,currentCreature); printCreature(DF,currentCreature);
*/ */
Creatures->Finish(); Creatures->Finish();
DF->Detach(); DF->Detach();
#ifndef LINUX_BUILD #ifndef LINUX_BUILD

@ -13,7 +13,6 @@ using namespace DFHack;
int main (int numargs, const char ** args) int main (int numargs, const char ** args)
{ {
DFHack::VersionInfoFactory * VIF = new DFHack::VersionInfoFactory("Memory.xml"); DFHack::VersionInfoFactory * VIF = new DFHack::VersionInfoFactory("Memory.xml");
for(int i = 0; i < VIF->versions.size(); i++) for(int i = 0; i < VIF->versions.size(); i++)
{ {