Visual Studio compatibility patch from jifodus
parent
e85df7cfc0
commit
8e72f2af0e
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue