From 9268a79a66da3b5014d27e660e7b26037b1838d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 21 Feb 2010 05:51:29 +0100 Subject: [PATCH] Reading of tiletypes under ice - 'ice veins' --- examples/veinlook.cpp | 77 +++++++++++++++++++++---------------------- library/DFHackAPI.cpp | 34 ++++++++++++++----- library/DFHackAPI.h | 2 +- library/DFMemInfo.cpp | 16 +++++++++ library/DFMemInfo.h | 1 + tools/prospector.cpp | 3 +- 6 files changed, 83 insertions(+), 50 deletions(-) diff --git a/examples/veinlook.cpp b/examples/veinlook.cpp index 1f6941f4b..f2886ab54 100644 --- a/examples/veinlook.cpp +++ b/examples/veinlook.cpp @@ -280,6 +280,7 @@ main(int argc, char *argv[]) vector stonetypes; vector< vector > layerassign; vector veinVector; + vector IceVeinVector; // init the API DFHack::API DF("Memory.xml"); @@ -449,7 +450,8 @@ main(int argc, char *argv[]) DF.WriteDirtyBit(cursorX+i,cursorY+j,cursorZ,dirtybit); } veinVector.clear(); - DF.ReadVeins(cursorX+i,cursorY+j,cursorZ,veinVector); + IceVeinVector.clear(); + DF.ReadVeins(cursorX+i,cursorY+j,cursorZ,veinVector,IceVeinVector); } } } @@ -459,37 +461,20 @@ main(int argc, char *argv[]) gotoxy(0,49); cprintf("+,- = switch vein"); gotoxy(0,50); - if(vein == veinVector.size()) vein = veinVector.size() - 1; + uint32_t mineralsize = veinVector.size(); + uint32_t icesize = IceVeinVector.size(); + uint32_t totalVeinSize = mineralsize+ icesize; + if(vein == totalVeinSize) vein = totalVeinSize - 1; if(vein < -1) vein = -1; - cprintf("X %d/%d, Y %d/%d, Z %d/%d. Vein %d of %d",cursorX+1,x_max,cursorY+1,y_max,cursorZ,z_max,vein+1,veinVector.size()); - if(!veinVector.empty()) + cprintf("X %d/%d, Y %d/%d, Z %d/%d. Vein %d of %d",cursorX+1,x_max,cursorY+1,y_max,cursorZ,z_max,vein+1,totalVeinSize); + if(!veinVector.empty() || !IceVeinVector.empty()) { - if(vein != -1 && vein < veinVector.size()) + if(vein != -1 && vein < totalVeinSize) { - //string str = getGCCClassName(p, veinVector[vein].vtable); - string className = p->readClassName(veinVector[vein].vtable); - //string str = "34block_square_event_frozen_liquidst"; - if(className == "block_square_event_frozen_liquid") - { - t_frozenliquidvein frozen; - uint32_t size = sizeof(t_frozenliquidvein); - p->read(veinVector[vein].address_of,size,(uint8_t *)&frozen); - for(uint32_t i = 0;i<16;i++) - { - for (uint32_t j = 0; j< 16;j++) - { - int color = COLOR_BLACK; - int tile = frozen.tiles[i][j]; - color = pickColor(tile); - - attron(A_STANDOUT); - puttile(i+16,j+16,tile, color); - attroff(A_STANDOUT); - } - } - } - else if (className == "block_square_event_mineral") + uint32_t realvein = 0; + if(vein < mineralsize) { + realvein = vein; //iterate through vein rows for(uint32_t j = 0;j<16;j++) { @@ -497,31 +482,45 @@ main(int argc, char *argv[]) for (uint32_t k = 0; k< 16;k++) { // and the bit array with a one-bit mask, check if the bit is set - bool set = !!(((1 << k) & veinVector[vein].assignment[j]) >> k); + bool set = !!(((1 << k) & veinVector[realvein].assignment[j]) >> k); if(set) { putch(k+16,j+16,'$',COLOR_RED); } } } - gotoxy(0,53); - cprintf("%s",stonetypes[veinVector[vein].type].name); + gotoxy(0,51); + cprintf("Mineral: %s",stonetypes[veinVector[vein].type].name); } - gotoxy(0,51); - cprintf("%s, addr 0x%x, vptr 0x%x",className.c_str(),veinVector[vein].address_of, veinVector[vein].vtable); - gotoxy(0,52); - int32_t classID; - if(p->getDescriptor()->resolveClassId(veinVector[vein].address_of,classID)) + else { - cprintf("mxml: %s",classes[classID].c_str()); + realvein = vein - mineralsize; + t_frozenliquidvein &frozen = IceVeinVector[realvein]; + for(uint32_t i = 0;i<16;i++) + { + for (uint32_t j = 0; j< 16;j++) + { + int color = COLOR_BLACK; + int tile = frozen.tiles[i][j]; + color = pickColor(tile); + + attron(A_STANDOUT); + puttile(i+16,j+16,tile, color); + attroff(A_STANDOUT); + } + } + gotoxy(0,51); + cprintf("ICE"); } } } uint32_t sptr = blockaddr + p->getDescriptor()->getOffset("block_flags"); - gotoxy (0,54); + gotoxy (0,52); cprintf("block address 0x%x",blockaddr); - gotoxy (0,55); + gotoxy (0,53); cprintf("dirty bit: %d",dirtybit); + gotoxy (0,54); + cprintf ("d - dig veins, o - dump map block, z - toggle dirty bit"); wrefresh(stdscr); } pDF = 0; diff --git a/library/DFHackAPI.cpp b/library/DFHackAPI.cpp index e08b84f22..d2ce37bbc 100644 --- a/library/DFHackAPI.cpp +++ b/library/DFHackAPI.cpp @@ -45,6 +45,8 @@ public: uint32_t biome_stuffs; uint32_t veinvector; uint32_t veinsize; + uint32_t vein_mineral_vptr; + uint32_t vein_ice_vptr; uint32_t window_x_offset; uint32_t window_y_offset; @@ -163,6 +165,9 @@ bool API::InitMap() d->veinvector = d->offset_descriptor->getOffset ("v_vein"); d->veinsize = d->offset_descriptor->getHexValue ("v_vein_size"); + + d->vein_ice_vptr = d->offset_descriptor->getClassVPtr("block_square_event_frozen_liquid"); + d->vein_mineral_vptr = d->offset_descriptor->getClassVPtr("block_square_event_mineral"); // get the map pointer uint32_t x_array_loc = g_pProcess->readDWord (map_offset); @@ -367,13 +372,12 @@ bool API::ReadRegionOffsets (uint32_t x, uint32_t y, uint32_t z, uint8_t *buffer return false; } - -// veins of a block, expects empty vein vector -bool API::ReadVeins (uint32_t x, uint32_t y, uint32_t z, vector & veins) +// veins of a block, expects empty vein vectors +bool API::ReadVeins(uint32_t x, uint32_t y, uint32_t z, vector & veins, vector & ices) { uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; - //assert (sizeof (t_vein) == d->veinsize); veins.clear(); + ices.clear(); if (addr && d->veinvector && d->veinsize) { // veins are stored as a vector of pointers to veins @@ -386,14 +390,26 @@ bool API::ReadVeins (uint32_t x, uint32_t y, uint32_t z, vector & veins for (uint32_t i = 0; i < size;i++) { t_vein v; + t_frozenliquidvein fv; // read the vein pointer from the vector uint32_t temp = * (uint32_t *) p_veins[i]; - // read the vein data (dereference pointer) - g_pProcess->read (temp, d->veinsize, (uint8_t *) &v); - v.address_of = temp; - // store it in the vector - veins.push_back (v); + uint32_t type = g_pProcess->readDWord(temp); + if(type == d->vein_mineral_vptr) + { + // read the vein data (dereference pointer) + g_pProcess->read (temp, sizeof(t_vein), (uint8_t *) &v); + v.address_of = temp; + // store it in the vector + veins.push_back (v); + } + else if(type == d->vein_ice_vptr) + { + // read the ice vein data (dereference pointer) + g_pProcess->read (temp, sizeof(t_frozenliquidvein), (uint8_t *) &fv); + // store it in the vector + ices.push_back (fv); + } } return true; } diff --git a/library/DFHackAPI.h b/library/DFHackAPI.h index cdb24c882..0ebe6338f 100644 --- a/library/DFHackAPI.h +++ b/library/DFHackAPI.h @@ -149,7 +149,7 @@ namespace DFHack bool ReadRegionOffsets(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint8_t *buffer); // 16 * sizeof(uint8_t) /// read aggregated veins of a block - bool ReadVeins(uint32_t blockx, uint32_t blocky, uint32_t blockz, vector & veins); + bool ReadVeins(uint32_t blockx, uint32_t blocky, uint32_t blockz, vector & veins, vector & ices); /** * Buildings, constructions, plants, all pretty straighforward. InitReadBuildings returns all the building types as a mapping between a numeric values and strings diff --git a/library/DFMemInfo.cpp b/library/DFMemInfo.cpp index aa2afa4d3..a1745a977 100644 --- a/library/DFMemInfo.cpp +++ b/library/DFMemInfo.cpp @@ -328,6 +328,22 @@ bool memory_info::resolveClassId(uint32_t address, int32_t & classid) return false; } +//ALERT: doesn't care about multiclasses +uint32_t memory_info::getClassVPtr(string classname) +{ + // FIXME: another stupid search. + for(uint32_t i = 0;i< classes.size();i++) + { + //if(classes[i].) + if(classes[i].classname == classname) // got class + { + return classes[i].vtable; + } + } + // we failed to find anything that would match + return 0; +} + // Flatten vtables into a index<->name mapping void memory_info::getClassIDMapping(vector & v_ClassID2ObjName) { diff --git a/library/DFMemInfo.h b/library/DFMemInfo.h index 77aaf5999..abe99e492 100644 --- a/library/DFMemInfo.h +++ b/library/DFMemInfo.h @@ -118,6 +118,7 @@ namespace DFHack // ALERT: uses memory reading directly bool resolveClassId(const uint32_t address, int32_t & classid); void getClassIDMapping(vector & v_ClassID2ObjName); + uint32_t getClassVPtr(string classname); void flush(); diff --git a/tools/prospector.cpp b/tools/prospector.cpp index eb4250ca0..2427979c7 100644 --- a/tools/prospector.cpp +++ b/tools/prospector.cpp @@ -85,6 +85,7 @@ int main (int argc, const char* argv[]) int16_t tempvein [16][16]; vector veins; + vector iceveins; // walk the map! for(uint32_t x = 0; x< x_max;x++) { @@ -101,7 +102,7 @@ int main (int argc, const char* argv[]) memset(tempvein, -1, sizeof(tempvein)); veins.clear(); - DF.ReadVeins(x,y,z,veins); + DF.ReadVeins(x,y,z,veins,iceveins); if(showbaselayers) {