Remove DfVector, break MSVC builds until further notice.

develop
Petr Mrázek 2012-01-04 01:45:11 +01:00
parent 5b528694b7
commit 86464b99cc
34 changed files with 281 additions and 393 deletions

@ -39,7 +39,6 @@ include/SDL_keyboard.h
include/SDL_keysym.h include/SDL_keysym.h
include/TileTypes.h include/TileTypes.h
include/Types.h include/Types.h
include/Vector.h
include/VersionInfo.h include/VersionInfo.h
include/VersionInfoFactory.h include/VersionInfoFactory.h
include/Virtual.h include/Virtual.h

@ -154,9 +154,9 @@ void virtual_identity::Init(Core *core)
// Read pre-filled vtable ptrs // Read pre-filled vtable ptrs
OffsetGroup *ptr_table = core->vinfo->getGroup("vtable"); OffsetGroup *ptr_table = core->vinfo->getGroup("vtable");
for (virtual_identity *p = list; p; p = p->next) { for (virtual_identity *p = list; p; p = p->next) {
uint32_t tmp; void * tmp;
if (ptr_table->getSafeAddress(p->getName(),tmp)) if (ptr_table->getSafeAddress(p->getName(),tmp))
p->vtable_ptr = (void*)tmp; p->vtable_ptr = tmp;
} }
} }
@ -169,7 +169,7 @@ DF_KNOWN_GLOBALS
void DFHack::InitDataDefGlobals(Core *core) { void DFHack::InitDataDefGlobals(Core *core) {
OffsetGroup *global_table = core->vinfo->getGroup("global"); OffsetGroup *global_table = core->vinfo->getGroup("global");
uint32_t tmp; void * tmp;
#define SIMPLE_GLOBAL(name,tname) \ #define SIMPLE_GLOBAL(name,tname) \
if (global_table->getSafeAddress(#name,tmp)) df::global::name = (tname*)tmp; if (global_table->getSafeAddress(#name,tmp)) df::global::name = (tname*)tmp;

@ -111,8 +111,8 @@ Process::~Process()
string Process::doReadClassName (void * vptr) string Process::doReadClassName (void * vptr)
{ {
//FIXME: BAD!!!!! //FIXME: BAD!!!!!
int typeinfo = Process::readDWord((uint32_t)vptr - 0x4); void * typeinfo = Process::readPtr(vptr - 0x4);
int typestring = Process::readDWord(typeinfo + 0x4); void * typestring = Process::readPtr(typeinfo + 0x4);
string raw = readCString(typestring); string raw = readCString(typestring);
size_t start = raw.find_first_of("abcdefghijklmnopqrstuvwxyz");// trim numbers size_t start = raw.find_first_of("abcdefghijklmnopqrstuvwxyz");// trim numbers
size_t end = raw.length(); size_t end = raw.length();
@ -138,8 +138,8 @@ void Process::getMemRanges( vector<t_memrange> & ranges )
(char*)&permissions, (char*)&permissions,
&offset, &device1, &device2, &node, &offset, &device1, &device2, &node,
(char*)&temp.name); (char*)&temp.name);
temp.start = start; temp.start = (void *) start;
temp.end = end; temp.end = (void *) end;
temp.read = permissions[0] == 'r'; temp.read = permissions[0] == 'r';
temp.write = permissions[1] == 'w'; temp.write = permissions[1] == 'w';
temp.execute = permissions[2] == 'x'; temp.execute = permissions[2] == 'x';
@ -214,7 +214,7 @@ bool Process::setPermisions(const t_memrange & range,const t_memrange &trgrange)
if(trgrange.read)protect|=PROT_READ; if(trgrange.read)protect|=PROT_READ;
if(trgrange.write)protect|=PROT_WRITE; if(trgrange.write)protect|=PROT_WRITE;
if(trgrange.execute)protect|=PROT_EXEC; if(trgrange.execute)protect|=PROT_EXEC;
result=mprotect((void *)range.start, range.end-range.start,protect); result=mprotect((void *)range.start, (size_t)range.end-(size_t)range.start,protect);
return result==0; return result==0;
} }

@ -158,6 +158,8 @@ namespace DFHack
{ {
typedef pair <INVAL_TYPE, uint32_t> nullableUint32; typedef pair <INVAL_TYPE, uint32_t> nullableUint32;
typedef map <string, nullableUint32 >::iterator uint32_Iter; typedef map <string, nullableUint32 >::iterator uint32_Iter;
typedef pair <INVAL_TYPE, void *> nullableVoidPtr;
typedef map <string, nullableVoidPtr >::iterator voidptr_Iter;
typedef pair <INVAL_TYPE, int32_t> nullableInt32; typedef pair <INVAL_TYPE, int32_t> nullableInt32;
typedef map <string, nullableInt32 >::iterator int32_Iter; typedef map <string, nullableInt32 >::iterator int32_Iter;
typedef pair <INVAL_TYPE, string> nullableString; typedef pair <INVAL_TYPE, string> nullableString;
@ -166,7 +168,7 @@ namespace DFHack
class OffsetGroupPrivate class OffsetGroupPrivate
{ {
public: public:
map <string, nullableUint32 > addresses; map <string, nullableVoidPtr > addresses;
map <string, nullableUint32 > hexvals; map <string, nullableUint32 > hexvals;
map <string, nullableInt32 > offsets; map <string, nullableInt32 > offsets;
map <string, nullableString > strings; map <string, nullableString > strings;
@ -183,7 +185,7 @@ void OffsetGroup::createOffset(const string & key)
void OffsetGroup::createAddress(const string & key) void OffsetGroup::createAddress(const string & key)
{ {
OGd->addresses[key] = nullableUint32(NOT_SET, 0); OGd->addresses[key] = nullableVoidPtr(NOT_SET, 0);
} }
void OffsetGroup::createHexValue(const string & key) void OffsetGroup::createHexValue(const string & key)
@ -227,10 +229,10 @@ void OffsetGroup::setOffsetValidity (const string & key, const INVAL_TYPE inval)
void OffsetGroup::setAddress (const string & key, const string & value, const INVAL_TYPE inval) void OffsetGroup::setAddress (const string & key, const string & value, const INVAL_TYPE inval)
{ {
uint32_Iter it = OGd->addresses.find(key); voidptr_Iter it = OGd->addresses.find(key);
if(it != OGd->addresses.end()) if(it != OGd->addresses.end())
{ {
uint32_t address = strtol(value.c_str(), NULL, 16); void * address = (void *) strtol(value.c_str(), NULL, 16);
if((*it).second.second == address) if((*it).second.second == address)
std::cout << "Pointless address setting: " << this->getFullName() + key << endl; std::cout << "Pointless address setting: " << this->getFullName() + key << endl;
(*it).second.second = address; (*it).second.second = address;
@ -244,7 +246,7 @@ void OffsetGroup::setAddressValidity (const string & key, const INVAL_TYPE inval
{ {
if(inval != NOT_SET) if(inval != NOT_SET)
{ {
uint32_Iter it = OGd->addresses.find(key); voidptr_Iter it = OGd->addresses.find(key);
if(it != OGd->addresses.end()) if(it != OGd->addresses.end())
{ {
(*it).second.first = inval; (*it).second.first = inval;
@ -305,9 +307,9 @@ void OffsetGroup::setStringValidity (const string & key, const INVAL_TYPE inval)
} }
// Get named address // Get named address
uint32_t OffsetGroup::getAddress (const string & key) void * OffsetGroup::getAddress (const string & key)
{ {
uint32_Iter iter = OGd->addresses.find(key); voidptr_Iter iter = OGd->addresses.find(key);
if(iter != OGd->addresses.end()) if(iter != OGd->addresses.end())
{ {
@ -321,9 +323,9 @@ uint32_t OffsetGroup::getAddress (const string & key)
} }
// Get named offset, return bool instead of throwing exceptions // Get named offset, return bool instead of throwing exceptions
bool OffsetGroup::getSafeAddress (const string & key, uint32_t & out) bool OffsetGroup::getSafeAddress (const string & key, void * & out)
{ {
uint32_Iter iter = OGd->addresses.find(key); voidptr_Iter iter = OGd->addresses.find(key);
if(iter != OGd->addresses.end() && (*iter).second.first == IS_VALID) if(iter != OGd->addresses.end() && (*iter).second.first == IS_VALID)
{ {
out = (*iter).second.second; out = (*iter).second.second;
@ -410,7 +412,7 @@ OffsetGroup * OffsetGroup::createGroup(const std::string &name)
void OffsetGroup::RebaseAddresses(int32_t offset) void OffsetGroup::RebaseAddresses(int32_t offset)
{ {
for(uint32_Iter iter = OGd->addresses.begin(); iter != OGd->addresses.end(); iter++) for(voidptr_Iter iter = OGd->addresses.begin(); iter != OGd->addresses.end(); iter++)
{ {
if(iter->second.first) if(iter->second.first)
OGd->addresses[iter->first].second = iter->second.second + offset; OGd->addresses[iter->first].second = iter->second.second + offset;
@ -470,18 +472,19 @@ std::string OffsetGroup::getFullName()
std::string OffsetGroup::PrintOffsets(int indentation) std::string OffsetGroup::PrintOffsets(int indentation)
{ {
voidptr_Iter addriter;
uint32_Iter iter; uint32_Iter iter;
ostringstream ss; ostringstream ss;
indentr i(indentation); indentr i(indentation);
typedef pair <uint32_t, pair< string, nullableUint32 > > horrible; typedef pair <void *, pair< string, nullableVoidPtr > > horrible;
vector < horrible > addrsorter; vector < horrible > addrsorter;
for(iter = OGd->addresses.begin(); iter != OGd->addresses.end(); iter++) for(addriter = OGd->addresses.begin(); addriter != OGd->addresses.end(); addriter++)
{ {
if(!(*iter).second.first) if(!(*addriter).second.first)
addrsorter.push_back( make_pair( 0, *iter ) ); addrsorter.push_back( make_pair( (void *)0, *addriter ) );
else else
{ {
addrsorter.push_back( make_pair( (*iter).second.second, *iter ) ); addrsorter.push_back( make_pair( (*addriter).second.second, *addriter ) );
} }
} }
std::sort(addrsorter.begin(), addrsorter.end(), compare_pair_first<>()); std::sort(addrsorter.begin(), addrsorter.end(), compare_pair_first<>());
@ -569,7 +572,7 @@ void OffsetGroup::setInvalid(INVAL_TYPE invalidity)
if(invalidity == NOT_SET) if(invalidity == NOT_SET)
return; return;
uint32_Iter iter; voidptr_Iter iter;
for(iter = OGd->addresses.begin(); iter != OGd->addresses.end(); iter++) for(iter = OGd->addresses.begin(); iter != OGd->addresses.end(); iter++)
{ {
if((*iter).second.first) if((*iter).second.first)
@ -581,17 +584,18 @@ void OffsetGroup::setInvalid(INVAL_TYPE invalidity)
if((*iter2).second.first) if((*iter2).second.first)
(*iter2).second.first = invalidity; (*iter2).second.first = invalidity;
} }
for(iter = OGd->hexvals.begin(); iter != OGd->hexvals.end(); iter++) uint32_Iter iter3;
{ for(iter3 = OGd->hexvals.begin(); iter3 != OGd->hexvals.end(); iter3++)
if((*iter).second.first)
(*iter).second.first = invalidity;
}
strings_Iter iter3;
for(iter3 = OGd->strings.begin(); iter3 != OGd->strings.end(); iter3++)
{ {
if((*iter3).second.first) if((*iter3).second.first)
(*iter3).second.first = invalidity; (*iter3).second.first = invalidity;
} }
strings_Iter iter5;
for(iter5 = OGd->strings.begin(); iter5 != OGd->strings.end(); iter5++)
{
if((*iter5).second.first)
(*iter5).second.first = invalidity;
}
groups_Iter iter4; groups_Iter iter4;
for(iter4 = OGd->groups.begin(); iter4 != OGd->groups.end(); iter4++) for(iter4 = OGd->groups.begin(); iter4 != OGd->groups.end(); iter4++)
{ {
@ -603,7 +607,7 @@ std::vector<OffsetKey> OffsetGroup::getKeys() const
std::vector<OffsetKey> ret; std::vector<OffsetKey> ret;
OffsetKey K; OffsetKey K;
K.keytype=IS_ADDRESS; K.keytype=IS_ADDRESS;
for(uint32_Iter iter = OGd->addresses.begin(); iter != OGd->addresses.end(); iter++) for(voidptr_Iter iter = OGd->addresses.begin(); iter != OGd->addresses.end(); iter++)
{ {
K.key=iter->first; K.key=iter->first;
K.inval=iter->second.first; K.inval=iter->second.first;
@ -1015,7 +1019,7 @@ void VersionInfo::setClassChild (t_class * parent, const char * name, const char
// FIXME: This in now DEPRECATED! // FIXME: This in now DEPRECATED!
bool VersionInfo::resolveObjectToClassID(const uint32_t address, int32_t & classid) bool VersionInfo::resolveObjectToClassID(const void * address, int32_t & classid)
{ {
uint32_t vtable = d->p->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

@ -72,8 +72,8 @@ namespace DFHack
*/ */
struct DFHACK_EXPORT t_memrange struct DFHACK_EXPORT t_memrange
{ {
uint64_t start; void * start;
uint64_t end; void * end;
// memory range name (if any) // memory range name (if any)
char name[1024]; char name[1024];
// permission to read // permission to read
@ -84,7 +84,7 @@ namespace DFHack
bool execute : 1; bool execute : 1;
// is a shared region // is a shared region
bool shared : 1; bool shared : 1;
inline bool isInRange( uint64_t address) inline bool isInRange( void * address)
{ {
if (address >= start && address < end) return true; if (address >= start && address < end) return true;
return false; return false;
@ -104,99 +104,110 @@ namespace DFHack
Process(VersionInfoFactory * known_versions); Process(VersionInfoFactory * known_versions);
~Process(); ~Process();
/// read a 8-byte integer /// read a 8-byte integer
uint64_t readQuad(const uint32_t address) uint64_t readQuad(const void * address)
{ {
return *(uint64_t *)address; return *(uint64_t *)address;
} }
/// read a 8-byte integer /// read a 8-byte integer
void readQuad(const uint32_t address, uint64_t & value) void readQuad(const void * address, uint64_t & value)
{ {
value = *(uint64_t *)address; value = *(uint64_t *)address;
}; };
/// write a 8-byte integer /// write a 8-byte integer
void writeQuad(const uint32_t address, const uint64_t value) void writeQuad(const void * address, const uint64_t value)
{ {
(*(uint64_t *)address) = value; (*(uint64_t *)address) = value;
}; };
/// read a 4-byte integer /// read a 4-byte integer
uint32_t readDWord(const uint32_t address) uint32_t readDWord(const void * address)
{ {
return *(uint32_t *)address; return *(uint32_t *)address;
} }
/// read a 4-byte integer /// read a 4-byte integer
void readDWord(const uint32_t address, uint32_t & value) void readDWord(const void * address, uint32_t & value)
{ {
value = *(uint32_t *)address; value = *(uint32_t *)address;
}; };
/// write a 4-byte integer /// write a 4-byte integer
void writeDWord(const uint32_t address, const uint32_t value) void writeDWord(const void * address, const uint32_t value)
{ {
(*(uint32_t *)address) = value; (*(uint32_t *)address) = value;
}; };
/// read a pointer
void * readPtr(const void * address)
{
return *(void **)address;
}
/// read a pointer
void readPtr(const void * address, void * & value)
{
value = *(void **)address;
};
/// read a float /// read a float
float readFloat(const uint32_t address) float readFloat(const void * address)
{ {
return *(float*)address; return *(float*)address;
} }
/// write a float /// write a float
void readFloat(const uint32_t address, float & value) void readFloat(const void * address, float & value)
{ {
value = *(float*)address; value = *(float*)address;
}; };
/// read a 2-byte integer /// read a 2-byte integer
uint16_t readWord(const uint32_t address) uint16_t readWord(const void * address)
{ {
return *(uint16_t *)address; return *(uint16_t *)address;
} }
/// read a 2-byte integer /// read a 2-byte integer
void readWord(const uint32_t address, uint16_t & value) void readWord(const void * address, uint16_t & value)
{ {
value = *(uint16_t *)address; value = *(uint16_t *)address;
}; };
/// write a 2-byte integer /// write a 2-byte integer
void writeWord(const uint32_t address, const uint16_t value) void writeWord(const void * address, const uint16_t value)
{ {
(*(uint16_t *)address) = value; (*(uint16_t *)address) = value;
}; };
/// read a byte /// read a byte
uint8_t readByte(const uint32_t address) uint8_t readByte(const void * address)
{ {
return *(uint8_t *)address; return *(uint8_t *)address;
} }
/// read a byte /// read a byte
void readByte(const uint32_t address, uint8_t & value) void readByte(const void * address, uint8_t & value)
{ {
value = *(uint8_t *)address; value = *(uint8_t *)address;
}; };
/// write a byte /// write a byte
void writeByte(const uint32_t address, const uint8_t value) void writeByte(const void * address, const uint8_t value)
{ {
(*(uint8_t *)address) = value; (*(uint8_t *)address) = value;
}; };
/// read an arbitrary amount of bytes /// read an arbitrary amount of bytes
void read( uint32_t address, uint32_t length, uint8_t* buffer) void read(void * address, uint32_t length, uint8_t* buffer)
{ {
memcpy(buffer, (void *) address, length); memcpy(buffer, (void *) address, length);
}; };
/// write an arbitrary amount of bytes /// write an arbitrary amount of bytes
void write(uint32_t address, uint32_t length, uint8_t* buffer) void write(void * address, uint32_t length, uint8_t* buffer)
{ {
memcpy((void *) address, buffer, length); memcpy((void *) address, buffer, length);
}; };
/// read an STL string /// read an STL string
const std::string readSTLString (uint32_t offset) const std::string readSTLString (void * offset)
{ {
std::string * str = (std::string *) offset; std::string * str = (std::string *) offset;
return *str; return *str;
}; };
/// read an STL string /// read an STL string
size_t readSTLString (uint32_t offset, char * buffer, size_t bufcapacity) size_t readSTLString (void * offset, char * buffer, size_t bufcapacity)
{ {
if(!bufcapacity || bufcapacity == 1) if(!bufcapacity || bufcapacity == 1)
return 0; return 0;
@ -209,7 +220,7 @@ namespace DFHack
* write an STL string * write an STL string
* @return length written * @return length written
*/ */
size_t writeSTLString(const uint32_t address, const std::string writeString) size_t writeSTLString(const void * address, const std::string writeString)
{ {
std::string * str = (std::string *) address; std::string * str = (std::string *) address;
str->assign(writeString); str->assign(writeString);
@ -219,7 +230,7 @@ namespace DFHack
* attempt to copy a string from source address to target address. may truncate or leak, depending on platform * attempt to copy a string from source address to target address. may truncate or leak, depending on platform
* @return length copied * @return length copied
*/ */
size_t copySTLString(const uint32_t address, const uint32_t target) size_t copySTLString(const void * address, const uint32_t target)
{ {
std::string * strsrc = (std::string *) address; std::string * strsrc = (std::string *) address;
std::string * str = (std::string *) target; std::string * str = (std::string *) target;
@ -239,7 +250,7 @@ namespace DFHack
} }
/// read a null-terminated C string /// read a null-terminated C string
const std::string readCString (uint32_t offset) const std::string readCString (void * offset)
{ {
return std::string((char *) offset); return std::string((char *) offset);
}; };

@ -1,96 +0,0 @@
/*
https://github.com/peterix/dfhack
Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#pragma once
#ifndef DFVECTOR_H_INCLUDED
#define DFVECTOR_H_INCLUDED
#include "Pragma.h"
#include "Export.h"
#include "VersionInfo.h"
#include "MemAccess.h"
#include <string.h>
#include <vector>
namespace DFHack
{
template <class T>
class DFHACK_EXPORT DfVector
{
private:
std::vector<T> * real_vec;
public:
DfVector(uint32_t address)
{
real_vec = (std::vector<T> *) address;
};
~DfVector()
{
};
// get offset of the specified index
inline const T& operator[] (uint32_t index)
{
// FIXME: vector out of bounds exception
//assert(index < size);
return real_vec->at(index);
};
// get offset of the specified index
inline const T& at (uint32_t index)
{
//assert(index < size);
return real_vec->at(index);
};
// update value at index
bool set(uint32_t index, T value)
{
if (index >= real_vec->size())
return false;
real_vec->at(index) = value;
return true;
}
// remove value
bool remove(uint32_t index)
{
if (index >= real_vec->size())
return false;
// Remove the item
real_vec->erase(real_vec->begin() + index);
return true;
}
// get vector size
inline uint32_t size ()
{
return real_vec->size();
};
// get vector start
inline const T * start ()
{
return real_vec->data();
};
};
}
#endif // DFVECTOR_H_INCLUDED

@ -88,13 +88,13 @@ namespace DFHack
OffsetGroup * createGroup ( const std::string & name ); OffsetGroup * createGroup ( const std::string & name );
int32_t getOffset (const std::string & key); int32_t getOffset (const std::string & key);
uint32_t getAddress (const std::string & key); void * getAddress (const std::string & key);
uint32_t getHexValue (const std::string & key); uint32_t getHexValue (const std::string & key);
std::string getString (const std::string & key); std::string getString (const std::string & key);
OffsetGroup * getGroup ( const std::string & name ); OffsetGroup * getGroup ( const std::string & name );
bool getSafeOffset (const std::string & key, int32_t & out); bool getSafeOffset (const std::string & key, int32_t & out);
bool getSafeAddress (const std::string & key, uint32_t & out); bool getSafeAddress (const std::string & key, void * & out);
void setOffset (const std::string& key, const std::string& value, const DFHack::INVAL_TYPE inval = IS_VALID); void setOffset (const std::string& key, const std::string& value, const DFHack::INVAL_TYPE inval = IS_VALID);
void setOffsetValidity(const std::string& key, const DFHack::INVAL_TYPE inval = IS_VALID); void setOffsetValidity(const std::string& key, const DFHack::INVAL_TYPE inval = IS_VALID);
@ -189,7 +189,7 @@ namespace DFHack
* uses memory reading directly, needs suspend. input = address of the object * uses memory reading directly, needs suspend. input = address of the object
* fails if it's unable to read from memory * fails if it's unable to read from memory
*/ */
bool resolveObjectToClassID (const uint32_t address, int32_t & classID); bool resolveObjectToClassID (const void * address, int32_t & classID);
/** /**
* Get a ClassID when you know the classname. can fail if the class is not in the cache * Get a ClassID when you know the classname. can fail if the class is not in the cache

@ -42,7 +42,7 @@ namespace DFHack
*/ */
struct t_building struct t_building
{ {
uint32_t origin; void * origin;
uint32_t vtable; uint32_t vtable;
uint32_t x1; uint32_t x1;
uint32_t y1; uint32_t y1;

@ -74,7 +74,7 @@ namespace DFHack
uint32_t unk6; uint32_t unk6;
/// Address of the read object in DF memory. Added by DFHack. /// Address of the read object in DF memory. Added by DFHack.
uint32_t origin; t_construction * origin;
}; };
#pragma pack (pop) #pragma pack (pop)
class DFContextShared; class DFContextShared;

@ -97,7 +97,7 @@ namespace DFHack
struct dfh_engraving struct dfh_engraving
{ {
t_engraving s; t_engraving s;
uint32_t origin; t_engraving * origin;
}; };
/** /**
* The Engravings module - allows reading engravings :D * The Engravings module - allows reading engravings :D

@ -149,7 +149,7 @@ namespace DFHack
/// placeholder /// placeholder
bool discovered; bool discovered;
/// this is NOT part of the DF feature, but an address of the feature as seen by DFhack. /// this is NOT part of the DF feature, but an address of the feature as seen by DFhack.
uint32_t origin; void * origin;
}; };

@ -18,7 +18,7 @@ namespace DFHack
*/ */
struct t_spawnPoint struct t_spawnPoint
{ {
uint32_t origin; void * origin;
int16_t race; int16_t race;
uint16_t type; uint16_t type;
uint16_t x; uint16_t x;

@ -32,7 +32,6 @@ using namespace std;
#include "VersionInfo.h" #include "VersionInfo.h"
#include "MemAccess.h" #include "MemAccess.h"
#include "Vector.h"
#include "Types.h" #include "Types.h"
#include "Error.h" #include "Error.h"
#include "modules/Buildings.h" #include "modules/Buildings.h"
@ -58,13 +57,12 @@ struct t_building_df40d
struct Buildings::Private struct Buildings::Private
{ {
uint32_t buildings_vector; vector <void *> * custom_workshop_vector;
uint32_t custom_workshop_vector;
uint32_t building_custom_workshop_type; uint32_t building_custom_workshop_type;
uint32_t custom_workshop_type; uint32_t custom_workshop_type;
uint32_t custom_workshop_name; uint32_t custom_workshop_name;
int32_t custom_workshop_id; int32_t custom_workshop_id;
DfVector <uint32_t> * p_bld; vector <t_building_df40d *> * p_bld;
Process * owner; Process * owner;
bool Inited; bool Inited;
bool hasCustomWorkshops; bool hasCustomWorkshops;
@ -88,7 +86,7 @@ Buildings::Buildings()
d->Inited = true; d->Inited = true;
try try
{ {
d->buildings_vector = OG_build->getAddress ("buildings_vector"); d->p_bld = (decltype(d->p_bld)) OG_build->getAddress ("buildings_vector");
} }
catch(DFHack::Error::AllMemdef &e) catch(DFHack::Error::AllMemdef &e)
{ {
@ -99,7 +97,7 @@ Buildings::Buildings()
{ {
try try
{ {
d->custom_workshop_vector = OG_build->getAddress("custom_workshop_vector"); d->custom_workshop_vector =(decltype(d->custom_workshop_vector)) OG_build->getAddress ("custom_workshop_vector");
d->building_custom_workshop_type = OG_build->getOffset("building_custom_workshop_type"); d->building_custom_workshop_type = OG_build->getOffset("building_custom_workshop_type");
d->custom_workshop_type = OG_build->getOffset("custom_workshop_type"); d->custom_workshop_type = OG_build->getOffset("custom_workshop_type");
d->custom_workshop_name = OG_build->getOffset("custom_workshop_name"); d->custom_workshop_name = OG_build->getOffset("custom_workshop_name");
@ -124,7 +122,6 @@ bool Buildings::Start(uint32_t & numbuildings)
{ {
if(!d->Inited) if(!d->Inited)
return false; return false;
d->p_bld = new DfVector <uint32_t> (d->buildings_vector);
numbuildings = d->p_bld->size(); numbuildings = d->p_bld->size();
d->Started = true; d->Started = true;
return true; return true;
@ -134,37 +131,25 @@ bool Buildings::Read (const uint32_t index, t_building & building)
{ {
if(!d->Started) if(!d->Started)
return false; return false;
t_building_df40d bld_40d; t_building_df40d *bld_40d = d->p_bld->at (index);
// read pointer from vector at position
uint32_t temp = d->p_bld->at (index);
//d->p_bld->read(index,(uint8_t *)&temp);
//read building from memory
d->owner->read (temp, sizeof (t_building_df40d), (uint8_t *) &bld_40d);
// transform // transform
int32_t type = -1; int32_t type = -1;
d->owner->getDescriptor()->resolveObjectToClassID (temp, type); d->owner->getDescriptor()->resolveObjectToClassID (bld_40d, type);
building.origin = temp; building.origin = bld_40d;
building.vtable = bld_40d.vtable; building.vtable = bld_40d->vtable;
building.x1 = bld_40d.x1; building.x1 = bld_40d->x1;
building.x2 = bld_40d.x2; building.x2 = bld_40d->x2;
building.y1 = bld_40d.y1; building.y1 = bld_40d->y1;
building.y2 = bld_40d.y2; building.y2 = bld_40d->y2;
building.z = bld_40d.z; building.z = bld_40d->z;
building.material = bld_40d.material; building.material = bld_40d->material;
building.type = type; building.type = type;
return true; return true;
} }
bool Buildings::Finish() bool Buildings::Finish()
{ {
if(d->p_bld)
{
delete d->p_bld;
d->p_bld = NULL;
}
d->Started = false; d->Started = false;
return true; return true;
} }
@ -177,14 +162,14 @@ bool Buildings::ReadCustomWorkshopTypes(map <uint32_t, string> & btypes)
return false; return false;
Process * p = d->owner; Process * p = d->owner;
DfVector <uint32_t> p_matgloss (d->custom_workshop_vector); uint32_t size = d->custom_workshop_vector->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 = p->readSTLString (p_matgloss[i] + d->custom_workshop_name); void * obj = d->custom_workshop_vector->at(i);
uint32_t type = p->readDWord (p_matgloss[i] + d->custom_workshop_type); string out = p->readSTLString (obj + d->custom_workshop_name);
uint32_t type = p->readDWord (obj + d->custom_workshop_type);
#ifdef DEBUG #ifdef DEBUG
cout << out << ": " << type << endl; cout << out << ": " << type << endl;
#endif #endif

@ -33,7 +33,6 @@ using namespace std;
#include "VersionInfo.h" #include "VersionInfo.h"
#include "MemAccess.h" #include "MemAccess.h"
#include "Vector.h"
#include "Types.h" #include "Types.h"
#include "modules/Constructions.h" #include "modules/Constructions.h"
#include "ModuleFactory.h" #include "ModuleFactory.h"
@ -43,10 +42,7 @@ using namespace DFHack;
struct Constructions::Private struct Constructions::Private
{ {
uint32_t construction_vector; vector <t_construction *> * p_cons;
// translation
DfVector <uint32_t> * p_cons;
Process * owner; Process * owner;
bool Inited; bool Inited;
bool Started; bool Started;
@ -62,10 +58,9 @@ Constructions::Constructions()
Core & c = Core::getInstance(); Core & c = Core::getInstance();
d = new Private; d = new Private;
d->owner = c.p; d->owner = c.p;
d->p_cons = 0;
d->Inited = d->Started = false; d->Inited = d->Started = false;
VersionInfo * mem = c.vinfo; VersionInfo * mem = c.vinfo;
d->construction_vector = mem->getGroup("Constructions")->getAddress ("vector"); d->p_cons = (decltype(d->p_cons)) mem->getGroup("Constructions")->getAddress ("vector");
d->Inited = true; d->Inited = true;
} }
@ -78,7 +73,6 @@ Constructions::~Constructions()
bool Constructions::Start(uint32_t & numconstructions) bool Constructions::Start(uint32_t & numconstructions)
{ {
d->p_cons = new DfVector <uint32_t> (d->construction_vector);
numconstructions = d->p_cons->size(); numconstructions = d->p_cons->size();
d->Started = true; d->Started = true;
return true; return true;
@ -89,24 +83,14 @@ bool Constructions::Read (const uint32_t index, t_construction & construction)
{ {
if(!d->Started) return false; if(!d->Started) return false;
// read pointer from vector at position t_construction * orig = d->p_cons->at(index);
uint32_t temp = d->p_cons->at (index); construction = *orig;
construction.origin = orig;
//read construction from memory
d->owner->read (temp, sizeof (t_construction), (uint8_t *) &construction);
// transform
construction.origin = temp;
return true; return true;
} }
bool Constructions::Finish() bool Constructions::Finish()
{ {
if(d->p_cons)
{
delete d->p_cons;
d->p_cons = NULL;
}
d->Started = false; d->Started = false;
return true; return true;
} }

@ -31,8 +31,7 @@ distribution.
using namespace std; using namespace std;
#include "VersionInfo.h" #include "VersionInfo.h"
//#include "MemAccess.h" #include "MemAccess.h"
#include "Vector.h"
#include "Types.h" #include "Types.h"
#include "modules/Engravings.h" #include "modules/Engravings.h"
#include "ModuleFactory.h" #include "ModuleFactory.h"
@ -43,8 +42,7 @@ using namespace DFHack;
struct Engravings::Private struct Engravings::Private
{ {
uint32_t engraving_vector; uint32_t engraving_vector;
// translation vector <t_engraving *> * p_engr;
DfVector <uint32_t> * p_engr;
Process * owner; Process * owner;
bool Inited; bool Inited;
@ -61,9 +59,8 @@ Engravings::Engravings()
Core & c = Core::getInstance(); Core & c = Core::getInstance();
d = new Private; d = new Private;
d->owner = c.p; d->owner = c.p;
d->p_engr = 0;
d->Inited = d->Started = false; d->Inited = d->Started = false;
d->engraving_vector = c.vinfo->getGroup("Engravings")->getAddress ("vector"); d->p_engr = (decltype(d->p_engr)) c.vinfo->getGroup("Engravings")->getAddress ("vector");
d->Inited = true; d->Inited = true;
} }
@ -76,7 +73,8 @@ Engravings::~Engravings()
bool Engravings::Start(uint32_t & numengravings) bool Engravings::Start(uint32_t & numengravings)
{ {
d->p_engr = new DfVector <uint32_t> (d->engraving_vector); if(!d->Inited)
return false;
numengravings = d->p_engr->size(); numengravings = d->p_engr->size();
d->Started = true; d->Started = true;
return true; return true;
@ -88,13 +86,10 @@ bool Engravings::Read (const uint32_t index, dfh_engraving & engraving)
if(!d->Started) return false; if(!d->Started) return false;
// read pointer from vector at position // read pointer from vector at position
uint32_t temp = d->p_engr->at (index); engraving.s = *d->p_engr->at (index);
//read construction from memory
d->owner->read (temp, sizeof (t_engraving), (uint8_t *) &(engraving.s));
// transform // transform
engraving.origin = temp; engraving.origin = d->p_engr->at (index);
return true; return true;
} }
@ -108,11 +103,6 @@ bool Engravings::Write (const dfh_engraving & engraving)
bool Engravings::Finish() bool Engravings::Finish()
{ {
if(d->p_engr)
{
delete d->p_engr;
d->p_engr = NULL;
}
d->Started = false; d->Started = false;
return true; return true;
} }

@ -37,7 +37,6 @@ using namespace std;
#include "Error.h" #include "Error.h"
#include "VersionInfo.h" #include "VersionInfo.h"
#include "MemAccess.h" #include "MemAccess.h"
#include "Vector.h"
#include "ModuleFactory.h" #include "ModuleFactory.h"
#include "Core.h" #include "Core.h"

@ -91,16 +91,23 @@ struct Gui::Private
} }
bool Started; bool Started;
uint32_t window_x_offset; int32_t * window_x_offset;
uint32_t window_y_offset; int32_t * window_y_offset;
uint32_t window_z_offset; int32_t * window_z_offset;
uint32_t cursor_xyz_offset; struct xyz
uint32_t designation_xyz_offset; {
uint32_t mouse_xy_offset; int32_t x;
uint32_t window_dims_offset; int32_t y;
int32_t z;
} * cursor_xyz_offset, * designation_xyz_offset;
struct xy
{
int32_t x;
int32_t y;
} * mouse_xy_offset, * window_dims_offset;
bool StartedScreen; bool StartedScreen;
uint32_t screen_tiles_ptr_offset; void * screen_tiles_ptr_offset;
Process * owner; Process * owner;
}; };
@ -157,19 +164,33 @@ Gui::Gui()
try try
{ {
OG_Position = mem->getGroup("Position"); OG_Position = mem->getGroup("Position");
d->window_x_offset = OG_Position->getAddress ("window_x"); d->window_x_offset = (int32_t *) OG_Position->getAddress ("window_x");
d->window_y_offset = OG_Position->getAddress ("window_y"); d->window_y_offset = (int32_t *) OG_Position->getAddress ("window_y");
d->window_z_offset = OG_Position->getAddress ("window_z"); d->window_z_offset = (int32_t *) OG_Position->getAddress ("window_z");
d->cursor_xyz_offset = OG_Position->getAddress ("cursor_xyz"); d->cursor_xyz_offset = (Private::xyz *) OG_Position->getAddress ("cursor_xyz");
d->window_dims_offset = OG_Position->getAddress ("window_dims"); d->window_dims_offset = (Private::xy *) OG_Position->getAddress ("window_dims");
d->Started = true; d->Started = true;
} }
catch(Error::All &){}; catch(Error::All &){};
OG_Position->getSafeAddress("mouse_xy", d->mouse_xy_offset);
OG_Position->getSafeAddress("designation_xyz", d->designation_xyz_offset);
try try
{ {
d->screen_tiles_ptr_offset = OG_Position->getAddress ("screen_tiles_pointer"); d->mouse_xy_offset = (Private::xy *) OG_Position->getAddress ("mouse_xy");
}
catch(Error::All &)
{
d->mouse_xy_offset = 0;
};
try
{
d->designation_xyz_offset = (Private::xyz *) OG_Position->getAddress ("designation_xyz");
}
catch(Error::All &)
{
d->designation_xyz_offset = 0;
};
try
{
d->screen_tiles_ptr_offset = (void *) OG_Position->getAddress ("screen_tiles_pointer");
d->StartedScreen = true; d->StartedScreen = true;
} }
catch(Error::All &){}; catch(Error::All &){};
@ -299,10 +320,10 @@ bool Gui::getScreenTiles (int32_t width, int32_t height, t_screen screen[])
{ {
if(!d->StartedScreen) return false; if(!d->StartedScreen) return false;
uint32_t screen_addr = d->owner->readDWord(d->screen_tiles_ptr_offset); void * screen_addr = (void *) d->owner->readDWord(d->screen_tiles_ptr_offset);
uint8_t* tiles = new uint8_t[width*height*4/* + 80 + width*height*4*/]; uint8_t* tiles = new uint8_t[width*height*4/* + 80 + width*height*4*/];
d->owner->read (screen_addr, (width*height*4/* + 80 + width*height*4*/), (uint8_t *) tiles); d->owner->read (screen_addr, (width*height*4/* + 80 + width*height*4*/), tiles);
for(int32_t iy=0; iy<height; iy++) for(int32_t iy=0; iy<height; iy++)
{ {

@ -36,7 +36,6 @@ using namespace std;
#include "Types.h" #include "Types.h"
#include "VersionInfo.h" #include "VersionInfo.h"
#include "MemAccess.h" #include "MemAccess.h"
#include "Vector.h"
#include "modules/Materials.h" #include "modules/Materials.h"
#include "modules/Items.h" #include "modules/Items.h"
#include "modules/Units.h" #include "modules/Units.h"
@ -58,7 +57,7 @@ class Items::Private
std::map<int32_t, df_item *> idLookupTable; std::map<int32_t, df_item *> idLookupTable;
uint32_t refVectorOffset; uint32_t refVectorOffset;
uint32_t idFieldOffset; uint32_t idFieldOffset;
uint32_t itemVectorAddress; void * itemVectorAddress;
ClassNameCheck isOwnerRefClass; ClassNameCheck isOwnerRefClass;
ClassNameCheck isContainerRefClass; ClassNameCheck isContainerRefClass;

@ -37,7 +37,6 @@ using namespace std;
#include "Error.h" #include "Error.h"
#include "VersionInfo.h" #include "VersionInfo.h"
#include "MemAccess.h" #include "MemAccess.h"
#include "Vector.h"
#include "ModuleFactory.h" #include "ModuleFactory.h"
#include "Core.h" #include "Core.h"
@ -96,7 +95,7 @@ struct Maps::Private
FEATURES FEATURES
*/ */
// FIXME: replace with a struct pointer, eventually. needs to be mapped out first // FIXME: replace with a struct pointer, eventually. needs to be mapped out first
uint32_t world_data; void * world_data;
uint32_t local_f_start; // offset from world_data uint32_t local_f_start; // offset from world_data
// FIXME: replace by virtual function call // FIXME: replace by virtual function call
uint32_t local_material; uint32_t local_material;
@ -122,7 +121,7 @@ struct Maps::Private
set <uint32_t> unknown_veins; set <uint32_t> unknown_veins;
// map between feature address and the read object // map between feature address and the read object
map <uint32_t, t_feature> local_feature_store; map <void *, t_feature> local_feature_store;
map <DFCoord, vector <t_feature *> > m_local_feature; map <DFCoord, vector <t_feature *> > m_local_feature;
vector <t_feature> v_global_feature; vector <t_feature> v_global_feature;
@ -142,7 +141,7 @@ Maps::Maps()
// get the offsets once here // get the offsets once here
OffsetGroup *OG_Maps = mem->getGroup("Maps"); OffsetGroup *OG_Maps = mem->getGroup("Maps");
off.world_data = OG_Maps->getAddress("world_data"); off.world_data = (void *) OG_Maps->getAddress("world_data");
{ {
mdata = (map_data *) OG_Maps->getAddress ("map_data"); mdata = (map_data *) OG_Maps->getAddress ("map_data");
off.world_size_x = OG_Maps->getOffset ("world_size_x_from_wdata"); off.world_size_x = OG_Maps->getOffset ("world_size_x_from_wdata");
@ -508,13 +507,13 @@ bool Maps::StartFeatures()
Process * p = d->owner; Process * p = d->owner;
Private::t_offsets &off = d->offsets; Private::t_offsets &off = d->offsets;
uint32_t base = 0; void * base = 0;
uint32_t global_feature_vector = 0; void * global_feature_vector = 0;
uint32_t world = p->readDWord(off.world_data); void * world = p->readPtr( (void *) off.world_data);
if(!world) return false; if(!world) return false;
base = p->readDWord(world + off.local_f_start); base = p->readPtr(world + off.local_f_start);
global_feature_vector = p->readDWord(off.world_data) + off.global_vector; global_feature_vector = p->readDWord(off.world_data) + (void *) off.global_vector;
// deref pointer to the humongo-structure // deref pointer to the humongo-structure
if(!base) if(!base)
@ -549,22 +548,21 @@ bool Maps::StartFeatures()
// base = pointer to local feature structure (inside world data struct) // base = pointer to local feature structure (inside world data struct)
// bigregion is 16x16 regions. for each bigregion in X dimension: // bigregion is 16x16 regions. for each bigregion in X dimension:
uint32_t mega_column = p->readDWord(base + bigregion_x * 4); void * mega_column = p->readPtr(base + bigregion_x * 4);
// 16B structs, second DWORD of the struct is a pointer // 16B structs, second DWORD of the struct is a pointer
uint32_t loc_f_array16x16 = p->readDWord(mega_column + offset_elem + (sizeof_elem * bigregion_y)); void * loc_f_array16x16 = p->readPtr(mega_column + offset_elem + (sizeof_elem * bigregion_y));
if(loc_f_array16x16) if(loc_f_array16x16)
{ {
uint32_t feat_vector = loc_f_array16x16 + sizeof_16vec * sub_x + sizeof_vec * sub_y; vector <void *> * p_features = (vector <void *> *) (loc_f_array16x16 + sizeof_16vec * sub_x + sizeof_vec * sub_y);
DfVector<uint32_t> p_features(feat_vector); uint32_t size = p_features->size();
uint32_t size = p_features.size();
DFCoord pc(blockX,blockY); DFCoord pc(blockX,blockY);
std::vector<t_feature *> tempvec; std::vector<t_feature *> tempvec;
for(uint32_t i = 0; i < size; i++) for(uint32_t i = 0; i < size; i++)
{ {
uint32_t cur_ptr = p_features[i]; void * cur_ptr = p_features->at(i);
map <uint32_t, t_feature>::iterator it; map <void *, t_feature>::iterator it;
it = d->local_feature_store.find(cur_ptr); it = d->local_feature_store.find(cur_ptr);
// do we already have the feature? // do we already have the feature?
if(it != d->local_feature_store.end()) if(it != d->local_feature_store.end())
@ -579,7 +577,7 @@ bool Maps::StartFeatures()
// create, add to store // create, add to store
t_feature tftemp; t_feature tftemp;
tftemp.discovered = false; //= p->readDWord(cur_ptr + 4); tftemp.discovered = false; //= p->readDWord(cur_ptr + 4);
tftemp.origin = cur_ptr; tftemp.origin = (t_feature *) cur_ptr;
string name = p->readClassName((void *)p->readDWord( cur_ptr )); string name = p->readClassName((void *)p->readDWord( cur_ptr ));
if(name == "feature_init_deep_special_tubest") if(name == "feature_init_deep_special_tubest")
{ {
@ -611,17 +609,15 @@ bool Maps::StartFeatures()
const uint32_t global_feature_funcptr = off.global_funcptr; const uint32_t global_feature_funcptr = off.global_funcptr;
const uint32_t glob_main_mat_offset = off.global_material; const uint32_t glob_main_mat_offset = off.global_material;
const uint32_t glob_sub_mat_offset = off.global_submaterial; const uint32_t glob_sub_mat_offset = off.global_submaterial;
DfVector<uint32_t> p_features (global_feature_vector); vector <void *> * p_features = (vector <void *> *) global_feature_vector;
d->v_global_feature.clear(); d->v_global_feature.clear();
uint32_t size = p_features.size(); uint32_t size = p_features->size();
d->v_global_feature.reserve(size); d->v_global_feature.reserve(size);
for(uint32_t i = 0; i < size; i++) for(uint32_t i = 0; i < size; i++)
{ {
t_feature temp; t_feature temp;
uint32_t feat_ptr = p->readDWord(p_features[i] + global_feature_funcptr ); void * feat_ptr = p->readPtr(p_features->at(i) + global_feature_funcptr );
temp.origin = feat_ptr; temp.origin = feat_ptr;
//temp.discovered = p->readDWord( feat_ptr + 4 ); // maybe, placeholder
temp.discovered = false; temp.discovered = false;
// FIXME: use the memory_info cache mechanisms // FIXME: use the memory_info cache mechanisms
@ -887,8 +883,8 @@ bool Maps::RemoveBlockEvent(uint32_t x, uint32_t y, uint32_t z, t_virtual * whic
} }
/* /*
* Layer geology * Layer geology
*/ */
bool Maps::ReadGeology (vector < vector <uint16_t> >& assign) bool Maps::ReadGeology (vector < vector <uint16_t> >& assign)
{ {
MAPS_GUARD MAPS_GUARD
@ -896,17 +892,18 @@ bool Maps::ReadGeology (vector < vector <uint16_t> >& assign)
Process *p = d->owner; 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.
uint16_t worldSizeX, worldSizeY; uint16_t worldSizeX, worldSizeY;
uint32_t regions, geoblocks_vector_addr; void *regions;
void *geoblocks_vector_addr;
Private::t_offsets &off = d->offsets; Private::t_offsets &off = d->offsets;
// get world size // get world size
uint32_t world = p->readDWord(off.world_data); void * world = p->readPtr(off.world_data);
p->readWord (world + off.world_size_x, worldSizeX); p->readWord (world + off.world_size_x, worldSizeX);
p->readWord (world + off.world_size_y, worldSizeY); p->readWord (world + off.world_size_y, worldSizeY);
regions = p->readDWord ( world + off.world_regions); // ptr2_region_array regions = p->readPtr ( world + off.world_regions); // ptr2_region_array
geoblocks_vector_addr = world + off.world_geoblocks_vector; geoblocks_vector_addr = world + off.world_geoblocks_vector;
// read the geoblock vector // read the geoblock vector
DfVector <uint32_t> geoblocks (geoblocks_vector_addr); vector <void *> & geoblocks = *(vector <void *> *)(geoblocks_vector_addr);
// iterate over 8 surrounding regions + local region // iterate over 8 surrounding regions + local region
for (int i = eNorthWest; i < eBiomeCount; i++) for (int i = eNorthWest; i < eBiomeCount; i++)
@ -925,8 +922,8 @@ bool Maps::ReadGeology (vector < vector <uint16_t> >& assign)
/// regions are a 2d array. consists of pointers to arrays of regions /// regions are a 2d array. consists of pointers to arrays of regions
/// 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; void * geoX;
p->readDWord (regions + bioRX*4, geoX); p->readPtr (regions + bioRX*4, geoX);
// get index into geoblock vector // get index into geoblock vector
uint16_t geoindex; uint16_t geoindex;
@ -935,11 +932,11 @@ bool Maps::ReadGeology (vector < vector <uint16_t> >& assign)
/// 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
// read the matgloss pointer from the vector into temp // read the matgloss pointer from the vector into temp
uint32_t geoblock_off = geoblocks[geoindex]; void * geoblock_off = geoblocks[geoindex];
/// 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 (geoblock_off + off.geolayer_geoblock_offset); // let's hope vector <void *> & geolayers = *(vector <void *> *)(geoblock_off + off.geolayer_geoblock_offset);
// 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);
@ -949,7 +946,7 @@ bool Maps::ReadGeology (vector < vector <uint16_t> >& assign)
for (uint32_t j = 0;j < geolayers.size();j++) for (uint32_t j = 0;j < geolayers.size();j++)
{ {
// read pointer to a layer // read pointer to a layer
uint32_t geol_offset = geolayers[j]; void * 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 (p->readWord (geol_offset + off.type_inside_geolayer)); d->v_geology[i].push_back (p->readWord (geol_offset + off.type_inside_geolayer));
} }

@ -35,7 +35,6 @@ using namespace std;
#include "modules/Materials.h" #include "modules/Materials.h"
#include "VersionInfo.h" #include "VersionInfo.h"
#include "MemAccess.h" #include "MemAccess.h"
#include "Vector.h"
#include "Error.h" #include "Error.h"
#include "ModuleFactory.h" #include "ModuleFactory.h"
#include "Core.h" #include "Core.h"
@ -52,8 +51,8 @@ class Materials::Private
public: public:
Process * owner; Process * owner;
OffsetGroup * OG_Materials; OffsetGroup * OG_Materials;
uint32_t vector_races; void * vector_races;
uint32_t vector_other; void * vector_other;
}; };
Materials::Materials() Materials::Materials()
@ -67,10 +66,10 @@ Materials::Materials()
df_inorganic = 0; df_inorganic = 0;
OffsetGroup *OG_Materials = d->OG_Materials = c.vinfo->getGroup("Materials"); OffsetGroup *OG_Materials = d->OG_Materials = c.vinfo->getGroup("Materials");
{ {
OG_Materials->getSafeAddress("inorganics",(uint32_t &)df_inorganic); OG_Materials->getSafeAddress("inorganics",(void * &)df_inorganic);
OG_Materials->getSafeAddress("organics_all",(uint32_t &)df_organic); OG_Materials->getSafeAddress("organics_all",(void * &)df_organic);
OG_Materials->getSafeAddress("organics_plants",(uint32_t &)df_plants); OG_Materials->getSafeAddress("organics_plants",(void * &)df_plants);
OG_Materials->getSafeAddress("organics_trees",(uint32_t &)df_trees); OG_Materials->getSafeAddress("organics_trees",(void * &)df_trees);
d->vector_races = OG_Materials->getAddress("creature_type_vector"); d->vector_races = OG_Materials->getAddress("creature_type_vector");
} }
} }
@ -111,16 +110,16 @@ bool t_matglossInorganic::isGem()
} }
// good for now // good for now
inline bool ReadNamesOnly(Process* p, uint32_t address, vector<t_matgloss> & names) inline bool ReadNamesOnly(Process* p, void * address, vector<t_matgloss> & names)
{ {
DfVector <uint32_t> p_matgloss (address); vector <string *> * p_names = (vector <string *> *) address;
uint32_t size = p_matgloss.size(); uint32_t size = p_names->size();
names.clear(); names.clear();
names.reserve (size); names.reserve (size);
for (uint32_t i = 0; i < size;i++) for (uint32_t i = 0; i < size;i++)
{ {
t_matgloss mat; t_matgloss mat;
mat.id = *(std::string *)p_matgloss[i]; mat.id = *p_names->at(i);
names.push_back(mat); names.push_back(mat);
} }
return true; return true;
@ -159,21 +158,21 @@ bool Materials::CopyInorganicMaterials (std::vector<t_matglossInorganic> & inorg
bool Materials::CopyOrganicMaterials (std::vector<t_matgloss> & organic) bool Materials::CopyOrganicMaterials (std::vector<t_matgloss> & organic)
{ {
if(df_organic) if(df_organic)
return ReadNamesOnly(d->owner, (uint32_t) df_organic, organic ); return ReadNamesOnly(d->owner, (void *) df_organic, organic );
else return false; else return false;
} }
bool Materials::CopyWoodMaterials (std::vector<t_matgloss> & tree) bool Materials::CopyWoodMaterials (std::vector<t_matgloss> & tree)
{ {
if(df_trees) if(df_trees)
return ReadNamesOnly(d->owner, (uint32_t) df_trees, tree ); return ReadNamesOnly(d->owner, (void *) df_trees, tree );
else return false; else return false;
} }
bool Materials::CopyPlantMaterials (std::vector<t_matgloss> & plant) bool Materials::CopyPlantMaterials (std::vector<t_matgloss> & plant)
{ {
if(df_plants) if(df_plants)
return ReadNamesOnly(d->owner, (uint32_t) df_plants, plant ); return ReadNamesOnly(d->owner, (void *) df_plants, plant );
else return false; else return false;
} }
@ -185,7 +184,7 @@ bool Materials::ReadCreatureTypes (void)
bool Materials::ReadOthers(void) bool Materials::ReadOthers(void)
{ {
Process * p = d->owner; Process * p = d->owner;
uint32_t matBase = d->OG_Materials->getAddress ("other"); void * matBase = d->OG_Materials->getAddress ("other");
uint32_t i = 0; uint32_t i = 0;
std::string * ptr; std::string * ptr;
@ -194,7 +193,7 @@ bool Materials::ReadOthers(void)
while(1) while(1)
{ {
t_matglossOther mat; t_matglossOther mat;
ptr = (std::string *) p->readDWord(matBase + i*4); ptr = (std::string *) p->readPtr(matBase + i*4);
if(ptr==0) if(ptr==0)
break; break;
mat.id = *ptr; mat.id = *ptr;
@ -208,7 +207,7 @@ bool Materials::ReadDescriptorColors (void)
{ {
Process * p = d->owner; Process * p = d->owner;
OffsetGroup * OG_Descriptors = p->getDescriptor()->getGroup("Materials")->getGroup("descriptors"); OffsetGroup * OG_Descriptors = p->getDescriptor()->getGroup("Materials")->getGroup("descriptors");
DfVector <uint32_t> p_colors (OG_Descriptors->getAddress ("colors_vector")); vector <void *> & p_colors = *(vector<void*> *) OG_Descriptors->getAddress ("colors_vector");
uint32_t size = p_colors.size(); uint32_t size = p_colors.size();
color.clear(); color.clear();
@ -237,7 +236,7 @@ bool Materials::ReadCreatureTypesEx (void)
uint32_t sizeof_string = OG_string->getHexValue ("sizeof"); uint32_t sizeof_string = OG_string->getHexValue ("sizeof");
OffsetGroup * OG_Mats = mem->getGroup("Materials"); OffsetGroup * OG_Mats = mem->getGroup("Materials");
DfVector <uint32_t> p_races (OG_Mats->getAddress ("creature_type_vector")); vector <void *> & p_races = *(vector<void*> *) OG_Mats->getAddress ("creature_type_vector");
OffsetGroup * OG_Creature = OG_Mats->getGroup("creature"); OffsetGroup * OG_Creature = OG_Mats->getGroup("creature");
uint32_t castes_vector_offset = OG_Creature->getOffset ("caste_vector"); uint32_t castes_vector_offset = OG_Creature->getOffset ("caste_vector");
@ -287,13 +286,13 @@ bool Materials::ReadCreatureTypesEx (void)
mat.tilecolor.back = p->readWord( p_races[i] + tile_color_offset + 2 ); mat.tilecolor.back = p->readWord( p_races[i] + tile_color_offset + 2 );
mat.tilecolor.bright = p->readWord( p_races[i] + tile_color_offset + 4 ); mat.tilecolor.bright = p->readWord( p_races[i] + tile_color_offset + 4 );
DfVector <uint32_t> p_castes(p_races[i] + castes_vector_offset); vector <void *> & p_castes = *(vector<void*> *) (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++)
{ {
/* caste name */ /* caste name */
t_creaturecaste caste; t_creaturecaste caste;
uint32_t caste_start = p_castes[j]; void * caste_start = p_castes[j];
caste.id = p->readSTLString (caste_start); caste.id = p->readSTLString (caste_start);
caste.singular = p->readSTLString (caste_start + sizeof_string); caste.singular = p->readSTLString (caste_start + sizeof_string);
caste.plural = p->readSTLString (caste_start + 2 * sizeof_string); caste.plural = p->readSTLString (caste_start + 2 * sizeof_string);
@ -303,13 +302,13 @@ bool Materials::ReadCreatureTypesEx (void)
{ {
/* color mod reading */ /* color mod reading */
// Caste + offset > color mod vector // Caste + offset > color mod vector
DfVector <uint32_t> p_colormod(caste_start + caste_colormod_offset); vector <void *> & p_colormod = *(vector<void*> *) (caste_start + caste_colormod_offset);
sizecolormod = p_colormod.size(); sizecolormod = p_colormod.size();
caste.ColorModifier.resize(sizecolormod); caste.ColorModifier.resize(sizecolormod);
for(uint32_t k = 0; k < sizecolormod;k++) for(uint32_t k = 0; k < sizecolormod;k++)
{ {
// color mod [0] -> color list // color mod [0] -> color list
DfVector <uint32_t> p_colorlist(p_colormod[k]); vector <uint32_t> & p_colorlist = *(vector<uint32_t> *) (p_colormod[k]);
sizecolorlist = p_colorlist.size(); sizecolorlist = p_colorlist.size();
caste.ColorModifier[k].colorlist.resize(sizecolorlist); caste.ColorModifier[k].colorlist.resize(sizecolorlist);
for(uint32_t l = 0; l < sizecolorlist; l++) for(uint32_t l = 0; l < sizecolorlist; l++)
@ -320,7 +319,7 @@ bool Materials::ReadCreatureTypesEx (void)
caste.ColorModifier[k].enddate = p->readDWord( p_colormod[k] + color_modifier_enddate_offset ); caste.ColorModifier[k].enddate = p->readDWord( p_colormod[k] + color_modifier_enddate_offset );
} }
/* body parts */ /* body parts */
DfVector <uint32_t> p_bodypart(caste_start + caste_bodypart_offset); vector <void *> & p_bodypart = *(vector<void*> *) (caste_start + caste_bodypart_offset);
caste.bodypart.empty(); caste.bodypart.empty();
sizebp = p_bodypart.size(); sizebp = p_bodypart.size();
for(uint32_t k = 0; k < sizebp; k++) for(uint32_t k = 0; k < sizebp; k++)
@ -338,7 +337,7 @@ bool Materials::ReadCreatureTypesEx (void)
} }
mat.castes.push_back(caste); mat.castes.push_back(caste);
} }
DfVector <uint32_t> p_extract(p_races[i] + extract_vector_offset); vector <void *> & p_extract = *(vector<void*> *) (p_races[i] + extract_vector_offset);
for(uint32_t j = 0; j < p_extract.size(); j++) for(uint32_t j = 0; j < p_extract.size(); j++)
{ {
t_creatureextract extract; t_creatureextract extract;

@ -33,7 +33,6 @@ using namespace std;
#include "modules/Translation.h" #include "modules/Translation.h"
#include "VersionInfo.h" #include "VersionInfo.h"
#include "MemAccess.h" #include "MemAccess.h"
#include "Vector.h"
#include "Types.h" #include "Types.h"
#include "ModuleFactory.h" #include "ModuleFactory.h"
#include "Core.h" #include "Core.h"
@ -46,8 +45,8 @@ Module* DFHack::createTranslation()
struct Translation::Private struct Translation::Private
{ {
uint32_t genericAddress; void * genericAddress;
uint32_t transAddress; void * transAddress;
uint32_t word_table_offset; uint32_t word_table_offset;
uint32_t sizeof_string; uint32_t sizeof_string;
@ -97,15 +96,15 @@ bool Translation::Start()
return false; return false;
Process * p = c.p; Process * p = c.p;
Finish(); Finish();
DfVector <uint32_t> genericVec (d->genericAddress); vector <void *> & genericVec = *(vector <void *> *) d->genericAddress;
DfVector <uint32_t> transVec (d->transAddress); vector <void *> & transVec = *(vector <void *> *) d->transAddress;
DFDict & translations = d->dicts.translations; DFDict & translations = d->dicts.translations;
DFDict & foreign_languages = d->dicts.foreign_languages; DFDict & foreign_languages = d->dicts.foreign_languages;
translations.resize(10); translations.resize(10);
for (uint32_t i = 0;i < genericVec.size();i++) for (uint32_t i = 0;i < genericVec.size();i++)
{ {
uint32_t genericNamePtr = genericVec.at(i); void * genericNamePtr = genericVec[i];
for(int j=0; j<10;j++) for(int j=0; j<10;j++)
{ {
string word = p->readSTLString (genericNamePtr + j * d->sizeof_string); string word = p->readSTLString (genericNamePtr + j * d->sizeof_string);
@ -116,11 +115,11 @@ bool Translation::Start()
foreign_languages.resize(transVec.size()); foreign_languages.resize(transVec.size());
for (uint32_t i = 0; i < transVec.size();i++) for (uint32_t i = 0; i < transVec.size();i++)
{ {
uint32_t transPtr = transVec.at(i); void * transPtr = transVec.at(i);
DfVector <uint32_t> trans_names_vec (transPtr + d->word_table_offset); vector <void *> & trans_names_vec = *(vector <void *> *) (transPtr + d->word_table_offset);
for (uint32_t j = 0;j < trans_names_vec.size();j++) for (uint32_t j = 0;j < trans_names_vec.size();j++)
{ {
uint32_t transNamePtr = trans_names_vec.at(j); void * transNamePtr = trans_names_vec[j];
string name = p->readSTLString (transNamePtr); string name = p->readSTLString (transNamePtr);
foreign_languages[i].push_back (name); foreign_languages[i].push_back (name);
} }

@ -36,7 +36,6 @@ using namespace std;
#include "VersionInfo.h" #include "VersionInfo.h"
#include "MemAccess.h" #include "MemAccess.h"
#include "Vector.h"
#include "Error.h" #include "Error.h"
#include "Types.h" #include "Types.h"
@ -54,8 +53,8 @@ struct Units::Private
bool Inited; bool Inited;
bool Started; bool Started;
uint32_t dwarf_race_index_addr; void * dwarf_race_index_addr;
uint32_t dwarf_civ_id_addr; void * dwarf_civ_id_addr;
bool IdMapReady; bool IdMapReady;
std::map<int32_t, int32_t> IdMap; std::map<int32_t, int32_t> IdMap;
@ -86,8 +85,8 @@ Units::Units()
try try
{ {
creatures = (vector <df_unit *> *) OG_Creatures->getAddress ("vector"); creatures = (vector <df_unit *> *) OG_Creatures->getAddress ("vector");
d->dwarf_race_index_addr = OG_Creatures->getAddress("current_race"); d->dwarf_race_index_addr = (void *) OG_Creatures->getAddress("current_race");
d->dwarf_civ_id_addr = OG_Creatures->getAddress("current_civ"); d->dwarf_civ_id_addr = (void *) OG_Creatures->getAddress("current_civ");
} }
catch(Error::All&){}; catch(Error::All&){};
d->Inited = true; d->Inited = true;

@ -32,7 +32,6 @@ using namespace std;
#include "VersionInfo.h" #include "VersionInfo.h"
#include "MemAccess.h" #include "MemAccess.h"
#include "Vector.h"
#include "Types.h" #include "Types.h"
#include "modules/Vegetation.h" #include "modules/Vegetation.h"
#include "modules/Translation.h" #include "modules/Translation.h"

@ -40,7 +40,7 @@ using namespace DFHack;
struct Vermin::Private struct Vermin::Private
{ {
uint32_t spawn_points_vector; void * spawn_points_vector;
uint32_t race_offset; uint32_t race_offset;
uint32_t type_offset; uint32_t type_offset;
uint32_t position_offset; uint32_t position_offset;
@ -140,7 +140,7 @@ bool SpawnPoints::Read (const uint32_t index, t_spawnPoint & sp)
return false; return false;
// read pointer from vector at position // read pointer from vector at position
uint32_t temp = (uint32_t) p_sp->at (index); void * temp = p_sp->at (index);
sp.origin = temp; sp.origin = temp;
sp.race = v->d->owner->readWord(temp + v->d->race_offset); sp.race = v->d->owner->readWord(temp + v->d->race_offset);
@ -161,7 +161,7 @@ bool SpawnPoints::Write (const uint32_t index, t_spawnPoint & sp)
return false; return false;
// read pointer from vector at position // read pointer from vector at position
uint32_t temp = (uint32_t) p_sp->at (index); void * temp = p_sp->at (index);
v->d->owner->writeWord(temp + v->d->race_offset, sp.race); v->d->owner->writeWord(temp + v->d->race_offset, sp.race);
v->d->owner->writeWord(temp + v->d->type_offset, sp.type); v->d->owner->writeWord(temp + v->d->type_offset, sp.type);

@ -54,22 +54,22 @@ struct World::Private
bool Inited; bool Inited;
bool PauseInited; bool PauseInited;
uint32_t pause_state_offset; void * pause_state_offset;
bool StartedTime; bool StartedTime;
uint32_t year_offset; void * year_offset;
uint32_t tick_offset; void * tick_offset;
bool StartedWeather; bool StartedWeather;
uint32_t weather_offset; void * weather_offset;
bool StartedMode; bool StartedMode;
uint32_t gamemode_offset; void * gamemode_offset;
uint32_t controlmode_offset; void * controlmode_offset;
uint32_t controlmodecopy_offset; void * controlmodecopy_offset;
bool StartedFolder; bool StartedFolder;
uint32_t folder_name_offset; void * folder_name_offset;
Process * owner; Process * owner;
}; };

@ -12,7 +12,6 @@ using namespace std;
#include "Types.h" #include "Types.h"
#include "VersionInfo.h" #include "VersionInfo.h"
#include "MemAccess.h" #include "MemAccess.h"
#include "Vector.h"
#include "modules/Materials.h" #include "modules/Materials.h"
#include "modules/Items.h" #include "modules/Items.h"
#include "modules/Units.h" #include "modules/Units.h"
@ -44,9 +43,9 @@ namespace Kitchen
std::vector<t_materialIndex>& materialIndices; // the material index vector of the kitchen exclusion list std::vector<t_materialIndex>& materialIndices; // the material index vector of the kitchen exclusion list
std::vector<t_exclusionType>& exclusionTypes; // the exclusion type vector of the kitchen excluions list std::vector<t_exclusionType>& exclusionTypes; // the exclusion type vector of the kitchen excluions list
static uint32_t addr(const DFHack::Core& core, int index) static void * addr(const DFHack::Core& core, int index)
{ {
static uint32_t start = core.vinfo->getAddress("kitchen_limits"); static void * start = core.vinfo->getAddress("kitchen_limits");
return start + sizeof(std::vector<int>) * index; return start + sizeof(std::vector<int>) * index;
}; };
}; };

@ -15,20 +15,20 @@ public:
ANYBYTE=0x101,DWORD_,ANYDWORD,ADDRESS ANYBYTE=0x101,DWORD_,ANYDWORD,ADDRESS
}; };
Hexsearch(const SearchArgType &args,uint64_t startpos,uint64_t endpos); Hexsearch(const SearchArgType &args,void * startpos,void * endpos);
~Hexsearch(); ~Hexsearch();
void Reset(){pos_=startpos_;}; void Reset(){pos_=startpos_;};
void SetStart(uint64_t pos){pos_=pos;}; void SetStart(void * pos){pos_=pos;};
uint64_t FindNext(); void * FindNext();
std::vector<uint64_t> FindAll(); std::vector<void *> FindAll();
private: private:
bool Compare(int a,int b); bool Compare(int a,int b);
void ReparseArgs(); void ReparseArgs();
SearchArgType args_; SearchArgType args_;
uint64_t pos_,startpos_,endpos_; void * pos_,* startpos_,* endpos_;
std::vector<int> BadCharShifts,GoodSuffixShift; std::vector<int> BadCharShifts,GoodSuffixShift;
void PrepareGoodSuffixTable(); void PrepareGoodSuffixTable();
void PrepareBadCharShift(); void PrepareBadCharShift();

@ -1,7 +1,7 @@
#include "hexsearch.h" #include "hexsearch.h"
Hexsearch::Hexsearch(const SearchArgType &args,uint64_t startpos,uint64_t endpos):args_(args),pos_(startpos),startpos_(startpos),endpos_(endpos) Hexsearch::Hexsearch(const SearchArgType &args,void * startpos,void * endpos):args_(args),pos_(startpos),startpos_(startpos),endpos_(endpos)
{ {
ReparseArgs(); ReparseArgs();
} }
@ -52,7 +52,7 @@ void Hexsearch::ReparseArgs()
} }
} }
} }
uint64_t Hexsearch::FindNext() //TODO rewrite using Boyer-Moore algorithm void * Hexsearch::FindNext() //TODO rewrite using Boyer-Moore algorithm
{ {
DFHack::Core &inst=DFHack::Core::getInstance(); DFHack::Core &inst=DFHack::Core::getInstance();
DFHack::Process *p=inst.p; DFHack::Process *p=inst.p;
@ -81,16 +81,16 @@ uint64_t Hexsearch::FindNext() //TODO rewrite using Boyer-Moore algorithm
return pos_-args_.size(); return pos_-args_.size();
} }
} }
pos_++; pos_ = pos_ + 1;
} }
delete [] buf; delete [] buf;
return 0; return 0;
} }
std::vector<uint64_t> Hexsearch::FindAll() std::vector<void *> Hexsearch::FindAll()
{ {
std::vector<uint64_t> ret; std::vector<void *> ret;
uint64_t cpos=pos_; void * cpos=pos_;
while(cpos!=0) while(cpos!=0)
{ {
cpos=FindNext(); cpos=FindNext();

@ -2,14 +2,14 @@
int lua::Hexsearch::find(lua_State *L) int lua::Hexsearch::find(lua_State *L)
{ {
lua::state st(L); lua::state st(L);
uint64_t pos=p->FindNext(); void * pos=p->FindNext();
st.push(pos); st.push(pos);
return 1; return 1;
} }
int lua::Hexsearch::findall(lua_State *L) int lua::Hexsearch::findall(lua_State *L)
{ {
lua::state st(L); lua::state st(L);
std::vector<uint64_t> pos=p->FindAll(); std::vector<void *> pos=p->FindAll();
st.newtable(); st.newtable();
for(unsigned i=0;i<pos.size();i++) for(unsigned i=0;i<pos.size();i++)
{ {
@ -22,10 +22,10 @@ int lua::Hexsearch::findall(lua_State *L)
lua::Hexsearch::Hexsearch(lua_State *L,int id):tblid(id) lua::Hexsearch::Hexsearch(lua_State *L,int id):tblid(id)
{ {
lua::state st(L); lua::state st(L);
uint64_t start,end; void * start,* end;
::Hexsearch::SearchArgType args; ::Hexsearch::SearchArgType args;
start=st.as<uint32_t>(1); start= (void *)st.as<uint32_t>(1);
end=st.as<uint32_t>(2); end=(void *)st.as<uint32_t>(2);
for(int i=3;i<=st.gettop();i++) for(int i=3;i<=st.gettop();i++)
{ {
args.push_back(st.as<int>(i)); args.push_back(st.as<int>(i));

@ -32,7 +32,7 @@ static int LoadMod(lua_State *L)
buf=new char[size]; buf=new char[size];
f.GetText(buf); f.GetText(buf);
//std::cout<<"poking @:"<<std::hex<<pos<<"size :"<<size<<std::endl; //std::cout<<"poking @:"<<std::hex<<pos<<"size :"<<size<<std::endl;
DFHack::Core::getInstance().p->write(pos,size,(uint8_t*)buf); DFHack::Core::getInstance().p->write((void *) pos,size,(uint8_t*)buf);
delete [] buf; delete [] buf;
st.push(pos); st.push(pos);
st.push(size); st.push(size);

@ -14,7 +14,7 @@ static int lua_Process_readDWord(lua_State *S)
{ {
lua::state st(S); lua::state st(S);
DFHack::Process* c=GetProcessPtr(st); DFHack::Process* c=GetProcessPtr(st);
uint32_t ret=c->readDWord(st.as<uint32_t>(1)); uint32_t ret=c->readDWord( (void *) st.as<uint32_t>(1));
st.push(ret); st.push(ret);
return 1; return 1;
} }
@ -22,14 +22,14 @@ static int lua_Process_writeDWord(lua_State *S)
{ {
lua::state st(S); lua::state st(S);
DFHack::Process* c=GetProcessPtr(st); DFHack::Process* c=GetProcessPtr(st);
c->writeDWord(st.as<uint32_t>(1),st.as<uint32_t>(2)); c->writeDWord((void *) st.as<uint32_t>(1),st.as<uint32_t>(2));
return 0; return 0;
} }
static int lua_Process_readFloat(lua_State *S) static int lua_Process_readFloat(lua_State *S)
{ {
lua::state st(S); lua::state st(S);
DFHack::Process* c=GetProcessPtr(st); DFHack::Process* c=GetProcessPtr(st);
float ret=c->readFloat(st.as<uint32_t>(1)); float ret=c->readFloat((void *) st.as<uint32_t>(1));
st.push(ret); st.push(ret);
return 1; return 1;
} }
@ -38,7 +38,7 @@ static int lua_Process_readWord(lua_State *S)
{ {
lua::state st(S); lua::state st(S);
DFHack::Process* c=GetProcessPtr(st); DFHack::Process* c=GetProcessPtr(st);
uint16_t ret=c->readWord(st.as<uint32_t>(1)); uint16_t ret=c->readWord((void *) st.as<uint32_t>(1));
st.push(ret); st.push(ret);
return 1; return 1;
} }
@ -47,14 +47,14 @@ static int lua_Process_writeWord(lua_State *S)
{ {
lua::state st(S); lua::state st(S);
DFHack::Process* c=GetProcessPtr(st); DFHack::Process* c=GetProcessPtr(st);
c->writeWord(st.as<uint32_t>(1),st.as<uint16_t>(2)); c->writeWord((void *) st.as<uint32_t>(1),st.as<uint16_t>(2));
return 0; return 0;
} }
static int lua_Process_readByte(lua_State *S) static int lua_Process_readByte(lua_State *S)
{ {
lua::state st(S); lua::state st(S);
DFHack::Process* c=GetProcessPtr(st); DFHack::Process* c=GetProcessPtr(st);
uint8_t ret=c->readByte(st.as<uint32_t>(1)); uint8_t ret=c->readByte((void *) st.as<uint32_t>(1));
st.push(ret); st.push(ret);
return 1; return 1;
} }
@ -63,7 +63,7 @@ static int lua_Process_writeByte(lua_State *S)
{ {
lua::state st(S); lua::state st(S);
DFHack::Process* c=GetProcessPtr(st); DFHack::Process* c=GetProcessPtr(st);
c->writeByte(st.as<uint32_t>(1),st.as<uint8_t>(2)); c->writeByte((void *) st.as<uint32_t>(1),st.as<uint8_t>(2));
return 0; return 0;
} }
static int lua_Process_read(lua_State *S) static int lua_Process_read(lua_State *S)
@ -77,7 +77,7 @@ static int lua_Process_read(lua_State *S)
buf=(uint8_t*)lua_touserdata(st,3); buf=(uint8_t*)lua_touserdata(st,3);
else else
buf=new uint8_t[len]; buf=new uint8_t[len];
c->read(st.as<uint32_t>(1),len,buf); c->read((void *) st.as<uint32_t>(1),len,buf);
st.pushlightuserdata(buf); st.pushlightuserdata(buf);
return 1; return 1;
} }
@ -85,14 +85,14 @@ static int lua_Process_write(lua_State *S)
{ {
lua::state st(S); lua::state st(S);
DFHack::Process* c=GetProcessPtr(st); DFHack::Process* c=GetProcessPtr(st);
c-> write(st.as<uint32_t>(1),st.as<uint32_t>(2),static_cast<uint8_t*>(lua_touserdata(st,3))); c-> write((void *) st.as<uint32_t>(1),st.as<uint32_t>(2),static_cast<uint8_t*>(lua_touserdata(st,3)));
return 0; return 0;
} }
static int lua_Process_readSTLString (lua_State *S) static int lua_Process_readSTLString (lua_State *S)
{ {
lua::state st(S); lua::state st(S);
DFHack::Process* c=GetProcessPtr(st); DFHack::Process* c=GetProcessPtr(st);
std::string r=c->readSTLString(st.as<uint32_t>(1)); std::string r=c->readSTLString((void *) st.as<uint32_t>(1));
st.push(r); st.push(r);
return 1; return 1;
} }
@ -101,14 +101,14 @@ static int lua_Process_writeSTLString(lua_State *S)
{ {
lua::state st(S); lua::state st(S);
DFHack::Process* c=GetProcessPtr(st); DFHack::Process* c=GetProcessPtr(st);
c->writeSTLString(st.as<uint32_t>(1),st.as<std::string>(2)); c->writeSTLString((void *) st.as<uint32_t>(1),st.as<std::string>(2));
return 0; return 0;
} }
static int lua_Process_copySTLString(lua_State *S) static int lua_Process_copySTLString(lua_State *S)
{ {
lua::state st(S); lua::state st(S);
DFHack::Process* c=GetProcessPtr(st); DFHack::Process* c=GetProcessPtr(st);
c->copySTLString(st.as<uint32_t>(1),st.as<uint32_t>(2)); c->copySTLString((void *) st.as<uint32_t>(1),st.as<uint32_t>(2));
return 0; return 0;
} }
static int lua_Process_doReadClassName(lua_State *S) static int lua_Process_doReadClassName(lua_State *S)
@ -131,7 +131,7 @@ static int lua_Process_readCString (lua_State *S)
{ {
lua::state st(S); lua::state st(S);
DFHack::Process* c=GetProcessPtr(st); DFHack::Process* c=GetProcessPtr(st);
std::string r=c->readCString(st.as<uint32_t>(1)); std::string r=c->readCString((void *) st.as<uint32_t>(1));
st.push(r); st.push(r);
return 1; return 1;
} }
@ -226,10 +226,10 @@ static int lua_Process_setPermisions(lua_State *S)
DFHack::t_memrange range,trange; DFHack::t_memrange range,trange;
st.getfield("start",1); st.getfield("start",1);
range.start=st.as<uint64_t>(); range.start= (void *)st.as<uint64_t>();
st.pop(); st.pop();
st.getfield("end",1); st.getfield("end",1);
range.end=st.as<uint64_t>(); range.end= (void *)st.as<uint64_t>();
st.pop(); st.pop();
st.getfield("read",2); st.getfield("read",2);

@ -16,7 +16,7 @@ int OffsetGroup::getOffset(lua_State *L)
int OffsetGroup::getAddress(lua_State *L) int OffsetGroup::getAddress(lua_State *L)
{ {
lua::state st(L); lua::state st(L);
uint32_t ret=p->getAddress(st.as<std::string>(1)); uint32_t ret= (uint32_t)p->getAddress(st.as<std::string>(1));
st.push(ret); st.push(ret);
return 1; return 1;
} }
@ -57,7 +57,7 @@ int OffsetGroup::getSafeOffset(lua_State *L)
int OffsetGroup::getSafeAddress(lua_State *L) int OffsetGroup::getSafeAddress(lua_State *L)
{ {
lua::state st(L); lua::state st(L);
uint32_t out; void * out;
bool ret=p->getSafeAddress(st.as<std::string>(1),out); bool ret=p->getSafeAddress(st.as<std::string>(1),out);
st.push(ret); st.push(ret);
st.push(out); st.push(out);
@ -286,7 +286,7 @@ static int __lua_resolveObjectToClassID(lua_State *S)
{ {
lua::state st(S); lua::state st(S);
int32_t ret; int32_t ret;
bool output=DFHack::Core::getInstance().vinfo->resolveObjectToClassID(st.as<uint32_t>(1),ret); bool output=DFHack::Core::getInstance().vinfo->resolveObjectToClassID((void *)st.as<uint32_t>(1),ret);
st.push(output); st.push(output);
st.push(ret); st.push(ret);
return 2; return 2;
@ -329,7 +329,7 @@ static int __lua_getOffset(lua_State *S)
static int __lua_getAddress(lua_State *S) static int __lua_getAddress(lua_State *S)
{ {
lua::state st(S); lua::state st(S);
uint32_t ret=DFHack::Core::getInstance().vinfo->getAddress(st.as<std::string>(1)); void * ret=DFHack::Core::getInstance().vinfo->getAddress(st.as<std::string>(1));
st.push(ret); st.push(ret);
return 1; return 1;
} }
@ -392,7 +392,7 @@ static int __lua_getSafeOffset(lua_State *S)
static int __lua_getSafeAddress(lua_State *S) static int __lua_getSafeAddress(lua_State *S)
{ {
lua::state st(S); lua::state st(S);
uint32_t out; void * out;
bool ret=DFHack::Core::getInstance().vinfo->getSafeAddress(st.as<std::string>(1),out); bool ret=DFHack::Core::getInstance().vinfo->getSafeAddress(st.as<std::string>(1),out);
st.push(ret); st.push(ret);
st.push(out); st.push(out);

@ -17,7 +17,7 @@ static tthread::mutex* mymutex=0;
struct memory_data struct memory_data
{ {
size_t addr; void * addr;
size_t len; size_t len;
size_t refresh; size_t refresh;
int state; int state;
@ -57,7 +57,7 @@ bool isAddr(uint32_t *trg,vector<t_memrange> & ranges)
{ {
if(trg[0]%4==0) if(trg[0]%4==0)
for(size_t i=0;i<ranges.size();i++) for(size_t i=0;i<ranges.size();i++)
if(ranges[i].isInRange(trg[0])) if(ranges[i].isInRange((void *)trg[0]))
return true; return true;
return false; return false;
@ -131,7 +131,7 @@ DFhackCExport command_result plugin_onupdate ( Core * c )
timeLast = time2; timeLast = time2;
c->p->read(memdata.addr,memdata.len,memdata.buf); c->p->read(memdata.addr,memdata.len,memdata.buf);
outputHex(memdata.buf,memdata.lbuf,memdata.len,memdata.addr,c,memdata.ranges); outputHex(memdata.buf,memdata.lbuf,memdata.len,(size_t)memdata.addr,c,memdata.ranges);
memcpy(memdata.lbuf, memdata.buf, memdata.len); memcpy(memdata.lbuf, memdata.buf, memdata.len);
if(memdata.refresh==0) if(memdata.refresh==0)
Deinit(); Deinit();
@ -143,7 +143,7 @@ DFhackCExport command_result memview (Core * c, vector <string> & parameters)
{ {
mymutex->lock(); mymutex->lock();
c->p->getMemRanges(memdata.ranges); c->p->getMemRanges(memdata.ranges);
memdata.addr=convert(parameters[0],true); memdata.addr=(void *)convert(parameters[0],true);
if(memdata.addr==0) if(memdata.addr==0)
{ {
Deinit(); Deinit();

@ -19,9 +19,9 @@ using namespace DFHack;
struct t_vecTriplet struct t_vecTriplet
{ {
uint32_t start; void * start;
uint32_t end; void * end;
uint32_t alloc_end; void * alloc_end;
}; };
DFhackCExport command_result df_vectors (Core * c, DFhackCExport command_result df_vectors (Core * c,
@ -74,7 +74,7 @@ static bool mightBeVec(vector<t_memrange> &heap_ranges,
// Vector length might not be a multiple of 4 if, for example, // Vector length might not be a multiple of 4 if, for example,
// it's a vector of uint8_t or uint16_t. However, the actual memory // it's a vector of uint8_t or uint16_t. However, the actual memory
// allocated to the vector should be 4 byte aligned. // allocated to the vector should be 4 byte aligned.
if ((vec->start % 4 != 0) || (vec->alloc_end % 4 != 0)) if (((int)vec->start % 4 != 0) || ((int)vec->alloc_end % 4 != 0))
return false; return false;
for (size_t i = 0; i < heap_ranges.size(); i++) for (size_t i = 0; i < heap_ranges.size(); i++)
@ -88,7 +88,7 @@ static bool mightBeVec(vector<t_memrange> &heap_ranges,
return false; return false;
} }
static bool inAnyRange(vector<t_memrange> &ranges, uint32_t ptr) static bool inAnyRange(vector<t_memrange> &ranges, void * ptr)
{ {
for (size_t i = 0; i < ranges.size(); i++) for (size_t i = 0; i < ranges.size(); i++)
{ {
@ -141,7 +141,7 @@ static void vectorsUsage(Console &con)
static void printVec(Console &con, const char* msg, t_vecTriplet *vec, static void printVec(Console &con, const char* msg, t_vecTriplet *vec,
uint32_t start, uint32_t pos) uint32_t start, uint32_t pos)
{ {
uint32_t length = vec->end - vec->start; uint32_t length = (int)vec->end - (int)vec->start;
uint32_t offset = pos - start; uint32_t offset = pos - start;
con.print("%8s offset %06p, addr %010p, start %010p, length %u\n", con.print("%8s offset %06p, addr %010p, start %010p, length %u\n",
@ -193,15 +193,15 @@ DFhackCExport command_result df_vectors (Core * c, vector <string> & parameters)
{ {
t_memrange &range = heap_ranges[i]; t_memrange &range = heap_ranges[i];
if (!range.isInRange(start)) if (!range.isInRange((void *)start))
continue; continue;
// Found the range containing the start // Found the range containing the start
if (!range.isInRange(end)) if (!range.isInRange((void *)end))
{ {
con.print("Scanning %u bytes would read past end of memory " con.print("Scanning %u bytes would read past end of memory "
"range.\n", bytes); "range.\n", bytes);
uint32_t diff = end - range.end; uint32_t diff = end - (int)range.end;
con.print("Cutting bytes down by %u.\n", diff); con.print("Cutting bytes down by %u.\n", diff);
end = (uint32_t) range.end; end = (uint32_t) range.end;
@ -242,7 +242,7 @@ DFhackCExport command_result df_vectors (Core * c, vector <string> & parameters)
{ {
uint32_t ptr = * ( (uint32_t*) pos); uint32_t ptr = * ( (uint32_t*) pos);
if (inAnyRange(heap_ranges, ptr)) if (inAnyRange(heap_ranges, (void *) ptr))
{ {
t_vecTriplet* vec = (t_vecTriplet*) ptr; t_vecTriplet* vec = (t_vecTriplet*) ptr;
@ -320,7 +320,7 @@ DFhackCExport command_result df_clearvec (Core * c, vector <string> & parameters
continue; continue;
} }
if (!inAnyRange(heap_ranges, addr)) if (!inAnyRange(heap_ranges, (void *) addr))
{ {
con << addr_str << " not in any valid address range." << std::endl; con << addr_str << " not in any valid address range." << std::endl;
continue; continue;
@ -338,7 +338,7 @@ DFhackCExport command_result df_clearvec (Core * c, vector <string> & parameters
addr = * ( (uint32_t*) addr); addr = * ( (uint32_t*) addr);
vec = (t_vecTriplet*) addr; vec = (t_vecTriplet*) addr;
if (inAnyRange(heap_ranges, addr) && mightBeVec(heap_ranges, vec)) if (inAnyRange(heap_ranges, (void *) addr) && mightBeVec(heap_ranges, vec))
{ {
valid = true; valid = true;
ptr = true; ptr = true;