Visual Studio compatibility patch from jifodus

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

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

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

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

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

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

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

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

@ -24,6 +24,23 @@ distribution.
#ifndef TILETYPES_H_INCLUDED
#define TILETYPES_H_INCLUDED
#ifdef LINUX_BUILD
# ifndef DFHACKAPI
# define DFHACKAPI
# endif
#else
# ifdef BUILD_DFHACK_LIB
# ifndef DFHACKAPI
# define DFHACKAPI extern "C" __declspec(dllexport)
# endif
# else
# ifndef DFHACKAPI
# define DFHACKAPI extern "C" __declspec(dllimport)
# endif
# endif
#endif
enum VegetationType{
TREE_DEAD,
TREE_OK,
@ -33,12 +50,12 @@ enum VegetationType{
SHRUB_OK
};
bool isWallTerrain(int in);
bool isFloorTerrain(int in);
bool isRampTerrain(int in);
bool isStairTerrain(int in);
bool isOpenTerrain(int in);
int getVegetationType(int in);
int picktexture(int in);
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

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

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

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

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

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

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