diff --git a/examples/veinlook.cpp b/examples/veinlook.cpp index 7084f1092..3d13f4d36 100644 --- a/examples/veinlook.cpp +++ b/examples/veinlook.cpp @@ -13,6 +13,7 @@ using namespace std; #include #include using namespace DFHack; +#include #include #include #include @@ -200,9 +201,9 @@ void hexdump (DFHack::API& DF, uint32_t address, uint32_t length, int filenum) char *buf = new char[reallength]; ofstream myfile; - string name = "hexdump"; - name += filenum; - name+= ".txt"; + stringstream ss; + ss << "hexdump" << filenum << ".txt"; + string name = ss.str(); myfile.open (name.c_str()); @@ -328,14 +329,17 @@ main(int argc, char *argv[]) bool dig = false; bool dump = false; + bool digbit = false; int vein = 0; int filenum = 0; + uint32_t blockflags = 0; uint32_t blockaddr = 0; // walk the map! for (;;) { dig = false; dump = false; + digbit = false; DF.Resume(); int c = getch(); /* refresh, accept single keystroke of input */ clrscr(); @@ -372,6 +376,9 @@ main(int argc, char *argv[]) case '-': vein --; break; + case 'z': + digbit = true; + break; default: break; } @@ -425,11 +432,25 @@ main(int argc, char *argv[]) blockaddr = DF.getBlockPtr(cursorX+i,cursorY+j,cursorZ); if(dump) { - hexdump(DF,blockaddr,0x1DB8,filenum); + hexdump(DF,blockaddr,0x1E00/*0x1DB8*/,filenum); filenum++; } if(dig) DF.WriteDesignations(cursorX+i,cursorY+j,cursorZ, (uint32_t *) designations); + DF.ReadBlockFlags(cursorX+i,cursorY+j,cursorZ,blockflags); + if(digbit) + { + // toggle dig bit + if(blockflags & 1) + { + blockflags &= 0xFFFFFFFE; + } + else + { + blockflags |= 1; // set first bit + } + DF.WriteBlockFlags(cursorX+i,cursorY+j,cursorZ,blockflags); + } veinVector.clear(); DF.ReadVeins(cursorX+i,cursorY+j,cursorZ,veinVector); } @@ -494,7 +515,7 @@ main(int argc, char *argv[]) } } gotoxy (0,53); - cprintf("block address 0x%x",blockaddr); + cprintf("block address 0x%x, block flags 0x%x",blockaddr,blockflags); wrefresh(stdscr); } pDF = 0; diff --git a/library/DFHackAPI.cpp b/library/DFHackAPI.cpp index 1739b20e1..afcad6534 100644 --- a/library/DFHackAPI.cpp +++ b/library/DFHackAPI.cpp @@ -41,6 +41,7 @@ public: uint32_t tile_type_offset; uint32_t designation_offset; uint32_t occupancy_offset; + uint32_t block_flags_offset; uint32_t biome_stuffs; uint32_t veinvector; uint32_t veinsize; @@ -158,6 +159,7 @@ bool API::InitMap() d->tile_type_offset = d->offset_descriptor->getOffset ("type"); d->designation_offset = d->offset_descriptor->getOffset ("designation"); d->occupancy_offset = d->offset_descriptor->getOffset ("occupancy"); + d->block_flags_offset = d->offset_descriptor->getOffset ("block_flags"); d->biome_stuffs = d->offset_descriptor->getOffset ("biome_stuffs"); d->veinvector = d->offset_descriptor->getOffset ("v_vein"); @@ -245,6 +247,27 @@ bool API::ReadTileTypes (uint32_t x, uint32_t y, uint32_t z, uint16_t *buffer) return false; } +bool API::ReadBlockFlags(uint32_t x, uint32_t y, uint32_t z, uint32_t &flags) +{ + uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; + if (addr) + { + g_pProcess->read (addr + d->block_flags_offset, sizeof (uint32_t), (uint8_t *) &flags); + return true; + } + return false; +} +bool API::WriteBlockFlags(uint32_t x, uint32_t y, uint32_t z, uint32_t flags) +{ + uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; + if (addr) + { + g_pProcess->write (addr + d->block_flags_offset, sizeof (uint32_t), (uint8_t *) &flags); + return true; + } + return false; +} + // 256 * sizeof(uint32_t) bool API::ReadDesignations (uint32_t x, uint32_t y, uint32_t z, uint32_t *buffer) diff --git a/library/DFHackAPI.h b/library/DFHackAPI.h index f41647261..63af7059d 100644 --- a/library/DFHackAPI.h +++ b/library/DFHackAPI.h @@ -142,6 +142,9 @@ namespace DFHack bool ReadOccupancy(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer); // 256 * sizeof(uint32_t) bool WriteOccupancy(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer); // 256 * sizeof(uint32_t) + bool ReadBlockFlags(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t &flags); + bool WriteBlockFlags(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t flags); + /// read region offsets of a block bool ReadRegionOffsets(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint8_t *buffer); // 16 * sizeof(uint8_t) diff --git a/output/Memory.xml b/output/Memory.xml index 91c4d9e71..6b864cbc6 100644 --- a/output/Memory.xml +++ b/output/Memory.xml @@ -562,6 +562,7 @@ 0x0264 0x0664 0x1D64 + 0x1D78 0x00 @@ -765,8 +766,9 @@ 0x2C 0x0082 0x0284 - 0x0684 + 0x0684 0x1D84 + 0x1DF8
0x015334F8
@@ -1501,6 +1503,7 @@ 0x0254 0x0654 0x1D54 + 0x1D68
0x093745EC