diff --git a/data/Memory.xml b/data/Memory.xml index fd0072623..9c5bd6e48 100644 --- a/data/Memory.xml +++ b/data/Memory.xml @@ -1698,6 +1698,7 @@ map_data_1b60_offset 0x1B9c
0x168E73C
0x014b9f1c
0X1F4 + 0x2FC 0x4AC 0x64c 0x71c diff --git a/library/VersionInfo.cpp b/library/VersionInfo.cpp index e5c6873f9..a7d427056 100644 --- a/library/VersionInfo.cpp +++ b/library/VersionInfo.cpp @@ -127,8 +127,8 @@ void OffsetGroup::createString(const string & key) void OffsetGroup::setOffset (const string & key, const string & value) { - int32_Iter it; - if((it = OGd->offsets.find(key)) != OGd->offsets.end()) + int32_Iter it = OGd->offsets.find(key); + if(it != OGd->offsets.end()) { int32_t offset = strtol(value.c_str(), NULL, 16); (*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) { - uint32_Iter it; - if((it = OGd->addresses.find(key)) != OGd->addresses.end()) + uint32_Iter it = OGd->addresses.find(key); + if(it != OGd->addresses.end()) { int32_t address = strtol(value.c_str(), NULL, 16); (*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) { - uint32_Iter it; - if((it = OGd->hexvals.find(key)) != OGd->hexvals.end()) + uint32_Iter it = OGd->hexvals.find(key); + if(it != OGd->hexvals.end()) { (*it).second.second = strtol(value.c_str(), NULL, 16); (*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) { - strings_Iter it; - if((it = OGd->strings.find(key)) != OGd->strings.end()) + strings_Iter it = OGd->strings.find(key); + if(it != OGd->strings.end()) { (*it).second.second = value; (*it).second.first = true; diff --git a/library/VersionInfoFactory.cpp b/library/VersionInfoFactory.cpp index 14076426b..6a1bd517b 100644 --- a/library/VersionInfoFactory.cpp +++ b/library/VersionInfoFactory.cpp @@ -118,7 +118,7 @@ void VersionInfoFactory::ParseOffsets(TiXmlElement * parent, VersionInfo* target // work variables OffsetGroup * currentGroup = 0; TiXmlElement * currentElem = 0; - cerr << ""<< endl; + //cerr << ""<< endl; while(1) { // get current work variables @@ -137,7 +137,7 @@ void VersionInfoFactory::ParseOffsets(TiXmlElement * parent, VersionInfo* target } else { - cerr << "" << endl; + //cerr << "" << endl; continue; } } @@ -178,10 +178,10 @@ void VersionInfoFactory::ParseOffsets(TiXmlElement * parent, VersionInfo* target og = currentGroup->createGroup(cstr_name); else og = currentGroup->getGroup(cstr_name); - cerr << "" << endl; + //cerr << "" << endl; // advance this level to the next element groupPair & gp = breadcrumbs.back(); - gp.first = gp.first->NextSiblingElement(); + gp.first = currentElem->NextSiblingElement(); // add a new level that will be processed next breadcrumbs.push_back(groupPair(currentElem->FirstChildElement(), og)); @@ -250,10 +250,10 @@ void VersionInfoFactory::ParseOffsets(TiXmlElement * parent, VersionInfo* target // advance to next element groupPair & gp = breadcrumbs.back(); - gp.first = gp.first->NextSiblingElement(); + gp.first = currentElem->NextSiblingElement(); continue; } - cerr << ""<< endl; + //cerr << ""<< endl; } void VersionInfoFactory::ParseBase (TiXmlElement* entry, VersionInfo* mem) diff --git a/library/include/dfhack/modules/Creatures.h b/library/include/dfhack/modules/Creatures.h index 1686be281..67418d08a 100644 --- a/library/include/dfhack/modules/Creatures.h +++ b/library/include/dfhack/modules/Creatures.h @@ -5,6 +5,7 @@ */ #include "dfhack/DFExport.h" #include "dfhack/DFModule.h" +#include "dfhack/modules/Items.h" namespace DFHack { /* @@ -374,6 +375,8 @@ namespace DFHack const uint16_t x2, const uint16_t y2,const uint16_t z2); bool ReadCreature(const int32_t index, t_creature & furball); bool ReadJob(const t_creature * furball, std::vector & mat); + bool ReadInventoryIdx(const uint32_t index, std::vector & item); + bool ReadInventoryPtr(const uint32_t index, std::vector & item); /* Getters */ uint32_t GetDwarfRaceIndex ( void ); diff --git a/library/modules/Creatures.cpp b/library/modules/Creatures.cpp index cd1022e4b..73f2691c7 100644 --- a/library/modules/Creatures.cpp +++ b/library/modules/Creatures.cpp @@ -109,6 +109,9 @@ Creatures::Creatures(DFContextShared* _d) creatures.name_firstname_offset = minfo->getOffset("name_firstname"); creatures.name_nickname_offset = minfo->getOffset("name_nickname"); 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_civ_id_addr = minfo->getAddress("dwarf_civ_id"); /* @@ -609,3 +612,26 @@ bool Creatures::ReadJob(const t_creature * furball, vector & mat) } return true; } + +bool Creatures::ReadInventoryIdx(const uint32_t index, std::vector & 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 & item) +{ + unsigned int i; + if(!d->Started) return false; + Process * p = d->owner; + + DfVector citem(p, temp + d->creatures.inventory_offset); + if(citem.size() == 0) + return false; + item.resize(citem.size()); + for(i=0;ireadDWord(citem[i]); + return true; +} diff --git a/library/shm/mod-creature2010.h b/library/shm/mod-creature2010.h index f52122127..64a9936a6 100644 --- a/library/shm/mod-creature2010.h +++ b/library/shm/mod-creature2010.h @@ -67,6 +67,7 @@ typedef struct uint32_t appearance_vector_offset; uint32_t birth_year_offset; uint32_t birth_time_offset; + uint32_t inventory_offset; } creature_offsets; typedef struct diff --git a/tools/examples/creaturedump.cpp b/tools/examples/creaturedump.cpp index b9113130a..c18c3806f 100644 --- a/tools/examples/creaturedump.cpp +++ b/tools/examples/creaturedump.cpp @@ -271,6 +271,17 @@ void printCreature(DFHack::Context * DF, const DFHack::t_creature & creature) } } + std::vector 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) cout << "gives birth in " << creature.pregnancy_timer/1200 << " days. "; @@ -415,6 +426,7 @@ int main (int numargs, char ** args) Creatures = DF->getCreatures(); Materials = DF->getMaterials(); + Items = DF->getItems(); World = DF->getWorld(); current_year = World->ReadCurrentYear(); current_tick = World->ReadCurrentTick(); @@ -450,6 +462,7 @@ int main (int numargs, char ** args) //DF.InitViewAndCursor(); for(uint32_t i = 0; i < numCreatures; i++) { + printf("%d/%d\n", i, numCreatures); DFHack::t_creature temp; Creatures->ReadCreature(i,temp); if(check.empty() || string(Materials->raceEx[temp.race].rawname) == check) @@ -459,6 +472,7 @@ int main (int numargs, char ** args) printCreature(DF,temp); addrs.push_back(temp.origin); } + printf("!\n"); } if(addrs.size() <= 10) { @@ -473,6 +487,7 @@ int main (int numargs, char ** args) DF.ReadCreature(currentIdx, currentCreature); printCreature(DF,currentCreature); */ + Creatures->Finish(); DF->Detach(); #ifndef LINUX_BUILD diff --git a/tools/supported/dumpoffsets.cpp b/tools/supported/dumpoffsets.cpp index 963cffcbb..d9240f760 100644 --- a/tools/supported/dumpoffsets.cpp +++ b/tools/supported/dumpoffsets.cpp @@ -13,7 +13,6 @@ using namespace DFHack; int main (int numargs, const char ** args) { - DFHack::VersionInfoFactory * VIF = new DFHack::VersionInfoFactory("Memory.xml"); for(int i = 0; i < VIF->versions.size(); i++) {