Modular API

develop
Petr Mrázek 2010-04-05 00:48:19 +02:00
parent d080e73ac2
commit 500ee6a49b
49 changed files with 942 additions and 570 deletions

@ -3,30 +3,45 @@
#include <mod-core.h>
#include <mod-maps.h>
#include <mod-creature40d.h>
using namespace DFHack;
#include "private/APIPrivate.h"
#include "DFMemInfo.h"
#include "DFProcess.h"
#include "modules/Creatures.h"
#include "modules/Maps.h"
#include "modules/Materials.h"
#include "modules/Position.h"
#include "modules/Gui.h"
using namespace DFHack;
APIPrivate::APIPrivate()
{
// init modules
creatures = 0;
maps = 0;
position = 0;
gui = 0;
materials = 0;
}
bool APIPrivate::InitReadNames()
APIPrivate::~APIPrivate()
{
try
if(creatures) delete creatures;
if(maps) delete maps;
if(position) delete position;
if(gui) delete gui;
if(materials) delete materials;
}
bool APIPrivate::InitReadNames()
{
name_firstname_offset = offset_descriptor->getOffset("name_firstname");
name_nickname_offset = offset_descriptor->getOffset("name_nickname");
name_words_offset = offset_descriptor->getOffset("name_words");
}
catch(Error::MissingMemoryDefinition)
{
return false;
}
return true;
}
void APIPrivate::readName(t_name & name, uint32_t address)
{
g_pProcess->readSTLString(address + name_firstname_offset , name.first_name, 128);

@ -23,14 +23,26 @@ distribution.
*/
#include "DFCommonInternal.h"
#include "DFProcess.h"
#include "DFProcessEnumerator.h"
#include "DFHackAPI.h"
#include "DFError.h"
#include <shms.h>
#include <mod-core.h>
#include <mod-maps.h>
#include <mod-creature40d.h>
using namespace DFHack;
#include "private/APIPrivate.h"
#include "modules/Maps.h"
#include "modules/Materials.h"
#include "modules/Position.h"
#include "modules/Gui.h"
#include "modules/Creatures.h"
using namespace DFHack;
API::API (const string path_to_xml)
: d (new APIPrivate())
{
@ -151,6 +163,44 @@ DFWindow * API::getWindow()
return d->p->getWindow();
}
/*******************************************************************************
M O D U L E S
*******************************************************************************/
Creatures * API::getCreatures()
{
if(!d->creatures)
d->creatures = new Creatures(d);
return d->creatures;
}
Maps * API::getMaps()
{
if(!d->maps)
d->maps = new Maps(d);
return d->maps;
}
Gui * API::getGui()
{
if(!d->gui)
d->gui = new Gui(d);
return d->gui;
}
Position * API::getPosition()
{
if(!d->position)
d->position = new Position(d);
return d->position;
}
Materials * API::getMaterials()
{
if(!d->materials)
d->materials = new Materials(d);
return d->materials;
}
/*
// returns number of buildings, expects v_buildingtypes that will later map t_building.type to its name
bool API::InitReadBuildings ( uint32_t& numbuildings )
@ -504,53 +554,7 @@ bool API::ReadHotkeys(t_hotkey hotkeys[])
}
return true;
}
// returns index of creature actually read or -1 if no creature can be found
int32_t API::ReadCreatureInBox (int32_t index, t_creature & furball,
const uint16_t x1, const uint16_t y1, const uint16_t z1,
const uint16_t x2, const uint16_t y2, const uint16_t z2)
{
if (!d->creaturesInited) return -1;
if(d->creature_module)
{
// supply the module with offsets so it can work with them
SHMCREATURESHDR->index = index;
SHMCREATURESHDR->x = x1;
SHMCREATURESHDR->y = y1;
SHMCREATURESHDR->z = z1;
SHMCREATURESHDR->x2 = x2;
SHMCREATURESHDR->y2 = y2;
SHMCREATURESHDR->z2 = z2;
const uint32_t cmd = Creatures::CREATURE_FIND_IN_BOX + (d->creature_module << 16);
g_pProcess->SetAndWait(cmd);
if(SHMCREATURESHDR->index != -1)
memcpy(&furball,SHMDATA(void),sizeof(t_creature));
return SHMCREATURESHDR->index;
}
else
{
uint16_t coords[3];
uint32_t size = d->p_cre->getSize();
while (uint32_t(index) < size)
{
// read pointer from vector at position
uint32_t temp = * (uint32_t *) d->p_cre->at (index);
g_pProcess->read (temp + d->creatures.creature_pos_offset, 3 * sizeof (uint16_t), (uint8_t *) &coords);
if (coords[0] >= x1 && coords[0] < x2)
{
if (coords[1] >= y1 && coords[1] < y2)
{
if (coords[2] >= z1 && coords[2] < z2)
{
ReadCreature (index, furball);
return index;
}
}
}
index++;
}
return -1;
}
}
bool API::getItemIndexesInBox(vector<uint32_t> &indexes,
const uint16_t x1, const uint16_t y1, const uint16_t z1,

@ -23,25 +23,10 @@ distribution.
*/
#include "DFCommonInternal.h"
/*
#if !defined(NDEBUG)
#define BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING
#define BOOST_MULTI_INDEX_ENABLE_SAFE_MODE
#endif
// really, we don't need it
#define BOOST_MULTI_INDEX_DISABLE_SERIALIZATION
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/member.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <string>
using boost::multi_index_container;
using namespace boost::multi_index;
*/
#include "DFMemInfo.h"
#include "DFError.h"
#include "DFProcess.h"
using namespace DFHack;
/*

@ -23,6 +23,10 @@ distribution.
*/
#include "DFCommonInternal.h"
#include "DFMemInfo.h"
#include "DFMemInfoManager.h"
#include "DFError.h"
using namespace DFHack;
MemInfoManager::~MemInfoManager()

@ -22,6 +22,11 @@ must not be misrepresented as being the original software.
distribution.
*/
#include "DFCommonInternal.h"
#include "DFProcess.h"
#include "DFWindow.h"
#include "DFMemInfo.h"
#include "DFError.h"
#include <errno.h>
#include <sys/shm.h>
#include <sys/types.h>

@ -22,6 +22,10 @@ must not be misrepresented as being the original software.
distribution.
*/
#include "DFCommonInternal.h"
#include "DFProcess.h"
#include "DFWindow.h"
#include "DFMemInfo.h"
#include "DFError.h"
#include <errno.h>
#include <DFError.h>
#include <sys/ptrace.h>

@ -22,6 +22,10 @@ must not be misrepresented as being the original software.
distribution.
*/
#include "DFCommonInternal.h"
#include "DFProcess.h"
#include "DFWindow.h"
#include "DFMemInfo.h"
#include "DFError.h"
#include <errno.h>
#include <sys/ptrace.h>
using namespace DFHack;

@ -22,6 +22,10 @@ must not be misrepresented as being the original software.
distribution.
*/
#include "DFCommonInternal.h"
#include "DFProcess.h"
#include "DFWindow.h"
#include "DFMemInfo.h"
#include "DFError.h"
#include "shms.h"
#include "mod-core.h"
using namespace DFHack;

@ -22,6 +22,10 @@ must not be misrepresented as being the original software.
distribution.
*/
#include "DFCommonInternal.h"
#include "DFProcess.h"
#include "DFWindow.h"
#include "DFMemInfo.h"
#include "DFError.h"
using namespace DFHack;
class NormalProcess::Private

@ -23,6 +23,10 @@ distribution.
*/
#include "DFCommonInternal.h"
#include "DFProcessEnumerator.h"
#include "DFProcess.h"
#include "DFMemInfo.h"
#include "DFMemInfoManager.h"
#include <sys/shm.h>
#include <sys/types.h>
#include <sys/ipc.h>

@ -23,6 +23,10 @@ distribution.
*/
#include "DFCommonInternal.h"
#include "DFProcessEnumerator.h"
#include "DFProcess.h"
#include "DFMemInfo.h"
#include "DFMemInfoManager.h"
using namespace DFHack;
/// HACK: global variables (only one process can be attached at the same time.)

@ -24,6 +24,9 @@ distribution.
#include "Tranquility.h"
#include "DFCommonInternal.h"
#include "DFVector.h"
#include "DFMemInfo.h"
#include "DFProcess.h"
using namespace DFHack;

@ -22,6 +22,7 @@ must not be misrepresented as being the original software.
distribution.
*/
#include "DFCommonInternal.h"
#include "DFWindow.h"
#include <X11/Xlib.h> //need for X11 functions
#include <X11/keysym.h>

@ -23,6 +23,8 @@ distribution.
*/
#include "DFCommonInternal.h"
#include "DFWindow.h"
#include "DFProcess.h"
using namespace DFHack;
// should always reflect the enum in DFkeys.h

@ -77,6 +77,7 @@ namespace DFHack
# define BUILD_DFHACK_LIB
#endif
/*
#include "DFTypes.h"
//#include "DFDataModel.h"
#include "DFProcess.h"
@ -86,13 +87,14 @@ namespace DFHack
#include "DFVector.h"
#include "DFMemInfo.h"
#include "DFError.h"
*/
#include <stdlib.h>
#include <tinyxml.h>
#include <md5wrapper.h>
#include <iostream>
#include "DFHackAPI.h"
//#include "DFHackAPI.h"
#define _QUOTEME(x) #x
#define QUOT(x) _QUOTEME(x)

@ -40,6 +40,14 @@ namespace DFHack
class APIPrivate;
class memory_info;
class Process;
// modules
class Maps;
class Creatures;
class Position;
class Gui;
class Materials;
class DFHACK_EXPORT API
{
APIPrivate * const d;
@ -76,11 +84,11 @@ namespace DFHack
void ReadRaw (const uint32_t offset, const uint32_t size, uint8_t *target);
void WriteRaw (const uint32_t offset, const uint32_t size, uint8_t *source);
#include "../modules/Position-proc.h"
#include "../modules/Gui-proc.h"
#include "../modules/Maps-proc.h"
#include "../modules/Materials-proc.h"
#include "../modules/Creatures-proc.h"
Creatures * getCreatures();
Maps * getMaps();
Gui * getGui();
Position * getPosition();
Materials * getMaterials();
/*
* Constructions (costructed walls, floors, ramps, etc...)

@ -53,26 +53,6 @@ struct junk_fill
*/
};
struct t_matgloss
{
char id[128]; //the id in the raws
uint8_t fore; // Annoyingly the offset for this differs between types
uint8_t back;
uint8_t bright;
char name[128]; //this is the name displayed ingame
};
struct t_matglossPlant
{
char id[128]; //the id in the raws
uint8_t fore; // Annoyingly the offset for this differs between types
uint8_t back;
uint8_t bright;
char name[128]; //this is the name displayed ingame
char drink_name[128]; //the name this item becomes a drink
char food_name[128];
char extract_name[128];
};
/*
struct t_vein
{

@ -0,0 +1,33 @@
#ifndef CL_MOD_CREATURES
#define CL_MOD_CREATURES
/*
* Creatures
*/
#include "Export.h"
namespace DFHack
{
class APIPrivate;
struct t_creature;
class DFHACK_EXPORT Creatures
{
public:
Creatures(DFHack::APIPrivate * d);
~Creatures();
bool Start( uint32_t & numCreatures);
bool Finish();
// Read creatures in a box, starting with index. Returns -1 if no more creatures
// found. Call repeatedly do get all creatures in a specified box (uses tile coords)
int32_t ReadCreatureInBox(const int32_t index, t_creature & furball,
const uint16_t x1, const uint16_t y1,const uint16_t z1,
const uint16_t x2, const uint16_t y2,const uint16_t z2);
bool ReadCreature(const int32_t index, t_creature & furball);
/// write labors of a creature (for Dwarf Therapist)
//bool WriteLabors(const uint32_t index, uint8_t labors[NUM_CREATURE_LABORS]);
private:
struct Private;
Private *d;
};
}
#endif

@ -0,0 +1,34 @@
#ifndef CL_MOD_GUI
#define CL_MOD_GUI
/*
* Gui: Query the DF's GUI state
*/
#include "Export.h"
namespace DFHack
{
class APIPrivate;
struct t_viewscreen;
class DFHACK_EXPORT Gui
{
public:
Gui(DFHack::APIPrivate * d);
~Gui();
bool Start();
bool Finish();
///true if paused, false if not
bool ReadPauseState();
/// read the DF menu view state (stock screen, unit screen, other screens
bool ReadViewScreen(t_viewscreen &);
/// read the DF menu state (designation menu ect)
uint32_t ReadMenuState();
private:
struct Private;
Private *d;
};
}
#endif

@ -0,0 +1,109 @@
#ifndef CL_MOD_MAPS
#define CL_MOD_MAPS
#include "Export.h"
/*
* Maps: Read and write DF's map
*/
namespace DFHack
{
class APIPrivate;
struct t_viewscreen;
class DFHACK_EXPORT Maps
{
public:
Maps(DFHack::APIPrivate * d);
~Maps();
bool Start();
bool Finish();
// 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( std::vector < std::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);
/**
* Get the address of a block or 0 if block is not valid
*/
uint32_t getBlockPtr (uint32_t blockx, uint32_t blocky, uint32_t blockz);
/// read the whole map block at block coords (see DFTypes.h for the block structure)
bool ReadBlock40d(uint32_t blockx, uint32_t blocky, uint32_t blockz, mapblock40d * buffer);
/// read/write block tile types
bool ReadTileTypes(uint32_t blockx, uint32_t blocky, uint32_t blockz, tiletypes40d *buffer);
bool WriteTileTypes(uint32_t blockx, uint32_t blocky, uint32_t blockz, tiletypes40d *buffer);
/// read/write block designations
bool ReadDesignations(uint32_t blockx, uint32_t blocky, uint32_t blockz, designations40d *buffer);
bool WriteDesignations (uint32_t blockx, uint32_t blocky, uint32_t blockz, designations40d *buffer);
/// read/write block occupancies
bool ReadOccupancy(uint32_t blockx, uint32_t blocky, uint32_t blockz, occupancies40d *buffer);
bool WriteOccupancy(uint32_t blockx, uint32_t blocky, uint32_t blockz, occupancies40d *buffer);
/// read/write the block dirty bit - this is used to mark a map block so that DF scans it for designated jobs like digging
bool ReadDirtyBit(uint32_t blockx, uint32_t blocky, uint32_t blockz, bool &dirtybit);
bool WriteDirtyBit(uint32_t blockx, uint32_t blocky, uint32_t blockz, bool dirtybit);
/// read/write the block flags
bool ReadBlockFlags(uint32_t blockx, uint32_t blocky, uint32_t blockz, t_blockflags &blockflags);
bool WriteBlockFlags(uint32_t blockx, uint32_t blocky, uint32_t blockz, t_blockflags blockflags);
/// read region offsets of a block - used for determining layer stone matgloss
bool ReadRegionOffsets(uint32_t blockx, uint32_t blocky, uint32_t blockz, biome_indices40d *buffer);
/// read aggregated veins of a block
bool ReadVeins(uint32_t blockx, uint32_t blocky, uint32_t blockz, std::vector <t_vein> & veins, std::vector <t_frozenliquidvein>& ices);
private:
struct Private;
Private *d;
};
}
#endif

@ -0,0 +1,53 @@
#ifndef CL_MOD_MATERIALS
#define CL_MOD_MATERIALS
/*
* Creatures
*/
#include "Export.h"
namespace DFHack
{
struct APIPrivate;
struct t_matgloss
{
char id[128]; //the id in the raws
uint8_t fore; // Annoyingly the offset for this differs between types
uint8_t back;
uint8_t bright;
char name[128]; //this is the name displayed ingame
};
struct t_matglossPlant
{
char id[128]; //the id in the raws
uint8_t fore; // Annoyingly the offset for this differs between types
uint8_t back;
uint8_t bright;
char name[128]; //this is the name displayed ingame
char drink_name[128]; //the name this item becomes a drink
char food_name[128];
char extract_name[128];
};
class DFHACK_EXPORT Materials
{
public:
Materials(DFHack::APIPrivate * _d);
~Materials();
bool ReadInorganicMaterials (std::vector<t_matgloss> & output);
bool ReadOrganicMaterials (std::vector<t_matgloss> & output);
bool ReadWoodMaterials (std::vector<t_matgloss> & output);
bool ReadPlantMaterials (std::vector<t_matgloss> & output);
// bool ReadPlantMaterials (std::vector<t_matglossPlant> & output);
// TODO: maybe move to creatures?
bool ReadCreatureTypes (std::vector<t_matgloss> & output);
private:
APIPrivate* d;
};
}
#endif

@ -0,0 +1,35 @@
#ifndef CL_MOD_POSITION
#define CL_MOD_POSITION
/*
* View position and size and cursor position
*/
#include "Export.h"
namespace DFHack
{
struct APIPrivate;
class DFHACK_EXPORT Position
{
public:
Position(APIPrivate * d);
~Position();
/*
* Cursor and window coords
*/
bool getViewCoords (int32_t &x, int32_t &y, int32_t &z);
bool setViewCoords (const int32_t x, const int32_t y, const int32_t z);
bool getCursorCoords (int32_t &x, int32_t &y, int32_t &z);
bool setCursorCoords (const int32_t x, const int32_t y, const int32_t z);
/*
* Window size in tiles
*/
bool getWindowSize(int32_t & width, int32_t & height);
private:
struct Private;
Private *d;
};
}
#endif

@ -1,4 +0,0 @@
bool creaturesInited;
Creatures2010::creature_offsets creatures;
uint32_t creature_module;
DfVector *p_cre;

@ -1,15 +0,0 @@
/*
* Creatures
*/
bool InitReadCreatures( uint32_t & numcreatures );
// Read creatures in a box, starting with index. Returns -1 if no more creatures
// found. Call repeatedly do get all creatures in a specified box (uses tile coords)
int32_t ReadCreatureInBox(const int32_t index, t_creature & furball,
const uint16_t x1, const uint16_t y1,const uint16_t z1,
const uint16_t x2, const uint16_t y2,const uint16_t z2);
bool ReadCreature(const int32_t index, t_creature & furball);
/// write labors of a creature (for Dwarf Therapist)
//bool WriteLabors(const uint32_t index, uint8_t labors[NUM_CREATURE_LABORS]);
void FinishReadCreatures();

@ -25,72 +25,120 @@ distribution.
#include "DFCommonInternal.h"
#include "../private/APIPrivate.h"
#define SHMCREATURESHDR ((Creatures2010::shm_creature_hdr *)d->shm_start)
// we connect to those
#include <shms.h>
#include <mod-core.h>
#include <mod-creature2010.h>
#include "modules/Creatures.h"
#include "DFVector.h"
#include "DFMemInfo.h"
#include "DFProcess.h"
#include "DFError.h"
#include "DFTypes.h"
#define SHMCREATURESHDR ((Creatures2010::shm_creature_hdr *)d->d->shm_start)
#define SHMCMD(num) ((shm_cmd *)d->d->shm_start)[num]->pingpong
#define SHMHDR ((shm_core_hdr *)d->d->shm_start)
#define SHMDATA(type) ((type *)(d->d->shm_start + SHM_HEADER))
using namespace DFHack;
bool API::InitReadCreatures( uint32_t &numcreatures )
struct Creatures::Private
{
bool Inited;
bool Started;
Creatures2010::creature_offsets creatures;
uint32_t creature_module;
DfVector *p_cre;
APIPrivate *d;
};
Creatures::Creatures(APIPrivate* _d)
{
if(!d->InitReadNames()) return false;
d = new Private;
d->d = _d;
d->Inited = false;
d->Started = false;
d->d->InitReadNames(); // throws on error
try
{
memory_info * minfo = d->offset_descriptor;
Creatures2010::creature_offsets & off = d->creatures;
off.creature_vector = minfo->getAddress ("creature_vector");
off.creature_pos_offset = minfo->getOffset ("creature_position");
off.creature_profession_offset = minfo->getOffset ("creature_profession");
off.creature_race_offset = minfo->getOffset ("creature_race");
off.creature_flags1_offset = minfo->getOffset ("creature_flags1");
off.creature_flags2_offset = minfo->getOffset ("creature_flags2");
off.creature_name_offset = minfo->getOffset ("creature_name");
off.creature_sex_offset = minfo->getOffset ("creature_sex");
off.creature_id_offset = minfo->getOffset ("creature_id");
off.creature_labors_offset = minfo->getOffset ("creature_labors");
off.creature_happiness_offset = minfo->getOffset ("creature_happiness");
off.creature_artifact_name_offset = minfo->getOffset("creature_artifact_name");
memory_info * minfo = d->d->offset_descriptor;
Creatures2010::creature_offsets &creatures = d->creatures;
creatures.creature_vector = minfo->getAddress ("creature_vector");
creatures.creature_pos_offset = minfo->getOffset ("creature_position");
creatures.creature_profession_offset = minfo->getOffset ("creature_profession");
creatures.creature_race_offset = minfo->getOffset ("creature_race");
creatures.creature_flags1_offset = minfo->getOffset ("creature_flags1");
creatures.creature_flags2_offset = minfo->getOffset ("creature_flags2");
creatures.creature_name_offset = minfo->getOffset ("creature_name");
creatures.creature_sex_offset = minfo->getOffset ("creature_sex");
creatures.creature_id_offset = minfo->getOffset ("creature_id");
creatures.creature_labors_offset = minfo->getOffset ("creature_labors");
creatures.creature_happiness_offset = minfo->getOffset ("creature_happiness");
creatures.creature_artifact_name_offset = minfo->getOffset("creature_artifact_name");
// name offsets for the creature module
off.name_firstname_offset = minfo->getOffset("name_firstname");
off.name_nickname_offset = minfo->getOffset("name_nickname");
off.name_words_offset = minfo->getOffset("name_words");
d->p_cre = new DfVector (d->p, off.creature_vector, 4);
d->creaturesInited = true;
numcreatures = d->p_cre->getSize();
// --> SHM initialization (if possible) <--
g_pProcess->getModuleIndex("Creatures2010",1,d->creature_module);
creatures.name_firstname_offset = minfo->getOffset("name_firstname");
creatures.name_nickname_offset = minfo->getOffset("name_nickname");
creatures.name_words_offset = minfo->getOffset("name_words");
if(d->creature_module)
// upload offsets to the SHM
if(g_pProcess->getModuleIndex("Creatures2010",1,d->creature_module))
{
// supply the module with offsets so it can work with them
memcpy(SHMDATA(Creatures2010::creature_offsets),&d->creatures,sizeof(Creatures2010::creature_offsets));
memcpy(SHMDATA(Creatures2010::creature_offsets),&creatures,sizeof(Creatures2010::creature_offsets));
const uint32_t cmd = Creatures2010::CREATURE_INIT + (d->creature_module << 16);
g_pProcess->SetAndWait(cmd);
}
return true;
d->Inited = true;
}
catch (Error::MissingMemoryDefinition&)
{
d->creaturesInited = false;
numcreatures = 0;
d->Inited = false;
throw;
}
}
bool API::ReadCreature (const int32_t index, t_creature & furball)
Creatures::~Creatures()
{
if(!d->creaturesInited) return false;
if(d->Started)
Finish();
}
bool Creatures::Start( uint32_t &numcreatures )
{
d->p_cre = new DfVector (d->d->p, d->creatures.creature_vector, 4);
d->Started = true;
numcreatures = d->p_cre->getSize();
return true;
}
bool Creatures::Finish()
{
if(d->p_cre)
{
delete d->p_cre;
d->p_cre = 0;
}
d->Started = false;
return true;
}
bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
{
if(!d->Started) return false;
// SHM fast path
if(d->creature_module)
{
// supply the module with offsets so it can work with them
SHMCREATURESHDR->index = index;
const uint32_t cmd = Creatures2010::CREATURE_AT_INDEX + (d->creature_module << 16);
g_pProcess->SetAndWait(cmd);
memcpy(&furball,SHMDATA(t_creature),sizeof(t_creature));
// cerr << "creature read from SHM!" << endl;
return true;
}
// non-SHM slow path
// read pointer from vector at position
uint32_t temp = * (uint32_t *) d->p_cre->at (index);
furball.origin = temp;
@ -101,9 +149,9 @@ bool API::ReadCreature (const int32_t index, t_creature & furball)
g_pProcess->readDWord (temp + offs.creature_flags1_offset, furball.flags1.whole);
g_pProcess->readDWord (temp + offs.creature_flags2_offset, furball.flags2.whole);
// names
d->readName(furball.name,temp + offs.creature_name_offset);
d->d->readName(furball.name,temp + offs.creature_name_offset);
//d->readName(furball.squad_name, temp + offs.creature_squad_name_offset);
d->readName(furball.artifact_name, temp + offs.creature_artifact_name_offset);
d->d->readName(furball.artifact_name, temp + offs.creature_artifact_name_offset);
// custom profession
//fill_char_buf (furball.custom_profession, d->p->readSTLString (temp + offs.creature_custom_profession_offset));
@ -173,6 +221,56 @@ bool API::ReadCreature (const int32_t index, t_creature & furball)
return true;
}
// returns index of creature actually read or -1 if no creature can be found
int32_t Creatures::ReadCreatureInBox (int32_t index, t_creature & furball,
const uint16_t x1, const uint16_t y1, const uint16_t z1,
const uint16_t x2, const uint16_t y2, const uint16_t z2)
{
if (!d->Started) return -1;
if(d->creature_module)
{
// supply the module with offsets so it can work with them
SHMCREATURESHDR->index = index;
SHMCREATURESHDR->x = x1;
SHMCREATURESHDR->y = y1;
SHMCREATURESHDR->z = z1;
SHMCREATURESHDR->x2 = x2;
SHMCREATURESHDR->y2 = y2;
SHMCREATURESHDR->z2 = z2;
const uint32_t cmd = Creatures2010::CREATURE_FIND_IN_BOX + (d->creature_module << 16);
g_pProcess->SetAndWait(cmd);
if(SHMCREATURESHDR->index != -1)
memcpy(&furball,SHMDATA(void),sizeof(t_creature));
return SHMCREATURESHDR->index;
}
else
{
uint16_t coords[3];
uint32_t size = d->p_cre->getSize();
while (uint32_t(index) < size)
{
// read pointer from vector at position
uint32_t temp = * (uint32_t *) d->p_cre->at (index);
g_pProcess->read (temp + d->creatures.creature_pos_offset, 3 * sizeof (uint16_t), (uint8_t *) &coords);
if (coords[0] >= x1 && coords[0] < x2)
{
if (coords[1] >= y1 && coords[1] < y2)
{
if (coords[2] >= z1 && coords[2] < z2)
{
ReadCreature (index, furball);
return index;
}
}
}
index++;
}
return -1;
}
}
/*
bool API::WriteLabors(const uint32_t index, uint8_t labors[NUM_CREATURE_LABORS])
{
@ -189,13 +287,3 @@ bool API::getCurrentCursorCreature(uint32_t & creature_index)
return true;
}
*/
void API::FinishReadCreatures()
{
if(d->p_cre)
{
delete d->p_cre;
d->p_cre = 0;
}
d->creaturesInited = false;
//FinishReadNameTables();
}

@ -1,4 +0,0 @@
uint32_t pause_state_offset;
uint32_t view_screen_offset;
uint32_t current_cursor_creature_offset;
uint32_t current_menu_state_offset;

@ -1,10 +0,0 @@
/*
* Query the DF's GUI state
*/
bool InitReadGuiState();
///true if paused, false if not
bool ReadPauseState();
/// read the DF menu view state (stock screen, unit screen, other screens
bool ReadViewScreen(t_viewscreen &);
/// read the DF menu state (designation menu ect)
uint32_t ReadMenuState();

@ -24,27 +24,72 @@ distribution.
#include "DFCommonInternal.h"
#include "../private/APIPrivate.h"
#include "modules/Gui.h"
#include "DFProcess.h"
#include "DFMemInfo.h"
#include "DFTypes.h"
using namespace DFHack;
bool API::ReadPauseState()
struct Gui::Private
{
bool Inited;
bool Started;
uint32_t pause_state_offset;
uint32_t view_screen_offset;
uint32_t current_cursor_creature_offset;
uint32_t current_menu_state_offset;
APIPrivate *d;
};
Gui::Gui(APIPrivate * _d)
{
d = new Private;
d->d = _d;
d->Inited = d->Started = true;
memory_info * mem = d->d->offset_descriptor;
d->current_menu_state_offset = mem->getAddress("current_menu_state");
d->pause_state_offset = mem->getAddress ("pause_state");
d->view_screen_offset = mem->getAddress ("view_screen");
d->Inited = d->Started = true;
}
Gui::~Gui()
{
delete d;
}
bool Gui::Start()
{
return true;
}
bool Gui::Finish()
{
return true;
}
bool Gui::ReadPauseState()
{
// replace with an exception
if(!d->cursorWindowInited) return false;
if(!d->Inited) return false;
uint32_t pauseState = g_pProcess->readDWord (d->pause_state_offset);
return pauseState & 1;
}
uint32_t API::ReadMenuState()
uint32_t Gui::ReadMenuState()
{
if(d->cursorWindowInited)
if(d->Inited)
return(g_pProcess->readDWord(d->current_menu_state_offset));
return false;
}
bool API::ReadViewScreen (t_viewscreen &screen)
bool Gui::ReadViewScreen (t_viewscreen &screen)
{
if (!d->cursorWindowInited) return false;
if (!d->Inited) return false;
uint32_t last = g_pProcess->readDWord (d->view_screen_offset);
uint32_t screenAddr = g_pProcess->readDWord (last);
@ -55,5 +100,5 @@ bool API::ReadViewScreen (t_viewscreen &screen)
screenAddr = g_pProcess->readDWord (nextScreenPtr);
nextScreenPtr = g_pProcess->readDWord (nextScreenPtr + 4);
}
return d->offset_descriptor->resolveObjectToClassID (last, screen.type);
return d->d->offset_descriptor->resolveObjectToClassID (last, screen.type);
}

@ -1,17 +0,0 @@
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 block_flags_offset;
uint32_t veinvector;
uint32_t vein_mineral_vptr;
uint32_t vein_ice_vptr;
uint32_t vein_spatter_vptr;
uint32_t maps_module;
//uint32_t biome_stuffs;
//vector<uint16_t> v_geology[eBiomeCount];

@ -1,80 +0,0 @@
// 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( std::vector < std::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);
/**
* Get the address of a block or 0 if block is not valid
*/
uint32_t getBlockPtr (uint32_t blockx, uint32_t blocky, uint32_t blockz);
/// read the whole map block at block coords (see DFTypes.h for the block structure)
bool ReadBlock40d(uint32_t blockx, uint32_t blocky, uint32_t blockz, mapblock40d * buffer);
/// read/write block tile types
bool ReadTileTypes(uint32_t blockx, uint32_t blocky, uint32_t blockz, tiletypes40d *buffer);
bool WriteTileTypes(uint32_t blockx, uint32_t blocky, uint32_t blockz, tiletypes40d *buffer);
/// read/write block designations
bool ReadDesignations(uint32_t blockx, uint32_t blocky, uint32_t blockz, designations40d *buffer);
bool WriteDesignations (uint32_t blockx, uint32_t blocky, uint32_t blockz, designations40d *buffer);
/// read/write block occupancies
bool ReadOccupancy(uint32_t blockx, uint32_t blocky, uint32_t blockz, occupancies40d *buffer);
bool WriteOccupancy(uint32_t blockx, uint32_t blocky, uint32_t blockz, occupancies40d *buffer);
/// read/write the block dirty bit - this is used to mark a map block so that DF scans it for designated jobs like digging
bool ReadDirtyBit(uint32_t blockx, uint32_t blocky, uint32_t blockz, bool &dirtybit);
bool WriteDirtyBit(uint32_t blockx, uint32_t blocky, uint32_t blockz, bool dirtybit);
/// read/write the block flags
bool ReadBlockFlags(uint32_t blockx, uint32_t blocky, uint32_t blockz, t_blockflags &blockflags);
bool WriteBlockFlags(uint32_t blockx, uint32_t blocky, uint32_t blockz, t_blockflags blockflags);
/// read region offsets of a block - used for determining layer stone matgloss
bool ReadRegionOffsets(uint32_t blockx, uint32_t blocky, uint32_t blockz, biome_indices40d *buffer);
/// read aggregated veins of a block
bool ReadVeins(uint32_t blockx, uint32_t blocky, uint32_t blockz, std::vector <t_vein> & veins, std::vector <t_frozenliquidvein>& ices);

@ -23,76 +23,108 @@ distribution.
*/
#include "DFCommonInternal.h"
#include <shms.h>
#include <mod-core.h>
#include <mod-maps.h>
#include "../private/APIPrivate.h"
#include "modules/Maps.h"
#include "DFError.h"
#include "DFMemInfo.h"
#include "DFProcess.h"
#include "DFVector.h"
#define SHMMAPSHDR ((Maps::shm_maps_hdr *)d->shm_start)
#define SHMMAPSHDR ((Server::Maps::shm_maps_hdr *)d->d->shm_start)
#define SHMCMD(num) ((shm_cmd *)d->d->shm_start)[num]->pingpong
#define SHMHDR ((shm_core_hdr *)d->d->shm_start)
#define SHMDATA(type) ((type *)(d->d->shm_start + SHM_HEADER))
using namespace DFHack;
/*-----------------------------------*
* Init the mapblock pointer array *
*-----------------------------------*/
bool API::InitMap()
struct Maps::Private
{
uint32_t map_offset = d->offset_descriptor->getAddress ("map_data");
uint32_t x_count_offset = d->offset_descriptor->getAddress ("x_count_block");
uint32_t y_count_offset = d->offset_descriptor->getAddress ("y_count_block");
uint32_t z_count_offset = d->offset_descriptor->getAddress ("z_count_block");
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 maps_module;
Server::Maps::maps_offsets offsets;
APIPrivate *d;
bool Inited;
bool Started;
//uint32_t biome_stuffs;
//vector<uint16_t> v_geology[eBiomeCount];
};
Maps::Maps(APIPrivate* _d)
{
d = new Private;
d->d = _d;
d->Inited = d->Started = false;
DFHack::memory_info * mem = d->d->offset_descriptor;
Server::Maps::maps_offsets &off = d->offsets;
// get the offsets once here
d->tile_type_offset = d->offset_descriptor->getOffset ("type");
d->designation_offset = d->offset_descriptor->getOffset ("designation");
//d->occupancy_offset = d->offset_descriptor->getOffset ("occupancy");
off.map_offset = mem->getAddress ("map_data");
off.x_count_offset = mem->getAddress ("x_count_block");
off.y_count_offset = mem->getAddress ("y_count_block");
off.z_count_offset = mem->getAddress ("z_count_block");
off.tile_type_offset = mem->getOffset ("type");
off.designation_offset = mem->getOffset ("designation");
//d->biome_stuffs = d->offset_descriptor->getOffset ("biome_stuffs");
d->veinvector = d->offset_descriptor->getOffset ("v_vein");
off.veinvector = mem->getOffset ("v_vein");
// these can fail and will be found when looking at the actual veins later
// basically a cache
d->vein_ice_vptr = 0;
d->offset_descriptor->resolveClassnameToVPtr("block_square_event_frozen_liquid", d->vein_ice_vptr);
d->vein_mineral_vptr = 0;
d->offset_descriptor->resolveClassnameToVPtr("block_square_event_mineral",d->vein_mineral_vptr);
/*
* --> SHM initialization (if possible) <--
*/
/*
g_pProcess->getModuleIndex("Maps2010",1,d->maps_module);
off.vein_ice_vptr = 0;
mem->resolveClassnameToVPtr("block_square_event_frozen_liquid", off.vein_ice_vptr);
off.vein_mineral_vptr = 0;
mem->resolveClassnameToVPtr("block_square_event_mineral",off.vein_mineral_vptr);
if(d->maps_module)
// upload offsets to SHM server if possible
d->maps_module = 0;
if(g_pProcess->getModuleIndex("Maps2010",1,d->maps_module))
{
// supply the module with offsets so it can work with them
Maps::maps_offsets *off = SHMDATA(Maps::maps_offsets);
off->designation_offset = d->designation_offset;
off->map_offset = map_offset;
off->tile_type_offset = d->tile_type_offset;
off->vein_ice_vptr = d->vein_ice_vptr; // FIXME: not necessarily true, the shm server side needs a class lookup >_<
off->vein_mineral_vptr = d->vein_mineral_vptr; // FIXME: not necessarily true, the shm server side needs a class lookup >_<
off->veinvector = d->veinvector;
off->x_count_offset = x_count_offset;
off->y_count_offset = y_count_offset;
off->z_count_offset = z_count_offset;
Server::Maps::maps_offsets *off2 = SHMDATA(Server::Maps::maps_offsets);
memcpy(off2, &(d->offsets), sizeof(Server::Maps::maps_offsets));
full_barrier
const uint32_t cmd = Maps::MAP_INIT + (d->maps_module << 16);
const uint32_t cmd = Server::Maps::MAP_INIT + (d->maps_module << 16);
g_pProcess->SetAndWait(cmd);
//cerr << "Map acceleration enabled!" << endl;
}
*/
d->Inited = true;
}
Maps::~Maps()
{
if(d->Started)
Finish();
}
/*-----------------------------------*
* Init the mapblock pointer array *
*-----------------------------------*/
bool Maps::Start()
{
if(!d->Inited)
return false;
if(d->Started)
Finish();
Server::Maps::maps_offsets &off = d->offsets;
// get the map pointer
uint32_t x_array_loc = g_pProcess->readDWord (map_offset);
uint32_t x_array_loc = g_pProcess->readDWord (off.map_offset);
if (!x_array_loc)
{
return false;
// FIXME: only throw this due to programmer error, in the other map functions
//throw Error::NoMapLoaded();
}
// get the size
uint32_t mx, my, mz;
mx = d->x_block_count = g_pProcess->readDWord (x_count_offset);
my = d->y_block_count = g_pProcess->readDWord (y_count_offset);
mz = d->z_block_count = g_pProcess->readDWord (z_count_offset);
mx = d->x_block_count = g_pProcess->readDWord (off.x_count_offset);
my = d->y_block_count = g_pProcess->readDWord (off.y_count_offset);
mz = d->z_block_count = g_pProcess->readDWord (off.z_count_offset);
// test for wrong map dimensions
if (mx == 0 || mx > 48 || my == 0 || my > 48 || mz == 0)
@ -125,7 +157,7 @@ bool API::InitMap()
return true;
}
bool API::DestroyMap()
bool Maps::Finish()
{
if (d->block != NULL)
{
@ -135,28 +167,28 @@ bool API::DestroyMap()
return true;
}
bool API::isValidBlock (uint32_t x, uint32_t y, uint32_t z)
bool Maps::isValidBlock (uint32_t x, uint32_t y, uint32_t z)
{
if ( x >= d->x_block_count || y >= d->y_block_count || z >= d->z_block_count)
return false;
return d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z] != 0;
}
uint32_t API::getBlockPtr (uint32_t x, uint32_t y, uint32_t z)
uint32_t Maps::getBlockPtr (uint32_t x, uint32_t y, uint32_t z)
{
if ( x >= d->x_block_count || y >= d->y_block_count || z >= d->z_block_count)
return 0;
return d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
}
bool API::ReadBlock40d(uint32_t x, uint32_t y, uint32_t z, mapblock40d * buffer)
bool Maps::ReadBlock40d(uint32_t x, uint32_t y, uint32_t z, mapblock40d * buffer)
{
if(d->shm_start && d->maps_module) // ACCELERATE!
if(d->d->shm_start && d->maps_module) // ACCELERATE!
{
SHMMAPSHDR->x = x;
SHMMAPSHDR->y = y;
SHMMAPSHDR->z = z;
volatile uint32_t cmd = Maps::MAP_READ_BLOCK_BY_COORDS + (d->maps_module << 16);
volatile uint32_t cmd = Server::Maps::MAP_READ_BLOCK_BY_COORDS + (d->maps_module << 16);
if(!g_pProcess->SetAndWait(cmd))
return false;
memcpy(buffer,SHMDATA(mapblock40d),sizeof(mapblock40d));
@ -167,7 +199,7 @@ bool API::ReadBlock40d(uint32_t x, uint32_t y, uint32_t z, mapblock40d * buffer)
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
if (addr)
{
g_pProcess->read (addr + d->tile_type_offset, sizeof (buffer->tiletypes), (uint8_t *) buffer->tiletypes);
g_pProcess->read (addr + d->offsets.tile_type_offset, sizeof (buffer->tiletypes), (uint8_t *) buffer->tiletypes);
buffer->origin = addr;
uint32_t addr_of_struct = g_pProcess->readDWord(addr);
buffer->blockflags.whole = g_pProcess->readDWord(addr_of_struct);
@ -179,18 +211,18 @@ bool API::ReadBlock40d(uint32_t x, uint32_t y, uint32_t z, mapblock40d * buffer)
// 256 * sizeof(uint16_t)
bool API::ReadTileTypes (uint32_t x, uint32_t y, uint32_t z, tiletypes40d *buffer)
bool Maps::ReadTileTypes (uint32_t x, uint32_t y, uint32_t z, tiletypes40d *buffer)
{
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
if (addr)
{
g_pProcess->read (addr + d->tile_type_offset, sizeof (tiletypes40d), (uint8_t *) buffer);
g_pProcess->read (addr + d->offsets.tile_type_offset, sizeof (tiletypes40d), (uint8_t *) buffer);
return true;
}
return false;
}
bool API::ReadDirtyBit(uint32_t x, uint32_t y, uint32_t z, bool &dirtybit)
bool Maps::ReadDirtyBit(uint32_t x, uint32_t y, uint32_t z, bool &dirtybit)
{
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
if(addr)
@ -202,7 +234,7 @@ bool API::ReadDirtyBit(uint32_t x, uint32_t y, uint32_t z, bool &dirtybit)
return false;
}
bool API::WriteDirtyBit(uint32_t x, uint32_t y, uint32_t z, bool dirtybit)
bool Maps::WriteDirtyBit(uint32_t x, uint32_t y, uint32_t z, bool dirtybit)
{
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
if (addr)
@ -218,7 +250,7 @@ bool API::WriteDirtyBit(uint32_t x, uint32_t y, uint32_t z, bool dirtybit)
}
/// read/write the block flags
bool API::ReadBlockFlags(uint32_t x, uint32_t y, uint32_t z, t_blockflags &blockflags)
bool Maps::ReadBlockFlags(uint32_t x, uint32_t y, uint32_t z, t_blockflags &blockflags)
{
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
if(addr)
@ -229,7 +261,7 @@ bool API::ReadBlockFlags(uint32_t x, uint32_t y, uint32_t z, t_blockflags &block
}
return false;
}
bool API::WriteBlockFlags(uint32_t x, uint32_t y, uint32_t z, t_blockflags blockflags)
bool Maps::WriteBlockFlags(uint32_t x, uint32_t y, uint32_t z, t_blockflags blockflags)
{
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
if (addr)
@ -241,24 +273,24 @@ bool API::WriteBlockFlags(uint32_t x, uint32_t y, uint32_t z, t_blockflags block
return false;
}
bool API::ReadDesignations (uint32_t x, uint32_t y, uint32_t z, designations40d *buffer)
bool Maps::ReadDesignations (uint32_t x, uint32_t y, uint32_t z, designations40d *buffer)
{
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
if (addr)
{
g_pProcess->read (addr + d->designation_offset, sizeof (designations40d), (uint8_t *) buffer);
g_pProcess->read (addr + d->offsets.designation_offset, sizeof (designations40d), (uint8_t *) buffer);
return true;
}
return false;
}
// 256 * sizeof(uint16_t)
bool API::WriteTileTypes (uint32_t x, uint32_t y, uint32_t z, tiletypes40d *buffer)
bool Maps::WriteTileTypes (uint32_t x, uint32_t y, uint32_t z, tiletypes40d *buffer)
{
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
if (addr)
{
g_pProcess->write (addr + d->tile_type_offset, sizeof (tiletypes40d), (uint8_t *) buffer);
g_pProcess->write (addr + d->offsets.tile_type_offset, sizeof (tiletypes40d), (uint8_t *) buffer);
return true;
}
return false;
@ -266,12 +298,12 @@ bool API::WriteTileTypes (uint32_t x, uint32_t y, uint32_t z, tiletypes40d *buff
// 256 * sizeof(uint32_t)
bool API::WriteDesignations (uint32_t x, uint32_t y, uint32_t z, designations40d *buffer)
bool Maps::WriteDesignations (uint32_t x, uint32_t y, uint32_t z, designations40d *buffer)
{
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
if (addr)
{
g_pProcess->write (addr + d->designation_offset, sizeof (designations40d), (uint8_t *) buffer);
g_pProcess->write (addr + d->offsets.designation_offset, sizeof (designations40d), (uint8_t *) buffer);
return true;
}
return false;
@ -281,7 +313,7 @@ bool API::WriteDesignations (uint32_t x, uint32_t y, uint32_t z, designations40d
//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 API::ReadRegionOffsets (uint32_t x, uint32_t y, uint32_t z, biome_indices40d *buffer)
bool Maps::ReadRegionOffsets (uint32_t x, uint32_t y, uint32_t z, biome_indices40d *buffer)
{
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
if (addr)
@ -294,16 +326,17 @@ bool API::ReadRegionOffsets (uint32_t x, uint32_t y, uint32_t z, biome_indices40
*/
// veins of a block, expects empty vein vectors
bool API::ReadVeins(uint32_t x, uint32_t y, uint32_t z, vector <t_vein> & veins, vector <t_frozenliquidvein>& ices)
bool Maps::ReadVeins(uint32_t x, uint32_t y, uint32_t z, vector <t_vein> & veins, vector <t_frozenliquidvein>& ices)
{
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
veins.clear();
ices.clear();
if (addr && d->veinvector)
Server::Maps::maps_offsets &off = d->offsets;
if (addr && off.veinvector)
{
// veins are stored as a vector of pointers to veins
/*pointer is 4 bytes! we work with a 32bit program here, no matter what architecture we compile khazad for*/
DfVector p_veins (d->p, addr + d->veinvector, 4);
DfVector p_veins (d->d->p, addr + off.veinvector, 4);
uint32_t size = p_veins.getSize();
veins.reserve (size);
@ -317,7 +350,7 @@ bool API::ReadVeins(uint32_t x, uint32_t y, uint32_t z, vector <t_vein> & veins,
uint32_t temp = * (uint32_t *) p_veins[i];
uint32_t type = g_pProcess->readDWord(temp);
try_again:
if(type == d->vein_mineral_vptr)
if(type == off.vein_mineral_vptr)
{
// read the vein data (dereference pointer)
g_pProcess->read (temp, sizeof(t_vein), (uint8_t *) &v);
@ -325,7 +358,7 @@ try_again:
// store it in the vector
veins.push_back (v);
}
else if(type == d->vein_ice_vptr)
else if(type == off.vein_ice_vptr)
{
// read the ice vein data (dereference pointer)
g_pProcess->read (temp, sizeof(t_frozenliquidvein), (uint8_t *) &fv);
@ -334,12 +367,12 @@ try_again:
}
else if(g_pProcess->readClassName(type) == "block_square_event_frozen_liquid")
{
d->vein_ice_vptr = type;
off.vein_ice_vptr = type;
goto try_again;
}
else if(g_pProcess->readClassName(type) == "block_square_event_mineral")
{
d->vein_mineral_vptr = type;
off.vein_mineral_vptr = type;
goto try_again;
}
}
@ -350,7 +383,7 @@ try_again:
// getter for map size
void API::getSize (uint32_t& x, uint32_t& y, uint32_t& z)
void Maps::getSize (uint32_t& x, uint32_t& y, uint32_t& z)
{
x = d->x_block_count;
y = d->y_block_count;

@ -1,13 +0,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
*/
bool ReadInorganicMaterials (std::vector<t_matgloss> & output);
bool ReadOrganicMaterials (std::vector<t_matgloss> & output);
bool ReadWoodMaterials (std::vector<t_matgloss> & output);
bool ReadPlantMaterials (std::vector<t_matgloss> & output);
// bool ReadPlantMaterials (std::vector<t_matglossPlant> & output);
bool ReadCreatureTypes (std::vector<t_matgloss> & output);

@ -24,7 +24,18 @@ distribution.
#include "DFCommonInternal.h"
#include "../private/APIPrivate.h"
#include "modules/Materials.h"
#include "DFVector.h"
#include "DFMemInfo.h"
#include "DFProcess.h"
using namespace DFHack;
Materials::Materials(APIPrivate * d_)
{
d = d_;
}
Materials::~Materials(){}
/*
{
LABEL_53:
@ -169,34 +180,34 @@ inline bool ReadNamesOnly(Process* p, uint32_t address, vector<t_matgloss> & nam
return true;
}
bool API::ReadInorganicMaterials (vector<t_matgloss> & inorganic)
bool Materials::ReadInorganicMaterials (vector<t_matgloss> & inorganic)
{
return ReadNamesOnly(d->p, d->offset_descriptor->getAddress ("mat_inorganics"), inorganic );
}
bool API::ReadOrganicMaterials (vector<t_matgloss> & organic)
bool Materials::ReadOrganicMaterials (vector<t_matgloss> & organic)
{
return ReadNamesOnly(d->p, d->offset_descriptor->getAddress ("mat_organics_all"), organic );
}
bool API::ReadWoodMaterials (vector<t_matgloss> & trees)
bool Materials::ReadWoodMaterials (vector<t_matgloss> & trees)
{
return ReadNamesOnly(d->p, d->offset_descriptor->getAddress ("mat_organics_trees"), trees );
}
bool API::ReadPlantMaterials (vector<t_matgloss> & plants)
bool Materials::ReadPlantMaterials (vector<t_matgloss> & plants)
{
return ReadNamesOnly(d->p, d->offset_descriptor->getAddress ("mat_organics_plants"), plants );
}
/*
Gives bad results combined with the creature race field!
bool API::ReadCreatureTypes (vector<t_matgloss> & creatures)
bool Materials::ReadCreatureTypes (vector<t_matgloss> & creatures)
{
return ReadNamesOnly(d->p, d->offset_descriptor->getAddress ("mat_creature_types"), creatures );
return true;
}
*/
bool API::ReadCreatureTypes (vector<t_matgloss> & creatures)
bool Materials::ReadCreatureTypes (vector<t_matgloss> & creatures)
{
return ReadNamesOnly(d->p, d->offset_descriptor->getAddress ("creature_type_vector"), creatures );
return true;

@ -1,6 +0,0 @@
uint32_t window_x_offset;
uint32_t window_y_offset;
uint32_t window_z_offset;
uint32_t cursor_xyz_offset;
uint32_t window_dims_offset;
bool cursorWindowInited;

@ -1,17 +0,0 @@
/*
* Cursor and window coords
*/
bool InitViewAndCursor();
bool getViewCoords (int32_t &x, int32_t &y, int32_t &z);
bool setViewCoords (const int32_t x, const int32_t y, const int32_t z);
bool getCursorCoords (int32_t &x, int32_t &y, int32_t &z);
bool setCursorCoords (const int32_t x, const int32_t y, const int32_t z);
/*
* Window size in tiles
*/
bool InitViewSize();
bool getWindowSize(int32_t & width, int32_t & height);
/// get the creature vector index of the creature currently under DF' cursor
bool getCurrentCursorCreature (uint32_t & creature_index);

@ -24,24 +24,54 @@ distribution.
#include "DFCommonInternal.h"
#include "../private/APIPrivate.h"
#include "modules/Position.h"
#include "DFMemInfo.h"
#include "DFProcess.h"
using namespace DFHack;
bool API::InitViewAndCursor()
struct Position::Private
{
uint32_t window_x_offset;
uint32_t window_y_offset;
uint32_t window_z_offset;
uint32_t cursor_xyz_offset;
uint32_t window_dims_offset;
APIPrivate *d;
bool Inited;
bool Started;
//uint32_t biome_stuffs;
//vector<uint16_t> v_geology[eBiomeCount];
};
Position::Position(APIPrivate * d_)
{
d = new Private;
d->d = d_;
d->Inited = d->Started = false;
memory_info * mem = d->d->offset_descriptor;
d->window_x_offset = mem->getAddress ("window_x");
d->window_y_offset = mem->getAddress ("window_y");
d->window_z_offset = mem->getAddress ("window_z");
d->cursor_xyz_offset = mem->getAddress ("cursor_xyz");
d->window_dims_offset = mem->getAddress ("window_dims");
d->Inited = d->Started = true;
}
Position::~Position()
{
delete d;
}
/*
bool Position::InitViewAndCursor()
{
try
{
d->window_x_offset = d->offset_descriptor->getAddress ("window_x");
d->window_y_offset = d->offset_descriptor->getAddress ("window_y");
d->window_z_offset = d->offset_descriptor->getAddress ("window_z");
d->cursor_xyz_offset = d->offset_descriptor->getAddress ("cursor_xyz");
d->current_cursor_creature_offset = d->offset_descriptor->getAddress ("current_cursor_creature");
d->window_dims_offset = d->offset_descriptor->getAddress ("window_dims");
d->current_menu_state_offset = d->offset_descriptor->getAddress("current_menu_state");
d->pause_state_offset = d->offset_descriptor->getAddress ("pause_state");
d->view_screen_offset = d->offset_descriptor->getAddress ("view_screen");
d->cursorWindowInited = true;
d->Inited = true;
return true;
}
catch (Error::MissingMemoryDefinition&)
@ -50,10 +80,10 @@ bool API::InitViewAndCursor()
throw;
}
}
bool API::getViewCoords (int32_t &x, int32_t &y, int32_t &z)
*/
bool Position::getViewCoords (int32_t &x, int32_t &y, int32_t &z)
{
if (!d->cursorWindowInited) return false;
if (!d->Inited) return false;
g_pProcess->readDWord (d->window_x_offset, (uint32_t &) x);
g_pProcess->readDWord (d->window_y_offset, (uint32_t &) y);
g_pProcess->readDWord (d->window_z_offset, (uint32_t &) z);
@ -61,18 +91,18 @@ bool API::getViewCoords (int32_t &x, int32_t &y, int32_t &z)
}
//FIXME: confine writing of coords to map bounds?
bool API::setViewCoords (const int32_t x, const int32_t y, const int32_t z)
bool Position::setViewCoords (const int32_t x, const int32_t y, const int32_t z)
{
if (!d->cursorWindowInited) return false;
if (!d->Inited) return false;
g_pProcess->writeDWord (d->window_x_offset, (uint32_t) x);
g_pProcess->writeDWord (d->window_y_offset, (uint32_t) y);
g_pProcess->writeDWord (d->window_z_offset, (uint32_t) z);
return true;
}
bool API::getCursorCoords (int32_t &x, int32_t &y, int32_t &z)
bool Position::getCursorCoords (int32_t &x, int32_t &y, int32_t &z)
{
if(!d->cursorWindowInited) return false;
if(!d->Inited) return false;
int32_t coords[3];
g_pProcess->read (d->cursor_xyz_offset, 3*sizeof (int32_t), (uint8_t *) coords);
x = coords[0];
@ -83,17 +113,17 @@ bool API::getCursorCoords (int32_t &x, int32_t &y, int32_t &z)
}
//FIXME: confine writing of coords to map bounds?
bool API::setCursorCoords (const int32_t x, const int32_t y, const int32_t z)
bool Position::setCursorCoords (const int32_t x, const int32_t y, const int32_t z)
{
if (!d->cursorWindowInited) return false;
if (!d->Inited) return false;
int32_t coords[3] = {x, y, z};
g_pProcess->write (d->cursor_xyz_offset, 3*sizeof (int32_t), (uint8_t *) coords);
return true;
}
bool API::getWindowSize (int32_t &width, int32_t &height)
bool Position::getWindowSize (int32_t &width, int32_t &height)
{
if(! d->cursorWindowInited) return false;
if(!d->Inited) return false;
int32_t coords[2];
g_pProcess->read (d->window_dims_offset, 2*sizeof (int32_t), (uint8_t *) coords);

@ -29,34 +29,26 @@ distribution.
#ifndef APIPRIVATE_H_INCLUDED
#define APIPRIVATE_H_INCLUDED
// we connect to those
#include <shms.h>
#include <mod-core.h>
#include <mod-maps.h>
// #include <mod-creature40d.h>
#include <mod-creature2010.h>
#define SHMCMD(num) ((shm_cmd *)d->shm_start)[num]->pingpong
#define SHMHDR ((shm_core_hdr *)d->shm_start)
#define SHMDATA(type) ((type *)(d->shm_start + SHM_HEADER))
namespace DFHack
{
class Materials;
class Gui;
class Position;
class Maps;
class Creatures;
class ProcessEnumerator;
class Process;
class memory_info;
struct t_name;
class APIPrivate
{
public:
APIPrivate();
~APIPrivate();
void readName(t_name & name, uint32_t address);
// get the name offsets
bool InitReadNames();
#include "../modules/Creatures-data.h"
#include "../modules/Maps-data.h"
#include "../modules/Position-data.h"
#include "../modules/Gui-data.h"
#include "../modules/Materials-data.h"
uint32_t name_firstname_offset;
uint32_t name_nickname_offset;
uint32_t name_words_offset;
@ -67,6 +59,13 @@ public:
memory_info* offset_descriptor;
string xml;
// Modules
Creatures * creatures;
Maps * maps;
Position * position;
Gui * gui;
Materials * materials;
/*
uint32_t item_material_offset;

@ -77,7 +77,7 @@ enum CREATURE_COMMAND
CREATURE_INIT = 0, // initialization
CREATURE_FIND_IN_BOX,
CREATURE_AT_INDEX,
NUM_CREATURE_CMDS,
NUM_CREATURE_CMDS
};
DFPP_module Init(void);

@ -26,6 +26,8 @@ distribution.
#define MOD_CREATURES40D_H
namespace DFHack
{
namespace Server
{
namespace Creatures
{
@ -102,5 +104,6 @@ DFPP_module Init(void);
}
}
}
#endif

@ -29,6 +29,8 @@ distribution.
#include <DFTypes.h>
namespace DFHack
{
namespace Server
{
namespace Maps
{
@ -95,10 +97,10 @@ enum MAPS_COMMAND
MAP_READ_BLOCKS_3D, // read blocks between two coords (volumetric)
MAP_READ_ALL_BLOCKS, // read the entire map
MAP_REVEAL, // reveal the whole map
NUM_MAPS_CMDS,
NUM_MAPS_CMDS
};
DFPP_module Init(void);
}
}
}

@ -41,7 +41,7 @@ enum DFPP_CmdType
{
CANCELLATION, // we should jump out of the Act()
CLIENT_WAIT, // we are waiting for the client
FUNCTION, // we call a function as a result of the command
FUNCTION // we call a function as a result of the command
};
struct DFPP_command

@ -10,6 +10,8 @@ using namespace std;
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFMemInfo.h>
#include <modules/Materials.h>
#include <modules/Creatures.h>
template <typename T>
void print_bits ( T val, std::ostream& out )
@ -321,8 +323,11 @@ int main (void)
return 1;
}
DFHack::Creatures * Creatures = DF.getCreatures();
DFHack::Materials * Materials = DF.getMaterials();
uint32_t numCreatures;
if(!DF.InitReadCreatures(numCreatures))
if(!Creatures->Start(numCreatures))
{
cerr << "Can't get creatures" << endl;
#ifndef LINUX_BUILD
@ -348,7 +353,7 @@ int main (void)
*/
mem = DF.getMemoryInfo();
// get stone matgloss mapping
if(!DF.ReadCreatureTypes(creaturestypes))
if(!Materials->ReadCreatureTypes(creaturestypes))
{
cerr << "Can't get the creature types." << endl;
return 1;
@ -364,7 +369,7 @@ int main (void)
for(uint32_t i = 0; i < numCreatures; i++)
{
DFHack::t_creature temp;
DF.ReadCreature(i,temp);
Creatures->ReadCreature(i,temp);
//if(string(creaturestypes[temp.type].id) == "DWARF")
{
cout << "index " << i << " ";
@ -380,7 +385,7 @@ int main (void)
DF.ReadCreature(currentIdx, currentCreature);
printCreature(DF,currentCreature);
*/
DF.FinishReadCreatures();
Creatures->Finish();
DF.Detach();
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;

@ -11,6 +11,7 @@ using namespace std;
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <modules/Maps.h>
void print_progress (int current, int total)
{
@ -48,11 +49,12 @@ int main (int numargs, char** args)
uint32_t num_blocks = 0;
uint64_t bytes_read = 0;
DFHack::mapblock40d Block;
DFHack::Maps *Maps = 0;
DFHack::API DF("Memory.xml");
try
{
DF.Attach();
Maps = DF.getMaps();
}
catch (exception& e)
{
@ -70,25 +72,25 @@ int main (int numargs, char** args)
{
print_progress (i, iterations);
if(!DF.InitMap())
if(!Maps->Start())
break;
DF.getSize(x_max,y_max,z_max);
Maps->getSize(x_max,y_max,z_max);
for(uint32_t x = 0; x< x_max;x++)
{
for(uint32_t y = 0; y< y_max;y++)
{
for(uint32_t z = 0; z< z_max;z++)
{
if(DF.isValidBlock(x,y,z))
if(Maps->isValidBlock(x,y,z))
{
DF.ReadBlock40d(x, y, z, &Block);
Maps->ReadBlock40d(x, y, z, &Block);
num_blocks ++;
bytes_read += sizeof(DFHack::mapblock40d);
}
}
}
}
DF.DestroyMap();
Maps->Finish();
}
DF.Detach();
time(&end);

@ -13,6 +13,7 @@ using namespace std;
#include <DFProcess.h>
#include <DFMemInfo.h>
#include <DFVector.h>
#include <modules/Materials.h>
void DumpObjStr0Vector (const char * name, DFHack::Process *p, uint32_t addr)
{
@ -62,6 +63,8 @@ int main (int numargs, const char ** args)
DFHack::Process* p = DF.getProcess();
DFHack::memory_info* mem = DF.getMemoryInfo();
DFHack::Materials *Materials = DF.getMaterials();
//const vector<string> * names = mem->getClassIDMapping();
/*
DumpObjStr0Vector("Material templates",p, mem->getAddress("mat_templates"));
@ -91,7 +94,7 @@ int main (int numargs, const char ** args)
cout << "----==== Inorganic ====----" << endl;
vector<DFHack::t_matgloss> matgloss;
DF.ReadInorganicMaterials (matgloss);
Materials->ReadInorganicMaterials (matgloss);
for(int i = 0; i < matgloss.size();i++)
{
cout << matgloss[i].id << endl;
@ -99,14 +102,14 @@ int main (int numargs, const char ** args)
cout << endl << "----==== Organic ====----" << endl;
vector<DFHack::t_matgloss> organic;
DF.ReadOrganicMaterials (matgloss);
Materials->ReadOrganicMaterials (matgloss);
for(int i = 0; i < matgloss.size();i++)
{
cout << matgloss[i].id << endl;
}
cout << endl << "----==== Creature types ====----" << endl;
vector<DFHack::t_matgloss> creature;
DF.ReadCreatureTypes (matgloss);
Materials->ReadCreatureTypes (matgloss);
for(int i = 0; i < matgloss.size();i++)
{
cout << matgloss[i].id << endl;

@ -9,13 +9,16 @@ using namespace std;
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <modules/Position.h>
int main (void)
{
DFHack::API DF("Memory.xml");
DFHack::Position * Position = 0;
try
{
DF.Attach();
Position = DF.getPosition();
}
catch (exception& e)
{
@ -25,17 +28,16 @@ int main (void)
#endif
return 1;
}
if (DF.InitViewAndCursor())
if (Position)
{
int32_t x,y,z;
int32_t width,height;
if(DF.getViewCoords(x,y,z))
if(Position->getViewCoords(x,y,z))
cout << "view coords: " << x << "/" << y << "/" << z << endl;
if(DF.getCursorCoords(x,y,z))
if(Position->getCursorCoords(x,y,z))
cout << "cursor coords: " << x << "/" << y << "/" << z << endl;
if(DF.getWindowSize(width,height))
if(Position->getWindowSize(width,height))
cout << "window size : " << width << " " << height << endl;
}
else

@ -8,17 +8,21 @@
#include <map>
using namespace std;
#include <sstream>
#include "fake-curses.h"
#include <stdlib.h>
#include <signal.h>
#include <locale.h>
#include <DFTypes.h>
#include <DFTileTypes.h>
#include <DFHackAPI.h>
#include <DFProcess.h>
#include <DFMemInfo.h>
#include <modules/Maps.h>
#include <modules/Materials.h>
using namespace DFHack;
#include <sstream>
#include "fake-curses.h"
#include <stdlib.h>
#include <signal.h>
#include <locale.h>
string error;
API * pDF = 0;
@ -308,10 +312,16 @@ main(int argc, char *argv[])
vector<t_vein> veinVector;
vector<t_frozenliquidvein> IceVeinVector;
DFHack::Materials * Mats = 0;
DFHack::Maps * Maps = 0;
DFHack::API DF("Memory.xml");
try
{
DF.Attach();
Mats = DF.getMaterials();
Maps = DF.getMaps();
pDF = &DF;
}
catch (exception& e)
@ -325,20 +335,20 @@ main(int argc, char *argv[])
Process* p = DF.getProcess();
// init the map
if(!DF.InitMap())
if(!Maps->Start())
{
error = "Can't find a map to look at.";
pDF = 0;
finish(0);
}
DF.getSize(x_max_a,y_max_a,z_max_a);
Maps->getSize(x_max_a,y_max_a,z_max_a);
x_max = x_max_a;
y_max = y_max_a;
z_max = z_max_a;
// get stone matgloss mapping
if(!DF.ReadInorganicMaterials(stonetypes))
if(!Mats->ReadInorganicMaterials(stonetypes))
{
error = "Can't read stone types.";
pDF = 0;
@ -455,18 +465,18 @@ main(int argc, char *argv[])
mapblock40d * Block = &blocks[i+1][j+1];
if(DF.isValidBlock(cursorX+i,cursorY+j,cursorZ))
if(Maps->isValidBlock(cursorX+i,cursorY+j,cursorZ))
{
DF.ReadBlock40d(cursorX+i,cursorY+j,cursorZ, Block);
Maps->ReadBlock40d(cursorX+i,cursorY+j,cursorZ, Block);
// extra processing of the block in the middle
if(i == 0 && j == 0)
{
// read veins
DF.ReadVeins(cursorX+i,cursorY+j,cursorZ,veinVector,IceVeinVector);
Maps->ReadVeins(cursorX+i,cursorY+j,cursorZ,veinVector,IceVeinVector);
// get pointer to block
blockaddr = DF.getBlockPtr(cursorX+i,cursorY+j,cursorZ);
blockaddr = Maps->getBlockPtr(cursorX+i,cursorY+j,cursorZ);
blockaddr2 = Block->origin;
// dig all veins and trees
@ -481,7 +491,7 @@ main(int argc, char *argv[])
Block->designation[x][y].bits.dig = designation_default;
}
}
DF.WriteDesignations(cursorX+i,cursorY+j,cursorZ, &(Block->designation));
Maps->WriteDesignations(cursorX+i,cursorY+j,cursorZ, &(Block->designation));
}
// do a dump of the block data
if(dump)
@ -490,12 +500,12 @@ main(int argc, char *argv[])
filenum++;
}
// read/write dirty bit of the block
DF.ReadDirtyBit(cursorX+i,cursorY+j,cursorZ,dirtybit);
DF.ReadBlockFlags(cursorX+i,cursorY+j,cursorZ,bflags);
Maps->ReadDirtyBit(cursorX+i,cursorY+j,cursorZ,dirtybit);
Maps->ReadBlockFlags(cursorX+i,cursorY+j,cursorZ,bflags);
if(digbit)
{
dirtybit = !dirtybit;
DF.WriteDirtyBit(cursorX+i,cursorY+j,cursorZ,dirtybit);
Maps->WriteDirtyBit(cursorX+i,cursorY+j,cursorZ,dirtybit);
}
}
}

@ -19,6 +19,8 @@ using namespace std;
#include <DFTypes.h>
#include <DFTileTypes.h>
#include <DFHackAPI.h>
#include <modules/Maps.h>
#include <modules/Materials.h>
int main (int argc, const char* argv[])
{
@ -69,8 +71,12 @@ int main (int argc, const char* argv[])
return 1;
}
DFHack::Maps * Maps = DF.getMaps();
DFHack::Materials * Mats = DF.getMaterials();
// init the map
if(!DF.InitMap())
if(!Maps->Start())
{
cerr << "Can't init map." << endl;
#ifndef LINUX_BUILD
@ -78,10 +84,10 @@ int main (int argc, const char* argv[])
#endif
return 1;
}
DF.getSize(x_max,y_max,z_max);
Maps->getSize(x_max,y_max,z_max);
// get stone matgloss mapping
if(!DF.ReadInorganicMaterials(stonetypes))
if(!Mats->ReadInorganicMaterials(stonetypes))
{
//DF.DestroyMap();
cerr << "Can't get the materials." << endl;
@ -113,16 +119,16 @@ int main (int argc, const char* argv[])
{
for(uint32_t z = 0; z< z_max;z++)
{
if(!DF.isValidBlock(x,y,z))
if(!Maps->isValidBlock(x,y,z))
continue;
// read data
DF.ReadTileTypes(x,y,z, &tiletypes);
DF.ReadDesignations(x,y,z, &designations);
Maps->ReadTileTypes(x,y,z, &tiletypes);
Maps->ReadDesignations(x,y,z, &designations);
memset(tempvein, -1, sizeof(tempvein));
veins.clear();
DF.ReadVeins(x,y,z,veins,iceveins);
Maps->ReadVeins(x,y,z,veins,iceveins);
/*
if(showbaselayers)
{

@ -7,6 +7,7 @@ using namespace std;
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <modules/Maps.h>
int main (void)
{
@ -27,8 +28,9 @@ int main (void)
return 1;
}
DFHack::Maps *Maps =DF.getMaps();
// init the map
if(!DF.InitMap())
if(!Maps->Start())
{
cerr << "Can't init map." << endl;
#ifndef LINUX_BUILD
@ -37,7 +39,7 @@ int main (void)
return 1;
}
DF.getSize(x_max,y_max,z_max);
Maps->getSize(x_max,y_max,z_max);
// walk the map
for(uint32_t x = 0; x< x_max;x++)
@ -46,17 +48,17 @@ int main (void)
{
for(uint32_t z = 0; z< z_max;z++)
{
if(DF.isValidBlock(x,y,z))
if(Maps->isValidBlock(x,y,z))
{
// read block designations
DF.ReadDesignations(x,y,z, &designations);
Maps->ReadDesignations(x,y,z, &designations);
// change the hidden flag to 0
for (uint32_t i = 0; i < 16;i++) for (uint32_t j = 0; j < 16;j++)
{
designations[i][j].bits.hidden = 0;
}
// write the designations back
DF.WriteDesignations(x,y,z, &designations);
Maps->WriteDesignations(x,y,z, &designations);
}
}
}