Added 'dirty' bit of a block to veinlook, API.

develop
Petr Mrázek 2010-02-20 12:58:52 +01:00
parent 88cb312a65
commit 26568fe5ea
4 changed files with 56 additions and 6 deletions

@ -13,6 +13,7 @@ using namespace std;
#include <DFHackAPI.h>
#include <DFProcess.h>
using namespace DFHack;
#include <sstream>
#include <curses.h>
#include <stdlib.h>
#include <signal.h>
@ -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;

@ -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)

@ -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)

@ -562,6 +562,7 @@
<Offset name="designation">0x0264</Offset>
<Offset name="occupancy">0x0664</Offset>
<Offset name="biome_stuffs">0x1D64</Offset>
<Offset name="block_flags">0x1D78</Offset>
<!-- creature offsets -->
<Offset name="creature_first_name">0x00</Offset>
@ -767,6 +768,7 @@
<Offset name="designation">0x0284</Offset>
<Offset name="occupancy">0x0684</Offset>
<Offset name="biome_stuffs">0x1D84</Offset>
<Offset name="block_flags">0x1DF8</Offset>
<!-- the world and its offsets -->
<Address name="world">0x015334F8</Address>
@ -1501,6 +1503,7 @@
<Offset name="designation">0x0254</Offset>
<Offset name="occupancy">0x0654</Offset>
<Offset name="biome_stuffs">0x1D54</Offset>
<Offset name="block_flags">0x1D68</Offset>
<!-- the world and its offsets -->
<Address name="world">0x093745EC</Address>