From dab8d37c031b79ce99b3beb1b89b9dc44f59b5cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Fri, 23 Oct 2009 10:54:24 +0000 Subject: [PATCH] creature dump test, valid offsets for linux d9 and d11 --- library/DFHackAPI.cpp | 8 ++++---- output/Memory.xml | 7 +++++++ tools/CMakeLists.txt | 6 +++++- tools/creaturedump.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 tools/creaturedump.cpp diff --git a/library/DFHackAPI.cpp b/library/DFHackAPI.cpp index 86330ed4e..038c9198b 100644 --- a/library/DFHackAPI.cpp +++ b/library/DFHackAPI.cpp @@ -383,7 +383,7 @@ bool DFHackAPIImpl::ReadCreatureMatgloss(vector & creatures) { int matgloss_address = offset_descriptor->getAddress("matgloss"); int matgloss_offset = offset_descriptor->getHexValue("matgloss_skip"); - DfVector p_matgloss = dm->readVector(matgloss_address + matgloss_offset*4, 4); + DfVector p_matgloss = dm->readVector(matgloss_address + matgloss_offset*6, 4); creatures.clear(); @@ -595,7 +595,7 @@ uint32_t DFHackAPIImpl::InitReadVegetation() vegetationInited = true; int vegetation = offset_descriptor->getAddress("vegetation"); tree_offset = offset_descriptor->getOffset("tree_desc_offset"); - assert(vegetation && treeoffset); + assert(vegetation && tree_offset); p_veg = new DfVector(dm->readVector(vegetation,4)); return p_veg->getSize(); } @@ -627,7 +627,7 @@ uint32_t DFHackAPIImpl::InitReadCreatures() int creatures = offset_descriptor->getAddress("creatures"); creature_pos_offset = offset_descriptor->getOffset("creature_position"); creature_type_offset = offset_descriptor->getOffset("creature_type"); - assert(creatures && creatureposoffset && creaturetypeoffset); + assert(creatures && creature_pos_offset && creature_type_offset); p_cre = new DfVector(dm->readVector(creatures, 4)); return p_cre->getSize(); } @@ -635,7 +635,7 @@ uint32_t DFHackAPIImpl::InitReadCreatures() bool DFHackAPIImpl::ReadCreature(const uint32_t &index, t_creature & furball) { - assert(vegetationInited); + assert(creaturesInited); uint32_t temp; // read pointer from vector at position p_cre->read(index,(uint8_t *)&temp); diff --git a/output/Memory.xml b/output/Memory.xml index bc7447ea4..7aa922323 100644 --- a/output/Memory.xml +++ b/output/Memory.xml @@ -368,6 +368,12 @@
0x09335CB0
+
0x093326AC
+ + + 0x4C + 0x44 + 0x40 @@ -512,6 +518,7 @@
0x08F41918
0x08F55740
0x08F58890
+
0x08F55250
0x08F95BD0
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 28c150c7b..576e81285 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -19,4 +19,8 @@ TARGET_LINK_LIBRARIES(prospector dfhack) # cleanmap - removes mud, snow, blood and similar stuff from a map. farmers beware ADD_EXECUTABLE(cleanmap cleanmap.cpp) -TARGET_LINK_LIBRARIES(cleanmap dfhack) \ No newline at end of file +TARGET_LINK_LIBRARIES(cleanmap dfhack) + +# creaturedump - basic creature dump - a test of the creature related exports +ADD_EXECUTABLE(creaturedump creaturedump.cpp) +TARGET_LINK_LIBRARIES(creaturedump dfhack) \ No newline at end of file diff --git a/tools/creaturedump.cpp b/tools/creaturedump.cpp new file mode 100644 index 000000000..a910d71e3 --- /dev/null +++ b/tools/creaturedump.cpp @@ -0,0 +1,40 @@ +// Creature dump + +#include +#include +#include +using namespace std; + +#include +#include + +int main (void) +{ + vector creaturestypes; + + DFHackAPI *pDF = CreateDFHackAPI("Memory.xml"); + DFHackAPI &DF = *pDF; + if(!DF.Attach()) + { + cerr << "DF not found" << endl; + return 1; + } + + // get stone matgloss mapping + if(!DF.ReadCreatureMatgloss(creaturestypes)) + { + cerr << "Can't get the creature types." << endl; + return 1; + } + + uint32_t numCreatures = DF.InitReadCreatures(); + for(uint32_t i = 0; i < numCreatures; i++) + { + t_creature temp; + DF.ReadCreature(i, temp); + cout << "creature type " << creaturestypes[temp.type].id << ", position:" << temp.x << " " << temp.y << " "<< temp.z << endl; + } + DF.FinishReadCreatures(); + delete pDF; + return 0; +} \ No newline at end of file