From ceaea4341dc3b82cf585fd73340bb1e10cf207e0 Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 23 Apr 2010 18:22:45 +0200 Subject: [PATCH] mood dump test --- dfhack/include/modules/Creatures.h | 1 + tools/CMakeLists.txt | 7 +- tools/moodump.cpp | 115 +++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 tools/moodump.cpp diff --git a/dfhack/include/modules/Creatures.h b/dfhack/include/modules/Creatures.h index e6f826f9b..15a85c7be 100644 --- a/dfhack/include/modules/Creatures.h +++ b/dfhack/include/modules/Creatures.h @@ -327,6 +327,7 @@ namespace DFHack t_name name; int16_t mood; + int16_t mood_skill; t_name artifact_name; uint8_t profession; diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 2be94dc20..e707d0f2a 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -5,6 +5,10 @@ IF(UNIX) add_definitions(-DLINUX_BUILD) ENDIF(UNIX) +# a moodump clone +ADD_EXECUTABLE(dfmoodump moodump.cpp) +TARGET_LINK_LIBRARIES(dfmoodump dfhack) + # a reveal clone ADD_EXECUTABLE(dfreveal reveal.cpp) TARGET_LINK_LIBRARIES(dfreveal dfhack) @@ -63,6 +67,7 @@ dfincremental #dfmagma_create dfprospector dfreveal +dfmoodump RUNTIME DESTINATION bin ) -ENDIF(UNIX) \ No newline at end of file +ENDIF(UNIX) diff --git a/tools/moodump.cpp b/tools/moodump.cpp new file mode 100644 index 000000000..5f2b179f5 --- /dev/null +++ b/tools/moodump.cpp @@ -0,0 +1,115 @@ +#include +#include +#include +#include +using namespace std; + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct matGlosses +{ + vector plantMat; + vector woodMat; + vector stoneMat; + vector metalMat; + vector creatureMat; +}; + +vector creaturestypes; +matGlosses mat; +vector< vector > itemTypes; +DFHack::memory_info *mem; +vector< vector > englishWords; +vector< vector > foreignWords; + +int main (int numargs, char ** args) +{ + DFHack::API DF("Memory.xml"); + DFHack::Process * p; + try + { + DF.Attach(); + } + catch (exception& e) + { + cerr << e.what() << endl; + #ifndef LINUX_BUILD + cin.ignore(); + #endif + return 1; + } + p = DF.getProcess(); + string check = ""; + if(numargs == 2) + check = args[1]; + + DFHack::Creatures * Creatures = DF.getCreatures(); + DFHack::Materials * Materials = DF.getMaterials(); + DFHack::Translation * Tran = DF.getTranslation(); + + uint32_t numCreatures; + if(!Creatures->Start(numCreatures)) + { + cerr << "Can't get creatures" << endl; + #ifndef LINUX_BUILD + cin.ignore(); + #endif + return 1; + } + if(!numCreatures) + { + cerr << "No creatures to print" << endl; + #ifndef LINUX_BUILD + cin.ignore(); + #endif + return 1; + } + mem = DF.getMemoryInfo(); + // get stone matgloss mapping + if(!Materials->ReadCreatureTypesEx(creaturestypes)) + { + cerr << "Can't get the creature types." << endl; + return 1; + } + + if(!Tran->Start()) + { + cerr << "Can't get name tables" << endl; + return 1; + } + vector addrs; + //DF.InitViewAndCursor(); + for(uint32_t i = 0; i < numCreatures; i++) + { + DFHack::t_creature temp; + unsigned int current_job; + unsigned int mat_start; + unsigned int mat_end; + unsigned int j; + + Creatures->ReadCreature(i,temp); + if(temp.mood) + { + cout << "address: " << hex << temp.origin << dec << " creature type: " << creaturestypes[temp.race].rawname << endl; + current_job = p->readDWord(temp.origin + 0x390); + mat_start = p->readDWord(current_job + 0xa4 + 4*3); + mat_end = p->readDWord(current_job + 0xa4 + 4*4); + } + } + Creatures->Finish(); + DF.Detach(); + #ifndef LINUX_BUILD + cout << "Done. Press any key to continue" << endl; + cin.ignore(); + #endif + return 0; +} +