develop
mizipzor 2010-02-21 00:35:31 +01:00
commit f156dcdc17
4 changed files with 55 additions and 5 deletions

@ -12,7 +12,9 @@ using namespace std;
#include <DFTileTypes.h> #include <DFTileTypes.h>
#include <DFHackAPI.h> #include <DFHackAPI.h>
#include <DFProcess.h> #include <DFProcess.h>
#include <DFMemInfo.h>
using namespace DFHack; using namespace DFHack;
#include <sstream>
#include <curses.h> #include <curses.h>
#include <stdlib.h> #include <stdlib.h>
#include <signal.h> #include <signal.h>
@ -200,9 +202,9 @@ void hexdump (DFHack::API& DF, uint32_t address, uint32_t length, int filenum)
char *buf = new char[reallength]; char *buf = new char[reallength];
ofstream myfile; ofstream myfile;
string name = "hexdump"; stringstream ss;
name += filenum; ss << "hexdump" << filenum << ".txt";
name+= ".txt"; string name = ss.str();
myfile.open (name.c_str()); myfile.open (name.c_str());
@ -297,6 +299,7 @@ main(int argc, char *argv[])
error = "Can't find a map to look at."; error = "Can't find a map to look at.";
pDF = 0; pDF = 0;
finish(0); finish(0);
#include <DFMemInfo.h>
} }
DF.getSize(x_max_a,y_max_a,z_max_a); DF.getSize(x_max_a,y_max_a,z_max_a);
@ -328,14 +331,17 @@ main(int argc, char *argv[])
bool dig = false; bool dig = false;
bool dump = false; bool dump = false;
bool digbit = false;
int vein = 0; int vein = 0;
int filenum = 0; int filenum = 0;
bool dirtybit = false;
uint32_t blockaddr = 0; uint32_t blockaddr = 0;
// walk the map! // walk the map!
for (;;) for (;;)
{ {
dig = false; dig = false;
dump = false; dump = false;
digbit = false;
DF.Resume(); DF.Resume();
int c = getch(); /* refresh, accept single keystroke of input */ int c = getch(); /* refresh, accept single keystroke of input */
clrscr(); clrscr();
@ -372,6 +378,9 @@ main(int argc, char *argv[])
case '-': case '-':
vein --; vein --;
break; break;
case 'z':
digbit = true;
break;
default: default:
break; break;
} }
@ -425,11 +434,17 @@ main(int argc, char *argv[])
blockaddr = DF.getBlockPtr(cursorX+i,cursorY+j,cursorZ); blockaddr = DF.getBlockPtr(cursorX+i,cursorY+j,cursorZ);
if(dump) if(dump)
{ {
hexdump(DF,blockaddr,0x1DB8,filenum); hexdump(DF,blockaddr,0x1E00/*0x1DB8*/,filenum);
filenum++; filenum++;
} }
if(dig) if(dig)
DF.WriteDesignations(cursorX+i,cursorY+j,cursorZ, (uint32_t *) designations); DF.WriteDesignations(cursorX+i,cursorY+j,cursorZ, (uint32_t *) designations);
DF.ReadDirtyBit(cursorX+i,cursorY+j,cursorZ,dirtybit);
if(digbit)
{
dirtybit = !dirtybit;
DF.WriteDirtyBit(cursorX+i,cursorY+j,cursorZ,dirtybit);
}
veinVector.clear(); veinVector.clear();
DF.ReadVeins(cursorX+i,cursorY+j,cursorZ,veinVector); DF.ReadVeins(cursorX+i,cursorY+j,cursorZ,veinVector);
} }
@ -493,8 +508,12 @@ main(int argc, char *argv[])
cprintf("%s, address 0x%x",className.c_str(),veinVector[vein].address_of); cprintf("%s, address 0x%x",className.c_str(),veinVector[vein].address_of);
} }
} }
uint32_t sptr = blockaddr + p->getDescriptor()->getOffset("block_flags");
gotoxy (0,53); gotoxy (0,53);
cprintf("block address 0x%x",blockaddr); cprintf("block address 0x%x",blockaddr);
gotoxy (0,54);
cprintf("dirty bit: %d",dirtybit);
wrefresh(stdscr); wrefresh(stdscr);
} }
pDF = 0; pDF = 0;

@ -41,6 +41,7 @@ public:
uint32_t tile_type_offset; uint32_t tile_type_offset;
uint32_t designation_offset; uint32_t designation_offset;
uint32_t occupancy_offset; uint32_t occupancy_offset;
uint32_t block_flags_offset;
uint32_t biome_stuffs; uint32_t biome_stuffs;
uint32_t veinvector; uint32_t veinvector;
uint32_t veinsize; uint32_t veinsize;
@ -245,6 +246,33 @@ bool API::ReadTileTypes (uint32_t x, uint32_t y, uint32_t z, uint16_t *buffer)
return false; return false;
} }
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)
{
uint32_t addr_of_struct = g_pProcess->readDWord(addr);
dirtybit = g_pProcess->readDWord(addr_of_struct) & 1;
return true;
}
return false;
}
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)
{
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;
}
// 256 * sizeof(uint32_t) // 256 * sizeof(uint32_t)
bool API::ReadDesignations (uint32_t x, uint32_t y, uint32_t z, uint32_t *buffer) 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 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 WriteOccupancy(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer); // 256 * sizeof(uint32_t)
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 /// read region offsets of a block
bool ReadRegionOffsets(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint8_t *buffer); // 16 * sizeof(uint8_t) bool ReadRegionOffsets(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint8_t *buffer); // 16 * sizeof(uint8_t)