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<DFHack::t_matgloss> stonetypes;
vector< vector <uint16_t> > layerassign; vector< vector <uint16_t> > layerassign;
vector<t_vein> veinVector; vector<t_vein> veinVector;
vector<t_frozenliquidvein> IceVeinVector;
// init the API // init the API
DFHack::API DF("Memory.xml"); DFHack::API DF("Memory.xml");
@ -449,7 +450,8 @@ main(int argc, char *argv[])
DF.WriteDirtyBit(cursorX+i,cursorY+j,cursorZ,dirtybit); DF.WriteDirtyBit(cursorX+i,cursorY+j,cursorZ,dirtybit);
} }
veinVector.clear(); 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); gotoxy(0,49);
cprintf("+,- = switch vein"); cprintf("+,- = switch vein");
gotoxy(0,50); 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; 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()); 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()) if(!veinVector.empty() || !IceVeinVector.empty())
{ {
if(vein != -1 && vein < veinVector.size()) if(vein != -1 && vein < totalVeinSize)
{ {
//string str = getGCCClassName(p, veinVector[vein].vtable); uint32_t realvein = 0;
string className = p->readClassName(veinVector[vein].vtable); if(vein < mineralsize)
//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")
{ {
realvein = vein;
//iterate through vein rows //iterate through vein rows
for(uint32_t j = 0;j<16;j++) 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++) for (uint32_t k = 0; k< 16;k++)
{ {
// and the bit array with a one-bit mask, check if the bit is set // 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) if(set)
{ {
putch(k+16,j+16,'$',COLOR_RED); putch(k+16,j+16,'$',COLOR_RED);
} }
} }
} }
gotoxy(0,53); gotoxy(0,51);
cprintf("%s",stonetypes[veinVector[vein].type].name); cprintf("Mineral: %s",stonetypes[veinVector[vein].type].name);
} }
gotoxy(0,51); else
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("mxml: %s",classes[classID].c_str()); realvein = vein - mineralsize;
t_frozenliquidvein &frozen = IceVeinVector[realvein];
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);
}
}
gotoxy(0,51);
cprintf("ICE");
} }
} }
} }
uint32_t sptr = blockaddr + p->getDescriptor()->getOffset("block_flags"); uint32_t sptr = blockaddr + p->getDescriptor()->getOffset("block_flags");
gotoxy (0,54); gotoxy (0,52);
cprintf("block address 0x%x",blockaddr); cprintf("block address 0x%x",blockaddr);
gotoxy (0,55); gotoxy (0,53);
cprintf("dirty bit: %d",dirtybit); cprintf("dirty bit: %d",dirtybit);
gotoxy (0,54);
cprintf ("d - dig veins, o - dump map block, z - toggle dirty bit");
wrefresh(stdscr); wrefresh(stdscr);
} }
pDF = 0; pDF = 0;

@ -45,6 +45,8 @@ public:
uint32_t biome_stuffs; uint32_t biome_stuffs;
uint32_t veinvector; uint32_t veinvector;
uint32_t veinsize; uint32_t veinsize;
uint32_t vein_mineral_vptr;
uint32_t vein_ice_vptr;
uint32_t window_x_offset; uint32_t window_x_offset;
uint32_t window_y_offset; uint32_t window_y_offset;
@ -163,6 +165,9 @@ bool API::InitMap()
d->veinvector = d->offset_descriptor->getOffset ("v_vein"); d->veinvector = d->offset_descriptor->getOffset ("v_vein");
d->veinsize = d->offset_descriptor->getHexValue ("v_vein_size"); 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 // get the map pointer
uint32_t x_array_loc = g_pProcess->readDWord (map_offset); uint32_t x_array_loc = g_pProcess->readDWord (map_offset);
@ -367,13 +372,12 @@ bool API::ReadRegionOffsets (uint32_t x, uint32_t y, uint32_t z, uint8_t *buffer
return false; return false;
} }
// veins of a block, expects empty vein vectors
// veins of a block, expects empty vein vector bool API::ReadVeins(uint32_t x, uint32_t y, uint32_t z, vector <t_vein> & veins, vector <t_frozenliquidvein>& ices)
bool API::ReadVeins (uint32_t x, uint32_t y, uint32_t z, vector <t_vein> & veins)
{ {
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; 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(); veins.clear();
ices.clear();
if (addr && d->veinvector && d->veinsize) if (addr && d->veinvector && d->veinsize)
{ {
// veins are stored as a vector of pointers to veins // veins are stored as a vector of pointers to veins
@ -386,14 +390,26 @@ bool API::ReadVeins (uint32_t x, uint32_t y, uint32_t z, vector <t_vein> & veins
for (uint32_t i = 0; i < size;i++) for (uint32_t i = 0; i < size;i++)
{ {
t_vein v; t_vein v;
t_frozenliquidvein fv;
// read the vein pointer from the vector // read the vein pointer from the vector
uint32_t temp = * (uint32_t *) p_veins[i]; uint32_t temp = * (uint32_t *) p_veins[i];
// read the vein data (dereference pointer) uint32_t type = g_pProcess->readDWord(temp);
g_pProcess->read (temp, d->veinsize, (uint8_t *) &v); if(type == d->vein_mineral_vptr)
v.address_of = temp; {
// store it in the vector // read the vein data (dereference pointer)
veins.push_back (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 true;
} }

@ -149,7 +149,7 @@ namespace DFHack
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)
/// read aggregated veins of a block /// 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 * 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; 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 // Flatten vtables into a index<->name mapping
void memory_info::getClassIDMapping(vector<string> & v_ClassID2ObjName) void memory_info::getClassIDMapping(vector<string> & v_ClassID2ObjName)
{ {

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

@ -85,6 +85,7 @@ int main (int argc, const char* argv[])
int16_t tempvein [16][16]; int16_t tempvein [16][16];
vector <DFHack::t_vein> veins; vector <DFHack::t_vein> veins;
vector <DFHack::t_frozenliquidvein> iceveins;
// walk the map! // walk the map!
for(uint32_t x = 0; x< x_max;x++) 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)); memset(tempvein, -1, sizeof(tempvein));
veins.clear(); veins.clear();
DF.ReadVeins(x,y,z,veins); DF.ReadVeins(x,y,z,veins,iceveins);
if(showbaselayers) if(showbaselayers)
{ {