Fix MSVC builds, break buildings :D

develop
Petr Mrázek 2012-01-05 23:39:14 +01:00
parent 86464b99cc
commit 78a98de37e
20 changed files with 123 additions and 148 deletions

@ -1,4 +1,5 @@
call "%VS100COMNTOOLS%vsvars32.bat" call "%VS100COMNTOOLS%vsvars32.bat"
cd VC2010 cd VC2010
msbuild /m /p:Platform=Win32 /p:Configuration=Release ALL_BUILD.vcxproj msbuild /m /p:Platform=Win32 /p:Configuration=Release ALL_BUILD.vcxproj
cd .. cd ..
pause

@ -111,8 +111,8 @@ Process::~Process()
string Process::doReadClassName (void * vptr) string Process::doReadClassName (void * vptr)
{ {
//FIXME: BAD!!!!! //FIXME: BAD!!!!!
void * typeinfo = Process::readPtr(vptr - 0x4); char * typeinfo = Process::readPtr(((char *)vptr - 0x4));
void * typestring = Process::readPtr(typeinfo + 0x4); char * 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();

@ -112,7 +112,7 @@ namespace DFHack
uint32_t my_pid; uint32_t my_pid;
IMAGE_NT_HEADERS pe_header; IMAGE_NT_HEADERS pe_header;
IMAGE_SECTION_HEADER * sections; IMAGE_SECTION_HEADER * sections;
uint32_t base; char * base;
}; };
} }
Process::Process(VersionInfoFactory * factory) Process::Process(VersionInfoFactory * factory)
@ -134,7 +134,7 @@ Process::Process(VersionInfoFactory * factory)
} }
// got base ;) // got base ;)
d->base = (uint32_t)hmod; d->base = (char *)hmod;
// read from this process // read from this process
try try
@ -161,7 +161,7 @@ Process::Process(VersionInfoFactory * factory)
identified = true; identified = true;
// give the process a data model and memory layout fixed for the base of first module // give the process a data model and memory layout fixed for the base of first module
my_descriptor = new VersionInfo(*vinfo); my_descriptor = new VersionInfo(*vinfo);
my_descriptor->RebaseAll(d->base); my_descriptor->RebaseAll((uint32_t)d->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
my_descriptor->setParentProcess(this); my_descriptor->setParentProcess(this);
for(size_t i = 0; i < threads_ids.size();i++) for(size_t i = 0; i < threads_ids.size();i++)
@ -236,7 +236,7 @@ struct HeapBlock
ULONG reserved; ULONG reserved;
}; };
*/ */
void HeapNodes(DWORD pid, map<uint64_t, unsigned int> & heaps) void HeapNodes(DWORD pid, map<char *, unsigned int> & heaps)
{ {
// Create debug buffer // Create debug buffer
PDEBUG_BUFFER db = RtlCreateQueryDebugBuffer(0, FALSE); PDEBUG_BUFFER db = RtlCreateQueryDebugBuffer(0, FALSE);
@ -247,7 +247,7 @@ void HeapNodes(DWORD pid, map<uint64_t, unsigned int> & heaps)
// Go through each of the heap nodes and dispaly the information // Go through each of the heap nodes and dispaly the information
for (unsigned int i = 0; i < heapNodeCount; i++) for (unsigned int i = 0; i < heapNodeCount; i++)
{ {
heaps[heapInfo[i].Base] = i; heaps[(char *)heapInfo[i].Base] = i;
} }
// Clean up the buffer // Clean up the buffer
RtlDestroyQueryDebugBuffer( db ); RtlDestroyQueryDebugBuffer( db );
@ -257,9 +257,9 @@ void HeapNodes(DWORD pid, map<uint64_t, unsigned int> & heaps)
void Process::getMemRanges( vector<t_memrange> & ranges ) void Process::getMemRanges( vector<t_memrange> & ranges )
{ {
MEMORY_BASIC_INFORMATION MBI; MEMORY_BASIC_INFORMATION MBI;
map<uint64_t, unsigned int> heaps; map<char *, unsigned int> heaps;
uint64_t movingStart = 0; uint64_t movingStart = 0;
map <uint64_t, string> nameMap; map <char *, string> nameMap;
// get page size // get page size
SYSTEM_INFO si; SYSTEM_INFO si;
@ -277,18 +277,18 @@ void Process::getMemRanges( vector<t_memrange> & ranges )
if( !(MBI.State & MEM_COMMIT) /*|| !(MBI.Type & MEM_PRIVATE)*/ ) if( !(MBI.State & MEM_COMMIT) /*|| !(MBI.Type & MEM_PRIVATE)*/ )
continue; continue;
t_memrange temp; t_memrange temp;
temp.start = (uint64_t) MBI.BaseAddress; temp.start = (char *) MBI.BaseAddress;
temp.end = ((uint64_t)MBI.BaseAddress + (uint64_t)MBI.RegionSize); temp.end = ((char *)MBI.BaseAddress + (uint64_t)MBI.RegionSize);
temp.read = MBI.Protect & PAGE_EXECUTE_READ || MBI.Protect & PAGE_EXECUTE_READWRITE || MBI.Protect & PAGE_READONLY || MBI.Protect & PAGE_READWRITE; temp.read = MBI.Protect & PAGE_EXECUTE_READ || MBI.Protect & PAGE_EXECUTE_READWRITE || MBI.Protect & PAGE_READONLY || MBI.Protect & PAGE_READWRITE;
temp.write = MBI.Protect & PAGE_EXECUTE_READWRITE || MBI.Protect & PAGE_READWRITE; temp.write = MBI.Protect & PAGE_EXECUTE_READWRITE || MBI.Protect & PAGE_READWRITE;
temp.execute = MBI.Protect & PAGE_EXECUTE_READ || MBI.Protect & PAGE_EXECUTE_READWRITE || MBI.Protect & PAGE_EXECUTE; temp.execute = MBI.Protect & PAGE_EXECUTE_READ || MBI.Protect & PAGE_EXECUTE_READWRITE || MBI.Protect & PAGE_EXECUTE;
temp.valid = true; temp.valid = true;
if(!GetModuleBaseName(d->my_handle, (HMODULE) temp.start, temp.name, 1024)) if(!GetModuleBaseName(d->my_handle, (HMODULE) temp.start, temp.name, 1024))
{ {
if(nameMap.count(temp.start)) if(nameMap.count((char *)temp.start))
{ {
// potential buffer overflow... // potential buffer overflow...
strcpy(temp.name, nameMap[temp.start].c_str()); strcpy(temp.name, nameMap[(char *)temp.start].c_str());
} }
else else
{ {
@ -298,9 +298,9 @@ void Process::getMemRanges( vector<t_memrange> & ranges )
else else
{ {
// could be a heap? // could be a heap?
if(heaps.count(temp.start)) if(heaps.count((char *)temp.start))
{ {
sprintf(temp.name,"HEAP %d",heaps[temp.start]); sprintf(temp.name,"HEAP %d",heaps[(char*)temp.start]);
} }
else temp.name[0]=0; else temp.name[0]=0;
} }
@ -320,7 +320,7 @@ void Process::getMemRanges( vector<t_memrange> & ranges )
nm.append(temp.name); nm.append(temp.name);
nm.append(" : "); nm.append(" : ");
nm.append(sectionName); nm.append(sectionName);
nameMap[temp.start + d->sections[i].VirtualAddress] = nm; nameMap[(char *)temp.start + d->sections[i].VirtualAddress] = nm;
} }
} }
else else
@ -333,14 +333,14 @@ void Process::getMemRanges( vector<t_memrange> & ranges )
uint32_t Process::getBase() uint32_t Process::getBase()
{ {
if(d) if(d)
return d->base; return (uint32_t) d->base;
return 0x400000; return 0x400000;
} }
string Process::doReadClassName (void * vptr) string Process::doReadClassName (void * vptr)
{ {
int rtti = readDWord((uint32_t)vptr - 0x4); char * rtti = readPtr((char *)vptr - 0x4);
int typeinfo = readDWord(rtti + 0xC); char * typeinfo = readPtr(rtti + 0xC);
string raw = readCString(typeinfo + 0xC); // skips the .?AV string raw = readCString(typeinfo + 0xC); // skips the .?AV
raw.resize(raw.length() - 2);// trim @@ from end raw.resize(raw.length() - 2);// trim @@ from end
return raw; return raw;
@ -367,7 +367,7 @@ bool Process::setPermisions(const t_memrange & range,const t_memrange &trgrange)
if(trgrange.read && trgrange.write && trgrange.execute)newprotect=PAGE_EXECUTE_READWRITE; if(trgrange.read && trgrange.write && trgrange.execute)newprotect=PAGE_EXECUTE_READWRITE;
DWORD oldprotect=0; DWORD oldprotect=0;
bool result; bool result;
result=VirtualProtect((LPVOID)range.start,range.end-range.start,newprotect,&oldprotect); result=VirtualProtect((LPVOID)range.start,(char *)range.end-(char *)range.start,newprotect,&oldprotect);
return result; return result;
} }

@ -158,8 +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 pair <INVAL_TYPE, char *> nullableBytePtr;
typedef map <string, nullableVoidPtr >::iterator voidptr_Iter; typedef map <string, nullableBytePtr >::iterator byteptr_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;
@ -168,7 +168,7 @@ namespace DFHack
class OffsetGroupPrivate class OffsetGroupPrivate
{ {
public: public:
map <string, nullableVoidPtr > addresses; map <string, nullableBytePtr > 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;
@ -185,7 +185,7 @@ void OffsetGroup::createOffset(const string & key)
void OffsetGroup::createAddress(const string & key) void OffsetGroup::createAddress(const string & key)
{ {
OGd->addresses[key] = nullableVoidPtr(NOT_SET, 0); OGd->addresses[key] = nullableBytePtr(NOT_SET, (char*) 0);
} }
void OffsetGroup::createHexValue(const string & key) void OffsetGroup::createHexValue(const string & key)
@ -229,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)
{ {
voidptr_Iter it = OGd->addresses.find(key); byteptr_Iter it = OGd->addresses.find(key);
if(it != OGd->addresses.end()) if(it != OGd->addresses.end())
{ {
void * address = (void *) strtol(value.c_str(), NULL, 16); char * address = (char *) 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;
@ -246,7 +246,7 @@ void OffsetGroup::setAddressValidity (const string & key, const INVAL_TYPE inval
{ {
if(inval != NOT_SET) if(inval != NOT_SET)
{ {
voidptr_Iter it = OGd->addresses.find(key); byteptr_Iter it = OGd->addresses.find(key);
if(it != OGd->addresses.end()) if(it != OGd->addresses.end())
{ {
(*it).second.first = inval; (*it).second.first = inval;
@ -307,9 +307,9 @@ void OffsetGroup::setStringValidity (const string & key, const INVAL_TYPE inval)
} }
// Get named address // Get named address
void * OffsetGroup::getAddress (const string & key) char * OffsetGroup::getAddress (const string & key)
{ {
voidptr_Iter iter = OGd->addresses.find(key); byteptr_Iter iter = OGd->addresses.find(key);
if(iter != OGd->addresses.end()) if(iter != OGd->addresses.end())
{ {
@ -325,7 +325,7 @@ void * 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, void * & out) bool OffsetGroup::getSafeAddress (const string & key, void * & out)
{ {
voidptr_Iter iter = OGd->addresses.find(key); byteptr_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;
@ -412,7 +412,7 @@ OffsetGroup * OffsetGroup::createGroup(const std::string &name)
void OffsetGroup::RebaseAddresses(int32_t offset) void OffsetGroup::RebaseAddresses(int32_t offset)
{ {
for(voidptr_Iter iter = OGd->addresses.begin(); iter != OGd->addresses.end(); iter++) for(byteptr_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;
@ -472,11 +472,11 @@ std::string OffsetGroup::getFullName()
std::string OffsetGroup::PrintOffsets(int indentation) std::string OffsetGroup::PrintOffsets(int indentation)
{ {
voidptr_Iter addriter; byteptr_Iter addriter;
uint32_Iter iter; uint32_Iter iter;
ostringstream ss; ostringstream ss;
indentr i(indentation); indentr i(indentation);
typedef pair <void *, pair< string, nullableVoidPtr > > horrible; typedef pair <void *, pair< string, nullableBytePtr > > horrible;
vector < horrible > addrsorter; vector < horrible > addrsorter;
for(addriter = OGd->addresses.begin(); addriter != OGd->addresses.end(); addriter++) for(addriter = OGd->addresses.begin(); addriter != OGd->addresses.end(); addriter++)
{ {
@ -572,7 +572,7 @@ void OffsetGroup::setInvalid(INVAL_TYPE invalidity)
if(invalidity == NOT_SET) if(invalidity == NOT_SET)
return; return;
voidptr_Iter iter; byteptr_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)
@ -607,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(voidptr_Iter iter = OGd->addresses.begin(); iter != OGd->addresses.end(); iter++) for(byteptr_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;
@ -1019,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 void * address, int32_t & classid) bool VersionInfo::resolveObjectToClassID(const char * 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

@ -136,14 +136,14 @@ namespace DFHack
}; };
/// read a pointer /// read a pointer
void * readPtr(const void * address) char * readPtr(const void * address)
{ {
return *(void **)address; return *(char **)address;
} }
/// read a pointer /// read a pointer
void readPtr(const void * address, void * & value) void readPtr(const void * address, char * & value)
{ {
value = *(void **)address; value = *(char **)address;
}; };
/// read a float /// read a float

@ -88,7 +88,7 @@ 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);
void * getAddress (const std::string & key); char * 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 );
@ -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 void * address, int32_t & classID); bool resolveObjectToClassID (const char * 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,8 +42,6 @@ namespace DFHack
*/ */
struct t_building struct t_building
{ {
void * origin;
uint32_t vtable;
uint32_t x1; uint32_t x1;
uint32_t y1; uint32_t y1;
uint32_t x2; uint32_t x2;
@ -51,7 +49,8 @@ namespace DFHack
uint32_t z; uint32_t z;
t_matglossPair material; t_matglossPair material;
uint32_t type; uint32_t type;
// FIXME: not complete, we need building presence bitmaps for stuff like farm plots and stockpiles, orientation (N,E,S,W) and state (open/closed) int32_t custom_type;
void * origin;
}; };
#ifdef __cplusplus #ifdef __cplusplus

@ -76,7 +76,7 @@ namespace DFHack
private: private:
Vermin* v; Vermin* v;
std::vector <void*> * p_sp; std::vector <char*> * p_sp;
friend class Vermin; friend class Vermin;
}; };

@ -39,6 +39,17 @@ using namespace std;
#include "Core.h" #include "Core.h"
using namespace DFHack; using namespace DFHack;
#include "DataDefs.h"
#include "df/world.h"
#include "df/world_raws.h"
#include "df/building_def.h"
#include "df/building.h"
#include "df/building_workshopst.h"
using namespace df::enums;
using df::global::world;
using df::building_def;
//raw //raw
struct t_building_df40d struct t_building_df40d
{ {
@ -57,16 +68,10 @@ struct t_building_df40d
struct Buildings::Private struct Buildings::Private
{ {
vector <void *> * custom_workshop_vector;
uint32_t building_custom_workshop_type;
uint32_t custom_workshop_type;
uint32_t custom_workshop_name;
int32_t custom_workshop_id;
vector <t_building_df40d *> * p_bld;
Process * owner; Process * owner;
bool Inited; bool Inited;
bool hasCustomWorkshops;
bool Started; bool Started;
int32_t custom_workshop_id;
}; };
Module* DFHack::createBuildings() Module* DFHack::createBuildings()
@ -78,37 +83,10 @@ Buildings::Buildings()
{ {
Core & c = Core::getInstance(); Core & c = Core::getInstance();
d = new Private; d = new Private;
d->p_bld = NULL; d->Started = false;
d->Inited = d->Started = d->hasCustomWorkshops = false;
VersionInfo * mem = c.vinfo;
d->owner = c.p; d->owner = c.p;
OffsetGroup * OG_build = mem->getGroup("Buildings");
d->Inited = true; d->Inited = true;
try c.vinfo->resolveClassnameToClassID("building_custom_workshop", d->custom_workshop_id);
{
d->p_bld = (decltype(d->p_bld)) OG_build->getAddress ("buildings_vector");
}
catch(DFHack::Error::AllMemdef &e)
{
cerr << "Buildings not available... " << e.what() << endl;
d->Inited = false;
}
if(d->Inited)
{
try
{
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->custom_workshop_type = OG_build->getOffset("custom_workshop_type");
d->custom_workshop_name = OG_build->getOffset("custom_workshop_name");
mem->resolveClassnameToClassID("building_custom_workshop", d->custom_workshop_id);
d->hasCustomWorkshops = true;
}
catch(DFHack::Error::AllMemdef &e)
{
cerr << "Custom workshops not available. Memory Definition: " << e.what() << endl;
}
}
} }
Buildings::~Buildings() Buildings::~Buildings()
@ -122,7 +100,7 @@ bool Buildings::Start(uint32_t & numbuildings)
{ {
if(!d->Inited) if(!d->Inited)
return false; return false;
numbuildings = d->p_bld->size(); numbuildings = world->buildings.all.size();
d->Started = true; d->Started = true;
return true; return true;
} }
@ -131,20 +109,20 @@ 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 = d->p_bld->at (index); df::building *bld_40d = world->buildings.all[index];
// transform // transform
int32_t type = -1; int32_t type = -1;
d->owner->getDescriptor()->resolveObjectToClassID (bld_40d, type); d->owner->getDescriptor()->resolveObjectToClassID ( (char *)bld_40d, type);
building.origin = bld_40d;
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.index = bld_40d->materialIndex;
building.material.type = bld_40d->materialType;
building.type = type; building.type = type;
building.origin = (void *) &bld_40d;
return true; return true;
} }
@ -158,38 +136,35 @@ bool Buildings::ReadCustomWorkshopTypes(map <uint32_t, string> & btypes)
{ {
if(!d->Inited) if(!d->Inited)
return false; return false;
if(!d->hasCustomWorkshops) Core & c = Core::getInstance();
return false;
Process * p = d->owner; Process * p = d->owner;
uint32_t size = d->custom_workshop_vector->size(); vector <building_def *> & bld_def = world->raws.buildings.all;
uint32_t size = bld_def.size();
btypes.clear(); btypes.clear();
for (uint32_t i = 0; i < size;i++) c.con.print("Probing vector at 0x%x for custom workshops.\n", &bld_def);
for (auto iter = bld_def.begin(); iter != bld_def.end();iter++)
{ {
void * obj = d->custom_workshop_vector->at(i); building_def * temp = *iter;
string out = p->readSTLString (obj + d->custom_workshop_name); btypes[temp->id] = temp->code;
uint32_t type = p->readDWord (obj + d->custom_workshop_type); c.con.print("%d : %s\n",temp->id, temp->code.c_str());
#ifdef DEBUG
cout << out << ": " << type << endl;
#endif
btypes[type] = out;
} }
return true; return true;
} }
// FIXME: ugly hack
int32_t Buildings::GetCustomWorkshopType(t_building & building) int32_t Buildings::GetCustomWorkshopType(t_building & building)
{ {
if(!d->Inited) if(!d->Inited)
return false; return false;
if(!d->hasCustomWorkshops)
return false;
int32_t type = (int32_t)building.type; int32_t type = (int32_t)building.type;
int32_t ret = -1; int32_t ret = -1;
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) d->owner->readDWord(building.origin + d->building_custom_workshop_type); df::building_workshopst * workshop = (df::building_workshopst *) building.origin;
ret = workshop->custom_type;
} }
return ret; return ret;
} }

@ -95,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
void * world_data; char * 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;
@ -141,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 = (void *) OG_Maps->getAddress("world_data"); off.world_data = 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");
@ -507,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;
void * base = 0; char * base = 0;
void * global_feature_vector = 0; char * global_feature_vector = 0;
void * world = p->readPtr( (void *) off.world_data); char * world = p->readPtr( (void *) off.world_data);
if(!world) return false; if(!world) return false;
base = p->readPtr(world + off.local_f_start); base = p->readPtr(world + off.local_f_start);
global_feature_vector = p->readDWord(off.world_data) + (void *) off.global_vector; global_feature_vector = p->readPtr(off.world_data) + off.global_vector;
// deref pointer to the humongo-structure // deref pointer to the humongo-structure
if(!base) if(!base)
@ -548,19 +548,19 @@ 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:
void * mega_column = p->readPtr(base + bigregion_x * 4); char * 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
void * loc_f_array16x16 = p->readPtr(mega_column + offset_elem + (sizeof_elem * bigregion_y)); char * loc_f_array16x16 = p->readPtr(mega_column + offset_elem + (sizeof_elem * bigregion_y));
if(loc_f_array16x16) if(loc_f_array16x16)
{ {
vector <void *> * p_features = (vector <void *> *) (loc_f_array16x16 + sizeof_16vec * sub_x + sizeof_vec * sub_y); vector <char *> * p_features = (vector <char *> *) (loc_f_array16x16 + sizeof_16vec * sub_x + sizeof_vec * sub_y);
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++)
{ {
void * cur_ptr = p_features->at(i); char * cur_ptr = p_features->at(i);
map <void *, 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);
@ -609,14 +609,14 @@ 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;
vector <void *> * p_features = (vector <void *> *) global_feature_vector; vector <char *> * p_features = (vector <char *> *) 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;
void * feat_ptr = p->readPtr(p_features->at(i) + global_feature_funcptr ); char * feat_ptr = p->readPtr(p_features->at(i) + global_feature_funcptr );
temp.origin = feat_ptr; temp.origin = feat_ptr;
temp.discovered = false; temp.discovered = false;
@ -892,18 +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;
void *regions; char *regions;
void *geoblocks_vector_addr; char *geoblocks_vector_addr;
Private::t_offsets &off = d->offsets; Private::t_offsets &off = d->offsets;
// get world size // get world size
void * world = p->readPtr(off.world_data); char * 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->readPtr ( 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
vector <void *> & geoblocks = *(vector <void *> *)(geoblocks_vector_addr); vector <char *> & geoblocks = *(vector <char *> *)(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++)
@ -922,7 +922,7 @@ 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
void * geoX; char * geoX;
p->readPtr (regions + bioRX*4, geoX); p->readPtr (regions + bioRX*4, geoX);
// get index into geoblock vector // get index into geoblock vector
@ -932,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
void * geoblock_off = geoblocks[geoindex]; char * 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
vector <void *> & geolayers = *(vector <void *> *)(geoblock_off + off.geolayer_geoblock_offset); vector <char *> & geolayers = *(vector <char *> *)(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);
@ -946,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
void * geol_offset = geolayers[j]; char * 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));
} }

@ -184,7 +184,7 @@ bool Materials::ReadCreatureTypes (void)
bool Materials::ReadOthers(void) bool Materials::ReadOthers(void)
{ {
Process * p = d->owner; Process * p = d->owner;
void * matBase = d->OG_Materials->getAddress ("other"); char * matBase = d->OG_Materials->getAddress ("other");
uint32_t i = 0; uint32_t i = 0;
std::string * ptr; std::string * ptr;
@ -207,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");
vector <void *> & p_colors = *(vector<void*> *) OG_Descriptors->getAddress ("colors_vector"); vector <char *> & p_colors = *(vector<char*> *) OG_Descriptors->getAddress ("colors_vector");
uint32_t size = p_colors.size(); uint32_t size = p_colors.size();
color.clear(); color.clear();
@ -236,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");
vector <void *> & p_races = *(vector<void*> *) OG_Mats->getAddress ("creature_type_vector"); vector <char *> & p_races = *(vector<char*> *) 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");
@ -286,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 );
vector <void *> & p_castes = *(vector<void*> *) (p_races[i] + castes_vector_offset); vector <char *> & p_castes = *(vector<char*> *) (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;
void * caste_start = p_castes[j]; char * 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);
@ -302,7 +302,7 @@ bool Materials::ReadCreatureTypesEx (void)
{ {
/* color mod reading */ /* color mod reading */
// Caste + offset > color mod vector // Caste + offset > color mod vector
vector <void *> & p_colormod = *(vector<void*> *) (caste_start + caste_colormod_offset); vector <char *> & p_colormod = *(vector<char*> *) (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++)
@ -319,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 */
vector <void *> & p_bodypart = *(vector<void*> *) (caste_start + caste_bodypart_offset); vector <char *> & p_bodypart = *(vector<char*> *) (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++)

@ -96,15 +96,15 @@ bool Translation::Start()
return false; return false;
Process * p = c.p; Process * p = c.p;
Finish(); Finish();
vector <void *> & genericVec = *(vector <void *> *) d->genericAddress; vector <char *> & genericVec = *(vector <char *> *) d->genericAddress;
vector <void *> & transVec = *(vector <void *> *) d->transAddress; vector <char *> & transVec = *(vector <char *> *) 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++)
{ {
void * genericNamePtr = genericVec[i]; char * 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);
@ -115,7 +115,7 @@ 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++)
{ {
void * transPtr = transVec.at(i); char * transPtr = transVec.at(i);
vector <void *> & trans_names_vec = *(vector <void *> *) (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++)
{ {

@ -119,7 +119,7 @@ SpawnPoints::SpawnPoints(Vermin* v_)
cerr << "Couldn't get spawn points: Vermin module not inited" << endl; cerr << "Couldn't get spawn points: Vermin module not inited" << endl;
return; return;
} }
p_sp = (vector <void*>*) (v->d->spawn_points_vector); p_sp = (vector <char*>*) (v->d->spawn_points_vector);
} }
SpawnPoints::~SpawnPoints() SpawnPoints::~SpawnPoints()
@ -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
void * temp = p_sp->at (index); char * 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
void * temp = p_sp->at (index); char * 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);

@ -61,7 +61,7 @@ struct World::Private
void * tick_offset; void * tick_offset;
bool StartedWeather; bool StartedWeather;
void * weather_offset; char * weather_offset;
bool StartedMode; bool StartedMode;
void * gamemode_offset; void * gamemode_offset;

@ -45,7 +45,7 @@ namespace Kitchen
static void * addr(const DFHack::Core& core, int index) static void * addr(const DFHack::Core& core, int index)
{ {
static void * start = core.vinfo->getAddress("kitchen_limits"); static char * start = core.vinfo->getAddress("kitchen_limits");
return start + sizeof(std::vector<int>) * index; return start + sizeof(std::vector<int>) * index;
}; };
}; };

@ -15,11 +15,11 @@ public:
ANYBYTE=0x101,DWORD_,ANYDWORD,ADDRESS ANYBYTE=0x101,DWORD_,ANYDWORD,ADDRESS
}; };
Hexsearch(const SearchArgType &args,void * startpos,void * endpos); Hexsearch(const SearchArgType &args,char * startpos,char * endpos);
~Hexsearch(); ~Hexsearch();
void Reset(){pos_=startpos_;}; void Reset(){pos_=startpos_;};
void SetStart(void * pos){pos_=pos;}; void SetStart(char * pos){pos_=pos;};
void * FindNext(); void * FindNext();
std::vector<void *> FindAll(); std::vector<void *> FindAll();
@ -28,7 +28,7 @@ private:
bool Compare(int a,int b); bool Compare(int a,int b);
void ReparseArgs(); void ReparseArgs();
SearchArgType args_; SearchArgType args_;
void * pos_,* startpos_,* endpos_; char * 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,void * startpos,void * endpos):args_(args),pos_(startpos),startpos_(startpos),endpos_(endpos) Hexsearch::Hexsearch(const SearchArgType &args,char * startpos,char * endpos):args_(args),pos_(startpos),startpos_(startpos),endpos_(endpos)
{ {
ReparseArgs(); ReparseArgs();
} }

@ -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);
void * start,* end; char * start,* end;
::Hexsearch::SearchArgType args; ::Hexsearch::SearchArgType args;
start= (void *)st.as<uint32_t>(1); start= (char *)st.as<uint32_t>(1);
end=(void *)st.as<uint32_t>(2); end=(char *)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));

@ -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((void *)st.as<uint32_t>(1),ret); bool output=DFHack::Core::getInstance().vinfo->resolveObjectToClassID((char *)st.as<uint32_t>(1),ret);
st.push(output); st.push(output);
st.push(ret); st.push(ret);
return 2; return 2;

@ -1 +1 @@
Subproject commit 1b28039e2c93daa3c2f69f5e2a000ff8c96ee1f8 Subproject commit 45b11988bccfeb059f55ded6e4ad0d317e802714