Multi-process rework

develop
Petr Mrázek 2010-05-23 23:06:10 +02:00
parent 795e2e9883
commit 8dd594dd93
65 changed files with 617 additions and 1228 deletions

@ -33,7 +33,7 @@ include_directories (${CMAKE_SOURCE_DIR}/dfhack/depends/tinyxml/)
include_directories (${CMAKE_SOURCE_DIR}/dfhack/depends/argstream/)
add_subdirectory (dfhack)
add_subdirectory (dfhack/python)
#add_subdirectory (dfhack/python)
#add_subdirectory (dfhack/shm)
#FIXME: add exports for MSVC
#add_subdirectory (dfhack/depends/md5)

@ -20,7 +20,7 @@
using namespace DFHack;
APIPrivate::APIPrivate()
DFContextPrivate::DFContextPrivate()
{
// init modules
creatures = 0;
@ -36,7 +36,7 @@ APIPrivate::APIPrivate()
items = 0;
}
APIPrivate::~APIPrivate()
DFContextPrivate::~DFContextPrivate()
{
if(creatures) delete creatures;
if(maps) delete maps;
@ -50,7 +50,7 @@ APIPrivate::~APIPrivate()
if(world) delete world;
}
bool APIPrivate::InitReadNames()
bool DFContextPrivate::InitReadNames()
{
name_firstname_offset = offset_descriptor->getOffset("name_firstname");
name_nickname_offset = offset_descriptor->getOffset("name_nickname");
@ -58,7 +58,7 @@ bool APIPrivate::InitReadNames()
return true;
}
void APIPrivate::readName(t_name & name, uint32_t address)
void DFContextPrivate::readName(t_name & name, uint32_t address)
{
p->readSTLString(address + name_firstname_offset , name.first_name, 128);
p->readSTLString(address + name_nickname_offset , name.nickname, 128);

@ -12,7 +12,7 @@ include/DFTileTypes.h
include/DFTypes.h
include/DFVector.h
include/DFWindow.h
include/DFHackAPI_C.h
#include/DFHackAPI_C.h
include/integers.h
shm/shms.h
)
@ -20,12 +20,13 @@ shm/shms.h
SET(PROJECT_SRCS
DFMemInfo.cpp
DFMemInfoManager.cpp
DFHackAPI.cpp
DFContextManager.cpp
DFContext.cpp
APIPrivate.cpp
DFTileTypes.cpp
DFVector.cpp
DFHackAPI_C.cpp
DFTypes_C.cpp
#DFHackAPI_C.cpp
#DFTypes_C.cpp
depends/md5/md5.cpp
depends/md5/md5wrapper.cpp
@ -47,16 +48,16 @@ modules/Vegetation.cpp
modules/Buildings.cpp
modules/Constructions.cpp
modules/Position_C.cpp
modules/Gui_C.cpp
modules/Materials_C.cpp
modules/Buildings_C.cpp
modules/Constructions_C.cpp
modules/Maps_C.cpp
modules/Vegetation_C.cpp
modules/Creatures_C.cpp
modules/Translation_C.cpp
modules/Items_C.cpp
#modules/Position_C.cpp
#modules/Gui_C.cpp
#modules/Materials_C.cpp
#modules/Buildings_C.cpp
#modules/Constructions_C.cpp
#modules/Maps_C.cpp
#modules/Vegetation_C.cpp
#modules/Creatures_C.cpp
#modules/Translation_C.cpp
#modules/Items_C.cpp
)
SET(PROJECT_HDRS_LINUX

@ -1,613 +0,0 @@
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#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>
#include "private/APIPrivate.h"
#include "modules/Maps.h"
#include "modules/Materials.h"
#include "modules/Items.h"
#include "modules/Position.h"
#include "modules/Gui.h"
#include "modules/World.h"
#include "modules/Creatures.h"
#include "modules/Translation.h"
#include "modules/Vegetation.h"
#include "modules/Buildings.h"
#include "modules/Constructions.h"
using namespace DFHack;
API::API (const string path_to_xml)
: d (new APIPrivate())
{
d->xml = QUOT (MEMXML_DATA_PATH);
d->xml += "/";
d->xml += path_to_xml;
d->pm = NULL;
d->p = 0;
d->shm_start = 0;
}
API::~API()
{
Detach();
delete d;
}
bool API::Attach()
{
if(d->p != NULL)
{
return d->p->suspend();
}
// detach all processes, destroy manager
if (d->pm == 0)
{
d->pm = new ProcessEnumerator (d->xml); // FIXME: handle bad XML better
}
else
{
d->pm->purge();
}
// find a process (ProcessManager can find multiple when used properly)
if (!d->pm->findProcessess())
{
throw Error::NoProcess();
//cerr << "couldn't find a suitable process" << endl;
//return false;
}
d->p = (*d->pm) [0];
if (!d->p->attach())
{
throw Error::CantAttach();
//cerr << "couldn't attach to process" << endl;
//return false; // couldn't attach to process, no go
}
d->shm_start = d->p->getSHMStart();
d->offset_descriptor = d->p->getDescriptor();
// process is attached, everything went just fine... hopefully
return true;
}
bool API::Detach()
{
if(!d->p)
return false;
if (!d->p->detach())
{
return false;
}
if (d->pm != NULL)
{
delete d->pm;
}
d->pm = NULL;
d->p = NULL;
d->shm_start = 0;
d->offset_descriptor = NULL;
// invalidate all modules
if(d->creatures)
{
delete d->creatures;
d->creatures = 0;
}
if(d->creatures)
{
delete d->creatures;
d->creatures = 0;
}
if(d->maps)
{
delete d->maps;
d->maps = 0;
}
if(d->gui)
{
delete d->gui;
d->gui = 0;
}
if(d->world)
{
delete d->world;
d->world = 0;
}
if(d->position)
{
delete d->position;
d->position = 0;
}
if(d->materials)
{
delete d->materials;
d->materials = 0;
}
if(d->items)
{
delete d->items;
d->items = 0;
}
if(d->translation)
{
delete d->translation;
d->translation = 0;
}
if(d->vegetation)
{
delete d->vegetation;
d->vegetation = 0;
}
if(d->constructions)
{
delete d->constructions;
d->constructions = 0;
}
if(d->translation)
{
delete d->translation;
d->translation = 0;
}
return true;
}
bool API::isAttached()
{
return d->p != NULL;
}
bool API::Suspend()
{
return d->p->suspend();
}
bool API::AsyncSuspend()
{
return d->p->asyncSuspend();
}
bool API::Resume()
{
return d->p->resume();
}
bool API::ForceResume()
{
return d->p->forceresume();
}
bool API::isSuspended()
{
return d->p->isSuspended();
}
void API::ReadRaw (const uint32_t offset, const uint32_t size, uint8_t *target)
{
d->p->read (offset, size, target);
}
void API::WriteRaw (const uint32_t offset, const uint32_t size, uint8_t *source)
{
d->p->write (offset, size, source);
}
memory_info *API::getMemoryInfo()
{
return d->offset_descriptor;
}
Process * API::getProcess()
{
return d->p;
}
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;
}
World * API::getWorld()
{
if(!d->world)
d->world = new World(d);
return d->world;
}
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;
}
Items * API::getItems()
{
if(!d->items)
d->items = new Items(d);
return d->items;
}
Translation * API::getTranslation()
{
if(!d->translation)
d->translation = new Translation(d);
return d->translation;
}
Vegetation * API::getVegetation()
{
if(!d->vegetation)
d->vegetation = new Vegetation(d);
return d->vegetation;
}
Buildings * API::getBuildings()
{
if(!d->buildings)
d->buildings = new Buildings(d);
return d->buildings;
}
Constructions * API::getConstructions()
{
if(!d->constructions)
d->constructions = new Constructions(d);
return d->constructions;
}
/*
// returns number of buildings, expects v_buildingtypes that will later map t_building.type to its name
bool API::InitReadEffects ( uint32_t & numeffects )
{
if(d->effectsInited)
FinishReadEffects();
int effects = 0;
try
{
effects = d->offset_descriptor->getAddress ("effects_vector");
}
catch(Error::MissingMemoryDefinition)
{
return false;
}
d->effectsInited = true;
d->p_effect = new DfVector (d->p, effects);
numeffects = d->p_effect->getSize();
return true;
}
bool API::ReadEffect(const uint32_t index, t_effect_df40d & effect)
{
if(!d->effectsInited)
return false;
if(index >= d->p_effect->getSize())
return false;
// read pointer from vector at position
uint32_t temp = d->p_effect->at (index);
//read effect from memory
d->p->read (temp, sizeof (t_effect_df40d), (uint8_t *) &effect);
return true;
}
// use with care!
bool API::WriteEffect(const uint32_t index, const t_effect_df40d & effect)
{
if(!d->effectsInited)
return false;
if(index >= d->p_effect->getSize())
return false;
// read pointer from vector at position
uint32_t temp = d->p_effect->at (index);
// write effect to memory
d->p->write(temp,sizeof(t_effect_df40d), (uint8_t *) &effect);
return true;
}
void API::FinishReadEffects()
{
if(d->p_effect)
{
delete d->p_effect;
d->p_effect = NULL;
}
d->effectsInited = false;
}
*/
/*
bool API::InitReadNotes( uint32_t &numnotes )
{
try
{
memory_info * minfo = d->offset_descriptor;
int notes = minfo->getAddress ("notes");
d->note_foreground_offset = minfo->getOffset ("note_foreground");
d->note_background_offset = minfo->getOffset ("note_background");
d->note_name_offset = minfo->getOffset ("note_name");
d->note_xyz_offset = minfo->getOffset ("note_xyz");
d->p_notes = new DfVector (d->p, notes);
d->notesInited = true;
numnotes = d->p_notes->getSize();
return true;
}
catch (Error::MissingMemoryDefinition&)
{
d->notesInited = false;
numnotes = 0;
throw;
}
}
bool API::ReadNote (const int32_t index, t_note & note)
{
if(!d->notesInited) return false;
// read pointer from vector at position
uint32_t temp = d->p_notes->at (index);
note.symbol = d->p->readByte(temp);
note.foreground = d->p->readWord(temp + d->note_foreground_offset);
note.background = d->p->readWord(temp + d->note_background_offset);
d->p->readSTLString (temp + d->note_name_offset, note.name, 128);
d->p->read (temp + d->note_xyz_offset, 3*sizeof (uint16_t), (uint8_t *) &note.x);
return true;
}
bool API::InitReadSettlements( uint32_t & numsettlements )
{
if(!d->InitReadNames()) return false;
try
{
memory_info * minfo = d->offset_descriptor;
int allSettlements = minfo->getAddress ("settlements");
int currentSettlement = minfo->getAddress("settlement_current");
d->settlement_name_offset = minfo->getOffset ("settlement_name");
d->settlement_world_xy_offset = minfo->getOffset ("settlement_world_xy");
d->settlement_local_xy_offset = minfo->getOffset ("settlement_local_xy");
d->p_settlements = new DfVector (d->p, allSettlements);
d->p_current_settlement = new DfVector(d->p, currentSettlement);
d->settlementsInited = true;
numsettlements = d->p_settlements->getSize();
return true;
}
catch (Error::MissingMemoryDefinition&)
{
d->settlementsInited = false;
numsettlements = 0;
throw;
}
}
bool API::ReadSettlement(const int32_t index, t_settlement & settlement)
{
if(!d->settlementsInited) return false;
if(!d->p_settlements->getSize()) return false;
// read pointer from vector at position
uint32_t temp = d->p_settlements->at (index);
settlement.origin = temp;
d->readName(settlement.name, temp + d->settlement_name_offset);
d->p->read(temp + d->settlement_world_xy_offset, 2 * sizeof(int16_t), (uint8_t *) &settlement.world_x);
d->p->read(temp + d->settlement_local_xy_offset, 4 * sizeof(int16_t), (uint8_t *) &settlement.local_x1);
return true;
}
bool API::ReadCurrentSettlement(t_settlement & settlement)
{
if(!d->settlementsInited) return false;
if(!d->p_current_settlement->getSize()) return false;
uint32_t temp = d->p_current_settlement->at(0);
settlement.origin = temp;
d->readName(settlement.name, temp + d->settlement_name_offset);
d->p->read(temp + d->settlement_world_xy_offset, 2 * sizeof(int16_t), (uint8_t *) &settlement.world_x);
d->p->read(temp + d->settlement_local_xy_offset, 4 * sizeof(int16_t), (uint8_t *) &settlement.local_x1);
return true;
}
void API::FinishReadSettlements()
{
if(d->p_settlements)
{
delete d->p_settlements;
d->p_settlements = NULL;
}
if(d->p_current_settlement)
{
delete d->p_current_settlement;
d->p_current_settlement = NULL;
}
d->settlementsInited = false;
}
bool API::getItemIndexesInBox(vector<uint32_t> &indexes,
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->itemsInited) return false;
indexes.clear();
uint32_t size = d->p_itm->getSize();
struct temp2{
uint16_t coords[3];
uint32_t flags;
};
temp2 temp2;
for(uint32_t i =0;i<size;i++){
uint32_t temp = d->p_itm->at(i);
d->p->read(temp+sizeof(uint32_t),5 * sizeof(uint16_t), (uint8_t *) &temp2);
if(temp2.flags & (1 << 0)){
if (temp2.coords[0] >= x1 && temp2.coords[0] < x2)
{
if (temp2.coords[1] >= y1 && temp2.coords[1] < y2)
{
if (temp2.coords[2] >= z1 && temp2.coords[2] < z2)
{
indexes.push_back(i);
}
}
}
}
}
return true;
}
*/
/*
void API::FinishReadNotes()
{
if(d->p_notes)
{
delete d->p_notes;
d->p_notes = 0;
}
d->notesInited = false;
}
*/
/*
bool API::InitReadItems(uint32_t & numitems)
{
try
{
int items = d->offset_descriptor->getAddress ("items");
d->item_material_offset = d->offset_descriptor->getOffset ("item_materials");
d->p_itm = new DfVector (d->p, items);
d->itemsInited = true;
numitems = d->p_itm->getSize();
return true;
}
catch (Error::MissingMemoryDefinition&)
{
d->itemsInited = false;
numitems = 0;
throw;
}
}
bool API::ReadItem (const uint32_t index, t_item & item)
{
if (!d->itemsInited) return false;
t_item_df40d item_40d;
// read pointer from vector at position
uint32_t temp = d->p_itm->at (index);
//read building from memory
d->p->read (temp, sizeof (t_item_df40d), (uint8_t *) &item_40d);
// transform
int32_t type = -1;
d->offset_descriptor->resolveObjectToClassID (temp, type);
item.origin = temp;
item.vtable = item_40d.vtable;
item.x = item_40d.x;
item.y = item_40d.y;
item.z = item_40d.z;
item.type = type;
item.ID = item_40d.ID;
item.flags.whole = item_40d.flags;
//TODO certain item types (creature based, threads, seeds, bags do not have the first matType byte, instead they have the material index only located at 0x68
d->p->read (temp + d->item_material_offset, sizeof (t_matglossPair), (uint8_t *) &item.material);
//for(int i = 0; i < 0xCC; i++){ // used for item research
// uint8_t byte = MreadByte(temp+i);
// item.bytes.push_back(byte);
//}
return true;
}
void API::FinishReadItems()
{
if(d->p_itm)
{
delete d->p_itm;
d->p_itm = NULL;
}
d->itemsInited = false;
}
*/
/*
bool API::ReadItemTypes(vector< vector< t_itemType > > & itemTypes)
{
memory_info * minfo = d->offset_descriptor;
int matgloss_address = minfo->getAddress("matgloss");
int matgloss_skip = minfo->getHexValue("matgloss_skip");
int item_type_name_offset = minfo->getOffset("item_type_name");
for(int i = 8;i<20;i++)
{
DfVector p_temp (d->p, matgloss_address + i*matgloss_skip);
vector< t_itemType > typesForVec;
for(uint32_t j =0; j<p_temp.getSize();j++)
{
t_itemType currType;
uint32_t temp = *(uint32_t *) p_temp[j];
// Mread(temp+40,sizeof(name),(uint8_t *) name);
d->p->readSTLString(temp+4,currType.id,128);
d->p->readSTLString(temp+item_type_name_offset,currType.name,128);
//stringsForVec.push_back(string(name));
typesForVec.push_back(currType);
}
itemTypes.push_back(typesForVec);
}
return true;
}
*/

@ -44,7 +44,7 @@ extern "C" {
DFHackObject* API_Alloc(const char* path_to_xml)
{
DFHack::API* api = new DFHack::API(std::string(path_to_xml));
DFHack::ContextManager* api = new DFHack::ContextManager(std::string(path_to_xml));
return (DFHackObject*)api;
}
@ -54,7 +54,7 @@ void API_Free(DFHackObject* api)
{
if(api != NULL)
{
DFHack::API* a = (DFHack::API*)api;
DFHack::ContextManager* a = (DFHack::ContextManager*)api;
delete a;
api = NULL;
@ -65,7 +65,7 @@ int API_Attach(DFHackObject* api)
{
if(api != NULL)
{
return ((DFHack::API*)api)->Attach();
return ((DFHack::ContextManager*)api)->Attach();
}
return -1;
}
@ -74,7 +74,7 @@ int API_Detach(DFHackObject* api)
{
if(api != NULL)
{
return ((DFHack::API*)api)->Detach();
return ((DFHack::ContextManager*)api)->Detach();
}
return -1;
@ -84,7 +84,7 @@ int API_isAttached(DFHackObject* api)
{
if(api != NULL)
{
return ((DFHack::API*)api)->isAttached();
return ((DFHack::ContextManager*)api)->isAttached();
}
return -1;
@ -94,7 +94,7 @@ int API_Suspend(DFHackObject* api)
{
if(api != NULL)
{
return ((DFHack::API*)api)->Suspend();
return ((DFHack::ContextManager*)api)->Suspend();
}
return -1;
@ -104,7 +104,7 @@ int API_Resume(DFHackObject* api)
{
if(api != NULL)
{
return ((DFHack::API*)api)->Resume();
return ((DFHack::ContextManager*)api)->Resume();
}
return -1;
@ -114,7 +114,7 @@ int API_isSuspended(DFHackObject* api)
{
if(api != NULL)
{
return ((DFHack::API*)api)->isSuspended();
return ((DFHack::ContextManager*)api)->isSuspended();
}
return -1;
@ -124,7 +124,7 @@ int API_ForceResume(DFHackObject* api)
{
if(api != NULL)
{
return ((DFHack::API*)api)->ForceResume();
return ((DFHack::ContextManager*)api)->ForceResume();
}
return -1;
@ -134,7 +134,7 @@ int API_AsyncSuspend(DFHackObject* api)
{
if(api != NULL)
{
return ((DFHack::API*)api)->AsyncSuspend();
return ((DFHack::ContextManager*)api)->AsyncSuspend();
}
return -1;
@ -146,7 +146,7 @@ DFHackObject* API_getMemoryInfo(DFHackObject* api)
{
if(api != NULL)
{
return (DFHackObject*)((DFHack::API*)api)->getMemoryInfo();
return (DFHackObject*)((DFHack::ContextManager*)api)->getMemoryInfo();
}
return NULL;
@ -156,7 +156,7 @@ DFHackObject* API_getProcess(DFHackObject* api)
{
if(api != NULL)
{
return (DFHackObject*)((DFHack::API*)api)->getProcess();
return (DFHackObject*)((DFHack::ContextManager*)api)->getProcess();
}
return NULL;
@ -166,7 +166,7 @@ DFHackObject* API_getWindow(DFHackObject* api)
{
if(api != NULL)
{
return (DFHackObject*)((DFHack::API*)api)->getWindow();
return (DFHackObject*)((DFHack::ContextManager*)api)->getWindow();
}
return NULL;
@ -176,7 +176,7 @@ DFHackObject* API_getCreatures(DFHackObject* api)
{
if(api != NULL)
{
return (DFHackObject*)((DFHack::API*)api)->getCreatures();
return (DFHackObject*)((DFHack::ContextManager*)api)->getCreatures();
}
return NULL;
@ -186,7 +186,7 @@ DFHackObject* API_getMaps(DFHackObject* api)
{
if(api != NULL)
{
return (DFHackObject*)((DFHack::API*)api)->getMaps();
return (DFHackObject*)((DFHack::ContextManager*)api)->getMaps();
}
return NULL;
@ -196,7 +196,7 @@ DFHackObject* API_getGui(DFHackObject* api)
{
if(api != NULL)
{
return (DFHackObject*)((DFHack::API*)api)->getGui();
return (DFHackObject*)((DFHack::ContextManager*)api)->getGui();
}
return NULL;
@ -206,7 +206,7 @@ DFHackObject* API_getPosition(DFHackObject* api)
{
if(api != NULL)
{
return (DFHackObject*)((DFHack::API*)api)->getPosition();
return (DFHackObject*)((DFHack::ContextManager*)api)->getPosition();
}
return NULL;
@ -216,7 +216,7 @@ DFHackObject* API_getMaterials(DFHackObject* api)
{
if(api != NULL)
{
return (DFHackObject*)((DFHack::API*)api)->getMaterials();
return (DFHackObject*)((DFHack::ContextManager*)api)->getMaterials();
}
return NULL;
@ -226,7 +226,7 @@ DFHackObject* API_getTranslation(DFHackObject* api)
{
if(api != NULL)
{
return (DFHackObject*)((DFHack::API*)api)->getTranslation();
return (DFHackObject*)((DFHack::ContextManager*)api)->getTranslation();
}
return NULL;
@ -236,7 +236,7 @@ DFHackObject* API_getVegetation(DFHackObject* api)
{
if(api != NULL)
{
return (DFHackObject*)((DFHack::API*)api)->getVegetation();
return (DFHackObject*)((DFHack::ContextManager*)api)->getVegetation();
}
return NULL;
@ -246,7 +246,7 @@ DFHackObject* API_getBuildings(DFHackObject* api)
{
if(api != NULL)
{
return (DFHackObject*)((DFHack::API*)api)->getBuildings();
return (DFHackObject*)((DFHack::ContextManager*)api)->getBuildings();
}
return NULL;
@ -256,7 +256,7 @@ DFHackObject* API_getConstructions(DFHackObject* api)
{
if(api != NULL)
{
return (DFHackObject*)((DFHack::API*)api)->getConstructions();
return (DFHackObject*)((DFHack::ContextManager*)api)->getConstructions();
}
return NULL;
@ -266,7 +266,7 @@ DFHackObject* API_getItems(DFHackObject* api)
{
if(api != NULL)
{
return (DFHackObject*)((DFHack::API*)api)->getItems();
return (DFHackObject*)((DFHack::ContextManager*)api)->getItems();
}
return NULL;
@ -276,7 +276,7 @@ void API_ReadRaw(DFHackObject* api, const uint32_t offset, const uint32_t size,
{
if(api != NULL)
{
((DFHack::API*)api)->ReadRaw(offset, size, target);
((DFHack::ContextManager*)api)->ReadRaw(offset, size, target);
}
}
@ -284,7 +284,7 @@ void API_WriteRaw(DFHackObject* api, const uint32_t offset, const uint32_t size,
{
if(api != NULL)
{
((DFHack::API*)api)->WriteRaw(offset, size, source);
((DFHack::ContextManager*)api)->WriteRaw(offset, size, source);
}
}

@ -377,7 +377,7 @@ void NormalProcess::read (const uint32_t offset, const uint32_t size, uint8_t *t
}
else
{
read(offset + result, size - result, target + result);
this->read(offset + result, size - result, target + result);
}
}
}

@ -1,187 +0,0 @@
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#ifndef SIMPLEAPI_H_INCLUDED
#define SIMPLEAPI_H_INCLUDED
#include "Tranquility.h"
#include "Export.h"
#include <string>
#include <vector>
#include <map>
#include "integers.h"
#include "DFTileTypes.h"
#include "DFTypes.h"
#include "DFWindow.h"
namespace DFHack
{
class APIPrivate;
class memory_info;
class Process;
// modules
class Maps;
class Creatures;
class Position;
class Gui;
class World;
class Materials;
class Translation;
class Vegetation;
class Buildings;
class Constructions;
class Items;
class DFHACK_EXPORT API
{
APIPrivate * const d;
public:
API(const std::string path_to_xml);
~API();
/*
* Basic control over DF's process state
*/
bool Attach();
bool Detach();
bool isAttached();
/// stop DF from executing
bool Suspend();
bool isSuspended();
/// stop DF from executing, asynchronous, use with polling
bool AsyncSuspend();
/// resume DF
bool Resume();
/// forces resume on Windows. This can be a bad thing with multiple DF tools running!
bool ForceResume();
memory_info *getMemoryInfo();
Process * getProcess();
DFWindow * getWindow();
/// read/write size bytes of raw data at offset. DANGEROUS, CAN SEGFAULT DF!
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);
// get the creatures module
Creatures * getCreatures();
// get the maps module
Maps * getMaps();
// get the gui module
Gui * getGui();
// get the world module
World * getWorld();
// get the position module
Position * getPosition();
// get the materials module
Materials * getMaterials();
// get the items module
Items * getItems();
// get the translation module
Translation * getTranslation();
// get the vegetation module
Vegetation * getVegetation();
// get the buildings module
Buildings * getBuildings();
// get the constructions module
Constructions * getConstructions();
/*
* Effects like mist, dragonfire or dust
*/
/*
bool InitReadEffects ( uint32_t & numeffects );
bool ReadEffect(const uint32_t index, t_effect_df40d & effect);
bool WriteEffect(const uint32_t index, const t_effect_df40d & effect);
void FinishReadEffects();
*/
/*
* Trees and shrubs
*/
/*
bool InitReadVegetation( uint32_t & numplants );
bool ReadVegetation(const int32_t index, t_tree_desc & shrubbery);
void FinishReadVegetation();
*/
/*
* Notes placed by the player
*/
/*
/// start reading notes. numnotes is an output - total notes present
bool InitReadNotes( uint32_t & numnotes );
/// read note from the note vector at index
bool ReadNote(const int32_t index, t_note & note);
/// free the note vector
void FinishReadNotes();
*/
/*
* Settlements
*/
/*
bool InitReadSettlements( uint32_t & numsettlements );
bool ReadSettlement(const int32_t index, t_settlement & settlement);
bool ReadCurrentSettlement(t_settlement & settlement);
void FinishReadSettlements();
*/
/*
* Item reading
*/
/*
bool InitReadItems(uint32_t & numitems);
bool getItemIndexesInBox(std::vector<uint32_t> &indexes,
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 ReadItem(const uint32_t index, t_item & item);
void FinishReadItems();
*/
/*
* Get the other API parts for raw access
*/
/*
// FIXME: BAD!
bool ReadAllMatgloss(vector< vector< string > > & all);
*/
//bool ReadItemTypes(std::vector< std::vector< t_itemType > > & itemTypes);
};
} // namespace DFHack
#endif // SIMPLEAPI_H_INCLUDED

@ -58,11 +58,10 @@ void DumpDWordVector (const char * name, DFHack::Process *p, uint32_t addr)
address = absolute address of dump start
length = length in lines. 1 line = 16 bytes
*/
void hexdump (DFHack::API& DF, uint32_t address, uint32_t length)
void hexdump (DFHack::Context *DF, uint32_t address, uint32_t length)
{
char *buf = new char[length * 16];
DF.ReadRaw(address, length * 16, (uint8_t *) buf);
DF->ReadRaw(address, length * 16, (uint8_t *) buf);
for (uint32_t i = 0; i < length; i++)
{
// leading offset
@ -74,7 +73,6 @@ void hexdump (DFHack::API& DF, uint32_t address, uint32_t length)
for(int k = 0; k < 4; k++)
{
int idx = i * 16 + j * 4 + k;
cout << hex << setw(2) << int(static_cast<unsigned char>(buf[idx])) << " ";
}
cout << " ";
@ -84,14 +82,14 @@ void hexdump (DFHack::API& DF, uint32_t address, uint32_t length)
delete buf;
}
void interleave_hex (DFHack::API& DF, vector < uint32_t > & addresses, uint32_t length)
void interleave_hex (DFHack::Context* DF, vector < uint32_t > & addresses, uint32_t length)
{
vector <char * > bufs;
for(uint32_t counter = 0; counter < addresses.size(); counter ++)
{
char * buf = new char[length * 16];
DF.ReadRaw(addresses[counter], length * 16, (uint8_t *) buf);
DF->ReadRaw(addresses[counter], length * 16, (uint8_t *) buf);
bufs.push_back(buf);
}
cout << setfill('0');

@ -25,11 +25,11 @@ namespace DFHack
// FIXME: not complete, we need building presence bitmaps for stuff like farm plots and stockpiles, orientation (N,E,S,W) and state (open/closed)
};
class APIPrivate;
class DFContextPrivate;
class DFHACK_EXPORT Buildings
{
public:
Buildings(APIPrivate * d);
Buildings(DFContextPrivate * d);
~Buildings();
bool Start(uint32_t & numBuildings);
// read one building at offset

@ -39,11 +39,11 @@ namespace DFHack
uint32_t origin;
};
#pragma pack (pop)
class APIPrivate;
class DFContextPrivate;
class DFHACK_EXPORT Constructions
{
public:
Constructions(APIPrivate * d);
Constructions(DFContextPrivate * d);
~Constructions();
bool Start(uint32_t & numConstructions);
bool Read (const uint32_t index, t_construction & constr);

@ -353,12 +353,12 @@ namespace DFHack
uint32_t birth_time;
};
class APIPrivate;
class DFContextPrivate;
struct t_creature;
class DFHACK_EXPORT Creatures
{
public:
Creatures(DFHack::APIPrivate * d);
Creatures(DFHack::DFContextPrivate * d);
~Creatures();
bool Start( uint32_t & numCreatures);
bool Finish();

@ -8,13 +8,13 @@
namespace DFHack
{
class APIPrivate;
class DFContextPrivate;
struct t_viewscreen;
class DFHACK_EXPORT Gui
{
public:
Gui(DFHack::APIPrivate * d);
Gui(DFHack::DFContextPrivate * d);
~Gui();
bool Start();
bool Finish();

@ -7,6 +7,10 @@
namespace DFHack
{
class Context;
class DFContextPrivate;
enum accessor_type {ACCESSOR_CONSTANT, ACCESSOR_INDIRECT, ACCESSOR_DOUBLE_INDIRECT};
/* this is used to store data about the way accessors work */
@ -73,7 +77,7 @@ public:
class DFHACK_EXPORT Items
{
public:
Items(DFHack::APIPrivate * _d);
Items(DFContextPrivate * _d);
~Items();
std::string getItemDescription(uint32_t itemptr, Materials * Materials);
std::string getItemClass(int32_t index);

@ -255,13 +255,13 @@ namespace DFHack
C L I E N T M O D U L E
***************************************************************************/
class APIPrivate;
class DFContextPrivate;
struct t_viewscreen;
class DFHACK_EXPORT Maps
{
public:
Maps(DFHack::APIPrivate * d);
Maps(DFHack::DFContextPrivate * d);
~Maps();
bool Start();
bool Finish();
@ -303,7 +303,6 @@ namespace DFHack
std::map <uint32_t, t_feature> local_feature_store;
// map between mangled coords and pointer to feature
bool ReadGlobalFeatures( std::vector <t_feature> & features);
bool ReadLocalFeatures( std::map <planecoord, std::vector<t_feature *> > & local_features );
/*

@ -6,7 +6,7 @@
#include "Export.h"
namespace DFHack
{
class APIPrivate;
class DFContextPrivate;
struct t_matgloss
{
@ -119,7 +119,7 @@ namespace DFHack
class DFHACK_EXPORT Materials
{
public:
Materials(DFHack::APIPrivate * _d);
Materials(DFHack::DFContextPrivate * _d);
~Materials();
std::vector<t_matgloss> inorganic;

@ -16,12 +16,12 @@ namespace DFHack
int32_t z;
};
class APIPrivate;
class DFContextPrivate;
class DFHACK_EXPORT Position
{
public:
Position(APIPrivate * d);
Position(DFContextPrivate * d);
~Position();
/*
* Cursor and window coords

@ -6,7 +6,7 @@
#include "Export.h"
namespace DFHack
{
class APIPrivate;
class DFContextPrivate;
typedef std::vector< std::vector<std::string> > DFDict;
typedef struct
{
@ -17,7 +17,7 @@ namespace DFHack
class DFHACK_EXPORT Translation
{
public:
Translation(APIPrivate * d);
Translation(DFContextPrivate * d);
~Translation();
bool Start();
bool Finish();

@ -27,11 +27,11 @@ namespace DFHack
uint32_t address;
};
class APIPrivate;
class DFContextPrivate;
class DFHACK_EXPORT Vegetation
{
public:
Vegetation(APIPrivate * d);
Vegetation(DFContextPrivate * d);
~Vegetation();
bool Start(uint32_t & numTrees);
bool Read (const uint32_t index, t_tree & shrubbery);

@ -8,12 +8,12 @@
namespace DFHack
{
class APIPrivate;
class DFContextPrivate;
class DFHACK_EXPORT World
{
public:
World(DFHack::APIPrivate * d);
World(DFHack::DFContextPrivate * d);
~World();
bool Start();
bool Finish();

@ -58,13 +58,13 @@ struct Buildings::Private
uint32_t custom_workshop_name;
int32_t custom_workshop_id;
DfVector <uint32_t> * p_bld;
APIPrivate *d;
DFContextPrivate *d;
Process * owner;
bool Inited;
bool Started;
};
Buildings::Buildings(APIPrivate * d_)
Buildings::Buildings(DFContextPrivate * d_)
{
d = new Private;
d->d = d_;

@ -39,13 +39,13 @@ struct Constructions::Private
// translation
DfVector <uint32_t> * p_cons;
APIPrivate *d;
DFContextPrivate *d;
Process * owner;
bool Inited;
bool Started;
};
Constructions::Constructions(APIPrivate * d_)
Constructions::Constructions(DFContextPrivate * d_)
{
d = new Private;
d->d = d_;

@ -55,11 +55,11 @@ struct Creatures::Private
uint32_t dwarf_race_index_addr;
uint32_t dwarf_civ_id_addr;
DfVector <uint32_t> *p_cre;
APIPrivate *d;
DFContextPrivate *d;
Process *owner;
};
Creatures::Creatures(APIPrivate* _d)
Creatures::Creatures(DFContextPrivate* _d)
{
d = new Private;
d->d = _d;

@ -39,11 +39,11 @@ struct Gui::Private
uint32_t view_screen_offset;
uint32_t current_cursor_creature_offset;
uint32_t current_menu_state_offset;
APIPrivate *d;
DFContextPrivate *d;
Process * owner;
};
Gui::Gui(APIPrivate * _d)
Gui::Gui(DFContextPrivate * _d)
{
d = new Private;

@ -36,7 +36,7 @@ using namespace DFHack;
class Items::Private
{
public:
APIPrivate *d;
DFContextPrivate *d;
Process * owner;
/*
bool Inited;
@ -44,7 +44,7 @@ class Items::Private
*/
};
Items::Items(APIPrivate * d_)
Items::Items(DFContextPrivate * d_)
{
d = new Private;
d->d = d_;

@ -50,7 +50,7 @@ struct Maps::Private
uint32_t maps_module;
Server::Maps::maps_offsets offsets;
APIPrivate *d;
DFContextPrivate *d;
Process * owner;
bool Inited;
bool Started;
@ -61,7 +61,7 @@ struct Maps::Private
vector<uint16_t> v_geology[eBiomeCount];
};
Maps::Maps(APIPrivate* _d)
Maps::Maps(DFContextPrivate* _d)
{
d = new Private;
d->d = _d;

@ -35,7 +35,7 @@ using namespace DFHack;
class Materials::Private
{
public:
APIPrivate *d;
DFContextPrivate *d;
Process * owner;
/*
bool Inited;
@ -43,7 +43,7 @@ class Materials::Private
*/
};
Materials::Materials(APIPrivate * d_)
Materials::Materials(DFContextPrivate * d_)
{
d = new Private;
d->d = d_;

@ -45,7 +45,7 @@ struct Position::Private
uint32_t hotkey_xyz_offset;
uint32_t hotkey_size;
APIPrivate *d;
DFContextPrivate *d;
Process * owner;
bool Inited;
bool Started;
@ -54,7 +54,7 @@ struct Position::Private
//vector<uint16_t> v_geology[eBiomeCount];
};
Position::Position(APIPrivate * d_)
Position::Position(DFContextPrivate * d_)
{
d = new Private;
d->d = d_;

@ -43,12 +43,12 @@ struct Translation::Private
// translation
Dicts dicts;
APIPrivate *d;
DFContextPrivate *d;
bool Inited;
bool Started;
};
Translation::Translation(APIPrivate * d_)
Translation::Translation(DFContextPrivate * d_)
{
d = new Private;
d->d = d_;

@ -40,13 +40,13 @@ struct Vegetation::Private
// translation
DfVector <uint32_t> * p_veg;
APIPrivate *d;
DFContextPrivate *d;
Process * owner;
bool Inited;
bool Started;
};
Vegetation::Vegetation(APIPrivate * d_)
Vegetation::Vegetation(DFContextPrivate * d_)
{
d = new Private;
d->owner = d_->p;

@ -49,11 +49,11 @@ struct World::Private
bool Started;
uint32_t year_offset;
uint32_t tick_offset;
APIPrivate *d;
DFContextPrivate *d;
Process * owner;
};
World::World(APIPrivate * _d)
World::World(DFContextPrivate * _d)
{
d = new Private;

@ -46,11 +46,11 @@ namespace DFHack
class Constructions;
class memory_info;
struct t_name;
class APIPrivate
class DFContextPrivate
{
public:
APIPrivate();
~APIPrivate();
DFContextPrivate();
~DFContextPrivate();
// names, used by a few other modules.
void readName(t_name & name, uint32_t address);

@ -68,7 +68,7 @@ struct DF_API
PyObject* vegetation_type;
PyObject* gui_type;
DFHack::API* api_Ptr;
DFHack::ContextManager* api_Ptr;
};
// API type Allocation, Deallocation, and Initialization
@ -110,7 +110,7 @@ static int DF_API_init(DF_API* self, PyObject* args, PyObject* kwds)
return -1;
if(memFileString)
self->api_Ptr = new DFHack::API(std::string(memFileString));
self->api_Ptr = new DFHack::ContextManager(std::string(memFileString));
else
return -1;
}

@ -8,18 +8,21 @@
#include <ctime>
using namespace std;
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFContextManager.h>
#include <DFContext.h>
#include <DFError.h>
int main (void)
{
time_t start, end;
double time_diff;
DFHack::API DF("Memory.xml");
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context* DF;
try
{
DF.Attach();
DF.Detach();
DF = DFMgr.getSingleContext();
DF->Attach();
DF->Detach();
}
catch (exception& e)
{
@ -67,17 +70,17 @@ int main (void)
cout << "attach tests done in " << time_diff << " seconds." << endl;
*/
cout << "Testing suspend/resume" << endl;
DF.Attach();
DF->Attach();
time(&start);
for (int i = 0; i < 1000; i++)
{
DF.Suspend();
DF->Suspend();
if(i%10 == 0)
cout << i / 10 << "%" << endl;
DF.Resume();
DF->Resume();
}
time(&end);
DF.Detach();
DF->Detach();
time_diff = difftime(end, start);
cout << "suspend tests done in " << time_diff << " seconds." << endl;

@ -11,7 +11,8 @@ using namespace std;
#include <DFGlobal.h>
#include <DFError.h>
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFContextManager.h>
#include <DFContext.h>
#include <DFMemInfo.h>
#include <DFProcess.h>
#include <DFTypes.h>
@ -47,10 +48,12 @@ int main (int argc,const char* argv[])
map <uint32_t, string> custom_workshop_types;
DFHack::API DF ("Memory.xml");
DFHack::ContextManager DFMgr ("Memory.xml");
DFHack::Context *DF;
try
{
DF.Attach();
DF = DFMgr.getSingleContext();
DF->Attach();
}
catch (exception& e)
{
@ -61,9 +64,9 @@ int main (int argc,const char* argv[])
return 1;
}
DFHack::memory_info * mem = DF.getMemoryInfo();
DFHack::Buildings * Bld = DF.getBuildings();
DFHack::Position * Pos = DF.getPosition();
DFHack::memory_info * mem = DF->getMemoryInfo();
DFHack::Buildings * Bld = DF->getBuildings();
DFHack::Position * Pos = DF->getPosition();
uint32_t numBuildings;
if(Bld->Start(numBuildings))
@ -107,7 +110,12 @@ int main (int argc,const char* argv[])
{
DFHack::t_building temp;
Bld->Read(i, temp);
if((uint32_t)x >= temp.x1 && (uint32_t)x <= temp.x2 && (uint32_t)y >= temp.y1 && (uint32_t)y <= temp.y2 && (uint32_t)z == temp.z)
if( (uint32_t)x >= temp.x1
&& (uint32_t)x <= temp.x2
&& (uint32_t)y >= temp.y1
&& (uint32_t)y <= temp.y2
&& (uint32_t)z == temp.z
)
{
string typestr;
mem->resolveClassIDToClassname(temp.type, typestr);
@ -142,7 +150,7 @@ int main (int argc,const char* argv[])
cerr << "buildings not supported for this DF version" << endl;
}
DF.Detach();
DF->Detach();
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;
cin.ignore();

@ -17,7 +17,8 @@ using namespace std;
#include <DFError.h>
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFContextManager.h>
#include <DFContext.h>
#include <DFMemInfo.h>
#include <DFProcess.h>
#include <argstream.h>
@ -68,10 +69,12 @@ int main ( int argc, char** argv )
s_creatures.push_back("CAT");
}
DFHack::API DF("Memory.xml");
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context *DF;
try
{
DF.Attach();
DF = DFMgr.getSingleContext();
DF->Attach();
}
catch (exception& e)
{
@ -82,10 +85,10 @@ int main ( int argc, char** argv )
return 1;
}
proc = DF.getProcess();
mem = DF.getMemoryInfo();
DFHack::Materials *Mats = DF.getMaterials();
DFHack::Creatures *Cre = DF.getCreatures();
proc = DF->getProcess();
mem = DF->getMemoryInfo();
DFHack::Materials *Mats = DF->getMaterials();
DFHack::Creatures *Cre = DF->getCreatures();
creature_pregnancy_offset = mem->getOffset("creature_pregnancy");
if(!Mats->ReadCreatureTypesEx())
@ -168,7 +171,7 @@ int main ( int argc, char** argv )
cout << totalchanged << " pregnancies accelerated. Total creatures checked: " << totalcount << "." << endl;
Cre->Finish();
DF.Detach();
DF->Detach();
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;
cin.ignore();

@ -12,7 +12,8 @@ using namespace std;
#include <DFGlobal.h>
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFContextManager.h>
#include <DFContext.h>
#include <DFProcess.h>
#include <DFMemInfo.h>
#include <DFTypes.h>
@ -25,10 +26,12 @@ using namespace DFHack;
int main (int numargs, const char ** args)
{
DFHack::API DF("Memory.xml");
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context* DF;
try
{
DF.Attach();
DF = DFMgr.getSingleContext();
DF->Attach();
}
catch (exception& e)
{
@ -39,10 +42,10 @@ int main (int numargs, const char ** args)
return 1;
}
DFHack::Position *Pos = DF.getPosition();
DFHack::Position *Pos = DF->getPosition();
DFHack::Constructions *Cons = DF.getConstructions();
DFHack::Materials *Mats = DF.getMaterials();
DFHack::Constructions *Cons = DF->getConstructions();
DFHack::Materials *Mats = DF->getMaterials();
Mats->ReadInorganicMaterials();
uint32_t numConstr;
Cons->Start(numConstr);

@ -10,7 +10,8 @@ using namespace std;
#include <DFGlobal.h>
#include <DFError.h>
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFContextManager.h>
#include <DFContext.h>
#include <DFMemInfo.h>
#include <DFProcess.h>
#include <modules/Materials.h>
@ -140,7 +141,7 @@ likeType printLike40d(DFHack::t_like like, const matGlosses & mat,const vector<
}
*/
void printCreature(DFHack::API & DF, const DFHack::t_creature & creature)
void printCreature(DFHack::Context * DF, const DFHack::t_creature & creature)
{
uint32_t dayoflife;
cout << "address: " << hex << creature.origin << dec << " creature type: " << Materials->raceEx[creature.race].rawname
@ -162,8 +163,8 @@ void printCreature(DFHack::API & DF, const DFHack::t_creature & creature)
addendl = true;
}
DFHack::Translation *Tran = DF.getTranslation();
DFHack::memory_info *mem = DF.getMemoryInfo();
DFHack::Translation *Tran = DF->getTranslation();
DFHack::memory_info *mem = DF->getMemoryInfo();
string transName = Tran->TranslateName(creature.name,false);
if(!transName.empty())
@ -398,10 +399,12 @@ void printCreature(DFHack::API & DF, const DFHack::t_creature & creature)
int main (int numargs, char ** args)
{
DFHack::World * World;
DFHack::API DF("Memory.xml");
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context* DF;
try
{
DF.Attach();
DF = DFMgr.getSingleContext();
DF->Attach();
}
catch (exception& e)
{
@ -415,12 +418,12 @@ int main (int numargs, char ** args)
if(numargs == 2)
check = args[1];
Creatures = DF.getCreatures();
Materials = DF.getMaterials();
World = DF.getWorld();
Creatures = DF->getCreatures();
Materials = DF->getMaterials();
World = DF->getWorld();
current_year = World->ReadCurrentYear();
current_tick = World->ReadCurrentTick();
DFHack::Translation * Tran = DF.getTranslation();
DFHack::Translation * Tran = DF->getTranslation();
uint32_t numCreatures;
if(!Creatures->Start(numCreatures))
@ -440,7 +443,7 @@ int main (int numargs, char ** args)
return 1;
}
mem = DF.getMemoryInfo();
mem = DF->getMemoryInfo();
Materials->ReadAllMaterials();
if(!Tran->Start())
@ -476,7 +479,7 @@ int main (int numargs, char ** args)
printCreature(DF,currentCreature);
*/
Creatures->Finish();
DF.Detach();
DF->Detach();
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;
cin.ignore();

@ -13,7 +13,8 @@ using namespace std;
#include <DFError.h>
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFContextManager.h>
#include <DFContext.h>
#include <DFMemInfo.h>
#include <DFProcess.h>
#include <DFVector.h>
@ -26,13 +27,14 @@ DFHack::Items * Items;
int main ()
{
DFHack::API DF("Memory.xml");
DFHack::Process * p;
unsigned int i,j;
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context * DF;
try
{
DF.Attach();
DF = DFMgr.getSingleContext();
DF->Attach();
}
catch (exception& e)
{
@ -43,13 +45,13 @@ int main ()
return 1;
}
DFHack::memory_info * mem = DF.getMemoryInfo();
Materials = DF.getMaterials();
DFHack::memory_info * mem = DF->getMemoryInfo();
Materials = DF->getMaterials();
Materials->ReadAllMaterials();
p = DF.getProcess();
p = DF->getProcess();
DFHack::DfVector <uint32_t> p_items (p, p->getDescriptor()->getAddress ("items_vector"));
uint32_t size = p_items.size();
Items = DF.getItems();
Items = DF->getItems();
printf("type\tvtable\tname\tquality\tdecorate\n");

@ -10,7 +10,8 @@
using namespace std;
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFContextManager.h>
#include <DFContext.h>
#include <modules/Maps.h>
void print_progress (int current, int total)
@ -50,11 +51,13 @@ int main (int numargs, char** args)
uint64_t bytes_read = 0;
DFHack::mapblock40d Block;
DFHack::Maps *Maps = 0;
DFHack::API DF("Memory.xml");
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context *DF;
try
{
DF.Attach();
Maps = DF.getMaps();
DF = DFMgr.getSingleContext();
DF->Attach();
Maps = DF->getMaps();
}
catch (exception& e)
{
@ -92,7 +95,7 @@ int main (int numargs, char** args)
}
Maps->Finish();
}
DF.Detach();
DF->Detach();
time(&end);
time_diff = difftime(end, start);
cout << num_blocks << " blocks read" << endl;

@ -45,7 +45,7 @@ uint32_t endian_swap(uint32_t x)
int main (void)
{
DFHack::API DF("Memory.xml");
DFHack::ContextManager DF("Memory.xml");
try
{
DF.Attach();

@ -6,7 +6,8 @@
using namespace std;
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFContextManager.h>
#include <DFContext.h>
#include <modules/Maps.h>
int main (void)
@ -14,10 +15,14 @@ int main (void)
uint32_t x_max,y_max,z_max;
DFHack::designations40d designations;
DFHack::API DF("Memory.xml");
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context * DF;
DFHack::Maps *Maps;
try
{
DF.Attach();
DF = DFMgr.getSingleContext();
DF->Attach();
Maps = DF->getMaps();
}
catch (exception& e)
{
@ -27,8 +32,6 @@ int main (void)
#endif
return 1;
}
DFHack::Maps *Maps =DF.getMaps();
// init the map
if(!Maps->Start())
{

@ -7,17 +7,20 @@
using namespace std;
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFContextManager.h>
#include <DFContext.h>
#include <DFMemInfo.h>
#include <modules/Position.h>
int main (void)
{
DFHack::API DF("Memory.xml");
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context * DF;
try
{
DF.Attach();
DF = DFMgr.getSingleContext();
DF->Attach();
}
catch (exception& e)
{
@ -28,8 +31,8 @@ int main (void)
return 1;
}
DFHack::memory_info * mem = DF.getMemoryInfo();
DFHack::Position * Pos = DF.getPosition();
DFHack::memory_info * mem = DF->getMemoryInfo();
DFHack::Position * Pos = DF->getPosition();
// get stone matgloss mapping
/*
uint32_t numNotes;
@ -59,7 +62,7 @@ int main (void)
"\ttext: " << hotkeys[i].name << endl;
}
//DF.FinishReadNotes();
DF.Detach();
DF->Detach();
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;
cin.ignore();

@ -10,7 +10,8 @@ using namespace std;
#include <DFGlobal.h>
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFContextManager.h>
#include <DFContext.h>
#include <DFProcess.h>
#include <DFMemInfo.h>
#include <DFVector.h>
@ -24,10 +25,13 @@ int main (int numargs, const char ** args)
istringstream input (args[1],istringstream::in);
input >> std::hex >> addr;
}
DFHack::API DF("Memory.xml");
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context * DF;
try
{
DF.Attach();
DF = DFMgr.getSingleContext();
DF->Attach();
}
catch (exception& e)
{
@ -38,9 +42,9 @@ int main (int numargs, const char ** args)
return 1;
}
DFHack::Process* p = DF.getProcess();
DFHack::memory_info* mem = DF.getMemoryInfo();
DFHack::Materials *Materials = DF.getMaterials();
DFHack::Process* p = DF->getProcess();
DFHack::memory_info* mem = DF->getMemoryInfo();
DFHack::Materials *Materials = DF->getMaterials();
cout << "----==== Inorganic ====----" << endl;
Materials->ReadInorganicMaterials ();

@ -8,17 +8,20 @@
using namespace std;
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFContextManager.h>
#include <DFContext.h>
#include <modules/Position.h>
int main (void)
{
DFHack::API DF("Memory.xml");
DFHack::Position * Position = 0;
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context * DF;
try
{
DF.Attach();
Position = DF.getPosition();
DF = DFMgr.getSingleContext();
DF->Attach();
Position = DF->getPosition();
}
catch (exception& e)
{
@ -45,7 +48,7 @@ int main (void)
cerr << "cursor and window parameters are unsupported on your version of DF" << endl;
}
if(!DF.Detach())
if(!DF->Detach())
{
cerr << "Can't detach from DF" << endl;
}

@ -22,7 +22,7 @@ vector< vector<string> > foreignWords;
uint32_t numCreatures;
vector<DFHack::t_matgloss> creaturestypes;
void printDwarves(DFHack::API & DF)
void printDwarves(DFHack::ContextManager & DF)
{
int dwarfCounter = 0;
DFHack::Creatures * c = DF.getCreatures();
@ -57,7 +57,7 @@ void printDwarves(DFHack::API & DF)
}
}
bool getDwarfSelection(DFHack::API & DF, DFHack::t_creature & toChange,string & changeString, string & commandString,int & eraseAmount,int &dwarfNum,bool &isName)
bool getDwarfSelection(DFHack::ContextManager & DF, DFHack::t_creature & toChange,string & changeString, string & commandString,int & eraseAmount,int &dwarfNum,bool &isName)
{
static string lastText;
bool dwarfSuccess = false;
@ -142,7 +142,7 @@ bool getDwarfSelection(DFHack::API & DF, DFHack::t_creature & toChange,string &
return true;
}
bool waitTillChanged(DFHack::API &DF, int creatureToCheck, string changeValue, bool isName)
bool waitTillChanged(DFHack::ContextManager &DF, int creatureToCheck, string changeValue, bool isName)
{
DFHack::DFWindow * w = DF.getWindow();
DF.Suspend();
@ -181,7 +181,7 @@ bool waitTillChanged(DFHack::API &DF, int creatureToCheck, string changeValue, b
}
bool waitTillScreenState(DFHack::API &DF, string screenState,bool EqualTo=true)
bool waitTillScreenState(DFHack::ContextManager &DF, string screenState,bool EqualTo=true)
{
DFHack::DFWindow * w = DF.getWindow();
DFHack::t_viewscreen current;
@ -207,7 +207,7 @@ bool waitTillScreenState(DFHack::API &DF, string screenState,bool EqualTo=true)
}
bool waitTillCursorState(DFHack::API &DF, bool On)
bool waitTillCursorState(DFHack::ContextManager &DF, bool On)
{
DFHack::DFWindow * w = DF.getWindow();
int32_t x,y,z;
@ -232,7 +232,7 @@ bool waitTillCursorState(DFHack::API &DF, bool On)
}
bool waitTillMenuState(DFHack::API &DF, uint32_t menuState,bool EqualTo=true)
bool waitTillMenuState(DFHack::ContextManager &DF, uint32_t menuState,bool EqualTo=true)
{
int tryCount = 0;
DFHack::DFWindow * w = DF.getWindow();
@ -256,7 +256,7 @@ bool waitTillMenuState(DFHack::API &DF, uint32_t menuState,bool EqualTo=true)
}
bool moveToBaseWindow(DFHack::API &DF)
bool moveToBaseWindow(DFHack::ContextManager &DF)
{
DFHack::DFWindow * w = DF.getWindow();
DFHack::t_viewscreen current;
@ -283,7 +283,7 @@ bool moveToBaseWindow(DFHack::API &DF)
}
bool setCursorToCreature(DFHack::API &DF)
bool setCursorToCreature(DFHack::ContextManager &DF)
{
DFHack::DFWindow * w = DF.getWindow();
int32_t x,y,z;
@ -306,7 +306,7 @@ bool setCursorToCreature(DFHack::API &DF)
int main (void)
{
DFHack::API DF("Memory.xml");
DFHack::ContextManager DF("Memory.xml");
DFHack::Creatures *c;
DFHack::Materials *m;
try

@ -11,7 +11,7 @@ using namespace std;
#include <stdio.h>
void printSettlement(DFHack::API & DF, const DFHack::t_settlement & settlement, const vector< vector<string> > &englishWords, const vector< vector<string> > &foreignWords)
void printSettlement(DFHack::ContextManager & DF, const DFHack::t_settlement & settlement, const vector< vector<string> > &englishWords, const vector< vector<string> > &foreignWords)
{
cout << "First name: " << settlement.name.first_name << endl << "Nickname: " << settlement.name.nickname << endl;
cout << settlement.name.words[0] << " " << settlement.name.words[1] << " " << settlement.name.words[2] << " "
@ -31,7 +31,7 @@ void printSettlement(DFHack::API & DF, const DFHack::t_settlement & settlement,
int main (int argc,const char* argv[])
{
DFHack::API DF("Memory.xml");
DFHack::ContextManager DF("Memory.xml");
try
{
DF.Attach();

@ -12,7 +12,8 @@ using namespace std;
#include <DFGlobal.h>
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFContextManager.h>
#include <DFContext.h>
#include <DFProcess.h>
#include <DFMemInfo.h>
#include <DFVector.h>
@ -83,10 +84,12 @@ int main (int numargs, const char ** args)
vector<t_frozenliquidvein> IceVeinVector;
vector<t_spattervein> splatter;
DFHack::API DF("Memory.xml");
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context * DF;
try
{
DF.Attach();
DF = DFMgr.getSingleContext();
DF->Attach();
}
catch (exception& e)
{
@ -97,9 +100,9 @@ int main (int numargs, const char ** args)
return 1;
}
DFHack::Maps *Maps =DF.getMaps();
DFHack::Position *Pos =DF.getPosition();
DFHack::Materials *Mats =DF.getMaterials();
DFHack::Maps *Maps =DF->getMaps();
DFHack::Position *Pos =DF->getPosition();
DFHack::Materials *Mats =DF->getMaterials();
Mats->ReadCreatureTypes();

@ -9,15 +9,17 @@
using namespace std;
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFContextManager.h>
#include <DFContext.h>
int main (void)
{
string blah;
DFHack::API DF("Memory.xml");
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context * DF;
try
{
DF.Attach();
DF = DFMgr.getSingleContext();
DF->Attach();
}
catch (exception& e)
{
@ -30,23 +32,23 @@ int main (void)
cout << "Attached, DF should be suspended now" << endl;
getline(cin, blah);
DF.Resume();
DF->Resume();
cout << "Resumed, DF should be running" << endl;
getline(cin, blah);
DF.Suspend();
DF->Suspend();
cout << "Suspended, DF should be suspended now" << endl;
getline(cin, blah);
DF.Resume();
DF->Resume();
cout << "Resumed, testing ForceResume. Suspend using SysInternals Process Explorer" << endl;
getline(cin, blah);
DF.ForceResume();
DF->ForceResume();
cout << "ForceResumed. DF should be running." << endl;
getline(cin, blah);
if(!DF.Detach())
if(!DF->Detach())
{
cerr << "Can't detach from DF" << endl;
return 1;

@ -12,7 +12,8 @@ using namespace std;
#include <DFGlobal.h>
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFContextManager.h>
#include <DFContext.h>
#include <DFProcess.h>
#include <DFMemInfo.h>
#include <DFVector.h>
@ -30,10 +31,12 @@ int main (int numargs, const char ** args)
istringstream input (args[1],istringstream::in);
input >> std::hex >> addr;
}
DFHack::API DF("Memory.xml");
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context * DF;
try
{
DF.Attach();
DF = DFMgr.getSingleContext();
DF->Attach();
}
catch (exception& e)
{
@ -44,11 +47,11 @@ int main (int numargs, const char ** args)
return 1;
}
DFHack::Process* p = DF.getProcess();
DFHack::memory_info* mem = DF.getMemoryInfo();
DFHack::Position * pos = DF.getPosition();
DFHack::Vegetation * v = DF.getVegetation();
DFHack::Materials * mat = DF.getMaterials();
DFHack::Process* p = DF->getProcess();
DFHack::memory_info* mem = DF->getMemoryInfo();
DFHack::Position * pos = DF->getPosition();
DFHack::Vegetation * v = DF->getVegetation();
DFHack::Materials * mat = DF->getMaterials();
mat->ReadOrganicMaterials();
int32_t x,y,z;

@ -12,7 +12,8 @@ using namespace std;
#include <DFGlobal.h>
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFContextManager.h>
#include <DFContext.h>
#include <DFProcess.h>
#include <DFMemInfo.h>
#include <DFVector.h>
@ -94,10 +95,13 @@ LABEL_17:
*/
int main (int numargs, const char ** args)
{
DFHack::API DF("Memory.xml");
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context * DF;
try
{
DF.Attach();
DF = DFMgr.getSingleContext();
DF->Attach();
}
catch (exception& e)
{
@ -108,10 +112,10 @@ int main (int numargs, const char ** args)
return 1;
}
DFHack::Position *Pos = DF.getPosition();
DFHack::memory_info* mem = DF.getMemoryInfo();
DFHack::Maps *Maps = DF.getMaps();
DFHack::Process * p = DF.getProcess();
DFHack::Position *Pos = DF->getPosition();
DFHack::memory_info* mem = DF->getMemoryInfo();
DFHack::Maps *Maps = DF->getMaps();
DFHack::Process * p = DF->getProcess();
uint32_t designatus = mem->getOffset("map_data_designation");
uint32_t block_feature1 = mem->getOffset("map_data_feature_local");
uint32_t block_feature2 = mem->getOffset("map_data_feature_global");

@ -19,7 +19,8 @@ using namespace std;
#include <DFGlobal.h>
#include <DFTypes.h>
#include <DFTileTypes.h>
#include <DFHackAPI.h>
#include <DFContextManager.h>
#include <DFContext.h>
#include <DFProcess.h>
#include <DFMemInfo.h>
#include <modules/Maps.h>
@ -29,7 +30,7 @@ using namespace DFHack;
string error;
API * pDF = 0;
Context * pDF = 0;
struct t_tempz
@ -239,7 +240,7 @@ int pickColor(int tiletype)
address = absolute address of dump start
length = length in bytes
*/
void hexdump (DFHack::API& DF, uint32_t address, uint32_t length, int filenum)
void hexdump (DFHack::Context* DF, uint32_t address, uint32_t length, int filenum)
{
uint32_t reallength;
uint32_t lines;
@ -254,7 +255,7 @@ void hexdump (DFHack::API& DF, uint32_t address, uint32_t length, int filenum)
myfile.open (name.c_str());
DF.ReadRaw(address, reallength, (uint8_t *) buf);
DF->ReadRaw(address, reallength, (uint8_t *) buf);
for (int i = 0; i < lines; i++)
{
// leading offset
@ -412,10 +413,10 @@ void do_features(Process* p, uint32_t blockaddr, uint32_t blockX, uint32_t block
}
}
*/
void do_features(API& DF, mapblock40d * block, uint32_t blockX, uint32_t blockY, int printX, int printY, vector<DFHack::t_matgloss> &stonetypes)
void do_features(Context* DF, mapblock40d * block, uint32_t blockX, uint32_t blockY, int printX, int printY, vector<DFHack::t_matgloss> &stonetypes)
{
Maps * Maps = DF.getMaps();
Process * p = DF.getProcess();
Maps * Maps = DF->getMaps();
Process * p = DF->getProcess();
if(!Maps)
return;
vector<DFHack::t_feature> global_features;
@ -549,13 +550,14 @@ main(int argc, char *argv[])
DFHack::Maps * Maps = 0;
DFHack::API DF("Memory.xml");
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context* DF;
try
{
DF.Attach();
Mats = DF.getMaterials();
Maps = DF.getMaps();
pDF = &DF;
pDF = DF = DFMgr.getSingleContext();
DF->Attach();
Mats = DF->getMaterials();
Maps = DF->getMaps();
}
catch (exception& e)
{
@ -566,12 +568,11 @@ main(int argc, char *argv[])
finish(0);
}
Process* p = DF.getProcess();
Process* p = DF->getProcess();
// init the map
if(!Maps->Start())
{
error = "Can't find a map to look at.";
pDF = 0;
finish(0);
}
@ -631,7 +632,7 @@ main(int argc, char *argv[])
e_tempmode temperature = TEMP_NO;
// resume so we don't block DF while we wait for input
DF.Resume();
DF->Resume();
for (;;)
{
@ -697,6 +698,10 @@ main(int argc, char *argv[])
case 'm':
temperature = TEMP_2;
break;
case 27: // escape key
DF->Detach();
return 0;
break;
default:
break;
}
@ -720,7 +725,7 @@ main(int argc, char *argv[])
dirtybit = 0;
// Supend, read/write data
DF.Suspend();
DF->Suspend();
uint32_t effectnum;
/*
if(DF.InitReadEffects(effectnum))
@ -796,7 +801,7 @@ main(int argc, char *argv[])
}
}
// Resume, print stuff to the terminal
DF.Resume();
DF->Resume();
for(int i = -1; i <= 1; i++) for(int j = -1; j <= 1; j++)
{
mapblock40d * Block = &blocks[i+1][j+1];

@ -1798,16 +1798,16 @@ map_data_1b60_offset 0x1B9c
Materials
=========
soil, stone, metal
inorganics vector = WORLD + 0x54B7C = 0x16AFD04
inorganics vector
<Address name="mat_inorganics">0x9324e68</Address>0x16afd04
wood and plant matter, WORLD + 0x54B94
wood and plant matter
<Address name="mat_organics_all">0x9324E74</Address>
plant matter, WORLD + 0x54BAC
plant matter
<Address name="mat_organics_plants">0x9324E80</Address>
just wood, WORLD + 0x54BDC
just wood
<Address name="mat_organics_trees">0x9324E98</Address>
creature types actually used for creatures,
@ -1816,6 +1816,14 @@ map_data_1b60_offset 0x1B9c
<Offset name="creature_type_extract_vector">0x1A14</Offset>
<Offset name="creature_tile">0xE0</Offset>
<Offset name="creature_tile_color">0xF6</Offset>
Translations
============
WORLD + 0x54E50
<Address name="language_vector">23</Address>
WORLD + 0x54E80
<Address name="translation_vector">24</Address>
<Offset name="word_table">0x4C</Offset>
<!--
Constructions
@ -1893,14 +1901,6 @@ map_data_1b60_offset 0x1B9c
WORLD + 0x108
<Address name="construction_vector">22</Address>
Translations
============
WORLD + 0x54E50
<Address name="language_vector">23</Address>
WORLD + 0x54E80
<Address name="translation_vector">24</Address>
<Offset name="word_table">0x4C</Offset>
Vegetation
==========
WORLD + 0x15184

@ -3,10 +3,13 @@
#include <iostream>
#include <integers.h>
#include <vector>
#include <map>
using namespace std;
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFContextManager.h>
#include <DFContext.h>
#include <DFMemInfo.h>
#include <DFTypes.h>
#include <stddef.h>
#include <modules/Maps.h>
@ -18,10 +21,11 @@ int main (void)
uint32_t bytes_read = 0;
vector<DFHack::t_spattervein> splatter;
DFHack::API DF("Memory.xml");
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context *DF = DFMgr.getSingleContext();
try
{
DF.Attach();
DF->Attach();
}
catch (exception& e)
{
@ -31,7 +35,7 @@ int main (void)
#endif
return 1;
}
DFHack::Maps *Mapz = DF.getMaps();
DFHack::Maps *Mapz = DF->getMaps();
// init the map
if(!Mapz->Start())
@ -64,25 +68,14 @@ int main (void)
{
uint32_t addr = vein.address_of;
uint32_t offset = offsetof(DFHack::t_spattervein, intensity);
DF.WriteRaw(addr + offset,sizeof(zeroes),(uint8_t *) zeroes);
DF->WriteRaw(addr + offset,sizeof(zeroes),(uint8_t *) zeroes);
}
}
/*
// read block designations
DF.ReadOccupancy(x,y,z, &occupancies);
// change the hidden flag to 0
for (uint32_t i = 0; i < 16;i++) for (uint32_t j = 0; j < 16;j++)
{
occupancies[i][j].unibits.splatter = 0;
}
// write the designations back
DF.WriteOccupancy(x,y,z, &occupancies);
*/
}
}
}
}
DF.Detach();
DF->Detach();
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;
cin.ignore();

@ -40,7 +40,7 @@ int main ()
int items;
int found = 0, converted = 0;
DFHack::API DF("Memory.xml");
DFHack::ContextManager DF("Memory.xml");
try
{
DF.Attach();

@ -15,7 +15,8 @@ using namespace std;
#include <DFTypes.h>
#include <DFTileTypes.h>
#include <DFHackAPI.h>
#include <DFContextManager.h>
#include <DFContext.h>
#include <argstream.h>
#include <modules/Maps.h>
@ -327,10 +328,11 @@ int main (int argc, char** argv)
}
else
{
DFHack::API DF("Memory.xml");
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context *DF = DFMgr.getSingleContext();
try
{
DF.Attach();
DF->Attach();
}
catch (exception& e)
{
@ -340,14 +342,14 @@ int main (int argc, char** argv)
#endif
return 1;
}
DFHack::Maps *Maps = DF.getMaps();
DFHack::Maps *Maps = DF->getMaps();
if (Maps && Maps->Start())
{
int count = dig(Maps, targets, max, origin[0],origin[1],origin[2], verbose);
cout << count << " targets designated" << endl;
Maps->Finish();
if (!DF.Detach())
if (!DF->Detach())
{
cerr << "Unable to detach DF process" << endl;
}

@ -22,13 +22,15 @@
#include <DFTypes.h>
#include <DFTileTypes.h>
#include <DFHackAPI.h>
#include <DFContextManager.h>
#include <DFContext.h>
#include <argstream.h>
#include <modules/Maps.h>
#include <modules/Position.h>
#define BLOCK_SIZE 16
void dig(DFHack::Maps* layers, DFHack::Position* position, ::std::vector< ::std::string >& dig_map, bool verbose = false) {
int32_t x_cent;
int32_t y_cent;
@ -141,10 +143,11 @@ int main(int argc, char** argv) {
}
dig_map.resize(dig_map.size() - 1);
DFHack::API DF("Memory.xml");
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context * DF = DFMgr.getSingleContext();
try {
DF.Attach();
DF->Attach();
} catch (::std::exception& e) {
::std::cerr << e.what() << ::std::endl;
#ifndef LINUX_BUILD
@ -153,15 +156,15 @@ int main(int argc, char** argv) {
return 1;
}
DFHack::Maps *layers = DF.getMaps();
DFHack::Maps *layers = DF->getMaps();
if (layers && layers->Start()) {
dig(layers, DF.getPosition(), dig_map, true);
dig(layers, DF->getPosition(), dig_map, true);
::std::cout << "Finished digging" << ::std::endl;
layers->Finish();
if (!DF.Detach()) {
if (!DF->Detach()) {
::std::cerr << "Unable to detach DF process" << ::std::endl;
}

@ -20,13 +20,14 @@ using namespace std;
#endif
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFContextManager.h>
#include <DFContext.h>
#include <DFProcessEnumerator.h>
#include <DFProcess.h>
#include <DFMemInfo.h>
//TODO: lots of optimization
void searchLoop(DFHack::API & DF, vector <DFHack::t_memrange>& ranges, int size, int alignment)
void searchLoop(DFHack::ContextManager & DFMgr, vector <DFHack::t_memrange>& ranges, int size, int alignment)
{
int32_t test1;
int32_t test2;
@ -34,17 +35,13 @@ void searchLoop(DFHack::API & DF, vector <DFHack::t_memrange>& ranges, int size,
vector <int64_t> newfound;
found.reserve(100000);
newfound.reserve(100000);
//bool initial = 1;
cout << "search ready - insert integers, 'p' for results" << endl;
string select;
while (1)
{
cout << ">>";
DF.Detach();
std::getline(cin, select);
DF.Attach();
if(select == "p")
{
cout << "Found addresses:" << endl;
@ -55,9 +52,13 @@ void searchLoop(DFHack::API & DF, vector <DFHack::t_memrange>& ranges, int size,
}
else if(sscanf(select.c_str(),"%d", &test1) == 1)
{
// refresh the list of processes, get first suitable, attach
DFMgr.Refresh();
DFHack::Context * DF = DFMgr.getSingleContext();
DF->Attach();
newfound.clear();
bool initial = found.empty();
if(initial)
{
// for each range
@ -66,11 +67,10 @@ void searchLoop(DFHack::API & DF, vector <DFHack::t_memrange>& ranges, int size,
// can't read? range is invalid to us
if(!ranges[i].read)
continue;
//loop
for(uint64_t offset = ranges[i].start;offset <= ranges[i].end - size; offset+=alignment)
{
DF.ReadRaw(offset, size, (uint8_t *) &test2);
DF->ReadRaw(offset, size, (uint8_t *) &test2);
if(test1 == test2 )
found.push_back(offset);
}
@ -81,28 +81,97 @@ void searchLoop(DFHack::API & DF, vector <DFHack::t_memrange>& ranges, int size,
{
for(int j = 0; j < found.size();j++)
{
DF.ReadRaw(found[j], size, (uint8_t *) &test2);
DF->ReadRaw(found[j], size, (uint8_t *) &test2);
if(test1 == test2)
{
newfound.push_back(found[j]);
}
}
cout << "matched " << newfound.size() << " addresses out of " << found.size() << endl;
found = newfound;
}
DF->Detach();
}
else break;
}
}
typedef struct
{
uint32_t start;
uint32_t finish;
uint32_t alloc_finish;
} vecTriplet;
void searchLoopVector(DFHack::ContextManager & DFMgr, vector <DFHack::t_memrange>& ranges, uint32_t element_size)
{
vecTriplet load;
uint32_t length;
vector <int64_t> found;
vector <int64_t> newfound;
found.reserve(100000);
newfound.reserve(100000);
//bool initial = 1;
cout << "search ready - insert vector length" << endl;
string select;
while (1)
{
cout << ">>";
std::getline(cin, select);
if(select == "p")
{
cout << "Found vectors:" << endl;
for(int i = 0; i < found.size();i++)
{
cout << hex << "0x" << found[i] << endl;
}
}
else if(sscanf(select.c_str(),"%d", &length) == 1)
{
// refresh the list of processes, get first suitable, attach
DFMgr.Refresh();
DFHack::Context * DF = DFMgr.getSingleContext();
DF->Attach();
// clear the list of found addresses
found.clear();
// for each range
for (int i = 0; i < ranges.size();i++)
{
// can't read? range is invalid to us
if(!ranges[i].read)
continue;
//loop
for(uint64_t offset = ranges[i].start;offset <= ranges[i].end - sizeof(vecTriplet); offset++)
{
DF->ReadRaw(offset, sizeof(vecTriplet), (uint8_t *) &load);
if(load.start <= load.finish && load.finish <= load.alloc_finish)
if((load.finish - load.start) / element_size == length)
found.push_back(offset);
}
}
cout << "found " << found.size() << " addresses" << endl;
// detach again
DF->Detach();
}
else
{
break;
}
}
}
int main (void)
{
string select;
DFHack::API DF("Memory.xml");
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context * DF = DFMgr.getSingleContext();
try
{
DF.Attach();
DF->Attach();
}
catch (exception& e)
{
@ -112,7 +181,7 @@ int main (void)
#endif
return 1;
}
DFHack::Process * p = DF.getProcess();
DFHack::Process * p = DF->getProcess();
vector <DFHack::t_memrange> ranges;
vector <DFHack::t_memrange> selected_ranges;
p->getMemRanges(ranges);
@ -164,7 +233,28 @@ int main (void)
{
selected_ranges[i].print();
}
try_again_type:
cout << "Select search type: 1=number(default), 2=vector, 3=string" << endl;
cout << ">>";
std::getline(cin, select);
int mode;
if(select.empty())
{
mode = 1;
}
else if( sscanf(select.c_str(), "%d", &mode) == 1 )
{
if(mode != 1 && mode != 2 && mode != 3)
{
goto try_again_type;
}
}
else
{
goto try_again_type;
}
if(mode == 1)
{
// input / validation of variable size
try_again_size:
cout << "Select searched variable size (1,2,4 bytes, default is 4)" << endl;
@ -208,16 +298,40 @@ int main (void)
{
goto try_again_align;
}
searchLoop(DF,selected_ranges, size, alignment);
// initial value
// cycle until you get only a few offsets (~10?)
if(!DF.Detach())
// we detach, searchLoop looks for the process again.
DF->Detach();
searchLoop(DFMgr, selected_ranges, size, alignment);
}
else if(mode == 2)// vector
{
cerr << "Can't detach from DF" << endl;
return 1;
// input / validation of variable size
try_again_vsize:
cout << "Select searched vector item size (in bytes, default is 4)" << endl;
cout << ">>";
std::getline(cin, select);
uint32_t size;
if(select.empty())
{
size = 4;
}
else if( sscanf(select.c_str(), "%d", &size) == 1 )
{
if(size == 0)
{
goto try_again_vsize;
}
}
else
{
goto try_again_vsize;
}
// we detach, searchLoop looks for the process again.
DF->Detach();
searchLoopVector(DFMgr, selected_ranges,size);
}
else if(mode == 3)// string
{
//searchLoopString(DF, selected_ranges);
}
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;

@ -189,7 +189,7 @@ void printItem(DFHack::t_item item, const string & typeString,const matGlosses &
int main ()
{
DFHack::API DF ("Memory.xml");
DFHack::ContextManager DF ("Memory.xml");
cout << "This utility lets you mass-designate items by type and material." << endl
<< "Like set on fire all MICROCLINE item_stone..." << endl
<< "Some unusual combinations might be untested and cause the program to crash..."<< endl

@ -4,10 +4,12 @@
#include <iostream>
#include <integers.h>
#include <vector>
#include <map>
using namespace std;
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFContextManager.h>
#include <DFContext.h>
#include <modules/Maps.h>
#include <modules/Position.h>
#include <DFTileTypes.h>
@ -20,14 +22,16 @@ int main (void)
DFHack::t_temperatures temp1,temp2;
uint32_t x_max,y_max,z_max;
DFHack::API DF("Memory.xml");
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context *DF;
DFHack::Maps * Maps;
DFHack::Position * Position;
try
{
DF.Attach();
Maps = DF.getMaps();
Position = DF.getPosition();
DF=DFMgr.getSingleContext();
DF->Attach();
Maps = DF->getMaps();
Position = DF->getPosition();
}
catch (exception& e)
{
@ -46,7 +50,7 @@ int main (void)
while(!end)
{
Maps->getSize(x_max,y_max,z_max);
DF.Resume();
DF->Resume();
string command = "";
cout <<"[" << mode << ":" << amount << ":" << flowmode << "]# ";
getline(cin, command);
@ -145,7 +149,7 @@ int main (void)
amount = 7;
else if(command.empty())
{
DF.Suspend();
DF->Suspend();
do
{
if(!Maps->Start())
@ -303,7 +307,7 @@ int main (void)
} while (0);
}
}
DF.Detach();
DF->Detach();
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;
cin.ignore();

@ -8,7 +8,8 @@ using namespace std;
#include <DFGlobal.h>
#include <DFError.h>
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFContextManager.h>
#include <DFContext.h>
#include <DFMemInfo.h>
#include <DFProcess.h>
#include <modules/Materials.h>
@ -22,11 +23,12 @@ vector< vector<string> > foreignWords;
int main (int numargs, char ** args)
{
DFHack::API DF("Memory.xml");
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context *DF = DFMgr.getSingleContext();
DFHack::Process * p;
try
{
DF.Attach();
DF->Attach();
}
catch (exception& e)
{
@ -36,14 +38,14 @@ int main (int numargs, char ** args)
#endif
return 1;
}
p = DF.getProcess();
p = DF->getProcess();
string check = "";
if(numargs == 2)
check = args[1];
DFHack::Creatures * Creatures = DF.getCreatures();
Materials = DF.getMaterials();
DFHack::Translation * Tran = DF.getTranslation();
DFHack::Creatures * Creatures = DF->getCreatures();
Materials = DF->getMaterials();
DFHack::Translation * Tran = DF->getTranslation();
uint32_t numCreatures;
if(!Creatures->Start(numCreatures))
@ -62,20 +64,18 @@ int main (int numargs, char ** args)
#endif
return 1;
}
mem = DF.getMemoryInfo();
mem = DF->getMemoryInfo();
if(!Materials->ReadInorganicMaterials())
{
cerr << "Can't get the inorganics types." << endl;
return 1;
}
if(!Materials->ReadCreatureTypesEx())
{
cerr << "Can't get the creature types." << endl;
return 1;
}
if(!Tran->Start())
{
cerr << "Can't get name tables" << endl;
@ -124,7 +124,7 @@ int main (int numargs, char ** args)
}
}
Creatures->Finish();
DF.Detach();
DF->Detach();
return 0;
}

@ -12,7 +12,8 @@ using namespace std;
#include <DFGlobal.h>
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFContextManager.h>
#include <DFContext.h>
#include <DFProcess.h>
#include <DFMemInfo.h>
#include <DFVector.h>
@ -27,10 +28,12 @@ using namespace std;
using namespace DFHack;
int main (int numargs, const char ** args)
{
DFHack::API DF("Memory.xml");
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context *DF = DFMgr.getSingleContext();
try
{
DF.Attach();
DF->Attach();
}
catch (exception& e)
{
@ -41,10 +44,10 @@ int main (int numargs, const char ** args)
return 1;
}
DFHack::Position *Pos = DF.getPosition();
DFHack::memory_info* mem = DF.getMemoryInfo();
DFHack::Maps *Maps = DF.getMaps();
DFHack::Process * p = DF.getProcess();
DFHack::Position *Pos = DF->getPosition();
DFHack::memory_info* mem = DF->getMemoryInfo();
DFHack::Maps *Maps = DF->getMaps();
DFHack::Process * p = DF->getProcess();
uint32_t designatus = mem->getOffset("map_data_designation");
uint32_t block_feature1 = mem->getOffset("map_data_feature_local");
uint32_t block_feature2 = mem->getOffset("map_data_feature_global");

@ -18,7 +18,8 @@ using namespace std;
#include <DFTypes.h>
#include <DFTileTypes.h>
#include <DFHackAPI.h>
#include <DFContextManager.h>
#include <DFContext.h>
#include <modules/Maps.h>
#include <modules/Materials.h>
@ -62,10 +63,12 @@ int main (int argc, const char* argv[])
vector< vector <uint16_t> > layerassign;
DFHack::API DF("Memory.xml");
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context *DF;
try
{
DF.Attach();
DF = DFMgr.getSingleContext();
DF->Attach();
}
catch (exception& e)
{
@ -77,8 +80,8 @@ int main (int argc, const char* argv[])
}
DFHack::Maps * Maps = DF.getMaps();
DFHack::Materials * Mats = DF.getMaterials();
DFHack::Maps * Maps = DF->getMaps();
DFHack::Materials * Mats = DF->getMaterials();
// init the map
if(!Maps->Start())
@ -291,7 +294,7 @@ int main (int argc, const char* argv[])
cout << Mats->inorganic[p->first].id << " : " << p->second << endl;
}
}
DF.Detach();
DF->Detach();
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;
cin.ignore();

@ -3,10 +3,12 @@
#include <iostream>
#include <integers.h>
#include <vector>
#include <map>
using namespace std;
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFContextManager.h>
#include <DFContext.h>
#include <modules/Maps.h>
@ -23,10 +25,12 @@ int main (void)
uint32_t x_max,y_max,z_max;
DFHack::designations40d designations;
DFHack::API DF("Memory.xml");
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context *DF;
try
{
DF.Attach();
DF = DFMgr.getSingleContext();
DF->Attach();
}
catch (exception& e)
{
@ -37,7 +41,7 @@ int main (void)
return 1;
}
DFHack::Maps *Maps =DF.getMaps();
DFHack::Maps *Maps =DF->getMaps();
// init the map
if(!Maps->Start())
{
@ -80,14 +84,14 @@ int main (void)
}
}
// FIXME: force game pause here!
DF.Detach();
DF->Detach();
cout << "Map revealed. Close window/force exit to keep it that way." << endl;
cout << "Press any key to unreveal. Don't close DF or unpause in that case!" << endl;
cin.ignore();
cout << "Unrevealing... please wait." << endl;
// FIXME: do some consistency checks here!
DF.Attach();
Maps = DF.getMaps();
DF->Attach();
Maps = DF->getMaps();
Maps->Start();
for(int i = 0; i < hidesaved.size();i++)
{

@ -9,15 +9,18 @@
using namespace std;
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFContextManager.h>
#include <DFContext.h>
int main (void)
{
string blah;
DFHack::API DF("Memory.xml");
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context *DF;
try
{
DF.Attach();
DF = DFMgr.getSingleContext();
DF->Attach();
}
catch (exception& e)
{
@ -28,11 +31,11 @@ int main (void)
return 1;
}
DF.ForceResume();
DF->ForceResume();
cout << "DF should be running again :)" << endl;
getline(cin, blah);
if(!DF.Detach())
if(!DF->Detach())
{
cerr << "Can't detach from DF" << endl;
return 1;

@ -11,7 +11,8 @@ using namespace std;
#include <DFTypes.h>
#include <DFTileTypes.h>
#include <DFHackAPI.h>
#include <DFContextManager.h>
#include <DFContext.h>
#include <modules/Maps.h>
#include <modules/Position.h>
#include <modules/Materials.h>
@ -290,10 +291,12 @@ int main (int argc, char* argv[])
return 1;
}
DFHack::API DF("Memory.xml");
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context * DF;
try
{
DF.Attach();
DF = DFMgr.getSingleContext();
DF->Attach();
}
catch (exception& e)
{
@ -305,15 +308,15 @@ int main (int argc, char* argv[])
}
uint32_t x_max,y_max,z_max;
DFHack::Maps * Maps = DF.getMaps();
DFHack::Materials * Mats = DF.getMaterials();
DFHack::Position * Pos = DF.getPosition();
DFHack::Maps * Maps = DF->getMaps();
DFHack::Materials * Mats = DF->getMaterials();
DFHack::Position * Pos = DF->getPosition();
// init the map
if(!Maps->Start())
{
cerr << "Can't init map. Make sure you have a map loaded in DF." << endl;
DF.Detach();
DF->Detach();
#ifndef LINUX_BUILD
cin.ignore();
#endif
@ -329,16 +332,16 @@ int main (int argc, char* argv[])
while(cx == -30000)
{
cerr << "Cursor is not active. Point the cursor at a vein." << endl;
DF.Resume();
DF->Resume();
cin.ignore();
DF.Suspend();
DF->Suspend();
Pos->getCursorCoords(cx,cy,cz);
}
Point xy ((uint32_t)cx,(uint32_t)cy,cz);
if(xy.x == 0 || xy.x == tx_max - 1 || xy.y == 0 || xy.y == ty_max - 1)
{
cerr << "I won't dig the borders. That would be cheating!" << endl;
DF.Detach();
DF->Detach();
#ifndef LINUX_BUILD
cin.ignore();
#endif
@ -355,7 +358,7 @@ int main (int argc, char* argv[])
{
cerr << "This tile is non-vein. Bye :)" << endl;
delete MCache;
DF.Detach();
DF->Detach();
#ifndef LINUX_BUILD
cin.ignore();
#endif
@ -469,7 +472,7 @@ int main (int argc, char* argv[])
}
MCache->WriteAll();
delete MCache;
DF.Detach();
DF->Detach();
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;
cin.ignore();