Reading of tiletypes under ice - 'ice veins'

develop
Petr Mrázek 2010-02-21 05:51:29 +01:00
parent 54c05279b1
commit 9268a79a66
6 changed files with 83 additions and 50 deletions

@ -280,6 +280,7 @@ main(int argc, char *argv[])
vector<DFHack::t_matgloss> stonetypes;
vector< vector <uint16_t> > layerassign;
vector<t_vein> veinVector;
vector<t_frozenliquidvein> 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("%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))
cprintf("Mineral: %s",stonetypes[veinVector[vein].type].name);
}
else
{
realvein = vein - mineralsize;
t_frozenliquidvein &frozen = IceVeinVector[realvein];
for(uint32_t i = 0;i<16;i++)
{
for (uint32_t j = 0; j< 16;j++)
{
cprintf("mxml: %s",classes[classID].c_str());
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;

@ -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;
@ -164,6 +166,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);
//FIXME: very inadequate
@ -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 <t_vein> & veins)
// veins of a block, expects empty vein vectors
bool API::ReadVeins(uint32_t x, uint32_t y, uint32_t z, vector <t_vein> & veins, vector <t_frozenliquidvein>& 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,15 +390,27 @@ bool API::ReadVeins (uint32_t x, uint32_t y, uint32_t z, vector <t_vein> & 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];
uint32_t type = g_pProcess->readDWord(temp);
if(type == d->vein_mineral_vptr)
{
// read the vein data (dereference pointer)
g_pProcess->read (temp, d->veinsize, (uint8_t *) &v);
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;
}
return false;

@ -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 <t_vein> & veins);
bool ReadVeins(uint32_t blockx, uint32_t blocky, uint32_t blockz, vector <t_vein> & veins, vector <t_frozenliquidvein>& ices);
/**
* Buildings, constructions, plants, all pretty straighforward. InitReadBuildings returns all the building types as a mapping between a numeric values and strings

@ -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<string> & v_ClassID2ObjName)
{

@ -118,6 +118,7 @@ namespace DFHack
// ALERT: uses memory reading directly
bool resolveClassId(const uint32_t address, int32_t & classid);
void getClassIDMapping(vector<string> & v_ClassID2ObjName);
uint32_t getClassVPtr(string classname);
void flush();

@ -85,6 +85,7 @@ int main (int argc, const char* argv[])
int16_t tempvein [16][16];
vector <DFHack::t_vein> veins;
vector <DFHack::t_frozenliquidvein> 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)
{