Removed bogus block flags, added actual dirty bit :)

develop
Petr Mrázek 2010-02-20 16:33:30 +01:00
parent 26568fe5ea
commit 3c7c197f7a
4 changed files with 25 additions and 25 deletions

@ -12,6 +12,7 @@ using namespace std;
#include <DFTileTypes.h>
#include <DFHackAPI.h>
#include <DFProcess.h>
#include <DFMemInfo.h>
using namespace DFHack;
#include <sstream>
#include <curses.h>
@ -298,6 +299,7 @@ main(int argc, char *argv[])
error = "Can't find a map to look at.";
pDF = 0;
finish(0);
#include <DFMemInfo.h>
}
DF.getSize(x_max_a,y_max_a,z_max_a);
@ -332,7 +334,7 @@ main(int argc, char *argv[])
bool digbit = false;
int vein = 0;
int filenum = 0;
uint32_t blockflags = 0;
bool dirtybit = false;
uint32_t blockaddr = 0;
// walk the map!
for (;;)
@ -437,19 +439,11 @@ main(int argc, char *argv[])
}
if(dig)
DF.WriteDesignations(cursorX+i,cursorY+j,cursorZ, (uint32_t *) designations);
DF.ReadBlockFlags(cursorX+i,cursorY+j,cursorZ,blockflags);
DF.ReadDirtyBit(cursorX+i,cursorY+j,cursorZ,dirtybit);
if(digbit)
{
// toggle dig bit
if(blockflags & 1)
{
blockflags &= 0xFFFFFFFE;
}
else
{
blockflags |= 1; // set first bit
}
DF.WriteBlockFlags(cursorX+i,cursorY+j,cursorZ,blockflags);
dirtybit = !dirtybit;
DF.WriteDirtyBit(cursorX+i,cursorY+j,cursorZ,dirtybit);
}
veinVector.clear();
DF.ReadVeins(cursorX+i,cursorY+j,cursorZ,veinVector);
@ -514,8 +508,12 @@ main(int argc, char *argv[])
cprintf("%s, address 0x%x",className.c_str(),veinVector[vein].address_of);
}
}
uint32_t sptr = blockaddr + p->getDescriptor()->getOffset("block_flags");
gotoxy (0,53);
cprintf("block address 0x%x, block flags 0x%x",blockaddr,blockflags);
cprintf("block address 0x%x",blockaddr);
gotoxy (0,54);
cprintf("dirty bit: %d",dirtybit);
wrefresh(stdscr);
}
pDF = 0;

@ -159,7 +159,6 @@ 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");
@ -247,22 +246,28 @@ 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)
bool API::ReadDirtyBit(uint32_t x, uint32_t y, uint32_t z, bool &dirtybit)
{
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
if (addr)
if(addr)
{
g_pProcess->read (addr + d->block_flags_offset, sizeof (uint32_t), (uint8_t *) &flags);
uint32_t addr_of_struct = g_pProcess->readDWord(addr);
dirtybit = g_pProcess->readDWord(addr_of_struct) & 1;
return true;
}
return false;
}
bool API::WriteBlockFlags(uint32_t x, uint32_t y, uint32_t z, uint32_t flags)
bool API::WriteDirtyBit(uint32_t x, uint32_t y, uint32_t z, bool dirtybit)
{
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);
uint32_t addr_of_struct = g_pProcess->readDWord(addr);
uint32_t dirtydword = g_pProcess->readDWord(addr_of_struct);
dirtydword &= 0xFFFFFFF0;
dirtydword |= dirtybit;
g_pProcess->writeDWord (addr_of_struct, dirtydword);
return true;
}
return false;

@ -141,9 +141,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);
bool ReadDirtyBit(uint32_t blockx, uint32_t blocky, uint32_t blockz, bool &dirtybit);
bool WriteDirtyBit(uint32_t blockx, uint32_t blocky, uint32_t blockz, bool dirtybit);
/// 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,7 +562,6 @@
<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>
@ -768,7 +767,6 @@
<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>
@ -1503,7 +1501,6 @@
<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>