From 26bbd1de176927ff44441357efb6a8914ce0b6af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Fri, 30 Apr 2010 21:52:37 +0200 Subject: [PATCH] Make new probe tool out of the 'vecc' thing. --- .../include/DFMiscUtils.h | 0 examples/buildingsdump.cpp | 2 +- examples/construction_dump.cpp | 2 +- examples/creaturedump.cpp | 2 +- examples/spatterdump.cpp | 2 +- examples/treedump.cpp | 2 +- examples/veccheck.cpp | 96 ++---------- examples/veinlook.cpp | 14 +- tools/CMakeLists.txt | 4 + tools/probe.cpp | 137 ++++++++++++++++++ 10 files changed, 161 insertions(+), 100 deletions(-) rename examples/miscutils.h => dfhack/include/DFMiscUtils.h (100%) create mode 100644 tools/probe.cpp diff --git a/examples/miscutils.h b/dfhack/include/DFMiscUtils.h similarity index 100% rename from examples/miscutils.h rename to dfhack/include/DFMiscUtils.h diff --git a/examples/buildingsdump.cpp b/examples/buildingsdump.cpp index 304e4ac96..5ba7d8357 100644 --- a/examples/buildingsdump.cpp +++ b/examples/buildingsdump.cpp @@ -18,7 +18,7 @@ using namespace std; #include #include #include -#include "miscutils.h" +#include int main (int argc,const char* argv[]) { diff --git a/examples/construction_dump.cpp b/examples/construction_dump.cpp index 19c52d1e1..3596059f6 100644 --- a/examples/construction_dump.cpp +++ b/examples/construction_dump.cpp @@ -19,7 +19,7 @@ using namespace std; #include #include #include -#include "miscutils.h" +#include using namespace DFHack; diff --git a/examples/creaturedump.cpp b/examples/creaturedump.cpp index d7e248332..8f2b8a237 100644 --- a/examples/creaturedump.cpp +++ b/examples/creaturedump.cpp @@ -16,7 +16,7 @@ using namespace std; #include #include #include -#include "miscutils.h" +#include enum likeType { diff --git a/examples/spatterdump.cpp b/examples/spatterdump.cpp index 09207de42..bf8d58dd0 100644 --- a/examples/spatterdump.cpp +++ b/examples/spatterdump.cpp @@ -21,7 +21,7 @@ using namespace std; #include #include #include -#include "miscutils.h" +#include using namespace DFHack; diff --git a/examples/treedump.cpp b/examples/treedump.cpp index 4b9aefc1d..de5bd54f4 100644 --- a/examples/treedump.cpp +++ b/examples/treedump.cpp @@ -20,7 +20,7 @@ using namespace std; #include #include #include -#include "miscutils.h" +#include int main (int numargs, const char ** args) { diff --git a/examples/veccheck.cpp b/examples/veccheck.cpp index 16290c0a0..05feb5c6b 100644 --- a/examples/veccheck.cpp +++ b/examples/veccheck.cpp @@ -21,7 +21,7 @@ using namespace std; #include #include #include -#include "miscutils.h" +#include #include using namespace DFHack; @@ -136,9 +136,11 @@ int main (int numargs, const char ** args) uint32_t tileX = cursorX % 16; uint32_t blockY = cursorY / 16; uint32_t tileY = cursorY % 16; + t_temperatures tmpb1, tmpb2; mapblock40d block; if(Maps->ReadBlock40d(blockX,blockY,cursorZ,&block)) { + Maps->ReadTemperatures(blockX,blockY,cursorZ,&tmpb1, &tmpb2); printf("block addr: 0x%x\n", block.origin); int16_t tiletype = block.tiletypes[tileX][tileY]; naked_designation &des = block.designation[tileX][tileY].bits; @@ -147,87 +149,17 @@ int main (int numargs, const char ** args) cout << endl; print_bits(block.occupancy[tileX][tileY].whole,cout); cout << endl; + // tiletype cout <<"tiletype: " << tiletype; if(tileTypeTable[tiletype].name) cout << " = " << tileTypeTable[tiletype].name; cout << endl; - // local feature present - if(des.feature_local) - { - cout << "local feature present: " << p->readWord(block.origin + block_feature1) << endl; - int16_t idx = p->readWord(block.origin + block_feature1); - if(idx != -1) - { - uint64_t block48_x = cursorX / 48 + regionX; - cout << "cursorX: " << cursorX << ", regionX:" << regionX << endl; - cout << "bigblock_x: " << block48_x << endl; - - // region X coord offset by 8 big blocks (48x48 tiles) - uint16_t region_x_plus8 = ( block48_x + 8 ) / 16; - //uint16_t v12b = block48_x / 16; - //cout << "v12: " << v12 << " : " << v12b << endl; - // plain region Y coord - uint64_t region_y_local = (cursorY / 48 + regionY) / 16; - cout << "region_y_local: " << region_y_local << endl; - - // deref pointer to the humongo-structure - uint32_t base = p->readDWord(feature1_start_ptr); - cout << "base! : " << base << endl; - // this is just a few pointers to arrays of 16B (4 DWORD) structs - uint32_t array_elem = p->readDWord(base + (region_x_plus8 / 16) * 4); - cout << "array_elem : " << array_elem << endl; - // second element of the struct is a pointer - uint32_t wtf = p->readDWord(array_elem + (16*(region_y_local/16)) + 4); // rounding! - - cout << "wtf : " << wtf << " @" << array_elem + (16*(region_y_local/16)) << endl; - if(wtf) - { - //v14 = v10 + 24 * ((signed __int16)_tX + 16 * v9 % 16); - uint32_t feat_vector = wtf + 24 * ((region_y_local % 16) + 16 * (region_x_plus8 % 16)); - cout << "local feature vector: " << feat_vector << endl; - DfVector p_features(p, feat_vector); - /* - for(int k = 0 ; k < p_features.size();k++) - { - printf("feature %d addr: 0x%x\n", k, p_features[k]); - string name = p->readClassName(p->readDWord( p_features[k] )); - cout << name << endl; - } - */ - printf("feature %d addr: 0x%x\n", idx, p_features[idx]); - string name = p->readClassName(p->readDWord( p_features[idx] )); - bool discovered = p->readDWord( p_features[idx] + 4 ); - cout << name << endl; - if(discovered) - { - cout << "You've discovered it already!" << endl; - } - } - } - } - // global feature present - if(des.feature_global) - { - int16_t idx = p->readWord(block.origin + block_feature2); - cout << "global feature present: " << idx << endl; - if(idx != -1) - { - DfVector p_features (p,mem->getAddress("global_feature_vector")); - if(idx < p_features.size()) - { - uint32_t feat_ptr = p->readDWord(p_features[idx] + mem->getOffset("global_feature_funcptr_")); - printf("feature descriptor?: 0x%x\n", feat_ptr); - string name = p->readClassName(p->readDWord( feat_ptr)); - bool discovered = p->readDWord( p_features[idx] + 4 ); - cout << name << endl; - if(discovered) - { - cout << "You've discovered it already!" << endl; - } - } - } - } + + + cout <<"temperature1: " << tmpb1[tileX][tileY] << " U" << endl; + cout <<"temperature2: " << tmpb2[tileX][tileY] << " U" << endl; + // biome, geolayer cout << "biome: " << des.biome << endl; cout << "geolayer: " << des.geolayer_index << endl; @@ -262,16 +194,6 @@ int main (int numargs, const char ** args) else cout << " "; cout << endl; - /* - block.designation[tx][ty].bits.moss = 1; - block.designation[tx][ty].bits.geolayer_index = 15; - block.tiletypes[tx][ty] = 344; - - print_bits(block.designation[tx][ty].whole,cout); - Maps->WriteDesignations(bx,by,cz,&(block.designation)); - Maps->WriteTileTypes(bx,by,cz,&(block.tiletypes)); - */ - } } #ifndef LINUX_BUILD diff --git a/examples/veinlook.cpp b/examples/veinlook.cpp index 237244b4c..a916db35f 100644 --- a/examples/veinlook.cpp +++ b/examples/veinlook.cpp @@ -24,7 +24,7 @@ using namespace std; #include #include #include -#include "miscutils.h" +#include using namespace DFHack; @@ -537,8 +537,6 @@ main(int argc, char *argv[]) map materials; materials.clear(); mapblock40d blocks[3][3]; - vector stonetypes; - vector creature_types; vector effects; vector< vector > layerassign; vector veinVector; @@ -583,14 +581,14 @@ main(int argc, char *argv[]) z_max = z_max_a; // get stone matgloss mapping - if(!Mats->ReadInorganicMaterials(stonetypes)) + if(!Mats->ReadInorganicMaterials()) { error = "Can't read stone types."; pDF = 0; finish(0); } - if(!Mats->ReadCreatureTypes(creature_types)) + if(!Mats->ReadCreatureTypes()) { error = "Can't read stone types."; pDF = 0; @@ -745,7 +743,7 @@ main(int argc, char *argv[]) // extra processing of the block in the middle if(i == 0 && j == 0) { - do_features(DF, Block, cursorX, cursorY, 50,10, stonetypes); + do_features(DF, Block, cursorX, cursorY, 50,10, Mats->inorganic); // read veins Maps->ReadVeins(cursorX+i,cursorY+j,cursorZ,&veinVector,&IceVeinVector,&splatter); @@ -882,7 +880,7 @@ main(int argc, char *argv[]) } } gotoxy(50,3); - cprintf("Mineral: %s",stonetypes[veinVector[vein].type].id); + cprintf("Mineral: %s",Mats->inorganic[veinVector[vein].type].id); } else if (vein < mineralsize + icesize) { @@ -922,7 +920,7 @@ main(int argc, char *argv[]) } } gotoxy(50,3); - cprintf("Spatter: %s",PrintSplatterType(splatter[realvein].mat1,splatter[realvein].mat2,creature_types).c_str()); + cprintf("Spatter: %s",PrintSplatterType(splatter[realvein].mat1,splatter[realvein].mat2,Mats->race).c_str()); } } } diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 41d235cd0..f689a5573 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -29,6 +29,10 @@ TARGET_LINK_LIBRARIES(dfcleanmap dfhack) ADD_EXECUTABLE(dfunstuck unstuck.cpp) TARGET_LINK_LIBRARIES(dfunstuck dfhack) +# probe - map tile probe +ADD_EXECUTABLE(dfprobe probe.cpp) +TARGET_LINK_LIBRARIES(dfprobe dfhack) + IF(UNIX) # incrementalsearch - a bit like cheat engine, only DF-specific, very basic # and Linux-only diff --git a/tools/probe.cpp b/tools/probe.cpp new file mode 100644 index 000000000..643d5b513 --- /dev/null +++ b/tools/probe.cpp @@ -0,0 +1,137 @@ +// 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 +#include +#include +#include + +using namespace DFHack; +int main (int numargs, const char ** args) +{ + DFHack::API DF("Memory.xml"); + try + { + DF.Attach(); + } + catch (exception& e) + { + cerr << e.what() << endl; + #ifndef LINUX_BUILD + cin.ignore(); + #endif + return 1; + } + + DFHack::Position *Pos = DF.getPosition(); + DFHack::memory_info* mem = DF.getMemoryInfo(); + DFHack::Maps *Maps = DF.getMaps(); + DFHack::Process * p = DF.getProcess(); + uint32_t designatus = mem->getOffset("map_data_designation"); + uint32_t block_feature1 = mem->getOffset("map_data_feature_local"); + uint32_t block_feature2 = mem->getOffset("map_data_feature_global"); + uint32_t region_x_offset = mem->getAddress("region_x"); + uint32_t region_y_offset = mem->getAddress("region_y"); + uint32_t region_z_offset = mem->getAddress("region_z"); + uint32_t feature1_start_ptr = mem->getAddress("local_feature_start_ptr"); + int32_t regionX, regionY, regionZ; + + // read position of the region inside DF world + p->readDWord (region_x_offset, (uint32_t &)regionX); + p->readDWord (region_y_offset, (uint32_t &)regionY); + p->readDWord (region_z_offset, (uint32_t &)regionZ); + + Maps->Start(); + + int32_t cursorX, cursorY, cursorZ; + Pos->getCursorCoords(cursorX,cursorY,cursorZ); + if(cursorX != -30000) + { + uint32_t blockX = cursorX / 16; + uint32_t tileX = cursorX % 16; + uint32_t blockY = cursorY / 16; + uint32_t tileY = cursorY % 16; + t_temperatures tmpb1, tmpb2; + mapblock40d block; + if(Maps->ReadBlock40d(blockX,blockY,cursorZ,&block)) + { + Maps->ReadTemperatures(blockX,blockY,cursorZ,&tmpb1, &tmpb2); + printf("block addr: 0x%x\n", block.origin); + int16_t tiletype = block.tiletypes[tileX][tileY]; + naked_designation &des = block.designation[tileX][tileY].bits; + uint32_t &desw = block.designation[tileX][tileY].whole; + print_bits(block.designation[tileX][tileY].whole,cout); + cout << endl; + print_bits(block.occupancy[tileX][tileY].whole,cout); + cout << endl; + + // tiletype + cout <<"tiletype: " << tiletype; + if(tileTypeTable[tiletype].name) + cout << " = " << tileTypeTable[tiletype].name; + cout << endl; + + + cout <<"temperature1: " << tmpb1[tileX][tileY] << " U" << endl; + cout <<"temperature2: " << tmpb2[tileX][tileY] << " U" << endl; + + // biome, geolayer + cout << "biome: " << des.biome << endl; + cout << "geolayer: " << des.geolayer_index << endl; + // liquids + if(des.flow_size) + { + if(des.liquid_type == DFHack::liquid_magma) + cout <<"magma: "; + else cout <<"water: "; + cout << des.flow_size << endl; + } + if(des.flow_forbid) + cout << "flow forbid" << endl; + if(des.pile) + cout << "stockpile?" << endl; + if(des.rained) + cout << "rained?" << endl; + if(des.smooth) + cout << "smooth?" << endl; + uint32_t designato = block.origin + designatus + (tileX * 16 + tileY) * sizeof(t_designation); + printf("designation offset: 0x%x\n", designato); + if(des.light) + cout << "Light "; + else + cout << " "; + if(des.skyview) + cout << "SkyView "; + else + cout << " "; + if(des.subterranean) + cout << "Underground "; + else + cout << " "; + cout << endl; + } + } + #ifndef LINUX_BUILD + cout << "Done. Press any key to continue" << endl; + cin.ignore(); + #endif + return 0; +}