Support for reading inventory

develop
simon 2010-08-17 15:21:54 +02:00
parent 4254190560
commit 9cf2e0f26d
6 changed files with 50 additions and 2 deletions

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

@ -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<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 */
uint32_t GetDwarfRaceIndex ( void );

@ -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<t_material> & mat)
}
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 birth_year_offset;
uint32_t birth_time_offset;
uint32_t inventory_offset;
} creature_offsets;
typedef struct

@ -19,6 +19,7 @@ enum likeType
};
DFHack::Materials * Materials;
DFHack::Items * Items;
DFHack::memory_info *mem;
vector< vector<string> > englishWords;
vector< vector<string> > foreignWords;
@ -271,6 +272,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)
cout << "gives birth in " << creature.pregnancy_timer/1200 << " days. ";
@ -415,6 +427,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 +463,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 +473,7 @@ int main (int numargs, char ** args)
printCreature(DF,temp);
addrs.push_back(temp.origin);
}
printf("!\n");
}
if(addrs.size() <= 10)
{
@ -473,6 +488,7 @@ int main (int numargs, char ** args)
DF.ReadCreature(currentIdx, currentCreature);
printCreature(DF,currentCreature);
*/
Creatures->Finish();
DF->Detach();
#ifndef LINUX_BUILD

@ -12,11 +12,12 @@ using namespace DFHack;
int main (int numargs, const char ** args)
{
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::ContextManager * DFMgr;
DFHack::Context * DF;
try
{
DF = DFMgr.getSingleContext();
DFMgr = new DFHack::ContextManager("Memory.xml");
DF = DFMgr->getSingleContext();
DF->Attach();
}
catch (exception& e)