Visual Studio compatibility patch from jifodus
parent
e85df7cfc0
commit
8e72f2af0e
@ -1,63 +1,63 @@
|
|||||||
/*
|
/*
|
||||||
www.sourceforge.net/projects/dfhack
|
www.sourceforge.net/projects/dfhack
|
||||||
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
|
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied
|
This software is provided 'as-is', without any express or implied
|
||||||
warranty. In no event will the authors be held liable for any
|
warranty. In no event will the authors be held liable for any
|
||||||
damages arising from the use of this software.
|
damages arising from the use of this software.
|
||||||
|
|
||||||
Permission is granted to anyone to use this software for any
|
Permission is granted to anyone to use this software for any
|
||||||
purpose, including commercial applications, and to alter it and
|
purpose, including commercial applications, and to alter it and
|
||||||
redistribute it freely, subject to the following restrictions:
|
redistribute it freely, subject to the following restrictions:
|
||||||
|
|
||||||
1. The origin of this software must not be misrepresented; you must
|
1. The origin of this software must not be misrepresented; you must
|
||||||
not claim that you wrote the original software. If you use this
|
not claim that you wrote the original software. If you use this
|
||||||
software in a product, an acknowledgment in the product documentation
|
software in a product, an acknowledgment in the product documentation
|
||||||
would be appreciated but is not required.
|
would be appreciated but is not required.
|
||||||
|
|
||||||
2. Altered source versions must be plainly marked as such, and
|
2. Altered source versions must be plainly marked as such, and
|
||||||
must not be misrepresented as being the original software.
|
must not be misrepresented as being the original software.
|
||||||
|
|
||||||
3. This notice may not be removed or altered from any source
|
3. This notice may not be removed or altered from any source
|
||||||
distribution.
|
distribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef DFCOMMON_H_INCLUDED
|
#ifndef DFCOMMON_H_INCLUDED
|
||||||
#define DFCOMMON_H_INCLUDED
|
#define DFCOMMON_H_INCLUDED
|
||||||
|
|
||||||
///TODO: separate into extrenal and internal
|
///TODO: separate into extrenal and internal
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
//#include <boost/bimap/bimap.hpp>
|
//#include <boost/bimap/bimap.hpp>
|
||||||
//using namespace boost::bimaps;
|
//using namespace boost::bimaps;
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#ifdef LINUX_BUILD
|
#ifdef LINUX_BUILD
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/ptrace.h>
|
#include <sys/ptrace.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#else
|
#else
|
||||||
#define WINVER 0x0500 // OpenThread(), PSAPI, Toolhelp32
|
#define WINVER 0x0500 // OpenThread(), PSAPI, Toolhelp32
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <winbase.h>
|
#include <winbase.h>
|
||||||
#include <winnt.h>
|
#include <winnt.h>
|
||||||
#include <psapi.h>
|
#include <psapi.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "DFTypes.h"
|
#include "DFTypes.h"
|
||||||
#include "DFDataModel.h"
|
#include "DFDataModel.h"
|
||||||
#include "DFProcessManager.h"
|
#include "DFProcessManager.h"
|
||||||
#include "DFMemAccess.h"
|
#include "DFMemAccess.h"
|
||||||
#include "DFVector.h"
|
#include "DFVector.h"
|
||||||
//#include "DfMap.h"
|
//#include "DfMap.h"
|
||||||
|
|
||||||
|
|
||||||
#endif // DFCOMMON_H_INCLUDED
|
#endif // DFCOMMON_H_INCLUDED
|
||||||
|
@ -1,54 +1,54 @@
|
|||||||
/*
|
/*
|
||||||
www.sourceforge.net/projects/dfhack
|
www.sourceforge.net/projects/dfhack
|
||||||
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
|
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied
|
This software is provided 'as-is', without any express or implied
|
||||||
warranty. In no event will the authors be held liable for any
|
warranty. In no event will the authors be held liable for any
|
||||||
damages arising from the use of this software.
|
damages arising from the use of this software.
|
||||||
|
|
||||||
Permission is granted to anyone to use this software for any
|
Permission is granted to anyone to use this software for any
|
||||||
purpose, including commercial applications, and to alter it and
|
purpose, including commercial applications, and to alter it and
|
||||||
redistribute it freely, subject to the following restrictions:
|
redistribute it freely, subject to the following restrictions:
|
||||||
|
|
||||||
1. The origin of this software must not be misrepresented; you must
|
1. The origin of this software must not be misrepresented; you must
|
||||||
not claim that you wrote the original software. If you use this
|
not claim that you wrote the original software. If you use this
|
||||||
software in a product, an acknowledgment in the product documentation
|
software in a product, an acknowledgment in the product documentation
|
||||||
would be appreciated but is not required.
|
would be appreciated but is not required.
|
||||||
|
|
||||||
2. Altered source versions must be plainly marked as such, and
|
2. Altered source versions must be plainly marked as such, and
|
||||||
must not be misrepresented as being the original software.
|
must not be misrepresented as being the original software.
|
||||||
|
|
||||||
3. This notice may not be removed or altered from any source
|
3. This notice may not be removed or altered from any source
|
||||||
distribution.
|
distribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef DATAMODEL_H_INCLUDED
|
#ifndef DATAMODEL_H_INCLUDED
|
||||||
#define DATAMODEL_H_INCLUDED
|
#define DATAMODEL_H_INCLUDED
|
||||||
|
|
||||||
class DfVector;
|
class DfVector;
|
||||||
|
|
||||||
// let's go pure virtual.
|
// let's go pure virtual.
|
||||||
class DataModel
|
class DataModel
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// read a string
|
// read a string
|
||||||
virtual const string readSTLString (uint32_t offset) = 0;
|
virtual const string readSTLString (uint32_t offset) = 0;
|
||||||
// read a vector from memory
|
// read a vector from memory
|
||||||
virtual DfVector readVector (uint32_t offset, uint32_t item_size) = 0;
|
virtual DfVector readVector (uint32_t offset, uint32_t item_size) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DMWindows40d : public DataModel
|
class DMWindows40d : public DataModel
|
||||||
{
|
{
|
||||||
virtual const string readSTLString (uint32_t offset);
|
virtual const string readSTLString (uint32_t offset);
|
||||||
// read a vector from memory
|
// read a vector from memory
|
||||||
virtual DfVector readVector (uint32_t offset, uint32_t item_size);
|
virtual DfVector readVector (uint32_t offset, uint32_t item_size);
|
||||||
};
|
};
|
||||||
|
|
||||||
class DMLinux40d : public DataModel
|
class DMLinux40d : public DataModel
|
||||||
{
|
{
|
||||||
virtual const string readSTLString (uint32_t offset);
|
virtual const string readSTLString (uint32_t offset);
|
||||||
// read a vector from memory
|
// read a vector from memory
|
||||||
virtual DfVector readVector (uint32_t offset, uint32_t item_size);
|
virtual DfVector readVector (uint32_t offset, uint32_t item_size);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DATAMODEL_H_INCLUDED
|
#endif // DATAMODEL_H_INCLUDED
|
||||||
|
@ -1,160 +1,296 @@
|
|||||||
/*
|
/*
|
||||||
www.sourceforge.net/projects/dfhack
|
www.sourceforge.net/projects/dfhack
|
||||||
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
|
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied
|
This software is provided 'as-is', without any express or implied
|
||||||
warranty. In no event will the authors be held liable for any
|
warranty. In no event will the authors be held liable for any
|
||||||
damages arising from the use of this software.
|
damages arising from the use of this software.
|
||||||
|
|
||||||
Permission is granted to anyone to use this software for any
|
Permission is granted to anyone to use this software for any
|
||||||
purpose, including commercial applications, and to alter it and
|
purpose, including commercial applications, and to alter it and
|
||||||
redistribute it freely, subject to the following restrictions:
|
redistribute it freely, subject to the following restrictions:
|
||||||
|
|
||||||
1. The origin of this software must not be misrepresented; you must
|
1. The origin of this software must not be misrepresented; you must
|
||||||
not claim that you wrote the original software. If you use this
|
not claim that you wrote the original software. If you use this
|
||||||
software in a product, an acknowledgment in the product documentation
|
software in a product, an acknowledgment in the product documentation
|
||||||
would be appreciated but is not required.
|
would be appreciated but is not required.
|
||||||
|
|
||||||
2. Altered source versions must be plainly marked as such, and
|
2. Altered source versions must be plainly marked as such, and
|
||||||
must not be misrepresented as being the original software.
|
must not be misrepresented as being the original software.
|
||||||
|
|
||||||
3. This notice may not be removed or altered from any source
|
3. This notice may not be removed or altered from any source
|
||||||
distribution.
|
distribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SIMPLEAPI_H_INCLUDED
|
#ifndef SIMPLEAPI_H_INCLUDED
|
||||||
#define SIMPLEAPI_H_INCLUDED
|
#define SIMPLEAPI_H_INCLUDED
|
||||||
|
|
||||||
class memory_info;
|
#ifdef LINUX_BUILD
|
||||||
class DfVector;
|
# ifndef DFHACKAPI
|
||||||
class ProcessManager;
|
# define DFHACKAPI
|
||||||
class Process;
|
# endif
|
||||||
class DataModel;
|
#else
|
||||||
|
# ifdef BUILD_DFHACK_LIB
|
||||||
//FIXME: better control over state, creation and destruction
|
# ifndef DFHACKAPI
|
||||||
//TODO: give this the pimpl treatment?
|
# define DFHACKAPI extern "C" __declspec(dllexport)
|
||||||
class DFHackAPI
|
# endif
|
||||||
{
|
# else
|
||||||
private:
|
# ifndef DFHACKAPI
|
||||||
// internals
|
# define DFHACKAPI extern "C" __declspec(dllimport)
|
||||||
uint32_t * block;
|
# endif
|
||||||
uint32_t x_block_count, y_block_count, z_block_count;
|
# endif
|
||||||
uint32_t regionX, regionY, regionZ;
|
#endif
|
||||||
uint32_t worldSizeX, worldSizeY;
|
|
||||||
|
#include <string>
|
||||||
uint32_t tile_type_offset;
|
#include <vector>
|
||||||
uint32_t designation_offset;
|
#include <stdint.h>
|
||||||
uint32_t occupancy_offset;
|
using namespace std;
|
||||||
|
|
||||||
ProcessManager* pm;
|
class DFHackAPI;
|
||||||
Process* p;
|
|
||||||
DataModel* dm;
|
// Imported function for actually creating an instance
|
||||||
memory_info* offset_descriptor;
|
DFHACKAPI DFHackAPI *CreateDFHackAPI0(const char *path_to_xml);
|
||||||
vector<uint16_t> v_geology[eBiomeCount];
|
|
||||||
string xml;
|
// C++ wrapper for convenience
|
||||||
|
inline DFHackAPI *CreateDFHackAPI(const string &path_to_xml)
|
||||||
bool constructionsInited;
|
{
|
||||||
bool buildingsInited;
|
return CreateDFHackAPI0(path_to_xml.c_str());
|
||||||
bool vegetationInited;
|
}
|
||||||
uint32_t treeoffset;
|
|
||||||
DfVector *p_cons;
|
// Technically the functions that use std::vector are unsafe.
|
||||||
DfVector *p_bld;
|
class DFHackAPI
|
||||||
DfVector *p_veg;
|
{
|
||||||
|
public:
|
||||||
|
virtual ~DFHackAPI() {}
|
||||||
public:
|
|
||||||
DFHackAPI(const string path_to_xml);
|
virtual bool Attach() = 0;
|
||||||
|
virtual bool Detach() = 0;
|
||||||
bool Attach();
|
virtual bool isAttached() = 0;
|
||||||
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.
|
||||||
* Matgloss. next four methods look very similar. I could use two and move the processing one level up...
|
* Yay for nebulous plans for a rock survey tool that tracks how much of which metal could be smelted from available resorces
|
||||||
* 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;
|
||||||
bool ReadStoneMatgloss(vector<t_matgloss> & output);
|
virtual bool ReadMetalMatgloss(vector<t_matgloss> & output) = 0;
|
||||||
bool ReadWoodMatgloss (vector<t_matgloss> & output);
|
virtual bool ReadPlantMatgloss(vector<t_matgloss> & output) = 0;
|
||||||
bool ReadMetalMatgloss(vector<t_matgloss> & output);
|
// FIXME: add creatures for all the creature products
|
||||||
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
|
||||||
// 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
|
||||||
Method for reading the geological surrounding of the currently loaded region.
|
array is indexed by the BiomeOffset enum
|
||||||
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
|
||||||
I omitted resolving the layer matgloss in this API, because it would
|
yourself. First get the stuff from ReadGeology and then for each block get
|
||||||
introduce overhead by calling some method for each tile. You have to do it
|
the RegionOffsets. For each tile get the real region from RegionOffsets and
|
||||||
yourself. First get the stuff from ReadGeology and then for each block get
|
cross-reference it with the geology stuff (region -- array of vectors, depth --
|
||||||
the RegionOffsets. For each tile get the real region from RegionOffsets and
|
vector). I'm thinking about turning that Geology stuff into a
|
||||||
cross-reference it with the geology stuff (region -- array of vectors, depth --
|
two-dimensional array with static size.
|
||||||
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)
|
||||||
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++)
|
||||||
// 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++)
|
||||||
{
|
{
|
||||||
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;
|
||||||
int geolayer = b->designation[x_b][y_b].bits.geolayer_index;
|
b->material[x_b][y_b].type = Mat_Stone;
|
||||||
int biome = b->designation[x_b][y_b].bits.biome;
|
b->material[x_b][y_b].index = v_geology[b->RegionOffsets[biome]][geolayer];
|
||||||
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;
|
||||||
*/
|
|
||||||
bool ReadGeology( vector < vector <uint16_t> >& assign );
|
/*
|
||||||
|
* BLOCK DATA
|
||||||
/*
|
*/
|
||||||
* BLOCK DATA
|
/// allocate and read pointers to map blocks
|
||||||
*/
|
virtual bool InitMap() = 0;
|
||||||
/// allocate and read pointers to map blocks
|
/// destroy the mapblock cache
|
||||||
bool InitMap();
|
virtual bool DestroyMap() = 0;
|
||||||
/// destroy the mapblock cache
|
/// get size of the map in tiles
|
||||||
bool DestroyMap();
|
virtual void getSize(uint32_t& x, uint32_t& y, uint32_t& z) = 0;
|
||||||
/// 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
|
||||||
/**
|
*/
|
||||||
* 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;
|
||||||
*/
|
|
||||||
bool isValidBlock(uint32_t blockx, uint32_t blocky, uint32_t blockz);
|
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)
|
||||||
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)
|
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;
|
||||||
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);
|
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)
|
||||||
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
|
||||||
|
virtual bool ReadRegionOffsets(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint8_t *buffer) = 0; // 16 * sizeof(uint8_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
|
||||||
|
virtual bool ReadVeins(uint32_t blockx, uint32_t blocky, uint32_t blockz, vector <t_vein> & veins) = 0;
|
||||||
/// 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
|
||||||
/**
|
*/
|
||||||
* 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;
|
||||||
uint32_t InitReadConstructions();
|
virtual void FinishReadConstructions() = 0;
|
||||||
bool ReadConstruction(const uint32_t &index, t_construction & construction);
|
|
||||||
void FinishReadConstructions();
|
virtual uint32_t InitReadBuildings(vector <string> &v_buildingtypes) = 0;
|
||||||
|
virtual bool ReadBuilding(const uint32_t &index, t_building & building) = 0;
|
||||||
uint32_t InitReadBuildings(vector <string> &v_buildingtypes);
|
virtual void FinishReadBuildings() = 0;
|
||||||
bool ReadBuilding(const uint32_t &index, t_building & building);
|
|
||||||
void FinishReadBuildings();
|
virtual uint32_t InitReadVegetation() = 0;
|
||||||
|
virtual bool ReadVegetation(const uint32_t &index, t_tree_desc & shrubbery) = 0;
|
||||||
uint32_t InitReadVegetation();
|
virtual void FinishReadVegetation() = 0;
|
||||||
bool ReadVegetation(const uint32_t &index, t_tree_desc & shrubbery);
|
};
|
||||||
void FinishReadVegetation();
|
|
||||||
};
|
#ifdef BUILD_DFHACK_LIB
|
||||||
#endif // 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 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
|
www.sourceforge.net/projects/dfhack
|
||||||
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
|
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied
|
This software is provided 'as-is', without any express or implied
|
||||||
warranty. In no event will the authors be held liable for any
|
warranty. In no event will the authors be held liable for any
|
||||||
damages arising from the use of this software.
|
damages arising from the use of this software.
|
||||||
|
|
||||||
Permission is granted to anyone to use this software for any
|
Permission is granted to anyone to use this software for any
|
||||||
purpose, including commercial applications, and to alter it and
|
purpose, including commercial applications, and to alter it and
|
||||||
redistribute it freely, subject to the following restrictions:
|
redistribute it freely, subject to the following restrictions:
|
||||||
|
|
||||||
1. The origin of this software must not be misrepresented; you must
|
1. The origin of this software must not be misrepresented; you must
|
||||||
not claim that you wrote the original software. If you use this
|
not claim that you wrote the original software. If you use this
|
||||||
software in a product, an acknowledgment in the product documentation
|
software in a product, an acknowledgment in the product documentation
|
||||||
would be appreciated but is not required.
|
would be appreciated but is not required.
|
||||||
|
|
||||||
2. Altered source versions must be plainly marked as such, and
|
2. Altered source versions must be plainly marked as such, and
|
||||||
must not be misrepresented as being the original software.
|
must not be misrepresented as being the original software.
|
||||||
|
|
||||||
3. This notice may not be removed or altered from any source
|
3. This notice may not be removed or altered from any source
|
||||||
distribution.
|
distribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef PROCESSUTIL_H_INCLUDED
|
#ifndef PROCESSUTIL_H_INCLUDED
|
||||||
#define PROCESSUTIL_H_INCLUDED
|
#define PROCESSUTIL_H_INCLUDED
|
||||||
|
|
||||||
#ifdef LINUX_BUILD
|
#ifdef LINUX_BUILD
|
||||||
#include "LinuxMemAccess.h"
|
#include "LinuxMemAccess.h"
|
||||||
#else
|
#else
|
||||||
#include "WindowsMemAccess.h"
|
#include "WindowsMemAccess.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // PROCESSUTIL_H_INCLUDED
|
#endif // PROCESSUTIL_H_INCLUDED
|
||||||
|
@ -1,113 +1,113 @@
|
|||||||
/*
|
/*
|
||||||
www.sourceforge.net/projects/dfhack
|
www.sourceforge.net/projects/dfhack
|
||||||
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
|
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied
|
This software is provided 'as-is', without any express or implied
|
||||||
warranty. In no event will the authors be held liable for any
|
warranty. In no event will the authors be held liable for any
|
||||||
damages arising from the use of this software.
|
damages arising from the use of this software.
|
||||||
|
|
||||||
Permission is granted to anyone to use this software for any
|
Permission is granted to anyone to use this software for any
|
||||||
purpose, including commercial applications, and to alter it and
|
purpose, including commercial applications, and to alter it and
|
||||||
redistribute it freely, subject to the following restrictions:
|
redistribute it freely, subject to the following restrictions:
|
||||||
|
|
||||||
1. The origin of this software must not be misrepresented; you must
|
1. The origin of this software must not be misrepresented; you must
|
||||||
not claim that you wrote the original software. If you use this
|
not claim that you wrote the original software. If you use this
|
||||||
software in a product, an acknowledgment in the product documentation
|
software in a product, an acknowledgment in the product documentation
|
||||||
would be appreciated but is not required.
|
would be appreciated but is not required.
|
||||||
|
|
||||||
2. Altered source versions must be plainly marked as such, and
|
2. Altered source versions must be plainly marked as such, and
|
||||||
must not be misrepresented as being the original software.
|
must not be misrepresented as being the original software.
|
||||||
|
|
||||||
3. This notice may not be removed or altered from any source
|
3. This notice may not be removed or altered from any source
|
||||||
distribution.
|
distribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MEMINFO_H_INCLUDED
|
#ifndef MEMINFO_H_INCLUDED
|
||||||
#define MEMINFO_H_INCLUDED
|
#define MEMINFO_H_INCLUDED
|
||||||
|
|
||||||
class memory_info
|
class memory_info
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum OSType
|
enum OSType
|
||||||
{
|
{
|
||||||
OS_WINDOWS,
|
OS_WINDOWS,
|
||||||
OS_LINUX,
|
OS_LINUX,
|
||||||
OS_BAD
|
OS_BAD
|
||||||
};
|
};
|
||||||
struct t_class
|
struct t_class
|
||||||
{
|
{
|
||||||
string classname;
|
string classname;
|
||||||
uint32_t vtable;
|
uint32_t vtable;
|
||||||
bool is_multiclass;
|
bool is_multiclass;
|
||||||
uint32_t multi_index;
|
uint32_t multi_index;
|
||||||
uint32_t assign;// index to typeclass array if multiclass. return value if not.
|
uint32_t assign;// index to typeclass array if multiclass. return value if not.
|
||||||
uint32_t type_offset; // offset of type data for multiclass
|
uint32_t type_offset; // offset of type data for multiclass
|
||||||
};
|
};
|
||||||
struct t_type
|
struct t_type
|
||||||
{
|
{
|
||||||
string classname;
|
string classname;
|
||||||
uint32_t assign;
|
uint32_t assign;
|
||||||
uint32_t type;
|
uint32_t type;
|
||||||
};
|
};
|
||||||
memory_info();
|
memory_info();
|
||||||
memory_info(const memory_info&);
|
memory_info(const memory_info&);
|
||||||
|
|
||||||
|
|
||||||
void RebaseAddresses(int32_t new_base);
|
void RebaseAddresses(int32_t new_base);
|
||||||
void RebaseAll(int32_t new_base);
|
void RebaseAll(int32_t new_base);
|
||||||
uint32_t getBase ();
|
uint32_t getBase ();
|
||||||
void setBase (string);
|
void setBase (string);
|
||||||
void setBase (uint32_t);
|
void setBase (uint32_t);
|
||||||
|
|
||||||
uint32_t getOffset (string);
|
uint32_t getOffset (string);
|
||||||
uint32_t getAddress (string);
|
uint32_t getAddress (string);
|
||||||
uint32_t getHexValue (string);
|
uint32_t getHexValue (string);
|
||||||
string getString (string);
|
string getString (string);
|
||||||
|
|
||||||
void setVersion(const char *);
|
void setVersion(const char *);
|
||||||
void setVersion(string);
|
void setVersion(string);
|
||||||
string getVersion();
|
string getVersion();
|
||||||
|
|
||||||
void setOS(const char *);
|
void setOS(const char *);
|
||||||
void setOS(string);
|
void setOS(string);
|
||||||
void setOS(OSType);
|
void setOS(OSType);
|
||||||
OSType getOS();
|
OSType getOS();
|
||||||
|
|
||||||
void setOffset (string, int32_t);
|
void setOffset (string, int32_t);
|
||||||
void setAddress (string, uint32_t);
|
void setAddress (string, uint32_t);
|
||||||
void setHexValue (string, uint32_t);
|
void setHexValue (string, uint32_t);
|
||||||
|
|
||||||
void setOffset (string, const char *);
|
void setOffset (string, const char *);
|
||||||
void setAddress (string, const char *);
|
void setAddress (string, const char *);
|
||||||
void setHexValue (string, const char *);
|
void setHexValue (string, const char *);
|
||||||
void setString (string, const char *);
|
void setString (string, const char *);
|
||||||
|
|
||||||
void setOffset (string, string);
|
void setOffset (string, string);
|
||||||
void setAddress (string, string);
|
void setAddress (string, string);
|
||||||
void setHexValue (string, string);
|
void setHexValue (string, string);
|
||||||
void setString (string, string);
|
void setString (string, string);
|
||||||
|
|
||||||
void RebaseVTable(int32_t offset);
|
void RebaseVTable(int32_t offset);
|
||||||
void setClass (const char * name, const char * vtable);
|
void setClass (const char * name, const char * vtable);
|
||||||
uint32_t setMultiClass (const char * name, const char * vtable, const char * typeoffset);
|
uint32_t setMultiClass (const char * name, const char * vtable, const char * typeoffset);
|
||||||
void setMultiClassChild (uint32_t multi_index, const char * name, const char * type);
|
void setMultiClassChild (uint32_t multi_index, const char * name, const char * type);
|
||||||
|
|
||||||
// ALERT: uses memory reading directly
|
// ALERT: uses memory reading directly
|
||||||
bool resolveClassId(uint32_t address, int32_t & classid);
|
bool resolveClassId(uint32_t address, int32_t & classid);
|
||||||
void copyBuildings(vector<string> & v_buildingtypes);
|
void copyBuildings(vector<string> & v_buildingtypes);
|
||||||
|
|
||||||
void flush();
|
void flush();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
map <string, uint32_t> addresses;
|
map <string, uint32_t> addresses;
|
||||||
map <string, uint32_t> offsets;
|
map <string, uint32_t> offsets;
|
||||||
map <string, uint32_t> hexvals;
|
map <string, uint32_t> hexvals;
|
||||||
map <string, string> strings;
|
map <string, string> strings;
|
||||||
vector<t_class> classes;
|
vector<t_class> classes;
|
||||||
vector<vector<t_type> > classsubtypes;
|
vector<vector<t_type> > classsubtypes;
|
||||||
int32_t base;
|
int32_t base;
|
||||||
uint32_t classindex;
|
uint32_t classindex;
|
||||||
string version;
|
string version;
|
||||||
OSType OS;
|
OSType OS;
|
||||||
};
|
};
|
||||||
#endif // MEMINFO_H_INCLUDED
|
#endif // MEMINFO_H_INCLUDED
|
||||||
|
@ -1,97 +1,97 @@
|
|||||||
/*
|
/*
|
||||||
www.sourceforge.net/projects/dfhack
|
www.sourceforge.net/projects/dfhack
|
||||||
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
|
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied
|
This software is provided 'as-is', without any express or implied
|
||||||
warranty. In no event will the authors be held liable for any
|
warranty. In no event will the authors be held liable for any
|
||||||
damages arising from the use of this software.
|
damages arising from the use of this software.
|
||||||
|
|
||||||
Permission is granted to anyone to use this software for any
|
Permission is granted to anyone to use this software for any
|
||||||
purpose, including commercial applications, and to alter it and
|
purpose, including commercial applications, and to alter it and
|
||||||
redistribute it freely, subject to the following restrictions:
|
redistribute it freely, subject to the following restrictions:
|
||||||
|
|
||||||
1. The origin of this software must not be misrepresented; you must
|
1. The origin of this software must not be misrepresented; you must
|
||||||
not claim that you wrote the original software. If you use this
|
not claim that you wrote the original software. If you use this
|
||||||
software in a product, an acknowledgment in the product documentation
|
software in a product, an acknowledgment in the product documentation
|
||||||
would be appreciated but is not required.
|
would be appreciated but is not required.
|
||||||
|
|
||||||
2. Altered source versions must be plainly marked as such, and
|
2. Altered source versions must be plainly marked as such, and
|
||||||
must not be misrepresented as being the original software.
|
must not be misrepresented as being the original software.
|
||||||
|
|
||||||
3. This notice may not be removed or altered from any source
|
3. This notice may not be removed or altered from any source
|
||||||
distribution.
|
distribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef PROCESSMANAGER_H_INCLUDED
|
#ifndef PROCESSMANAGER_H_INCLUDED
|
||||||
#define PROCESSMANAGER_H_INCLUDED
|
#define PROCESSMANAGER_H_INCLUDED
|
||||||
|
|
||||||
#ifdef LINUX_BUILD
|
#ifdef LINUX_BUILD
|
||||||
typedef pid_t ProcessHandle;
|
typedef pid_t ProcessHandle;
|
||||||
#else
|
#else
|
||||||
typedef HANDLE ProcessHandle;
|
typedef HANDLE ProcessHandle;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class memory_info;
|
class memory_info;
|
||||||
class DataModel;
|
class DataModel;
|
||||||
class TiXmlElement;
|
class TiXmlElement;
|
||||||
class Process;
|
class Process;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Currently attached process and its handle
|
* Currently attached process and its handle
|
||||||
*/
|
*/
|
||||||
extern Process * g_pProcess; ///< current process. non-NULL when picked
|
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 ProcessHandle g_ProcessHandle; ///< cache of handle to current process. used for speed reasons
|
||||||
extern FILE * g_ProcessMemFile; ///< opened /proc/PID/mem, valid when attached
|
extern FILE * g_ProcessMemFile; ///< opened /proc/PID/mem, valid when attached
|
||||||
|
|
||||||
class Process
|
class Process
|
||||||
{
|
{
|
||||||
friend class ProcessManager;
|
friend class ProcessManager;
|
||||||
protected:
|
protected:
|
||||||
Process(DataModel * dm, memory_info* mi, ProcessHandle ph, uint32_t pid);
|
Process(DataModel * dm, memory_info* mi, ProcessHandle ph, uint32_t pid);
|
||||||
~Process();
|
~Process();
|
||||||
DataModel* my_datamodel;
|
DataModel* my_datamodel;
|
||||||
memory_info * my_descriptor;
|
memory_info * my_descriptor;
|
||||||
ProcessHandle my_handle;
|
ProcessHandle my_handle;
|
||||||
uint32_t my_pid;
|
uint32_t my_pid;
|
||||||
string memFile;
|
string memFile;
|
||||||
bool attached;
|
bool attached;
|
||||||
void freeResources();
|
void freeResources();
|
||||||
void setMemFile(const string & memf);
|
void setMemFile(const string & memf);
|
||||||
public:
|
public:
|
||||||
// Set up stuff so we can read memory
|
// Set up stuff so we can read memory
|
||||||
bool attach();
|
bool attach();
|
||||||
bool detach();
|
bool detach();
|
||||||
// is the process still there?
|
// is the process still there?
|
||||||
memory_info *getDescriptor();
|
memory_info *getDescriptor();
|
||||||
DataModel *getDataModel();
|
DataModel *getDataModel();
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Process manager
|
* Process manager
|
||||||
*/
|
*/
|
||||||
class ProcessManager
|
class ProcessManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ProcessManager( string path_to_xml);
|
ProcessManager( string path_to_xml);
|
||||||
~ProcessManager();
|
~ProcessManager();
|
||||||
bool findProcessess();
|
bool findProcessess();
|
||||||
uint32_t size();
|
uint32_t size();
|
||||||
Process * operator[](uint32_t index);
|
Process * operator[](uint32_t index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// memory info entries loaded from a file
|
// memory info entries loaded from a file
|
||||||
std::vector<memory_info> meminfo;
|
std::vector<memory_info> meminfo;
|
||||||
// vector to keep track of dynamically created memory_info entries
|
// vector to keep track of dynamically created memory_info entries
|
||||||
std::vector<memory_info *> destroy_meminfo;
|
std::vector<memory_info *> destroy_meminfo;
|
||||||
Process * currentProcess;
|
Process * currentProcess;
|
||||||
ProcessHandle currentProcessHandle;
|
ProcessHandle currentProcessHandle;
|
||||||
std::vector<Process *> processes;
|
std::vector<Process *> processes;
|
||||||
bool loadDescriptors( string path_to_xml);
|
bool loadDescriptors( string path_to_xml);
|
||||||
void ParseVTable(TiXmlElement* vtable, memory_info& mem);
|
void ParseVTable(TiXmlElement* vtable, memory_info& mem);
|
||||||
void ParseEntry (TiXmlElement* entry, memory_info& mem, map <string ,TiXmlElement *>& knownEntries);
|
void ParseEntry (TiXmlElement* entry, memory_info& mem, map <string ,TiXmlElement *>& knownEntries);
|
||||||
#ifdef LINUX_BUILD
|
#ifdef LINUX_BUILD
|
||||||
Process* addProcess(const string & exe,ProcessHandle PH,const string & memFile);
|
Process* addProcess(const string & exe,ProcessHandle PH,const string & memFile);
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PROCESSMANAGER_H_INCLUDED
|
#endif // PROCESSMANAGER_H_INCLUDED
|
||||||
|
@ -1,44 +1,61 @@
|
|||||||
/*
|
/*
|
||||||
www.sourceforge.net/projects/dfhack
|
www.sourceforge.net/projects/dfhack
|
||||||
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
|
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied
|
This software is provided 'as-is', without any express or implied
|
||||||
warranty. In no event will the authors be held liable for any
|
warranty. In no event will the authors be held liable for any
|
||||||
damages arising from the use of this software.
|
damages arising from the use of this software.
|
||||||
|
|
||||||
Permission is granted to anyone to use this software for any
|
Permission is granted to anyone to use this software for any
|
||||||
purpose, including commercial applications, and to alter it and
|
purpose, including commercial applications, and to alter it and
|
||||||
redistribute it freely, subject to the following restrictions:
|
redistribute it freely, subject to the following restrictions:
|
||||||
|
|
||||||
1. The origin of this software must not be misrepresented; you must
|
1. The origin of this software must not be misrepresented; you must
|
||||||
not claim that you wrote the original software. If you use this
|
not claim that you wrote the original software. If you use this
|
||||||
software in a product, an acknowledgment in the product documentation
|
software in a product, an acknowledgment in the product documentation
|
||||||
would be appreciated but is not required.
|
would be appreciated but is not required.
|
||||||
|
|
||||||
2. Altered source versions must be plainly marked as such, and
|
2. Altered source versions must be plainly marked as such, and
|
||||||
must not be misrepresented as being the original software.
|
must not be misrepresented as being the original software.
|
||||||
|
|
||||||
3. This notice may not be removed or altered from any source
|
3. This notice may not be removed or altered from any source
|
||||||
distribution.
|
distribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TILETYPES_H_INCLUDED
|
#ifndef TILETYPES_H_INCLUDED
|
||||||
#define TILETYPES_H_INCLUDED
|
#define TILETYPES_H_INCLUDED
|
||||||
enum VegetationType{
|
|
||||||
TREE_DEAD,
|
#ifdef LINUX_BUILD
|
||||||
TREE_OK,
|
# ifndef DFHACKAPI
|
||||||
SAPLING_DEAD,
|
# define DFHACKAPI
|
||||||
SAPLING_OK,
|
# endif
|
||||||
SHRUB_DEAD,
|
#else
|
||||||
SHRUB_OK
|
# ifdef BUILD_DFHACK_LIB
|
||||||
};
|
# ifndef DFHACKAPI
|
||||||
|
# define DFHACKAPI extern "C" __declspec(dllexport)
|
||||||
bool isWallTerrain(int in);
|
# endif
|
||||||
bool isFloorTerrain(int in);
|
# else
|
||||||
bool isRampTerrain(int in);
|
# ifndef DFHACKAPI
|
||||||
bool isStairTerrain(int in);
|
# define DFHACKAPI extern "C" __declspec(dllimport)
|
||||||
bool isOpenTerrain(int in);
|
# endif
|
||||||
int getVegetationType(int in);
|
# endif
|
||||||
int picktexture(int in);
|
#endif
|
||||||
|
|
||||||
#endif // TILETYPES_H_INCLUDED
|
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
|
www.sourceforge.net/projects/dfhack
|
||||||
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
|
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied
|
This software is provided 'as-is', without any express or implied
|
||||||
warranty. In no event will the authors be held liable for any
|
warranty. In no event will the authors be held liable for any
|
||||||
damages arising from the use of this software.
|
damages arising from the use of this software.
|
||||||
|
|
||||||
Permission is granted to anyone to use this software for any
|
Permission is granted to anyone to use this software for any
|
||||||
purpose, including commercial applications, and to alter it and
|
purpose, including commercial applications, and to alter it and
|
||||||
redistribute it freely, subject to the following restrictions:
|
redistribute it freely, subject to the following restrictions:
|
||||||
|
|
||||||
1. The origin of this software must not be misrepresented; you must
|
1. The origin of this software must not be misrepresented; you must
|
||||||
not claim that you wrote the original software. If you use this
|
not claim that you wrote the original software. If you use this
|
||||||
software in a product, an acknowledgment in the product documentation
|
software in a product, an acknowledgment in the product documentation
|
||||||
would be appreciated but is not required.
|
would be appreciated but is not required.
|
||||||
|
|
||||||
2. Altered source versions must be plainly marked as such, and
|
2. Altered source versions must be plainly marked as such, and
|
||||||
must not be misrepresented as being the original software.
|
must not be misrepresented as being the original software.
|
||||||
|
|
||||||
3. This notice may not be removed or altered from any source
|
3. This notice may not be removed or altered from any source
|
||||||
distribution.
|
distribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TYPES_H_INCLUDED
|
#ifndef TYPES_H_INCLUDED
|
||||||
#define TYPES_H_INCLUDED
|
#define TYPES_H_INCLUDED
|
||||||
|
|
||||||
struct t_matgloss
|
struct t_matgloss
|
||||||
{
|
{
|
||||||
string id;
|
string id;
|
||||||
uint8_t fore; // Annoyingly the offset for this differs between types
|
uint8_t fore; // Annoyingly the offset for this differs between types
|
||||||
uint8_t back;
|
uint8_t back;
|
||||||
uint8_t bright;
|
uint8_t bright;
|
||||||
};
|
};
|
||||||
struct t_vein
|
struct t_vein
|
||||||
{
|
{
|
||||||
uint32_t vtable;
|
uint32_t vtable;
|
||||||
int16_t type;
|
int16_t type;
|
||||||
int16_t assignment[16];
|
int16_t assignment[16];
|
||||||
int16_t unknown;
|
int16_t unknown;
|
||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct t_matglossPair
|
struct t_matglossPair
|
||||||
{
|
{
|
||||||
int16_t type;
|
int16_t type;
|
||||||
int16_t index;
|
int16_t index;
|
||||||
};
|
};
|
||||||
|
|
||||||
// raw
|
// raw
|
||||||
struct t_construction_df40d
|
struct t_construction_df40d
|
||||||
{
|
{
|
||||||
int16_t x;
|
int16_t x;
|
||||||
int16_t y;
|
int16_t y;
|
||||||
int16_t z;
|
int16_t z;
|
||||||
int16_t unk1;
|
int16_t unk1;
|
||||||
int16_t unk2;
|
int16_t unk2;
|
||||||
t_matglossPair material; // 4B
|
t_matglossPair material; // 4B
|
||||||
// int16_t mat_type;
|
// int16_t mat_type;
|
||||||
// int16_t mat_idx;
|
// int16_t mat_idx;
|
||||||
};
|
};
|
||||||
|
|
||||||
// cooked
|
// cooked
|
||||||
struct t_construction
|
struct t_construction
|
||||||
{
|
{
|
||||||
uint16_t x;
|
uint16_t x;
|
||||||
uint16_t y;
|
uint16_t y;
|
||||||
uint16_t z;
|
uint16_t z;
|
||||||
t_matglossPair material;
|
t_matglossPair material;
|
||||||
// int16_t mat_type;
|
// int16_t mat_type;
|
||||||
// int16_t mat_idx;
|
// int16_t mat_idx;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
dword vtable;
|
dword vtable;
|
||||||
int minx;
|
int minx;
|
||||||
int miny;
|
int miny;
|
||||||
int centerx;
|
int centerx;
|
||||||
int maxx;
|
int maxx;
|
||||||
int maxy;
|
int maxy;
|
||||||
int centery;
|
int centery;
|
||||||
int z;
|
int z;
|
||||||
dword height_not_used;
|
dword height_not_used;
|
||||||
word mattype;
|
word mattype;
|
||||||
word matgloss;
|
word matgloss;
|
||||||
word type; // NOTE: the actual field is in a different place
|
word type; // NOTE: the actual field is in a different place
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//raw
|
//raw
|
||||||
struct t_building_df40d
|
struct t_building_df40d
|
||||||
{
|
{
|
||||||
uint32_t vtable;
|
uint32_t vtable;
|
||||||
uint32_t x1;
|
uint32_t x1;
|
||||||
uint32_t y1;
|
uint32_t y1;
|
||||||
uint32_t centerx;
|
uint32_t centerx;
|
||||||
uint32_t x2;
|
uint32_t x2;
|
||||||
uint32_t y2;
|
uint32_t y2;
|
||||||
uint32_t centery;
|
uint32_t centery;
|
||||||
uint32_t z;
|
uint32_t z;
|
||||||
uint32_t height;
|
uint32_t height;
|
||||||
t_matglossPair material;
|
t_matglossPair material;
|
||||||
// not complete
|
// not complete
|
||||||
};
|
};
|
||||||
|
|
||||||
//cooked
|
//cooked
|
||||||
struct t_building
|
struct t_building
|
||||||
{
|
{
|
||||||
uint32_t vtable;
|
uint32_t vtable;
|
||||||
|
|
||||||
uint32_t x1;
|
uint32_t x1;
|
||||||
uint32_t y1;
|
uint32_t y1;
|
||||||
|
|
||||||
uint32_t x2;
|
uint32_t x2;
|
||||||
uint32_t y2;
|
uint32_t y2;
|
||||||
|
|
||||||
uint32_t z;
|
uint32_t z;
|
||||||
|
|
||||||
t_matglossPair material;
|
t_matglossPair material;
|
||||||
|
|
||||||
uint32_t type;
|
uint32_t type;
|
||||||
// FIXME: not complete, we need building presence bitmaps for stuff like farm plots and stockpiles, orientation (N,E,S,W) and state (open/closed)
|
// 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
|
struct t_tree_desc
|
||||||
{
|
{
|
||||||
t_matglossPair material;
|
t_matglossPair material;
|
||||||
uint16_t x;
|
uint16_t x;
|
||||||
uint16_t y;
|
uint16_t y;
|
||||||
uint16_t z;
|
uint16_t z;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
case 10:
|
case 10:
|
||||||
ret += "leather";
|
ret += "leather";
|
||||||
break;
|
break;
|
||||||
case 11:
|
case 11:
|
||||||
ret += "silk cloth";
|
ret += "silk cloth";
|
||||||
break;
|
break;
|
||||||
case 12:
|
case 12:
|
||||||
ret += "plant thread cloth";
|
ret += "plant thread cloth";
|
||||||
break;
|
break;
|
||||||
case 13: // green glass
|
case 13: // green glass
|
||||||
ret += "green glass";
|
ret += "green glass";
|
||||||
break;
|
break;
|
||||||
case 14: // clear glass
|
case 14: // clear glass
|
||||||
ret += "clear glass";
|
ret += "clear glass";
|
||||||
break;
|
break;
|
||||||
case 15: // crystal glass
|
case 15: // crystal glass
|
||||||
ret += "crystal glass";
|
ret += "crystal glass";
|
||||||
break;
|
break;
|
||||||
case 17:
|
case 17:
|
||||||
ret += "ice";
|
ret += "ice";
|
||||||
break;
|
break;
|
||||||
case 18:
|
case 18:
|
||||||
ret += "charcoal";
|
ret += "charcoal";
|
||||||
break;
|
break;
|
||||||
case 19:
|
case 19:
|
||||||
ret += "potash";
|
ret += "potash";
|
||||||
break;
|
break;
|
||||||
case 20:
|
case 20:
|
||||||
ret += "ashes";
|
ret += "ashes";
|
||||||
break;
|
break;
|
||||||
case 21:
|
case 21:
|
||||||
ret += "pearlash";
|
ret += "pearlash";
|
||||||
break;
|
break;
|
||||||
case 24:
|
case 24:
|
||||||
ret += "soap";
|
ret += "soap";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// FIXME: in order in which the raw vectors appear in df memory, move to XML
|
// FIXME: in order in which the raw vectors appear in df memory, move to XML
|
||||||
enum MatglossType
|
enum MatglossType
|
||||||
{
|
{
|
||||||
Mat_Wood,
|
Mat_Wood,
|
||||||
Mat_Stone,
|
Mat_Stone,
|
||||||
Mat_Plant,
|
Mat_Plant,
|
||||||
Mat_Metal,
|
Mat_Metal,
|
||||||
Mat_Leather = 10,
|
Mat_Leather = 10,
|
||||||
Mat_SilkCloth = 11,
|
Mat_SilkCloth = 11,
|
||||||
Mat_PlantCloth = 12,
|
Mat_PlantCloth = 12,
|
||||||
Mat_GreenGlass = 13,
|
Mat_GreenGlass = 13,
|
||||||
Mat_ClearGlass = 14,
|
Mat_ClearGlass = 14,
|
||||||
Mat_CrystalGlass = 15,
|
Mat_CrystalGlass = 15,
|
||||||
Mat_Ice = 17,
|
Mat_Ice = 17,
|
||||||
Mat_Charcoal =18,
|
Mat_Charcoal =18,
|
||||||
Mat_Potash = 20,
|
Mat_Potash = 20,
|
||||||
Mat_Ashes = 20,
|
Mat_Ashes = 20,
|
||||||
Mat_PearlAsh = 21,
|
Mat_PearlAsh = 21,
|
||||||
Mat_Soap = 24,
|
Mat_Soap = 24,
|
||||||
//NUM_MATGLOSS_TYPES
|
//NUM_MATGLOSS_TYPES
|
||||||
};
|
};
|
||||||
|
|
||||||
enum BiomeOffset
|
enum BiomeOffset
|
||||||
{
|
{
|
||||||
eNorthWest,
|
eNorthWest,
|
||||||
eNorth,
|
eNorth,
|
||||||
eNorthEast,
|
eNorthEast,
|
||||||
eWest,
|
eWest,
|
||||||
eHere,
|
eHere,
|
||||||
eEast,
|
eEast,
|
||||||
eSouthWest,
|
eSouthWest,
|
||||||
eSouth,
|
eSouth,
|
||||||
eSouthEast,
|
eSouthEast,
|
||||||
eBiomeCount
|
eBiomeCount
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: research this further? consult DF hacker wizards?
|
// TODO: research this further? consult DF hacker wizards?
|
||||||
union t_designation
|
union t_designation
|
||||||
{
|
{
|
||||||
uint32_t whole;
|
uint32_t whole;
|
||||||
struct {
|
struct {
|
||||||
unsigned int flow_size : 3; // how much liquid is here?
|
unsigned int flow_size : 3; // how much liquid is here?
|
||||||
unsigned int pile : 1; // stockpile?
|
unsigned int pile : 1; // stockpile?
|
||||||
/*
|
/*
|
||||||
* All the different dig designations... needs more info, probably an enum
|
* All the different dig designations... needs more info, probably an enum
|
||||||
*/
|
*/
|
||||||
unsigned int dig : 3;
|
unsigned int dig : 3;
|
||||||
unsigned int detail : 1;///<- wtf
|
unsigned int detail : 1;///<- wtf
|
||||||
unsigned int detail_event : 1;///<- more wtf
|
unsigned int detail_event : 1;///<- more wtf
|
||||||
unsigned int hidden :1;
|
unsigned int hidden :1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This one is rather involved, but necessary to retrieve the base layer matgloss index
|
* 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
|
* see http://www.bay12games.com/forum/index.php?topic=608.msg253284#msg253284 for details
|
||||||
*/
|
*/
|
||||||
unsigned int geolayer_index :4;
|
unsigned int geolayer_index :4;
|
||||||
unsigned int light : 1;
|
unsigned int light : 1;
|
||||||
unsigned int subterranean : 1; // never seen the light of day?
|
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
|
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.
|
* Probably similar to the geolayer_index. Only with a different set of offsets and different data.
|
||||||
* we don't use this yet
|
* we don't use this yet
|
||||||
*/
|
*/
|
||||||
unsigned int biome : 4;
|
unsigned int biome : 4;
|
||||||
/*
|
/*
|
||||||
0 = water
|
0 = water
|
||||||
1 = magma
|
1 = magma
|
||||||
*/
|
*/
|
||||||
unsigned int liquid_type : 1;
|
unsigned int liquid_type : 1;
|
||||||
unsigned int water_table : 1; // srsly. wtf?
|
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 rained : 1; // does this mean actual rain (as in the blue blocks) or a wet tile?
|
||||||
unsigned int traffic : 2; // needs enum
|
unsigned int traffic : 2; // needs enum
|
||||||
unsigned int flow_forbid : 1; // idk wtf bbq
|
unsigned int flow_forbid : 1; // idk wtf bbq
|
||||||
unsigned int liquid_static : 1;
|
unsigned int liquid_static : 1;
|
||||||
unsigned int moss : 1;// I LOVE MOSS
|
unsigned int moss : 1;// I LOVE MOSS
|
||||||
unsigned int feature_present : 1; // another wtf... is this required for magma pipes to work?
|
unsigned int feature_present : 1; // another wtf... is this required for magma pipes to work?
|
||||||
unsigned int liquid_character : 2; // those ripples on streams?
|
unsigned int liquid_character : 2; // those ripples on streams?
|
||||||
} bits;
|
} bits;
|
||||||
};
|
};
|
||||||
|
|
||||||
// occupancy flags (rat,dwarf,horse,built wall,not build wall,etc)
|
// occupancy flags (rat,dwarf,horse,built wall,not build wall,etc)
|
||||||
union t_occupancy
|
union t_occupancy
|
||||||
{
|
{
|
||||||
uint32_t whole;
|
uint32_t whole;
|
||||||
struct {
|
struct {
|
||||||
unsigned int building : 3;// building type... should be an enum?
|
unsigned int building : 3;// building type... should be an enum?
|
||||||
// 7 = door
|
// 7 = door
|
||||||
unsigned int unit : 1;
|
unsigned int unit : 1;
|
||||||
unsigned int unit_grounded : 1;
|
unsigned int unit_grounded : 1;
|
||||||
unsigned int item : 1;
|
unsigned int item : 1;
|
||||||
// splatter. everyone loves splatter.
|
// splatter. everyone loves splatter.
|
||||||
unsigned int mud : 1;
|
unsigned int mud : 1;
|
||||||
unsigned int vomit :1;
|
unsigned int vomit :1;
|
||||||
unsigned int debris1 :1;
|
unsigned int debris1 :1;
|
||||||
unsigned int debris2 :1;
|
unsigned int debris2 :1;
|
||||||
unsigned int debris3 :1;
|
unsigned int debris3 :1;
|
||||||
unsigned int debris4 :1;
|
unsigned int debris4 :1;
|
||||||
unsigned int blood_g : 1;
|
unsigned int blood_g : 1;
|
||||||
unsigned int blood_g2 : 1;
|
unsigned int blood_g2 : 1;
|
||||||
unsigned int blood_b : 1;
|
unsigned int blood_b : 1;
|
||||||
unsigned int blood_b2 : 1;
|
unsigned int blood_b2 : 1;
|
||||||
unsigned int blood_y : 1;
|
unsigned int blood_y : 1;
|
||||||
unsigned int blood_y2 : 1;
|
unsigned int blood_y2 : 1;
|
||||||
unsigned int blood_m : 1;
|
unsigned int blood_m : 1;
|
||||||
unsigned int blood_m2 : 1;
|
unsigned int blood_m2 : 1;
|
||||||
unsigned int blood_c : 1;
|
unsigned int blood_c : 1;
|
||||||
unsigned int blood_c2 : 1;
|
unsigned int blood_c2 : 1;
|
||||||
unsigned int blood_w : 1;
|
unsigned int blood_w : 1;
|
||||||
unsigned int blood_w2 : 1;
|
unsigned int blood_w2 : 1;
|
||||||
unsigned int blood_o : 1;
|
unsigned int blood_o : 1;
|
||||||
unsigned int blood_o2 : 1;
|
unsigned int blood_o2 : 1;
|
||||||
unsigned int slime : 1;
|
unsigned int slime : 1;
|
||||||
unsigned int slime2 : 1;
|
unsigned int slime2 : 1;
|
||||||
unsigned int blood : 1;
|
unsigned int blood : 1;
|
||||||
unsigned int blood2 : 1;
|
unsigned int blood2 : 1;
|
||||||
unsigned int debris5 : 1;
|
unsigned int debris5 : 1;
|
||||||
unsigned int snow : 1;
|
unsigned int snow : 1;
|
||||||
} bits;
|
} bits;
|
||||||
struct {
|
struct {
|
||||||
unsigned int building : 3;// building type... should be an enum?
|
unsigned int building : 3;// building type... should be an enum?
|
||||||
// 7 = door
|
// 7 = door
|
||||||
unsigned int unit : 1;
|
unsigned int unit : 1;
|
||||||
unsigned int unit_grounded : 1;
|
unsigned int unit_grounded : 1;
|
||||||
unsigned int item : 1;
|
unsigned int item : 1;
|
||||||
// splatter. everyone loves splatter.
|
// splatter. everyone loves splatter.
|
||||||
unsigned int splatter : 26;
|
unsigned int splatter : 26;
|
||||||
} unibits;
|
} unibits;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TYPES_H_INCLUDED
|
#endif // TYPES_H_INCLUDED
|
||||||
|
@ -1,67 +1,67 @@
|
|||||||
/*
|
/*
|
||||||
www.sourceforge.net/projects/dfhack
|
www.sourceforge.net/projects/dfhack
|
||||||
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
|
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied
|
This software is provided 'as-is', without any express or implied
|
||||||
warranty. In no event will the authors be held liable for any
|
warranty. In no event will the authors be held liable for any
|
||||||
damages arising from the use of this software.
|
damages arising from the use of this software.
|
||||||
|
|
||||||
Permission is granted to anyone to use this software for any
|
Permission is granted to anyone to use this software for any
|
||||||
purpose, including commercial applications, and to alter it and
|
purpose, including commercial applications, and to alter it and
|
||||||
redistribute it freely, subject to the following restrictions:
|
redistribute it freely, subject to the following restrictions:
|
||||||
|
|
||||||
1. The origin of this software must not be misrepresented; you must
|
1. The origin of this software must not be misrepresented; you must
|
||||||
not claim that you wrote the original software. If you use this
|
not claim that you wrote the original software. If you use this
|
||||||
software in a product, an acknowledgment in the product documentation
|
software in a product, an acknowledgment in the product documentation
|
||||||
would be appreciated but is not required.
|
would be appreciated but is not required.
|
||||||
|
|
||||||
2. Altered source versions must be plainly marked as such, and
|
2. Altered source versions must be plainly marked as such, and
|
||||||
must not be misrepresented as being the original software.
|
must not be misrepresented as being the original software.
|
||||||
|
|
||||||
3. This notice may not be removed or altered from any source
|
3. This notice may not be removed or altered from any source
|
||||||
distribution.
|
distribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef DFVECTOR_H_INCLUDED
|
#ifndef DFVECTOR_H_INCLUDED
|
||||||
#define DFVECTOR_H_INCLUDED
|
#define DFVECTOR_H_INCLUDED
|
||||||
|
|
||||||
class DfVector
|
class DfVector
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// starting offset
|
// starting offset
|
||||||
uint32_t start;
|
uint32_t start;
|
||||||
// vector size
|
// vector size
|
||||||
uint32_t size;
|
uint32_t size;
|
||||||
// vector item size
|
// vector item size
|
||||||
uint32_t item_size;
|
uint32_t item_size;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DfVector(uint32_t _start, uint32_t _size, uint32_t _item_size):
|
DfVector(uint32_t _start, uint32_t _size, uint32_t _item_size):
|
||||||
start(_start),size(_size),item_size(_item_size) {};
|
start(_start),size(_size),item_size(_item_size) {};
|
||||||
DfVector(const DfVector & vec)
|
DfVector(const DfVector & vec)
|
||||||
{
|
{
|
||||||
start = vec.start;
|
start = vec.start;
|
||||||
size = vec.size;
|
size = vec.size;
|
||||||
item_size = vec.item_size;
|
item_size = vec.item_size;
|
||||||
};
|
};
|
||||||
DfVector(){};
|
DfVector(){};
|
||||||
// get offset of the specified index
|
// get offset of the specified index
|
||||||
inline uint32_t operator[](uint32_t index)
|
inline uint32_t operator[](uint32_t index)
|
||||||
{
|
{
|
||||||
assert(index < size);
|
assert(index < size);
|
||||||
return start + index*item_size;
|
return start + index*item_size;
|
||||||
};
|
};
|
||||||
// get vector size
|
// get vector size
|
||||||
inline uint32_t getSize()
|
inline uint32_t getSize()
|
||||||
{
|
{
|
||||||
return size;
|
return size;
|
||||||
};
|
};
|
||||||
// read item_size bytes from the right offset
|
// read item_size bytes from the right offset
|
||||||
inline void read (uint32_t index, uint8_t *target)
|
inline void read (uint32_t index, uint8_t *target)
|
||||||
{
|
{
|
||||||
assert(index < size);
|
assert(index < size);
|
||||||
Mread (start + index*item_size, item_size, target);
|
Mread (start + index*item_size, item_size, target);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DFVECTOR_H_INCLUDED
|
#endif // DFVECTOR_H_INCLUDED
|
||||||
|
@ -1,204 +1,204 @@
|
|||||||
/*
|
/*
|
||||||
www.sourceforge.net/projects/dfhack
|
www.sourceforge.net/projects/dfhack
|
||||||
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
|
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied
|
This software is provided 'as-is', without any express or implied
|
||||||
warranty. In no event will the authors be held liable for any
|
warranty. In no event will the authors be held liable for any
|
||||||
damages arising from the use of this software.
|
damages arising from the use of this software.
|
||||||
|
|
||||||
Permission is granted to anyone to use this software for any
|
Permission is granted to anyone to use this software for any
|
||||||
purpose, including commercial applications, and to alter it and
|
purpose, including commercial applications, and to alter it and
|
||||||
redistribute it freely, subject to the following restrictions:
|
redistribute it freely, subject to the following restrictions:
|
||||||
|
|
||||||
1. The origin of this software must not be misrepresented; you must
|
1. The origin of this software must not be misrepresented; you must
|
||||||
not claim that you wrote the original software. If you use this
|
not claim that you wrote the original software. If you use this
|
||||||
software in a product, an acknowledgment in the product documentation
|
software in a product, an acknowledgment in the product documentation
|
||||||
would be appreciated but is not required.
|
would be appreciated but is not required.
|
||||||
|
|
||||||
2. Altered source versions must be plainly marked as such, and
|
2. Altered source versions must be plainly marked as such, and
|
||||||
must not be misrepresented as being the original software.
|
must not be misrepresented as being the original software.
|
||||||
|
|
||||||
3. This notice may not be removed or altered from any source
|
3. This notice may not be removed or altered from any source
|
||||||
distribution.
|
distribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef DFMAP_H_INCLUDED
|
#ifndef DFMAP_H_INCLUDED
|
||||||
#define DFMAP_H_INCLUDED
|
#define DFMAP_H_INCLUDED
|
||||||
|
|
||||||
#define BLOCK_SIZE 16
|
#define BLOCK_SIZE 16
|
||||||
|
|
||||||
class DfMapHeader;
|
class DfMapHeader;
|
||||||
|
|
||||||
class Block
|
class Block
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// where does the Block come from?
|
// where does the Block come from?
|
||||||
uint32_t origin;
|
uint32_t origin;
|
||||||
// generic tile type. determines how the tile behaves ingame
|
// generic tile type. determines how the tile behaves ingame
|
||||||
uint16_t tile_type[BLOCK_SIZE][BLOCK_SIZE];
|
uint16_t tile_type[BLOCK_SIZE][BLOCK_SIZE];
|
||||||
t_designation designation[BLOCK_SIZE][BLOCK_SIZE];
|
t_designation designation[BLOCK_SIZE][BLOCK_SIZE];
|
||||||
t_occupancy occupancy[BLOCK_SIZE][BLOCK_SIZE];
|
t_occupancy occupancy[BLOCK_SIZE][BLOCK_SIZE];
|
||||||
// veins
|
// veins
|
||||||
vector <t_vein> veins;
|
vector <t_vein> veins;
|
||||||
t_matglossPair material[BLOCK_SIZE][BLOCK_SIZE];
|
t_matglossPair material[BLOCK_SIZE][BLOCK_SIZE];
|
||||||
vector<t_building*> v_buildings;
|
vector<t_building*> v_buildings;
|
||||||
vector<t_tree_desc*> v_trees;
|
vector<t_tree_desc*> v_trees;
|
||||||
void collapseVeins();
|
void collapseVeins();
|
||||||
/**
|
/**
|
||||||
// region offset modifiers... what a hack.
|
// region offset modifiers... what a hack.
|
||||||
// here we have double indexed offset into regions.
|
// 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)
|
// 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
|
// disassembled code where it's used follows. biome is biome from t_designation
|
||||||
biome_stuffs = *(_BYTE *)((char)biome + offset_Block + 0x1D84);
|
biome_stuffs = *(_BYTE *)((char)biome + offset_Block + 0x1D84);
|
||||||
biome_stuffs_mod3 = biome_stuffs % 3;
|
biome_stuffs_mod3 = biome_stuffs % 3;
|
||||||
biome_stuffs_div3 = biome_stuffs / 3;
|
biome_stuffs_div3 = biome_stuffs / 3;
|
||||||
biome_stuffs_mod3_ = biome_stuffs_mod3;
|
biome_stuffs_mod3_ = biome_stuffs_mod3;
|
||||||
if ( !biome_stuffs_mod3_ )
|
if ( !biome_stuffs_mod3_ )
|
||||||
--*(_WORD *)X_stuff;
|
--*(_WORD *)X_stuff;
|
||||||
if ( biome_stuffs_mod3_ == 2 )
|
if ( biome_stuffs_mod3_ == 2 )
|
||||||
++*(_WORD *)X_stuff;
|
++*(_WORD *)X_stuff;
|
||||||
if ( !biome_stuffs_div3 )
|
if ( !biome_stuffs_div3 )
|
||||||
--*(_WORD *)Y_stuff_;
|
--*(_WORD *)Y_stuff_;
|
||||||
if ( biome_stuffs_div3 == 2 )
|
if ( biome_stuffs_div3 == 2 )
|
||||||
++*(_WORD *)Y_stuff_;
|
++*(_WORD *)Y_stuff_;
|
||||||
*/
|
*/
|
||||||
uint8_t RegionOffsets[16];// idk if the length is right here
|
uint8_t RegionOffsets[16];// idk if the length is right here
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* This class can load and save DF maps
|
* This class can load and save DF maps
|
||||||
*/
|
*/
|
||||||
class DfMap
|
class DfMap
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// allow extractor direct access to our data, avoid call lag and lots of self-serving methods
|
// allow extractor direct access to our data, avoid call lag and lots of self-serving methods
|
||||||
friend class Extractor;
|
friend class Extractor;
|
||||||
|
|
||||||
Block **block;
|
Block **block;
|
||||||
uint32_t blocks_allocated;
|
uint32_t blocks_allocated;
|
||||||
bool valid;
|
bool valid;
|
||||||
|
|
||||||
// converts the (x,y,z) cell coords to internal coords
|
// converts the (x,y,z) cell coords to internal coords
|
||||||
// out_y, out_x - block coords
|
// out_y, out_x - block coords
|
||||||
// out_y2, out_x2 - cell coords in that block
|
// 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)
|
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_x = x / BLOCK_SIZE;
|
||||||
out_x2 = x % BLOCK_SIZE;
|
out_x2 = x % BLOCK_SIZE;
|
||||||
out_y = y / BLOCK_SIZE;
|
out_y = y / BLOCK_SIZE;
|
||||||
out_y2 = y % BLOCK_SIZE;
|
out_y2 = y % BLOCK_SIZE;
|
||||||
};
|
};
|
||||||
|
|
||||||
void allocBlockArray(uint32_t x,uint32_t y, uint32_t z);
|
void allocBlockArray(uint32_t x,uint32_t y, uint32_t z);
|
||||||
void updateCellCount();
|
void updateCellCount();
|
||||||
|
|
||||||
bool loadVersion1(FILE * Decompressed,DfMapHeader & h);
|
bool loadVersion1(FILE * Decompressed,DfMapHeader & h);
|
||||||
bool writeVersion1(FILE * SaveFile);
|
bool writeVersion1(FILE * SaveFile);
|
||||||
|
|
||||||
bool loadMatgloss2(FILE * Decompressed);
|
bool loadMatgloss2(FILE * Decompressed);
|
||||||
bool loadBlocks2(FILE * Decompressed,DfMapHeader & h);
|
bool loadBlocks2(FILE * Decompressed,DfMapHeader & h);
|
||||||
bool loadRegion2(FILE * Decompressed);
|
bool loadRegion2(FILE * Decompressed);
|
||||||
bool loadVersion2(FILE * Decompressed,DfMapHeader & h);
|
bool loadVersion2(FILE * Decompressed,DfMapHeader & h);
|
||||||
|
|
||||||
void writeMatgloss2(FILE * SaveFile);
|
void writeMatgloss2(FILE * SaveFile);
|
||||||
void writeBlocks2(FILE * SaveFile);
|
void writeBlocks2(FILE * SaveFile);
|
||||||
void writeRegion2(FILE * SaveFile);
|
void writeRegion2(FILE * SaveFile);
|
||||||
bool writeVersion2(FILE * SaveFile);
|
bool writeVersion2(FILE * SaveFile);
|
||||||
|
|
||||||
uint32_t regionX;
|
uint32_t regionX;
|
||||||
uint32_t regionY;
|
uint32_t regionY;
|
||||||
uint32_t regionZ;
|
uint32_t regionZ;
|
||||||
|
|
||||||
///FIXME: these belong to some world structure
|
///FIXME: these belong to some world structure
|
||||||
uint32_t worldSizeX;
|
uint32_t worldSizeX;
|
||||||
uint32_t worldSizeY;
|
uint32_t worldSizeY;
|
||||||
|
|
||||||
vector<uint16_t> v_geology[eBiomeCount];
|
vector<uint16_t> v_geology[eBiomeCount];
|
||||||
vector<string> v_matgloss[NUM_MATGLOSS_TYPES];
|
vector<string> v_matgloss[NUM_MATGLOSS_TYPES];
|
||||||
vector<string> v_buildingtypes;
|
vector<string> v_buildingtypes;
|
||||||
vector<t_construction> v_constructions;
|
vector<t_construction> v_constructions;
|
||||||
vector<t_building*> v_buildings;
|
vector<t_building*> v_buildings;
|
||||||
vector<t_tree_desc*> v_trees;
|
vector<t_tree_desc*> v_trees;
|
||||||
unsigned x_block_count, y_block_count, z_block_count; // block count
|
unsigned x_block_count, y_block_count, z_block_count; // block count
|
||||||
unsigned x_cell_count, y_cell_count, z_cell_count; // cell count
|
unsigned x_cell_count, y_cell_count, z_cell_count; // cell count
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DfMap();
|
DfMap();
|
||||||
DfMap(uint32_t x, uint32_t y, uint32_t z);
|
DfMap(uint32_t x, uint32_t y, uint32_t z);
|
||||||
DfMap(string file_name);
|
DfMap(string file_name);
|
||||||
~DfMap();
|
~DfMap();
|
||||||
|
|
||||||
/// TODO: rework matgloss
|
/// TODO: rework matgloss
|
||||||
void applyGeoMatgloss(Block * b);
|
void applyGeoMatgloss(Block * b);
|
||||||
// accessing vectors of materials
|
// accessing vectors of materials
|
||||||
uint16_t getNumMatGloss(uint16_t type);
|
uint16_t getNumMatGloss(uint16_t type);
|
||||||
string getMaterialTypeString (uint32_t type);
|
string getMaterialTypeString (uint32_t type);
|
||||||
string getMatGlossString(uint16_t type, uint16_t index);
|
string getMatGlossString(uint16_t type, uint16_t index);
|
||||||
// accessing vectors of building types
|
// accessing vectors of building types
|
||||||
uint32_t getNumBuildingTypes();
|
uint32_t getNumBuildingTypes();
|
||||||
string getBuildingTypeName(uint32_t index);
|
string getBuildingTypeName(uint32_t index);
|
||||||
|
|
||||||
bool isValid();
|
bool isValid();
|
||||||
bool load(string FilePath);
|
bool load(string FilePath);
|
||||||
bool write(string FilePath);
|
bool write(string FilePath);
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
Block* getBlock(uint32_t x, uint32_t y, uint32_t z);
|
Block* getBlock(uint32_t x, uint32_t y, uint32_t z);
|
||||||
Block* allocBlock(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);
|
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_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);
|
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 getXBlocks() { return x_block_count; }
|
||||||
inline unsigned int getYBlocks() { return y_block_count; }
|
inline unsigned int getYBlocks() { return y_block_count; }
|
||||||
inline unsigned int getZBlocks() { return z_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);
|
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);
|
||||||
uint16_t getTileType(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, uint32_t blockX, uint32_t blockY);
|
||||||
|
|
||||||
uint32_t getDesignations(uint32_t x, uint32_t y, uint32_t z);
|
uint32_t getDesignations(uint32_t x, uint32_t y, uint32_t z);
|
||||||
uint32_t getOccupancies(uint32_t x, uint32_t y, uint32_t z);
|
uint32_t getOccupancies(uint32_t x, uint32_t y, uint32_t z);
|
||||||
|
|
||||||
// get tile material
|
// get tile material
|
||||||
t_matglossPair getMaterialPair (uint32_t x, uint32_t y, uint32_t z);
|
t_matglossPair getMaterialPair (uint32_t x, uint32_t y, uint32_t z);
|
||||||
string getGeoMaterialString (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);
|
string getMaterialString (uint32_t type, uint32_t index);
|
||||||
|
|
||||||
// get coords of region used for materials
|
// get coords of region used for materials
|
||||||
void getGeoRegion (uint32_t x, uint32_t y, uint32_t z, int32_t& geoX, int32_t& geoY);
|
void getGeoRegion (uint32_t x, uint32_t y, uint32_t z, int32_t& geoX, int32_t& geoY);
|
||||||
|
|
||||||
// matgloss part of the designation
|
// matgloss part of the designation
|
||||||
uint32_t getGeolayerIndex (uint32_t x, uint32_t y, uint32_t z);
|
uint32_t getGeolayerIndex (uint32_t x, uint32_t y, uint32_t z);
|
||||||
|
|
||||||
void getRegionCoords (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);
|
void setRegionCoords (uint32_t x,uint32_t y,uint32_t z);
|
||||||
|
|
||||||
// what kind of building is here?
|
// what kind of building is here?
|
||||||
//uint16_t getBuilding (uint32_t x, uint32_t y, uint32_t z);
|
//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_building *getBuilding (uint32_t x, uint32_t y, uint32_t z);
|
||||||
t_tree_desc *getTree (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);
|
unsigned int getBiome (uint32_t x, uint32_t y, uint32_t z);
|
||||||
|
|
||||||
int picktexture(int);
|
int picktexture(int);
|
||||||
/*
|
/*
|
||||||
bool isOpenTerrain(int);
|
bool isOpenTerrain(int);
|
||||||
bool isStairTerrain(int);
|
bool isStairTerrain(int);
|
||||||
bool isRampTerrain(int);
|
bool isRampTerrain(int);
|
||||||
bool isFloorTerrain(int);
|
bool isFloorTerrain(int);
|
||||||
bool isWallTerrain(int);
|
bool isWallTerrain(int);
|
||||||
*/
|
*/
|
||||||
bool isBlockInitialized(uint32_t x, uint32_t y, uint32_t z);
|
bool isBlockInitialized(uint32_t x, uint32_t y, uint32_t z);
|
||||||
|
|
||||||
bool isHidden (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 isSubterranean (uint32_t x, uint32_t y, uint32_t z);
|
||||||
bool isSkyView (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 isSunLit (uint32_t x, uint32_t y, uint32_t z);
|
||||||
bool isMagma (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);
|
uint8_t getLiquidLevel(uint32_t x, uint32_t y, uint32_t z);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // DFMAP_H_INCLUDED
|
#endif // DFMAP_H_INCLUDED
|
||||||
|
@ -1,160 +1,160 @@
|
|||||||
// SOURCE: http://www.zlib.net/zpipe.c
|
// SOURCE: http://www.zlib.net/zpipe.c
|
||||||
|
|
||||||
#ifndef ZLIB_HELPER_HEADER
|
#ifndef ZLIB_HELPER_HEADER
|
||||||
#define ZLIB_HELPER_HEADER
|
#define ZLIB_HELPER_HEADER
|
||||||
|
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
//#define CHUNK 16384
|
//#define CHUNK 16384
|
||||||
#define CHUNK 262144
|
#define CHUNK 262144
|
||||||
|
|
||||||
/* Compress from file source to file dest until EOF on source.
|
/* 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
|
def() returns Z_OK on success, Z_MEM_ERROR if memory could not be
|
||||||
allocated for processing, Z_STREAM_ERROR if an invalid compression
|
allocated for processing, Z_STREAM_ERROR if an invalid compression
|
||||||
level is supplied, Z_VERSION_ERROR if the version of zlib.h and the
|
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
|
version of the library linked do not match, or Z_ERRNO if there is
|
||||||
an error reading or writing the files. */
|
an error reading or writing the files. */
|
||||||
inline int def(FILE *source, FILE *dest, int level)
|
inline int def(FILE *source, FILE *dest, int level)
|
||||||
{
|
{
|
||||||
int ret, flush;
|
int ret, flush;
|
||||||
unsigned have;
|
unsigned have;
|
||||||
z_stream strm;
|
z_stream strm;
|
||||||
unsigned char in[CHUNK];
|
unsigned char in[CHUNK];
|
||||||
unsigned char out[CHUNK];
|
unsigned char out[CHUNK];
|
||||||
|
|
||||||
/* allocate deflate state */
|
/* allocate deflate state */
|
||||||
strm.zalloc = Z_NULL;
|
strm.zalloc = Z_NULL;
|
||||||
strm.zfree = Z_NULL;
|
strm.zfree = Z_NULL;
|
||||||
strm.opaque = Z_NULL;
|
strm.opaque = Z_NULL;
|
||||||
ret = deflateInit(&strm, level);
|
ret = deflateInit(&strm, level);
|
||||||
if (ret != Z_OK)
|
if (ret != Z_OK)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
/* compress until end of file */
|
/* compress until end of file */
|
||||||
do {
|
do {
|
||||||
strm.avail_in = fread(in, 1, CHUNK, source);
|
strm.avail_in = fread(in, 1, CHUNK, source);
|
||||||
if (ferror(source)) {
|
if (ferror(source)) {
|
||||||
(void)deflateEnd(&strm);
|
(void)deflateEnd(&strm);
|
||||||
return Z_ERRNO;
|
return Z_ERRNO;
|
||||||
}
|
}
|
||||||
flush = feof(source) ? Z_FINISH : Z_NO_FLUSH;
|
flush = feof(source) ? Z_FINISH : Z_NO_FLUSH;
|
||||||
strm.next_in = in;
|
strm.next_in = in;
|
||||||
|
|
||||||
/* run deflate() on input until output buffer not full, finish
|
/* run deflate() on input until output buffer not full, finish
|
||||||
compression if all of source has been read in */
|
compression if all of source has been read in */
|
||||||
do {
|
do {
|
||||||
strm.avail_out = CHUNK;
|
strm.avail_out = CHUNK;
|
||||||
strm.next_out = out;
|
strm.next_out = out;
|
||||||
ret = deflate(&strm, flush); /* no bad return value */
|
ret = deflate(&strm, flush); /* no bad return value */
|
||||||
assert(ret != Z_STREAM_ERROR); /* state not clobbered */
|
assert(ret != Z_STREAM_ERROR); /* state not clobbered */
|
||||||
have = CHUNK - strm.avail_out;
|
have = CHUNK - strm.avail_out;
|
||||||
if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
|
if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
|
||||||
(void)deflateEnd(&strm);
|
(void)deflateEnd(&strm);
|
||||||
return Z_ERRNO;
|
return Z_ERRNO;
|
||||||
}
|
}
|
||||||
} while (strm.avail_out == 0);
|
} while (strm.avail_out == 0);
|
||||||
assert(strm.avail_in == 0); /* all input will be used */
|
assert(strm.avail_in == 0); /* all input will be used */
|
||||||
|
|
||||||
/* done when last data in file processed */
|
/* done when last data in file processed */
|
||||||
} while (flush != Z_FINISH);
|
} while (flush != Z_FINISH);
|
||||||
assert(ret == Z_STREAM_END); /* stream will be complete */
|
assert(ret == Z_STREAM_END); /* stream will be complete */
|
||||||
|
|
||||||
/* clean up and return */
|
/* clean up and return */
|
||||||
(void)deflateEnd(&strm);
|
(void)deflateEnd(&strm);
|
||||||
return Z_OK;
|
return Z_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Decompress from file source to file dest until stream ends or EOF.
|
/* 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
|
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
|
allocated for processing, Z_DATA_ERROR if the deflate data is
|
||||||
invalid or incomplete, Z_VERSION_ERROR if the version of zlib.h and
|
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
|
the version of the library linked do not match, or Z_ERRNO if there
|
||||||
is an error reading or writing the files. */
|
is an error reading or writing the files. */
|
||||||
inline int inf(FILE *source, FILE *dest)
|
inline int inf(FILE *source, FILE *dest)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
unsigned have;
|
unsigned have;
|
||||||
z_stream strm;
|
z_stream strm;
|
||||||
unsigned char in[CHUNK];
|
unsigned char in[CHUNK];
|
||||||
unsigned char out[CHUNK];
|
unsigned char out[CHUNK];
|
||||||
|
|
||||||
/* allocate inflate state */
|
/* allocate inflate state */
|
||||||
strm.zalloc = Z_NULL;
|
strm.zalloc = Z_NULL;
|
||||||
strm.zfree = Z_NULL;
|
strm.zfree = Z_NULL;
|
||||||
strm.opaque = Z_NULL;
|
strm.opaque = Z_NULL;
|
||||||
strm.avail_in = 0;
|
strm.avail_in = 0;
|
||||||
strm.next_in = Z_NULL;
|
strm.next_in = Z_NULL;
|
||||||
ret = inflateInit(&strm);
|
ret = inflateInit(&strm);
|
||||||
if (ret != Z_OK)
|
if (ret != Z_OK)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
/* decompress until deflate stream ends or end of file */
|
/* decompress until deflate stream ends or end of file */
|
||||||
do {
|
do {
|
||||||
strm.avail_in = fread(in, 1, CHUNK, source);
|
strm.avail_in = fread(in, 1, CHUNK, source);
|
||||||
if (ferror(source)) {
|
if (ferror(source)) {
|
||||||
(void)inflateEnd(&strm);
|
(void)inflateEnd(&strm);
|
||||||
return Z_ERRNO;
|
return Z_ERRNO;
|
||||||
}
|
}
|
||||||
if (strm.avail_in == 0)
|
if (strm.avail_in == 0)
|
||||||
break;
|
break;
|
||||||
strm.next_in = in;
|
strm.next_in = in;
|
||||||
|
|
||||||
/* run inflate() on input until output buffer not full */
|
/* run inflate() on input until output buffer not full */
|
||||||
do {
|
do {
|
||||||
strm.avail_out = CHUNK;
|
strm.avail_out = CHUNK;
|
||||||
strm.next_out = out;
|
strm.next_out = out;
|
||||||
ret = inflate(&strm, Z_NO_FLUSH);
|
ret = inflate(&strm, Z_NO_FLUSH);
|
||||||
assert(ret != Z_STREAM_ERROR); /* state not clobbered */
|
assert(ret != Z_STREAM_ERROR); /* state not clobbered */
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case Z_NEED_DICT:
|
case Z_NEED_DICT:
|
||||||
ret = Z_DATA_ERROR; /* and fall through */
|
ret = Z_DATA_ERROR; /* and fall through */
|
||||||
case Z_DATA_ERROR:
|
case Z_DATA_ERROR:
|
||||||
case Z_MEM_ERROR:
|
case Z_MEM_ERROR:
|
||||||
(void)inflateEnd(&strm);
|
(void)inflateEnd(&strm);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
have = CHUNK - strm.avail_out;
|
have = CHUNK - strm.avail_out;
|
||||||
if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
|
if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
|
||||||
(void)inflateEnd(&strm);
|
(void)inflateEnd(&strm);
|
||||||
return Z_ERRNO;
|
return Z_ERRNO;
|
||||||
}
|
}
|
||||||
} while (strm.avail_out == 0);
|
} while (strm.avail_out == 0);
|
||||||
|
|
||||||
/* done when inflate() says it's done */
|
/* done when inflate() says it's done */
|
||||||
} while (ret != Z_STREAM_END);
|
} while (ret != Z_STREAM_END);
|
||||||
|
|
||||||
/* clean up and return */
|
/* clean up and return */
|
||||||
(void)inflateEnd(&strm);
|
(void)inflateEnd(&strm);
|
||||||
return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
|
return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* report a zlib or i/o error */
|
/* report a zlib or i/o error */
|
||||||
inline void zerr(int ret)
|
inline void zerr(int ret)
|
||||||
{
|
{
|
||||||
printf("zpipe: %d\n", ret);
|
printf("zpipe: %d\n", ret);
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case Z_ERRNO:
|
case Z_ERRNO:
|
||||||
if (ferror(stdin))
|
if (ferror(stdin))
|
||||||
fprintf(stderr,"error reading stdin\n");
|
fprintf(stderr,"error reading stdin\n");
|
||||||
if (ferror(stdout))
|
if (ferror(stdout))
|
||||||
fprintf(stderr,"error writing stdout\n");
|
fprintf(stderr,"error writing stdout\n");
|
||||||
break;
|
break;
|
||||||
case Z_STREAM_ERROR:
|
case Z_STREAM_ERROR:
|
||||||
printf("invalid compression level\n");
|
printf("invalid compression level\n");
|
||||||
break;
|
break;
|
||||||
case Z_DATA_ERROR:
|
case Z_DATA_ERROR:
|
||||||
printf("invalid or incomplete deflate data\n");
|
printf("invalid or incomplete deflate data\n");
|
||||||
break;
|
break;
|
||||||
case Z_MEM_ERROR:
|
case Z_MEM_ERROR:
|
||||||
printf("out of memory\n");
|
printf("out of memory\n");
|
||||||
break;
|
break;
|
||||||
case Z_VERSION_ERROR:
|
case Z_VERSION_ERROR:
|
||||||
printf("zlib version mismatch!\n");
|
printf("zlib version mismatch!\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // ZLIB_HELPER_HEADER
|
#endif // ZLIB_HELPER_HEADER
|
||||||
|
Loading…
Reference in New Issue