Merge remote branch 'remotes/upstream/DF2010' into Branch_remotes/origin/pydfhack

develop
doomchild 2010-04-05 09:45:27 -05:00
commit 17e920e738
124 changed files with 14228 additions and 7621 deletions

5
.gitignore vendored

@ -8,7 +8,7 @@ output/*
!output/Memory.xml
# a file generated by cmake
library/config.h
dfhack/include/config.h
# any build folders
build*/
@ -18,3 +18,6 @@ build*/
#ignore Kdevelop stuff
.kdev4
#fake curses header
examples/fake-curses.h

@ -26,11 +26,17 @@ SET( LIBRARY_OUTPUT_PATH ${dfhack_SOURCE_DIR}/output CACHE PATH "Output director
SET( EXECUTABLE_OUTPUT_PATH ${dfhack_SOURCE_DIR}/output CACHE PATH "Output directory for the dfhack tools" )
SET( CMAKE_SWIG_OUTDIR ${dfhack_SOURCE_DIR}/output CACHE PATH "Global output directory for swig generated language wrappers" )
include_directories (${CMAKE_SOURCE_DIR}/library/)
include_directories (${CMAKE_SOURCE_DIR}/shmserver/)
include_directories (${CMAKE_SOURCE_DIR}/depends/)
add_subdirectory (library)
include_directories (${CMAKE_SOURCE_DIR}/dfhack/include/)
include_directories (${CMAKE_SOURCE_DIR}/dfhack/shm/)
include_directories (${CMAKE_SOURCE_DIR}/dfhack/depends/md5/)
include_directories (${CMAKE_SOURCE_DIR}/dfhack/depends/tinyxml/)
include_directories (${CMAKE_SOURCE_DIR}/dfhack/depends/argstream/)
add_subdirectory (dfhack)
#add_subdirectory (dfhack/shm)
#FIXME: add exports for MSVC
#add_subdirectory (dfhack/depends/md5)
#add_subdirectory (dfhack/depends/tinyxml)
#add_subdirectory (dfhack/depends/argstream)
add_subdirectory (tools)
add_subdirectory (examples)
add_subdirectory (shmserver)

File diff suppressed because it is too large Load Diff

@ -1,6 +0,0 @@
#!/bin/bash
exec 3< cpfile
while read <&3
do echo $REPLY | cpio -pvdm cleansed
done
exec 3>&-

@ -0,0 +1,50 @@
#include "DFCommonInternal.h"
#include <shms.h>
#include <mod-core.h>
#include <mod-maps.h>
#include <mod-creature40d.h>
#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;
}
APIPrivate::~APIPrivate()
{
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");
return true;
}
void APIPrivate::readName(t_name & name, uint32_t address)
{
g_pProcess->readSTLString(address + name_firstname_offset , name.first_name, 128);
g_pProcess->readSTLString(address + name_nickname_offset , name.nickname, 128);
g_pProcess->read(address + name_words_offset ,48, (uint8_t *) name.words);
}

@ -1,49 +1,49 @@
# don't use this file directly. use the one in the root folder of the project
SET(PROJECT_HDRS
DFCommonInternal.h
DFError.h
DFHackAPI.h
DFMemInfo.h
DFMemInfoManager.h
DFProcessEnumerator.h
DFProcess.h
DFTileTypes.h
DFTypes.h
DFVector.h
DFWindow.h
integers.h
md5/md5.h
md5/md5wrapper.h
tinyxml/tinystr.h
tinyxml/tinyxml.h
argstream/argstream.h
../shmserver/shms.h
include/DFCommonInternal.h
include/DFError.h
include/DFHackAPI.h
include/DFMemInfo.h
include/DFMemInfoManager.h
include/DFProcessEnumerator.h
include/DFProcess.h
include/DFTileTypes.h
include/DFTypes.h
include/DFVector.h
include/DFWindow.h
include/integers.h
shm/shms.h
)
SET(PROJECT_SRCS
DFMemInfo.cpp
DFMemInfoManager.cpp
DFHackAPI.cpp
APIPrivate.cpp
DFTileTypes.cpp
DFVector.cpp
md5/md5.cpp
md5/md5wrapper.cpp
tinyxml/tinystr.cpp
tinyxml/tinyxml.cpp
tinyxml/tinyxmlerror.cpp
tinyxml/tinyxmlparser.cpp
depends/md5/md5.cpp
depends/md5/md5wrapper.cpp
depends/tinyxml/tinystr.cpp
depends/tinyxml/tinyxml.cpp
depends/tinyxml/tinyxmlerror.cpp
depends/tinyxml/tinyxmlparser.cpp
modules/Creatures.cpp
modules/Gui.cpp
modules/Maps.cpp
modules/Materials.cpp
modules/Position.cpp
)
SET(PROJECT_HDRS_LINUX
)
SET(PROJECT_HDRS_WINDOWS
stdint_win.h
include/stdint_win.h
)
SET(PROJECT_SRCS_LINUX
@ -79,7 +79,7 @@ SET( MEMXML_DATA_PATH . CACHE PATH "search path for Memory.xml")
#OPTION( WITH_BAR "Enable BAR component" OFF )
CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/library/config.h.cmake ${CMAKE_SOURCE_DIR}/library/config.h )
CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/dfhack/config.h.cmake ${CMAKE_SOURCE_DIR}/dfhack/include/config.h )
@ -90,7 +90,7 @@ IF(UNIX)
SET(CMAKE_CXX_FLAGS_DEBUG "-g -Wall -pedantic")
SET(CMAKE_CXX_FLAGS "-fvisibility=hidden")
SET(PROJECT_LIBS ${X11_LIBRARY} rt)
SET(PROJECT_LIBS ${X11_LIBRARY} rt ) #dfhack-md5 dfhack-tixml
ELSE(UNIX)
SET(PROJECT_LIBS psapi)
ENDIF(UNIX)

@ -0,0 +1,812 @@
/*
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/Position.h"
#include "modules/Gui.h"
#include "modules/Creatures.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->shm_start = 0;
}
API::~API()
{
// FIXME: call all finishread* methods here
Detach();
delete d;
}
bool API::Attach()
{
// 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;
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)
{
g_pProcess->read (offset, size, target);
}
void API::WriteRaw (const uint32_t offset, const uint32_t size, uint8_t *source)
{
g_pProcess->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;
}
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 )
{
int buildings = 0;
try
{
buildings = d->offset_descriptor->getAddress ("buildings");
}
catch(Error::MissingMemoryDefinition)
{
return false;
}
d->buildingsInited = true;
d->p_bld = new DfVector (d->p,buildings, 4);
numbuildings = d->p_bld->getSize();
return true;
}
// read one building
bool API::ReadBuilding (const int32_t index, t_building & building)
{
if(!d->buildingsInited) return false;
t_building_df40d bld_40d;
// read pointer from vector at position
uint32_t temp = * (uint32_t *) d->p_bld->at (index);
//d->p_bld->read(index,(uint8_t *)&temp);
//read building from memory
g_pProcess->read (temp, sizeof (t_building_df40d), (uint8_t *) &bld_40d);
// transform
int32_t type = -1;
d->offset_descriptor->resolveObjectToClassID (temp, type);
building.origin = temp;
building.vtable = bld_40d.vtable;
building.x1 = bld_40d.x1;
building.x2 = bld_40d.x2;
building.y1 = bld_40d.y1;
building.y2 = bld_40d.y2;
building.z = bld_40d.z;
building.material = bld_40d.material;
building.type = type;
return true;
}
void API::FinishReadBuildings()
{
if(d->p_bld)
{
delete d->p_bld;
d->p_bld = NULL;
}
d->buildingsInited = false;
}
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, 4);
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 = * (uint32_t *) d->p_effect->at (index);
//read effect from memory
g_pProcess->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 = * (uint32_t *) d->p_effect->at (index);
// write effect to memory
g_pProcess->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;
}
//TODO: maybe do construction reading differently - this could go slow with many of them.
// returns number of constructions, prepares a vector, returns total number of constructions
bool API::InitReadConstructions(uint32_t & numconstructions)
{
int constructions = 0;
try
{
constructions = d->offset_descriptor->getAddress ("constructions");
}
catch(Error::MissingMemoryDefinition)
{
return false;
}
d->p_cons = new DfVector (d->p,constructions, 4);
d->constructionsInited = true;
numconstructions = d->p_cons->getSize();
return true;
}
bool API::ReadConstruction (const int32_t index, t_construction & construction)
{
if(!d->constructionsInited) return false;
t_construction_df40d c_40d;
// read pointer from vector at position
uint32_t temp = * (uint32_t *) d->p_cons->at (index);
//read construction from memory
g_pProcess->read (temp, sizeof (t_construction_df40d), (uint8_t *) &c_40d);
// transform
construction.x = c_40d.x;
construction.y = c_40d.y;
construction.z = c_40d.z;
construction.material = c_40d.material;
return true;
}
void API::FinishReadConstructions()
{
if(d->p_cons)
{
delete d->p_cons;
d->p_cons = NULL;
}
d->constructionsInited = false;
}
bool API::InitReadVegetation(uint32_t & numplants)
{
try
{
int vegetation = d->offset_descriptor->getAddress ("vegetation");
d->tree_offset = d->offset_descriptor->getOffset ("tree_desc_offset");
d->vegetationInited = true;
d->p_veg = new DfVector (d->p, vegetation, 4);
numplants = d->p_veg->getSize();
return true;
}
catch (Error::MissingMemoryDefinition&)
{
d->vegetationInited = false;
numplants = 0;
throw;
}
}
bool API::ReadVegetation (const int32_t index, t_tree_desc & shrubbery)
{
if(!d->vegetationInited)
return false;
// read pointer from vector at position
uint32_t temp = * (uint32_t *) d->p_veg->at (index);
//read construction from memory
g_pProcess->read (temp + d->tree_offset, sizeof (t_tree_desc), (uint8_t *) &shrubbery);
// FIXME: this is completely wrong. type isn't just tree/shrub but also different kinds of trees. stuff that grows around ponds has its own type ID
if (shrubbery.material.type == 3) shrubbery.material.type = 2;
return true;
}
void API::FinishReadVegetation()
{
if(d->p_veg)
{
delete d->p_veg;
d->p_veg = 0;
}
d->vegetationInited = 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, 4);
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 = * (uint32_t *) d->p_notes->at (index);
note.symbol = g_pProcess->readByte(temp);
note.foreground = g_pProcess->readWord(temp + d->note_foreground_offset);
note.background = g_pProcess->readWord(temp + d->note_background_offset);
d->p->readSTLString (temp + d->note_name_offset, note.name, 128);
g_pProcess->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, 4);
d->p_current_settlement = new DfVector(d->p, currentSettlement,4);
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 = * (uint32_t *) d->p_settlements->at (index);
settlement.origin = temp;
d->readName(settlement.name, temp + d->settlement_name_offset);
g_pProcess->read(temp + d->settlement_world_xy_offset, 2 * sizeof(int16_t), (uint8_t *) &settlement.world_x);
g_pProcess->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 = * (uint32_t *) d->p_current_settlement->at(0);
settlement.origin = temp;
d->readName(settlement.name, temp + d->settlement_name_offset);
g_pProcess->read(temp + d->settlement_world_xy_offset, 2 * sizeof(int16_t), (uint8_t *) &settlement.world_x);
g_pProcess->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::InitReadHotkeys( )
{
try
{
memory_info * minfo = d->offset_descriptor;
d->hotkey_start = minfo->getAddress("hotkey_start");
d->hotkey_mode_offset = minfo->getOffset ("hotkey_mode");
d->hotkey_xyz_offset = minfo->getOffset("hotkey_xyz");
d->hotkey_size = minfo->getHexValue("hotkey_size");
d->hotkeyInited = true;
return true;
}
catch (Error::MissingMemoryDefinition&)
{
d->hotkeyInited = false;
throw;
}
}
bool API::ReadHotkeys(t_hotkey hotkeys[])
{
if (!d->hotkeyInited) return false;
uint32_t currHotkey = d->hotkey_start;
for(uint32_t i = 0 ; i < NUM_HOTKEYS ;i++)
{
d->p->readSTLString(currHotkey,hotkeys[i].name,10);
hotkeys[i].mode = g_pProcess->readWord(currHotkey+d->hotkey_mode_offset);
g_pProcess->read (currHotkey + d->hotkey_xyz_offset, 3*sizeof (int32_t), (uint8_t *) &hotkeys[i].x);
currHotkey+=d->hotkey_size;
}
return true;
}
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 = *(uint32_t *) d->p_itm->at(i);
g_pProcess->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;
}
*/
/*
bool API::InitReadNameTables(vector<vector<string> > & translations , vector<vector<string> > & foreign_languages) //(map< string, vector<string> > & nameTable)
{
try
{
int genericAddress = d->offset_descriptor->getAddress ("language_vector");
int transAddress = d->offset_descriptor->getAddress ("translation_vector");
int word_table_offset = d->offset_descriptor->getOffset ("word_table");
int sizeof_string = d->offset_descriptor->getHexValue ("sizeof_string");
DfVector genericVec (d->p, genericAddress, 4);
DfVector transVec (d->p, transAddress, 4);
translations.resize(10);
for (uint32_t i = 0;i < genericVec.getSize();i++)
{
uint32_t genericNamePtr = * (uint32_t *) genericVec.at (i);
for(int i=0; i<10;i++)
{
string word = d->p->readSTLString (genericNamePtr + i * sizeof_string);
translations[i].push_back (word);
}
}
foreign_languages.resize(transVec.getSize());
for (uint32_t i = 0; i < transVec.getSize();i++)
{
uint32_t transPtr = * (uint32_t *) transVec.at (i);
//string transName = d->p->readSTLString (transPtr);
DfVector trans_names_vec (d->p, transPtr + word_table_offset, 4);
for (uint32_t j = 0;j < trans_names_vec.getSize();j++)
{
uint32_t transNamePtr = * (uint32_t *) trans_names_vec.at (j);
string name = d->p->readSTLString (transNamePtr);
foreign_languages[i].push_back (name);
}
}
d->nameTablesInited = true;
return true;
}
catch (Error::MissingMemoryDefinition&)
{
d->nameTablesInited = false;
throw;
}
}
string API::TranslateName(const DFHack::t_name &name,const std::vector< std::vector<std::string> > & translations ,const std::vector< std::vector<std::string> > & foreign_languages, bool inEnglish)
{
string out;
assert (d->nameTablesInited);
map<string, vector<string> >::const_iterator it;
if(!inEnglish)
{
if(name.words[0] >=0 || name.words[1] >=0)
{
if(name.words[0]>=0) out.append(foreign_languages[name.language][name.words[0]]);
if(name.words[1]>=0) out.append(foreign_languages[name.language][name.words[1]]);
out[0] = toupper(out[0]);
}
if(name.words[5] >=0)
{
string word;
for(int i=2;i<=5;i++)
if(name.words[i]>=0) word.append(foreign_languages[name.language][name.words[i]]);
word[0] = toupper(word[0]);
if(out.length() > 0) out.append(" ");
out.append(word);
}
if(name.words[6] >=0)
{
string word;
word.append(foreign_languages[name.language][name.words[6]]);
word[0] = toupper(word[0]);
if(out.length() > 0) out.append(" ");
out.append(word);
}
}
else
{
if(name.words[0] >=0 || name.words[1] >=0)
{
if(name.words[0]>=0) out.append(translations[name.parts_of_speech[0]+1][name.words[0]]);
if(name.words[1]>=0) out.append(translations[name.parts_of_speech[1]+1][name.words[1]]);
out[0] = toupper(out[0]);
}
if(name.words[5] >=0)
{
if(out.length() > 0)
out.append(" the");
else
out.append("The");
string word;
for(int i=2;i<=5;i++)
{
if(name.words[i]>=0)
{
word = translations[name.parts_of_speech[i]+1][name.words[i]];
word[0] = toupper(word[0]);
out.append(" " + word);
}
}
}
if(name.words[6] >=0)
{
if(out.length() > 0)
out.append(" of");
else
out.append("Of");
string word;
word.append(translations[name.parts_of_speech[6]+1][name.words[6]]);
word[0] = toupper(word[0]);
out.append(" " + word);
}
}
return out;
}
void API::FinishReadNameTables()
{
d->nameTablesInited = false;
}
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, 4);
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 = * (uint32_t *) d->p_itm->at (index);
//read building from memory
g_pProcess->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
g_pProcess->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,4);
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;
}
*/

@ -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,13 +22,18 @@ 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>
#include <sys/ipc.h>
#include <time.h>
#include "../shmserver/shms.h"
#include "../shmserver/mod-core.h"
#include <shms.h>
#include <mod-core.h>
#include <sys/time.h>
#include <time.h>
#include <sched.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,8 +22,12 @@ must not be misrepresented as being the original software.
distribution.
*/
#include "DFCommonInternal.h"
#include "../shmserver/shms.h"
#include "../shmserver/mod-core.h"
#include "DFProcess.h"
#include "DFWindow.h"
#include "DFMemInfo.h"
#include "DFError.h"
#include "shms.h"
#include "mod-core.h"
using namespace DFHack;
// a full memory barrier! better be safe than sorry.

@ -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,11 +23,15 @@ 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>
#include <time.h>
#include "../shmserver/shms.h"
#include "shms.h"
using namespace DFHack;

@ -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;
@ -33,7 +36,7 @@ DfVector::DfVector(Process * p, uint32_t address, uint32_t _item_size)
uint32_t triplet[3];
item_size = _item_size;
memory_info * mem = p->getDescriptor();
uint32_t offs = mem->getOffset("hacked_vector_triplet");
uint32_t offs = mem->getOffset("vector_triplet");
p->read(address + offs, sizeof(triplet), (uint8_t *) &triplet);
start = triplet[0];

@ -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

@ -0,0 +1 @@
ADD_LIBRARY(dfhack-md5 SHARED md5.cpp md5wrapper.cpp)

@ -45,7 +45,7 @@
//----------------------------------------------------------------------
//STL includes
#include <string>
#include "../integers.h"
#include <integers.h>
//----------------------------------------------------------------------
//typedefs
typedef unsigned char *POINTER;

@ -0,0 +1 @@
ADD_LIBRARY(dfhack-tixml SHARED tinystr.cpp tinyxml.cpp tinyxmlerror.cpp tinyxmlparser.cpp)

@ -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/tinyxml.h"
#include "md5/md5wrapper.h"
#include <tinyxml.h>
#include <md5wrapper.h>
#include <iostream>
#include "DFHackAPI.h"
//#include "DFHackAPI.h"
#define _QUOTEME(x) #x
#define QUOT(x) _QUOTEME(x)

@ -0,0 +1,188 @@
/*
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 Materials;
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);
Creatures * getCreatures();
Maps * getMaps();
Gui * getGui();
Position * getPosition();
Materials * getMaterials();
/*
* Constructions (costructed walls, floors, ramps, etc...)
*/
/*
/// start reading constructions. numconstructions is an output - total constructions present
bool InitReadConstructions( uint32_t & numconstructions );
/// read a construiction at index
bool ReadConstruction(const int32_t index, t_construction & construction);
/// cleanup after reading constructions
void FinishReadConstructions();
*/
/*
* Buildings - also includes zones and stockpiles
*/
/*
bool InitReadBuildings ( uint32_t & numbuildings );
bool ReadBuilding(const int32_t index, t_building & building);
void FinishReadBuildings();
*/
/*
* 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();
*/
/*
* Hotkeys (DF's zoom locations)
*/
/*
bool InitReadHotkeys( );
bool ReadHotkeys(t_hotkey hotkeys[]);
*/
/*
* DF translation tables and name translation
*/
/*
bool InitReadNameTables (std::vector< std::vector<std::string> > & translations , std::vector< std::vector<std::string> > & foreign_languages);
void FinishReadNameTables();
std::string TranslateName(const t_name & name,const std::vector< std::vector<std::string> > & translations ,const std::vector< std::vector<std::string> > & foreign_languages, bool inEnglish=true);
*/
/*
* 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

@ -53,27 +53,7 @@ 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
{
uint32_t vtable;
@ -83,7 +63,15 @@ struct t_vein
uint32_t flags;
uint32_t address_of; // this is NOT part of the DF vein, but an address of the vein as seen by DFhack.
};
*/
struct t_vein
{
uint32_t vtable;
int32_t type;
int16_t assignment[16];
uint32_t flags;
uint32_t address_of; // this is NOT part of the DF vein, but an address of the vein as seen by DFhack.
};
// stores what tiles should appear when the ice melts
struct t_frozenliquidvein
{
@ -540,12 +528,12 @@ CREATURE
//#pragma pack(push,4)
struct t_name
{
char first_name[128];
char nickname[128];
int32_t words[7];
uint16_t parts_of_speech[7];
uint32_t language;
bool has_name;
char first_name[128];
char nickname[128];
int32_t words[7];
uint16_t parts_of_speech[7];
uint32_t language;
bool has_name;
};
struct t_skill
@ -581,8 +569,8 @@ struct t_creature
t_creaturflags1 flags1;
t_creaturflags2 flags2;
t_name name;
t_name squad_name;
t_name artifact_name;
t_name squad_name;
t_name artifact_name;
uint8_t profession;
char custom_profession[128];
// enabled labors
@ -853,7 +841,7 @@ union t_blockflags
typedef int16_t tiletypes40d [16][16];
typedef DFHack::t_designation designations40d [16][16];
typedef DFHack::t_occupancy occupancies40d [16][16];
typedef uint8_t biome_indices40d [8];
typedef uint8_t biome_indices40d [16];
typedef struct
{

@ -0,0 +1,6 @@
#ifndef CONFIG_H
#define CONFIG_H
#define MEMXML_DATA_PATH .
#endif // CONFIG_H

@ -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

@ -0,0 +1,289 @@
/*
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 "../private/APIPrivate.h"
// 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;
struct Creatures::Private
{
bool Inited;
bool Started;
Creatures2010::creature_offsets creatures;
uint32_t creature_module;
DfVector *p_cre;
APIPrivate *d;
};
Creatures::Creatures(APIPrivate* _d)
{
d = new Private;
d->d = _d;
d->Inited = false;
d->Started = false;
d->d->InitReadNames(); // throws on error
try
{
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
creatures.name_firstname_offset = minfo->getOffset("name_firstname");
creatures.name_nickname_offset = minfo->getOffset("name_nickname");
creatures.name_words_offset = minfo->getOffset("name_words");
// 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),&creatures,sizeof(Creatures2010::creature_offsets));
const uint32_t cmd = Creatures2010::CREATURE_INIT + (d->creature_module << 16);
g_pProcess->SetAndWait(cmd);
}
d->Inited = true;
}
catch (Error::MissingMemoryDefinition&)
{
d->Inited = false;
throw;
}
}
Creatures::~Creatures()
{
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)
{
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));
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;
Creatures2010::creature_offsets &offs = d->creatures;
//read creature from memory
g_pProcess->read (temp + offs.creature_pos_offset, 3 * sizeof (uint16_t), (uint8_t *) & (furball.x)); // xyz really
g_pProcess->readDWord (temp + offs.creature_race_offset, furball.type);
g_pProcess->readDWord (temp + offs.creature_flags1_offset, furball.flags1.whole);
g_pProcess->readDWord (temp + offs.creature_flags2_offset, furball.flags2.whole);
// names
d->d->readName(furball.name,temp + offs.creature_name_offset);
//d->readName(furball.squad_name, temp + offs.creature_squad_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));
// labors
g_pProcess->read (temp + offs.creature_labors_offset, NUM_CREATURE_LABORS, furball.labors);
// traits
//g_pProcess->read (temp + offs.creature_traits_offset, sizeof (uint16_t) * NUM_CREATURE_TRAITS, (uint8_t *) &furball.traits);
// learned skills
/*
DfVector skills (d->p, temp + offs.creature_skills_offset, 4 );
furball.numSkills = skills.getSize();
for (uint32_t i = 0; i < furball.numSkills;i++)
{
uint32_t temp2 = * (uint32_t *) skills[i];
//skills.read(i, (uint8_t *) &temp2);
// a byte: this gives us 256 skills maximum.
furball.skills[i].id = g_pProcess->readByte (temp2);
furball.skills[i].rating = g_pProcess->readByte (temp2 + 4);
furball.skills[i].experience = g_pProcess->readWord (temp2 + 8);
}
*/
// profession
furball.profession = g_pProcess->readByte (temp + offs.creature_profession_offset);
// current job HACK: the job object isn't cleanly represented here
/*
uint32_t jobIdAddr = g_pProcess->readDWord (temp + offs.creature_current_job_offset);
if (jobIdAddr)
{
furball.current_job.active = true;
furball.current_job.jobId = g_pProcess->readByte (jobIdAddr + offs.creature_current_job_id_offset);
}
else
{
furball.current_job.active = false;
}
*/
//likes
/*
DfVector likes(d->p, temp + offs.creature_likes_offset, 4);
furball.numLikes = likes.getSize();
for(uint32_t i = 0;i<furball.numLikes;i++)
{
uint32_t temp2 = *(uint32_t *) likes[i];
g_pProcess->read(temp2,sizeof(t_like),(uint8_t *) &furball.likes[i]);
}
furball.mood = (int16_t) g_pProcess->readWord (temp + offs.creature_mood_offset);
*/
g_pProcess->readDWord (temp + offs.creature_happiness_offset, furball.happiness);
g_pProcess->readDWord (temp + offs.creature_id_offset, furball.id);
/*
g_pProcess->readDWord (temp + offs.creature_agility_offset, furball.agility);
g_pProcess->readDWord (temp + offs.creature_strength_offset, furball.strength);
g_pProcess->readDWord (temp + offs.creature_toughness_offset, furball.toughness);
g_pProcess->readDWord (temp + offs.creature_money_offset, furball.money);
furball.squad_leader_id = (int32_t) g_pProcess->readDWord (temp + offs.creature_squad_leader_id_offset);
*/
g_pProcess->readByte (temp + offs.creature_sex_offset, furball.sex);
/*
g_pProcess->readDWord(temp + offs.creature_pregnancy_offset, furball.pregnancy_timer);
furball.blood_max = (int32_t) g_pProcess->readDWord(temp + offs.creature_blood_max_offset);
furball.blood_current = (int32_t) g_pProcess->readDWord(temp + offs.creature_blood_current_offset);
g_pProcess->readDWord(temp + offs.creature_bleed_offset, furball.bleed_rate);
*/
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])
{
if(!d->creaturesInited) return false;
uint32_t temp = * (uint32_t *) d->p_cre->at (index);
WriteRaw(temp + d->creatures.creature_labors_offset, NUM_CREATURE_LABORS, labors);
}
*/
/*
bool API::getCurrentCursorCreature(uint32_t & creature_index)
{
if(!d->cursorWindowInited) return false;
creature_index = g_pProcess->readDWord(d->current_cursor_creature_offset);
return true;
}
*/

@ -0,0 +1,104 @@
/*
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 "../private/APIPrivate.h"
#include "modules/Gui.h"
#include "DFProcess.h"
#include "DFMemInfo.h"
#include "DFTypes.h"
using namespace DFHack;
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->Inited) return false;
uint32_t pauseState = g_pProcess->readDWord (d->pause_state_offset);
return pauseState & 1;
}
uint32_t Gui::ReadMenuState()
{
if(d->Inited)
return(g_pProcess->readDWord(d->current_menu_state_offset));
return false;
}
bool Gui::ReadViewScreen (t_viewscreen &screen)
{
if (!d->Inited) return false;
uint32_t last = g_pProcess->readDWord (d->view_screen_offset);
uint32_t screenAddr = g_pProcess->readDWord (last);
uint32_t nextScreenPtr = g_pProcess->readDWord (last + 4);
while (nextScreenPtr != 0)
{
last = nextScreenPtr;
screenAddr = g_pProcess->readDWord (nextScreenPtr);
nextScreenPtr = g_pProcess->readDWord (nextScreenPtr + 4);
}
return d->d->offset_descriptor->resolveObjectToClassID (last, screen.type);
}

@ -0,0 +1,536 @@
/*
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 <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 ((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;
struct Maps::Private
{
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
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");
off.biome_stuffs = mem->getOffset ("biome_stuffs");
off.veinvector = mem->getOffset ("v_vein");
// these can fail and will be found when looking at the actual veins later
// basically a cache
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);
// 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
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 = Server::Maps::MAP_INIT + (d->maps_module << 16);
g_pProcess->SetAndWait(cmd);
}
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 (off.map_offset);
if (!x_array_loc)
{
return false;
}
// get the size
uint32_t mx, my, mz;
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)
{
throw Error::BadMapDimensions(mx, my);
//return false;
}
// alloc array for pointers to all blocks
d->block = new uint32_t[mx*my*mz];
uint32_t *temp_x = new uint32_t[mx];
uint32_t *temp_y = new uint32_t[my];
uint32_t *temp_z = new uint32_t[mz];
g_pProcess->read (x_array_loc, mx * sizeof (uint32_t), (uint8_t *) temp_x);
for (uint32_t x = 0; x < mx; x++)
{
g_pProcess->read (temp_x[x], my * sizeof (uint32_t), (uint8_t *) temp_y);
// y -> map column
for (uint32_t y = 0; y < my; y++)
{
g_pProcess->read (temp_y[y],
mz * sizeof (uint32_t),
(uint8_t *) (d->block + x*my*mz + y*mz));
}
}
delete [] temp_x;
delete [] temp_y;
delete [] temp_z;
return true;
}
bool Maps::Finish()
{
if (d->block != NULL)
{
delete [] d->block;
d->block = NULL;
}
return true;
}
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 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 Maps::ReadBlock40d(uint32_t x, uint32_t y, uint32_t z, mapblock40d * buffer)
{
if(d->d->shm_start && d->maps_module) // ACCELERATE!
{
SHMMAPSHDR->x = x;
SHMMAPSHDR->y = y;
SHMMAPSHDR->z = z;
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));
return true;
}
else // plain old block read
{
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->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);
return true;
}
return false;
}
}
// 256 * sizeof(uint16_t)
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->offsets.tile_type_offset, sizeof (tiletypes40d), (uint8_t *) buffer);
return true;
}
return false;
}
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)
{
uint32_t addr_of_struct = g_pProcess->readDWord(addr);
dirtybit = g_pProcess->readDWord(addr_of_struct) & 1;
return true;
}
return false;
}
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)
{
uint32_t addr_of_struct = g_pProcess->readDWord(addr);
uint32_t dirtydword = g_pProcess->readDWord(addr_of_struct);
dirtydword &= 0xFFFFFFFE;
dirtydword |= (uint32_t) dirtybit;
g_pProcess->writeDWord (addr_of_struct, dirtydword);
return true;
}
return false;
}
/// read/write the block flags
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)
{
uint32_t addr_of_struct = g_pProcess->readDWord(addr);
blockflags.whole = g_pProcess->readDWord(addr_of_struct);
return true;
}
return false;
}
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)
{
uint32_t addr_of_struct = g_pProcess->readDWord(addr);
g_pProcess->writeDWord (addr_of_struct, blockflags.whole);
return true;
}
return false;
}
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->offsets.designation_offset, sizeof (designations40d), (uint8_t *) buffer);
return true;
}
return false;
}
// 256 * sizeof(uint16_t)
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->offsets.tile_type_offset, sizeof (tiletypes40d), (uint8_t *) buffer);
return true;
}
return false;
}
// 256 * sizeof(uint32_t)
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->offsets.designation_offset, sizeof (designations40d), (uint8_t *) buffer);
return true;
}
return false;
}
// FIXME: this is bad. determine the real size!
//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 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)
{
g_pProcess->read (addr + d->offsets.biome_stuffs, sizeof (biome_indices40d), (uint8_t *) buffer);
return true;
}
return false;
}
// veins of a block, expects empty vein vectors
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();
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->d->p, addr + off.veinvector, 4);
uint32_t size = p_veins.getSize();
veins.reserve (size);
// read all veins
for (uint32_t i = 0; i < size;i++)
{
t_vein v;
t_frozenliquidvein fv;
// read the vein pointer from the vector
uint32_t temp = * (uint32_t *) p_veins[i];
uint32_t type = g_pProcess->readDWord(temp);
try_again:
if(type == off.vein_mineral_vptr)
{
// read the vein data (dereference pointer)
g_pProcess->read (temp, sizeof(t_vein), (uint8_t *) &v);
v.address_of = temp;
// store it in the vector
veins.push_back (v);
}
else if(type == off.vein_ice_vptr)
{
// read the ice vein data (dereference pointer)
g_pProcess->read (temp, sizeof(t_frozenliquidvein), (uint8_t *) &fv);
// store it in the vector
ices.push_back (fv);
}
else if(g_pProcess->readClassName(type) == "block_square_event_frozen_liquid")
{
off.vein_ice_vptr = type;
goto try_again;
}
else if(g_pProcess->readClassName(type) == "block_square_event_mineral")
{
off.vein_mineral_vptr = type;
goto try_again;
}
}
return true;
}
return false;
}
// getter for map size
void Maps::getSize (uint32_t& x, uint32_t& y, uint32_t& z)
{
x = d->x_block_count;
y = d->y_block_count;
z = d->z_block_count;
}
/*
__int16 __userpurge GetGeologicalRegion<ax>(__int16 block_X<cx>, int X<ebx>, __int16 block_Y<di>, int block_addr<esi>, int Y)
{
char bio_off; // al@1
int tile_designation; // ecx@1
__int64 corrected_x; // qax@1
__int64 corrected_y; // qax@1
int difY; // eax@9
int difX; // edx@9
signed __int64 bio_off_2; // qax@9
signed __int64 bio_off_2_; // qtt@9
__int16 result; // ax@23
corrected_x = reg_off_x + (block_X + (signed int)*(_WORD *)(block_addr + 0x90)) / 48;
*(_WORD *)X = ((BYTE4(corrected_x) & 0xF) + (_DWORD)corrected_x) >> 4;
corrected_y = reg_off_y + (block_Y + (signed int)*(_WORD *)(block_addr + 0x92)) / 48;
*(_WORD *)Y = ((BYTE4(corrected_y) & 0xF) + (_DWORD)corrected_y) >> 4;
tile_designation = *(_DWORD *)(block_addr + 4 * (block_Y + 16 * block_X) + 0x29C);
bio_off = 0;
if ( tile_designation & 0x20000 )
bio_off = 1;
if ( tile_designation & 0x40000 )
bio_off |= 2u;
if ( tile_designation & 0x80000 )
bio_off |= 4u;
if ( tile_designation & 0x100000 )
bio_off |= 8u;
bio_off_2 = *(_BYTE *)(bio_off + block_addr + 0x1D9C);
bio_off_2_ = bio_off_2;
difY = bio_off_2 / 3;
difX = bio_off_2_ % 3;
if ( !difX )
--*(_WORD *)X;
if ( difX == 2 )
++*(_WORD *)X;
if ( !difY )
--*(_WORD *)Y;
if ( difY == 2 )
++*(_WORD *)Y;
if ( *(_WORD *)X < 0 )
*(_WORD *)X = 0;
if ( *(_WORD *)Y < 0 )
*(_WORD *)Y = 0;
if ( *(_WORD *)X >= (_WORD)World_size )
*(_WORD *)X = World_size - 1;
result = HIWORD(World_size);
if ( *(_WORD *)Y >= HIWORD(World_size) )
{
result = HIWORD(World_size) - 1;
*(_WORD *)Y = HIWORD(World_size) - 1;
}
return result;
}
*/
//vector<uint16_t> v_geology[eBiomeCount];
bool Maps::ReadGeology (vector < vector <uint16_t> >& assign)
{
memory_info * minfo = d->d->offset_descriptor;
// get needed addresses and offsets. Now this is what I call crazy.
int region_x_offset = minfo->getAddress ("region_x");
int region_y_offset = minfo->getAddress ("region_y");
int region_z_offset = minfo->getAddress ("region_z");
/* <Address name="geoblock_vector">0x16AF52C</Address>
<Address name="ptr2_region_array">0x16AF574</Address>*/
int world_regions = minfo->getAddress ("ptr2_region_array");
int region_size = minfo->getHexValue ("region_size");
int region_geo_index_offset = minfo->getOffset ("region_geo_index_off");
int world_geoblocks_vector = minfo->getAddress ("geoblock_vector");
int world_size_x = minfo->getAddress ("world_size_x");
int world_size_y = minfo->getAddress ("world_size_y");
int geolayer_geoblock_offset = minfo->getOffset ("geolayer_geoblock_offset");
int type_inside_geolayer = minfo->getOffset ("type_inside_geolayer");
uint32_t regionX, regionY, regionZ;
uint16_t worldSizeX, worldSizeY;
// read position of the region inside DF world
g_pProcess->readDWord (region_x_offset, regionX);
g_pProcess->readDWord (region_y_offset, regionY);
g_pProcess->readDWord (region_z_offset, regionZ);
// get world size
g_pProcess->readWord (world_size_x, worldSizeX);
g_pProcess->readWord (world_size_y, worldSizeY);
// get pointer to first part of 2d array of regions
uint32_t regions = g_pProcess->readDWord (world_regions);
// read the geoblock vector
DfVector geoblocks (d->d->p, world_geoblocks_vector, 4);
// iterate over 8 surrounding regions + local region
for (int i = eNorthWest; i < eBiomeCount; i++)
{
// check against worldmap boundaries, fix if needed
int bioRX = regionX / 16 + (i % 3) - 1;
if (bioRX < 0) bioRX = 0;
if (bioRX >= worldSizeX) bioRX = worldSizeX - 1;
int bioRY = regionY / 16 + (i / 3) - 1;
if (bioRY < 0) bioRY = 0;
if (bioRY >= worldSizeY) bioRY = worldSizeY - 1;
/// regions are a 2d array. consists of pointers to arrays of regions
/// regions are of region_size size
// get pointer to column of regions
uint32_t geoX;
g_pProcess->readDWord (regions + bioRX*4, geoX);
// get index into geoblock vector
uint16_t geoindex;
g_pProcess->readWord (geoX + bioRY*region_size + region_geo_index_offset, geoindex);
/// geology blocks are assigned to regions from a vector
// get the geoblock from the geoblock vector using the geoindex
// read the matgloss pointer from the vector into temp
uint32_t geoblock_off = * (uint32_t *) geoblocks[geoindex];
/// geology blocks have a vector of layer descriptors
// get the vector with pointer to layers
DfVector geolayers (d->d->p, geoblock_off + geolayer_geoblock_offset , 4); // let's hope
// make sure we don't load crap
assert (geolayers.getSize() > 0 && geolayers.getSize() <= 16);
/// layer descriptor has a field that determines the type of stone/soil
d->v_geology[i].reserve (geolayers.getSize());
// finally, read the layer matgloss
for (uint32_t j = 0;j < geolayers.getSize();j++)
{
// read pointer to a layer
uint32_t geol_offset = * (uint32_t *) geolayers[j];
// read word at pointer + 2, store in our geology vectors
d->v_geology[i].push_back (g_pProcess->readWord (geol_offset + type_inside_geolayer));
}
}
assign.clear();
assign.reserve (eBiomeCount);
for (int i = 0; i < eBiomeCount;i++)
{
assign.push_back (d->v_geology[i]);
}
return true;
}

@ -0,0 +1,214 @@
/*
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 "../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:
if ( a1
|| (signed int)a2 < 0
|| a2 >= (inorg_end - inorg_start) >> 2
|| (v13 = *(_DWORD *)(inorg_start + 4 * a2), !v13) )
{
switch ( a1 )
{
case 1:
sub_40FDD0("AMBER");
break;
case 2:
sub_40FDD0("CORAL");
break;
case 3:
sub_40FDD0("GLASS_GREEN");
break;
case 4:
sub_40FDD0("GLASS_CLEAR");
break;
case 5:
sub_40FDD0("GLASS_CRYSTAL");
break;
case 6:
sub_40FDD0("WATER");
break;
case 7:
sub_40FDD0("COAL");
break;
case 8:
sub_40FDD0("POTASH");
break;
case 9:
sub_40FDD0("ASH");
break;
case 10:
sub_40FDD0("PEARLASH");
break;
case 11:
sub_40FDD0("LYE");
break;
case 12:
sub_40FDD0("MUD");
break;
case 13:
sub_40FDD0("VOMIT");
break;
case 14:
sub_40FDD0("SALT");
break;
case 15:
sub_40FDD0("FILTH_B");
break;
case 16:
sub_40FDD0("FILTH_Y");
break;
case 17:
sub_40FDD0("UNKNOWN_SUBSTANCE");
break;
case 18:
sub_40FDD0("GRIME");
break;
default:
sub_40A070("NONE", 4u);
break;
}
result = sub_40A070("NONE", 4u);
if ( a1 == 7 )
{
result = a2;
if ( a2 )
{
if ( a2 == 1 )
result = sub_40A070("CHARCOAL", 8u);
}
else
{
result = sub_40A070("COKE", 4u);
}
}
}
else
{
sub_40A070("INORGANIC", 9u);
result = sub_409CA0(v13, 0, -1);
}
}
*/
/*
bool API::ReadInorganicMaterials (vector<t_matgloss> & inorganic)
{
memory_info * minfo = d->offset_descriptor;
int matgloss_address = minfo->getAddress ("mat_inorganics");
int matgloss_colors = minfo->getOffset ("material_color");
int matgloss_stone_name_offset = minfo->getOffset("matgloss_stone_name");
DfVector p_matgloss (d->p, matgloss_address, 4);
uint32_t size = p_matgloss.getSize();
inorganic.resize (0);
inorganic.reserve (size);
for (uint32_t i = 0; i < size;i++)
{
// read the matgloss pointer from the vector into temp
uint32_t temp = * (uint32_t *) p_matgloss[i];
// read the string pointed at by
t_matgloss mat;
//cout << temp << endl;
//fill_char_buf(mat.id, d->p->readSTLString(temp)); // reads a C string given an address
d->p->readSTLString (temp, mat.id, 128);
d->p->readSTLString (temp+matgloss_stone_name_offset, mat.name, 128);
mat.fore = (uint8_t) g_pProcess->readWord (temp + matgloss_colors);
mat.back = (uint8_t) g_pProcess->readWord (temp + matgloss_colors + 2);
mat.bright = (uint8_t) g_pProcess->readWord (temp + matgloss_colors + 4);
inorganic.push_back (mat);
}
return true;
}
*/
// good for now
inline bool ReadNamesOnly(Process* p, uint32_t address, vector<t_matgloss> & names)
{
DfVector p_matgloss (p, address, 4);
uint32_t size = p_matgloss.getSize();
names.clear();
names.reserve (size);
for (uint32_t i = 0; i < size;i++)
{
t_matgloss mat;
p->readSTLString (*(uint32_t *) p_matgloss[i], mat.id, 128);
names.push_back(mat);
}
return true;
}
bool Materials::ReadInorganicMaterials (vector<t_matgloss> & inorganic)
{
return ReadNamesOnly(d->p, d->offset_descriptor->getAddress ("mat_inorganics"), inorganic );
}
bool Materials::ReadOrganicMaterials (vector<t_matgloss> & organic)
{
return ReadNamesOnly(d->p, d->offset_descriptor->getAddress ("mat_organics_all"), organic );
}
bool Materials::ReadWoodMaterials (vector<t_matgloss> & trees)
{
return ReadNamesOnly(d->p, d->offset_descriptor->getAddress ("mat_organics_trees"), trees );
}
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 Materials::ReadCreatureTypes (vector<t_matgloss> & creatures)
{
return ReadNamesOnly(d->p, d->offset_descriptor->getAddress ("mat_creature_types"), creatures );
return true;
}
*/
bool Materials::ReadCreatureTypes (vector<t_matgloss> & creatures)
{
return ReadNamesOnly(d->p, d->offset_descriptor->getAddress ("creature_type_vector"), creatures );
return true;
}

@ -0,0 +1,133 @@
/*
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 "../private/APIPrivate.h"
#include "modules/Position.h"
#include "DFMemInfo.h"
#include "DFProcess.h"
using namespace DFHack;
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->Inited = true;
return true;
}
catch (Error::MissingMemoryDefinition&)
{
d->cursorWindowInited = false;
throw;
}
}
*/
bool Position::getViewCoords (int32_t &x, int32_t &y, int32_t &z)
{
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);
return true;
}
//FIXME: confine writing of coords to map bounds?
bool Position::setViewCoords (const int32_t x, const int32_t y, const int32_t z)
{
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 Position::getCursorCoords (int32_t &x, int32_t &y, int32_t &z)
{
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];
y = coords[1];
z = coords[2];
if (x == -30000) return false;
return true;
}
//FIXME: confine writing of coords to map bounds?
bool Position::setCursorCoords (const int32_t x, const int32_t y, const int32_t z)
{
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 Position::getWindowSize (int32_t &width, int32_t &height)
{
if(!d->Inited) return false;
int32_t coords[2];
g_pProcess->read (d->window_dims_offset, 2*sizeof (int32_t), (uint8_t *) coords);
width = coords[0];
height = coords[1];
return true;
}

@ -0,0 +1,114 @@
/*
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.
*/
/*
* WARNING: Only include from API modules
*/
#ifndef APIPRIVATE_H_INCLUDED
#define APIPRIVATE_H_INCLUDED
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();
// names, used by a few other modules.
void readName(t_name & name, uint32_t address);
// get the name offsets
bool InitReadNames();
uint32_t name_firstname_offset;
uint32_t name_nickname_offset;
uint32_t name_words_offset;
bool namesInited;
ProcessEnumerator* pm;
Process* p;
char * shm_start;
memory_info* offset_descriptor;
string xml;
// Modules
Creatures * creatures;
Maps * maps;
Position * position;
Gui * gui;
Materials * materials;
/*
uint32_t item_material_offset;
uint32_t note_foreground_offset;
uint32_t note_background_offset;
uint32_t note_name_offset;
uint32_t note_xyz_offset;
uint32_t hotkey_start;
uint32_t hotkey_mode_offset;
uint32_t hotkey_xyz_offset;
uint32_t hotkey_size;
uint32_t settlement_name_offset;
uint32_t settlement_world_xy_offset;
uint32_t settlement_local_xy_offset;
uint32_t dwarf_lang_table_offset;
bool constructionsInited;
bool buildingsInited;
bool effectsInited;
bool vegetationInited;
bool itemsInited;
bool notesInited;
bool hotkeyInited;
bool settlementsInited;
bool nameTablesInited;
uint32_t tree_offset;
DfVector *p_cons;
DfVector *p_bld;
DfVector *p_effect;
DfVector *p_veg;
DfVector *p_itm;
DfVector *p_notes;
DfVector *p_settlements;
DfVector *p_current_settlement;
*/
};
}
#endif

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from pydfhack import *
from ctypes import *

@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
from distutils.core import setup, Extension
e = Extension("pydfhack",
sources=["UnionBase.cpp", "pydfhack.cpp", "DF_API.cpp"],
include_dirs=["..\\"],
include_dirs=["..\\include"],
library_dirs=["..\\..\\output"],
libraries=["libdfhack"])

@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
import pydfhack

@ -0,0 +1,87 @@
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix)
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 MOD_CREATURES2010_H
#define MOD_CREATURES2010_H
namespace DFHack
{
namespace Creatures2010
{
#define CREATURES2010_VERSION 1
typedef struct
{
// creature offsets
uint32_t creature_vector;
uint32_t creature_pos_offset;
uint32_t creature_profession_offset;
uint32_t creature_race_offset;
uint32_t creature_flags1_offset;
uint32_t creature_flags2_offset;
uint32_t creature_name_offset;
uint32_t creature_sex_offset;
uint32_t creature_id_offset;
uint32_t creature_labors_offset;
uint32_t creature_happiness_offset;
uint32_t creature_artifact_name_offset;
// name offsets (needed for reading creature names)
uint32_t name_firstname_offset;
uint32_t name_nickname_offset;
uint32_t name_words_offset;
} creature_offsets;
typedef struct
{
bool inited;
creature_offsets offsets;
} creature_modulestate;
typedef struct
{
shm_cmd cmd[SHM_MAX_CLIENTS]; // MANDATORY!
// box
uint32_t x;
uint32_t y;
uint32_t z;
uint32_t x2;
uint32_t y2;
uint32_t z2;
// starting index
int32_t index;
} shm_creature_hdr;
enum CREATURE_COMMAND
{
CREATURE_INIT = 0, // initialization
CREATURE_FIND_IN_BOX,
CREATURE_AT_INDEX,
NUM_CREATURE_CMDS
};
DFPP_module Init(void);
}
}
#endif

@ -27,8 +27,10 @@ distribution.
namespace DFHack
{
namespace Creatures
namespace Server
{
namespace Creatures
{
#define CREATURES40D_VERSION 1
typedef struct
@ -100,6 +102,7 @@ enum CREATURE_COMMAND
};
DFPP_module Init(void);
}
}
}

@ -30,10 +30,12 @@ distribution.
namespace DFHack
{
namespace Maps
namespace Server
{
namespace Maps
{
#define MAPS_VERSION 2
#define MAPS_VERSION 3
typedef struct
{
uint32_t map_offset;// = d->offset_descriptor->getAddress ("map_data");
@ -47,6 +49,7 @@ typedef struct
uint32_t veinvector;// = d->offset_descriptor->getOffset ("v_vein");
uint32_t vein_mineral_vptr;
uint32_t vein_ice_vptr;
uint32_t vein_spatter_vptr;
/*
GEOLOGY
uint32_t region_x_offset;// = minfo->getAddress ("region_x");
@ -94,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

@ -9,6 +9,10 @@ ENDIF(UNIX)
ADD_EXECUTABLE(dfattachtest attachtest.cpp)
TARGET_LINK_LIBRARIES(dfattachtest dfhack)
# buildingsdump - dump buildings and their raw data filtered by type
#ADD_EXECUTABLE(dfbuildingsdump buildingsdump.cpp)
#TARGET_LINK_LIBRARIES(dfbuildingsdump dfhack)
# a benchmark program, reads the map 1000x
ADD_EXECUTABLE(dfexpbench expbench.cpp)
TARGET_LINK_LIBRARIES(dfexpbench dfhack)
@ -17,10 +21,6 @@ TARGET_LINK_LIBRARIES(dfexpbench dfhack)
ADD_EXECUTABLE(dfcreaturedump creaturedump.cpp)
TARGET_LINK_LIBRARIES(dfcreaturedump dfhack)
# buildingsdump - dump buildings and their raw data filtered by type
ADD_EXECUTABLE(dfbuildingsdump buildingsdump.cpp)
TARGET_LINK_LIBRARIES(dfbuildingsdump dfhack)
# materialtest - just list the first material of each type
ADD_EXECUTABLE(dfmaterialtest materialtest.cpp)
TARGET_LINK_LIBRARIES(dfmaterialtest dfhack)
@ -35,13 +35,13 @@ ADD_EXECUTABLE(dfsuspend suspendtest.cpp)
TARGET_LINK_LIBRARIES(dfsuspend dfhack)
# itemdump - dump the item under the cursor
ADD_EXECUTABLE(dfitemdump dfitemdump.cpp)
TARGET_LINK_LIBRARIES(dfitemdump dfhack)
# ADD_EXECUTABLE(dfitemdump dfitemdump.cpp)
# TARGET_LINK_LIBRARIES(dfitemdump dfhack)
# hotkeynotedump - dumps the hotkeys and notes for the loaded map
# Author: belal
ADD_EXECUTABLE(dfhotkeynotedump hotkeynotedump.cpp)
TARGET_LINK_LIBRARIES(dfhotkeynotedump dfhack)
# ADD_EXECUTABLE(dfhotkeynotedump hotkeynotedump.cpp)
# TARGET_LINK_LIBRARIES(dfhotkeynotedump dfhack)
# findnameindexes
# Author: belal
@ -50,17 +50,17 @@ TARGET_LINK_LIBRARIES(dfhotkeynotedump dfhack)
# settlementdump - dumps the settlements on the loaded map
# Author: belal
ADD_EXECUTABLE(dfsettlementdump settlementdump.cpp)
TARGET_LINK_LIBRARIES(dfsettlementdump dfhack)
# ADD_EXECUTABLE(dfsettlementdump settlementdump.cpp)
# TARGET_LINK_LIBRARIES(dfsettlementdump dfhack)
# veccheck - read vector values at address
#ADD_EXECUTABLE(dfvecc veccheck.cpp)
#TARGET_LINK_LIBRARIES(dfvecc dfhack)
ADD_EXECUTABLE(dfvecc veccheck.cpp)
TARGET_LINK_LIBRARIES(dfvecc dfhack)
# catsplosion - Makes every cat pregnant, and almost due...
# Author: Zhentar
ADD_EXECUTABLE(dfcatsplosion catsplosion.cpp)
TARGET_LINK_LIBRARIES(dfcatsplosion dfhack)
# ADD_EXECUTABLE(dfcatsplosion catsplosion.cpp)
# TARGET_LINK_LIBRARIES(dfcatsplosion dfhack)
IF(UNIX)
SET(CURSES_NEED_WIDE "YES")
@ -101,25 +101,25 @@ ENDIF(UNIX)
# renamer - change the custom names and professions of creatures, sends keys to
# df directly
# Author: belal
ADD_EXECUTABLE(dfrenamer renamer.cpp)
TARGET_LINK_LIBRARIES(dfrenamer dfhack)
#ADD_EXECUTABLE(dfrenamer renamer.cpp)
#TARGET_LINK_LIBRARIES(dfrenamer dfhack)
IF(UNIX)
install(TARGETS
dfattachtest
dfexpbench
dfcreaturedump
dfbuildingsdump
#dfexpbench
#dfcreaturedump
#dfbuildingsdump
dfmaterialtest
dfposition
dfsuspend
dfitemdump
dfhotkeynotedump
#dfitemdump
#dfhotkeynotedump
#dffindnameindexes
dfsettlementdump
dfrenamer
#dfvecc
dfcatsplosion
#dfsettlementdump
#dfrenamer
dfvecc
#dfcatsplosion
RUNTIME DESTINATION bin
)
ENDIF(UNIX)

@ -20,7 +20,7 @@ using namespace std;
#include <DFHackAPI.h>
#include <DFMemInfo.h>
#include <DFProcess.h>
#include <argstream/argstream.h>
#include <argstream.h>
vector<DFHack::t_matgloss> creaturestypes;

@ -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 )
@ -43,8 +45,8 @@ vector< vector <DFHack::t_itemType> > itemTypes;
DFHack::memory_info *mem;
vector< vector<string> > englishWords;
vector< vector<string> > foreignWords;
likeType printLike(DFHack::t_like like, const matGlosses & mat,const vector< vector <DFHack::t_itemType> > & itemTypes)
/*
likeType printLike40d(DFHack::t_like like, const matGlosses & mat,const vector< vector <DFHack::t_itemType> > & itemTypes)
{ // The function in DF which prints out the likes is a monster, it is a huge switch statement with tons of options and calls a ton of other functions as well,
//so I am not going to try and put all the possibilites here, only the low hanging fruit, with stones and metals, as well as items,
//you can easily find good canidates for military duty for instance
@ -147,7 +149,7 @@ likeType printLike(DFHack::t_like like, const matGlosses & mat,const vector< vec
}
return(FAIL);
}
*/
void printCreature(DFHack::API & DF, const DFHack::t_creature & creature)
{
@ -163,13 +165,15 @@ void printCreature(DFHack::API & DF, const DFHack::t_creature & creature)
cout << ", nick name: " << creature.name.nickname;
addendl = true;
}
/*
string transName = DF.TranslateName(creature.name,englishWords,foreignWords,false);
if(!transName.empty())
{
cout << ", trans name: " << transName;
addendl=true;
}
*/
/*
cout << ", likes: ";
for(uint32_t i = 0;i<creature.numLikes; i++)
{
@ -177,13 +181,15 @@ void printCreature(DFHack::API & DF, const DFHack::t_creature & creature)
{
cout << ", ";
}
}
}
*/
if(addendl)
{
cout << endl;
addendl = false;
}
cout << "profession: " << mem->getProfession(creature.profession) << "(" << (int) creature.profession << ")";
/*
if(creature.custom_profession[0])
{
cout << ", custom profession: " << creature.custom_profession;
@ -192,16 +198,18 @@ void printCreature(DFHack::API & DF, const DFHack::t_creature & creature)
{
cout << ", current job: " << mem->getJob(creature.current_job.jobId);
}
*/
cout << endl;
cout << "happiness: " << creature.happiness << ", strength: " << creature.strength << ", agility: "
<< creature.agility << ", toughness: " << creature.toughness << ", money: " << creature.money << ", id: " << creature.id;
cout << "happiness: " << creature.happiness /*<< ", strength: " << creature.strength << ", agility: "
<< creature.agility << ", toughness: " << creature.toughness << ", money: " << creature.money*/ << ", id: " << creature.id;
/*
if(creature.squad_leader_id != -1)
{
cout << ", squad_leader_id: " << creature.squad_leader_id;
}
if(creature.mood != -1){
cout << ", mood: " << creature.mood << " ";
}
}*/
cout << ", sex: ";
if(creature.sex == 0)
{
@ -212,10 +220,11 @@ void printCreature(DFHack::API & DF, const DFHack::t_creature & creature)
cout <<"Male";
}
cout << endl;
/*
if(creature.pregnancy_timer > 0)
cout << "gives birth in " << creature.pregnancy_timer/1200 << " days. ";
cout << "Blood: " << creature.blood_current << "/" << creature.blood_max << " bleeding: " << creature.bleed_rate;
*/
cout << endl;
/*
@ -288,10 +297,12 @@ void printCreature(DFHack::API & DF, const DFHack::t_creature & creature)
cout << "from the underworld, ";
}
cout << endl;
if(creature.flags1.bits.had_mood && (creature.mood == -1 || creature.mood == 8 ) ){
/*
if(creature.flags1.bits.had_mood && (creature.mood == -1 || creature.mood == 8 ) )
{
string artifact_name = DF.TranslateName(creature.artifact_name,englishWords,foreignWords,false);
cout << "artifact: " << artifact_name << endl;
}
}*/
cout << endl;
}
@ -312,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
@ -329,38 +343,40 @@ int main (void)
#endif
return 1;
}
/*
DF.ReadItemTypes(itemTypes);
DF.ReadPlantMatgloss(mat.plantMat);
DF.ReadWoodMatgloss(mat.woodMat);
DF.ReadStoneMatgloss(mat.stoneMat);
DF.ReadMetalMatgloss(mat.metalMat);
DF.ReadCreatureMatgloss(mat.creatureMat);
*/
mem = DF.getMemoryInfo();
// get stone matgloss mapping
if(!DF.ReadCreatureMatgloss(creaturestypes))
if(!Materials->ReadCreatureTypes(creaturestypes))
{
cerr << "Can't get the creature types." << endl;
return 1;
}
/*
if(!DF.InitReadNameTables(englishWords,foreignWords))
{
cerr << "Can't get name tables" << endl;
return 1;
}
DF.InitViewAndCursor();
*/
//DF.InitViewAndCursor();
for(uint32_t i = 0; i < numCreatures; i++)
{
DFHack::t_creature temp;
DF.ReadCreature(i,temp);
if(string(creaturestypes[temp.type].id) == "DWARF")
Creatures->ReadCreature(i,temp);
//if(string(creaturestypes[temp.type].id) == "DWARF")
{
cout << "index " << i << " ";
printCreature(DF,temp);
}
}
/*
uint32_t currentIdx;
DFHack::t_creature currentCreature;
DF.getCurrentCursorCreature(currentIdx);
@ -368,7 +384,8 @@ 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);

@ -1,15 +1,52 @@
// Just show some position data
#include <iostream>
#include <climits>
#include <integers.h>
#include <vector>
#include <sstream>
#include <ctime>
using namespace std;
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFProcess.h>
#include <DFMemInfo.h>
#include <DFVector.h>
#include <modules/Materials.h>
int main (void)
void DumpObjStr0Vector (const char * name, DFHack::Process *p, uint32_t addr)
{
cout << "----==== " << name << " ====----" << endl;
DFHack::DfVector vect(p,addr,4);
for(int i = 0; i < vect.getSize();i++)
{
uint32_t addr = *(uint32_t *) vect[i];
cout << p->readSTLString(addr) << endl;
}
cout << endl;
}
void DumpDWordVector (const char * name, DFHack::Process *p, uint32_t addr)
{
cout << "----==== " << name << " ====----" << endl;
DFHack::DfVector vect(p,addr,4);
for(int i = 0; i < vect.getSize();i++)
{
uint32_t number = *(uint32_t *) vect[i];
cout << number << endl;
}
cout << endl;
}
int main (int numargs, const char ** args)
{
uint32_t addr;
if (numargs == 2)
{
istringstream input (args[1],istringstream::in);
input >> std::hex >> addr;
}
DFHack::API DF("Memory.xml");
try
{
@ -24,48 +61,62 @@ int main (void)
return 1;
}
if(!DF.InitMap())
{
cerr << "No map loaded, it would be unsafe to enumerate materials" << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
DF.DestroyMap();
DFHack::Process* p = DF.getProcess();
DFHack::memory_info* mem = DF.getMemoryInfo();
DFHack::Materials *Materials = DF.getMaterials();
vector <DFHack::t_matgloss> Woods;
DF.ReadWoodMatgloss(Woods);
//const vector<string> * names = mem->getClassIDMapping();
/*
DumpObjStr0Vector("Material templates",p, mem->getAddress("mat_templates"));
vector <DFHack::t_matgloss> Plants;
DF.ReadPlantMatgloss(Plants);
DumpObjStr0Vector("Inorganics",p, mem->getAddress("mat_inorganics"));
vector <DFHack::t_matgloss> Metals;
DF.ReadMetalMatgloss(Metals);
DumpObjStr0Vector("Organics - all",p, mem->getAddress("mat_organics_all"));
vector <DFHack::t_matgloss> Stones;
DF.ReadStoneMatgloss(Stones);
DumpObjStr0Vector("Organics - plants",p, mem->getAddress("mat_organics_plants"));
vector <DFHack::t_matgloss> CreatureTypes;
DF.ReadCreatureMatgloss(CreatureTypes);
DumpDWordVector("Maybe map between all organics and plants",p, mem->getAddress("mat_unk1_numbers"));
cout << "Wood: " << Woods[0].id << endl;
cout << "Plant: " << Plants[0].id << endl;
cout << "Metal: " << Metals[0].id << endl;
cout << "Stone: " << Stones[0].id << endl;
cout << "Creature: " << CreatureTypes[0].id << endl;
cout << endl;
cout << "Dumping all stones!" << endl;
for(uint32_t i = 0; i < Stones.size();i++)
DumpObjStr0Vector("Trees/wood",p, mem->getAddress("mat_organics_trees"));
DumpDWordVector("Maybe map between all organics and trees",p, mem->getAddress("mat_unk2_numbers"));
DumpObjStr0Vector("Body material templates",p, mem->getAddress("mat_body_material_templates"));
DumpObjStr0Vector("Body detail plans",p, mem->getAddress("mat_body_detail_plans"));
DumpObjStr0Vector("Bodies",p, mem->getAddress("mat_bodies"));
DumpObjStr0Vector("Bodygloss",p, mem->getAddress("mat_bodygloss"));
DumpObjStr0Vector("Creature variations",p, mem->getAddress("mat_creature_variations"));
*/
cout << "----==== Inorganic ====----" << endl;
vector<DFHack::t_matgloss> matgloss;
Materials->ReadInorganicMaterials (matgloss);
for(int i = 0; i < matgloss.size();i++)
{
cout << Stones[i].id << "$" << endl;;
cout << matgloss[i].id << endl;
}
DF.Detach();
cout << endl << "----==== Organic ====----" << endl;
vector<DFHack::t_matgloss> organic;
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;
Materials->ReadCreatureTypes (matgloss);
for(int i = 0; i < matgloss.size();i++)
{
cout << matgloss[i].id << endl;
}
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;
cin.ignore();
#endif
return 0;
}

@ -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,31 +28,23 @@ int main (void)
#endif
return 1;
}
if (DF.InitViewAndCursor())
if (Position)
{
int32_t x,y,z;
if(DF.getViewCoords(x,y,z))
int32_t width,height;
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(Position->getWindowSize(width,height))
cout << "window size : " << width << " " << height << endl;
}
else
{
cerr << "cursor and window parameters are unsupported on your version of DF" << endl;
}
if(DF.InitViewSize())
{
int32_t width,height;
if(DF.getWindowSize(width,height))
cout << "window size : " << width << " " << height << endl;
}
else
{
cerr << "view size is unsupported on your version of DF" << endl;
}
if(!DF.Detach())
{
cerr << "Can't detach from DF" << endl;

@ -12,6 +12,31 @@ using namespace std;
#include <DFHackAPI.h>
#include <DFProcess.h>
#include <DFMemInfo.h>
#include <DFVector.h>
void DumpObjStr0Vector (const char * name, DFHack::Process *p, uint32_t addr)
{
cout << "----==== " << name << " ====----" << endl;
DFHack::DfVector vect(p,addr,4);
for(int i = 0; i < vect.getSize();i++)
{
uint32_t addr = *(uint32_t *) vect[i];
cout << p->readSTLString(addr) << endl;
}
cout << endl;
}
void DumpDWordVector (const char * name, DFHack::Process *p, uint32_t addr)
{
cout << "----==== " << name << " ====----" << endl;
DFHack::DfVector vect(p,addr,4);
for(int i = 0; i < vect.getSize();i++)
{
uint32_t number = *(uint32_t *) vect[i];
cout << number << endl;
}
cout << endl;
}
int main (int numargs, const char ** args)
{
@ -37,23 +62,35 @@ int main (int numargs, const char ** args)
DFHack::Process* p = DF.getProcess();
DFHack::memory_info* mem = DF.getMemoryInfo();
const vector<string> * names = mem->getClassIDMapping();
for(int i = 0; i < names->size();i++)
{
cout << i << " " << names->at(i) << endl;
}
/*
#ifdef LINUX_BUILD
cout << "start 0x" << hex << p->readDWord(addr+0x0) << endl;
cout << "end 0x" << hex << p->readDWord(addr+0x4) << endl;
cout << "cap 0x" << hex << p->readDWord(addr+0x8) << endl;
#else
cout << "start 0x" << hex << p->readDWord(addr+0x4) << endl;
cout << "end 0x" << hex << p->readDWord(addr+0x8) << endl;
cout << "cap 0x" << hex << p->readDWord(addr+0xC) << endl;
#endif
*/
//const vector<string> * names = mem->getClassIDMapping();
DumpObjStr0Vector("Material templates",p, mem->getAddress("mat_templates"));
DumpObjStr0Vector("Inorganics",p, mem->getAddress("mat_inorganics"));
DumpObjStr0Vector("Organics - all",p, mem->getAddress("mat_organics_all"));
DumpObjStr0Vector("Organics - plants",p, mem->getAddress("mat_organics_plants"));
DumpDWordVector("Maybe map between all organics and plants",p, mem->getAddress("mat_unk1_numbers"));
DumpObjStr0Vector("Trees/wood",p, mem->getAddress("mat_organics_trees"));
DumpDWordVector("Maybe map between all organics and trees",p, mem->getAddress("mat_unk2_numbers"));
DumpObjStr0Vector("Body material templates",p, mem->getAddress("mat_body_material_templates"));
DumpObjStr0Vector("Body detail plans",p, mem->getAddress("mat_body_detail_plans"));
DumpObjStr0Vector("Bodies",p, mem->getAddress("mat_bodies"));
DumpObjStr0Vector("Bodygloss",p, mem->getAddress("mat_bodygloss"));
DumpObjStr0Vector("Creature variations",p, mem->getAddress("mat_creature_variations"));
DumpObjStr0Vector("Creature types",p, mem->getAddress("mat_creature_types"));
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;
cin.ignore();

@ -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,26 +335,26 @@ 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.ReadStoneMatgloss(stonetypes))
if(!Mats->ReadInorganicMaterials(stonetypes))
{
error = "Can't read stone types.";
pDF = 0;
finish(0);
}
/*
// get region geology
if(!DF.ReadGeology( layerassign ))
{
@ -352,7 +362,7 @@ main(int argc, char *argv[])
pDF = 0;
finish(0);
}
*/
// FIXME: could fail on small forts
int cursorX = x_max/2 - 1;
int cursorY = y_max/2 - 1;
@ -439,6 +449,7 @@ main(int argc, char *argv[])
// Supend, read/write data
DF.Suspend();
uint32_t effectnum;
/*
if(DF.InitReadEffects(effectnum))
{
for(uint32_t i = 0; i < effectnum;i++)
@ -448,23 +459,24 @@ main(int argc, char *argv[])
effects.push_back(effect);
}
}
*/
for(int i = -1; i <= 1; i++) for(int j = -1; j <= 1; j++)
{
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
@ -479,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)
@ -488,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);
}
}
}
@ -507,7 +519,7 @@ main(int argc, char *argv[])
{
int color = COLOR_BLACK;
color = pickColor(Block->tiletypes[x][y]);
if(!Block->designation[x][y].bits.hidden)
//if(!Block->designation[x][y].bits.hidden)
/*{
puttile(x+(i+1)*16,y+(j+1)*16,Block->tiletypes[x][y], color);
}
@ -524,7 +536,7 @@ main(int argc, char *argv[])
{
for(uint zz = 0; zz < effects.size();zz++)
{
if(effects[zz].z == cursorZ && !effects[zz].isHidden)
if(effects[zz].z == cursorZ /*&& !effects[zz].isHidden*/)
{
// block coords to tile coords
uint16_t x = effects[zz].x - (cursorX * 16);
@ -562,10 +574,14 @@ main(int argc, char *argv[])
//iterate through the bits
for (uint32_t k = 0; k< 16;k++)
{
/*
if(tileTypeTable[blocks[1][1].tiletypes[k][j]].m != VEIN)
continue;
*/
/*
if(blocks[1][1].designation[k][j].bits.hidden)
continue;
*/
// and the bit array with a one-bit mask, check if the bit is set
bool set = !!(((1 << k) & veinVector[realvein].assignment[j]) >> k);
if(set)
@ -575,7 +591,7 @@ main(int argc, char *argv[])
}
}
gotoxy(0,51);
cprintf("Mineral: %s",stonetypes[veinVector[vein].type].name);
cprintf("Mineral: %s",stonetypes[veinVector[vein].type].id);
}
else
{

File diff suppressed because it is too large Load Diff

@ -1,301 +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 memory_info;
class Process;
class DFHACK_EXPORT API
{
class Private;
Private * 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();
/*
* Query the DF's GUI state
*/
///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();
/*
* Matgloss. next four methods look very similar. I could use two and move the processing one level up...
* I'll keep it like this, even with the code duplication as it will hopefully get more features and separate data types later.
* Yay for nebulous plans for a rock survey tool that tracks how much of which metal could be smelted from available resorces
*/
bool ReadStoneMatgloss(std::vector<t_matgloss> & output);
bool ReadWoodMatgloss (std::vector<t_matgloss> & output);
bool ReadMetalMatgloss(std::vector<t_matgloss> & output);
bool ReadPlantMatgloss(std::vector<t_matgloss> & output);
bool ReadPlantMatgloss (std::vector<t_matglossPlant> & plants);
bool ReadCreatureMatgloss(std::vector<t_matgloss> & output);
// 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);
/*
* Constructions (costructed walls, floors, ramps, etc...)
*/
/// start reading constructions. numconstructions is an output - total constructions present
bool InitReadConstructions( uint32_t & numconstructions );
/// read a construiction at index
bool ReadConstruction(const int32_t index, t_construction & construction);
/// cleanup after reading constructions
void FinishReadConstructions();
/*
* Buildings - also includes zones and stockpiles
*/
bool InitReadBuildings ( uint32_t & numbuildings );
bool ReadBuilding(const int32_t index, t_building & building);
void FinishReadBuildings();
/*
* 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();
/*
* 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);
void FinishReadCreatures();
/// 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);
/// write labors of a creature (for Dwarf Therapist)
bool WriteLabors(const uint32_t index, uint8_t labors[NUM_CREATURE_LABORS]);
/*
* 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();
/*
* Hotkeys (DF's zoom locations)
*/
bool InitReadHotkeys( );
bool ReadHotkeys(t_hotkey hotkeys[]);
/*
* Cursor, and view 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);
/// get the creature vector index of the creature currently under DF' cursor
bool getCurrentCursorCreature (uint32_t & creature_index);
/*
* Window size in tiles
*/
bool InitViewSize();
bool getWindowSize(int32_t & width, int32_t & height);
/*
* DF translation tables and name translation
*/
bool InitReadNameTables (std::vector< std::vector<std::string> > & translations , std::vector< std::vector<std::string> > & foreign_languages);
void FinishReadNameTables();
std::string TranslateName(const t_name & name,const std::vector< std::vector<std::string> > & translations ,const std::vector< std::vector<std::string> > & foreign_languages, bool inEnglish=true);
/*
* 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
*/
memory_info *getMemoryInfo();
Process * getProcess();
DFWindow * getWindow();
/*
// FIXME: BAD!
bool ReadAllMatgloss(vector< vector< string > > & all);
*/
bool ReadItemTypes(std::vector< std::vector< t_itemType > > & itemTypes);
};
} // namespace DFHack
#endif // SIMPLEAPI_H_INCLUDED

@ -1 +0,0 @@
import pydfhack

@ -1,361 +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 BUILD_DFHACK_LIB
# define BUILD_DFHACK_LIB
#endif
#include "DFCommon.h"
#include "DFHackAPI.h"
#include "DFHackAPIc.h"
#ifdef LINUX_BUILD
# ifndef secure_strcpy
# define secure_strcpy(dst, size, buf) strcpy((dst), (buf))
# endif
#else
# if defined(_MSC_VER) && _MSC_VER >= 1400
# ifndef secure_strcpy
# define secure_strcpy(dst, size, buf) strcpy_s((dst), (size), (buf))
# endif
# else
# ifndef secure_strcpy
# define secure_strcpy(dst, size, buf) strcpy((dst), (buf))
# endif
# endif
#endif
#ifdef __cplusplus
extern "C"
{
#endif
// The C interface for vector management
DFHACKAPI void DFHackAPIVector_free (DFHackAPIVectorC *vector)
{
uint32_t i;
switch (vector->type)
{
case DFHackAPIVectorTypeC_Normal:
delete [] (vector->data);
break;
case DFHackAPIVectorTypeC_Matgloss:
delete [] ( (t_matgloss *) vector->data);
break;
case DFHackAPIVectorTypeC_Uint16:
delete [] ( (uint16_t *) vector->data);
break;
case DFHackAPIVectorTypeC_Vein:
delete [] ( (t_vein *) vector->data);
break;
case DFHackAPIVectorTypeC_String:
for (i = 0; i < vector->length; i++)
delete [] ( (char **) vector->data) [i];
delete [] ( (char **) vector->data);
break;
case DFHackAPIVectorTypeC_Recursive:
for (i = 0; i < vector->length; i++)
DFHackAPIVector_free (& ( (DFHackAPIVectorC *) vector->data) [i]);
delete [] ( (DFHackAPIVectorC *) vector->data);
break;
}
vector->type = DFHackAPIVectorTypeC_Normal;
vector->length = 0;
vector->data = 0;
}
// The C interface to DFHackAPI (for multiple language support)
DFHACKAPI DFHackAPIHandle CreateDFHackAPI (const char *path_to_xml)
{
return new DFHackAPIImpl (path_to_xml);
}
DFHACKAPI void DestroyDFHackAPI (DFHackAPIHandle self)
{
if (self != NULL)
delete self;
}
DFHACKAPI bool DFHackAPI_Attach (DFHackAPIHandle self)
{
return self->Attach();
}
DFHACKAPI bool DFHackAPI_Detach (DFHackAPIHandle self)
{
return self->Detach();
}
DFHACKAPI bool DFHackAPI_isAttached (DFHackAPIHandle self)
{
return self->isAttached();
}
DFHACKAPI bool DFHackAPI_ReadStoneMatgloss (DFHackAPIHandle self, DFHackAPIVectorC *output)
{
vector<t_matgloss> result;
uint32_t i;
bool retn = self->ReadStoneMatgloss (result);
output->type = DFHackAPIVectorTypeC_Matgloss;
output->length = result.size();
output->data = new t_matgloss[output->length];
for (i = 0; i < output->length; i++)
( (t_matgloss *) output->data) [i] = result[i];
return retn;
}
DFHACKAPI bool DFHackAPI_ReadWoodMatgloss (DFHackAPIHandle self, DFHackAPIVectorC *output)
{
vector<t_matgloss> result;
uint32_t i;
bool retn = self->ReadWoodMatgloss (result);
output->type = DFHackAPIVectorTypeC_Matgloss;
output->length = result.size();
output->data = new t_matgloss[output->length];
for (i = 0; i < output->length; i++)
( (t_matgloss *) output->data) [i] = result[i];
return retn;
}
DFHACKAPI bool DFHackAPI_ReadMetalMatgloss (DFHackAPIHandle self, DFHackAPIVectorC *output)
{
vector<t_matgloss> result;
uint32_t i;
bool retn = self->ReadMetalMatgloss (result);
output->type = DFHackAPIVectorTypeC_Matgloss;
output->length = result.size();
output->data = new t_matgloss[output->length];
for (i = 0; i < output->length; i++)
( (t_matgloss *) output->data) [i] = result[i];
return retn;
}
DFHACKAPI bool DFHackAPI_ReadPlantMatgloss (DFHackAPIHandle self, DFHackAPIVectorC *output)
{
vector<t_matgloss> result;
uint32_t i;
bool retn = self->ReadPlantMatgloss (result);
output->type = DFHackAPIVectorTypeC_Matgloss;
output->length = result.size();
output->data = new t_matgloss[output->length];
for (i = 0; i < output->length; i++)
( (t_matgloss *) output->data) [i] = result[i];
return retn;
}
DFHACKAPI bool DFHackAPI_ReadCreatureMatgloss (DFHackAPIHandle self, DFHackAPIVectorC *output)
{
vector<t_matgloss> result;
uint32_t i;
bool retn = self->ReadCreatureMatgloss (result);
output->type = DFHackAPIVectorTypeC_Matgloss;
output->length = result.size();
output->data = new t_matgloss[output->length];
for (i = 0; i < output->length; i++)
( (t_matgloss *) output->data) [i] = result[i];
return retn;
}
DFHACKAPI bool DFHackAPI_ReadGeology (DFHackAPIHandle self, DFHackAPIVectorC *assign)
{
vector< vector<uint16_t> > result;
uint32_t i, j;
bool retn = self->ReadGeology (result);
assign->type = DFHackAPIVectorTypeC_Recursive;
assign->length = result.size();
assign->data = new DFHackAPIVectorC[assign->length];
for (i = 0; i < assign->length; i++)
{
DFHackAPIVectorC &current = ( (DFHackAPIVectorC *) assign->data) [i];
current.type = DFHackAPIVectorTypeC_Uint16;
current.length = result[i].size();
current.data = new uint16_t[current.length];
for (j = 0; j < current.length; j++)
( (uint16_t *) current.data) [j] = result[i][j];
}
return retn;
}
DFHACKAPI bool DFHackAPI_InitMap (DFHackAPIHandle self)
{
return self->InitMap();
}
DFHACKAPI bool DFHackAPI_DestroyMap (DFHackAPIHandle self)
{
return self->DestroyMap();
}
DFHACKAPI void DFHackAPI_getSize (DFHackAPIHandle self, uint32_t* x, uint32_t* y, uint32_t* z)
{
return self->getSize (*x, *y, *z);
}
DFHACKAPI bool DFHackAPI_isValidBlock (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz)
{
return self->isValidBlock (blockx, blocky, blockz);
}
DFHACKAPI bool DFHackAPI_ReadTileTypes (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint16_t *buffer)
{
return self->ReadTileTypes (blockx, blocky, blockz, buffer);
}
DFHACKAPI bool DFHackAPI_WriteTileTypes (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint16_t *buffer)
{
return self->WriteTileTypes (blockx, blocky, blockz, buffer);
}
DFHACKAPI bool DFHackAPI_ReadDesignations (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer)
{
return self->ReadDesignations (blockx, blocky, blockz, buffer);
}
DFHACKAPI bool DFHackAPI_WriteDesignations (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer)
{
return self->WriteDesignations (blockx, blocky, blockz, buffer);
}
DFHACKAPI bool DFHackAPI_ReadOccupancy (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer)
{
return self->ReadOccupancy (blockx, blocky, blockz, buffer);
}
DFHACKAPI bool DFHackAPI_WriteOccupancy (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer)
{
return self->WriteOccupancy (blockx, blocky, blockz, buffer);
}
DFHACKAPI bool DFHackAPI_ReadRegionOffsets (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint8_t *buffer)
{
return self->ReadRegionOffsets (blockx, blocky, blockz, buffer);
}
DFHACKAPI bool DFHackAPI_ReadVeins (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, DFHackAPIVectorC * veins)
{
vector<t_vein> result;
uint32_t i;
bool retn = self->ReadVeins (blockx, blocky, blockz, result);
veins->type = DFHackAPIVectorTypeC_Vein;
veins->length = result.size();
veins->data = new t_vein[veins->length];
for (i = 0; i < veins->length; i++)
( (t_vein *) veins->data) [i] = result[i];
return retn;
}
DFHACKAPI uint32_t DFHackAPI_InitReadConstructions (DFHackAPIHandle self)
{
return self->InitReadConstructions();
}
DFHACKAPI bool DFHackAPI_ReadConstruction (DFHackAPIHandle self, const uint32_t *index, t_construction * construction)
{
return self->ReadConstruction (*index, *construction);
}
DFHACKAPI void DFHackAPI_FinishReadConstructions (DFHackAPIHandle self)
{
self->FinishReadConstructions();
}
DFHACKAPI uint32_t DFHackAPI_InitReadBuildings (DFHackAPIHandle self, DFHackAPIVectorC *v_buildingtypes)
{
vector<string> result;
uint32_t i;
uint32_t retn = self->InitReadBuildings (result);
v_buildingtypes->type = DFHackAPIVectorTypeC_String;
v_buildingtypes->length = result.size();
v_buildingtypes->data = new char *[v_buildingtypes->length];
for (i = 0; i < v_buildingtypes->length; i++)
{
char *str = new char[result[i].size() + 1];
secure_strcpy (str, result[i].size() + 1, result[i].c_str());
( (char **) v_buildingtypes->data) [i] = str;
}
return retn;
}
DFHACKAPI bool DFHackAPI_ReadBuilding (DFHackAPIHandle self, const uint32_t *index, t_building * building)
{
return self->ReadBuilding (*index, *building);
}
DFHACKAPI void DFHackAPI_FinishReadBuildings (DFHackAPIHandle self)
{
self->FinishReadBuildings();
}
DFHACKAPI uint32_t DFHackAPI_InitReadVegetation (DFHackAPIHandle self)
{
return self->InitReadVegetation();
}
DFHACKAPI bool DFHackAPI_ReadVegetation (DFHackAPIHandle self, const uint32_t *index, t_tree_desc * shrubbery)
{
return self->ReadVegetation (*index, *shrubbery);
}
DFHACKAPI void DFHackAPI_FinishReadVegetation (DFHackAPIHandle self)
{
self->FinishReadVegetation();
}
DFHACKAPI uint32_t DFHackAPI_InitReadCreatures (DFHackAPIHandle self)
{
return self->InitReadCreatures();
}
DFHACKAPI bool DFHackAPI_ReadCreature (DFHackAPIHandle self, const uint32_t *index, t_creature * furball)
{
return self->ReadCreature (*index, *furball);
}
DFHACKAPI void DFHackAPI_FinishReadCreatures (DFHackAPIHandle self)
{
self->FinishReadCreatures();
}
DFHACKAPI void DFHackAPI_ReadRaw (DFHackAPIHandle self, const uint32_t &offset, const uint32_t &size, uint8_t *target)
{
self->ReadRaw(offset, size, target);
}
#ifdef __cplusplus
}
#endif

@ -1,483 +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 SIMPLEAPIC_H_INCLUDED
#define SIMPLEAPIC_H_INCLUDED
#ifdef LINUX_BUILD
# ifndef DFHACKAPI
# define DFHACKAPI extern "C"
# endif
#else
# ifdef BUILD_DFHACK_LIB
# ifndef DFHACKAPI
# define DFHACKAPI extern "C" __declspec(dllexport)
# endif
# else
# ifndef DFHACKAPI
# define DFHACKAPI extern "C" __declspec(dllimport)
# endif
# endif
#endif
#include "integers.h"
#ifdef __cplusplus
# include <vector>
# include <string>
using namespace std;
#endif
typedef enum DFHackAPIVectorTypeC
{
DFHackAPIVectorTypeC_Normal, // array of struct's
DFHackAPIVectorTypeC_Matgloss, // array of t_matgloss's
DFHackAPIVectorTypeC_Uint16, // array of uint16_t's
DFHackAPIVectorTypeC_Vein, // array of t_vein's
DFHackAPIVectorTypeC_String, // array of const char *'s
DFHackAPIVectorTypeC_Recursive, // array of DFHackAPIVectorC struct's
DFHackAPIVectorTypeC_DWord = 0xffffffff // Unused
} DFHackAPIVectorTypeC;
typedef struct DFHackAPIVectorC
{
void *data;
uint32_t length;
DFHackAPIVectorTypeC type;
} DFHackAPIVector;
#ifdef __cplusplus
typedef class DFHackAPIImpl *DFHackAPIHandle;
#else
typedef struct DFHackAPIImpl *DFHackAPIHandle;
typedef char bool;
#endif
#ifdef __cplusplus
extern "C"
{
#endif // __cplusplus
// The C interface for vector management
DFHACKAPI void DFHackAPIVector_free (DFHackAPIVectorC *vector);
// The C interface to DFHackAPI (for multiple language support)
DFHACKAPI DFHackAPIHandle CreateDFHackAPI (const char *path_to_xml);
DFHACKAPI void DestroyDFHackAPI (DFHackAPIHandle self);
DFHACKAPI bool DFHackAPI_Attach (DFHackAPIHandle self);
DFHACKAPI bool DFHackAPI_Detach (DFHackAPIHandle self);
DFHACKAPI bool DFHackAPI_isAttached (DFHackAPIHandle self);
DFHACKAPI bool DFHackAPI_ReadStoneMatgloss (DFHackAPIHandle self, DFHackAPIVectorC *output);
DFHACKAPI bool DFHackAPI_ReadWoodMatgloss (DFHackAPIHandle self, DFHackAPIVectorC *output);
DFHACKAPI bool DFHackAPI_ReadMetalMatgloss (DFHackAPIHandle self, DFHackAPIVectorC *output);
DFHACKAPI bool DFHackAPI_ReadPlantMatgloss (DFHackAPIHandle self, DFHackAPIVectorC *output);
DFHACKAPI bool DFHackAPI_ReadCreatureMatgloss (DFHackAPIHandle self, DFHackAPIVectorC *output);
DFHACKAPI bool DFHackAPI_ReadGeology (DFHackAPIHandle self, DFHackAPIVectorC *assign);
DFHACKAPI bool DFHackAPI_InitMap (DFHackAPIHandle self);
DFHACKAPI bool DFHackAPI_DestroyMap (DFHackAPIHandle self);
DFHACKAPI void DFHackAPI_getSize (DFHackAPIHandle self, uint32_t* x, uint32_t* y, uint32_t* z);
DFHACKAPI bool DFHackAPI_isValidBlock (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz);
DFHACKAPI bool DFHackAPI_ReadTileTypes (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint16_t *buffer);
DFHACKAPI bool DFHackAPI_WriteTileTypes (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint16_t *buffer);
DFHACKAPI bool DFHackAPI_ReadDesignations (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer);
DFHACKAPI bool DFHackAPI_WriteDesignations (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer);
DFHACKAPI bool DFHackAPI_ReadOccupancy (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer);
DFHACKAPI bool DFHackAPI_WriteOccupancy (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer);
DFHACKAPI bool DFHackAPI_ReadRegionOffsets (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint8_t *buffer);
DFHACKAPI bool DFHackAPI_ReadVeins (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, DFHackAPIVectorC * veins);
DFHACKAPI uint32_t DFHackAPI_InitReadConstructions (DFHackAPIHandle self);
DFHACKAPI bool DFHackAPI_ReadConstruction (DFHackAPIHandle self, const uint32_t *index, t_construction * construction);
DFHACKAPI void DFHackAPI_FinishReadConstructions (DFHackAPIHandle self);
DFHACKAPI uint32_t DFHackAPI_InitReadBuildings (DFHackAPIHandle self, DFHackAPIVectorC *v_buildingtypes);
DFHACKAPI bool DFHackAPI_ReadBuilding (DFHackAPIHandle self, const uint32_t *index, t_building * building);
DFHACKAPI void DFHackAPI_FinishReadBuildings (DFHackAPIHandle self);
DFHACKAPI uint32_t DFHackAPI_InitReadVegetation (DFHackAPIHandle self);
DFHACKAPI bool DFHackAPI_ReadVegetation (DFHackAPIHandle self, const uint32_t *index, t_tree_desc * shrubbery);
DFHACKAPI void DFHackAPI_FinishReadVegetation (DFHackAPIHandle self);
DFHACKAPI uint32_t DFHackAPI_InitReadCreatures (DFHackAPIHandle self);
DFHACKAPI bool DFHackAPI_ReadCreature (DFHackAPIHandle self, const uint32_t *index, t_creature * furball);
DFHACKAPI void DFHackAPI_FinishReadCreatures (DFHackAPIHandle self);
DFHACKAPI void DFHackAPI_ReadRaw (DFHackAPIHandle self, const uint32_t &offset, const uint32_t &size, uint8_t *target);
#ifdef __cplusplus
}
#endif // __cplusplus
// C++ wrappers for C API that use vectors
#ifdef __cplusplus
inline bool DFHackAPI_ReadStoneMatgloss (DFHackAPIHandle self, vector<t_matgloss> & output)
{
DFHackAPIVectorC vector;
bool result = DFHackAPI_ReadStoneMatgloss (self, &vector);
uint32_t i;
for (i = 0; i < vector.length; i++)
output.push_back ( ( (t_matgloss *) vector.data) [i]);
DFHackAPIVector_free (&vector);
return result;
}
inline bool DFHackAPI_ReadWoodMatgloss (DFHackAPIHandle self, vector<t_matgloss> & output)
{
DFHackAPIVectorC vector;
bool result = DFHackAPI_ReadWoodMatgloss (self, &vector);
uint32_t i;
for (i = 0; i < vector.length; i++)
output.push_back ( ( (t_matgloss *) vector.data) [i]);
DFHackAPIVector_free (&vector);
return result;
}
inline bool DFHackAPI_ReadMetalMatgloss (DFHackAPIHandle self, vector<t_matgloss> & output)
{
DFHackAPIVectorC vector;
bool result = DFHackAPI_ReadMetalMatgloss (self, &vector);
uint32_t i;
for (i = 0; i < vector.length; i++)
output.push_back ( ( (t_matgloss *) vector.data) [i]);
DFHackAPIVector_free (&vector);
return result;
}
inline bool DFHackAPI_ReadPlantMatgloss (DFHackAPIHandle self, vector<t_matgloss> & output)
{
DFHackAPIVectorC vector;
bool result = DFHackAPI_ReadPlantMatgloss (self, &vector);
uint32_t i;
for (i = 0; i < vector.length; i++)
output.push_back ( ( (t_matgloss *) vector.data) [i]);
DFHackAPIVector_free (&vector);
return result;
}
inline bool DFHackAPI_ReadCreatureMatgloss (DFHackAPIHandle self, vector<t_matgloss> & output)
{
DFHackAPIVectorC vector;
bool result = DFHackAPI_ReadCreatureMatgloss (self, &vector);
uint32_t i;
for (i = 0; i < vector.length; i++)
output.push_back ( ( (t_matgloss *) vector.data) [i]);
DFHackAPIVector_free (&vector);
return result;
}
inline bool DFHackAPI_ReadGeology (DFHackAPIHandle self, vector< vector<uint16_t> > &assign)
{
DFHackAPIVectorC vec;
bool result = DFHackAPI_ReadGeology (self, &vec);
uint32_t i;
for (i = 0; i < vec.length; i++)
{
DFHackAPIVectorC &current = ( (DFHackAPIVectorC *) vec.data) [i];
vector<uint16_t> fill;
uint32_t j;
for (j = 0; j < current.length; j++)
fill.push_back ( ( (uint16_t *) current.data) [j]);
assign.push_back (fill);
}
DFHackAPIVector_free (&vec);
return result;
}
inline bool DFHackAPI_ReadVeins (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, vector <t_vein> & veins)
{
DFHackAPIVectorC vector;
bool result = DFHackAPI_ReadVeins (self, blockx, blocky, blockz, &vector);
uint32_t i;
for (i = 0; i < vector.length; i++)
veins.push_back ( ( (t_vein *) vector.data) [i]);
DFHackAPIVector_free (&vector);
return result;
}
inline uint32_t DFHackAPI_InitReadBuildings (DFHackAPIHandle self, vector <string> &v_buildingtypes)
{
DFHackAPIVectorC vector;
uint32_t result = DFHackAPI_InitReadBuildings (self, &vector);
uint32_t i;
for (i = 0; i < vector.length; i++)
v_buildingtypes.push_back ( ( (const char **) vector.data) [i]);
DFHackAPIVector_free (&vector);
return result;
}
#endif // __cplusplus
// C++ class wrapper for C DFHackAPI
#ifdef __cplusplus
class CDFHackAPI
{
DFHackAPIHandle handle;
public:
CDFHackAPI (const string &path_to_xml)
: handle (CreateDFHackAPI (path_to_xml.c_str()))
{
if (handle == NULL)
{
// TODO: handle failure
}
}
inline ~CDFHackAPI()
{
DestroyDFHackAPI (handle);
handle = NULL;
}
inline bool Attach()
{
return DFHackAPI_Attach (handle);
}
inline bool Detach()
{
return DFHackAPI_Detach (handle);
}
inline bool isAttached()
{
return DFHackAPI_isAttached (handle);
}
/**
* 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
*/
inline bool ReadStoneMatgloss (vector<t_matgloss> & output)
{
return DFHackAPI_ReadStoneMatgloss (handle, output);
}
inline bool ReadWoodMatgloss (vector<t_matgloss> & output)
{
return DFHackAPI_ReadWoodMatgloss (handle, output);
}
inline bool ReadMetalMatgloss (vector<t_matgloss> & output)
{
return DFHackAPI_ReadMetalMatgloss (handle, output);
}
inline bool ReadPlantMatgloss (vector<t_matgloss> & output)
{
return DFHackAPI_ReadPlantMatgloss (handle, output);
}
inline bool ReadCreatureMatgloss (vector<t_matgloss> & output)
{
return DFHackAPI_ReadCreatureMatgloss (handle, output);
}
// 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];
}
}
}
*/
inline bool ReadGeology (vector < vector <uint16_t> >& assign)
{
return DFHackAPI_ReadGeology (handle, assign);
}
/*
* BLOCK DATA
*/
/// allocate and read pointers to map blocks
inline bool InitMap()
{
return DFHackAPI_InitMap (handle);
}
/// destroy the mapblock cache
inline bool DestroyMap()
{
return DFHackAPI_DestroyMap (handle);
}
/// get size of the map in tiles
inline void getSize (uint32_t& x, uint32_t& y, uint32_t& z)
{
DFHackAPI_getSize (handle, &x, &y, &z);
}
/**
* Return false/0 on failure, buffer allocated by client app, 256 items long
*/
inline bool isValidBlock (uint32_t blockx, uint32_t blocky, uint32_t blockz)
{
return DFHackAPI_isValidBlock (handle, blockx, blocky, blockz);
}
inline bool ReadTileTypes (uint32_t blockx, uint32_t blocky, uint32_t blockz, uint16_t *buffer) // 256 * sizeof(uint16_t)
{
return DFHackAPI_ReadTileTypes (handle, blockx, blocky, blockz, buffer);
}
inline bool WriteTileTypes (uint32_t blockx, uint32_t blocky, uint32_t blockz, uint16_t *buffer) // 256 * sizeof(uint16_t)
{
return DFHackAPI_WriteTileTypes (handle, blockx, blocky, blockz, buffer);
}
inline bool ReadDesignations (uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer) // 256 * sizeof(uint32_t)
{
return DFHackAPI_ReadDesignations (handle, blockx, blocky, blockz, buffer);
}
inline bool WriteDesignations (uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer)
{
return DFHackAPI_WriteDesignations (handle, blockx, blocky, blockz, buffer);
}
inline bool ReadOccupancy (uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer) // 256 * sizeof(uint32_t)
{
return DFHackAPI_ReadOccupancy (handle, blockx, blocky, blockz, buffer);
}
inline bool WriteOccupancy (uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer) // 256 * sizeof(uint32_t)
{
return DFHackAPI_WriteOccupancy (handle, blockx, blocky, blockz, buffer);
}
/// read region offsets of a block
inline bool ReadRegionOffsets (uint32_t blockx, uint32_t blocky, uint32_t blockz, uint8_t *buffer) // 16 * sizeof(uint8_t)
{
return DFHackAPI_ReadRegionOffsets (handle, blockx, blocky, blockz, buffer);
}
/// read aggregated veins of a block
inline bool ReadVeins (uint32_t blockx, uint32_t blocky, uint32_t blockz, vector <t_vein> & veins)
{
return DFHackAPI_ReadVeins (handle, blockx, blocky, blockz, veins);
}
/**
* Buildings, constructions, plants, all pretty straighforward. InitReadBuildings returns all the building types as a mapping between a numeric values and strings
*/
inline uint32_t InitReadConstructions()
{
return DFHackAPI_InitReadConstructions (handle);
}
inline bool ReadConstruction (const uint32_t &index, t_construction & construction)
{
return DFHackAPI_ReadConstruction (handle, &index, & construction);
}
inline void FinishReadConstructions()
{
DFHackAPI_FinishReadConstructions (handle);
}
inline uint32_t InitReadBuildings (vector <string> &v_buildingtypes)
{
return DFHackAPI_InitReadBuildings (handle, v_buildingtypes);
}
inline bool ReadBuilding (const uint32_t &index, t_building & building)
{
return DFHackAPI_ReadBuilding (handle, &index, &building);
}
inline void FinishReadBuildings()
{
DFHackAPI_FinishReadBuildings (handle);
}
inline uint32_t InitReadVegetation()
{
return DFHackAPI_InitReadVegetation (handle);
}
inline bool ReadVegetation (const uint32_t &index, t_tree_desc & shrubbery)
{
return DFHackAPI_ReadVegetation (handle, &index, &shrubbery);
}
inline void FinishReadVegetation()
{
DFHackAPI_FinishReadVegetation (handle);
}
inline uint32_t InitReadCreatures()
{
return DFHackAPI_InitReadCreatures (handle);
}
inline bool ReadCreature (const uint32_t &index, t_creature & furball)
{
return DFHackAPI_ReadCreature (handle, &index, &furball);
}
inline void FinishReadCreatures()
{
DFHackAPI_FinishReadCreatures (handle);
}
inline void ReadRaw(const uint32_t &offset, const uint32_t &size, uint8_t *target)
{
DFHackAPI_ReadRaw(handle, offset, size, target);
}
};
#endif // __cplusplus
#endif // SIMPLEAPIC_H_INCLUDED

@ -1,182 +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.
*/
/**
* DO NOT USE THIS FILE DIRECTLY! USE MemAccess.h INSTEAD!
*/
#include "integers.h"
inline
uint8_t MreadByte (const uint32_t &offset)
{
return ptrace(PTRACE_PEEKDATA,g_ProcessHandle, offset, NULL);
}
inline
void MreadByte (const uint32_t &offset, uint8_t &val )
{
val = ptrace(PTRACE_PEEKDATA,g_ProcessHandle, offset, NULL);
}
inline
uint16_t MreadWord (const uint32_t &offset)
{
return ptrace(PTRACE_PEEKDATA,g_ProcessHandle, offset, NULL);
}
inline
void MreadWord (const uint32_t &offset, uint16_t &val)
{
val = ptrace(PTRACE_PEEKDATA,g_ProcessHandle, offset, NULL);
}
inline
uint32_t MreadDWord (const uint32_t &offset)
{
return ptrace(PTRACE_PEEKDATA,g_ProcessHandle, offset, NULL);
}
inline
void MreadDWord (const uint32_t &offset, uint32_t &val)
{
val = ptrace(PTRACE_PEEKDATA,g_ProcessHandle, offset, NULL);
}
// extremely terrible braindamage
inline
bool Mread ( uint32_t offset, uint32_t size, uint8_t *target)
{
uint8_t *mover = target;
while (size)
{
if(size >= 4)
{
* (uint32_t *)mover = MreadDWord(offset);
mover+=4;
offset +=4;
size -=4;
}
else if(size >= 2)
{
* (uint16_t *)mover = MreadWord(offset);
mover+=2;
offset +=2;
size -=2;
}
else if(size == 1)
{
* (uint8_t *)mover = MreadByte(offset);
mover+=1;
offset ++;
size --;
}
}
return true;
}
/*
* WRITING
*/
inline
void MwriteDWord (uint32_t offset, uint32_t data)
{
ptrace(PTRACE_POKEDATA,g_ProcessHandle, offset, data);
}
// using these is expensive.
inline
void MwriteWord (uint32_t offset, uint16_t data)
{
uint32_t orig = MreadDWord(offset);
orig &= 0xFFFF0000;
orig |= data;
/*
orig |= 0x0000FFFF;
orig &= data;
*/
ptrace(PTRACE_POKEDATA,g_ProcessHandle, offset, orig);
}
inline
void MwriteByte (uint32_t offset, uint8_t data)
{
uint32_t orig = MreadDWord(offset);
orig &= 0xFFFFFF00;
orig |= data;
/*
orig |= 0x000000FF;
orig &= data;
*/
ptrace(PTRACE_POKEDATA,g_ProcessHandle, offset, orig);
}
// blah. I hate the kernel devs for crippling /proc/PID/mem. THIS IS RIDICULOUS
inline
bool Mwrite (uint32_t offset, uint32_t size, uint8_t *source)
{
uint32_t indexptr = 0;
while (size > 0)
{
// default: we push 4 bytes
if(size >= 4)
{
MwriteDWord(offset, *(uint32_t *) (source + indexptr));
offset +=4;
indexptr +=4;
size -=4;
}
// last is either three or 2 bytes
else if(size >= 2)
{
MwriteWord(offset, *(uint16_t *) (source + indexptr));
offset +=2;
indexptr +=2;
size -=2;
}
// finishing move
else if(size == 1)
{
MwriteByte(offset, *(uint8_t *) (source + indexptr));
return true;
}
}
}
inline
const std::string MreadCString (uint32_t offset)
{
std::string temp;
char temp_c[256];
int counter = 0;
char r;
do
{
r = MreadByte(offset+counter);
temp_c[counter] = r;
counter++;
} while (r && counter < 255);
temp_c[counter] = 0;
temp = temp_c;
return temp;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -1,12 +1,11 @@
# -*- coding: utf-8 -*-
import pydfhack
x = pydfhack.API("Memory.xml")
y = pydfhack.MatglossVector()
DF = pydfhack.API("Memory.xml")
if x.Attach():
success,stones = x.ReadStoneMatgloss()
if DF.Attach():
success,stones = DF.ReadStoneMatgloss()
if success:
print "Dumping all stone"
for matgloss in stones:
print "ID %s, name %s" % (matgloss.id, matgloss.name)
x.Detach()
DF.Detach()

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More