From fb9ca213ec34e301a5dc3987b9a5180286ee069f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 18 Apr 2010 14:56:09 +0200 Subject: [PATCH] DFVector is now a template, eliminationg tons of ugly casts. I think I got them all, but testing is required. --- dfhack/DFHackAPI.cpp | 26 +++++++-------- dfhack/DFVector.cpp | 28 +--------------- dfhack/include/DFCommonInternal.h | 10 ++---- dfhack/include/DFGlobal.h | 12 +++++++ dfhack/include/DFProcess.h | 1 - dfhack/include/DFVector.h | 54 +++++++++++++++++++++---------- dfhack/modules/Buildings.cpp | 16 ++++----- dfhack/modules/Constructions.cpp | 8 ++--- dfhack/modules/Creatures.cpp | 26 +++++++-------- dfhack/modules/Maps.cpp | 20 ++++++------ dfhack/modules/Materials.cpp | 24 +++++++------- dfhack/modules/Translation.cpp | 22 ++++++------- dfhack/modules/Vegetation.cpp | 8 ++--- dfhack/shm/mod-creature40d.cpp | 1 - examples/buildingsdump.cpp | 1 + examples/construction_dump.cpp | 2 +- examples/creaturedump.cpp | 1 + examples/materialtest.cpp | 1 + examples/miscutils.h | 20 ++++++------ examples/spatterdump.cpp | 1 + examples/treedump.cpp | 1 + examples/veccheck.cpp | 1 + examples/veinlook.cpp | 1 + tools/dfbauxite.cpp | 8 ++--- 24 files changed, 150 insertions(+), 143 deletions(-) create mode 100644 dfhack/include/DFGlobal.h diff --git a/dfhack/DFHackAPI.cpp b/dfhack/DFHackAPI.cpp index 2ec8edccf..5e9bd8737 100644 --- a/dfhack/DFHackAPI.cpp +++ b/dfhack/DFHackAPI.cpp @@ -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 &indexes, }; temp2 temp2; for(uint32_t i =0;ip_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; jgetDescriptor(); - 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; -}; diff --git a/dfhack/include/DFCommonInternal.h b/dfhack/include/DFCommonInternal.h index 255dde145..85d4643fe 100644 --- a/dfhack/include/DFCommonInternal.h +++ b/dfhack/include/DFCommonInternal.h @@ -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 diff --git a/dfhack/include/DFGlobal.h b/dfhack/include/DFGlobal.h new file mode 100644 index 000000000..c43984a44 --- /dev/null +++ b/dfhack/include/DFGlobal.h @@ -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 \ No newline at end of file diff --git a/dfhack/include/DFProcess.h b/dfhack/include/DFProcess.h index 65adefe7f..15a75bef3 100644 --- a/dfhack/include/DFProcess.h +++ b/dfhack/include/DFProcess.h @@ -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 diff --git a/dfhack/include/DFVector.h b/dfhack/include/DFVector.h index 12e940cd0..7d69330a8 100644 --- a/dfhack/include/DFVector.h +++ b/dfhack/include/DFVector.h @@ -27,41 +27,61 @@ distribution. #include "Tranquility.h" #include "Export.h" - namespace DFHack { class Process; + template 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; }; }; } diff --git a/dfhack/modules/Buildings.cpp b/dfhack/modules/Buildings.cpp index a3ccaa77c..4262d74b3 100644 --- a/dfhack/modules/Buildings.cpp +++ b/dfhack/modules/Buildings.cpp @@ -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 * 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 (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 & btypes) { if(!d->Started) return false; - DfVector p_matgloss (g_pProcess, d->custom_workshop_vector, 4); - uint32_t size = p_matgloss.getSize(); + DfVector 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 diff --git a/dfhack/modules/Constructions.cpp b/dfhack/modules/Constructions.cpp index 1aa9c5a00..532240e77 100644 --- a/dfhack/modules/Constructions.cpp +++ b/dfhack/modules/Constructions.cpp @@ -37,7 +37,7 @@ struct Constructions::Private { uint32_t construction_vector; // translation - DfVector * p_cons; + DfVector * 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 (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); diff --git a/dfhack/modules/Creatures.cpp b/dfhack/modules/Creatures.cpp index 366182b49..27232d044 100644 --- a/dfhack/modules/Creatures.cpp +++ b/dfhack/modules/Creatures.cpp @@ -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 *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 (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 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 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 likes(d->p, temp + offs.creature_likes_offset); furball.numLikes = likes.getSize(); for(uint32_t i = 0;ip_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); diff --git a/dfhack/modules/Maps.cpp b/dfhack/modules/Maps.cpp index 8446e3322..bca7491b3 100644 --- a/dfhack/modules/Maps.cpp +++ b/dfhack/modules/Maps.cpp @@ -422,13 +422,13 @@ bool Maps::ReadVeins(uint32_t x, uint32_t y, uint32_t z, vector * 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 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 >& assign) uint32_t regions = g_pProcess->readDWord (world_regions); // read the geoblock vector - DfVector geoblocks (d->d->p, world_geoblocks_vector, 4); + DfVector 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 >& 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 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)); } diff --git a/dfhack/modules/Materials.cpp b/dfhack/modules/Materials.cpp index 4e2059705..5e467acbd 100644 --- a/dfhack/modules/Materials.cpp +++ b/dfhack/modules/Materials.cpp @@ -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 & 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 p_matgloss (d->p, matgloss_address); uint32_t size = p_matgloss.getSize(); inorganic.resize (0); @@ -144,7 +144,7 @@ bool API::ReadInorganicMaterials (vector & 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 & inorganic) // good for now inline bool ReadNamesOnly(Process* p, uint32_t address, vector & names) { - DfVector p_matgloss (p, address, 4); - uint32_t size = p_matgloss.getSize(); + DfVector 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 & creatures) bool Materials::ReadCreatureTypesEx (vector & creatures) { - DfVector p_races (g_pProcess, d->offset_descriptor->getAddress ("creature_type_vector"), 4); + DfVector 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 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)); diff --git a/dfhack/modules/Translation.cpp b/dfhack/modules/Translation.cpp index ddec1c72e..c82f82d32 100644 --- a/dfhack/modules/Translation.cpp +++ b/dfhack/modules/Translation.cpp @@ -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 genericVec (p, d->genericAddress); + DfVector 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 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); } diff --git a/dfhack/modules/Vegetation.cpp b/dfhack/modules/Vegetation.cpp index 721f6af1e..e39bb2516 100644 --- a/dfhack/modules/Vegetation.cpp +++ b/dfhack/modules/Vegetation.cpp @@ -38,7 +38,7 @@ struct Vegetation::Private uint32_t vegetation_vector; uint32_t tree_desc_offset; // translation - DfVector * p_veg; + DfVector * 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 (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; diff --git a/dfhack/shm/mod-creature40d.cpp b/dfhack/shm/mod-creature40d.cpp index 63c033066..35b17b57f 100644 --- a/dfhack/shm/mod-creature40d.cpp +++ b/dfhack/shm/mod-creature40d.cpp @@ -84,7 +84,6 @@ void ReadCreatureAtIndex(void *data) } raw_skill; // learned skills std::vector * skillv = (std::vector *) (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++) { diff --git a/examples/buildingsdump.cpp b/examples/buildingsdump.cpp index d4cccb440..304e4ac96 100644 --- a/examples/buildingsdump.cpp +++ b/examples/buildingsdump.cpp @@ -8,6 +8,7 @@ #include using namespace std; +#include #include #include #include diff --git a/examples/construction_dump.cpp b/examples/construction_dump.cpp index 57552dcf1..1f81faeb1 100644 --- a/examples/construction_dump.cpp +++ b/examples/construction_dump.cpp @@ -10,11 +10,11 @@ #include using namespace std; +#include #include #include #include #include -#include #include #include #include diff --git a/examples/creaturedump.cpp b/examples/creaturedump.cpp index 8d3f88507..ffcb1b22e 100644 --- a/examples/creaturedump.cpp +++ b/examples/creaturedump.cpp @@ -6,6 +6,7 @@ #include using namespace std; +#include #include #include #include diff --git a/examples/materialtest.cpp b/examples/materialtest.cpp index 1f397df41..b73e4ec20 100644 --- a/examples/materialtest.cpp +++ b/examples/materialtest.cpp @@ -8,6 +8,7 @@ #include using namespace std; +#include #include #include #include diff --git a/examples/miscutils.h b/examples/miscutils.h index 504933e36..02b8f6462 100644 --- a/examples/miscutils.h +++ b/examples/miscutils.h @@ -10,15 +10,17 @@ #include using namespace std; +#include +#include #include 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 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 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 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; diff --git a/examples/spatterdump.cpp b/examples/spatterdump.cpp index 1f7aca438..69d1aeedd 100644 --- a/examples/spatterdump.cpp +++ b/examples/spatterdump.cpp @@ -10,6 +10,7 @@ #include using namespace std; +#include #include #include #include diff --git a/examples/treedump.cpp b/examples/treedump.cpp index 463bbb8c3..a5f00d35e 100644 --- a/examples/treedump.cpp +++ b/examples/treedump.cpp @@ -10,6 +10,7 @@ #include using namespace std; +#include #include #include #include diff --git a/examples/veccheck.cpp b/examples/veccheck.cpp index 9f016677a..adc318a5b 100644 --- a/examples/veccheck.cpp +++ b/examples/veccheck.cpp @@ -10,6 +10,7 @@ #include using namespace std; +#include #include #include #include diff --git a/examples/veinlook.cpp b/examples/veinlook.cpp index 707eaf7b9..fdda877ec 100644 --- a/examples/veinlook.cpp +++ b/examples/veinlook.cpp @@ -16,6 +16,7 @@ using namespace std; #include #include +#include #include #include #include diff --git a/tools/dfbauxite.cpp b/tools/dfbauxite.cpp index 10e867f4a..cebff1351 100644 --- a/tools/dfbauxite.cpp +++ b/tools/dfbauxite.cpp @@ -31,7 +31,7 @@ int main () { DFHack::Process *proc; DFHack::memory_info *meminfo; - DFHack::DfVector *items_vector; + DFHack::DfVector *items_vector; DFHack::t_item_df40d item_40d; DFHack::t_matglossPair item_40d_material; vector 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 (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);