DFVector is now a template, eliminationg tons of ugly casts.

I think I got them all, but testing is required.
develop
Petr Mrázek 2010-04-18 14:56:09 +02:00
parent 13d07e5d70
commit fb9ca213ec
24 changed files with 150 additions and 143 deletions

@ -250,7 +250,7 @@ bool API::InitReadEffects ( uint32_t & numeffects )
return false;
}
d->effectsInited = true;
d->p_effect = new DfVector (d->p, effects, 4);
d->p_effect = new DfVector (d->p, effects);
numeffects = d->p_effect->getSize();
return true;
}
@ -263,7 +263,7 @@ bool API::ReadEffect(const uint32_t index, t_effect_df40d & effect)
return false;
// read pointer from vector at position
uint32_t temp = * (uint32_t *) d->p_effect->at (index);
uint32_t temp = d->p_effect->at (index);
//read effect from memory
g_pProcess->read (temp, sizeof (t_effect_df40d), (uint8_t *) &effect);
return true;
@ -277,7 +277,7 @@ bool API::WriteEffect(const uint32_t index, const t_effect_df40d & effect)
if(index >= d->p_effect->getSize())
return false;
// read pointer from vector at position
uint32_t temp = * (uint32_t *) d->p_effect->at (index);
uint32_t temp = d->p_effect->at (index);
// write effect to memory
g_pProcess->write(temp,sizeof(t_effect_df40d), (uint8_t *) &effect);
return true;
@ -306,7 +306,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, notes, 4);
d->p_notes = new DfVector (d->p, notes);
d->notesInited = true;
numnotes = d->p_notes->getSize();
return true;
@ -322,7 +322,7 @@ bool API::ReadNote (const int32_t index, t_note & note)
{
if(!d->notesInited) return false;
// read pointer from vector at position
uint32_t temp = * (uint32_t *) d->p_notes->at (index);
uint32_t temp = d->p_notes->at (index);
note.symbol = g_pProcess->readByte(temp);
note.foreground = g_pProcess->readWord(temp + d->note_foreground_offset);
note.background = g_pProcess->readWord(temp + d->note_background_offset);
@ -343,8 +343,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, allSettlements, 4);
d->p_current_settlement = new DfVector(d->p, currentSettlement,4);
d->p_settlements = new DfVector (d->p, allSettlements);
d->p_current_settlement = new DfVector(d->p, currentSettlement);
d->settlementsInited = true;
numsettlements = d->p_settlements->getSize();
return true;
@ -362,7 +362,7 @@ bool API::ReadSettlement(const int32_t index, t_settlement & settlement)
if(!d->p_settlements->getSize()) return false;
// read pointer from vector at position
uint32_t temp = * (uint32_t *) d->p_settlements->at (index);
uint32_t temp = d->p_settlements->at (index);
settlement.origin = temp;
d->readName(settlement.name, temp + d->settlement_name_offset);
g_pProcess->read(temp + d->settlement_world_xy_offset, 2 * sizeof(int16_t), (uint8_t *) &settlement.world_x);
@ -375,7 +375,7 @@ bool API::ReadCurrentSettlement(t_settlement & settlement)
if(!d->settlementsInited) return false;
if(!d->p_current_settlement->getSize()) return false;
uint32_t temp = * (uint32_t *) d->p_current_settlement->at(0);
uint32_t temp = d->p_current_settlement->at(0);
settlement.origin = temp;
d->readName(settlement.name, temp + d->settlement_name_offset);
g_pProcess->read(temp + d->settlement_world_xy_offset, 2 * sizeof(int16_t), (uint8_t *) &settlement.world_x);
@ -411,7 +411,7 @@ bool API::getItemIndexesInBox(vector<uint32_t> &indexes,
};
temp2 temp2;
for(uint32_t i =0;i<size;i++){
uint32_t temp = *(uint32_t *) d->p_itm->at(i);
uint32_t temp = d->p_itm->at(i);
g_pProcess->read(temp+sizeof(uint32_t),5 * sizeof(uint16_t), (uint8_t *) &temp2);
if(temp2.flags & (1 << 0)){
if (temp2.coords[0] >= x1 && temp2.coords[0] < x2)
@ -449,7 +449,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, items, 4);
d->p_itm = new DfVector (d->p, items);
d->itemsInited = true;
numitems = d->p_itm->getSize();
return true;
@ -468,7 +468,7 @@ bool API::ReadItem (const uint32_t index, t_item & item)
t_item_df40d item_40d;
// read pointer from vector at position
uint32_t temp = * (uint32_t *) d->p_itm->at (index);
uint32_t temp = d->p_itm->at (index);
//read building from memory
g_pProcess->read (temp, sizeof (t_item_df40d), (uint8_t *) &item_40d);
@ -512,7 +512,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, matgloss_address + i*matgloss_skip,4);
DfVector p_temp (d->p, matgloss_address + i*matgloss_skip);
vector< t_itemType > typesForVec;
for(uint32_t j =0; j<p_temp.getSize();j++)
{

@ -24,34 +24,8 @@ distribution.
#include "Tranquility.h"
#include "DFCommonInternal.h"
#include "DFVector.h"
#include "DFMemInfo.h"
#include "DFProcess.h"
#include "DFVector.h"
using namespace DFHack;
DfVector::DfVector(Process * p, uint32_t address, uint32_t _item_size)
{
uint32_t triplet[3];
item_size = _item_size;
memory_info * mem = p->getDescriptor();
uint32_t offs = mem->getOffset("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()
{
data = 0;
};
DfVector::~DfVector()
{
if(data)
delete [] data;
};

@ -22,6 +22,8 @@ must not be misrepresented as being the original software.
distribution.
*/
#include "DFGlobal.h"
#ifndef DFCOMMONINTERNAL_H_INCLUDED
#define DFCOMMONINTERNAL_H_INCLUDED
@ -65,14 +67,6 @@ typedef pid_t ProcessHandle;
typedef HANDLE ProcessHandle;
#endif
namespace DFHack
{
class Process;
/*
* Currently attached process and its handle
*/
extern Process * g_pProcess; ///< current process. non-NULL when picked
}
#ifndef BUILD_DFHACK_LIB
# define BUILD_DFHACK_LIB
#endif

@ -0,0 +1,12 @@
#ifndef DFHACK_GLOBAL
#define DFHACK_GLOBAL
#include "Export.h"
namespace DFHack
{
class Process;
/*
* Currently attached process and its handle
*/
extern DFHACK_EXPORT Process * g_pProcess; ///< current process. non-NULL when picked
}
#endif

@ -34,7 +34,6 @@ namespace DFHack
class memory_info;
class Process;
class DFWindow;
class DfVector;
// structure describing a memory range
struct DFHACK_EXPORT t_memrange

@ -27,41 +27,61 @@ distribution.
#include "Tranquility.h"
#include "Export.h"
namespace DFHack
{
class Process;
template <class T>
class DFHACK_EXPORT DfVector
{
private:
// starting offset
uint32_t start;
// vector size
uint32_t size;
uint32_t item_size;
uint8_t* data;
uint32_t _start;// starting offset
uint32_t _size;// vector size
T * data; // cached data
public:
DfVector();
DfVector(Process * p, uint32_t address, uint32_t item_size);
~DfVector();
DfVector(Process * p, uint32_t address)
{
uint32_t triplet[3];
memory_info * mem = p->getDescriptor();
uint32_t offs = mem->getOffset("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 / sizeof(T);
data = new T[_size];
p->read(_start,byte_size, (uint8_t *)data);
};
DfVector()
{
data = 0;
};
~DfVector()
{
if(data)
delete [] data;
};
// get offset of the specified index
inline void* operator[] (uint32_t index)
inline T& operator[] (uint32_t index)
{
// FIXME: vector out of bounds exception
//assert(index < size);
return data + index*item_size;
return data[index];
};
// get offset of the specified index
inline void* at (uint32_t index)
inline T& at (uint32_t index)
{
//assert(index < size);
return data + index*item_size;
return data[index];
};
// get vector size
inline uint32_t getSize ()
inline uint32_t size ()
{
return _size;
};
// get vector start
inline uint32_t start ()
{
return size;
return _start;
};
};
}

@ -57,7 +57,7 @@ struct Buildings::Private
uint32_t custom_workshop_type;
uint32_t custom_workshop_name;
int32_t custom_workshop_id;
DfVector * p_bld;
DfVector <uint32_t> * p_bld;
APIPrivate *d;
bool Inited;
bool Started;
@ -87,8 +87,8 @@ Buildings::~Buildings()
bool Buildings::Start(uint32_t & numbuildings)
{
d->p_bld = new DfVector (g_pProcess, d->buildings_vector, 4);
numbuildings = d->p_bld->getSize();
d->p_bld = new DfVector <uint32_t> (g_pProcess, d->buildings_vector);
numbuildings = d->p_bld->size();
d->Started = true;
return true;
}
@ -100,7 +100,7 @@ bool Buildings::Read (const uint32_t index, t_building & building)
t_building_df40d bld_40d;
// read pointer from vector at position
uint32_t temp = * (uint32_t *) d->p_bld->at (index);
uint32_t temp = d->p_bld->at (index);
//d->p_bld->read(index,(uint8_t *)&temp);
//read building from memory
@ -136,13 +136,13 @@ bool Buildings::ReadCustomWorkshopTypes(map <uint32_t, string> & btypes)
{
if(!d->Started)
return false;
DfVector p_matgloss (g_pProcess, d->custom_workshop_vector, 4);
uint32_t size = p_matgloss.getSize();
DfVector <uint32_t> p_matgloss (g_pProcess, d->custom_workshop_vector);
uint32_t size = p_matgloss.size();
btypes.clear();
for (uint32_t i = 0; i < size;i++)
{
string out = g_pProcess->readSTLString (*(uint32_t *) p_matgloss[i] + d->custom_workshop_name);
uint32_t type = g_pProcess->readDWord (*(uint32_t *) p_matgloss[i] + d->custom_workshop_type);
string out = g_pProcess->readSTLString (p_matgloss[i] + d->custom_workshop_name);
uint32_t type = g_pProcess->readDWord (p_matgloss[i] + d->custom_workshop_type);
#ifdef DEBUG
cout << out << ": " << type << endl;
#endif

@ -37,7 +37,7 @@ struct Constructions::Private
{
uint32_t construction_vector;
// translation
DfVector * p_cons;
DfVector <uint32_t> * p_cons;
APIPrivate *d;
bool Inited;
@ -64,8 +64,8 @@ Constructions::~Constructions()
bool Constructions::Start(uint32_t & numconstructions)
{
d->p_cons = new DfVector (g_pProcess, d->construction_vector, 4);
numconstructions = d->p_cons->getSize();
d->p_cons = new DfVector <uint32_t> (g_pProcess, d->construction_vector);
numconstructions = d->p_cons->size();
d->Started = true;
return true;
}
@ -76,7 +76,7 @@ bool Constructions::Read (const uint32_t index, t_construction & construction)
if(!d->Started) return false;
// read pointer from vector at position
uint32_t temp = * (uint32_t *) d->p_cons->at (index);
uint32_t temp = d->p_cons->at (index);
//read construction from memory
g_pProcess->read (temp, sizeof (t_construction), (uint8_t *) &construction);

@ -25,9 +25,9 @@ distribution.
#include "DFCommonInternal.h"
#include "../private/APIPrivate.h"
#include "DFVector.h"
#include "DFMemInfo.h"
#include "DFProcess.h"
#include "DFVector.h"
#include "DFError.h"
#include "DFTypes.h"
@ -52,7 +52,7 @@ struct Creatures::Private
Creatures2010::creature_offsets creatures;
uint32_t creature_module;
uint32_t dwarf_race_index_addr;
DfVector *p_cre;
DfVector <uint32_t> *p_cre;
APIPrivate *d;
};
@ -120,9 +120,9 @@ Creatures::~Creatures()
bool Creatures::Start( uint32_t &numcreatures )
{
d->p_cre = new DfVector (d->d->p, d->creatures.vector, 4);
d->p_cre = new DfVector <uint32_t> (d->d->p, d->creatures.vector);
d->Started = true;
numcreatures = d->p_cre->getSize();
numcreatures = d->p_cre->size();
return true;
}
@ -153,7 +153,7 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
// non-SHM slow path
// read pointer from vector at position
uint32_t temp = * (uint32_t *) d->p_cre->at (index);
uint32_t temp = d->p_cre->at (index);
furball.origin = temp;
Creatures2010::creature_offsets &offs = d->creatures;
@ -208,7 +208,7 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
/*
// enum soul pointer vector
DfVector souls(g_pProcess,temp + offs.creature_soul_vector_offset,4);
DfVector <uint32_t> souls(g_pProcess,temp + offs.creature_soul_vector_offset);
*/
uint32_t soul = g_pProcess->readDWord(temp + offs.default_soul_offset);
furball.has_default_soul = false;
@ -216,11 +216,11 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
{
furball.has_default_soul = true;
// get first soul's skills
DfVector skills(g_pProcess, soul + offs.soul_skills_vector_offset, 4 );
furball.defaultSoul.numSkills = skills.getSize();
DfVector <uint32_t> skills(g_pProcess, soul + offs.soul_skills_vector_offset);
furball.defaultSoul.numSkills = skills.size();
for (uint32_t i = 0; i < furball.defaultSoul.numSkills;i++)
{
uint32_t temp2 = * (uint32_t *) skills[i];
uint32_t temp2 = skills[i];
// a byte: this gives us 256 skills maximum.
furball.defaultSoul.skills[i].id = g_pProcess->readByte (temp2);
furball.defaultSoul.skills[i].rating = g_pProcess->readByte (temp2 + 4);
@ -234,7 +234,7 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
}
//likes
/*
DfVector likes(d->p, temp + offs.creature_likes_offset, 4);
DfVector <uint32_t> likes(d->p, temp + offs.creature_likes_offset);
furball.numLikes = likes.getSize();
for(uint32_t i = 0;i<furball.numLikes;i++)
{
@ -270,11 +270,11 @@ int32_t Creatures::ReadCreatureInBox (int32_t index, t_creature & furball,
else
{
uint16_t coords[3];
uint32_t size = d->p_cre->getSize();
uint32_t size = d->p_cre->size();
while (uint32_t(index) < size)
{
// read pointer from vector at position
uint32_t temp = * (uint32_t *) d->p_cre->at (index);
uint32_t temp = d->p_cre->at(index);
g_pProcess->read (temp + d->creatures.pos_offset, 3 * sizeof (uint16_t), (uint8_t *) &coords);
if (coords[0] >= x1 && coords[0] < x2)
{
@ -298,7 +298,7 @@ int32_t Creatures::ReadCreatureInBox (int32_t index, t_creature & furball,
bool Creatures::WriteLabors(const uint32_t index, uint8_t labors[NUM_CREATURE_LABORS])
{
if(!d->Started) return false;
uint32_t temp = * (uint32_t *) d->p_cre->at (index);
uint32_t temp = d->p_cre->at (index);
g_pProcess->write(temp + d->creatures.labors_offset, NUM_CREATURE_LABORS, labors);
uint32_t pickup_equip;
g_pProcess->readDWord(temp + d->creatures.pickup_equipment_bit, pickup_equip);

@ -422,13 +422,13 @@ bool Maps::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->d->p, addr + off.veinvector, 4);
uint32_t size = p_veins.getSize();
DfVector <uint32_t> p_veins (d->d->p, addr + off.veinvector);
uint32_t size = p_veins.size();
// read all veins
for (uint32_t i = 0; i < size;i++)
{
// read the vein pointer from the vector
uint32_t temp = * (uint32_t *) p_veins[i];
uint32_t temp = p_veins[i];
uint32_t type = g_pProcess->readDWord(temp);
try_again:
if(veins && type == off.vein_mineral_vptr)
@ -578,7 +578,7 @@ bool Maps::ReadGeology (vector < vector <uint16_t> >& assign)
uint32_t regions = g_pProcess->readDWord (world_regions);
// read the geoblock vector
DfVector geoblocks (d->d->p, world_geoblocks_vector, 4);
DfVector <uint32_t> geoblocks (d->d->p, world_geoblocks_vector);
// iterate over 8 surrounding regions + local region
for (int i = eNorthWest; i < eBiomeCount; i++)
@ -604,21 +604,21 @@ bool Maps::ReadGeology (vector < vector <uint16_t> >& assign)
/// geology blocks are assigned to regions from a vector
// get the geoblock from the geoblock vector using the geoindex
// read the matgloss pointer from the vector into temp
uint32_t geoblock_off = * (uint32_t *) geoblocks[geoindex];
uint32_t geoblock_off = geoblocks[geoindex];
/// geology blocks have a vector of layer descriptors
// get the vector with pointer to layers
DfVector geolayers (d->d->p, geoblock_off + geolayer_geoblock_offset , 4); // let's hope
DfVector <uint32_t> geolayers (d->d->p, geoblock_off + geolayer_geoblock_offset); // let's hope
// make sure we don't load crap
assert (geolayers.getSize() > 0 && geolayers.getSize() <= 16);
assert (geolayers.size() > 0 && geolayers.size() <= 16);
/// layer descriptor has a field that determines the type of stone/soil
d->v_geology[i].reserve (geolayers.getSize());
d->v_geology[i].reserve (geolayers.size());
// finally, read the layer matgloss
for (uint32_t j = 0;j < geolayers.getSize();j++)
for (uint32_t j = 0;j < geolayers.size();j++)
{
// read pointer to a layer
uint32_t geol_offset = * (uint32_t *) geolayers[j];
uint32_t geol_offset = geolayers[j];
// read word at pointer + 2, store in our geology vectors
d->v_geology[i].push_back (g_pProcess->readWord (geol_offset + type_inside_geolayer));
}

@ -25,9 +25,9 @@ distribution.
#include "DFCommonInternal.h"
#include "../private/APIPrivate.h"
#include "modules/Materials.h"
#include "DFVector.h"
#include "DFMemInfo.h"
#include "DFProcess.h"
#include "DFVector.h"
using namespace DFHack;
@ -136,7 +136,7 @@ bool API::ReadInorganicMaterials (vector<t_matgloss> & inorganic)
int matgloss_colors = minfo->getOffset ("material_color");
int matgloss_stone_name_offset = minfo->getOffset("matgloss_stone_name");
DfVector p_matgloss (d->p, matgloss_address, 4);
DfVector <uint32_t> p_matgloss (d->p, matgloss_address);
uint32_t size = p_matgloss.getSize();
inorganic.resize (0);
@ -144,7 +144,7 @@ bool API::ReadInorganicMaterials (vector<t_matgloss> & inorganic)
for (uint32_t i = 0; i < size;i++)
{
// read the matgloss pointer from the vector into temp
uint32_t temp = * (uint32_t *) p_matgloss[i];
uint32_t temp = p_matgloss[i];
// read the string pointed at by
t_matgloss mat;
//cout << temp << endl;
@ -167,14 +167,14 @@ bool API::ReadInorganicMaterials (vector<t_matgloss> & inorganic)
// good for now
inline bool ReadNamesOnly(Process* p, uint32_t address, vector<t_matgloss> & names)
{
DfVector p_matgloss (p, address, 4);
uint32_t size = p_matgloss.getSize();
DfVector <uint32_t> p_matgloss (p, address);
uint32_t size = p_matgloss.size();
names.clear();
names.reserve (size);
for (uint32_t i = 0; i < size;i++)
{
t_matgloss mat;
p->readSTLString (*(uint32_t *) p_matgloss[i], mat.id, 128);
p->readSTLString (p_matgloss[i], mat.id, 128);
names.push_back(mat);
}
return true;
@ -215,23 +215,23 @@ bool Materials::ReadCreatureTypes (vector<t_matgloss> & creatures)
bool Materials::ReadCreatureTypesEx (vector<t_creaturetype> & creatures)
{
DfVector p_races (g_pProcess, d->offset_descriptor->getAddress ("creature_type_vector"), 4);
DfVector <uint32_t> p_races (g_pProcess, d->offset_descriptor->getAddress ("creature_type_vector"));
uint32_t castes_vector_offset = d->offset_descriptor->getOffset ("creature_type_caste_vector");
uint32_t sizeof_string = d->offset_descriptor->getHexValue ("sizeof_string");
uint32_t size = p_races.getSize();
uint32_t size = p_races.size();
uint32_t sizecas = 0;
creatures.clear();
creatures.reserve (size);
for (uint32_t i = 0; i < size;i++)
{
t_creaturetype mat;
g_pProcess->readSTLString (*(uint32_t *) p_races[i], mat.rawname, sizeof(mat.rawname));
DfVector p_castes(g_pProcess,(*(uint32_t *) p_races[i]) + castes_vector_offset, 4);
sizecas = p_castes.getSize();
g_pProcess->readSTLString (p_races[i], mat.rawname, sizeof(mat.rawname));
DfVector <uint32_t> p_castes(g_pProcess,p_races[i] + castes_vector_offset);
sizecas = p_castes.size();
for (uint32_t j = 0; j < sizecas;j++)
{
t_creaturecaste caste;
uint32_t caste_start = *(uint32_t *)p_castes[j];
uint32_t caste_start = p_castes[j];
g_pProcess->readSTLString (caste_start, caste.rawname, sizeof(caste.rawname));
g_pProcess->readSTLString (caste_start + sizeof_string, caste.singular, sizeof(caste.singular));
g_pProcess->readSTLString (caste_start + 2 * sizeof_string, caste.plural, sizeof(caste.plural));

@ -73,15 +73,15 @@ bool Translation::Start()
if(!d->Inited)
return false;
Process * p = d->d->p;
DfVector genericVec (p, d->genericAddress, 4);
DfVector transVec (p, d->transAddress, 4);
DfVector <uint32_t> genericVec (p, d->genericAddress);
DfVector <uint32_t> transVec (p, d->transAddress);
DFDict & translations = d->dicts.translations;
DFDict & foreign_languages = d->dicts.foreign_languages;
translations.resize(10);
for (uint32_t i = 0;i < genericVec.getSize();i++)
for (uint32_t i = 0;i < genericVec.size();i++)
{
uint32_t genericNamePtr = * (uint32_t *) genericVec.at (i);
uint32_t genericNamePtr = genericVec.at(i);
for(int i=0; i<10;i++)
{
string word = p->readSTLString (genericNamePtr + i * d->sizeof_string);
@ -89,15 +89,15 @@ bool Translation::Start()
}
}
foreign_languages.resize(transVec.getSize());
for (uint32_t i = 0; i < transVec.getSize();i++)
foreign_languages.resize(transVec.size());
for (uint32_t i = 0; i < transVec.size();i++)
{
uint32_t transPtr = * (uint32_t *) transVec.at (i);
//string transName = d->p->readSTLString (transPtr);
DfVector trans_names_vec (p, transPtr + d->word_table_offset, 4);
for (uint32_t j = 0;j < trans_names_vec.getSize();j++)
uint32_t transPtr = transVec.at(i);
DfVector <uint32_t> trans_names_vec (p, transPtr + d->word_table_offset);
for (uint32_t j = 0;j < trans_names_vec.size();j++)
{
uint32_t transNamePtr = * (uint32_t *) trans_names_vec.at (j);
uint32_t transNamePtr = trans_names_vec.at(j);
string name = p->readSTLString (transNamePtr);
foreign_languages[i].push_back (name);
}

@ -38,7 +38,7 @@ struct Vegetation::Private
uint32_t vegetation_vector;
uint32_t tree_desc_offset;
// translation
DfVector * p_veg;
DfVector <uint32_t> * p_veg;
APIPrivate *d;
bool Inited;
@ -65,8 +65,8 @@ Vegetation::~Vegetation()
bool Vegetation::Start(uint32_t & numplants)
{
d->p_veg = new DfVector (g_pProcess, d->vegetation_vector, 4);
numplants = d->p_veg->getSize();
d->p_veg = new DfVector <uint32_t> (g_pProcess, d->vegetation_vector);
numplants = d->p_veg->size();
d->Started = true;
return true;
}
@ -77,7 +77,7 @@ bool Vegetation::Read (const uint32_t index, t_tree & shrubbery)
if(!d->Started)
return false;
// read pointer from vector at position
uint32_t temp = * (uint32_t *) d->p_veg->at (index);
uint32_t temp = d->p_veg->at (index);
// read from memory
g_pProcess->read (temp + d->tree_desc_offset, sizeof (t_tree), (uint8_t *) &shrubbery);
shrubbery.address = temp;

@ -84,7 +84,6 @@ void ReadCreatureAtIndex(void *data)
} raw_skill;
// learned skills
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++)
{

@ -8,6 +8,7 @@
#include <vector>
using namespace std;
#include <DFGlobal.h>
#include <DFError.h>
#include <DFTypes.h>
#include <DFHackAPI.h>

@ -10,11 +10,11 @@
#include <cstdio>
using namespace std;
#include <DFGlobal.h>
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFProcess.h>
#include <DFMemInfo.h>
#include <DFVector.h>
#include <DFTypes.h>
#include <modules/Materials.h>
#include <modules/Position.h>

@ -6,6 +6,7 @@
#include <vector>
using namespace std;
#include <DFGlobal.h>
#include <DFError.h>
#include <DFTypes.h>
#include <DFHackAPI.h>

@ -8,6 +8,7 @@
#include <ctime>
using namespace std;
#include <DFGlobal.h>
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFProcess.h>

@ -10,15 +10,17 @@
#include <cstdio>
using namespace std;
#include <DFProcess.h>
#include <DFMemInfo.h>
#include <DFVector.h>
void DumpObjStr0Vector (const char * name, DFHack::Process *p, uint32_t addr)
{
cout << "----==== " << name << " ====----" << endl;
DFHack::DfVector vect(p,addr,4);
for(uint32_t i = 0; i < vect.getSize();i++)
DFHack::DfVector <uint32_t> vect(p,addr);
for(uint32_t i = 0; i < vect.size();i++)
{
uint32_t addr = *(uint32_t *) vect[i];
uint32_t addr = vect[i];
cout << p->readSTLString(addr) << endl;
}
cout << endl;
@ -26,10 +28,10 @@ void DumpObjStr0Vector (const char * name, DFHack::Process *p, uint32_t addr)
void DumpObjVtables (const char * name, DFHack::Process *p, uint32_t addr)
{
cout << "----==== " << name << " ====----" << endl;
DFHack::DfVector vect(p,addr,4);
for(uint32_t i = 0; i < vect.getSize();i++)
DFHack::DfVector <uint32_t> vect(p,addr);
for(uint32_t i = 0; i < vect.size();i++)
{
uint32_t addr = *(uint32_t *) vect[i];
uint32_t addr = vect[i];
uint32_t vptr = p->readDWord(addr);
cout << p->readClassName(vptr) << endl;
}
@ -38,10 +40,10 @@ void DumpObjVtables (const char * name, DFHack::Process *p, uint32_t addr)
void DumpDWordVector (const char * name, DFHack::Process *p, uint32_t addr)
{
cout << "----==== " << name << " ====----" << endl;
DFHack::DfVector vect(p,addr,4);
for(uint32_t i = 0; i < vect.getSize();i++)
DFHack::DfVector <uint32_t> vect(p,addr);
for(uint32_t i = 0; i < vect.size();i++)
{
uint32_t number = *(uint32_t *) vect[i];
uint32_t number = vect[i];
cout << number << endl;
}
cout << endl;

@ -10,6 +10,7 @@
#include <cstdio>
using namespace std;
#include <DFGlobal.h>
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFProcess.h>

@ -10,6 +10,7 @@
#include <cstdio>
using namespace std;
#include <DFGlobal.h>
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFProcess.h>

@ -10,6 +10,7 @@
#include <cstdio>
using namespace std;
#include <DFGlobal.h>
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFProcess.h>

@ -16,6 +16,7 @@ using namespace std;
#include <locale.h>
#include <math.h>
#include <DFGlobal.h>
#include <DFTypes.h>
#include <DFTileTypes.h>
#include <DFHackAPI.h>

@ -31,7 +31,7 @@ int main ()
{
DFHack::Process *proc;
DFHack::memory_info *meminfo;
DFHack::DfVector *items_vector;
DFHack::DfVector <uint32_t> *items_vector;
DFHack::t_item_df40d item_40d;
DFHack::t_matglossPair item_40d_material;
vector<DFHack::t_matgloss> stoneMat;
@ -105,11 +105,11 @@ int main ()
return EXIT_FAILURE;
}
items_vector = new DFHack::DfVector (proc, items, 4);
for(uint32_t i = 0; i < items_vector->getSize(); i++)
items_vector = new DFHack::DfVector <uint32_t> (proc, items);
for(uint32_t i = 0; i < items_vector->size(); i++)
{
// get pointer to object
temp = * (uint32_t *) items_vector->at (i);
temp = items_vector->at (i);
// read object
proc->read (temp, sizeof (DFHack::t_item_df40d), (uint8_t *) &item_40d);