diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index e430b94b0..7ec11cc62 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -57,6 +57,10 @@ TARGET_LINK_LIBRARIES(dfsuspend dfhack) ADD_EXECUTABLE(dfvecc veccheck.cpp) TARGET_LINK_LIBRARIES(dfvecc dfhack) +# treedump - dump them trees! +ADD_EXECUTABLE(dftreedump treedump.cpp) +TARGET_LINK_LIBRARIES(dftreedump dfhack) + # catsplosion - Makes every cat pregnant, and almost due... # Author: Zhentar # ADD_EXECUTABLE(dfcatsplosion catsplosion.cpp) diff --git a/examples/buildingsdump.cpp b/examples/buildingsdump.cpp index 7b87b734b..dee75ceb4 100644 --- a/examples/buildingsdump.cpp +++ b/examples/buildingsdump.cpp @@ -12,96 +12,7 @@ using namespace std; #include #include #include - -/* -address = absolute address of dump start -length = length in lines. 1 line = 16 bytes -*/ -void hexdump (DFHack::API& DF, uint32_t address, uint32_t length) -{ - char *buf = new char[length * 16]; - - DF.ReadRaw(address, length * 16, (uint8_t *) buf); - for (int i = 0; i < length; i++) - { - // leading offset - cout << "0x" << hex << setw(4) << i*16 << " "; - // groups - for(int j = 0; j < 4; j++) - { - // bytes - for(int k = 0; k < 4; k++) - { - int idx = i * 16 + j * 4 + k; - - cout << hex << setw(2) << int(static_cast(buf[idx])) << " "; - } - cout << " "; - } - cout << endl; - } - delete buf; -} - -void interleave_hex (DFHack::API& DF, vector < uint32_t > & addresses, uint32_t length) -{ - vector bufs; - - for(int counter = 0; counter < addresses.size(); counter ++) - { - char * buf = new char[length * 16]; - DF.ReadRaw(addresses[counter], length * 16, (uint8_t *) buf); - bufs.push_back(buf); - } - cout << setfill('0'); - - // output a header - cout << "line offset "; - for (int obj = 0; obj < addresses.size(); obj++) - { - cout << "0x" << hex << setw(9) << addresses[obj] << " "; - } - cout << endl; - - for(int offs = 0 ; offs < length * 16; offs += 4) - { - if((!(offs % 16)) && offs != 0) - { - cout << endl; - } - cout << setfill(' '); - cout << dec << setw(4) << offs/4 << " "; - cout << setfill('0'); - cout << "0x" << hex << setw(4) << offs << " "; - for (int object = 0; object < bufs.size(); object++) - { - // bytes - for(int k = 0; k < 4; k++) - { - uint8_t data = bufs[object][offs + k]; - cout << hex << setw(2) << int(static_cast(data)) << " "; - } - cout << " "; - } - cout << endl; - } - for(int counter = 0; counter < addresses.size(); counter ++) - { - delete bufs[counter]; - } -} - -template -void print_bits ( T val, std::ostream& out ) -{ - T n_bits = sizeof ( val ) * CHAR_BIT; - - for ( unsigned i = 0; i < n_bits; ++i ) { - out<< !!( val & 1 ) << " "; - val >>= 1; - } -} - +#include "miscutils.h" int main (int argc,const char* argv[]) { diff --git a/examples/materialtest.cpp b/examples/materialtest.cpp index 5f5acdda3..815a0c510 100644 --- a/examples/materialtest.cpp +++ b/examples/materialtest.cpp @@ -15,30 +15,6 @@ using namespace std; #include #include -void DumpObjStr0Vector (const char * name, DFHack::Process *p, uint32_t addr) -{ - cout << "----==== " << name << " ====----" << endl; - DFHack::DfVector vect(p,addr,4); - for(int i = 0; i < vect.getSize();i++) - { - uint32_t addr = *(uint32_t *) vect[i]; - cout << p->readSTLString(addr) << endl; - } - cout << endl; -} - -void DumpDWordVector (const char * name, DFHack::Process *p, uint32_t addr) -{ - cout << "----==== " << name << " ====----" << endl; - DFHack::DfVector vect(p,addr,4); - for(int i = 0; i < vect.getSize();i++) - { - uint32_t number = *(uint32_t *) vect[i]; - cout << number << endl; - } - cout << endl; -} - int main (int numargs, const char ** args) { uint32_t addr; @@ -65,33 +41,6 @@ int main (int numargs, const char ** args) DFHack::memory_info* mem = DF.getMemoryInfo(); DFHack::Materials *Materials = DF.getMaterials(); - //const vector * names = mem->getClassIDMapping(); - /* - DumpObjStr0Vector("Material templates",p, mem->getAddress("mat_templates")); - - DumpObjStr0Vector("Inorganics",p, mem->getAddress("mat_inorganics")); - - DumpObjStr0Vector("Organics - all",p, mem->getAddress("mat_organics_all")); - - DumpObjStr0Vector("Organics - plants",p, mem->getAddress("mat_organics_plants")); - - DumpDWordVector("Maybe map between all organics and plants",p, mem->getAddress("mat_unk1_numbers")); - - DumpObjStr0Vector("Trees/wood",p, mem->getAddress("mat_organics_trees")); - - DumpDWordVector("Maybe map between all organics and trees",p, mem->getAddress("mat_unk2_numbers")); - - DumpObjStr0Vector("Body material templates",p, mem->getAddress("mat_body_material_templates")); - - DumpObjStr0Vector("Body detail plans",p, mem->getAddress("mat_body_detail_plans")); - - DumpObjStr0Vector("Bodies",p, mem->getAddress("mat_bodies")); - - DumpObjStr0Vector("Bodygloss",p, mem->getAddress("mat_bodygloss")); - - DumpObjStr0Vector("Creature variations",p, mem->getAddress("mat_creature_variations")); - */ - cout << "----==== Inorganic ====----" << endl; vector matgloss; Materials->ReadInorganicMaterials (matgloss); diff --git a/examples/renamer.cpp b/examples/renamer.cpp index 953ff2591..927c620c7 100644 --- a/examples/renamer.cpp +++ b/examples/renamer.cpp @@ -14,19 +14,8 @@ using namespace std; #include #include #include -#include - -template -void print_bits ( T val, std::ostream& out ) -{ - T n_bits = sizeof ( val ) * CHAR_BIT; - - for ( unsigned i = 0; i < n_bits; ++i ) - { - out<< !!( val & 1 ) << " "; - val >>= 1; - } -} +#include +#include "miscutils.h" vector< vector > englishWords; vector< vector > foreignWords; diff --git a/examples/treedump.cpp b/examples/treedump.cpp new file mode 100644 index 000000000..463bbb8c3 --- /dev/null +++ b/examples/treedump.cpp @@ -0,0 +1,107 @@ +// Just show some position data + +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "miscutils.h" + +int main (int numargs, const char ** args) +{ + uint32_t addr; + if (numargs == 2) + { + istringstream input (args[1],istringstream::in); + input >> std::hex >> addr; + } + DFHack::API DF("Memory.xml"); + try + { + DF.Attach(); + } + catch (exception& e) + { + cerr << e.what() << endl; + #ifndef LINUX_BUILD + cin.ignore(); + #endif + return 1; + } + + DFHack::Process* p = DF.getProcess(); + DFHack::memory_info* mem = DF.getMemoryInfo(); + DFHack::Position * pos = DF.getPosition(); + DFHack::Vegetation * v = DF.getVegetation(); + DFHack::Materials * mat = DF.getMaterials(); + vector organics; + mat->ReadOrganicMaterials(organics); + + int32_t x,y,z; + pos->getCursorCoords(x,y,z); + + + uint32_t numVegs = 0; + v->Start(numVegs); + if(x == -30000) + { + cout << "----==== Trees ====----" << endl; + for(uint32_t i =0; i < numVegs; i++) + { + DFHack::t_tree tree; + v->Read(i,tree); + printf("%d/%d/%d, %d:%d\n",tree.x,tree.y,tree.z,tree.type,tree.material); + } + } + else + { + cout << "----==== Tree at "<< x << "/" << y << "/" << z << " ====----" << endl; + for(uint32_t i =0; i < numVegs; i++) + { + DFHack::t_tree tree; + v->Read(i,tree); + if(tree.x == x && tree.y == y && tree.z == z) + { + printf("%d:%d = ",tree.type,tree.material); + if(tree.type == 1 || tree.type == 3) + { + cout << "near-water "; + } + cout << organics[tree.material].id << " "; + if(tree.type == 0 || tree.type == 1) + { + cout << "tree"; + } + if(tree.type == 2 || tree.type == 3) + { + cout << "shrub"; + } + cout << endl; + printf("Address: 0x%x\n", tree.address); + hexdump(DF,tree.address,13); + break; + } + } + } + v->Finish(); + + #ifndef LINUX_BUILD + cout << "Done. Press any key to continue" << endl; + cin.ignore(); + #endif + return 0; +} diff --git a/examples/veccheck.cpp b/examples/veccheck.cpp index 74a746a8e..93452467f 100644 --- a/examples/veccheck.cpp +++ b/examples/veccheck.cpp @@ -19,72 +19,7 @@ using namespace std; #include #include #include - -void DumpObjStr0Vector (const char * name, DFHack::Process *p, uint32_t addr) -{ - cout << "----==== " << name << " ====----" << endl; - DFHack::DfVector vect(p,addr,4); - for(int i = 0; i < vect.getSize();i++) - { - uint32_t addr = *(uint32_t *) vect[i]; - cout << p->readSTLString(addr) << endl; - } - cout << endl; -} -void DumpObjVtables (const char * name, DFHack::Process *p, uint32_t addr) -{ - cout << "----==== " << name << " ====----" << endl; - DFHack::DfVector vect(p,addr,4); - for(int i = 0; i < vect.getSize();i++) - { - uint32_t addr = *(uint32_t *) vect[i]; - uint32_t vptr = p->readDWord(addr); - cout << p->readClassName(vptr) << endl; - } - cout << endl; -} -void DumpDWordVector (const char * name, DFHack::Process *p, uint32_t addr) -{ - cout << "----==== " << name << " ====----" << endl; - DFHack::DfVector vect(p,addr,4); - for(int i = 0; i < vect.getSize();i++) - { - uint32_t number = *(uint32_t *) vect[i]; - cout << number << endl; - } - cout << endl; -} - -/* -address = absolute address of dump start -length = length in lines. 1 line = 16 bytes -*/ -void hexdump (DFHack::API& DF, uint32_t address, uint32_t length) -{ - char *buf = new char[length * 16]; - - DF.ReadRaw(address, length * 16, (uint8_t *) buf); - for (int i = 0; i < length; i++) - { - // leading offset - cout << "0x" << hex << setw(4) << i*16 << " "; - // groups - for(int j = 0; j < 4; j++) - { - // bytes - for(int k = 0; k < 4; k++) - { - int idx = i * 16 + j * 4 + k; - - cout << hex << setw(2) << int(static_cast(buf[idx])) << " "; - } - cout << " "; - } - cout << endl; - } - delete buf; -} - +#include "miscutils.h" int main (int numargs, const char ** args) { @@ -107,122 +42,7 @@ int main (int numargs, const char ** args) #endif return 1; } - - DFHack::Process* p = DF.getProcess(); - DFHack::memory_info* mem = DF.getMemoryInfo(); - //const vector * names = mem->getClassIDMapping(); -/* - string name="Stuff"; - cout << "----==== " << name << " ====----" << endl; - DFHack::DfVector vect(p,0x165b290,4); - for(int i = 0; i < vect.getSize();i++) - { - uint32_t addr = *(uint32_t *) vect[i]; - DFHack::t_construction_df40d constr; - DF.ReadRaw(addr, sizeof(constr), (uint8_t *) &constr); - printf("0x%x %dX %dY %dZ: %d:%d\n", addr, constr.x, constr.y, constr.z, - constr.material.type,constr.material.index); - } - - - cout << endl; - */ - /* - DumpObjVtables("Constructions?",p,0x165b278); - DumpObjVtables("Constructions?",p,0x166edb8); - */ - /* - DumpObjStr0Vector("Material templates",p, mem->getAddress("mat_templates")); - */ - /* - DumpObjStr0Vector("Inorganics",p, mem->getAddress("mat_inorganics")); - - cout << "----==== Inorganics ====----" << endl; - DFHack::DfVector vect(p,addr,4); - for(int i = 0; i < vect.getSize();i++) - { - uint32_t addr = *(uint32_t *) vect[i]; - cout << p->readSTLString(addr) << endl; - } - cout << endl; - */ - /* - DumpObjStr0Vector("Organics - all",p, mem->getAddress("mat_organics_all")); - - DumpObjStr0Vector("Organics - plants",p, mem->getAddress("mat_organics_plants")); - - DumpDWordVector("Maybe map between all organics and plants",p, mem->getAddress("mat_unk1_numbers")); - - DumpObjStr0Vector("Trees/wood",p, mem->getAddress("mat_organics_trees")); - - DumpDWordVector("Maybe map between all organics and trees",p, mem->getAddress("mat_unk2_numbers")); - - DumpObjStr0Vector("Body material templates",p, mem->getAddress("mat_body_material_templates")); - - DumpObjStr0Vector("Body detail plans",p, mem->getAddress("mat_body_detail_plans")); - - DumpObjStr0Vector("Bodies",p, mem->getAddress("mat_bodies")); - - DumpObjStr0Vector("Bodygloss",p, mem->getAddress("mat_bodygloss")); - - DumpObjStr0Vector("Creature variations",p, mem->getAddress("mat_creature_variations")); - - DumpObjStr0Vector("Creature types",p, mem->getAddress("mat_creature_types")); - */ - DFHack::Position * pos = DF.getPosition(); - DFHack::Vegetation * v = DF.getVegetation(); - DFHack::Materials * mat = DF.getMaterials(); - vector organics; - mat->ReadOrganicMaterials(organics); - - int32_t x,y,z; - pos->getCursorCoords(x,y,z); - - - uint32_t numVegs = 0; - v->Start(numVegs); - if(x == -30000) - { - cout << "----==== Trees ====----" << endl; - for(uint32_t i =0; i < numVegs; i++) - { - DFHack::t_tree tree; - v->Read(i,tree); - printf("%d/%d/%d, %d:%d\n",tree.x,tree.y,tree.z,tree.type,tree.material); - } - } - else - { - cout << "----==== Tree at "<< x << "/" << y << "/" << z << " ====----" << endl; - for(uint32_t i =0; i < numVegs; i++) - { - DFHack::t_tree tree; - v->Read(i,tree); - if(tree.x == x && tree.y == y && tree.z == z) - { - printf("%d:%d = ",tree.type,tree.material); - if(tree.type == 1 || tree.type == 3) - { - cout << "near-water "; - } - cout << organics[tree.material].id << " "; - if(tree.type == 0 || tree.type == 1) - { - cout << "tree"; - } - if(tree.type == 2 || tree.type == 3) - { - cout << "shrub"; - } - cout << endl; - printf("Address: 0x%x\n", tree.address); - hexdump(DF,tree.address,13); - break; - } - } - } - v->Finish(); - + #ifndef LINUX_BUILD cout << "Done. Press any key to continue" << endl; cin.ignore(); diff --git a/output/Memory.xml b/output/Memory.xml index d80209eab..9eac342f3 100644 --- a/output/Memory.xml +++ b/output/Memory.xml @@ -2859,7 +2859,7 @@ 0x18 0xC Vector layout in MSVC 9: - DWORD Allocator + DWORD Allocator? DWORD ? DWORD ? DWORD Start @@ -2867,6 +2867,9 @@ DWORD AllocationEnd 0x1C + +
0x0165B188
Position and window dimensions ============================== @@ -3050,6 +3053,11 @@ map_data_1b60_offset 0x1B9c :( + Settlements + =========== + + :( +