Removed g_pProcess global.

develop
Petr Mrázek 2010-04-18 21:30:02 +02:00
parent fb9ca213ec
commit 2eddc69ef8
21 changed files with 263 additions and 207 deletions

@ -56,7 +56,7 @@ bool APIPrivate::InitReadNames()
void APIPrivate::readName(t_name & name, uint32_t address) void APIPrivate::readName(t_name & name, uint32_t address)
{ {
g_pProcess->readSTLString(address + name_firstname_offset , name.first_name, 128); p->readSTLString(address + name_firstname_offset , name.first_name, 128);
g_pProcess->readSTLString(address + name_nickname_offset , name.nickname, 128); p->readSTLString(address + name_nickname_offset , name.nickname, 128);
g_pProcess->read(address + name_words_offset ,48, (uint8_t *) name.words); p->read(address + name_words_offset ,48, (uint8_t *) name.words);
} }

@ -145,12 +145,12 @@ bool API::isSuspended()
void API::ReadRaw (const uint32_t offset, const uint32_t size, uint8_t *target) void API::ReadRaw (const uint32_t offset, const uint32_t size, uint8_t *target)
{ {
g_pProcess->read (offset, size, target); d->p->read (offset, size, target);
} }
void API::WriteRaw (const uint32_t offset, const uint32_t size, uint8_t *source) void API::WriteRaw (const uint32_t offset, const uint32_t size, uint8_t *source)
{ {
g_pProcess->write (offset, size, source); d->p->write (offset, size, source);
} }
memory_info *API::getMemoryInfo() memory_info *API::getMemoryInfo()
@ -265,7 +265,7 @@ bool API::ReadEffect(const uint32_t index, t_effect_df40d & effect)
// read pointer from vector at position // read pointer from vector at position
uint32_t temp = d->p_effect->at (index); uint32_t temp = d->p_effect->at (index);
//read effect from memory //read effect from memory
g_pProcess->read (temp, sizeof (t_effect_df40d), (uint8_t *) &effect); d->p->read (temp, sizeof (t_effect_df40d), (uint8_t *) &effect);
return true; return true;
} }
@ -279,7 +279,7 @@ bool API::WriteEffect(const uint32_t index, const t_effect_df40d & effect)
// read pointer from vector at position // read pointer from vector at position
uint32_t temp = d->p_effect->at (index); uint32_t temp = d->p_effect->at (index);
// write effect to memory // write effect to memory
g_pProcess->write(temp,sizeof(t_effect_df40d), (uint8_t *) &effect); d->p->write(temp,sizeof(t_effect_df40d), (uint8_t *) &effect);
return true; return true;
} }
@ -323,11 +323,11 @@ bool API::ReadNote (const int32_t index, t_note & note)
if(!d->notesInited) return false; if(!d->notesInited) return false;
// read pointer from vector at position // read pointer from vector at position
uint32_t temp = d->p_notes->at (index); uint32_t temp = d->p_notes->at (index);
note.symbol = g_pProcess->readByte(temp); note.symbol = d->p->readByte(temp);
note.foreground = g_pProcess->readWord(temp + d->note_foreground_offset); note.foreground = d->p->readWord(temp + d->note_foreground_offset);
note.background = g_pProcess->readWord(temp + d->note_background_offset); note.background = d->p->readWord(temp + d->note_background_offset);
d->p->readSTLString (temp + d->note_name_offset, note.name, 128); d->p->readSTLString (temp + d->note_name_offset, note.name, 128);
g_pProcess->read (temp + d->note_xyz_offset, 3*sizeof (uint16_t), (uint8_t *) &note.x); d->p->read (temp + d->note_xyz_offset, 3*sizeof (uint16_t), (uint8_t *) &note.x);
return true; return true;
} }
bool API::InitReadSettlements( uint32_t & numsettlements ) bool API::InitReadSettlements( uint32_t & numsettlements )
@ -365,8 +365,8 @@ bool API::ReadSettlement(const int32_t index, t_settlement & settlement)
uint32_t temp = d->p_settlements->at (index); uint32_t temp = d->p_settlements->at (index);
settlement.origin = temp; settlement.origin = temp;
d->readName(settlement.name, temp + d->settlement_name_offset); 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); d->p->read(temp + d->settlement_world_xy_offset, 2 * sizeof(int16_t), (uint8_t *) &settlement.world_x);
g_pProcess->read(temp + d->settlement_local_xy_offset, 4 * sizeof(int16_t), (uint8_t *) &settlement.local_x1); d->p->read(temp + d->settlement_local_xy_offset, 4 * sizeof(int16_t), (uint8_t *) &settlement.local_x1);
return true; return true;
} }
@ -378,8 +378,8 @@ bool API::ReadCurrentSettlement(t_settlement & settlement)
uint32_t temp = d->p_current_settlement->at(0); uint32_t temp = d->p_current_settlement->at(0);
settlement.origin = temp; settlement.origin = temp;
d->readName(settlement.name, temp + d->settlement_name_offset); 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); d->p->read(temp + d->settlement_world_xy_offset, 2 * sizeof(int16_t), (uint8_t *) &settlement.world_x);
g_pProcess->read(temp + d->settlement_local_xy_offset, 4 * sizeof(int16_t), (uint8_t *) &settlement.local_x1); d->p->read(temp + d->settlement_local_xy_offset, 4 * sizeof(int16_t), (uint8_t *) &settlement.local_x1);
return true; return true;
} }
@ -412,7 +412,7 @@ bool API::getItemIndexesInBox(vector<uint32_t> &indexes,
temp2 temp2; temp2 temp2;
for(uint32_t i =0;i<size;i++){ for(uint32_t i =0;i<size;i++){
uint32_t temp = 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); d->p->read(temp+sizeof(uint32_t),5 * sizeof(uint16_t), (uint8_t *) &temp2);
if(temp2.flags & (1 << 0)){ if(temp2.flags & (1 << 0)){
if (temp2.coords[0] >= x1 && temp2.coords[0] < x2) if (temp2.coords[0] >= x1 && temp2.coords[0] < x2)
{ {
@ -471,7 +471,7 @@ bool API::ReadItem (const uint32_t index, t_item & item)
uint32_t temp = d->p_itm->at (index); uint32_t temp = d->p_itm->at (index);
//read building from memory //read building from memory
g_pProcess->read (temp, sizeof (t_item_df40d), (uint8_t *) &item_40d); d->p->read (temp, sizeof (t_item_df40d), (uint8_t *) &item_40d);
// transform // transform
int32_t type = -1; int32_t type = -1;
@ -486,7 +486,7 @@ bool API::ReadItem (const uint32_t index, t_item & item)
item.flags.whole = item_40d.flags; item.flags.whole = item_40d.flags;
//TODO certain item types (creature based, threads, seeds, bags do not have the first matType byte, instead they have the material index only located at 0x68 //TODO certain item types (creature based, threads, seeds, bags do not have the first matType byte, instead they have the material index only located at 0x68
g_pProcess->read (temp + d->item_material_offset, sizeof (t_matglossPair), (uint8_t *) &item.material); d->p->read (temp + d->item_material_offset, sizeof (t_matglossPair), (uint8_t *) &item.material);
//for(int i = 0; i < 0xCC; i++){ // used for item research //for(int i = 0; i < 0xCC; i++){ // used for item research
// uint8_t byte = MreadByte(temp+i); // uint8_t byte = MreadByte(temp+i);
// item.bytes.push_back(byte); // item.bytes.push_back(byte);

@ -58,6 +58,7 @@ class memory_info::Private
uint32_t classindex; uint32_t classindex;
int32_t base; int32_t base;
Process * p; // the process this belongs to
string version; string version;
OSType OS; OSType OS;
@ -68,6 +69,7 @@ memory_info::memory_info()
:d(new Private) :d(new Private)
{ {
d->base = 0; d->base = 0;
d->p = 0;
d->classindex = 0; d->classindex = 0;
} }
@ -96,6 +98,10 @@ memory_info::memory_info(const memory_info &old)
d->traits = old.d->traits; d->traits = old.d->traits;
d->labors = old.d->labors; d->labors = old.d->labors;
} }
void memory_info::setParentProcess(Process * _p)
{
d->p = _p;
}
// destructor // destructor
memory_info::~memory_info() memory_info::~memory_info()
@ -327,7 +333,7 @@ void memory_info::setClassChild (t_class * parent, const char * name, const char
// FIXME: stupid. we need a better container // FIXME: stupid. we need a better container
bool memory_info::resolveObjectToClassID(const uint32_t address, int32_t & classid) bool memory_info::resolveObjectToClassID(const uint32_t address, int32_t & classid)
{ {
uint32_t vtable = g_pProcess->readDWord(address); uint32_t vtable = d->p->readDWord(address);
// try to find the vtable in our cache // try to find the vtable in our cache
map<uint32_t, t_class *>::iterator it; map<uint32_t, t_class *>::iterator it;
it = d->classIDs.find(vtable); it = d->classIDs.find(vtable);
@ -341,7 +347,7 @@ bool memory_info::resolveObjectToClassID(const uint32_t address, int32_t & class
else// couldn't find? else// couldn't find?
{ {
// we set up the class for the first time // we set up the class for the first time
string classname = g_pProcess->readClassName(vtable); string classname = d->p->readClassName(vtable);
d->classIDs[vtable] = cl = setClass(classname.c_str(),vtable); d->classIDs[vtable] = cl = setClass(classname.c_str(),vtable);
} }
// and isn't a multi-class // and isn't a multi-class
@ -356,7 +362,7 @@ bool memory_info::resolveObjectToClassID(const uint32_t address, int32_t & class
{ {
// find the type // find the type
vector <t_type*>& vec = cl->subs; vector <t_type*>& vec = cl->subs;
uint32_t type = g_pProcess->readWord(address + cl->type_offset); uint32_t type = d->p->readWord(address + cl->type_offset);
// return typed building if successful // return typed building if successful
//FIXME: the vector should map directly to the type IDs here, so we don't have to mess with O(n) search //FIXME: the vector should map directly to the type IDs here, so we don't have to mess with O(n) search
for (uint32_t k = 0; k < vec.size();k++) for (uint32_t k = 0; k < vec.size();k++)

@ -118,7 +118,6 @@ bool SHMProcess::Private::SetAndWait (uint32_t state)
FreeLocks(); FreeLocks();
attached = locked = identified = false; attached = locked = identified = false;
// we aren't the current process anymore // we aren't the current process anymore
g_pProcess = NULL;
throw Error::SHMServerDisappeared(); throw Error::SHMServerDisappeared();
} }
else else
@ -338,6 +337,7 @@ bool SHMProcess::Private::validate(vector <memory_info *> & known_versions)
{ {
memory_info * m = *it; memory_info * m = *it;
memdescriptor = m; memdescriptor = m;
m->setParentProcess((Process*)this);
identified = true; identified = true;
// cerr << "identified " << m->getVersion() << endl; // cerr << "identified " << m->getVersion() << endl;
return true; return true;
@ -537,11 +537,11 @@ bool SHMProcess::resume()
bool SHMProcess::attach() bool SHMProcess::attach()
{ {
if(g_pProcess != 0) if(d->attached)
{ {
// FIXME: throw exception here - programmer error if(!d->locked)
cerr << "client is already attached to a process!" << endl; return suspend();
return false; return true;
} }
if(!d->GetLocks()) if(!d->GetLocks())
{ {
@ -576,7 +576,6 @@ bool SHMProcess::attach()
cerr << "unable to suspend" << endl; cerr << "unable to suspend" << endl;
return false; return false;
} }
g_pProcess = this;
return true; return true;
} }
@ -597,7 +596,6 @@ bool SHMProcess::detach()
d->locked = false; d->locked = false;
d->attached = false; d->attached = false;
d->shm_addr = 0; d->shm_addr = 0;
g_pProcess = 0;
return true; return true;
} }
// fail if we can't detach // fail if we can't detach

@ -149,6 +149,7 @@ bool WineProcess::Private::validate(char* exe_file, uint32_t pid, char* mem_file
{ {
memory_info * m = *it; memory_info * m = *it;
my_descriptor = m; my_descriptor = m;
m->setParentProcess((Process*)this);
my_handle = my_pid = pid; my_handle = my_pid = pid;
// tell WineProcess about the /proc/PID/mem file // tell WineProcess about the /proc/PID/mem file
memFile = mem_file; memFile = mem_file;
@ -281,9 +282,11 @@ bool WineProcess::resume()
bool WineProcess::attach() bool WineProcess::attach()
{ {
int status; int status;
if(g_pProcess != NULL) if(d->attached)
{ {
return false; if(!d->suspended)
return suspend();
return true;
} }
// can we attach? // can we attach?
if (ptrace(PTRACE_ATTACH , d->my_handle, NULL, NULL) == -1) if (ptrace(PTRACE_ATTACH , d->my_handle, NULL, NULL) == -1)
@ -323,7 +326,6 @@ bool WineProcess::attach()
else else
{ {
d->attached = true; d->attached = true;
g_pProcess = this;
d->memFileHandle = proc_pid_mem; d->memFileHandle = proc_pid_mem;
return true; // we are attached return true; // we are attached
@ -356,7 +358,6 @@ bool WineProcess::detach()
else else
{ {
d->attached = false; d->attached = false;
g_pProcess = NULL;
return true; return true;
} }
} }

@ -126,6 +126,7 @@ bool NormalProcess::Private::validate(char * exe_file,uint32_t pid, char * memFi
if (memory_info::OS_LINUX == m->getOS()) if (memory_info::OS_LINUX == m->getOS())
{ {
my_descriptor = m; my_descriptor = m;
m->setParentProcess((Process*)this);
my_handle = my_pid = pid; my_handle = my_pid = pid;
} }
else else
@ -270,9 +271,11 @@ bool NormalProcess::resume()
bool NormalProcess::attach() bool NormalProcess::attach()
{ {
int status; int status;
if(g_pProcess != NULL) if(d->attached)
{ {
return false; if(!d->suspended)
return suspend();
return true;
} }
// can we attach? // can we attach?
if (ptrace(PTRACE_ATTACH , d->my_handle, NULL, NULL) == -1) if (ptrace(PTRACE_ATTACH , d->my_handle, NULL, NULL) == -1)
@ -311,7 +314,6 @@ bool NormalProcess::attach()
else else
{ {
d->attached = true; d->attached = true;
g_pProcess = this;
d->memFileHandle = proc_pid_mem; d->memFileHandle = proc_pid_mem;
return true; // we are attached return true; // we are attached
@ -344,7 +346,6 @@ bool NormalProcess::detach()
else else
{ {
d->attached = false; d->attached = false;
g_pProcess = NULL;
return true; return true;
} }
} }

@ -110,7 +110,6 @@ bool SHMProcess::Private::SetAndWait (uint32_t state)
FreeLocks(); FreeLocks();
attached = locked = identified = false; attached = locked = identified = false;
// we aren't the current process anymore // we aren't the current process anymore
g_pProcess = NULL;
throw Error::SHMServerDisappeared(); throw Error::SHMServerDisappeared();
} }
else else
@ -367,6 +366,7 @@ bool SHMProcess::Private::validate(vector <memory_info *> & known_versions)
memory_info *m = new memory_info(**it); memory_info *m = new memory_info(**it);
m->RebaseAll(base); m->RebaseAll(base);
memdescriptor = m; memdescriptor = m;
m->setParentProcess(this);
identified = true; identified = true;
cerr << "identified " << m->getVersion() << endl; cerr << "identified " << m->getVersion() << endl;
CloseHandle(hProcess); CloseHandle(hProcess);
@ -577,10 +577,11 @@ bool SHMProcess::resume()
bool SHMProcess::attach() bool SHMProcess::attach()
{ {
if(g_pProcess != 0) if(d->attached)
{ {
cerr << "there's already a process attached" << endl; if(!d->locked)
return false; return suspend();
return true;
} }
//cerr << "attach" << endl;// FIXME: throw //cerr << "attach" << endl;// FIXME: throw
if(!d->GetLocks()) if(!d->GetLocks())
@ -639,7 +640,6 @@ bool SHMProcess::attach()
//cerr << "unable to suspend" << endl;// FIXME: throw //cerr << "unable to suspend" << endl;// FIXME: throw
return false; return false;
} }
g_pProcess = this;
return true; return true;
} }
@ -663,7 +663,6 @@ bool SHMProcess::detach()
d->attached = false; d->attached = false;
d->locked = false; d->locked = false;
d->shm_addr = false; d->shm_addr = false;
g_pProcess = 0;
return true; return true;
} }

@ -127,6 +127,7 @@ NormalProcess::NormalProcess(uint32_t pid, vector <memory_info *> & known_versio
m->RebaseAll(base); m->RebaseAll(base);
// keep track of created memory_info object so we can destroy it later // keep track of created memory_info object so we can destroy it later
d->my_descriptor = m; d->my_descriptor = m;
m->setParentProcess(this);
// process is responsible for destroying its data model // process is responsible for destroying its data model
d->my_pid = pid; d->my_pid = pid;
d->my_handle = hProcess; d->my_handle = hProcess;
@ -249,12 +250,13 @@ bool NormalProcess::resume()
bool NormalProcess::attach() bool NormalProcess::attach()
{ {
if(g_pProcess != NULL) if(d->attached)
{ {
return false; if(!d->suspended)
return suspend();
return true;
} }
d->attached = true; d->attached = true;
g_pProcess = this;
suspend(); suspend();
return true; return true;
@ -269,7 +271,6 @@ bool NormalProcess::detach()
} }
resume(); resume();
d->attached = false; d->attached = false;
g_pProcess = NULL;
return true; return true;
} }

@ -35,9 +35,6 @@ distribution.
using namespace DFHack; using namespace DFHack;
/// HACK: global variables (only one process can be attached at the same time.)
Process * DFHack::g_pProcess; ///< current process. non-NULL when picked
class DFHack::ProcessEnumerator::Private class DFHack::ProcessEnumerator::Private
{ {
public: public:

@ -29,9 +29,6 @@ distribution.
#include "DFMemInfoManager.h" #include "DFMemInfoManager.h"
using namespace DFHack; using namespace DFHack;
/// HACK: global variables (only one process can be attached at the same time.)
Process * DFHack::g_pProcess; ///< current process. non-NULL when picked
class DFHack::ProcessEnumerator::Private class DFHack::ProcessEnumerator::Private
{ {
public: public:

@ -1,12 +1,11 @@
#ifndef DFHACK_GLOBAL #ifndef DFHACK_GLOBAL
#define DFHACK_GLOBAL #define DFHACK_GLOBAL
#include "Export.h" #include "Export.h"
// globals, if any, should be placed here.
namespace DFHack namespace DFHack
{ {
class Process; // extern DFHACK_EXPORT TYPE NAME;
/*
* Currently attached process and its handle
*/
extern DFHACK_EXPORT Process * g_pProcess; ///< current process. non-NULL when picked
} }
#endif #endif

@ -34,6 +34,12 @@ distribution.
namespace DFHack namespace DFHack
{ {
/*
* Stubs
*/
class Process;
/* /*
* Common data types * Common data types
*/ */
@ -148,6 +154,7 @@ namespace DFHack
void setLabor(const string &, const string &); void setLabor(const string &, const string &);
void RebaseVTable(const int32_t offset); void RebaseVTable(const int32_t offset);
void setParentProcess(Process * _p);
t_class * setClass (const char * classname, uint32_t vptr = 0, uint32_t typeoffset = 0); t_class * setClass (const char * classname, uint32_t vptr = 0, uint32_t typeoffset = 0);
void setClassChild (t_class * parent, const char * classname, const char * type); void setClassChild (t_class * parent, const char * classname, const char * type);

@ -61,7 +61,8 @@ namespace DFHack
bool ReadCreatureTypes (std::vector<t_matgloss> & output); bool ReadCreatureTypes (std::vector<t_matgloss> & output);
bool ReadCreatureTypesEx (vector<t_creaturetype> & creatures); bool ReadCreatureTypesEx (vector<t_creaturetype> & creatures);
private: private:
APIPrivate* d; class Private;
Private* d;
}; };
} }
#endif #endif

@ -59,6 +59,7 @@ struct Buildings::Private
int32_t custom_workshop_id; int32_t custom_workshop_id;
DfVector <uint32_t> * p_bld; DfVector <uint32_t> * p_bld;
APIPrivate *d; APIPrivate *d;
Process * owner;
bool Inited; bool Inited;
bool Started; bool Started;
}; };
@ -67,6 +68,7 @@ Buildings::Buildings(APIPrivate * d_)
{ {
d = new Private; d = new Private;
d->d = d_; d->d = d_;
d->owner = d_->p;
d->Inited = d->Started = false; d->Inited = d->Started = false;
memory_info * mem = d->d->offset_descriptor; memory_info * mem = d->d->offset_descriptor;
d->custom_workshop_vector = mem->getAddress("custom_workshop_vector"); d->custom_workshop_vector = mem->getAddress("custom_workshop_vector");
@ -87,7 +89,7 @@ Buildings::~Buildings()
bool Buildings::Start(uint32_t & numbuildings) bool Buildings::Start(uint32_t & numbuildings)
{ {
d->p_bld = new DfVector <uint32_t> (g_pProcess, d->buildings_vector); d->p_bld = new DfVector <uint32_t> (d->owner, d->buildings_vector);
numbuildings = d->p_bld->size(); numbuildings = d->p_bld->size();
d->Started = true; d->Started = true;
return true; return true;
@ -104,7 +106,7 @@ bool Buildings::Read (const uint32_t index, t_building & building)
//d->p_bld->read(index,(uint8_t *)&temp); //d->p_bld->read(index,(uint8_t *)&temp);
//read building from memory //read building from memory
g_pProcess->read (temp, sizeof (t_building_df40d), (uint8_t *) &bld_40d); d->owner->read (temp, sizeof (t_building_df40d), (uint8_t *) &bld_40d);
// transform // transform
int32_t type = -1; int32_t type = -1;
@ -136,13 +138,16 @@ bool Buildings::ReadCustomWorkshopTypes(map <uint32_t, string> & btypes)
{ {
if(!d->Started) if(!d->Started)
return false; return false;
DfVector <uint32_t> p_matgloss (g_pProcess, d->custom_workshop_vector);
Process * p = d->owner;
DfVector <uint32_t> p_matgloss (p, d->custom_workshop_vector);
uint32_t size = p_matgloss.size(); uint32_t size = p_matgloss.size();
btypes.clear(); btypes.clear();
for (uint32_t i = 0; i < size;i++) for (uint32_t i = 0; i < size;i++)
{ {
string out = g_pProcess->readSTLString (p_matgloss[i] + d->custom_workshop_name); string out = p->readSTLString (p_matgloss[i] + d->custom_workshop_name);
uint32_t type = g_pProcess->readDWord (p_matgloss[i] + d->custom_workshop_type); uint32_t type = p->readDWord (p_matgloss[i] + d->custom_workshop_type);
#ifdef DEBUG #ifdef DEBUG
cout << out << ": " << type << endl; cout << out << ": " << type << endl;
#endif #endif
@ -160,7 +165,7 @@ int32_t Buildings::GetCustomWorkshopType(t_building & building)
if(type != -1 && type == d->custom_workshop_id) if(type != -1 && type == d->custom_workshop_id)
{ {
// read the custom workshop subtype // read the custom workshop subtype
ret = (int32_t) g_pProcess->readDWord(building.origin + d->building_custom_workshop_type); ret = (int32_t) d->owner->readDWord(building.origin + d->building_custom_workshop_type);
} }
return ret; return ret;
} }

@ -40,6 +40,7 @@ struct Constructions::Private
DfVector <uint32_t> * p_cons; DfVector <uint32_t> * p_cons;
APIPrivate *d; APIPrivate *d;
Process * owner;
bool Inited; bool Inited;
bool Started; bool Started;
}; };
@ -48,6 +49,7 @@ Constructions::Constructions(APIPrivate * d_)
{ {
d = new Private; d = new Private;
d->d = d_; d->d = d_;
d->owner = d_->p;
d->p_cons = 0; d->p_cons = 0;
d->Inited = d->Started = false; d->Inited = d->Started = false;
memory_info * mem = d->d->offset_descriptor; memory_info * mem = d->d->offset_descriptor;
@ -64,7 +66,7 @@ Constructions::~Constructions()
bool Constructions::Start(uint32_t & numconstructions) bool Constructions::Start(uint32_t & numconstructions)
{ {
d->p_cons = new DfVector <uint32_t> (g_pProcess, d->construction_vector); d->p_cons = new DfVector <uint32_t> (d->owner, d->construction_vector);
numconstructions = d->p_cons->size(); numconstructions = d->p_cons->size();
d->Started = true; d->Started = true;
return true; return true;
@ -79,7 +81,7 @@ bool Constructions::Read (const uint32_t index, t_construction & construction)
uint32_t temp = d->p_cons->at (index); uint32_t temp = d->p_cons->at (index);
//read construction from memory //read construction from memory
g_pProcess->read (temp, sizeof (t_construction), (uint8_t *) &construction); d->owner->read (temp, sizeof (t_construction), (uint8_t *) &construction);
// transform // transform
construction.origin = temp; construction.origin = temp;

@ -54,12 +54,14 @@ struct Creatures::Private
uint32_t dwarf_race_index_addr; uint32_t dwarf_race_index_addr;
DfVector <uint32_t> *p_cre; DfVector <uint32_t> *p_cre;
APIPrivate *d; APIPrivate *d;
Process *owner;
}; };
Creatures::Creatures(APIPrivate* _d) Creatures::Creatures(APIPrivate* _d)
{ {
d = new Private; d = new Private;
d->d = _d; d->d = _d;
Process * p = d->owner = _d->p;
d->Inited = false; d->Inited = false;
d->Started = false; d->Started = false;
d->d->InitReadNames(); // throws on error d->d->InitReadNames(); // throws on error
@ -96,12 +98,12 @@ Creatures::Creatures(APIPrivate* _d)
creatures.name_words_offset = minfo->getOffset("name_words"); creatures.name_words_offset = minfo->getOffset("name_words");
d->dwarf_race_index_addr = minfo->getAddress("dwarf_race_index"); d->dwarf_race_index_addr = minfo->getAddress("dwarf_race_index");
// upload offsets to the SHM // upload offsets to the SHM
if(g_pProcess->getModuleIndex("Creatures2010",1,d->creature_module)) if(p->getModuleIndex("Creatures2010",1,d->creature_module))
{ {
// supply the module with offsets so it can work with them // supply the module with offsets so it can work with them
memcpy(SHMDATA(Creatures2010::creature_offsets),&creatures,sizeof(Creatures2010::creature_offsets)); memcpy(SHMDATA(Creatures2010::creature_offsets),&creatures,sizeof(Creatures2010::creature_offsets));
const uint32_t cmd = Creatures2010::CREATURE_INIT + (d->creature_module << 16); const uint32_t cmd = Creatures2010::CREATURE_INIT + (d->creature_module << 16);
g_pProcess->SetAndWait(cmd); p->SetAndWait(cmd);
} }
d->Inited = true; d->Inited = true;
} }
@ -120,7 +122,7 @@ Creatures::~Creatures()
bool Creatures::Start( uint32_t &numcreatures ) bool Creatures::Start( uint32_t &numcreatures )
{ {
d->p_cre = new DfVector <uint32_t> (d->d->p, d->creatures.vector); d->p_cre = new DfVector <uint32_t> (d->owner, d->creatures.vector);
d->Started = true; d->Started = true;
numcreatures = d->p_cre->size(); numcreatures = d->p_cre->size();
return true; return true;
@ -141,11 +143,12 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
{ {
if(!d->Started) return false; if(!d->Started) return false;
// SHM fast path // SHM fast path
Process * p = d->owner;
if(d->creature_module) if(d->creature_module)
{ {
SHMCREATURESHDR->index = index; SHMCREATURESHDR->index = index;
const uint32_t cmd = Creatures2010::CREATURE_AT_INDEX + (d->creature_module << 16); const uint32_t cmd = Creatures2010::CREATURE_AT_INDEX + (d->creature_module << 16);
g_pProcess->SetAndWait(cmd); p->SetAndWait(cmd);
memcpy(&furball,SHMDATA(t_creature),sizeof(t_creature)); memcpy(&furball,SHMDATA(t_creature),sizeof(t_creature));
return true; return true;
} }
@ -163,38 +166,38 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
d->d->readName(furball.name,temp + offs.name_offset); d->d->readName(furball.name,temp + offs.name_offset);
// basic stuff // basic stuff
g_pProcess->readDWord (temp + offs.happiness_offset, furball.happiness); p->readDWord (temp + offs.happiness_offset, furball.happiness);
g_pProcess->readDWord (temp + offs.id_offset, furball.id); p->readDWord (temp + offs.id_offset, furball.id);
g_pProcess->read (temp + offs.pos_offset, 3 * sizeof (uint16_t), (uint8_t *) & (furball.x)); // xyz really p->read (temp + offs.pos_offset, 3 * sizeof (uint16_t), (uint8_t *) & (furball.x)); // xyz really
g_pProcess->readDWord (temp + offs.race_offset, furball.race); p->readDWord (temp + offs.race_offset, furball.race);
g_pProcess->readByte (temp + offs.sex_offset, furball.sex); p->readByte (temp + offs.sex_offset, furball.sex);
g_pProcess->readDWord (temp + offs.flags1_offset, furball.flags1.whole); p->readDWord (temp + offs.flags1_offset, furball.flags1.whole);
g_pProcess->readDWord (temp + offs.flags2_offset, furball.flags2.whole); p->readDWord (temp + offs.flags2_offset, furball.flags2.whole);
// physical attributes // physical attributes
g_pProcess->read(temp + offs.physical_offset, sizeof(t_attrib) * 6, (uint8_t *)&furball.strength); p->read(temp + offs.physical_offset, sizeof(t_attrib) * 6, (uint8_t *)&furball.strength);
// mood stuff // mood stuff
furball.mood = (int16_t) g_pProcess->readWord (temp + offs.mood_offset); furball.mood = (int16_t) p->readWord (temp + offs.mood_offset);
d->d->readName(furball.artifact_name, temp + offs.artifact_name_offset); d->d->readName(furball.artifact_name, temp + offs.artifact_name_offset);
// custom profession // custom profession
fill_char_buf (furball.custom_profession, g_pProcess->readSTLString (temp + offs.custom_profession_offset)); fill_char_buf (furball.custom_profession, p->readSTLString (temp + offs.custom_profession_offset));
// labors // labors
g_pProcess->read (temp + offs.labors_offset, NUM_CREATURE_LABORS, furball.labors); p->read (temp + offs.labors_offset, NUM_CREATURE_LABORS, furball.labors);
// profession // profession
furball.profession = g_pProcess->readByte (temp + offs.profession_offset); furball.profession = p->readByte (temp + offs.profession_offset);
// current job HACK: the job object isn't cleanly represented here // current job HACK: the job object isn't cleanly represented here
/* /*
uint32_t jobIdAddr = g_pProcess->readDWord (temp + offs.creature_current_job_offset); uint32_t jobIdAddr = p->readDWord (temp + offs.creature_current_job_offset);
if (jobIdAddr) if (jobIdAddr)
{ {
furball.current_job.active = true; furball.current_job.active = true;
furball.current_job.jobId = g_pProcess->readByte (jobIdAddr + offs.creature_current_job_id_offset); furball.current_job.jobId = p->readByte (jobIdAddr + offs.creature_current_job_id_offset);
} }
else else
{ {
@ -203,34 +206,34 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
*/ */
/* /*
g_pProcess->readDWord(temp + offs.creature_pregnancy_offset, furball.pregnancy_timer); p->readDWord(temp + offs.creature_pregnancy_offset, furball.pregnancy_timer);
*/ */
/* /*
// enum soul pointer vector // enum soul pointer vector
DfVector <uint32_t> souls(g_pProcess,temp + offs.creature_soul_vector_offset); DfVector <uint32_t> souls(p,temp + offs.creature_soul_vector_offset);
*/ */
uint32_t soul = g_pProcess->readDWord(temp + offs.default_soul_offset); uint32_t soul = p->readDWord(temp + offs.default_soul_offset);
furball.has_default_soul = false; furball.has_default_soul = false;
if(soul) if(soul)
{ {
furball.has_default_soul = true; furball.has_default_soul = true;
// get first soul's skills // get first soul's skills
DfVector <uint32_t> skills(g_pProcess, soul + offs.soul_skills_vector_offset); DfVector <uint32_t> skills(p, soul + offs.soul_skills_vector_offset);
furball.defaultSoul.numSkills = skills.size(); furball.defaultSoul.numSkills = skills.size();
for (uint32_t i = 0; i < furball.defaultSoul.numSkills;i++) for (uint32_t i = 0; i < furball.defaultSoul.numSkills;i++)
{ {
uint32_t temp2 = skills[i]; uint32_t temp2 = skills[i];
// a byte: this gives us 256 skills maximum. // a byte: this gives us 256 skills maximum.
furball.defaultSoul.skills[i].id = g_pProcess->readByte (temp2); furball.defaultSoul.skills[i].id = p->readByte (temp2);
furball.defaultSoul.skills[i].rating = g_pProcess->readByte (temp2 + 4); furball.defaultSoul.skills[i].rating = p->readByte (temp2 + 4);
furball.defaultSoul.skills[i].experience = g_pProcess->readWord (temp2 + 8); furball.defaultSoul.skills[i].experience = p->readWord (temp2 + 8);
} }
// mental attributes are part of the soul // mental attributes are part of the soul
g_pProcess->read(soul + offs.soul_mental_offset, sizeof(t_attrib) * 13, (uint8_t *)&furball.defaultSoul.analytical_ability); p->read(soul + offs.soul_mental_offset, sizeof(t_attrib) * 13, (uint8_t *)&furball.defaultSoul.analytical_ability);
// traits as well // traits as well
g_pProcess->read(soul + offs.soul_traits_offset, sizeof (uint16_t) * NUM_CREATURE_TRAITS, (uint8_t *) &furball.defaultSoul.traits); p->read(soul + offs.soul_traits_offset, sizeof (uint16_t) * NUM_CREATURE_TRAITS, (uint8_t *) &furball.defaultSoul.traits);
} }
//likes //likes
/* /*
@ -239,7 +242,7 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
for(uint32_t i = 0;i<furball.numLikes;i++) for(uint32_t i = 0;i<furball.numLikes;i++)
{ {
uint32_t temp2 = *(uint32_t *) likes[i]; uint32_t temp2 = *(uint32_t *) likes[i];
g_pProcess->read(temp2,sizeof(t_like),(uint8_t *) &furball.likes[i]); p->read(temp2,sizeof(t_like),(uint8_t *) &furball.likes[i]);
}*/ }*/
return true; return true;
@ -250,7 +253,11 @@ int32_t Creatures::ReadCreatureInBox (int32_t index, t_creature & furball,
const uint16_t x1, const uint16_t y1, const uint16_t z1, const uint16_t x1, const uint16_t y1, const uint16_t z1,
const uint16_t x2, const uint16_t y2, const uint16_t z2) const uint16_t x2, const uint16_t y2, const uint16_t z2)
{ {
if (!d->Started) return -1; if (!d->Started)
return -1;
Process *p = d->owner;
if(d->creature_module) if(d->creature_module)
{ {
// supply the module with offsets so it can work with them // supply the module with offsets so it can work with them
@ -262,7 +269,7 @@ int32_t Creatures::ReadCreatureInBox (int32_t index, t_creature & furball,
SHMCREATURESHDR->y2 = y2; SHMCREATURESHDR->y2 = y2;
SHMCREATURESHDR->z2 = z2; SHMCREATURESHDR->z2 = z2;
const uint32_t cmd = Creatures2010::CREATURE_FIND_IN_BOX + (d->creature_module << 16); const uint32_t cmd = Creatures2010::CREATURE_FIND_IN_BOX + (d->creature_module << 16);
g_pProcess->SetAndWait(cmd); p->SetAndWait(cmd);
if(SHMCREATURESHDR->index != -1) if(SHMCREATURESHDR->index != -1)
memcpy(&furball,SHMDATA(void),sizeof(t_creature)); memcpy(&furball,SHMDATA(void),sizeof(t_creature));
return SHMCREATURESHDR->index; return SHMCREATURESHDR->index;
@ -275,7 +282,7 @@ int32_t Creatures::ReadCreatureInBox (int32_t index, t_creature & furball,
{ {
// read pointer from vector at position // read pointer from vector at position
uint32_t temp = 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); p->read (temp + d->creatures.pos_offset, 3 * sizeof (uint16_t), (uint8_t *) &coords);
if (coords[0] >= x1 && coords[0] < x2) if (coords[0] >= x1 && coords[0] < x2)
{ {
if (coords[1] >= y1 && coords[1] < y2) if (coords[1] >= y1 && coords[1] < y2)
@ -299,25 +306,29 @@ bool Creatures::WriteLabors(const uint32_t index, uint8_t labors[NUM_CREATURE_LA
{ {
if(!d->Started) return false; if(!d->Started) return false;
uint32_t temp = 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); Process * p = d->owner;
p->write(temp + d->creatures.labors_offset, NUM_CREATURE_LABORS, labors);
uint32_t pickup_equip; uint32_t pickup_equip;
g_pProcess->readDWord(temp + d->creatures.pickup_equipment_bit, pickup_equip); p->readDWord(temp + d->creatures.pickup_equipment_bit, pickup_equip);
pickup_equip |= 1u; pickup_equip |= 1u;
g_pProcess->writeDWord(temp + d->creatures.pickup_equipment_bit, pickup_equip); p->writeDWord(temp + d->creatures.pickup_equipment_bit, pickup_equip);
return true; return true;
} }
uint32_t Creatures::GetDwarfRaceIndex() uint32_t Creatures::GetDwarfRaceIndex()
{ {
if(!d->Inited) return 0; if(!d->Inited) return 0;
return g_pProcess->readDWord(d->dwarf_race_index_addr); Process * p = d->owner;
return p->readDWord(d->dwarf_race_index_addr);
} }
/* /*
bool API::getCurrentCursorCreature(uint32_t & creature_index) bool Creatures::getCurrentCursorCreature(uint32_t & creature_index)
{ {
if(!d->cursorWindowInited) return false; if(!d->cursorWindowInited) return false;
creature_index = g_pProcess->readDWord(d->current_cursor_creature_offset); Process * p = d->owner;
creature_index = p->readDWord(d->current_cursor_creature_offset);
return true; return true;
} }
*/ */

@ -40,6 +40,7 @@ struct Gui::Private
uint32_t current_cursor_creature_offset; uint32_t current_cursor_creature_offset;
uint32_t current_menu_state_offset; uint32_t current_menu_state_offset;
APIPrivate *d; APIPrivate *d;
Process * owner;
}; };
Gui::Gui(APIPrivate * _d) Gui::Gui(APIPrivate * _d)
@ -47,6 +48,7 @@ Gui::Gui(APIPrivate * _d)
d = new Private; d = new Private;
d->d = _d; d->d = _d;
d->owner = _d->p;
d->Inited = d->Started = true; d->Inited = d->Started = true;
memory_info * mem = d->d->offset_descriptor; memory_info * mem = d->d->offset_descriptor;
@ -76,29 +78,30 @@ bool Gui::ReadPauseState()
// replace with an exception // replace with an exception
if(!d->Inited) return false; if(!d->Inited) return false;
uint32_t pauseState = g_pProcess->readDWord (d->pause_state_offset); uint32_t pauseState = d->owner->readDWord (d->pause_state_offset);
return pauseState & 1; return pauseState & 1;
} }
uint32_t Gui::ReadMenuState() uint32_t Gui::ReadMenuState()
{ {
if(d->Inited) if(d->Inited)
return(g_pProcess->readDWord(d->current_menu_state_offset)); return(d->owner->readDWord(d->current_menu_state_offset));
return false; return false;
} }
bool Gui::ReadViewScreen (t_viewscreen &screen) bool Gui::ReadViewScreen (t_viewscreen &screen)
{ {
if (!d->Inited) return false; if (!d->Inited) return false;
Process * p = d->owner;
uint32_t last = g_pProcess->readDWord (d->view_screen_offset); uint32_t last = p->readDWord (d->view_screen_offset);
uint32_t screenAddr = g_pProcess->readDWord (last); uint32_t screenAddr = p->readDWord (last);
uint32_t nextScreenPtr = g_pProcess->readDWord (last + 4); uint32_t nextScreenPtr = p->readDWord (last + 4);
while (nextScreenPtr != 0) while (nextScreenPtr != 0)
{ {
last = nextScreenPtr; last = nextScreenPtr;
screenAddr = g_pProcess->readDWord (nextScreenPtr); screenAddr = p->readDWord (nextScreenPtr);
nextScreenPtr = g_pProcess->readDWord (nextScreenPtr + 4); nextScreenPtr = p->readDWord (nextScreenPtr + 4);
} }
return d->d->offset_descriptor->resolveObjectToClassID (last, screen.type); return d->d->offset_descriptor->resolveObjectToClassID (last, screen.type);
} }

@ -51,6 +51,7 @@ struct Maps::Private
Server::Maps::maps_offsets offsets; Server::Maps::maps_offsets offsets;
APIPrivate *d; APIPrivate *d;
Process * owner;
bool Inited; bool Inited;
bool Started; bool Started;
vector<uint16_t> v_geology[eBiomeCount]; vector<uint16_t> v_geology[eBiomeCount];
@ -60,9 +61,10 @@ Maps::Maps(APIPrivate* _d)
{ {
d = new Private; d = new Private;
d->d = _d; d->d = _d;
Process *p = d->owner = _d->p;
d->Inited = d->Started = false; d->Inited = d->Started = false;
DFHack::memory_info * mem = d->d->offset_descriptor; DFHack::memory_info * mem = p->getDescriptor();
Server::Maps::maps_offsets &off = d->offsets; Server::Maps::maps_offsets &off = d->offsets;
// get the offsets once here // get the offsets once here
@ -87,14 +89,14 @@ Maps::Maps(APIPrivate* _d)
// upload offsets to SHM server if possible // upload offsets to SHM server if possible
d->maps_module = 0; d->maps_module = 0;
if(g_pProcess->getModuleIndex("Maps2010",1,d->maps_module)) if(p->getModuleIndex("Maps2010",1,d->maps_module))
{ {
// supply the module with offsets so it can work with them // supply the module with offsets so it can work with them
Server::Maps::maps_offsets *off2 = SHMDATA(Server::Maps::maps_offsets); Server::Maps::maps_offsets *off2 = SHMDATA(Server::Maps::maps_offsets);
memcpy(off2, &(d->offsets), sizeof(Server::Maps::maps_offsets)); memcpy(off2, &(d->offsets), sizeof(Server::Maps::maps_offsets));
full_barrier full_barrier
const uint32_t cmd = Server::Maps::MAP_INIT + (d->maps_module << 16); const uint32_t cmd = Server::Maps::MAP_INIT + (d->maps_module << 16);
g_pProcess->SetAndWait(cmd); p->SetAndWait(cmd);
} }
d->Inited = true; d->Inited = true;
} }
@ -114,9 +116,10 @@ bool Maps::Start()
return false; return false;
if(d->Started) if(d->Started)
Finish(); Finish();
Process *p = d->owner;
Server::Maps::maps_offsets &off = d->offsets; Server::Maps::maps_offsets &off = d->offsets;
// get the map pointer // get the map pointer
uint32_t x_array_loc = g_pProcess->readDWord (off.map_offset); uint32_t x_array_loc = p->readDWord (off.map_offset);
if (!x_array_loc) if (!x_array_loc)
{ {
return false; return false;
@ -124,9 +127,9 @@ bool Maps::Start()
// get the size // get the size
uint32_t mx, my, mz; uint32_t mx, my, mz;
mx = d->x_block_count = g_pProcess->readDWord (off.x_count_offset); mx = d->x_block_count = p->readDWord (off.x_count_offset);
my = d->y_block_count = g_pProcess->readDWord (off.y_count_offset); my = d->y_block_count = p->readDWord (off.y_count_offset);
mz = d->z_block_count = g_pProcess->readDWord (off.z_count_offset); mz = d->z_block_count = p->readDWord (off.z_count_offset);
// test for wrong map dimensions // test for wrong map dimensions
if (mx == 0 || mx > 48 || my == 0 || my > 48 || mz == 0) if (mx == 0 || mx > 48 || my == 0 || my > 48 || mz == 0)
@ -141,14 +144,14 @@ bool Maps::Start()
uint32_t *temp_y = new uint32_t[my]; uint32_t *temp_y = new uint32_t[my];
uint32_t *temp_z = new uint32_t[mz]; uint32_t *temp_z = new uint32_t[mz];
g_pProcess->read (x_array_loc, mx * sizeof (uint32_t), (uint8_t *) temp_x); p->read (x_array_loc, mx * sizeof (uint32_t), (uint8_t *) temp_x);
for (uint32_t x = 0; x < mx; x++) for (uint32_t x = 0; x < mx; x++)
{ {
g_pProcess->read (temp_x[x], my * sizeof (uint32_t), (uint8_t *) temp_y); p->read (temp_x[x], my * sizeof (uint32_t), (uint8_t *) temp_y);
// y -> map column // y -> map column
for (uint32_t y = 0; y < my; y++) for (uint32_t y = 0; y < my; y++)
{ {
g_pProcess->read (temp_y[y], p->read (temp_y[y],
mz * sizeof (uint32_t), mz * sizeof (uint32_t),
(uint8_t *) (d->block + x*my*mz + y*mz)); (uint8_t *) (d->block + x*my*mz + y*mz));
} }
@ -197,13 +200,14 @@ uint32_t Maps::getBlockPtr (uint32_t x, uint32_t y, uint32_t z)
bool Maps::ReadBlock40d(uint32_t x, uint32_t y, uint32_t z, mapblock40d * buffer) bool Maps::ReadBlock40d(uint32_t x, uint32_t y, uint32_t z, mapblock40d * buffer)
{ {
Process *p = d->owner;
if(d->d->shm_start && d->maps_module) // ACCELERATE! if(d->d->shm_start && d->maps_module) // ACCELERATE!
{ {
SHMMAPSHDR->x = x; SHMMAPSHDR->x = x;
SHMMAPSHDR->y = y; SHMMAPSHDR->y = y;
SHMMAPSHDR->z = z; SHMMAPSHDR->z = z;
volatile uint32_t cmd = Server::Maps::MAP_READ_BLOCK_BY_COORDS + (d->maps_module << 16); volatile uint32_t cmd = Server::Maps::MAP_READ_BLOCK_BY_COORDS + (d->maps_module << 16);
if(!g_pProcess->SetAndWait(cmd)) if(!p->SetAndWait(cmd))
return false; return false;
memcpy(buffer,SHMDATA(mapblock40d),sizeof(mapblock40d)); memcpy(buffer,SHMDATA(mapblock40d),sizeof(mapblock40d));
return true; return true;
@ -213,13 +217,13 @@ bool Maps::ReadBlock40d(uint32_t x, uint32_t y, uint32_t z, mapblock40d * buffer
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];
if (addr) if (addr)
{ {
g_pProcess->read (addr + d->offsets.tile_type_offset, sizeof (buffer->tiletypes), (uint8_t *) buffer->tiletypes); p->read (addr + d->offsets.tile_type_offset, sizeof (buffer->tiletypes), (uint8_t *) buffer->tiletypes);
g_pProcess->read (addr + d->offsets.designation_offset, sizeof (buffer->designation), (uint8_t *) buffer->designation); p->read (addr + d->offsets.designation_offset, sizeof (buffer->designation), (uint8_t *) buffer->designation);
g_pProcess->read (addr + d->offsets.occupancy_offset, sizeof (buffer->occupancy), (uint8_t *) buffer->occupancy); p->read (addr + d->offsets.occupancy_offset, sizeof (buffer->occupancy), (uint8_t *) buffer->occupancy);
g_pProcess->read (addr + d->offsets.biome_stuffs, sizeof (biome_indices40d), (uint8_t *) buffer->biome_indices); p->read (addr + d->offsets.biome_stuffs, sizeof (biome_indices40d), (uint8_t *) buffer->biome_indices);
buffer->origin = addr; buffer->origin = addr;
uint32_t addr_of_struct = g_pProcess->readDWord(addr); uint32_t addr_of_struct = p->readDWord(addr);
buffer->blockflags.whole = g_pProcess->readDWord(addr_of_struct); buffer->blockflags.whole = p->readDWord(addr_of_struct);
return true; return true;
} }
return false; return false;
@ -235,7 +239,7 @@ bool Maps::ReadTileTypes (uint32_t x, uint32_t y, uint32_t z, tiletypes40d *buff
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];
if (addr) if (addr)
{ {
g_pProcess->read (addr + d->offsets.tile_type_offset, sizeof (tiletypes40d), (uint8_t *) buffer); d->owner->read (addr + d->offsets.tile_type_offset, sizeof (tiletypes40d), (uint8_t *) buffer);
return true; return true;
} }
return false; return false;
@ -246,7 +250,7 @@ bool Maps::WriteTileTypes (uint32_t x, uint32_t y, uint32_t z, tiletypes40d *buf
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];
if (addr) if (addr)
{ {
g_pProcess->write (addr + d->offsets.tile_type_offset, sizeof (tiletypes40d), (uint8_t *) buffer); d->owner->write (addr + d->offsets.tile_type_offset, sizeof (tiletypes40d), (uint8_t *) buffer);
return true; return true;
} }
return false; return false;
@ -261,8 +265,9 @@ bool Maps::ReadDirtyBit(uint32_t x, uint32_t y, uint32_t z, bool &dirtybit)
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];
if(addr) if(addr)
{ {
uint32_t addr_of_struct = g_pProcess->readDWord(addr); Process * p = d->owner;
dirtybit = g_pProcess->readDWord(addr_of_struct) & 1; uint32_t addr_of_struct = p->readDWord(addr);
dirtybit = p->readDWord(addr_of_struct) & 1;
return true; return true;
} }
return false; return false;
@ -273,11 +278,12 @@ bool Maps::WriteDirtyBit(uint32_t x, uint32_t y, uint32_t z, bool dirtybit)
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];
if (addr) if (addr)
{ {
uint32_t addr_of_struct = g_pProcess->readDWord(addr); Process * p = d->owner;
uint32_t dirtydword = g_pProcess->readDWord(addr_of_struct); uint32_t addr_of_struct = p->readDWord(addr);
uint32_t dirtydword = p->readDWord(addr_of_struct);
dirtydword &= 0xFFFFFFFE; dirtydword &= 0xFFFFFFFE;
dirtydword |= (uint32_t) dirtybit; dirtydword |= (uint32_t) dirtybit;
g_pProcess->writeDWord (addr_of_struct, dirtydword); p->writeDWord (addr_of_struct, dirtydword);
return true; return true;
} }
return false; return false;
@ -289,8 +295,9 @@ bool Maps::ReadBlockFlags(uint32_t x, uint32_t y, uint32_t z, t_blockflags &bloc
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];
if(addr) if(addr)
{ {
uint32_t addr_of_struct = g_pProcess->readDWord(addr); Process * p = d->owner;
blockflags.whole = g_pProcess->readDWord(addr_of_struct); uint32_t addr_of_struct = p->readDWord(addr);
blockflags.whole = p->readDWord(addr_of_struct);
return true; return true;
} }
return false; return false;
@ -300,8 +307,9 @@ bool Maps::WriteBlockFlags(uint32_t x, uint32_t y, uint32_t z, t_blockflags bloc
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];
if (addr) if (addr)
{ {
uint32_t addr_of_struct = g_pProcess->readDWord(addr); Process * p = d->owner;
g_pProcess->writeDWord (addr_of_struct, blockflags.whole); uint32_t addr_of_struct = p->readDWord(addr);
p->writeDWord (addr_of_struct, blockflags.whole);
return true; return true;
} }
return false; return false;
@ -316,7 +324,7 @@ bool Maps::ReadDesignations (uint32_t x, uint32_t y, uint32_t z, designations40d
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];
if (addr) if (addr)
{ {
g_pProcess->read (addr + d->offsets.designation_offset, sizeof (designations40d), (uint8_t *) buffer); d->owner->read (addr + d->offsets.designation_offset, sizeof (designations40d), (uint8_t *) buffer);
return true; return true;
} }
return false; return false;
@ -327,7 +335,7 @@ bool Maps::WriteDesignations (uint32_t x, uint32_t y, uint32_t z, designations40
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];
if (addr) if (addr)
{ {
g_pProcess->write (addr + d->offsets.designation_offset, sizeof (designations40d), (uint8_t *) buffer); d->owner->write (addr + d->offsets.designation_offset, sizeof (designations40d), (uint8_t *) buffer);
return true; return true;
} }
return false; return false;
@ -342,7 +350,7 @@ bool Maps::ReadOccupancy (uint32_t x, uint32_t y, uint32_t z, occupancies40d *bu
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];
if (addr) if (addr)
{ {
g_pProcess->read (addr + d->offsets.occupancy_offset, sizeof (occupancies40d), (uint8_t *) buffer); d->owner->read (addr + d->offsets.occupancy_offset, sizeof (occupancies40d), (uint8_t *) buffer);
return true; return true;
} }
return false; return false;
@ -353,7 +361,7 @@ bool Maps::WriteOccupancy (uint32_t x, uint32_t y, uint32_t z, occupancies40d *b
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];
if (addr) if (addr)
{ {
g_pProcess->write (addr + d->offsets.occupancy_offset, sizeof (tiletypes40d), (uint8_t *) buffer); d->owner->write (addr + d->offsets.occupancy_offset, sizeof (tiletypes40d), (uint8_t *) buffer);
return true; return true;
} }
return false; return false;
@ -368,9 +376,9 @@ bool Maps::ReadTemperatures(uint32_t x, uint32_t y, uint32_t z, t_temperatures *
if (addr) if (addr)
{ {
if(temp1) if(temp1)
g_pProcess->read (addr + d->offsets.temperature1_offset, sizeof (t_temperatures), (uint8_t *) temp1); d->owner->read (addr + d->offsets.temperature1_offset, sizeof (t_temperatures), (uint8_t *) temp1);
if(temp2) if(temp2)
g_pProcess->read (addr + d->offsets.temperature2_offset, sizeof (t_temperatures), (uint8_t *) temp2); d->owner->read (addr + d->offsets.temperature2_offset, sizeof (t_temperatures), (uint8_t *) temp2);
return true; return true;
} }
return false; return false;
@ -381,9 +389,9 @@ bool Maps::WriteTemperatures (uint32_t x, uint32_t y, uint32_t z, t_temperatures
if (addr) if (addr)
{ {
if(temp1) if(temp1)
g_pProcess->write (addr + d->offsets.temperature1_offset, sizeof (t_temperatures), (uint8_t *) temp1); d->owner->write (addr + d->offsets.temperature1_offset, sizeof (t_temperatures), (uint8_t *) temp1);
if(temp2) if(temp2)
g_pProcess->write (addr + d->offsets.temperature2_offset, sizeof (t_temperatures), (uint8_t *) temp2); d->owner->write (addr + d->offsets.temperature2_offset, sizeof (t_temperatures), (uint8_t *) temp2);
return true; return true;
} }
return false; return false;
@ -397,7 +405,7 @@ bool Maps::ReadRegionOffsets (uint32_t x, uint32_t y, uint32_t z, biome_indices4
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];
if (addr) if (addr)
{ {
g_pProcess->read (addr + d->offsets.biome_stuffs, sizeof (biome_indices40d), (uint8_t *) buffer); d->owner->read (addr + d->offsets.biome_stuffs, sizeof (biome_indices40d), (uint8_t *) buffer);
return true; return true;
} }
return false; return false;
@ -411,6 +419,7 @@ bool Maps::ReadVeins(uint32_t x, uint32_t y, uint32_t z, vector <t_vein>* veins,
t_vein v; t_vein v;
t_frozenliquidvein fv; t_frozenliquidvein fv;
t_spattervein sv; t_spattervein sv;
Process* p = d->owner;
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];
if(veins) veins->clear(); if(veins) veins->clear();
@ -422,19 +431,19 @@ 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 // 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*/ /*pointer is 4 bytes! we work with a 32bit program here, no matter what architecture we compile khazad for*/
DfVector <uint32_t> p_veins (d->d->p, addr + off.veinvector); DfVector <uint32_t> p_veins (p, addr + off.veinvector);
uint32_t size = p_veins.size(); uint32_t size = p_veins.size();
// read all veins // read all veins
for (uint32_t i = 0; i < size;i++) for (uint32_t i = 0; i < size;i++)
{ {
// read the vein pointer from the vector // read the vein pointer from the vector
uint32_t temp = p_veins[i]; uint32_t temp = p_veins[i];
uint32_t type = g_pProcess->readDWord(temp); uint32_t type = p->readDWord(temp);
try_again: try_again:
if(veins && type == off.vein_mineral_vptr) if(veins && type == off.vein_mineral_vptr)
{ {
// read the vein data (dereference pointer) // read the vein data (dereference pointer)
g_pProcess->read (temp, sizeof(t_vein), (uint8_t *) &v); p->read (temp, sizeof(t_vein), (uint8_t *) &v);
v.address_of = temp; v.address_of = temp;
// store it in the vector // store it in the vector
veins->push_back (v); veins->push_back (v);
@ -442,7 +451,7 @@ try_again:
else if(ices && type == off.vein_ice_vptr) else if(ices && type == off.vein_ice_vptr)
{ {
// read the ice vein data (dereference pointer) // read the ice vein data (dereference pointer)
g_pProcess->read (temp, sizeof(t_frozenliquidvein), (uint8_t *) &fv); p->read (temp, sizeof(t_frozenliquidvein), (uint8_t *) &fv);
fv.address_of = temp; fv.address_of = temp;
// store it in the vector // store it in the vector
ices->push_back (fv); ices->push_back (fv);
@ -450,14 +459,14 @@ try_again:
else if(splatter && type == off.vein_spatter_vptr) else if(splatter && type == off.vein_spatter_vptr)
{ {
// read the splatter vein data (dereference pointer) // read the splatter vein data (dereference pointer)
g_pProcess->read (temp, sizeof(t_spattervein), (uint8_t *) &sv); p->read (temp, sizeof(t_spattervein), (uint8_t *) &sv);
sv.address_of = temp; sv.address_of = temp;
// store it in the vector // store it in the vector
splatter->push_back (sv); splatter->push_back (sv);
} }
else else
{ {
string cname = g_pProcess->readClassName(type); string cname = p->readClassName(type);
if(ices && cname == "block_square_event_frozen_liquidst") if(ices && cname == "block_square_event_frozen_liquidst")
{ {
off.vein_ice_vptr = type; off.vein_ice_vptr = type;
@ -548,6 +557,7 @@ __int16 __userpurge GetGeologicalRegion<ax>(__int16 block_X<cx>, int X<ebx>, __i
bool Maps::ReadGeology (vector < vector <uint16_t> >& assign) bool Maps::ReadGeology (vector < vector <uint16_t> >& assign)
{ {
memory_info * minfo = d->d->offset_descriptor; memory_info * minfo = d->d->offset_descriptor;
Process *p = d->owner;
// get needed addresses and offsets. Now this is what I call crazy. // get needed addresses and offsets. Now this is what I call crazy.
int region_x_offset = minfo->getAddress ("region_x"); int region_x_offset = minfo->getAddress ("region_x");
int region_y_offset = minfo->getAddress ("region_y"); int region_y_offset = minfo->getAddress ("region_y");
@ -566,16 +576,16 @@ bool Maps::ReadGeology (vector < vector <uint16_t> >& assign)
uint16_t worldSizeX, worldSizeY; uint16_t worldSizeX, worldSizeY;
// read position of the region inside DF world // read position of the region inside DF world
g_pProcess->readDWord (region_x_offset, regionX); p->readDWord (region_x_offset, regionX);
g_pProcess->readDWord (region_y_offset, regionY); p->readDWord (region_y_offset, regionY);
g_pProcess->readDWord (region_z_offset, regionZ); p->readDWord (region_z_offset, regionZ);
// get world size // get world size
g_pProcess->readWord (world_size_x, worldSizeX); p->readWord (world_size_x, worldSizeX);
g_pProcess->readWord (world_size_y, worldSizeY); p->readWord (world_size_y, worldSizeY);
// get pointer to first part of 2d array of regions // get pointer to first part of 2d array of regions
uint32_t regions = g_pProcess->readDWord (world_regions); uint32_t regions = p->readDWord (world_regions);
// read the geoblock vector // read the geoblock vector
DfVector <uint32_t> geoblocks (d->d->p, world_geoblocks_vector); DfVector <uint32_t> geoblocks (d->d->p, world_geoblocks_vector);
@ -595,11 +605,11 @@ bool Maps::ReadGeology (vector < vector <uint16_t> >& assign)
/// regions are of region_size size /// regions are of region_size size
// get pointer to column of regions // get pointer to column of regions
uint32_t geoX; uint32_t geoX;
g_pProcess->readDWord (regions + bioRX*4, geoX); p->readDWord (regions + bioRX*4, geoX);
// get index into geoblock vector // get index into geoblock vector
uint16_t geoindex; uint16_t geoindex;
g_pProcess->readWord (geoX + bioRY*region_size + region_geo_index_offset, geoindex); p->readWord (geoX + bioRY*region_size + region_geo_index_offset, geoindex);
/// geology blocks are assigned to regions from a vector /// geology blocks are assigned to regions from a vector
// get the geoblock from the geoblock vector using the geoindex // get the geoblock from the geoblock vector using the geoindex
@ -608,7 +618,7 @@ bool Maps::ReadGeology (vector < vector <uint16_t> >& assign)
/// geology blocks have a vector of layer descriptors /// geology blocks have a vector of layer descriptors
// get the vector with pointer to layers // get the vector with pointer to layers
DfVector <uint32_t> geolayers (d->d->p, geoblock_off + geolayer_geoblock_offset); // let's hope DfVector <uint32_t> geolayers (p, geoblock_off + geolayer_geoblock_offset); // let's hope
// make sure we don't load crap // make sure we don't load crap
assert (geolayers.size() > 0 && geolayers.size() <= 16); assert (geolayers.size() > 0 && geolayers.size() <= 16);
@ -620,7 +630,7 @@ bool Maps::ReadGeology (vector < vector <uint16_t> >& assign)
// read pointer to a layer // read pointer to a layer
uint32_t geol_offset = geolayers[j]; uint32_t geol_offset = geolayers[j];
// read word at pointer + 2, store in our geology vectors // read word at pointer + 2, store in our geology vectors
d->v_geology[i].push_back (g_pProcess->readWord (geol_offset + type_inside_geolayer)); d->v_geology[i].push_back (p->readWord (geol_offset + type_inside_geolayer));
} }
} }
assign.clear(); assign.clear();

@ -31,9 +31,21 @@ distribution.
using namespace DFHack; using namespace DFHack;
class Materials::Private
{
public:
APIPrivate *d;
Process * owner;
/*
bool Inited;
bool Started;
*/
};
Materials::Materials(APIPrivate * d_) Materials::Materials(APIPrivate * d_)
{ {
d = d_; d->d = d_;
d->owner = d_->p;
} }
Materials::~Materials(){} Materials::~Materials(){}
/* /*
@ -131,12 +143,13 @@ LABEL_53:
/* /*
bool API::ReadInorganicMaterials (vector<t_matgloss> & inorganic) bool API::ReadInorganicMaterials (vector<t_matgloss> & inorganic)
{ {
memory_info * minfo = d->offset_descriptor; Process *p = d->owner;
memory_info * minfo = p->getDescriptor();
int matgloss_address = minfo->getAddress ("mat_inorganics"); int matgloss_address = minfo->getAddress ("mat_inorganics");
int matgloss_colors = minfo->getOffset ("material_color"); int matgloss_colors = minfo->getOffset ("material_color");
int matgloss_stone_name_offset = minfo->getOffset("matgloss_stone_name"); int matgloss_stone_name_offset = minfo->getOffset("matgloss_stone_name");
DfVector <uint32_t> p_matgloss (d->p, matgloss_address); DfVector <uint32_t> p_matgloss (p, matgloss_address);
uint32_t size = p_matgloss.getSize(); uint32_t size = p_matgloss.getSize();
inorganic.resize (0); inorganic.resize (0);
@ -149,12 +162,12 @@ bool API::ReadInorganicMaterials (vector<t_matgloss> & inorganic)
t_matgloss mat; t_matgloss mat;
//cout << temp << endl; //cout << temp << endl;
//fill_char_buf(mat.id, d->p->readSTLString(temp)); // reads a C string given an address //fill_char_buf(mat.id, d->p->readSTLString(temp)); // reads a C string given an address
d->p->readSTLString (temp, mat.id, 128); p->readSTLString (temp, mat.id, 128);
d->p->readSTLString (temp+matgloss_stone_name_offset, mat.name, 128); p->readSTLString (temp+matgloss_stone_name_offset, mat.name, 128);
mat.fore = (uint8_t) g_pProcess->readWord (temp + matgloss_colors); mat.fore = (uint8_t) p->readWord (temp + matgloss_colors);
mat.back = (uint8_t) g_pProcess->readWord (temp + matgloss_colors + 2); mat.back = (uint8_t) p->readWord (temp + matgloss_colors + 2);
mat.bright = (uint8_t) g_pProcess->readWord (temp + matgloss_colors + 4); mat.bright = (uint8_t) p->readWord (temp + matgloss_colors + 4);
inorganic.push_back (mat); inorganic.push_back (mat);
} }
@ -182,42 +195,37 @@ inline bool ReadNamesOnly(Process* p, uint32_t address, vector<t_matgloss> & nam
bool Materials::ReadInorganicMaterials (vector<t_matgloss> & inorganic) bool Materials::ReadInorganicMaterials (vector<t_matgloss> & inorganic)
{ {
return ReadNamesOnly(d->p, d->offset_descriptor->getAddress ("mat_inorganics"), inorganic ); return ReadNamesOnly(d->owner, d->owner->getDescriptor()->getAddress ("mat_inorganics"), inorganic );
} }
bool Materials::ReadOrganicMaterials (vector<t_matgloss> & organic) bool Materials::ReadOrganicMaterials (vector<t_matgloss> & organic)
{ {
return ReadNamesOnly(d->p, d->offset_descriptor->getAddress ("mat_organics_all"), organic ); return ReadNamesOnly(d->owner, d->owner->getDescriptor()->getAddress ("mat_organics_all"), organic );
} }
bool Materials::ReadWoodMaterials (vector<t_matgloss> & trees) bool Materials::ReadWoodMaterials (vector<t_matgloss> & trees)
{ {
return ReadNamesOnly(d->p, d->offset_descriptor->getAddress ("mat_organics_trees"), trees ); return ReadNamesOnly(d->owner, d->owner->getDescriptor()->getAddress ("mat_organics_trees"), trees );
} }
bool Materials::ReadPlantMaterials (vector<t_matgloss> & plants) bool Materials::ReadPlantMaterials (vector<t_matgloss> & plants)
{ {
return ReadNamesOnly(d->p, d->offset_descriptor->getAddress ("mat_organics_plants"), plants ); return ReadNamesOnly(d->owner, d->owner->getDescriptor()->getAddress ("mat_organics_plants"), plants );
} }
/*
Gives bad results combined with the creature race field!
bool Materials::ReadCreatureTypes (vector<t_matgloss> & creatures)
{
return ReadNamesOnly(d->p, d->offset_descriptor->getAddress ("mat_creature_types"), creatures );
return true;
}
*/
bool Materials::ReadCreatureTypes (vector<t_matgloss> & creatures) bool Materials::ReadCreatureTypes (vector<t_matgloss> & creatures)
{ {
return ReadNamesOnly(d->p, d->offset_descriptor->getAddress ("creature_type_vector"), creatures ); return ReadNamesOnly(d->owner, d->owner->getDescriptor()->getAddress ("creature_type_vector"), creatures );
return true; return true;
} }
bool Materials::ReadCreatureTypesEx (vector<t_creaturetype> & creatures) bool Materials::ReadCreatureTypesEx (vector<t_creaturetype> & creatures)
{ {
DfVector <uint32_t> p_races (g_pProcess, d->offset_descriptor->getAddress ("creature_type_vector")); Process *p = d->owner;
uint32_t castes_vector_offset = d->offset_descriptor->getOffset ("creature_type_caste_vector"); memory_info *mem = d->owner->getDescriptor();
uint32_t sizeof_string = d->offset_descriptor->getHexValue ("sizeof_string"); DfVector <uint32_t> p_races (p, mem->getAddress ("creature_type_vector"));
uint32_t castes_vector_offset = mem->getOffset ("creature_type_caste_vector");
uint32_t sizeof_string = mem->getHexValue ("sizeof_string");
uint32_t size = p_races.size(); uint32_t size = p_races.size();
uint32_t sizecas = 0; uint32_t sizecas = 0;
creatures.clear(); creatures.clear();
@ -225,17 +233,17 @@ bool Materials::ReadCreatureTypesEx (vector<t_creaturetype> & creatures)
for (uint32_t i = 0; i < size;i++) for (uint32_t i = 0; i < size;i++)
{ {
t_creaturetype mat; t_creaturetype mat;
g_pProcess->readSTLString (p_races[i], mat.rawname, sizeof(mat.rawname)); p->readSTLString (p_races[i], mat.rawname, sizeof(mat.rawname));
DfVector <uint32_t> p_castes(g_pProcess,p_races[i] + castes_vector_offset); DfVector <uint32_t> p_castes(p, p_races[i] + castes_vector_offset);
sizecas = p_castes.size(); sizecas = p_castes.size();
for (uint32_t j = 0; j < sizecas;j++) for (uint32_t j = 0; j < sizecas;j++)
{ {
t_creaturecaste caste; t_creaturecaste caste;
uint32_t caste_start = p_castes[j]; uint32_t caste_start = p_castes[j];
g_pProcess->readSTLString (caste_start, caste.rawname, sizeof(caste.rawname)); p->readSTLString (caste_start, caste.rawname, sizeof(caste.rawname));
g_pProcess->readSTLString (caste_start + sizeof_string, caste.singular, sizeof(caste.singular)); p->readSTLString (caste_start + sizeof_string, caste.singular, sizeof(caste.singular));
g_pProcess->readSTLString (caste_start + 2 * sizeof_string, caste.plural, sizeof(caste.plural)); p->readSTLString (caste_start + 2 * sizeof_string, caste.plural, sizeof(caste.plural));
g_pProcess->readSTLString (caste_start + 3 * sizeof_string, caste.adjective, sizeof(caste.adjective)); p->readSTLString (caste_start + 3 * sizeof_string, caste.adjective, sizeof(caste.adjective));
mat.castes.push_back(caste); mat.castes.push_back(caste);
} }
creatures.push_back(mat); creatures.push_back(mat);

@ -46,6 +46,7 @@ struct Position::Private
uint32_t hotkey_size; uint32_t hotkey_size;
APIPrivate *d; APIPrivate *d;
Process * owner;
bool Inited; bool Inited;
bool Started; bool Started;
bool StartedHotkeys; bool StartedHotkeys;
@ -57,6 +58,7 @@ Position::Position(APIPrivate * d_)
{ {
d = new Private; d = new Private;
d->d = d_; d->d = d_;
d->owner = d_->p;
d->Inited = true; d->Inited = true;
d->StartedHotkeys = d->Started = false; d->StartedHotkeys = d->Started = false;
memory_info * mem; memory_info * mem;
@ -88,11 +90,13 @@ bool Position::ReadHotkeys(t_hotkey hotkeys[])
{ {
if (!d->StartedHotkeys) return false; if (!d->StartedHotkeys) return false;
uint32_t currHotkey = d->hotkey_start; uint32_t currHotkey = d->hotkey_start;
Process * p = d->owner;
for(uint32_t i = 0 ; i < NUM_HOTKEYS ;i++) for(uint32_t i = 0 ; i < NUM_HOTKEYS ;i++)
{ {
g_pProcess->readSTLString(currHotkey,hotkeys[i].name,10); p->readSTLString(currHotkey,hotkeys[i].name,10);
hotkeys[i].mode = g_pProcess->readWord(currHotkey+d->hotkey_mode_offset); hotkeys[i].mode = p->readWord(currHotkey+d->hotkey_mode_offset);
g_pProcess->read (currHotkey + d->hotkey_xyz_offset, 3*sizeof (int32_t), (uint8_t *) &hotkeys[i].x); p->read (currHotkey + d->hotkey_xyz_offset, 3*sizeof (int32_t), (uint8_t *) &hotkeys[i].x);
currHotkey+=d->hotkey_size; currHotkey+=d->hotkey_size;
} }
return true; return true;
@ -101,9 +105,11 @@ bool Position::ReadHotkeys(t_hotkey hotkeys[])
bool Position::getViewCoords (int32_t &x, int32_t &y, int32_t &z) bool Position::getViewCoords (int32_t &x, int32_t &y, int32_t &z)
{ {
if (!d->Inited) return false; if (!d->Inited) return false;
g_pProcess->readDWord (d->window_x_offset, (uint32_t &) x); Process * p = d->owner;
g_pProcess->readDWord (d->window_y_offset, (uint32_t &) y);
g_pProcess->readDWord (d->window_z_offset, (uint32_t &) z); p->readDWord (d->window_x_offset, (uint32_t &) x);
p->readDWord (d->window_y_offset, (uint32_t &) y);
p->readDWord (d->window_z_offset, (uint32_t &) z);
return true; return true;
} }
@ -111,9 +117,11 @@ bool Position::getViewCoords (int32_t &x, int32_t &y, int32_t &z)
bool Position::setViewCoords (const int32_t x, const int32_t y, const int32_t z) bool Position::setViewCoords (const int32_t x, const int32_t y, const int32_t z)
{ {
if (!d->Inited) return false; if (!d->Inited) return false;
g_pProcess->writeDWord (d->window_x_offset, (uint32_t) x); Process * p = d->owner;
g_pProcess->writeDWord (d->window_y_offset, (uint32_t) y);
g_pProcess->writeDWord (d->window_z_offset, (uint32_t) z); p->writeDWord (d->window_x_offset, (uint32_t) x);
p->writeDWord (d->window_y_offset, (uint32_t) y);
p->writeDWord (d->window_z_offset, (uint32_t) z);
return true; return true;
} }
@ -121,7 +129,7 @@ bool Position::getCursorCoords (int32_t &x, int32_t &y, int32_t &z)
{ {
if(!d->Inited) return false; if(!d->Inited) return false;
int32_t coords[3]; int32_t coords[3];
g_pProcess->read (d->cursor_xyz_offset, 3*sizeof (int32_t), (uint8_t *) coords); d->owner->read (d->cursor_xyz_offset, 3*sizeof (int32_t), (uint8_t *) coords);
x = coords[0]; x = coords[0];
y = coords[1]; y = coords[1];
z = coords[2]; z = coords[2];
@ -134,7 +142,7 @@ bool Position::setCursorCoords (const int32_t x, const int32_t y, const int32_t
{ {
if (!d->Inited) return false; if (!d->Inited) return false;
int32_t coords[3] = {x, y, z}; int32_t coords[3] = {x, y, z};
g_pProcess->write (d->cursor_xyz_offset, 3*sizeof (int32_t), (uint8_t *) coords); d->owner->write (d->cursor_xyz_offset, 3*sizeof (int32_t), (uint8_t *) coords);
return true; return true;
} }
@ -143,7 +151,7 @@ bool Position::getWindowSize (int32_t &width, int32_t &height)
if(!d->Inited) return false; if(!d->Inited) return false;
int32_t coords[2]; int32_t coords[2];
g_pProcess->read (d->window_dims_offset, 2*sizeof (int32_t), (uint8_t *) coords); d->owner->read (d->window_dims_offset, 2*sizeof (int32_t), (uint8_t *) coords);
width = coords[0]; width = coords[0];
height = coords[1]; height = coords[1];
return true; return true;

@ -41,6 +41,7 @@ struct Vegetation::Private
DfVector <uint32_t> * p_veg; DfVector <uint32_t> * p_veg;
APIPrivate *d; APIPrivate *d;
Process * owner;
bool Inited; bool Inited;
bool Started; bool Started;
}; };
@ -48,6 +49,7 @@ struct Vegetation::Private
Vegetation::Vegetation(APIPrivate * d_) Vegetation::Vegetation(APIPrivate * d_)
{ {
d = new Private; d = new Private;
d->owner = d_->p;
d->d = d_; d->d = d_;
d->Inited = d->Started = false; d->Inited = d->Started = false;
memory_info * mem = d->d->offset_descriptor; memory_info * mem = d->d->offset_descriptor;
@ -65,7 +67,7 @@ Vegetation::~Vegetation()
bool Vegetation::Start(uint32_t & numplants) bool Vegetation::Start(uint32_t & numplants)
{ {
d->p_veg = new DfVector <uint32_t> (g_pProcess, d->vegetation_vector); d->p_veg = new DfVector <uint32_t> (d->owner, d->vegetation_vector);
numplants = d->p_veg->size(); numplants = d->p_veg->size();
d->Started = true; d->Started = true;
return true; return true;
@ -79,7 +81,7 @@ bool Vegetation::Read (const uint32_t index, t_tree & shrubbery)
// read pointer from vector at position // read pointer from vector at position
uint32_t temp = d->p_veg->at (index); uint32_t temp = d->p_veg->at (index);
// read from memory // read from memory
g_pProcess->read (temp + d->tree_desc_offset, sizeof (t_tree), (uint8_t *) &shrubbery); d->owner->read (temp + d->tree_desc_offset, sizeof (t_tree), (uint8_t *) &shrubbery);
shrubbery.address = temp; shrubbery.address = temp;
return true; return true;
} }