From ddc2dd354dce5a130d4a9c7e4fbea27e31fe5b34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Fri, 23 Apr 2010 04:00:41 +0200 Subject: [PATCH] operator precedence! --- dfhack/include/modules/Maps.h | 4 +- examples/veccheck.cpp | 74 +++++++++++++++++++++++++---------- output/Memory.xml | 15 +++---- 3 files changed, 63 insertions(+), 30 deletions(-) diff --git a/dfhack/include/modules/Maps.h b/dfhack/include/modules/Maps.h index 2e03d54ce..883fa61ae 100644 --- a/dfhack/include/modules/Maps.h +++ b/dfhack/include/modules/Maps.h @@ -114,8 +114,8 @@ namespace DFHack e_traffic traffic : 2; // needs enum unsigned int flow_forbid : 1; // what? unsigned int liquid_static : 1; - unsigned int feature_type_1 : 1; // this tile is a part of a feature - unsigned int feature_type_2 : 1; // this tile is a part of a feature + unsigned int feature_local : 1; // this tile is a part of a feature + unsigned int feature_global : 1; // this tile is a part of a feature unsigned int liquid_character : 2; // those ripples on streams? }; diff --git a/examples/veccheck.cpp b/examples/veccheck.cpp index d3f55d5cf..685304ef5 100644 --- a/examples/veccheck.cpp +++ b/examples/veccheck.cpp @@ -113,18 +113,18 @@ int main (int numargs, const char ** args) 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_feature1"); - uint32_t block_feature2 = mem->getOffset("map_data_feature2"); + 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("feature1_start_ptr"); - uint32_t regionX, regionY, regionZ; + 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, regionX); - p->readDWord (region_y_offset, regionY); - p->readDWord (region_z_offset, regionZ); + 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(); @@ -152,46 +152,78 @@ int main (int numargs, const char ** args) if(tileTypeTable[tiletype].name) cout << " = " << tileTypeTable[tiletype].name; cout << endl; - // features present - if(des.feature_type_1) + // local feature present + if(des.feature_local) { - cout << "feature type 1 present: " << p->readDWord(block.origin + block_feature1) << endl; - int32_t idx = p->readDWord(block.origin + block_feature1); + 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 bigblock_x = cursorX / 48 + regionX; - // blah, dumb disassembly. too tired to think - uint16_t v12 = ((bigblock_x % 16) + bigblock_x) / 16; + uint64_t block48_x = cursorX / 48 + regionX; + cout << "cursorX: " << cursorX << ", regionX:" << regionX << endl; + cout << "bigblock_x: " << block48_x << endl; + + uint16_t v12 = ((block48_x & 0xF) + block48_x) >> 4; + uint16_t v12b = block48_x / 16; + cout << "v12: " << v12 << " : " << v12b << endl; + 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 + (v12 / 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) { - uint32_t feat_vector = wtf + 24 * (region_y_local % 16); + //v14 = v10 + 24 * ((signed __int16)_tX + 16 * v9 % 16); + uint32_t feat_vector = wtf + 24 * ((region_y_local % 16) + 16 * (v12 % 16)); + cout << "local feature vector: " << feat_vector << endl; DfVector p_features(p, feat_vector); - printf("feature addr: 0x%x\n", p_features[idx]); + /* + 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; + } } } } - if(des.feature_type_2) + // global feature present + if(des.feature_global) { - int32_t idx = p->readDWord(block.origin + block_feature2); - cout << "feature type 2 present: " << idx << endl; + int16_t idx = p->readWord(block.origin + block_feature2); + cout << "global feature present: " << idx << endl; if(idx != -1) { - DfVector p_features (p,mem->getAddress("feature2_vector")); + 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("feature2_funcptr_")); + 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; + } } } } diff --git a/output/Memory.xml b/output/Memory.xml index 5aff6abb2..d4a4ca514 100644 --- a/output/Memory.xml +++ b/output/Memory.xml @@ -1061,14 +1061,14 @@ size=212 0x179c 0x1D9C 0x0D9c - 0x2C adamantine? - 0x30 hell? + 0x2C local features + 0x30 global features WORLD + 0x54374 -
0x16AF4FC
- 0x100 +
0x16AF4FC
+ 0x100 WORLD + 0x54440 -
0x16AF5C8
+
0x16AF5C8