Visual Studio compatibility patch from jifodus

develop
Petr Mrázek 2009-10-04 13:08:20 +00:00
parent e85df7cfc0
commit 8e72f2af0e
23 changed files with 1579 additions and 1355 deletions

@ -1,63 +1,63 @@
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
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.
*/
#ifndef DFCOMMON_H_INCLUDED
#define DFCOMMON_H_INCLUDED
///TODO: separate into extrenal and internal
#include <string>
#include <vector>
#include <map>
//#include <boost/bimap/bimap.hpp>
//using namespace boost::bimaps;
#include <fstream>
using namespace std;
#include <stdint.h>
#include <assert.h>
#include <string.h>
#ifdef LINUX_BUILD
#include <sys/types.h>
#include <sys/ptrace.h>
#include <dirent.h>
#else
#define WINVER 0x0500 // OpenThread(), PSAPI, Toolhelp32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winbase.h>
#include <winnt.h>
#include <psapi.h>
#endif
#include "DFTypes.h"
#include "DFDataModel.h"
#include "DFProcessManager.h"
#include "DFMemAccess.h"
#include "DFVector.h"
//#include "DfMap.h"
#endif // DFCOMMON_H_INCLUDED
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
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.
*/
#ifndef DFCOMMON_H_INCLUDED
#define DFCOMMON_H_INCLUDED
///TODO: separate into extrenal and internal
#include <string>
#include <vector>
#include <map>
//#include <boost/bimap/bimap.hpp>
//using namespace boost::bimaps;
#include <fstream>
using namespace std;
#include <stdint.h>
#include <assert.h>
#include <string.h>
#ifdef LINUX_BUILD
#include <sys/types.h>
#include <sys/ptrace.h>
#include <dirent.h>
#else
#define WINVER 0x0500 // OpenThread(), PSAPI, Toolhelp32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winbase.h>
#include <winnt.h>
#include <psapi.h>
#endif
#include "DFTypes.h"
#include "DFDataModel.h"
#include "DFProcessManager.h"
#include "DFMemAccess.h"
#include "DFVector.h"
//#include "DfMap.h"
#endif // DFCOMMON_H_INCLUDED

@ -22,6 +22,8 @@ must not be misrepresented as being the original software.
distribution.
*/
#define BUILD_DFHACK_LIB
#include "DFCommon.h"

@ -1,54 +1,54 @@
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
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.
*/
#ifndef DATAMODEL_H_INCLUDED
#define DATAMODEL_H_INCLUDED
class DfVector;
// let's go pure virtual.
class DataModel
{
public:
// read a string
virtual const string readSTLString (uint32_t offset) = 0;
// read a vector from memory
virtual DfVector readVector (uint32_t offset, uint32_t item_size) = 0;
};
class DMWindows40d : public DataModel
{
virtual const string readSTLString (uint32_t offset);
// read a vector from memory
virtual DfVector readVector (uint32_t offset, uint32_t item_size);
};
class DMLinux40d : public DataModel
{
virtual const string readSTLString (uint32_t offset);
// read a vector from memory
virtual DfVector readVector (uint32_t offset, uint32_t item_size);
};
#endif // DATAMODEL_H_INCLUDED
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
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.
*/
#ifndef DATAMODEL_H_INCLUDED
#define DATAMODEL_H_INCLUDED
class DfVector;
// let's go pure virtual.
class DataModel
{
public:
// read a string
virtual const string readSTLString (uint32_t offset) = 0;
// read a vector from memory
virtual DfVector readVector (uint32_t offset, uint32_t item_size) = 0;
};
class DMWindows40d : public DataModel
{
virtual const string readSTLString (uint32_t offset);
// read a vector from memory
virtual DfVector readVector (uint32_t offset, uint32_t item_size);
};
class DMLinux40d : public DataModel
{
virtual const string readSTLString (uint32_t offset);
// read a vector from memory
virtual DfVector readVector (uint32_t offset, uint32_t item_size);
};
#endif // DATAMODEL_H_INCLUDED

@ -22,6 +22,8 @@ must not be misrepresented as being the original software.
distribution.
*/
#define BUILD_DFHACK_LIB
#include "DFCommon.h"
#include "DFVector.h"
#include "DFHackAPI.h"
@ -31,10 +33,18 @@ distribution.
matgloss other than stone/soil
*/
DFHACKAPI DFHackAPI *CreateDFHackAPI0(const char *path_to_xml)
{
return new DFHackAPIImpl(path_to_xml);
}
// TODO: templating for vectors, simple copy constructor for stl vectors
// TODO: encapsulate access to multidimensional arrays.
DFHackAPI::DFHackAPI(const string path_to_xml)
DFHackAPIImpl::DFHackAPIImpl(const string path_to_xml)
: block(NULL)
, pm(NULL), p(NULL), dm(NULL), offset_descriptor(NULL)
, p_cons(NULL), p_bld(NULL), p_veg(NULL)
{
xml = path_to_xml;
constructionsInited = false;
@ -47,7 +57,7 @@ DFHackAPI::DFHackAPI(const string path_to_xml)
/*-----------------------------------*
* Init the mapblock pointer array *
*-----------------------------------*/
bool DFHackAPI::InitMap()
bool DFHackAPIImpl::InitMap()
{
uint32_t map_loc, // location of the X array
temp_loc, // block location
@ -104,13 +114,24 @@ bool DFHackAPI::InitMap()
return true;
}
bool DFHackAPI::isValidBlock(uint32_t x, uint32_t y, uint32_t z)
bool DFHackAPIImpl::DestroyMap()
{
if (block != NULL)
{
delete [] block;
block = NULL;
}
return true;
}
bool DFHackAPIImpl::isValidBlock(uint32_t x, uint32_t y, uint32_t z)
{
return block[x*y_block_count*z_block_count + y*z_block_count + z] != NULL;
}
// 256 * sizeof(uint16_t)
bool DFHackAPI::ReadTileTypes(uint32_t x, uint32_t y, uint32_t z, uint16_t *buffer)
bool DFHackAPIImpl::ReadTileTypes(uint32_t x, uint32_t y, uint32_t z, uint16_t *buffer)
{
uint32_t addr = block[x*y_block_count*z_block_count + y*z_block_count + z];
if (addr!=NULL)
@ -123,7 +144,7 @@ bool DFHackAPI::ReadTileTypes(uint32_t x, uint32_t y, uint32_t z, uint16_t *buff
// 256 * sizeof(uint32_t)
bool DFHackAPI::ReadDesignations(uint32_t x, uint32_t y, uint32_t z, uint32_t *buffer)
bool DFHackAPIImpl::ReadDesignations(uint32_t x, uint32_t y, uint32_t z, uint32_t *buffer)
{
uint32_t addr = block[x*y_block_count*z_block_count + y*z_block_count + z];
if (addr!=NULL)
@ -136,7 +157,7 @@ bool DFHackAPI::ReadDesignations(uint32_t x, uint32_t y, uint32_t z, uint32_t *b
// 256 * sizeof(uint32_t)
bool DFHackAPI::ReadOccupancy(uint32_t x, uint32_t y, uint32_t z, uint32_t *buffer)
bool DFHackAPIImpl::ReadOccupancy(uint32_t x, uint32_t y, uint32_t z, uint32_t *buffer)
{
uint32_t addr = block[x*y_block_count*z_block_count + y*z_block_count + z];
if (addr!=NULL)
@ -149,7 +170,7 @@ bool DFHackAPI::ReadOccupancy(uint32_t x, uint32_t y, uint32_t z, uint32_t *buff
// 256 * sizeof(uint16_t)
bool DFHackAPI::WriteTileTypes(uint32_t x, uint32_t y, uint32_t z, uint16_t *buffer)
bool DFHackAPIImpl::WriteTileTypes(uint32_t x, uint32_t y, uint32_t z, uint16_t *buffer)
{
uint32_t addr = block[x*y_block_count*z_block_count + y*z_block_count + z];
if (addr!=NULL)
@ -162,7 +183,7 @@ bool DFHackAPI::WriteTileTypes(uint32_t x, uint32_t y, uint32_t z, uint16_t *buf
// 256 * sizeof(uint32_t)
bool DFHackAPI::WriteDesignations(uint32_t x, uint32_t y, uint32_t z, uint32_t *buffer)
bool DFHackAPIImpl::WriteDesignations(uint32_t x, uint32_t y, uint32_t z, uint32_t *buffer)
{
uint32_t addr = block[x*y_block_count*z_block_count + y*z_block_count + z];
if (addr!=NULL)
@ -175,7 +196,7 @@ bool DFHackAPI::WriteDesignations(uint32_t x, uint32_t y, uint32_t z, uint32_t *
// 256 * sizeof(uint32_t)
bool DFHackAPI::WriteOccupancy(uint32_t x, uint32_t y, uint32_t z, uint32_t *buffer)
bool DFHackAPIImpl::WriteOccupancy(uint32_t x, uint32_t y, uint32_t z, uint32_t *buffer)
{
uint32_t addr = block[x*y_block_count*z_block_count + y*z_block_count + z];
if (addr!=NULL)
@ -189,7 +210,7 @@ bool DFHackAPI::WriteOccupancy(uint32_t x, uint32_t y, uint32_t z, uint32_t *buf
//16 of them? IDK... there's probably just 7. Reading more doesn't cause errors as it's an array nested inside a block
// 16 * sizeof(uint8_t)
bool DFHackAPI::ReadRegionOffsets(uint32_t x, uint32_t y, uint32_t z, uint8_t *buffer)
bool DFHackAPIImpl::ReadRegionOffsets(uint32_t x, uint32_t y, uint32_t z, uint8_t *buffer)
{
uint32_t biome_stuffs = offset_descriptor->getOffset("biome_stuffs");
uint32_t addr = block[x*y_block_count*z_block_count + y*z_block_count + z];
@ -203,7 +224,7 @@ bool DFHackAPI::ReadRegionOffsets(uint32_t x, uint32_t y, uint32_t z, uint8_t *b
// veins of a block, expects empty vein vector
bool DFHackAPI::ReadVeins(uint32_t x, uint32_t y, uint32_t z, vector <t_vein> & veins)
bool DFHackAPIImpl::ReadVeins(uint32_t x, uint32_t y, uint32_t z, vector <t_vein> & veins)
{
uint32_t addr = block[x*y_block_count*z_block_count + y*z_block_count + z];
int veinvector = offset_descriptor->getOffset("v_vein");
@ -235,14 +256,14 @@ bool DFHackAPI::ReadVeins(uint32_t x, uint32_t y, uint32_t z, vector <t_vein> &
// getter for map size
void DFHackAPI::getSize(uint32_t& x, uint32_t& y, uint32_t& z)
void DFHackAPIImpl::getSize(uint32_t& x, uint32_t& y, uint32_t& z)
{
x = x_block_count;
y = y_block_count;
z = z_block_count;
}
bool DFHackAPI::ReadWoodMatgloss(vector<t_matgloss> & woods)
bool DFHackAPIImpl::ReadWoodMatgloss(vector<t_matgloss> & woods)
{
int matgloss_address = offset_descriptor->getAddress("matgloss");
// TODO: find flag for autumnal coloring?
@ -269,7 +290,7 @@ bool DFHackAPI::ReadWoodMatgloss(vector<t_matgloss> & woods)
return true;
}
bool DFHackAPI::ReadStoneMatgloss(vector<t_matgloss> & stones)
bool DFHackAPIImpl::ReadStoneMatgloss(vector<t_matgloss> & stones)
{
int matgloss_address = offset_descriptor->getAddress("matgloss");
int matgloss_offset = offset_descriptor->getHexValue("matgloss_skip");
@ -286,16 +307,16 @@ bool DFHackAPI::ReadStoneMatgloss(vector<t_matgloss> & stones)
// read the string pointed at by
t_matgloss mat;
mat.id = dm->readSTLString(temp); // reads a C string given an address
mat.fore = MreadWord(temp + matgloss_colors);
mat.back = MreadWord(temp + matgloss_colors + 2);
mat.bright = MreadWord(temp + matgloss_colors + 4);
mat.fore = (uint8_t)MreadWord(temp + matgloss_colors);
mat.back = (uint8_t)MreadWord(temp + matgloss_colors + 2);
mat.bright = (uint8_t)MreadWord(temp + matgloss_colors + 4);
stones.push_back(mat);
}
return true;
}
bool DFHackAPI::ReadMetalMatgloss(vector<t_matgloss> & metals)
bool DFHackAPIImpl::ReadMetalMatgloss(vector<t_matgloss> & metals)
{
int matgloss_address = offset_descriptor->getAddress("matgloss");
int matgloss_offset = offset_descriptor->getHexValue("matgloss_skip");
@ -314,15 +335,15 @@ bool DFHackAPI::ReadMetalMatgloss(vector<t_matgloss> & metals)
// read the string pointed at by
t_matgloss mat;
mat.id = dm->readSTLString(temp); // reads a C string given an address
mat.fore = MreadWord(temp + matgloss_colors);
mat.back = MreadWord(temp + matgloss_colors + 2);
mat.bright = MreadWord(temp + matgloss_colors + 4);
mat.fore = (uint8_t)MreadWord(temp + matgloss_colors);
mat.back = (uint8_t)MreadWord(temp + matgloss_colors + 2);
mat.bright = (uint8_t)MreadWord(temp + matgloss_colors + 4);
metals.push_back(mat);
}
return true;
}
bool DFHackAPI::ReadPlantMatgloss(vector<t_matgloss> & plants)
bool DFHackAPIImpl::ReadPlantMatgloss(vector<t_matgloss> & plants)
{
int matgloss_address = offset_descriptor->getAddress("matgloss");
int matgloss_offset = offset_descriptor->getHexValue("matgloss_skip");
@ -350,7 +371,7 @@ bool DFHackAPI::ReadPlantMatgloss(vector<t_matgloss> & plants)
}
//vector<uint16_t> v_geology[eBiomeCount];
bool DFHackAPI::ReadGeology( vector < vector <uint16_t> >& assign )
bool DFHackAPIImpl::ReadGeology( vector < vector <uint16_t> >& assign )
{
// get needed addresses and offsets
int region_x_offset = offset_descriptor->getAddress("region_x");
@ -445,7 +466,7 @@ bool DFHackAPI::ReadGeology( vector < vector <uint16_t> >& assign )
// returns number of buildings, expects v_buildingtypes that will later map t_building.type to its name
uint32_t DFHackAPI::InitReadBuildings(vector <string> &v_buildingtypes)
uint32_t DFHackAPIImpl::InitReadBuildings(vector <string> &v_buildingtypes)
{
buildingsInited = true;
int buildings = offset_descriptor->getAddress("buildings");
@ -457,7 +478,7 @@ uint32_t DFHackAPI::InitReadBuildings(vector <string> &v_buildingtypes)
// read one building
bool DFHackAPI::ReadBuilding(const uint32_t &index, t_building & building)
bool DFHackAPIImpl::ReadBuilding(const uint32_t &index, t_building & building)
{
assert(buildingsInited);
uint32_t temp;
@ -480,10 +501,12 @@ bool DFHackAPI::ReadBuilding(const uint32_t &index, t_building & building)
building.z = bld_40d.z;
building.material = bld_40d.material;
building.type = type;
return true;
}
void DFHackAPI::FinishReadBuildings()
void DFHackAPIImpl::FinishReadBuildings()
{
buildingsInited = false;
}
@ -491,7 +514,7 @@ void DFHackAPI::FinishReadBuildings()
//TODO: maybe do construction reading differently - this could go slow with many of them.
// returns number of constructions, prepares a vector, returns total number of constructions
uint32_t DFHackAPI::InitReadConstructions()
uint32_t DFHackAPIImpl::InitReadConstructions()
{
constructionsInited = true;
int constructions = offset_descriptor->getAddress("constructions");
@ -502,7 +525,7 @@ uint32_t DFHackAPI::InitReadConstructions()
}
bool DFHackAPI::ReadConstruction(const uint32_t &index, t_construction & construction)
bool DFHackAPIImpl::ReadConstruction(const uint32_t &index, t_construction & construction)
{
assert(constructionsInited);
t_construction_df40d c_40d;
@ -519,16 +542,18 @@ bool DFHackAPI::ReadConstruction(const uint32_t &index, t_construction & constru
construction.y = c_40d.y;
construction.z = c_40d.z;
construction.material = c_40d.material;
return true;
}
void DFHackAPI::FinishReadConstructions()
void DFHackAPIImpl::FinishReadConstructions()
{
constructionsInited = false;
}
uint32_t DFHackAPI::InitReadVegetation()
uint32_t DFHackAPIImpl::InitReadVegetation()
{
vegetationInited = true;
int vegetation = offset_descriptor->getAddress("vegetation");
@ -539,7 +564,7 @@ uint32_t DFHackAPI::InitReadVegetation()
}
bool DFHackAPI::ReadVegetation(const uint32_t &index, t_tree_desc & shrubbery)
bool DFHackAPIImpl::ReadVegetation(const uint32_t &index, t_tree_desc & shrubbery)
{
assert(vegetationInited);
uint32_t temp;
@ -549,16 +574,17 @@ bool DFHackAPI::ReadVegetation(const uint32_t &index, t_tree_desc & shrubbery)
Mread(temp + treeoffset, sizeof(t_tree_desc), (uint8_t *) &shrubbery);
// FIXME: this is completely wrong. type isn't just tree/shrub but also different kinds of trees. stuff that grows around ponds has its own type ID
if(shrubbery.material.type == 3) shrubbery.material.type = 2;
return true;
}
void DFHackAPI::FinishReadVegetation()
void DFHackAPIImpl::FinishReadVegetation()
{
vegetationInited = false;
}
bool DFHackAPI::Attach()
bool DFHackAPIImpl::Attach()
{
// detach all processes, destroy manager
if(pm != NULL)
@ -578,7 +604,7 @@ bool DFHackAPI::Attach()
// TODO: clean inited stuff here
bool DFHackAPI::Detach()
bool DFHackAPIImpl::Detach()
{
p->detach();
if(pm != NULL)
@ -589,3 +615,8 @@ bool DFHackAPI::Detach()
dm = NULL;
return true;
}
bool DFHackAPIImpl::isAttached()
{
return dm != NULL;
}

@ -1,160 +1,296 @@
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
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.
*/
#ifndef SIMPLEAPI_H_INCLUDED
#define SIMPLEAPI_H_INCLUDED
class memory_info;
class DfVector;
class ProcessManager;
class Process;
class DataModel;
//FIXME: better control over state, creation and destruction
//TODO: give this the pimpl treatment?
class DFHackAPI
{
private:
// internals
uint32_t * block;
uint32_t x_block_count, y_block_count, z_block_count;
uint32_t regionX, regionY, regionZ;
uint32_t worldSizeX, worldSizeY;
uint32_t tile_type_offset;
uint32_t designation_offset;
uint32_t occupancy_offset;
ProcessManager* pm;
Process* p;
DataModel* dm;
memory_info* offset_descriptor;
vector<uint16_t> v_geology[eBiomeCount];
string xml;
bool constructionsInited;
bool buildingsInited;
bool vegetationInited;
uint32_t treeoffset;
DfVector *p_cons;
DfVector *p_bld;
DfVector *p_veg;
public:
DFHackAPI(const string path_to_xml);
bool Attach();
bool Detach();
bool isAttached();
/**
* Matgloss. next four methods look very similar. I could use two and move the processing one level up...
* I'll keep it like this, even with the code duplication as it will hopefully get more features and separate data types later.
* Yay for nebulous plans for a rock survey tool that tracks how much of which metal could be smelted from available resorces
*/
bool ReadStoneMatgloss(vector<t_matgloss> & output);
bool ReadWoodMatgloss (vector<t_matgloss> & output);
bool ReadMetalMatgloss(vector<t_matgloss> & output);
bool ReadPlantMatgloss(vector<t_matgloss> & output);
// FIXME: add creatures for all the creature products
// read region surroundings, get their vectors of geolayers so we can do translation (or just hand the translation table to the client)
// returns an array of 9 vectors of indices into stone matgloss
/**
Method for reading the geological surrounding of the currently loaded region.
assign is a reference to an array of nine vectors of unsigned words that are to be filled with the data
array is indexed by the BiomeOffset enum
I omitted resolving the layer matgloss in this API, because it would
introduce overhead by calling some method for each tile. You have to do it
yourself. First get the stuff from ReadGeology and then for each block get
the RegionOffsets. For each tile get the real region from RegionOffsets and
cross-reference it with the geology stuff (region -- array of vectors, depth --
vector). I'm thinking about turning that Geology stuff into a
two-dimensional array with static size.
this is the algorithm for applying matgloss:
void DfMap::applyGeoMatgloss(Block * b)
{
// load layer matgloss
for(int x_b = 0; x_b < BLOCK_SIZE; x_b++)
{
for(int y_b = 0; y_b < BLOCK_SIZE; y_b++)
{
int geolayer = b->designation[x_b][y_b].bits.geolayer_index;
int biome = b->designation[x_b][y_b].bits.biome;
b->material[x_b][y_b].type = Mat_Stone;
b->material[x_b][y_b].index = v_geology[b->RegionOffsets[biome]][geolayer];
}
}
}
*/
bool ReadGeology( vector < vector <uint16_t> >& assign );
/*
* BLOCK DATA
*/
/// allocate and read pointers to map blocks
bool InitMap();
/// destroy the mapblock cache
bool DestroyMap();
/// get size of the map in tiles
void getSize(uint32_t& x, uint32_t& y, uint32_t& z);
/**
* Return false/0 on failure, buffer allocated by client app, 256 items long
*/
bool isValidBlock(uint32_t blockx, uint32_t blocky, uint32_t blockz);
bool ReadTileTypes(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint16_t *buffer); // 256 * sizeof(uint16_t)
bool WriteTileTypes(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint16_t *buffer); // 256 * sizeof(uint16_t)
bool ReadDesignations(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer); // 256 * sizeof(uint32_t)
bool WriteDesignations (uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer);
bool ReadOccupancy(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer); // 256 * sizeof(uint32_t)
bool WriteOccupancy(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer); // 256 * sizeof(uint32_t)
/// read region offsets of a block
bool ReadRegionOffsets(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint8_t *buffer); // 16 * sizeof(uint8_t)
/// read aggregated veins of a block
bool ReadVeins(uint32_t blockx, uint32_t blocky, uint32_t blockz, vector <t_vein> & veins);
/**
* Buildings, constructions, plants, all pretty straighforward. InitReadBuildings returns all the building types as a mapping between a numeric values and strings
*/
uint32_t InitReadConstructions();
bool ReadConstruction(const uint32_t &index, t_construction & construction);
void FinishReadConstructions();
uint32_t InitReadBuildings(vector <string> &v_buildingtypes);
bool ReadBuilding(const uint32_t &index, t_building & building);
void FinishReadBuildings();
uint32_t InitReadVegetation();
bool ReadVegetation(const uint32_t &index, t_tree_desc & shrubbery);
void FinishReadVegetation();
};
#endif // SIMPLEAPI_H_INCLUDED
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
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.
*/
#ifndef SIMPLEAPI_H_INCLUDED
#define SIMPLEAPI_H_INCLUDED
#ifdef LINUX_BUILD
# ifndef DFHACKAPI
# define DFHACKAPI
# endif
#else
# ifdef BUILD_DFHACK_LIB
# ifndef DFHACKAPI
# define DFHACKAPI extern "C" __declspec(dllexport)
# endif
# else
# ifndef DFHACKAPI
# define DFHACKAPI extern "C" __declspec(dllimport)
# endif
# endif
#endif
#include <string>
#include <vector>
#include <stdint.h>
using namespace std;
class DFHackAPI;
// Imported function for actually creating an instance
DFHACKAPI DFHackAPI *CreateDFHackAPI0(const char *path_to_xml);
// C++ wrapper for convenience
inline DFHackAPI *CreateDFHackAPI(const string &path_to_xml)
{
return CreateDFHackAPI0(path_to_xml.c_str());
}
// Technically the functions that use std::vector are unsafe.
class DFHackAPI
{
public:
virtual ~DFHackAPI() {}
virtual bool Attach() = 0;
virtual bool Detach() = 0;
virtual bool isAttached() = 0;
/**
* Matgloss. next four methods look very similar. I could use two and move the processing one level up...
* I'll keep it like this, even with the code duplication as it will hopefully get more features and separate data types later.
* Yay for nebulous plans for a rock survey tool that tracks how much of which metal could be smelted from available resorces
*/
virtual bool ReadStoneMatgloss(vector<t_matgloss> & output) = 0;
virtual bool ReadWoodMatgloss (vector<t_matgloss> & output) = 0;
virtual bool ReadMetalMatgloss(vector<t_matgloss> & output) = 0;
virtual bool ReadPlantMatgloss(vector<t_matgloss> & output) = 0;
// FIXME: add creatures for all the creature products
// read region surroundings, get their vectors of geolayers so we can do translation (or just hand the translation table to the client)
// returns an array of 9 vectors of indices into stone matgloss
/**
Method for reading the geological surrounding of the currently loaded region.
assign is a reference to an array of nine vectors of unsigned words that are to be filled with the data
array is indexed by the BiomeOffset enum
I omitted resolving the layer matgloss in this API, because it would
introduce overhead by calling some method for each tile. You have to do it
yourself. First get the stuff from ReadGeology and then for each block get
the RegionOffsets. For each tile get the real region from RegionOffsets and
cross-reference it with the geology stuff (region -- array of vectors, depth --
vector). I'm thinking about turning that Geology stuff into a
two-dimensional array with static size.
this is the algorithm for applying matgloss:
void DfMap::applyGeoMatgloss(Block * b)
{
// load layer matgloss
for(int x_b = 0; x_b < BLOCK_SIZE; x_b++)
{
for(int y_b = 0; y_b < BLOCK_SIZE; y_b++)
{
int geolayer = b->designation[x_b][y_b].bits.geolayer_index;
int biome = b->designation[x_b][y_b].bits.biome;
b->material[x_b][y_b].type = Mat_Stone;
b->material[x_b][y_b].index = v_geology[b->RegionOffsets[biome]][geolayer];
}
}
}
*/
virtual bool ReadGeology( vector < vector <uint16_t> >& assign ) = 0;
/*
* BLOCK DATA
*/
/// allocate and read pointers to map blocks
virtual bool InitMap() = 0;
/// destroy the mapblock cache
virtual bool DestroyMap() = 0;
/// get size of the map in tiles
virtual void getSize(uint32_t& x, uint32_t& y, uint32_t& z) = 0;
/**
* Return false/0 on failure, buffer allocated by client app, 256 items long
*/
virtual bool isValidBlock(uint32_t blockx, uint32_t blocky, uint32_t blockz) = 0;
virtual bool ReadTileTypes(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint16_t *buffer) = 0; // 256 * sizeof(uint16_t)
virtual bool WriteTileTypes(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint16_t *buffer) = 0; // 256 * sizeof(uint16_t)
virtual bool ReadDesignations(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer) = 0; // 256 * sizeof(uint32_t)
virtual bool WriteDesignations (uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer) = 0;
virtual bool ReadOccupancy(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer) = 0; // 256 * sizeof(uint32_t)
virtual bool WriteOccupancy(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer) = 0; // 256 * sizeof(uint32_t)
/// read region offsets of a block
virtual bool ReadRegionOffsets(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint8_t *buffer) = 0; // 16 * sizeof(uint8_t)
/// read aggregated veins of a block
virtual bool ReadVeins(uint32_t blockx, uint32_t blocky, uint32_t blockz, vector <t_vein> & veins) = 0;
/**
* Buildings, constructions, plants, all pretty straighforward. InitReadBuildings returns all the building types as a mapping between a numeric values and strings
*/
virtual uint32_t InitReadConstructions() = 0;
virtual bool ReadConstruction(const uint32_t &index, t_construction & construction) = 0;
virtual void FinishReadConstructions() = 0;
virtual uint32_t InitReadBuildings(vector <string> &v_buildingtypes) = 0;
virtual bool ReadBuilding(const uint32_t &index, t_building & building) = 0;
virtual void FinishReadBuildings() = 0;
virtual uint32_t InitReadVegetation() = 0;
virtual bool ReadVegetation(const uint32_t &index, t_tree_desc & shrubbery) = 0;
virtual void FinishReadVegetation() = 0;
};
#ifdef BUILD_DFHACK_LIB
class memory_info;
class DfVector;
class ProcessManager;
class Process;
class DataModel;
//FIXME: better control over state, creation and destruction
//TODO: give this the pimpl treatment?
class DFHackAPIImpl : public DFHackAPI
{
private:
// internals
uint32_t * block;
uint32_t x_block_count, y_block_count, z_block_count;
uint32_t regionX, regionY, regionZ;
uint32_t worldSizeX, worldSizeY;
uint32_t tile_type_offset;
uint32_t designation_offset;
uint32_t occupancy_offset;
ProcessManager* pm;
Process* p;
DataModel* dm;
memory_info* offset_descriptor;
vector<uint16_t> v_geology[eBiomeCount];
string xml;
bool constructionsInited;
bool buildingsInited;
bool vegetationInited;
uint32_t treeoffset;
DfVector *p_cons;
DfVector *p_bld;
DfVector *p_veg;
public:
DFHackAPIImpl(const string path_to_xml);
bool Attach();
bool Detach();
bool isAttached();
/**
* Matgloss. next four methods look very similar. I could use two and move the processing one level up...
* I'll keep it like this, even with the code duplication as it will hopefully get more features and separate data types later.
* Yay for nebulous plans for a rock survey tool that tracks how much of which metal could be smelted from available resorces
*/
bool ReadStoneMatgloss(vector<t_matgloss> & output);
bool ReadWoodMatgloss (vector<t_matgloss> & output);
bool ReadMetalMatgloss(vector<t_matgloss> & output);
bool ReadPlantMatgloss(vector<t_matgloss> & output);
// FIXME: add creatures for all the creature products
// read region surroundings, get their vectors of geolayers so we can do translation (or just hand the translation table to the client)
// returns an array of 9 vectors of indices into stone matgloss
/**
Method for reading the geological surrounding of the currently loaded region.
assign is a reference to an array of nine vectors of unsigned words that are to be filled with the data
array is indexed by the BiomeOffset enum
I omitted resolving the layer matgloss in this API, because it would
introduce overhead by calling some method for each tile. You have to do it
yourself. First get the stuff from ReadGeology and then for each block get
the RegionOffsets. For each tile get the real region from RegionOffsets and
cross-reference it with the geology stuff (region -- array of vectors, depth --
vector). I'm thinking about turning that Geology stuff into a
two-dimensional array with static size.
this is the algorithm for applying matgloss:
void DfMap::applyGeoMatgloss(Block * b)
{
// load layer matgloss
for(int x_b = 0; x_b < BLOCK_SIZE; x_b++)
{
for(int y_b = 0; y_b < BLOCK_SIZE; y_b++)
{
int geolayer = b->designation[x_b][y_b].bits.geolayer_index;
int biome = b->designation[x_b][y_b].bits.biome;
b->material[x_b][y_b].type = Mat_Stone;
b->material[x_b][y_b].index = v_geology[b->RegionOffsets[biome]][geolayer];
}
}
}
*/
bool ReadGeology( vector < vector <uint16_t> >& assign );
/*
* BLOCK DATA
*/
/// allocate and read pointers to map blocks
bool InitMap();
/// destroy the mapblock cache
bool DestroyMap();
/// get size of the map in tiles
void getSize(uint32_t& x, uint32_t& y, uint32_t& z);
/**
* Return false/0 on failure, buffer allocated by client app, 256 items long
*/
bool isValidBlock(uint32_t blockx, uint32_t blocky, uint32_t blockz);
bool ReadTileTypes(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint16_t *buffer); // 256 * sizeof(uint16_t)
bool WriteTileTypes(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint16_t *buffer); // 256 * sizeof(uint16_t)
bool ReadDesignations(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer); // 256 * sizeof(uint32_t)
bool WriteDesignations (uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer);
bool ReadOccupancy(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer); // 256 * sizeof(uint32_t)
bool WriteOccupancy(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer); // 256 * sizeof(uint32_t)
/// read region offsets of a block
bool ReadRegionOffsets(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint8_t *buffer); // 16 * sizeof(uint8_t)
/// read aggregated veins of a block
bool ReadVeins(uint32_t blockx, uint32_t blocky, uint32_t blockz, vector <t_vein> & veins);
/**
* Buildings, constructions, plants, all pretty straighforward. InitReadBuildings returns all the building types as a mapping between a numeric values and strings
*/
uint32_t InitReadConstructions();
bool ReadConstruction(const uint32_t &index, t_construction & construction);
void FinishReadConstructions();
uint32_t InitReadBuildings(vector <string> &v_buildingtypes);
bool ReadBuilding(const uint32_t &index, t_building & building);
void FinishReadBuildings();
uint32_t InitReadVegetation();
bool ReadVegetation(const uint32_t &index, t_tree_desc & shrubbery);
void FinishReadVegetation();
};
#endif
#endif // SIMPLEAPI_H_INCLUDED

@ -1,34 +1,34 @@
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
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.
*/
#ifndef PROCESSUTIL_H_INCLUDED
#define PROCESSUTIL_H_INCLUDED
#ifdef LINUX_BUILD
#include "LinuxMemAccess.h"
#else
#include "WindowsMemAccess.h"
#endif
#endif // PROCESSUTIL_H_INCLUDED
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
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.
*/
#ifndef PROCESSUTIL_H_INCLUDED
#define PROCESSUTIL_H_INCLUDED
#ifdef LINUX_BUILD
#include "LinuxMemAccess.h"
#else
#include "WindowsMemAccess.h"
#endif
#endif // PROCESSUTIL_H_INCLUDED

@ -22,6 +22,8 @@ must not be misrepresented as being the original software.
distribution.
*/
#define BUILD_DFHACK_LIB
#include "DFCommon.h"
#include "DFMemInfo.h"
#include <stdlib.h>

@ -1,113 +1,113 @@
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
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.
*/
#ifndef MEMINFO_H_INCLUDED
#define MEMINFO_H_INCLUDED
class memory_info
{
public:
enum OSType
{
OS_WINDOWS,
OS_LINUX,
OS_BAD
};
struct t_class
{
string classname;
uint32_t vtable;
bool is_multiclass;
uint32_t multi_index;
uint32_t assign;// index to typeclass array if multiclass. return value if not.
uint32_t type_offset; // offset of type data for multiclass
};
struct t_type
{
string classname;
uint32_t assign;
uint32_t type;
};
memory_info();
memory_info(const memory_info&);
void RebaseAddresses(int32_t new_base);
void RebaseAll(int32_t new_base);
uint32_t getBase ();
void setBase (string);
void setBase (uint32_t);
uint32_t getOffset (string);
uint32_t getAddress (string);
uint32_t getHexValue (string);
string getString (string);
void setVersion(const char *);
void setVersion(string);
string getVersion();
void setOS(const char *);
void setOS(string);
void setOS(OSType);
OSType getOS();
void setOffset (string, int32_t);
void setAddress (string, uint32_t);
void setHexValue (string, uint32_t);
void setOffset (string, const char *);
void setAddress (string, const char *);
void setHexValue (string, const char *);
void setString (string, const char *);
void setOffset (string, string);
void setAddress (string, string);
void setHexValue (string, string);
void setString (string, string);
void RebaseVTable(int32_t offset);
void setClass (const char * name, const char * vtable);
uint32_t setMultiClass (const char * name, const char * vtable, const char * typeoffset);
void setMultiClassChild (uint32_t multi_index, const char * name, const char * type);
// ALERT: uses memory reading directly
bool resolveClassId(uint32_t address, int32_t & classid);
void copyBuildings(vector<string> & v_buildingtypes);
void flush();
private:
map <string, uint32_t> addresses;
map <string, uint32_t> offsets;
map <string, uint32_t> hexvals;
map <string, string> strings;
vector<t_class> classes;
vector<vector<t_type> > classsubtypes;
int32_t base;
uint32_t classindex;
string version;
OSType OS;
};
#endif // MEMINFO_H_INCLUDED
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
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.
*/
#ifndef MEMINFO_H_INCLUDED
#define MEMINFO_H_INCLUDED
class memory_info
{
public:
enum OSType
{
OS_WINDOWS,
OS_LINUX,
OS_BAD
};
struct t_class
{
string classname;
uint32_t vtable;
bool is_multiclass;
uint32_t multi_index;
uint32_t assign;// index to typeclass array if multiclass. return value if not.
uint32_t type_offset; // offset of type data for multiclass
};
struct t_type
{
string classname;
uint32_t assign;
uint32_t type;
};
memory_info();
memory_info(const memory_info&);
void RebaseAddresses(int32_t new_base);
void RebaseAll(int32_t new_base);
uint32_t getBase ();
void setBase (string);
void setBase (uint32_t);
uint32_t getOffset (string);
uint32_t getAddress (string);
uint32_t getHexValue (string);
string getString (string);
void setVersion(const char *);
void setVersion(string);
string getVersion();
void setOS(const char *);
void setOS(string);
void setOS(OSType);
OSType getOS();
void setOffset (string, int32_t);
void setAddress (string, uint32_t);
void setHexValue (string, uint32_t);
void setOffset (string, const char *);
void setAddress (string, const char *);
void setHexValue (string, const char *);
void setString (string, const char *);
void setOffset (string, string);
void setAddress (string, string);
void setHexValue (string, string);
void setString (string, string);
void RebaseVTable(int32_t offset);
void setClass (const char * name, const char * vtable);
uint32_t setMultiClass (const char * name, const char * vtable, const char * typeoffset);
void setMultiClassChild (uint32_t multi_index, const char * name, const char * type);
// ALERT: uses memory reading directly
bool resolveClassId(uint32_t address, int32_t & classid);
void copyBuildings(vector<string> & v_buildingtypes);
void flush();
private:
map <string, uint32_t> addresses;
map <string, uint32_t> offsets;
map <string, uint32_t> hexvals;
map <string, string> strings;
vector<t_class> classes;
vector<vector<t_type> > classsubtypes;
int32_t base;
uint32_t classindex;
string version;
OSType OS;
};
#endif // MEMINFO_H_INCLUDED

@ -22,6 +22,8 @@ must not be misrepresented as being the original software.
distribution.
*/
#define BUILD_DFHACK_LIB
#include "DFCommon.h"
#ifdef LINUX_BUILD
#include <sys/wait.h>
@ -32,7 +34,7 @@ Process::Process(DataModel * dm, memory_info* mi, ProcessHandle ph, uint32_t pid
{
my_datamodel = dm;
my_descriptor = mi;
my_handle = ph;
my_handle = ph;
my_pid = pid;
attached = false;
}
@ -121,14 +123,14 @@ void Process::freeResources()
//FIXME: should support stopping and resuming the process
bool Process::attach()
{
if(attached)
{
return false;
}
{
if(attached)
{
return false;
}
/*
if(DebugActiveProcess(my_pid))
{
{
*/
attached = true;
g_pProcess = this;
@ -145,7 +147,7 @@ bool Process::detach()
if(!attached)
{
return false;
}
}
//TODO: find a safer way to suspend processes
/*if(DebugActiveProcessStop(my_pid))
{*/

@ -22,6 +22,8 @@ must not be misrepresented as being the original software.
distribution.
*/
#define BUILD_DFHACK_LIB
#include "DFCommon.h"
#include "DFDataModel.h"
@ -229,7 +231,7 @@ bool ProcessManager::findProcessess()
numProccesses = memoryNeeded / sizeof(DWORD);
// iterate through processes
for ( int i = 0; i < numProccesses; i++ )
for ( int i = 0; i < (int)numProccesses; i++ )
{
found = false;

@ -1,97 +1,97 @@
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
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.
*/
#ifndef PROCESSMANAGER_H_INCLUDED
#define PROCESSMANAGER_H_INCLUDED
#ifdef LINUX_BUILD
typedef pid_t ProcessHandle;
#else
typedef HANDLE ProcessHandle;
#endif
class memory_info;
class DataModel;
class TiXmlElement;
class Process;
/*
* Currently attached process and its handle
*/
extern Process * g_pProcess; ///< current process. non-NULL when picked
extern ProcessHandle g_ProcessHandle; ///< cache of handle to current process. used for speed reasons
extern FILE * g_ProcessMemFile; ///< opened /proc/PID/mem, valid when attached
class Process
{
friend class ProcessManager;
protected:
Process(DataModel * dm, memory_info* mi, ProcessHandle ph, uint32_t pid);
~Process();
DataModel* my_datamodel;
memory_info * my_descriptor;
ProcessHandle my_handle;
uint32_t my_pid;
string memFile;
bool attached;
void freeResources();
void setMemFile(const string & memf);
public:
// Set up stuff so we can read memory
bool attach();
bool detach();
// is the process still there?
memory_info *getDescriptor();
DataModel *getDataModel();
};
/*
* Process manager
*/
class ProcessManager
{
public:
ProcessManager( string path_to_xml);
~ProcessManager();
bool findProcessess();
uint32_t size();
Process * operator[](uint32_t index);
private:
// memory info entries loaded from a file
std::vector<memory_info> meminfo;
// vector to keep track of dynamically created memory_info entries
std::vector<memory_info *> destroy_meminfo;
Process * currentProcess;
ProcessHandle currentProcessHandle;
std::vector<Process *> processes;
bool loadDescriptors( string path_to_xml);
void ParseVTable(TiXmlElement* vtable, memory_info& mem);
void ParseEntry (TiXmlElement* entry, memory_info& mem, map <string ,TiXmlElement *>& knownEntries);
#ifdef LINUX_BUILD
Process* addProcess(const string & exe,ProcessHandle PH,const string & memFile);
#endif
};
#endif // PROCESSMANAGER_H_INCLUDED
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
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.
*/
#ifndef PROCESSMANAGER_H_INCLUDED
#define PROCESSMANAGER_H_INCLUDED
#ifdef LINUX_BUILD
typedef pid_t ProcessHandle;
#else
typedef HANDLE ProcessHandle;
#endif
class memory_info;
class DataModel;
class TiXmlElement;
class Process;
/*
* Currently attached process and its handle
*/
extern Process * g_pProcess; ///< current process. non-NULL when picked
extern ProcessHandle g_ProcessHandle; ///< cache of handle to current process. used for speed reasons
extern FILE * g_ProcessMemFile; ///< opened /proc/PID/mem, valid when attached
class Process
{
friend class ProcessManager;
protected:
Process(DataModel * dm, memory_info* mi, ProcessHandle ph, uint32_t pid);
~Process();
DataModel* my_datamodel;
memory_info * my_descriptor;
ProcessHandle my_handle;
uint32_t my_pid;
string memFile;
bool attached;
void freeResources();
void setMemFile(const string & memf);
public:
// Set up stuff so we can read memory
bool attach();
bool detach();
// is the process still there?
memory_info *getDescriptor();
DataModel *getDataModel();
};
/*
* Process manager
*/
class ProcessManager
{
public:
ProcessManager( string path_to_xml);
~ProcessManager();
bool findProcessess();
uint32_t size();
Process * operator[](uint32_t index);
private:
// memory info entries loaded from a file
std::vector<memory_info> meminfo;
// vector to keep track of dynamically created memory_info entries
std::vector<memory_info *> destroy_meminfo;
Process * currentProcess;
ProcessHandle currentProcessHandle;
std::vector<Process *> processes;
bool loadDescriptors( string path_to_xml);
void ParseVTable(TiXmlElement* vtable, memory_info& mem);
void ParseEntry (TiXmlElement* entry, memory_info& mem, map <string ,TiXmlElement *>& knownEntries);
#ifdef LINUX_BUILD
Process* addProcess(const string & exe,ProcessHandle PH,const string & memFile);
#endif
};
#endif // PROCESSMANAGER_H_INCLUDED

@ -21,9 +21,12 @@ must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#define BUILD_DFHACK_LIB
#include "DFTileTypes.h"
bool isWallTerrain(int in)
DFHACKAPI bool isWallTerrain(int in)
{
switch (in)
{
@ -181,7 +184,7 @@ bool isWallTerrain(int in)
return false;
}
bool isFloorTerrain(int in)
DFHACKAPI bool isFloorTerrain(int in)
{
switch (in)
{
@ -340,7 +343,7 @@ bool isFloorTerrain(int in)
return false;
}
bool isRampTerrain(int in)
DFHACKAPI bool isRampTerrain(int in)
{
switch (in)
{
@ -362,7 +365,7 @@ bool isRampTerrain(int in)
return false;
}
bool isStairTerrain(int in)
DFHACKAPI bool isStairTerrain(int in)
{
switch (in)
{
@ -409,7 +412,7 @@ bool isStairTerrain(int in)
return false;
}
bool isOpenTerrain(int in)
DFHACKAPI bool isOpenTerrain(int in)
{
switch (in)
{
@ -1047,7 +1050,7 @@ int picktexture(int in)
return 6;
}*/
int getVegetationType(int in)
DFHACKAPI int getVegetationType(int in)
{
switch(in)
{
@ -1064,4 +1067,6 @@ int getVegetationType(int in)
case 34: //shrub
return SHRUB_OK;
}
// ????
return -1;
}

@ -1,44 +1,61 @@
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
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.
*/
#ifndef TILETYPES_H_INCLUDED
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
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.
*/
#ifndef TILETYPES_H_INCLUDED
#define TILETYPES_H_INCLUDED
enum VegetationType{
TREE_DEAD,
TREE_OK,
SAPLING_DEAD,
SAPLING_OK,
SHRUB_DEAD,
SHRUB_OK
};
bool isWallTerrain(int in);
bool isFloorTerrain(int in);
bool isRampTerrain(int in);
bool isStairTerrain(int in);
bool isOpenTerrain(int in);
int getVegetationType(int in);
int picktexture(int in);
#endif // TILETYPES_H_INCLUDED
#ifdef LINUX_BUILD
# ifndef DFHACKAPI
# define DFHACKAPI
# endif
#else
# ifdef BUILD_DFHACK_LIB
# ifndef DFHACKAPI
# define DFHACKAPI extern "C" __declspec(dllexport)
# endif
# else
# ifndef DFHACKAPI
# define DFHACKAPI extern "C" __declspec(dllimport)
# endif
# endif
#endif
enum VegetationType{
TREE_DEAD,
TREE_OK,
SAPLING_DEAD,
SAPLING_OK,
SHRUB_DEAD,
SHRUB_OK
};
DFHACKAPI bool isWallTerrain(int in);
DFHACKAPI bool isFloorTerrain(int in);
DFHACKAPI bool isRampTerrain(int in);
DFHACKAPI bool isStairTerrain(int in);
DFHACKAPI bool isOpenTerrain(int in);
DFHACKAPI int getVegetationType(int in);
DFHACKAPI int picktexture(int in);
#endif // TILETYPES_H_INCLUDED

@ -1,302 +1,302 @@
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
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.
*/
#ifndef TYPES_H_INCLUDED
#define TYPES_H_INCLUDED
struct t_matgloss
{
string id;
uint8_t fore; // Annoyingly the offset for this differs between types
uint8_t back;
uint8_t bright;
};
struct t_vein
{
uint32_t vtable;
int16_t type;
int16_t assignment[16];
int16_t unknown;
uint32_t flags;
};
struct t_matglossPair
{
int16_t type;
int16_t index;
};
// raw
struct t_construction_df40d
{
int16_t x;
int16_t y;
int16_t z;
int16_t unk1;
int16_t unk2;
t_matglossPair material; // 4B
// int16_t mat_type;
// int16_t mat_idx;
};
// cooked
struct t_construction
{
uint16_t x;
uint16_t y;
uint16_t z;
t_matglossPair material;
// int16_t mat_type;
// int16_t mat_idx;
};
/*
dword vtable;
int minx;
int miny;
int centerx;
int maxx;
int maxy;
int centery;
int z;
dword height_not_used;
word mattype;
word matgloss;
word type; // NOTE: the actual field is in a different place
*/
//raw
struct t_building_df40d
{
uint32_t vtable;
uint32_t x1;
uint32_t y1;
uint32_t centerx;
uint32_t x2;
uint32_t y2;
uint32_t centery;
uint32_t z;
uint32_t height;
t_matglossPair material;
// not complete
};
//cooked
struct t_building
{
uint32_t vtable;
uint32_t x1;
uint32_t y1;
uint32_t x2;
uint32_t y2;
uint32_t z;
t_matglossPair material;
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)
};
struct t_tree_desc
{
t_matglossPair material;
uint16_t x;
uint16_t y;
uint16_t z;
};
/*
case 10:
ret += "leather";
break;
case 11:
ret += "silk cloth";
break;
case 12:
ret += "plant thread cloth";
break;
case 13: // green glass
ret += "green glass";
break;
case 14: // clear glass
ret += "clear glass";
break;
case 15: // crystal glass
ret += "crystal glass";
break;
case 17:
ret += "ice";
break;
case 18:
ret += "charcoal";
break;
case 19:
ret += "potash";
break;
case 20:
ret += "ashes";
break;
case 21:
ret += "pearlash";
break;
case 24:
ret += "soap";
break;
*/
// FIXME: in order in which the raw vectors appear in df memory, move to XML
enum MatglossType
{
Mat_Wood,
Mat_Stone,
Mat_Plant,
Mat_Metal,
Mat_Leather = 10,
Mat_SilkCloth = 11,
Mat_PlantCloth = 12,
Mat_GreenGlass = 13,
Mat_ClearGlass = 14,
Mat_CrystalGlass = 15,
Mat_Ice = 17,
Mat_Charcoal =18,
Mat_Potash = 20,
Mat_Ashes = 20,
Mat_PearlAsh = 21,
Mat_Soap = 24,
//NUM_MATGLOSS_TYPES
};
enum BiomeOffset
{
eNorthWest,
eNorth,
eNorthEast,
eWest,
eHere,
eEast,
eSouthWest,
eSouth,
eSouthEast,
eBiomeCount
};
// TODO: research this further? consult DF hacker wizards?
union t_designation
{
uint32_t whole;
struct {
unsigned int flow_size : 3; // how much liquid is here?
unsigned int pile : 1; // stockpile?
/*
* All the different dig designations... needs more info, probably an enum
*/
unsigned int dig : 3;
unsigned int detail : 1;///<- wtf
unsigned int detail_event : 1;///<- more wtf
unsigned int hidden :1;
/*
* This one is rather involved, but necessary to retrieve the base layer matgloss index
* see http://www.bay12games.com/forum/index.php?topic=608.msg253284#msg253284 for details
*/
unsigned int geolayer_index :4;
unsigned int light : 1;
unsigned int subterranean : 1; // never seen the light of day?
unsigned int skyview : 1; // sky is visible now, it rains in here when it rains
/*
* Probably similar to the geolayer_index. Only with a different set of offsets and different data.
* we don't use this yet
*/
unsigned int biome : 4;
/*
0 = water
1 = magma
*/
unsigned int liquid_type : 1;
unsigned int water_table : 1; // srsly. wtf?
unsigned int rained : 1; // does this mean actual rain (as in the blue blocks) or a wet tile?
unsigned int traffic : 2; // needs enum
unsigned int flow_forbid : 1; // idk wtf bbq
unsigned int liquid_static : 1;
unsigned int moss : 1;// I LOVE MOSS
unsigned int feature_present : 1; // another wtf... is this required for magma pipes to work?
unsigned int liquid_character : 2; // those ripples on streams?
} bits;
};
// occupancy flags (rat,dwarf,horse,built wall,not build wall,etc)
union t_occupancy
{
uint32_t whole;
struct {
unsigned int building : 3;// building type... should be an enum?
// 7 = door
unsigned int unit : 1;
unsigned int unit_grounded : 1;
unsigned int item : 1;
// splatter. everyone loves splatter.
unsigned int mud : 1;
unsigned int vomit :1;
unsigned int debris1 :1;
unsigned int debris2 :1;
unsigned int debris3 :1;
unsigned int debris4 :1;
unsigned int blood_g : 1;
unsigned int blood_g2 : 1;
unsigned int blood_b : 1;
unsigned int blood_b2 : 1;
unsigned int blood_y : 1;
unsigned int blood_y2 : 1;
unsigned int blood_m : 1;
unsigned int blood_m2 : 1;
unsigned int blood_c : 1;
unsigned int blood_c2 : 1;
unsigned int blood_w : 1;
unsigned int blood_w2 : 1;
unsigned int blood_o : 1;
unsigned int blood_o2 : 1;
unsigned int slime : 1;
unsigned int slime2 : 1;
unsigned int blood : 1;
unsigned int blood2 : 1;
unsigned int debris5 : 1;
unsigned int snow : 1;
} bits;
struct {
unsigned int building : 3;// building type... should be an enum?
// 7 = door
unsigned int unit : 1;
unsigned int unit_grounded : 1;
unsigned int item : 1;
// splatter. everyone loves splatter.
unsigned int splatter : 26;
} unibits;
};
#endif // TYPES_H_INCLUDED
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
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.
*/
#ifndef TYPES_H_INCLUDED
#define TYPES_H_INCLUDED
struct t_matgloss
{
string id;
uint8_t fore; // Annoyingly the offset for this differs between types
uint8_t back;
uint8_t bright;
};
struct t_vein
{
uint32_t vtable;
int16_t type;
int16_t assignment[16];
int16_t unknown;
uint32_t flags;
};
struct t_matglossPair
{
int16_t type;
int16_t index;
};
// raw
struct t_construction_df40d
{
int16_t x;
int16_t y;
int16_t z;
int16_t unk1;
int16_t unk2;
t_matglossPair material; // 4B
// int16_t mat_type;
// int16_t mat_idx;
};
// cooked
struct t_construction
{
uint16_t x;
uint16_t y;
uint16_t z;
t_matglossPair material;
// int16_t mat_type;
// int16_t mat_idx;
};
/*
dword vtable;
int minx;
int miny;
int centerx;
int maxx;
int maxy;
int centery;
int z;
dword height_not_used;
word mattype;
word matgloss;
word type; // NOTE: the actual field is in a different place
*/
//raw
struct t_building_df40d
{
uint32_t vtable;
uint32_t x1;
uint32_t y1;
uint32_t centerx;
uint32_t x2;
uint32_t y2;
uint32_t centery;
uint32_t z;
uint32_t height;
t_matglossPair material;
// not complete
};
//cooked
struct t_building
{
uint32_t vtable;
uint32_t x1;
uint32_t y1;
uint32_t x2;
uint32_t y2;
uint32_t z;
t_matglossPair material;
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)
};
struct t_tree_desc
{
t_matglossPair material;
uint16_t x;
uint16_t y;
uint16_t z;
};
/*
case 10:
ret += "leather";
break;
case 11:
ret += "silk cloth";
break;
case 12:
ret += "plant thread cloth";
break;
case 13: // green glass
ret += "green glass";
break;
case 14: // clear glass
ret += "clear glass";
break;
case 15: // crystal glass
ret += "crystal glass";
break;
case 17:
ret += "ice";
break;
case 18:
ret += "charcoal";
break;
case 19:
ret += "potash";
break;
case 20:
ret += "ashes";
break;
case 21:
ret += "pearlash";
break;
case 24:
ret += "soap";
break;
*/
// FIXME: in order in which the raw vectors appear in df memory, move to XML
enum MatglossType
{
Mat_Wood,
Mat_Stone,
Mat_Plant,
Mat_Metal,
Mat_Leather = 10,
Mat_SilkCloth = 11,
Mat_PlantCloth = 12,
Mat_GreenGlass = 13,
Mat_ClearGlass = 14,
Mat_CrystalGlass = 15,
Mat_Ice = 17,
Mat_Charcoal =18,
Mat_Potash = 20,
Mat_Ashes = 20,
Mat_PearlAsh = 21,
Mat_Soap = 24,
//NUM_MATGLOSS_TYPES
};
enum BiomeOffset
{
eNorthWest,
eNorth,
eNorthEast,
eWest,
eHere,
eEast,
eSouthWest,
eSouth,
eSouthEast,
eBiomeCount
};
// TODO: research this further? consult DF hacker wizards?
union t_designation
{
uint32_t whole;
struct {
unsigned int flow_size : 3; // how much liquid is here?
unsigned int pile : 1; // stockpile?
/*
* All the different dig designations... needs more info, probably an enum
*/
unsigned int dig : 3;
unsigned int detail : 1;///<- wtf
unsigned int detail_event : 1;///<- more wtf
unsigned int hidden :1;
/*
* This one is rather involved, but necessary to retrieve the base layer matgloss index
* see http://www.bay12games.com/forum/index.php?topic=608.msg253284#msg253284 for details
*/
unsigned int geolayer_index :4;
unsigned int light : 1;
unsigned int subterranean : 1; // never seen the light of day?
unsigned int skyview : 1; // sky is visible now, it rains in here when it rains
/*
* Probably similar to the geolayer_index. Only with a different set of offsets and different data.
* we don't use this yet
*/
unsigned int biome : 4;
/*
0 = water
1 = magma
*/
unsigned int liquid_type : 1;
unsigned int water_table : 1; // srsly. wtf?
unsigned int rained : 1; // does this mean actual rain (as in the blue blocks) or a wet tile?
unsigned int traffic : 2; // needs enum
unsigned int flow_forbid : 1; // idk wtf bbq
unsigned int liquid_static : 1;
unsigned int moss : 1;// I LOVE MOSS
unsigned int feature_present : 1; // another wtf... is this required for magma pipes to work?
unsigned int liquid_character : 2; // those ripples on streams?
} bits;
};
// occupancy flags (rat,dwarf,horse,built wall,not build wall,etc)
union t_occupancy
{
uint32_t whole;
struct {
unsigned int building : 3;// building type... should be an enum?
// 7 = door
unsigned int unit : 1;
unsigned int unit_grounded : 1;
unsigned int item : 1;
// splatter. everyone loves splatter.
unsigned int mud : 1;
unsigned int vomit :1;
unsigned int debris1 :1;
unsigned int debris2 :1;
unsigned int debris3 :1;
unsigned int debris4 :1;
unsigned int blood_g : 1;
unsigned int blood_g2 : 1;
unsigned int blood_b : 1;
unsigned int blood_b2 : 1;
unsigned int blood_y : 1;
unsigned int blood_y2 : 1;
unsigned int blood_m : 1;
unsigned int blood_m2 : 1;
unsigned int blood_c : 1;
unsigned int blood_c2 : 1;
unsigned int blood_w : 1;
unsigned int blood_w2 : 1;
unsigned int blood_o : 1;
unsigned int blood_o2 : 1;
unsigned int slime : 1;
unsigned int slime2 : 1;
unsigned int blood : 1;
unsigned int blood2 : 1;
unsigned int debris5 : 1;
unsigned int snow : 1;
} bits;
struct {
unsigned int building : 3;// building type... should be an enum?
// 7 = door
unsigned int unit : 1;
unsigned int unit_grounded : 1;
unsigned int item : 1;
// splatter. everyone loves splatter.
unsigned int splatter : 26;
} unibits;
};
#endif // TYPES_H_INCLUDED

@ -1,67 +1,67 @@
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
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.
*/
#ifndef DFVECTOR_H_INCLUDED
#define DFVECTOR_H_INCLUDED
class DfVector
{
private:
// starting offset
uint32_t start;
// vector size
uint32_t size;
// vector item size
uint32_t item_size;
public:
DfVector(uint32_t _start, uint32_t _size, uint32_t _item_size):
start(_start),size(_size),item_size(_item_size) {};
DfVector(const DfVector & vec)
{
start = vec.start;
size = vec.size;
item_size = vec.item_size;
};
DfVector(){};
// get offset of the specified index
inline uint32_t operator[](uint32_t index)
{
assert(index < size);
return start + index*item_size;
};
// get vector size
inline uint32_t getSize()
{
return size;
};
// read item_size bytes from the right offset
inline void read (uint32_t index, uint8_t *target)
{
assert(index < size);
Mread (start + index*item_size, item_size, target);
};
};
#endif // DFVECTOR_H_INCLUDED
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
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.
*/
#ifndef DFVECTOR_H_INCLUDED
#define DFVECTOR_H_INCLUDED
class DfVector
{
private:
// starting offset
uint32_t start;
// vector size
uint32_t size;
// vector item size
uint32_t item_size;
public:
DfVector(uint32_t _start, uint32_t _size, uint32_t _item_size):
start(_start),size(_size),item_size(_item_size) {};
DfVector(const DfVector & vec)
{
start = vec.start;
size = vec.size;
item_size = vec.item_size;
};
DfVector(){};
// get offset of the specified index
inline uint32_t operator[](uint32_t index)
{
assert(index < size);
return start + index*item_size;
};
// get vector size
inline uint32_t getSize()
{
return size;
};
// read item_size bytes from the right offset
inline void read (uint32_t index, uint8_t *target)
{
assert(index < size);
Mread (start + index*item_size, item_size, target);
};
};
#endif // DFVECTOR_H_INCLUDED

@ -129,7 +129,7 @@ void MwriteByte (uint32_t offset, uint8_t data)
}
inline
bool Mwrite (uint32_t offset, uint32_t size, uint8_t *source)
void Mwrite (uint32_t offset, uint32_t size, uint8_t *source)
{
WriteProcessMemory(g_ProcessHandle, (int*) offset, source, size, NULL);
}
@ -140,6 +140,20 @@ bool Mwrite (uint32_t offset, uint32_t size, uint8_t *source)
inline
const string MreadCString (const uint32_t &offset)
{
string temp;
char temp_c[256];
DWORD read;
ReadProcessMemory(g_ProcessHandle, (int *) offset, temp_c, 255, &read);
temp_c[read+1] = 0;
temp = temp_c;
return temp;
// I'll let the original code go down in infamy, and burn. Burn. BURN. YES, BURN! DIE YOU HORRIBLE, HORRIBLE, CODE!
// Problems:
// * Does not check counter < 255, so potential buffer overrun.
// * Reads a single byte at a time, which is extremely inefficient (iirc, user -> kernel mode switch).
// * It adds an unnecessary null termination.
#if 0
string temp;
char temp_c[256];
int counter = 0;
@ -153,4 +167,5 @@ const string MreadCString (const uint32_t &offset)
temp_c[counter] = 0;
temp = temp_c;
return temp;
#endif
}

@ -1,204 +1,204 @@
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
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.
*/
#ifndef DFMAP_H_INCLUDED
#define DFMAP_H_INCLUDED
#define BLOCK_SIZE 16
class DfMapHeader;
class Block
{
public:
// where does the Block come from?
uint32_t origin;
// generic tile type. determines how the tile behaves ingame
uint16_t tile_type[BLOCK_SIZE][BLOCK_SIZE];
t_designation designation[BLOCK_SIZE][BLOCK_SIZE];
t_occupancy occupancy[BLOCK_SIZE][BLOCK_SIZE];
// veins
vector <t_vein> veins;
t_matglossPair material[BLOCK_SIZE][BLOCK_SIZE];
vector<t_building*> v_buildings;
vector<t_tree_desc*> v_trees;
void collapseVeins();
/**
// region offset modifiers... what a hack.
// here we have double indexed offset into regions.
// once inside t_designation, pointing into this, second time from here as a index modifier into region array (2d)
// disassembled code where it's used follows. biome is biome from t_designation
biome_stuffs = *(_BYTE *)((char)biome + offset_Block + 0x1D84);
biome_stuffs_mod3 = biome_stuffs % 3;
biome_stuffs_div3 = biome_stuffs / 3;
biome_stuffs_mod3_ = biome_stuffs_mod3;
if ( !biome_stuffs_mod3_ )
--*(_WORD *)X_stuff;
if ( biome_stuffs_mod3_ == 2 )
++*(_WORD *)X_stuff;
if ( !biome_stuffs_div3 )
--*(_WORD *)Y_stuff_;
if ( biome_stuffs_div3 == 2 )
++*(_WORD *)Y_stuff_;
*/
uint8_t RegionOffsets[16];// idk if the length is right here
};
/**
* This class can load and save DF maps
*/
class DfMap
{
private:
// allow extractor direct access to our data, avoid call lag and lots of self-serving methods
friend class Extractor;
Block **block;
uint32_t blocks_allocated;
bool valid;
// converts the (x,y,z) cell coords to internal coords
// out_y, out_x - block coords
// out_y2, out_x2 - cell coords in that block
inline void convertToDfMapCoords(uint32_t x, uint32_t y, uint32_t &out_x, uint32_t &out_y, uint32_t &out_x2, uint32_t &out_y2)
{
out_x = x / BLOCK_SIZE;
out_x2 = x % BLOCK_SIZE;
out_y = y / BLOCK_SIZE;
out_y2 = y % BLOCK_SIZE;
};
void allocBlockArray(uint32_t x,uint32_t y, uint32_t z);
void updateCellCount();
bool loadVersion1(FILE * Decompressed,DfMapHeader & h);
bool writeVersion1(FILE * SaveFile);
bool loadMatgloss2(FILE * Decompressed);
bool loadBlocks2(FILE * Decompressed,DfMapHeader & h);
bool loadRegion2(FILE * Decompressed);
bool loadVersion2(FILE * Decompressed,DfMapHeader & h);
void writeMatgloss2(FILE * SaveFile);
void writeBlocks2(FILE * SaveFile);
void writeRegion2(FILE * SaveFile);
bool writeVersion2(FILE * SaveFile);
uint32_t regionX;
uint32_t regionY;
uint32_t regionZ;
///FIXME: these belong to some world structure
uint32_t worldSizeX;
uint32_t worldSizeY;
vector<uint16_t> v_geology[eBiomeCount];
vector<string> v_matgloss[NUM_MATGLOSS_TYPES];
vector<string> v_buildingtypes;
vector<t_construction> v_constructions;
vector<t_building*> v_buildings;
vector<t_tree_desc*> v_trees;
unsigned x_block_count, y_block_count, z_block_count; // block count
unsigned x_cell_count, y_cell_count, z_cell_count; // cell count
public:
DfMap();
DfMap(uint32_t x, uint32_t y, uint32_t z);
DfMap(string file_name);
~DfMap();
/// TODO: rework matgloss
void applyGeoMatgloss(Block * b);
// accessing vectors of materials
uint16_t getNumMatGloss(uint16_t type);
string getMaterialTypeString (uint32_t type);
string getMatGlossString(uint16_t type, uint16_t index);
// accessing vectors of building types
uint32_t getNumBuildingTypes();
string getBuildingTypeName(uint32_t index);
bool isValid();
bool load(string FilePath);
bool write(string FilePath);
void clear();
Block* getBlock(uint32_t x, uint32_t y, uint32_t z);
Block* allocBlock(uint32_t x, uint32_t y, uint32_t z);
bool deallocBlock(uint32_t x, uint32_t y, uint32_t z);
vector<t_building *> * getBlockBuildingsVector(uint32_t x,uint32_t y,uint32_t z);
vector<t_tree_desc *> * getBlockVegetationVector(uint32_t x,uint32_t y,uint32_t z);
inline unsigned int getXBlocks() { return x_block_count; }
inline unsigned int getYBlocks() { return y_block_count; }
inline unsigned int getZBlocks() { return z_block_count; }
bool isTileSky(uint32_t x, uint32_t y, uint32_t z, uint32_t blockX, uint32_t blockY);
uint16_t getTileType(uint32_t x, uint32_t y, uint32_t z);
uint16_t getTileType(uint32_t x, uint32_t y, uint32_t z, uint32_t blockX, uint32_t blockY);
uint32_t getDesignations(uint32_t x, uint32_t y, uint32_t z);
uint32_t getOccupancies(uint32_t x, uint32_t y, uint32_t z);
// get tile material
t_matglossPair getMaterialPair (uint32_t x, uint32_t y, uint32_t z);
string getGeoMaterialString (uint32_t x, uint32_t y, uint32_t z);
string getMaterialString (uint32_t type, uint32_t index);
// get coords of region used for materials
void getGeoRegion (uint32_t x, uint32_t y, uint32_t z, int32_t& geoX, int32_t& geoY);
// matgloss part of the designation
uint32_t getGeolayerIndex (uint32_t x, uint32_t y, uint32_t z);
void getRegionCoords (uint32_t &x,uint32_t &y,uint32_t &z);
void setRegionCoords (uint32_t x,uint32_t y,uint32_t z);
// what kind of building is here?
//uint16_t getBuilding (uint32_t x, uint32_t y, uint32_t z);
t_building *getBuilding (uint32_t x, uint32_t y, uint32_t z);
t_tree_desc *getTree (uint32_t x, uint32_t y, uint32_t z);
unsigned int getBiome (uint32_t x, uint32_t y, uint32_t z);
int picktexture(int);
/*
bool isOpenTerrain(int);
bool isStairTerrain(int);
bool isRampTerrain(int);
bool isFloorTerrain(int);
bool isWallTerrain(int);
*/
bool isBlockInitialized(uint32_t x, uint32_t y, uint32_t z);
bool isHidden (uint32_t x, uint32_t y, uint32_t z);
bool isSubterranean (uint32_t x, uint32_t y, uint32_t z);
bool isSkyView (uint32_t x, uint32_t y, uint32_t z);
bool isSunLit (uint32_t x, uint32_t y, uint32_t z);
bool isMagma (uint32_t x, uint32_t y, uint32_t z);
uint8_t getLiquidLevel(uint32_t x, uint32_t y, uint32_t z);
};
#endif // DFMAP_H_INCLUDED
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
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.
*/
#ifndef DFMAP_H_INCLUDED
#define DFMAP_H_INCLUDED
#define BLOCK_SIZE 16
class DfMapHeader;
class Block
{
public:
// where does the Block come from?
uint32_t origin;
// generic tile type. determines how the tile behaves ingame
uint16_t tile_type[BLOCK_SIZE][BLOCK_SIZE];
t_designation designation[BLOCK_SIZE][BLOCK_SIZE];
t_occupancy occupancy[BLOCK_SIZE][BLOCK_SIZE];
// veins
vector <t_vein> veins;
t_matglossPair material[BLOCK_SIZE][BLOCK_SIZE];
vector<t_building*> v_buildings;
vector<t_tree_desc*> v_trees;
void collapseVeins();
/**
// region offset modifiers... what a hack.
// here we have double indexed offset into regions.
// once inside t_designation, pointing into this, second time from here as a index modifier into region array (2d)
// disassembled code where it's used follows. biome is biome from t_designation
biome_stuffs = *(_BYTE *)((char)biome + offset_Block + 0x1D84);
biome_stuffs_mod3 = biome_stuffs % 3;
biome_stuffs_div3 = biome_stuffs / 3;
biome_stuffs_mod3_ = biome_stuffs_mod3;
if ( !biome_stuffs_mod3_ )
--*(_WORD *)X_stuff;
if ( biome_stuffs_mod3_ == 2 )
++*(_WORD *)X_stuff;
if ( !biome_stuffs_div3 )
--*(_WORD *)Y_stuff_;
if ( biome_stuffs_div3 == 2 )
++*(_WORD *)Y_stuff_;
*/
uint8_t RegionOffsets[16];// idk if the length is right here
};
/**
* This class can load and save DF maps
*/
class DfMap
{
private:
// allow extractor direct access to our data, avoid call lag and lots of self-serving methods
friend class Extractor;
Block **block;
uint32_t blocks_allocated;
bool valid;
// converts the (x,y,z) cell coords to internal coords
// out_y, out_x - block coords
// out_y2, out_x2 - cell coords in that block
inline void convertToDfMapCoords(uint32_t x, uint32_t y, uint32_t &out_x, uint32_t &out_y, uint32_t &out_x2, uint32_t &out_y2)
{
out_x = x / BLOCK_SIZE;
out_x2 = x % BLOCK_SIZE;
out_y = y / BLOCK_SIZE;
out_y2 = y % BLOCK_SIZE;
};
void allocBlockArray(uint32_t x,uint32_t y, uint32_t z);
void updateCellCount();
bool loadVersion1(FILE * Decompressed,DfMapHeader & h);
bool writeVersion1(FILE * SaveFile);
bool loadMatgloss2(FILE * Decompressed);
bool loadBlocks2(FILE * Decompressed,DfMapHeader & h);
bool loadRegion2(FILE * Decompressed);
bool loadVersion2(FILE * Decompressed,DfMapHeader & h);
void writeMatgloss2(FILE * SaveFile);
void writeBlocks2(FILE * SaveFile);
void writeRegion2(FILE * SaveFile);
bool writeVersion2(FILE * SaveFile);
uint32_t regionX;
uint32_t regionY;
uint32_t regionZ;
///FIXME: these belong to some world structure
uint32_t worldSizeX;
uint32_t worldSizeY;
vector<uint16_t> v_geology[eBiomeCount];
vector<string> v_matgloss[NUM_MATGLOSS_TYPES];
vector<string> v_buildingtypes;
vector<t_construction> v_constructions;
vector<t_building*> v_buildings;
vector<t_tree_desc*> v_trees;
unsigned x_block_count, y_block_count, z_block_count; // block count
unsigned x_cell_count, y_cell_count, z_cell_count; // cell count
public:
DfMap();
DfMap(uint32_t x, uint32_t y, uint32_t z);
DfMap(string file_name);
~DfMap();
/// TODO: rework matgloss
void applyGeoMatgloss(Block * b);
// accessing vectors of materials
uint16_t getNumMatGloss(uint16_t type);
string getMaterialTypeString (uint32_t type);
string getMatGlossString(uint16_t type, uint16_t index);
// accessing vectors of building types
uint32_t getNumBuildingTypes();
string getBuildingTypeName(uint32_t index);
bool isValid();
bool load(string FilePath);
bool write(string FilePath);
void clear();
Block* getBlock(uint32_t x, uint32_t y, uint32_t z);
Block* allocBlock(uint32_t x, uint32_t y, uint32_t z);
bool deallocBlock(uint32_t x, uint32_t y, uint32_t z);
vector<t_building *> * getBlockBuildingsVector(uint32_t x,uint32_t y,uint32_t z);
vector<t_tree_desc *> * getBlockVegetationVector(uint32_t x,uint32_t y,uint32_t z);
inline unsigned int getXBlocks() { return x_block_count; }
inline unsigned int getYBlocks() { return y_block_count; }
inline unsigned int getZBlocks() { return z_block_count; }
bool isTileSky(uint32_t x, uint32_t y, uint32_t z, uint32_t blockX, uint32_t blockY);
uint16_t getTileType(uint32_t x, uint32_t y, uint32_t z);
uint16_t getTileType(uint32_t x, uint32_t y, uint32_t z, uint32_t blockX, uint32_t blockY);
uint32_t getDesignations(uint32_t x, uint32_t y, uint32_t z);
uint32_t getOccupancies(uint32_t x, uint32_t y, uint32_t z);
// get tile material
t_matglossPair getMaterialPair (uint32_t x, uint32_t y, uint32_t z);
string getGeoMaterialString (uint32_t x, uint32_t y, uint32_t z);
string getMaterialString (uint32_t type, uint32_t index);
// get coords of region used for materials
void getGeoRegion (uint32_t x, uint32_t y, uint32_t z, int32_t& geoX, int32_t& geoY);
// matgloss part of the designation
uint32_t getGeolayerIndex (uint32_t x, uint32_t y, uint32_t z);
void getRegionCoords (uint32_t &x,uint32_t &y,uint32_t &z);
void setRegionCoords (uint32_t x,uint32_t y,uint32_t z);
// what kind of building is here?
//uint16_t getBuilding (uint32_t x, uint32_t y, uint32_t z);
t_building *getBuilding (uint32_t x, uint32_t y, uint32_t z);
t_tree_desc *getTree (uint32_t x, uint32_t y, uint32_t z);
unsigned int getBiome (uint32_t x, uint32_t y, uint32_t z);
int picktexture(int);
/*
bool isOpenTerrain(int);
bool isStairTerrain(int);
bool isRampTerrain(int);
bool isFloorTerrain(int);
bool isWallTerrain(int);
*/
bool isBlockInitialized(uint32_t x, uint32_t y, uint32_t z);
bool isHidden (uint32_t x, uint32_t y, uint32_t z);
bool isSubterranean (uint32_t x, uint32_t y, uint32_t z);
bool isSkyView (uint32_t x, uint32_t y, uint32_t z);
bool isSunLit (uint32_t x, uint32_t y, uint32_t z);
bool isMagma (uint32_t x, uint32_t y, uint32_t z);
uint8_t getLiquidLevel(uint32_t x, uint32_t y, uint32_t z);
};
#endif // DFMAP_H_INCLUDED

@ -1,160 +1,160 @@
// SOURCE: http://www.zlib.net/zpipe.c
#ifndef ZLIB_HELPER_HEADER
#define ZLIB_HELPER_HEADER
#include <zlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
//#define CHUNK 16384
#define CHUNK 262144
/* Compress from file source to file dest until EOF on source.
def() returns Z_OK on success, Z_MEM_ERROR if memory could not be
allocated for processing, Z_STREAM_ERROR if an invalid compression
level is supplied, Z_VERSION_ERROR if the version of zlib.h and the
version of the library linked do not match, or Z_ERRNO if there is
an error reading or writing the files. */
inline int def(FILE *source, FILE *dest, int level)
{
int ret, flush;
unsigned have;
z_stream strm;
unsigned char in[CHUNK];
unsigned char out[CHUNK];
/* allocate deflate state */
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
ret = deflateInit(&strm, level);
if (ret != Z_OK)
return ret;
/* compress until end of file */
do {
strm.avail_in = fread(in, 1, CHUNK, source);
if (ferror(source)) {
(void)deflateEnd(&strm);
return Z_ERRNO;
}
flush = feof(source) ? Z_FINISH : Z_NO_FLUSH;
strm.next_in = in;
/* run deflate() on input until output buffer not full, finish
compression if all of source has been read in */
do {
strm.avail_out = CHUNK;
strm.next_out = out;
ret = deflate(&strm, flush); /* no bad return value */
assert(ret != Z_STREAM_ERROR); /* state not clobbered */
have = CHUNK - strm.avail_out;
if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
(void)deflateEnd(&strm);
return Z_ERRNO;
}
} while (strm.avail_out == 0);
assert(strm.avail_in == 0); /* all input will be used */
/* done when last data in file processed */
} while (flush != Z_FINISH);
assert(ret == Z_STREAM_END); /* stream will be complete */
/* clean up and return */
(void)deflateEnd(&strm);
return Z_OK;
}
/* Decompress from file source to file dest until stream ends or EOF.
inf() returns Z_OK on success, Z_MEM_ERROR if memory could not be
allocated for processing, Z_DATA_ERROR if the deflate data is
invalid or incomplete, Z_VERSION_ERROR if the version of zlib.h and
the version of the library linked do not match, or Z_ERRNO if there
is an error reading or writing the files. */
inline int inf(FILE *source, FILE *dest)
{
int ret;
unsigned have;
z_stream strm;
unsigned char in[CHUNK];
unsigned char out[CHUNK];
/* allocate inflate state */
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
strm.avail_in = 0;
strm.next_in = Z_NULL;
ret = inflateInit(&strm);
if (ret != Z_OK)
return ret;
/* decompress until deflate stream ends or end of file */
do {
strm.avail_in = fread(in, 1, CHUNK, source);
if (ferror(source)) {
(void)inflateEnd(&strm);
return Z_ERRNO;
}
if (strm.avail_in == 0)
break;
strm.next_in = in;
/* run inflate() on input until output buffer not full */
do {
strm.avail_out = CHUNK;
strm.next_out = out;
ret = inflate(&strm, Z_NO_FLUSH);
assert(ret != Z_STREAM_ERROR); /* state not clobbered */
switch (ret) {
case Z_NEED_DICT:
ret = Z_DATA_ERROR; /* and fall through */
case Z_DATA_ERROR:
case Z_MEM_ERROR:
(void)inflateEnd(&strm);
return ret;
}
have = CHUNK - strm.avail_out;
if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
(void)inflateEnd(&strm);
return Z_ERRNO;
}
} while (strm.avail_out == 0);
/* done when inflate() says it's done */
} while (ret != Z_STREAM_END);
/* clean up and return */
(void)inflateEnd(&strm);
return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
}
/* report a zlib or i/o error */
inline void zerr(int ret)
{
printf("zpipe: %d\n", ret);
switch (ret) {
case Z_ERRNO:
if (ferror(stdin))
fprintf(stderr,"error reading stdin\n");
if (ferror(stdout))
fprintf(stderr,"error writing stdout\n");
break;
case Z_STREAM_ERROR:
printf("invalid compression level\n");
break;
case Z_DATA_ERROR:
printf("invalid or incomplete deflate data\n");
break;
case Z_MEM_ERROR:
printf("out of memory\n");
break;
case Z_VERSION_ERROR:
printf("zlib version mismatch!\n");
}
}
#endif // ZLIB_HELPER_HEADER
// SOURCE: http://www.zlib.net/zpipe.c
#ifndef ZLIB_HELPER_HEADER
#define ZLIB_HELPER_HEADER
#include <zlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
//#define CHUNK 16384
#define CHUNK 262144
/* Compress from file source to file dest until EOF on source.
def() returns Z_OK on success, Z_MEM_ERROR if memory could not be
allocated for processing, Z_STREAM_ERROR if an invalid compression
level is supplied, Z_VERSION_ERROR if the version of zlib.h and the
version of the library linked do not match, or Z_ERRNO if there is
an error reading or writing the files. */
inline int def(FILE *source, FILE *dest, int level)
{
int ret, flush;
unsigned have;
z_stream strm;
unsigned char in[CHUNK];
unsigned char out[CHUNK];
/* allocate deflate state */
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
ret = deflateInit(&strm, level);
if (ret != Z_OK)
return ret;
/* compress until end of file */
do {
strm.avail_in = fread(in, 1, CHUNK, source);
if (ferror(source)) {
(void)deflateEnd(&strm);
return Z_ERRNO;
}
flush = feof(source) ? Z_FINISH : Z_NO_FLUSH;
strm.next_in = in;
/* run deflate() on input until output buffer not full, finish
compression if all of source has been read in */
do {
strm.avail_out = CHUNK;
strm.next_out = out;
ret = deflate(&strm, flush); /* no bad return value */
assert(ret != Z_STREAM_ERROR); /* state not clobbered */
have = CHUNK - strm.avail_out;
if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
(void)deflateEnd(&strm);
return Z_ERRNO;
}
} while (strm.avail_out == 0);
assert(strm.avail_in == 0); /* all input will be used */
/* done when last data in file processed */
} while (flush != Z_FINISH);
assert(ret == Z_STREAM_END); /* stream will be complete */
/* clean up and return */
(void)deflateEnd(&strm);
return Z_OK;
}
/* Decompress from file source to file dest until stream ends or EOF.
inf() returns Z_OK on success, Z_MEM_ERROR if memory could not be
allocated for processing, Z_DATA_ERROR if the deflate data is
invalid or incomplete, Z_VERSION_ERROR if the version of zlib.h and
the version of the library linked do not match, or Z_ERRNO if there
is an error reading or writing the files. */
inline int inf(FILE *source, FILE *dest)
{
int ret;
unsigned have;
z_stream strm;
unsigned char in[CHUNK];
unsigned char out[CHUNK];
/* allocate inflate state */
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
strm.avail_in = 0;
strm.next_in = Z_NULL;
ret = inflateInit(&strm);
if (ret != Z_OK)
return ret;
/* decompress until deflate stream ends or end of file */
do {
strm.avail_in = fread(in, 1, CHUNK, source);
if (ferror(source)) {
(void)inflateEnd(&strm);
return Z_ERRNO;
}
if (strm.avail_in == 0)
break;
strm.next_in = in;
/* run inflate() on input until output buffer not full */
do {
strm.avail_out = CHUNK;
strm.next_out = out;
ret = inflate(&strm, Z_NO_FLUSH);
assert(ret != Z_STREAM_ERROR); /* state not clobbered */
switch (ret) {
case Z_NEED_DICT:
ret = Z_DATA_ERROR; /* and fall through */
case Z_DATA_ERROR:
case Z_MEM_ERROR:
(void)inflateEnd(&strm);
return ret;
}
have = CHUNK - strm.avail_out;
if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
(void)inflateEnd(&strm);
return Z_ERRNO;
}
} while (strm.avail_out == 0);
/* done when inflate() says it's done */
} while (ret != Z_STREAM_END);
/* clean up and return */
(void)inflateEnd(&strm);
return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
}
/* report a zlib or i/o error */
inline void zerr(int ret)
{
printf("zpipe: %d\n", ret);
switch (ret) {
case Z_ERRNO:
if (ferror(stdin))
fprintf(stderr,"error reading stdin\n");
if (ferror(stdout))
fprintf(stderr,"error writing stdout\n");
break;
case Z_STREAM_ERROR:
printf("invalid compression level\n");
break;
case Z_DATA_ERROR:
printf("invalid or incomplete deflate data\n");
break;
case Z_MEM_ERROR:
printf("out of memory\n");
break;
case Z_VERSION_ERROR:
printf("zlib version mismatch!\n");
}
}
#endif // ZLIB_HELPER_HEADER

@ -16,6 +16,10 @@
* Petr Mrázek
*/
#if defined(_MSC_VER) && _MSC_VER >= 1400
#define _CRT_SECURE_NO_WARNINGS
#endif
//----------------------------------------------------------------------
//basic includes
#include <fstream>

@ -15,7 +15,8 @@ int main (void)
uint32_t bytes_read = 0;
t_occupancy occupancies[256];
DFHackAPI DF("Memory.xml");
DFHackAPI *pDF = CreateDFHackAPI("Memory.xml");
DFHackAPI &DF = *pDF;
if(!DF.Attach())
{
cerr << "DF not found" << endl;
@ -46,5 +47,6 @@ int main (void)
}
}
}
delete pDF;
return 0;
}

@ -17,7 +17,8 @@ int main (void)
t_designation designations[16][16];
t_occupancy occupancies[16][16];
DFHackAPI DF("Memory.xml");
DFHackAPI *pDF = CreateDFHackAPI("Memory.xml");
DFHackAPI &DF = *pDF;
if(!DF.Attach())
{
cerr << "DF not found" << endl;
@ -46,5 +47,6 @@ int main (void)
}
cout << num_blocks << " blocks read" << endl;
cout << bytes_read / (1024 * 1024) << " MB" << endl;
delete pDF;
return 0;
}

@ -10,6 +10,7 @@
#include <iostream>
#include <stdint.h>
#include <string.h> // for memset
#include <string>
#include <vector>
#include <map>
using namespace std;
@ -54,7 +55,8 @@ int main (int argc, const char* argv[])
vector< vector <uint16_t> > layerassign;
// init the API
DFHackAPI DF("Memory.xml");
DFHackAPI *pDF = CreateDFHackAPI("Memory.xml");
DFHackAPI &DF = *pDF;
// attach
if(!DF.Attach())
@ -119,7 +121,7 @@ int main (int argc, const char* argv[])
}
// for each vein
for(int i = 0; i < veins.size();i++)
for(int i = 0; i < (int)veins.size();i++)
{
//iterate through vein rows
for(uint32_t j = 0;j<16;j++)
@ -128,7 +130,7 @@ int main (int argc, const char* argv[])
for (uint32_t k = 0; k< 16;k++)
{
// and the bit array with a one-bit mask, check if the bit is set
bool set = ((1 << k) & veins[i].assignment[j]) >> k;
bool set = !!(((1 << k) & veins[i].assignment[j]) >> k);
if(set)
{
// store matgloss
@ -170,8 +172,8 @@ int main (int argc, const char* argv[])
}
// wait for input on windows so the tool is still usable to some extent
#ifndef LINUX_BUILD
uint32_t junk = 0;
cin >> junk;
cin.ignore();
#endif
delete pDF;
return 0;
}

@ -15,7 +15,8 @@ int main (void)
uint32_t bytes_read = 0;
t_designation designations[256];
DFHackAPI DF("Memory.xml");
DFHackAPI *pDF = CreateDFHackAPI("Memory.xml");
DFHackAPI &DF = *pDF;
if(!DF.Attach())
{
cerr << "DF not found" << endl;
@ -46,5 +47,6 @@ int main (void)
}
}
}
delete pDF;
return 0;
}