diff --git a/library/DFMemInfo.cpp b/library/DFMemInfo.cpp index 8c0b1f864..4d6149e77 100644 --- a/library/DFMemInfo.cpp +++ b/library/DFMemInfo.cpp @@ -734,3 +734,19 @@ std::string memory_info::getMood(const uint32_t moodID) } throw Error::MissingMemoryDefinition("Mood", moodID); } + +std::string memory_info::PrintOffsets() +{ + ostringstream ss; + map::const_iterator iter; + for(iter = d->addresses.begin(); iter != d->addresses.end(); iter++) + { + ss << "address " << (*iter).first << " : " << hex << "0x" << (*iter).second << endl; + } + map::const_iterator iter2; + for(iter2 = d->offsets.begin(); iter2 != d->offsets.end(); iter2++) + { + ss << "offset " << (*iter2).first << " : " << hex << "0x" << (*iter2).second << endl; + } + return ss.str(); +} \ No newline at end of file diff --git a/library/include/dfhack/DFMemInfo.h b/library/include/dfhack/DFMemInfo.h index 77b28ccd0..e40ecbf11 100644 --- a/library/include/dfhack/DFMemInfo.h +++ b/library/include/dfhack/DFMemInfo.h @@ -145,6 +145,11 @@ namespace DFHack * Get the internal classID->classname mapping (for speed). DO NOT MANIPULATE THE VECTOR! */ const std::vector * getClassIDMapping(); + + /** + * Get a string with all addresses and offsets + */ + std::string PrintOffsets(); }; } #endif // MEMINFO_H_INCLUDED diff --git a/tools/playground/CMakeLists.txt b/tools/playground/CMakeLists.txt index 749922a5a..eff712d97 100644 --- a/tools/playground/CMakeLists.txt +++ b/tools/playground/CMakeLists.txt @@ -13,6 +13,10 @@ TARGET_LINK_LIBRARIES(dfmoodump dfhack) ADD_EXECUTABLE(dftest test.cpp) TARGET_LINK_LIBRARIES(dftest dfhack) +# just dump offsets of the current version +ADD_EXECUTABLE(dfdoffsets dumpoffsets.cpp) +TARGET_LINK_LIBRARIES(dfdoffsets dfhack) + # bauxite - turn all mechanisms into bauxite mechanisms # Author: Alex Legg #ADD_EXECUTABLE(dfbauxite dfbauxite.cpp) diff --git a/tools/playground/dumpoffsets.cpp b/tools/playground/dumpoffsets.cpp new file mode 100644 index 000000000..2257ca1de --- /dev/null +++ b/tools/playground/dumpoffsets.cpp @@ -0,0 +1,38 @@ +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +#include +using namespace DFHack; + +int main (int numargs, const char ** args) +{ + DFHack::ContextManager DFMgr("Memory.xml"); + DFHack::Context * DF; + try + { + DF = DFMgr.getSingleContext(); + DF->Attach(); + } + catch (exception& e) + { + cerr << e.what() << endl; + #ifndef LINUX_BUILD + cin.ignore(); + #endif + return 1; + } + memory_info * minfo = DF->getMemoryInfo(); + if(minfo) + cout << minfo->PrintOffsets(); + #ifndef LINUX_BUILD + cout << "Done. Press any key to continue" << endl; + cin.ignore(); + #endif + return 0; +}