Accelerated creatures work on Windows

Refactored vector reading, proper length of vectors from MSVC9 is known (0x18, triplet starts at 0xC)
develop
Petr Mrázek 2010-03-30 02:26:52 +02:00
parent 85d347442d
commit 71fc49897f
16 changed files with 68 additions and 144 deletions

@ -151,8 +151,6 @@ likeType printLike(DFHack::t_like like, const matGlosses & mat,const vector< vec
void printCreature(DFHack::API & DF, const DFHack::t_creature & creature)
{
if(string(creaturestypes[creature.type].id) == "DWARF")
{
cout << "address: " << hex << creature.origin << dec << " creature type: " << creaturestypes[creature.type].id << ", position: " << creature.x << "x " << creature.y << "y "<< creature.z << "z" << endl;
bool addendl = false;
if(creature.name.first_name[0])
@ -294,7 +292,6 @@ void printCreature(DFHack::API & DF, const DFHack::t_creature & creature)
string artifact_name = DF.TranslateName(creature.artifact_name,englishWords,foreignWords,false);
cout << "artifact: " << artifact_name << endl;
}
}
cout << endl;
}
@ -358,8 +355,11 @@ int main (void)
{
DFHack::t_creature temp;
DF.ReadCreature(i,temp);
cout << "index " << i << " ";
printCreature(DF,temp);
if(string(creaturestypes[temp.type].id) == "DWARF")
{
cout << "index " << i << " ";
printCreature(DF,temp);
}
}
uint32_t currentIdx;
DFHack::t_creature currentCreature;

@ -499,7 +499,7 @@ bool API::ReadVeins(uint32_t x, uint32_t y, uint32_t z, vector <t_vein> & veins,
{
// veins are stored as a vector of pointers to veins
/*pointer is 4 bytes! we work with a 32bit program here, no matter what architecture we compile khazad for*/
DfVector p_veins = d->p->readVector (addr + d->veinvector, 4);
DfVector p_veins (d->p, addr + d->veinvector, 4);
uint32_t size = p_veins.getSize();
veins.reserve (size);
@ -559,7 +559,7 @@ bool API::ReadWoodMatgloss (vector<t_matgloss> & woods)
int matgloss_address = d->offset_descriptor->getAddress ("matgloss");
int matgloss_wood_name_offset = d->offset_descriptor->getOffset("matgloss_wood_name");
// TODO: find flag for autumnal coloring?
DfVector p_matgloss = d->p->readVector (matgloss_address, 4);
DfVector p_matgloss(d->p, matgloss_address, 4);
woods.clear();
@ -592,7 +592,7 @@ bool API::ReadStoneMatgloss (vector<t_matgloss> & stones)
int matgloss_colors = minfo->getOffset ("matgloss_stone_color");
int matgloss_stone_name_offset = minfo->getOffset("matgloss_stone_name");
DfVector p_matgloss = d->p->readVector (matgloss_address + matgloss_offset, 4);
DfVector p_matgloss (d->p, matgloss_address + matgloss_offset, 4);
uint32_t size = p_matgloss.getSize();
stones.resize (0);
@ -622,7 +622,7 @@ bool API::ReadMetalMatgloss (vector<t_matgloss> & metals)
int matgloss_offset = minfo->getHexValue ("matgloss_skip");
int matgloss_colors = minfo->getOffset ("matgloss_metal_color");
int matgloss_metal_name_offset = minfo->getOffset("matgloss_metal_name");
DfVector p_matgloss = d->p->readVector (matgloss_address + matgloss_offset * 3, 4);
DfVector p_matgloss(d->p, matgloss_address + matgloss_offset * 3, 4);
metals.clear();
@ -649,7 +649,7 @@ bool API::ReadPlantMatgloss (vector<t_matgloss> & plants)
int matgloss_address = minfo->getAddress ("matgloss");
int matgloss_offset = minfo->getHexValue ("matgloss_skip");
int matgloss_plant_name_offset = minfo->getOffset("matgloss_plant_name");
DfVector p_matgloss = d->p->readVector (matgloss_address + matgloss_offset * 2, 4);
DfVector p_matgloss(d->p, matgloss_address + matgloss_offset * 2, 4);
plants.clear();
@ -680,7 +680,7 @@ bool API::ReadPlantMatgloss (vector<t_matglossPlant> & plants)
int matgloss_plant_drink_offset = minfo->getOffset("matgloss_plant_drink");
int matgloss_plant_food_offset = minfo->getOffset("matgloss_plant_food");
int matgloss_plant_extract_offset = minfo->getOffset("matgloss_plant_extract");
DfVector p_matgloss = d->p->readVector (matgloss_address + matgloss_offset * 2, 4);
DfVector p_matgloss(d->p, matgloss_address + matgloss_offset * 2, 4);
plants.clear();
@ -713,7 +713,7 @@ bool API::ReadCreatureMatgloss (vector<t_matgloss> & creatures)
int matgloss_address = minfo->getAddress ("matgloss");
int matgloss_offset = minfo->getHexValue ("matgloss_skip");
int matgloss_creature_name_offset = minfo->getOffset("matgloss_creature_name");
DfVector p_matgloss = d->p->readVector (matgloss_address + matgloss_offset * 6, 4);
DfVector p_matgloss (d->p, matgloss_address + matgloss_offset * 6, 4);
creatures.clear();
@ -769,7 +769,7 @@ bool API::ReadGeology (vector < vector <uint16_t> >& assign)
uint32_t regions = g_pProcess->readDWord (world_offset + world_regions_offset);
// read the geoblock vector
DfVector geoblocks = d->p->readVector (world_offset + world_geoblocks_offset, 4);
DfVector geoblocks (d->p, world_offset + world_geoblocks_offset, 4);
// iterate over 8 surrounding regions + local region
for (int i = eNorthWest; i < eBiomeCount; i++)
@ -795,7 +795,7 @@ bool API::ReadGeology (vector < vector <uint16_t> >& assign)
uint32_t geoblock_off = * (uint32_t *) geoblocks[geoindex];
// get the vector with pointer to layers
DfVector geolayers = d->p->readVector (geoblock_off + geolayer_geoblock_offset , 4); // let's hope
DfVector geolayers (d->p, geoblock_off + geolayer_geoblock_offset , 4); // let's hope
// make sure we don't load crap
assert (geolayers.getSize() > 0 && geolayers.getSize() <= 16);
@ -833,7 +833,7 @@ bool API::InitReadBuildings ( uint32_t& numbuildings )
return false;
}
d->buildingsInited = true;
d->p_bld = new DfVector (d->p->readVector (buildings, 4));
d->p_bld = new DfVector (d->p,buildings, 4);
numbuildings = d->p_bld->getSize();
return true;
}
@ -894,7 +894,7 @@ bool API::InitReadEffects ( uint32_t & numeffects )
return false;
}
d->effectsInited = true;
d->p_effect = new DfVector (d->p->readVector (effects, 4));
d->p_effect = new DfVector (d->p, effects, 4);
numeffects = d->p_effect->getSize();
return true;
}
@ -951,7 +951,7 @@ bool API::InitReadConstructions(uint32_t & numconstructions)
{
return false;
}
d->p_cons = new DfVector (d->p->readVector (constructions, 4));
d->p_cons = new DfVector (d->p,constructions, 4);
d->constructionsInited = true;
numconstructions = d->p_cons->getSize();
return true;
@ -998,7 +998,7 @@ bool API::InitReadVegetation(uint32_t & numplants)
d->tree_offset = d->offset_descriptor->getOffset ("tree_desc_offset");
d->vegetationInited = true;
d->p_veg = new DfVector (d->p->readVector (vegetation, 4));
d->p_veg = new DfVector (d->p, vegetation, 4);
numplants = d->p_veg->getSize();
return true;
}
@ -1079,7 +1079,10 @@ bool API::InitReadCreatures( uint32_t &numcreatures )
off.name_nickname_offset = minfo->getOffset("name_nickname");
off.name_words_offset = minfo->getOffset("name_words");
d->p_cre = new DfVector (d->p->readVector (off.creature_vector, 4));
// HACK: vector correction
off.vector_correct = minfo->getOffset("hacked_vector_start");
d->p_cre = new DfVector (d->p, off.creature_vector, 4);
d->creaturesInited = true;
numcreatures = d->p_cre->getSize();
@ -1122,7 +1125,7 @@ bool API::InitReadNotes( uint32_t &numnotes )
d->note_name_offset = minfo->getOffset ("note_name");
d->note_xyz_offset = minfo->getOffset ("note_xyz");
d->p_notes = new DfVector (d->p->readVector (notes, 4));
d->p_notes = new DfVector (d->p, notes, 4);
d->notesInited = true;
numnotes = d->p_notes->getSize();
return true;
@ -1159,8 +1162,8 @@ bool API::InitReadSettlements( uint32_t & numsettlements )
d->settlement_world_xy_offset = minfo->getOffset ("settlement_world_xy");
d->settlement_local_xy_offset = minfo->getOffset ("settlement_local_xy");
d->p_settlements = new DfVector (d->p->readVector (allSettlements, 4));
d->p_current_settlement = new DfVector(d->p->readVector(currentSettlement,4));
d->p_settlements = new DfVector (d->p, allSettlements, 4);
d->p_current_settlement = new DfVector(d->p, currentSettlement,4);
d->settlementsInited = true;
numsettlements = d->p_settlements->getSize();
return true;
@ -1360,7 +1363,7 @@ bool API::ReadCreature (const int32_t index, t_creature & furball)
// traits
g_pProcess->read (temp + offs.creature_traits_offset, sizeof (uint16_t) * NUM_CREATURE_TRAITS, (uint8_t *) &furball.traits);
// learned skills
DfVector skills (d->p->readVector (temp + offs.creature_skills_offset, 4));
DfVector skills (d->p, temp + offs.creature_skills_offset, 4 );
furball.numSkills = skills.getSize();
for (uint32_t i = 0; i < furball.numSkills;i++)
{
@ -1387,7 +1390,7 @@ bool API::ReadCreature (const int32_t index, t_creature & furball)
}
//likes
DfVector likes(d->p->readVector(temp + offs.creature_likes_offset,4));
DfVector likes(d->p, temp + offs.creature_likes_offset, 4);
furball.numLikes = likes.getSize();
for(uint32_t i = 0;i<furball.numLikes;i++)
{
@ -1432,8 +1435,8 @@ bool API::InitReadNameTables(vector<vector<string> > & translations , vector<vec
int word_table_offset = d->offset_descriptor->getOffset ("word_table");
int sizeof_string = d->offset_descriptor->getHexValue ("sizeof_string");
DfVector genericVec (d->p->readVector (genericAddress, 4));
DfVector transVec (d->p->readVector (transAddress, 4));
DfVector genericVec (d->p, genericAddress, 4);
DfVector transVec (d->p, transAddress, 4);
translations.resize(10);
for (uint32_t i = 0;i < genericVec.getSize();i++)
@ -1451,7 +1454,7 @@ bool API::InitReadNameTables(vector<vector<string> > & translations , vector<vec
{
uint32_t transPtr = * (uint32_t *) transVec.at (i);
//string transName = d->p->readSTLString (transPtr);
DfVector trans_names_vec (d->p->readVector (transPtr + word_table_offset, 4));
DfVector trans_names_vec (d->p, transPtr + word_table_offset, 4);
for (uint32_t j = 0;j < trans_names_vec.getSize();j++)
{
uint32_t transNamePtr = * (uint32_t *) trans_names_vec.at (j);
@ -1774,7 +1777,7 @@ bool API::InitReadItems(uint32_t & numitems)
int items = d->offset_descriptor->getAddress ("items");
d->item_material_offset = d->offset_descriptor->getOffset ("item_materials");
d->p_itm = new DfVector (d->p->readVector (items, 4));
d->p_itm = new DfVector (d->p, items, 4);
d->itemsInited = true;
numitems = d->p_itm->getSize();
return true;
@ -1868,7 +1871,7 @@ bool API::ReadItemTypes(vector< vector< t_itemType > > & itemTypes)
int item_type_name_offset = minfo->getOffset("item_type_name");
for(int i = 8;i<20;i++)
{
DfVector p_temp = d->p->readVector(matgloss_address + i*matgloss_skip,4);
DfVector p_temp (d->p, matgloss_address + i*matgloss_skip,4);
vector< t_itemType > typesForVec;
for(uint32_t j =0; j<p_temp.getSize();j++)
{

@ -51,7 +51,7 @@ class memory_info::Private
{
public:
map <string, uint32_t> addresses;
map <string, uint32_t> offsets;
map <string, int32_t> offsets;
map <string, uint32_t> hexvals;
map <string, string> strings;
@ -201,7 +201,7 @@ void memory_info::setBase (const uint32_t b)
void memory_info::setOffset (const string & key, const string & value)
{
uint32_t offset = strtol(value.c_str(), NULL, 16);
int32_t offset = strtol(value.c_str(), NULL, 16);
d->offsets[key] = offset;
}
@ -475,9 +475,9 @@ uint32_t memory_info::getAddress (const char *key)
// Get named offset
uint32_t memory_info::getOffset (const char *key)
int32_t memory_info::getOffset (const char *key)
{
map <string, uint32_t>::iterator iter = d->offsets.find(key);
map <string, int32_t>::iterator iter = d->offsets.find(key);
if(iter != d->offsets.end())
{
return (*iter).second;
@ -511,9 +511,9 @@ uint32_t memory_info::getAddress (const string &key)
// Get named offset
uint32_t memory_info::getOffset (const string &key)
int32_t memory_info::getOffset (const string &key)
{
map <string, uint32_t>::iterator iter = d->offsets.find(key);
map <string, int32_t>::iterator iter = d->offsets.find(key);
if(iter != d->offsets.end())
{
return (*iter).second;

@ -103,10 +103,10 @@ namespace DFHack
void setBase (const string&);
void setBase (const uint32_t);
uint32_t getOffset (const string&);
int32_t getOffset (const string&);
uint32_t getAddress (const string&);
uint32_t getHexValue (const string&);
uint32_t getOffset (const char *);
int32_t getOffset (const char *);
uint32_t getAddress (const char *);
uint32_t getHexValue (const char *);

@ -789,24 +789,6 @@ const std::string SHMProcess::readCString (uint32_t offset)
return temp;
}
DfVector SHMProcess::readVector (uint32_t offset, uint32_t item_size)
{
if(!d->locked) throw Error::SHMAccessDenied();
/*
GNU libstdc++ vector is three pointers long
ptr start
ptr end
ptr alloc_end
we don't care about alloc_end because we don't try to add stuff
*/
uint32_t start = g_pProcess->readDWord(offset);
uint32_t end = g_pProcess->readDWord(offset+4);
uint32_t size = (end - start) /4;
return DfVector(start,size,item_size);
}
const std::string SHMProcess::readSTLString(uint32_t offset)
{
if(!d->locked) throw Error::SHMAccessDenied();

@ -498,24 +498,6 @@ const std::string WineProcess::readCString (uint32_t offset)
return temp;
}
DfVector WineProcess::readVector (uint32_t offset, uint32_t item_size)
{
/*
MSVC++ vector is four pointers long
ptr allocator
ptr start
ptr end
ptr alloc_end
we don't care about alloc_end because we don't try to add stuff
we also don't care about the allocator thing in front
*/
uint32_t start = g_pProcess->readDWord(offset+4);
uint32_t end = g_pProcess->readDWord(offset+8);
uint32_t size = (end - start) /4;
return DfVector(start,size,item_size);
}
size_t WineProcess::readSTLString (uint32_t offset, char * buffer, size_t bufcapacity)
{
/*

@ -486,22 +486,6 @@ const std::string NormalProcess::readCString (uint32_t offset)
return temp;
}
DfVector NormalProcess::readVector (uint32_t offset, uint32_t item_size)
{
/*
GNU libstdc++ vector is three pointers long
ptr start
ptr end
ptr alloc_end
we don't care about alloc_end because we don't try to add stuff
*/
uint32_t start = g_pProcess->readDWord(offset);
uint32_t end = g_pProcess->readDWord(offset+4);
uint32_t size = (end - start) /4;
return DfVector(start,size,item_size);
}
struct _Rep_base
{
uint32_t _M_length;

@ -851,26 +851,6 @@ const std::string SHMProcess::readCString (uint32_t offset)
return temp;
}
DfVector SHMProcess::readVector (uint32_t offset, uint32_t item_size)
{
if(!d->locked) throw Error::SHMAccessDenied();
/*
MSVC++ vector is four pointers long
ptr allocator
ptr start
ptr end
ptr alloc_end
we don't care about alloc_end because we don't try to add stuff
we also don't care about the allocator thing in front
*/
uint32_t start = g_pProcess->readDWord(offset+4);
uint32_t end = g_pProcess->readDWord(offset+8);
uint32_t size = (end - start) /4;
return DfVector(start,size,item_size);
}
const std::string SHMProcess::readSTLString(uint32_t offset)
{
if(!d->locked) throw Error::SHMAccessDenied();

@ -385,24 +385,6 @@ const string NormalProcess::readCString (const uint32_t offset)
return temp;
}
DfVector NormalProcess::readVector (uint32_t offset, uint32_t item_size)
{
/*
MSVC++ vector is four pointers long
ptr allocator
ptr start
ptr end
ptr alloc_end
we don't care about alloc_end because we don't try to add stuff
we also don't care about the allocator thing in front
*/
uint32_t start = g_pProcess->readDWord(offset+4);
uint32_t end = g_pProcess->readDWord(offset+8);
uint32_t size = (end - start) /4;
return DfVector(start,size,item_size);
}
size_t NormalProcess::readSTLString (uint32_t offset, char * buffer, size_t bufcapacity)
{
/*

@ -98,8 +98,6 @@ namespace DFHack
virtual const string readSTLString (uint32_t offset) = 0;
virtual size_t readSTLString (uint32_t offset, char * buffer, size_t bufcapacity) = 0;
virtual void writeSTLString(const uint32_t address, const std::string writeString) = 0;
// read a vector from memory
virtual DfVector readVector (uint32_t offset, uint32_t item_size) = 0;
// get class name of an object with rtti/type info
virtual string readClassName(uint32_t vptr) = 0;
@ -168,8 +166,6 @@ namespace DFHack
const string readSTLString (uint32_t offset);
size_t readSTLString (uint32_t offset, char * buffer, size_t bufcapacity);
void writeSTLString(const uint32_t address, const std::string writeString){};
// read a vector from memory
DfVector readVector (uint32_t offset, uint32_t item_size);
// get class name of an object with rtti/type info
string readClassName(uint32_t vptr);
@ -233,8 +229,6 @@ namespace DFHack
const string readSTLString (uint32_t offset);
size_t readSTLString (uint32_t offset, char * buffer, size_t bufcapacity);
void writeSTLString(const uint32_t address, const std::string writeString);
// read a vector from memory
DfVector readVector (uint32_t offset, uint32_t item_size);
// get class name of an object with rtti/type info
string readClassName(uint32_t vptr);
@ -297,8 +291,6 @@ namespace DFHack
const string readSTLString (uint32_t offset);
size_t readSTLString (uint32_t offset, char * buffer, size_t bufcapacity);
void writeSTLString(const uint32_t address, const std::string writeString){};
// read a vector from memory
DfVector readVector (uint32_t offset, uint32_t item_size);
// get class name of an object with rtti/type info
string readClassName(uint32_t vptr);

@ -27,10 +27,20 @@ distribution.
using namespace DFHack;
DfVector::DfVector(uint32_t _start, uint32_t _size, uint32_t _item_size): start(_start),size(_size),item_size(_item_size)
DfVector::DfVector(Process * p, uint32_t address, uint32_t _item_size)
{
data = (uint8_t *) new char[size * item_size];
g_pProcess->read(start,size*item_size, (uint8_t *)data);
uint32_t triplet[3];
item_size = _item_size;
memory_info * mem = p->getDescriptor();
uint32_t offs = mem->getOffset("hacked_vector_triplet");
p->read(address + offs, sizeof(triplet), (uint8_t *) &triplet);
start = triplet[0];
uint32_t byte_size = triplet[1] - triplet[0];
size = byte_size / item_size;
data = (uint8_t *) new char[byte_size];
g_pProcess->read(start,byte_size, (uint8_t *)data);
};
DfVector::DfVector()
{

@ -30,6 +30,7 @@ distribution.
namespace DFHack
{
class Process;
class DFHACK_EXPORT DfVector
{
private:
@ -42,7 +43,7 @@ namespace DFHack
public:
DfVector();
DfVector(uint32_t _start, uint32_t _size, uint32_t _item_size);
DfVector(Process * p, uint32_t address, uint32_t item_size);
~DfVector();
// get offset of the specified index
inline void* operator[] (uint32_t index)

@ -784,6 +784,8 @@
<Entry version="v0.27.176.38a" os="windows" id="38awin" base="meta-40d">
<HexValue name="pe_timestamp">0x47b6fac2</HexValue>
<String name="md5">48c831b6f3950913b8e1aeada563d2db</String>
<Offset name="hacked_vector_start">0x0</Offset><!-- where a vector actually starts -->
<Offset name="hacked_vector_triplet">0x4</Offset><!-- where the vector triplet is -->
<Address name="buildings">0x014639f4</Address>
<Address name="constructions">0x01463288</Address>
<Address name="creatures">0x01463388</Address>
@ -1161,6 +1163,8 @@
<Entry version="v0.28.181.40d2" os="windows" id="40d2win" base="40dwin">
<HexValue name="pe_timestamp">0x4953556c</HexValue>
<String name="md5">b1a8ca1f91734eb492b7f54f6823cddb</String>
<Offset name="hacked_vector_start">-0x8</Offset><!-- where a vector actually starts -->
<Offset name="hacked_vector_triplet">0x4</Offset><!-- where the vector triplet is -->
<Address name="buildings">0x014d1db0</Address>
<Address name="constructions">0x014bda18</Address>
<Address name="creatures">0x014D141C</Address>
@ -1562,6 +1566,8 @@
<Entry version="v0.28.181.40d2" os="linux" id="40d2lin" base="meta-40d">
<String name="md5">7a0859795e972574e80fa3cebc9fcf85</String>
<Offset name="hacked_vector_start">0x0</Offset><!-- where a vector actually starts -->
<Offset name="hacked_vector_triplet">0x0</Offset><!-- where the vector triplet is -->
<Address name="buildings">0x093154e0</Address>
<Address name="constructions">0x093016b8</Address>
<Address name="creatures">0x09355940</Address>

@ -44,7 +44,7 @@ void ReadCreatureAtIndex(void *data)
{
creature_modulestate * state = (creature_modulestate *) data;
creature_offsets & offsets = state->offsets;
std::vector<char *> * creaturev = (std::vector<char *> *) offsets.creature_vector;
std::vector<char *> * creaturev = (std::vector<char *> *) (offsets.creature_vector + offsets.vector_correct);
uint32_t length = creaturev->size();
int32_t index = SHMHDR->index;
@ -83,7 +83,7 @@ void ReadCreatureAtIndex(void *data)
uint16_t experience;
} raw_skill;
// learned skills
std::vector <void *> * skillv = (std::vector <void *> *) (temp + offsets.creature_skills_offset);
std::vector <void *> * skillv = (std::vector <void *> *) (temp + offsets.creature_skills_offset + offsets.vector_correct);
//DfVector skills (d->p->readVector (temp + offsets.creature_skills_offset, 4));
furball->numSkills = skillv->size();
for (uint32_t i = 0; i < furball->numSkills;i++)
@ -110,7 +110,7 @@ void ReadCreatureAtIndex(void *data)
}
//likes
std::vector <t_like *> * likev = (std::vector <t_like *> *) (temp + offsets.creature_likes_offset);
std::vector <t_like *> * likev = (std::vector <t_like *> *) (temp + offsets.creature_likes_offset + offsets.vector_correct);
furball->numLikes = likev->size();
for(uint32_t i = 0;i<furball->numLikes;i++)
{
@ -149,7 +149,7 @@ void FindNextCreatureInBox (void * data)
y = SHMHDR->y; y2 = SHMHDR->y2;
z = SHMHDR->z; z2 = SHMHDR->x2;
std::vector<char *> * creaturev = (std::vector<char *> *) offsets.creature_vector;
std::vector<char *> * creaturev = (std::vector<char *> *) (offsets.creature_vector + offsets.vector_correct);
uint32_t length = creaturev->size();
typedef uint16_t coords[3];

@ -67,6 +67,8 @@ typedef struct
uint32_t name_firstname_offset;
uint32_t name_nickname_offset;
uint32_t name_words_offset;
// HACK: vector address correction for SHM server
int32_t vector_correct;
} creature_offsets;
typedef struct

@ -105,7 +105,7 @@ int main ()
return EXIT_FAILURE;
}
items_vector = new DFHack::DfVector (proc->readVector (items, 4));
items_vector = new DFHack::DfVector (proc, items, 4);
for(uint32_t i = 0; i < items_vector->getSize(); i++)
{
// get pointer to object