Merge branch 'master' of git://github.com/peterix/dfhack

develop
simon 2010-05-27 11:22:58 +02:00
commit 04a16c4996
219 changed files with 3684 additions and 3096 deletions

@ -8,36 +8,25 @@ if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW) cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy) endif(COMMAND cmake_policy)
if("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}") if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
message(SEND_ERROR "In-source builds are not allowed.") message(SEND_ERROR "In-source builds are not allowed.")
endif("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}") endif("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
IF(NOT DEFINED CMAKE_BUILD_TYPE) IF(NOT DEFINED CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.") SET(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.")
ENDIF(NOT DEFINED CMAKE_BUILD_TYPE) ENDIF(NOT DEFINED CMAKE_BUILD_TYPE)
SET(SO_MAJOR_VERSION "0") SET( LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/output CACHE PATH "Output directory for the dfhack library" )
SET(SO_MINOR_VERSION "0") SET( EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/output CACHE PATH "Output directory for the dfhack tools" )
SET(SO_BUILD_VERSION "1")
SET(SO_VERSION "${SO_MAJOR_VERSION}.${SO_MINOR_VERSION}.${SO_BUILD_VERSION}")
include_directories (${CMAKE_SOURCE_DIR}/library/include/)
include_directories (${CMAKE_SOURCE_DIR}/library/shm/)
include_directories (${CMAKE_SOURCE_DIR}/library/depends/md5/)
include_directories (${CMAKE_SOURCE_DIR}/library/depends/tinyxml/)
include_directories (${CMAKE_SOURCE_DIR}/library/depends/argstream/)
SET( LIBRARY_OUTPUT_PATH ${dfhack_SOURCE_DIR}/output CACHE PATH "Output directory for the dfhack library" ) add_subdirectory (library)
SET( EXECUTABLE_OUTPUT_PATH ${dfhack_SOURCE_DIR}/output CACHE PATH "Output directory for the dfhack tools" ) #add_subdirectory (dfhack/python)
SET( CMAKE_SWIG_OUTDIR ${dfhack_SOURCE_DIR}/output CACHE PATH "Global output directory for swig generated language wrappers" ) add_subdirectory (tools/examples)
add_subdirectory (tools/playground)
include_directories (${CMAKE_SOURCE_DIR}/dfhack/include/) add_subdirectory (tools/supported)
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/python)
#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)

@ -50,6 +50,91 @@ repository is welcome and the right thing to do :)
At the time of writing there's no API reference or documentation. The code does At the time of writing there's no API reference or documentation. The code does
have a lot of comments though (and getting better all the time). have a lot of comments though (and getting better all the time).
Contributing to DFHack
----------------------
Several things should be kept in mind when contributing to DFHack.
**** Coding style ****
DFhack uses ANSI formatting and four spaces as indentation. Line endings are
UNIX. The files use UTF-8 encoding. Code not following this won't make me happy,
because I'll have to fix it. There's a good chance I'll make *you* fix it ;)
**** How to get new code into DFHack ****
You can send patches or make a clone of the github repo and ask me on the
IRC channel to pull your code in. I'll review it and see if there are any
problems. I'll fix them if they are minor.
Fixes are higher in priority. If you want to work on something, but don't
know what, check out http://github.com/peterix/dfhack/issues -- this is also
a good place to dump new ideas and/or bugs that need fixing.
**** Layout for tools ****
Tools live in the tools/ folder. There, they are split into three categories:
distributed: these tools get distributed with binary releases and are installed
by doing 'make install' on linux. They are supposed to be stable
and supported. Experimental, useless, buggy or untested stuff
doesn't belong here.
examples : examples are tools that aren't very useful, but show how DF
and DFHack work. They should use only DFHack API functions.
No actual hacking or 'magic offsets' are allowed.
playground : This is a catch-all folder for tools that aren't ready to be
examples or be distributed in binary releases. All new tools
should start here. They can contain actual hacking, magic values
and other nasty business.
**** Modules - what are they? ****
DFHack uses modules to partition sets of features into manageable chunks.
A module can have both client and server side.
Client side is the part that goes into the main library and is generally
written in C++. It is exposed to the users of DFHack.
Server side is used inside DF and serves to accelerate the client modules.
This is written mostly in C style.
There's a Core module that shouldn't be changed, because it defines
the basic commands like reading and writing raw data. The client parts
for the Core module are the various implementations of the Process
interface.
A good example of a module is Maps. Named the same in both client and
server, it allows accelerating the reading of map blocks.
Communication between modules happens by using shared memory. This is
pretty fast, but needs quite a bit of care to not break.
**** Dependencies ****
Internal : either part of the codebase or statically linked.
External : linked as dynamic loaded libraries (.dll, .so, etc.)
If you want to add dependencies, think twice about it. All internal dependencies
for core dfhack should be either public domain or require attribution at most.
Internal dependencies for tools can be either that, or any Free Software
licenses.
** Current internal dependencies **
tinyxml : used by core dfhack to read offset definitions from Memory.xml
md5 : an implementation of the MD5 hash algorithm. Used for identifying
DF binaries on Linux.
argstream: Allows reading terminal application arguments. GPL!
** Current external dependencies **
wide-character ncurses : used for the veinlook tool on Linux.
python 2.6 : required for building and using the python bindings.
** Build-time dependencies **
cmake: you need cmake to generate the build system and some configuration
headers
Tools Tools
----- -----
@ -79,6 +164,7 @@ be useful and are cross-platform just like the library itself.
- Your tool here: Write one ;) - Your tool here: Write one ;)
Memory offset definitions Memory offset definitions
------------------------- -------------------------

@ -1,150 +0,0 @@
# don't use this file directly. use the one in the root folder of the project
SET(PROJECT_HDRS
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/DFHackAPI_C.h
include/integers.h
shm/shms.h
)
SET(PROJECT_SRCS
DFMemInfo.cpp
DFMemInfoManager.cpp
DFHackAPI.cpp
APIPrivate.cpp
DFTileTypes.cpp
DFVector.cpp
DFHackAPI_C.cpp
DFTypes_C.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/World.cpp
modules/Items.cpp
modules/Maps.cpp
modules/Materials.cpp
modules/Position.cpp
modules/Translation.cpp
modules/Vegetation.cpp
modules/Buildings.cpp
modules/Constructions.cpp
modules/Position_C.cpp
modules/Gui_C.cpp
modules/Materials_C.cpp
modules/Buildings_C.cpp
modules/Constructions_C.cpp
modules/Maps_C.cpp
modules/Vegetation_C.cpp
modules/Creatures_C.cpp
modules/Translation_C.cpp
modules/Items_C.cpp
)
SET(PROJECT_HDRS_LINUX
)
SET(PROJECT_HDRS_WINDOWS
include/stdint_win.h
)
SET(PROJECT_SRCS_LINUX
DFProcess-linux.cpp
DFProcess-linux-SHM.cpp
DFProcess-linux-wine.cpp
DFWindow-linux.cpp
DFProcessEnumerator-linux.cpp
)
SET(PROJECT_SRCS_WINDOWS
DFProcess-windows.cpp
DFProcess-windows-SHM.cpp
DFWindow-windows.cpp
DFProcessEnumerator-windows.cpp
)
IF(UNIX)
LIST(APPEND PROJECT_HDRS ${PROJECT_HDRS_LINUX})
LIST(APPEND PROJECT_SRCS ${PROJECT_SRCS_LINUX})
ELSE(UNIX)
LIST(APPEND PROJECT_HDRS ${PROJECT_HDRS_WINDOWS})
LIST(APPEND PROJECT_SRCS ${PROJECT_SRCS_WINDOWS})
ENDIF(UNIX)
SET_SOURCE_FILES_PROPERTIES( ${PROJECT_HDRS} PROPERTIES HEADER_FILE_ONLY TRUE )
LIST(APPEND PROJECT_SRCS ${PROJECT_HDRS})
SET( MEMXML_DATA_PATH . CACHE PATH "search path for Memory.xml")
# OPTION( VARIABLE "Description" Initial state)
#OPTION( WITH_FOO "Enable FOO support" ON )
#OPTION( WITH_BAR "Enable BAR component" OFF )
# Are we 64bit? (Damn you, ptrace()!)
IF( CMAKE_SIZEOF_VOID_P MATCHES 4 )
SET( HAVE_64_BIT 0 )
ELSE( CMAKE_SIZEOF_VOID_P MATCHES 4 )
SET( HAVE_64_BIT 1 )
ENDIF( CMAKE_SIZEOF_VOID_P MATCHES 4 )
CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/dfhack/config.h.cmake ${CMAKE_SOURCE_DIR}/dfhack/include/config.h )
ADD_DEFINITIONS(-DBUILD_DFHACK_LIB)
IF(UNIX)
add_definitions(-DLINUX_BUILD)
add_definitions(-DUSE_CONFIG_H)
find_library(X11_LIBRARY X11)
SET(CMAKE_CXX_FLAGS_DEBUG "-g -Wall")
SET(CMAKE_CXX_FLAGS "-fvisibility=hidden")
SET(PROJECT_LIBS ${X11_LIBRARY} rt ) #dfhack-md5 dfhack-tixml
ELSE(UNIX)
SET(PROJECT_LIBS psapi)
ENDIF(UNIX)
ADD_LIBRARY(dfhack SHARED ${PROJECT_SRCS})
SET_TARGET_PROPERTIES(dfhack PROPERTIES DEBUG_POSTFIX "-debug" )
TARGET_LINK_LIBRARIES(dfhack ${PROJECT_LIBS})
IF(UNIX)
install(TARGETS dfhack LIBRARY DESTINATION lib)
install(FILES ${CMAKE_SOURCE_DIR}/output/Memory.xml DESTINATION share/dfhack)
ENDIF(UNIX)
# SWIG stuff is dead
# FIND_PACKAGE(SWIG)
#IF(SWIG_FOUND)
# INCLUDE(${SWIG_USE_FILE})
# FIND_PACKAGE(PythonLibs)
# IF(PYTHONLIBS_FOUND)
# INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
# SET(CMAKE_SWIG_FLAGS "-c++")
# SET_SOURCE_FILES_PROPERTIES(pydfhack.i PROPERTIES CPLUSPLUS ON)
# SET(CMAKE_DFHACK_SWIG_OUTDIR ${dfhack_SOURCE_DIR}/output CACHE PATH "Directory where Java wrapped libraries will be saved.")
# # SET_SOURCE_FILES_PROPERTIES(pydfhack.i PROPERTIES SWIG_FLAGS "-includeall")
# SWIG_ADD_MODULE(pydfhack python pydfhack.i)
# SWIG_LINK_LIBRARIES(pydfhack ${PYTHON_LIBRARIES} dfhack)
# ENDIF(PYTHONLIBS_FOUND)
#ENDIF(SWIG_FOUND)

@ -1,293 +0,0 @@
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
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 "Tranquility.h"
#include "Export.h"
#include <string>
#include <vector>
#include <map>
#include "integers.h"
#include "DFTileTypes.h"
#include "DFTypes.h"
#include "DFWindow.h"
#include "DFHackAPI.h"
using namespace std;
using namespace DFHack;
#include "DFHackAPI_C.h"
#ifdef __cplusplus
extern "C" {
#endif
DFHackObject* API_Alloc(const char* path_to_xml)
{
DFHack::API* api = new DFHack::API(std::string(path_to_xml));
return (DFHackObject*)api;
}
//FIXME: X:\dfhack\DFHackAPI_C.cpp:56: warning: deleting `DFHackObject* ' is undefined
//DC: Yeah, I forgot that trying to delete a void pointer might be a bad idea. This works now.
void API_Free(DFHackObject* api)
{
if(api != NULL)
{
DFHack::API* a = (DFHack::API*)api;
delete a;
api = NULL;
}
}
int API_Attach(DFHackObject* api)
{
if(api != NULL)
{
return ((DFHack::API*)api)->Attach();
}
return -1;
}
int API_Detach(DFHackObject* api)
{
if(api != NULL)
{
return ((DFHack::API*)api)->Detach();
}
return -1;
}
int API_isAttached(DFHackObject* api)
{
if(api != NULL)
{
return ((DFHack::API*)api)->isAttached();
}
return -1;
}
int API_Suspend(DFHackObject* api)
{
if(api != NULL)
{
return ((DFHack::API*)api)->Suspend();
}
return -1;
}
int API_Resume(DFHackObject* api)
{
if(api != NULL)
{
return ((DFHack::API*)api)->Resume();
}
return -1;
}
int API_isSuspended(DFHackObject* api)
{
if(api != NULL)
{
return ((DFHack::API*)api)->isSuspended();
}
return -1;
}
int API_ForceResume(DFHackObject* api)
{
if(api != NULL)
{
return ((DFHack::API*)api)->ForceResume();
}
return -1;
}
int API_AsyncSuspend(DFHackObject* api)
{
if(api != NULL)
{
return ((DFHack::API*)api)->AsyncSuspend();
}
return -1;
}
//module getters
DFHackObject* API_getMemoryInfo(DFHackObject* api)
{
if(api != NULL)
{
return (DFHackObject*)((DFHack::API*)api)->getMemoryInfo();
}
return NULL;
}
DFHackObject* API_getProcess(DFHackObject* api)
{
if(api != NULL)
{
return (DFHackObject*)((DFHack::API*)api)->getProcess();
}
return NULL;
}
DFHackObject* API_getWindow(DFHackObject* api)
{
if(api != NULL)
{
return (DFHackObject*)((DFHack::API*)api)->getWindow();
}
return NULL;
}
DFHackObject* API_getCreatures(DFHackObject* api)
{
if(api != NULL)
{
return (DFHackObject*)((DFHack::API*)api)->getCreatures();
}
return NULL;
}
DFHackObject* API_getMaps(DFHackObject* api)
{
if(api != NULL)
{
return (DFHackObject*)((DFHack::API*)api)->getMaps();
}
return NULL;
}
DFHackObject* API_getGui(DFHackObject* api)
{
if(api != NULL)
{
return (DFHackObject*)((DFHack::API*)api)->getGui();
}
return NULL;
}
DFHackObject* API_getPosition(DFHackObject* api)
{
if(api != NULL)
{
return (DFHackObject*)((DFHack::API*)api)->getPosition();
}
return NULL;
}
DFHackObject* API_getMaterials(DFHackObject* api)
{
if(api != NULL)
{
return (DFHackObject*)((DFHack::API*)api)->getMaterials();
}
return NULL;
}
DFHackObject* API_getTranslation(DFHackObject* api)
{
if(api != NULL)
{
return (DFHackObject*)((DFHack::API*)api)->getTranslation();
}
return NULL;
}
DFHackObject* API_getVegetation(DFHackObject* api)
{
if(api != NULL)
{
return (DFHackObject*)((DFHack::API*)api)->getVegetation();
}
return NULL;
}
DFHackObject* API_getBuildings(DFHackObject* api)
{
if(api != NULL)
{
return (DFHackObject*)((DFHack::API*)api)->getBuildings();
}
return NULL;
}
DFHackObject* API_getConstructions(DFHackObject* api)
{
if(api != NULL)
{
return (DFHackObject*)((DFHack::API*)api)->getConstructions();
}
return NULL;
}
DFHackObject* API_getItems(DFHackObject* api)
{
if(api != NULL)
{
return (DFHackObject*)((DFHack::API*)api)->getItems();
}
return NULL;
}
void API_ReadRaw(DFHackObject* api, const uint32_t offset, const uint32_t size, uint8_t* target)
{
if(api != NULL)
{
((DFHack::API*)api)->ReadRaw(offset, size, target);
}
}
void API_WriteRaw(DFHackObject* api, const uint32_t offset, const uint32_t size, uint8_t* source)
{
if(api != NULL)
{
((DFHack::API*)api)->WriteRaw(offset, size, source);
}
}
#ifdef __cplusplus
}
#endif

@ -1,226 +0,0 @@
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
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 "integers.h"
#include <stdlib.h>
#include "string.h"
#include <vector>
#include <algorithm>
using namespace std;
#include "DFCommonInternal.h"
#include "DFTypes.h"
#include "modules/Materials.h"
#include "DFTypes_C.h"
using namespace DFHack;
#ifdef __cplusplus
extern "C" {
#endif
c_colormodifier* ColorModifier_New()
{
c_colormodifier* temp;
temp = (c_colormodifier*)malloc(sizeof(c_colormodifier));
if(temp == NULL)
return NULL;
temp->part[0] = '\0';
temp->colorlist = NULL;
temp->colorlistLength = 0;
return temp;
}
void ColorModifier_Free(c_colormodifier* src)
{
if(src != NULL)
{
if(src->colorlist != NULL)
free(src->colorlist);
free(src);
}
}
c_creaturecaste* CreatureCaste_New()
{
c_creaturecaste* temp;
temp = (c_creaturecaste*)malloc(sizeof(c_creaturecaste));
if(temp == NULL)
return NULL;
temp->rawname[0] = '\0';
temp->singular[0] = '\0';
temp->plural[0] = '\0';
temp->adjective[0] = '\0';
temp->ColorModifier = NULL;
temp->colorModifierLength = 0;
temp->bodypart = NULL;
temp->bodypartLength = 0;
return temp;
}
void CreatureCaste_Free(c_creaturecaste* src)
{
if(src != NULL)
{
if(src->bodypart != NULL)
free(src->bodypart);
if(src->ColorModifier != NULL)
{
for(int i = 0; i < src->colorModifierLength; i++)
ColorModifier_Free(&src->ColorModifier[i]);
free(src->ColorModifier);
}
free(src);
}
}
c_creaturetype* CreatureType_New()
{
c_creaturetype* temp;
temp = (c_creaturetype*)malloc(sizeof(c_creaturetype));
if(temp == NULL)
return NULL;
temp->rawname[0] = '\0';
temp->castes = NULL;
temp->castesCount = 0;
temp->extract = NULL;
temp->extractCount = 0;
temp->tile_character = 0;
temp->tilecolor.fore = 0;
temp->tilecolor.back = 0;
temp->tilecolor.bright = 0;
return temp;
}
void CreatureType_Free(c_creaturetype* src)
{
if(src != NULL)
{
if(src->castes != NULL)
{
for(int i = 0; i < src->castesCount; i++)
CreatureCaste_Free(&src->castes[i]);
free(src->castes);
}
if(src->extract != NULL)
free(src->extract);
free(src);
}
}
#ifdef __cplusplus
}
#endif
int ColorListConvert(t_colormodifier* src, c_colormodifier* dest)
{
if(src == NULL || dest == NULL)
return -1;
strcpy(dest->part, src->part);
dest->colorlistLength = src->colorlist.size();
dest->colorlist = (uint32_t*)malloc(sizeof(uint32_t) * dest->colorlistLength);
copy(src->colorlist.begin(), src->colorlist.end(), dest->colorlist);
return 1;
}
int CreatureCasteConvert(t_creaturecaste* src, c_creaturecaste* dest)
{
if(src == NULL || dest == NULL)
return -1;
strcpy(dest->rawname, src->rawname);
strcpy(dest->singular, src->singular);
strcpy(dest->plural, src->plural);
strcpy(dest->adjective, src->adjective);
dest->colorModifierLength = src->ColorModifier.size();
dest->ColorModifier = (c_colormodifier*)malloc(sizeof(c_colormodifier) * dest->colorModifierLength);
for(int i = 0; i < dest->colorModifierLength; i++)
ColorListConvert(&src->ColorModifier[i], &dest->ColorModifier[i]);
dest->bodypartLength = src->bodypart.size();
dest->bodypart = (t_bodypart*)malloc(sizeof(t_bodypart) * dest->bodypartLength);
copy(src->bodypart.begin(), src->bodypart.end(), dest->bodypart);
return 1;
}
int CreatureTypeConvert(t_creaturetype* src, c_creaturetype* dest)
{
if(src == NULL || dest == NULL)
return -1;
strcpy(dest->rawname, src->rawname);
dest->tilecolor.fore = src->tilecolor.fore;
dest->tilecolor.back = src->tilecolor.back;
dest->tilecolor.bright = src->tilecolor.bright;
dest->tile_character = src->tile_character;
dest->castesCount = src->castes.size();
dest->castes = (c_creaturecaste*)malloc(sizeof(c_creaturecaste) * dest->castesCount);
for(int i = 0; i < dest->castesCount; i++)
CreatureCasteConvert(&src->castes[i], &dest->castes[i]);
dest->extractCount = src->extract.size();
dest->extract = (t_creatureextract*)malloc(sizeof(t_creatureextract) * dest->extractCount);
copy(src->extract.begin(), src->extract.end(), dest->extract);
return 1;
}

@ -1,73 +0,0 @@
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
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 DFHACK_C_API
#define DFHACK_C_API
#include "Export.h"
#include "integers.h"
typedef void DFHackObject;
#ifdef __cplusplus
extern "C" {
#endif
DFHACK_EXPORT DFHackObject* API_Alloc(const char* path_to_xml);
DFHACK_EXPORT void API_Free(DFHackObject* api);
DFHACK_EXPORT int API_Attach(DFHackObject* api);
DFHACK_EXPORT int API_Detach(DFHackObject* api);
DFHACK_EXPORT int API_isAttached(DFHackObject* api);
DFHACK_EXPORT int API_Suspend(DFHackObject* api);
DFHACK_EXPORT int API_Resume(DFHackObject* api);
DFHACK_EXPORT int API_isSuspended(DFHackObject* api);
DFHACK_EXPORT int API_ForceResume(DFHackObject* api);
DFHACK_EXPORT int API_AsyncSuspend(DFHackObject* api);
DFHACK_EXPORT DFHackObject* API_getMemoryInfo(DFHackObject* api);
DFHACK_EXPORT DFHackObject* API_getProcess(DFHackObject* api);
DFHACK_EXPORT DFHackObject* API_getWindow(DFHackObject* api);
DFHACK_EXPORT DFHackObject* API_getCreatures(DFHackObject* api);
DFHACK_EXPORT DFHackObject* API_getMaps(DFHackObject* api);
DFHACK_EXPORT DFHackObject* API_getGui(DFHackObject* api);
DFHACK_EXPORT DFHackObject* API_getPosition(DFHackObject* api);
DFHACK_EXPORT DFHackObject* API_getMaterials(DFHackObject* api);
DFHACK_EXPORT DFHackObject* API_getTranslation(DFHackObject* api);
DFHACK_EXPORT DFHackObject* API_getVegetation(DFHackObject* api);
DFHACK_EXPORT DFHackObject* API_getBuildings(DFHackObject* api);
DFHACK_EXPORT DFHackObject* API_getConstructions(DFHackObject* api);
DFHACK_EXPORT DFHackObject* API_getItems(DFHackObject* api);
//these are DANGEROUS...can crash/segfault DF, turn the seas to blood, call up the Antichrist, etc
DFHACK_EXPORT void API_ReadRaw(DFHackObject* api, const uint32_t offset, const uint32_t size, uint8_t* target);
DFHACK_EXPORT void API_WriteRaw(DFHackObject* api, const uint32_t offset, const uint32_t size, uint8_t* source);
#ifdef __cplusplus
}
#endif
#endif

@ -1,98 +0,0 @@
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
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 TYPES_C_API
#define TYPES_C_API
#include "Export.h"
#include "integers.h"
#include "DFTypes.h"
#include "modules/Materials.h"
#include "DFHackAPI_C.h"
using namespace DFHack;
#ifdef __cplusplus
extern "C" {
#endif
struct c_colormodifier
{
char part[128];
uint32_t* colorlist;
uint32_t colorlistLength;
};
c_colormodifier* ColorModifier_New();
void ColorModifier_Free(c_colormodifier* src);
struct c_creaturecaste
{
char rawname[128];
char singular[128];
char plural[128];
char adjective[128];
c_colormodifier* ColorModifier;
uint32_t colorModifierLength;
t_bodypart* bodypart;
uint32_t bodypartLength;
};
c_creaturecaste* CreatureCaste_New();
void CreatureCaste_Free(c_creaturecaste* src);
struct c_creaturetype
{
char rawname[128];
c_creaturecaste* castes;
uint32_t castesCount;
t_creatureextract* extract;
uint32_t extractCount;
uint8_t tile_character;
struct
{
uint16_t fore;
uint16_t back;
uint16_t bright;
} tilecolor;
};
c_creaturetype* CreatureType_New();
void CreatureType_Free(c_creaturetype* src);
#ifdef __cplusplus
}
#endif
int CreatureTypeConvert(t_creaturetype* src, c_creaturetype* dest);
int CreatureCasteConvert(t_creaturecaste* src, c_creaturecaste* dest);
int ColorListConvert(t_colormodifier* src, c_colormodifier* dest);
#endif

@ -1,219 +0,0 @@
%module pydfhack
%include "std_string.i"
%include "std_vector.i"
%include "std_map.i"
%include "stdint.i"
%include "typemaps.i"
/* This goes to the header of the wrapper code */
%{
#define LINUX_BUILD
#define SWIG_WRAPPER
#include "DFTypes.h"
#include "DFHackAPI.h"
using namespace std;
using namespace DFHack;
%}
/* make swig not react to the macro */
%define DFHACK_EXPORT
/* Parse the header file to generate wrappers */
%include "DFTypes.h"
/* templates have to be instantiated for swig */
%template(MatglossVector) std::vector<DFHack::t_matgloss>;
%template(PlantMatglossVector) std::vector<DFHack::t_matglossPlant>;
%template(VeinVector) std::vector <DFHack::t_vein>;
%template(IceVeinVector) std::vector <DFHack::t_frozenliquidvein>;
/*
This causes swig to generate BS uncompilable code
%template(GeologyAssign) std::vector < std::vector <uint16_t> >;
*/
/*
SWIG typemaps recipe
%apply double *OUTPUT { double *result }; // 'double *result' is to be treated as OUTPUT
%clear double *result; // Remove all typemaps for double *result
INPUT
int *INPUT
short *INPUT
long *INPUT
unsigned int *INPUT
unsigned short *INPUT
unsigned long *INPUT
double *INPUT
float *INPUT
OUTPUT
int *OUTPUT
short *OUTPUT
long *OUTPUT
unsigned int *OUTPUT
unsigned short *OUTPUT
unsigned long *OUTPUT
double *OUTPUT
float *OUTPUT
INOUT
int *INOUT
short *INOUT
long *INOUT
unsigned int *INOUT
unsigned short *INOUT
unsigned long *INOUT
double *INOUT
float *INOUT
*/
namespace DFHack
{
class memory_info;
class Process;
class API
{
class Private;
Private * const d;
public:
API(const std::string path_to_xml);
~API();
bool Attach();
bool Detach();
bool isAttached();
bool ReadPauseState();
bool ReadViewScreen(t_viewscreen &);
uint32_t ReadMenuState();
bool Suspend();
bool AsyncSuspend();
bool Resume();
bool ForceResume();
bool isSuspended();
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);
/*
* SWIG reports that it can't wrap the second method here
*/
bool ReadPlantMatgloss (std::vector<t_matglossPlant> & OUTPUT);
bool ReadCreatureMatgloss(std::vector<t_matgloss> & OUTPUT);
bool ReadGeology( std::vector < std::vector <uint16_t> >& OUTPUT );
bool InitMap();
bool DestroyMap();
%apply uint32_t& OUTPUT { uint32_t& x };
%apply uint32_t& OUTPUT { uint32_t& y };
%apply uint32_t& OUTPUT { uint32_t& z };
void getSize(uint32_t& x, uint32_t& y, uint32_t& z);
bool isValidBlock(uint32_t blockx, uint32_t blocky, uint32_t blockz);
uint32_t getBlockPtr (uint32_t blockx, uint32_t blocky, uint32_t blockz);
bool ReadBlock40d(uint32_t blockx, uint32_t blocky, uint32_t blockz, mapblock40d * OUTPUT);
bool ReadTileTypes(uint32_t blockx, uint32_t blocky, uint32_t blockz, tiletypes40d *OUTPUT);
bool WriteTileTypes(uint32_t blockx, uint32_t blocky, uint32_t blockz, tiletypes40d *INPUT);
bool ReadDesignations(uint32_t blockx, uint32_t blocky, uint32_t blockz, designations40d *OUTPUT);
bool WriteDesignations (uint32_t blockx, uint32_t blocky, uint32_t blockz, designations40d *INPUT);
bool ReadOccupancy(uint32_t blockx, uint32_t blocky, uint32_t blockz, occupancies40d *OUTPUT);
bool WriteOccupancy(uint32_t blockx, uint32_t blocky, uint32_t blockz, occupancies40d *INPUT);
bool ReadDirtyBit(uint32_t blockx, uint32_t blocky, uint32_t blockz, bool &OUTPUT);
bool WriteDirtyBit(uint32_t blockx, uint32_t blocky, uint32_t blockz, bool dirtybit);
bool ReadRegionOffsets(uint32_t blockx, uint32_t blocky, uint32_t blockz, biome_indices40d *OUTPUT);
bool ReadVeins(uint32_t blockx, uint32_t blocky, uint32_t blockz, std::vector <t_vein> & veins, std::vector <t_frozenliquidvein>& ices);
%apply uint32_t& OUTPUT { uint32_t & numObjs };
bool InitReadConstructions( uint32_t & numObjs );
bool ReadConstruction(const int32_t index, t_construction & OUTPUT);
void FinishReadConstructions();
bool InitReadBuildings ( uint32_t & numObjs );
bool ReadBuilding(const int32_t index, t_building & OUTPUT);
void FinishReadBuildings();
bool InitReadVegetation( uint32_t & numObjs );
bool ReadVegetation(const int32_t index, t_tree_desc & OUTPUT);
void FinishReadVegetation();
bool InitReadCreatures( uint32_t & numObjs );
int32_t ReadCreatureInBox(int32_t index, t_creature & OUTPUT,
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 & OUTPUT);
void FinishReadCreatures();
/*
A conundrum really.
*/
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);
bool InitViewAndCursor();
bool InitReadNotes( uint32_t & numnotes );
bool ReadNote(const int32_t index, t_note & OUTPUT);
void FinishReadNotes();
bool InitReadSettlements( uint32_t & numObjs );
bool ReadSettlement(const int32_t index, t_settlement & OUTPUT);
bool ReadCurrentSettlement(t_settlement & settlement);
void FinishReadSettlements();
bool InitReadHotkeys( );
bool ReadHotkeys(t_hotkey hotkeys[]);
%apply int32_t& OUTPUT { int32_t& x };
%apply int32_t& OUTPUT { int32_t& y };
%apply int32_t& OUTPUT { int32_t& z };
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);
bool getCurrentCursorCreature(uint32_t &OUTPUT);
bool InitViewSize();
%apply int32_t& OUTPUT { int32_t& width };
%apply int32_t& OUTPUT { int32_t& height };
bool getWindowSize(int32_t & width, int32_t & height);
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 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);
void WriteLabors(const uint32_t index, uint8_t labors[NUM_CREATURE_LABORS]);
bool InitReadItems(uint32_t & numitems);
bool ReadItem(const uint32_t index, t_item & OUTPUT);
void FinishReadItems();
memory_info *getMemoryInfo();
Process * getProcess();
DFWindow * getWindow();
bool ReadItemTypes(std::vector< std::vector< t_itemType > > & itemTypes);
};
};
%enddef DFHACK_EXPORT

@ -1,14 +0,0 @@
from ctypes import *
def _uintify(x, y, z):
return (c_uint(x), c_uint(y), c_uint(z))
def _allocate_array(t_type, count):
arr_type = t_type * count
arr = arr_type()
ptr = c_void_p()
ptr = addressof(arr)
return (arr, ptr)

@ -1,54 +0,0 @@
# don't use this file directly. use the one in the root folder of the project
SET(PROJECT_HDRS
shms.h
mod-core.h
mod-maps.h
)
SET(PROJECT_SRCS
mod-core.cpp
mod-maps.cpp
mod-creature40d.cpp
)
SET(PROJECT_HDRS_LINUX
)
SET(PROJECT_HDRS_WINDOWS
)
SET(PROJECT_SRCS_LINUX
shms-linux.cpp
)
SET(PROJECT_SRCS_WINDOWS
shms-windows.cpp
)
IF(UNIX)
LIST(APPEND PROJECT_HDRS ${PROJECT_HDRS_LINUX})
LIST(APPEND PROJECT_SRCS ${PROJECT_SRCS_LINUX})
ELSE(UNIX)
LIST(APPEND PROJECT_HDRS ${PROJECT_HDRS_WINDOWS})
LIST(APPEND PROJECT_SRCS ${PROJECT_SRCS_WINDOWS})
ENDIF(UNIX)
SET_SOURCE_FILES_PROPERTIES( ${PROJECT_HDRS} PROPERTIES HEADER_FILE_ONLY TRUE )
LIST(APPEND PROJECT_SRCS ${PROJECT_HDRS})
IF(CMAKE_SIZEOF_VOID_P EQUAL 4)
IF(UNIX)
add_definitions(-DLINUX_BUILD)
SET(PROJECT_LIBS rt)
SET(CMAKE_CXX_FLAGS "-fvisibility=hidden")
ADD_LIBRARY(dfconnect SHARED ${PROJECT_SRCS})
TARGET_LINK_LIBRARIES(dfconnect ${PROJECT_LIBS})
ELSE(UNIX)
# SET(PROJECT_LIBS psapi)
ADD_LIBRARY(SDL SHARED ${PROJECT_SRCS})
TARGET_LINK_LIBRARIES(SDL ${PROJECT_LIBS})
ENDIF(UNIX)
ENDIF(CMAKE_SIZEOF_VOID_P EQUAL 4)

@ -1,204 +0,0 @@
// Just show some position data
#include <iostream>
#include <iomanip>
#include <climits>
#include <integers.h>
#include <vector>
#include <sstream>
#include <ctime>
#include <cstdio>
using namespace std;
#include <DFGlobal.h>
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFProcess.h>
#include <DFMemInfo.h>
#include <DFVector.h>
#include <DFTypes.h>
#include <modules/Materials.h>
#include <modules/Position.h>
#include <modules/Maps.h>
#include <modules/Constructions.h>
#include <DFMiscUtils.h>
#include <DFTileTypes.h>
using namespace DFHack;
/*
int __userpurge get_feature_at<eax>(__int16 tZ<ax>, __int16 tY<cx>, int world_base<ebx>, signed __int16 tX)
{
int block; // ebp@1
signed __int16 __tX; // di@1
signed int _tY; // esi@1
int designation; // eax@2
int _tX; // ecx@2
signed int v9; // eax@4
int v10; // edx@4
__int64 region_x_local; // qax@4
__int16 v12; // cx@4
__int16 v13; // ax@5
int v14; // esi@5
int result; // eax@7
unsigned int some_stuff; // ebp@10
int v17; // edx@11
int _designation; // [sp+10h] [bp+4h]@2
__tX = tX;
LOWORD(_tY) = tY;
block = getBlock(world_base, tX, tY, tZ);
if ( !block )
goto LABEL_17;
_tX = tX;
_tY = (signed __int16)_tY;
designation = *(_DWORD *)(block + 0x29C + 4 * ((signed __int16)_tY % 16 + 16 * tX % 16));
_designation = designation;
if ( designation & 0x10000000 && *(_WORD *)(block + 0x2C) != -1 )// first feature_present bit - adamantine
{
region_x_local = __tX / 48 + *(_DWORD *)(world_base + 0x525C8);// tile_x / 48 + region_x
v12 = ((BYTE4(region_x_local) & 0xF) + (_DWORD)region_x_local) >> 4;
WORD2(region_x_local) = (_tY / 48 + *(_DWORD *)(world_base + 0x525CC)) / 16;// tile_y / 48 + region_y
v9 = v12;
_tX = SWORD2(region_x_local);
v10 = *(_DWORD *)(*(_DWORD *)(*(_DWORD *)(world_base + 0x54440) + 4 * (v9 >> 4))
+ 16 * (SWORD2(region_x_local) >> 4)
+ 4);
if ( v10 )
{
_tX %= 16;
v14 = v10 + 24 * ((signed __int16)_tX + 16 * v9 % 16);
v13 = *(_WORD *)(block + 0x2C);
if ( v13 >= 0 )
{
_tX = (*(_DWORD *)(v14 + 16) - *(_DWORD *)(v14 + 12)) >> 2;
if ( v13 < (unsigned int)_tX )
return *(_DWORD *)sub_519100(_tX, v10);
}
}
designation = _designation;
}
if ( designation & 0x20000000 && (some_stuff = *(_DWORD *)(block + 0x30), some_stuff != -1) )// second feature_present bit - slade and hell
{
v17 = (*(_DWORD *)(world_base + 0x54384) - *(_DWORD *)(world_base + 0x54380)) >> 2;
if ( some_stuff >= v17 )
_invalid_parameter_noinfo(_tX, v17);
result = *(_DWORD *)(*(_DWORD *)(*(_DWORD *)(world_base + 0x54380) + 4 * some_stuff) + 0x100);
}
else
{
LABEL_17:
result = 0;
}
return result;
}
*/
int main (int numargs, const char ** args)
{
DFHack::API DF("Memory.xml");
try
{
DF.Attach();
}
catch (exception& e)
{
cerr << e.what() << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
DFHack::Position *Pos = DF.getPosition();
DFHack::memory_info* mem = DF.getMemoryInfo();
DFHack::Maps *Maps = DF.getMaps();
DFHack::Process * p = DF.getProcess();
uint32_t designatus = mem->getOffset("map_data_designation");
uint32_t block_feature1 = mem->getOffset("map_data_feature_local");
uint32_t block_feature2 = mem->getOffset("map_data_feature_global");
uint32_t region_x_offset = mem->getAddress("region_x");
uint32_t region_y_offset = mem->getAddress("region_y");
uint32_t region_z_offset = mem->getAddress("region_z");
uint32_t feature1_start_ptr = mem->getAddress("local_feature_start_ptr");
int32_t regionX, regionY, regionZ;
// read position of the region inside DF world
p->readDWord (region_x_offset, (uint32_t &)regionX);
p->readDWord (region_y_offset, (uint32_t &)regionY);
p->readDWord (region_z_offset, (uint32_t &)regionZ);
Maps->Start();
int32_t cursorX, cursorY, cursorZ;
Pos->getCursorCoords(cursorX,cursorY,cursorZ);
if(cursorX != -30000)
{
uint32_t blockX = cursorX / 16;
uint32_t tileX = cursorX % 16;
uint32_t blockY = cursorY / 16;
uint32_t tileY = cursorY % 16;
t_temperatures tmpb1, tmpb2;
mapblock40d block;
if(Maps->ReadBlock40d(blockX,blockY,cursorZ,&block))
{
Maps->ReadTemperatures(blockX,blockY,cursorZ,&tmpb1, &tmpb2);
printf("block addr: 0x%x\n", block.origin);
int16_t tiletype = block.tiletypes[tileX][tileY];
naked_designation &des = block.designation[tileX][tileY].bits;
uint32_t &desw = block.designation[tileX][tileY].whole;
print_bits<uint32_t>(block.designation[tileX][tileY].whole,cout);
cout << endl;
print_bits<uint32_t>(block.occupancy[tileX][tileY].whole,cout);
cout << endl;
// tiletype
cout <<"tiletype: " << tiletype;
if(tileTypeTable[tiletype].name)
cout << " = " << tileTypeTable[tiletype].name;
cout << endl;
cout <<"temperature1: " << tmpb1[tileX][tileY] << " U" << endl;
cout <<"temperature2: " << tmpb2[tileX][tileY] << " U" << endl;
// biome, geolayer
cout << "biome: " << des.biome << endl;
cout << "geolayer: " << des.geolayer_index << endl;
// liquids
if(des.flow_size)
{
if(des.liquid_type == DFHack::liquid_magma)
cout <<"magma: ";
else cout <<"water: ";
cout << des.flow_size << endl;
}
if(des.flow_forbid)
cout << "flow forbid" << endl;
if(des.pile)
cout << "stockpile?" << endl;
if(des.rained)
cout << "rained?" << endl;
if(des.smooth)
cout << "smooth?" << endl;
uint32_t designato = block.origin + designatus + (tileX * 16 + tileY) * sizeof(t_designation);
printf("designation offset: 0x%x\n", designato);
if(des.light)
cout << "L";
else
cout << " ";
if(des.skyview)
cout << "S";
else
cout << " ";
if(des.subterranean)
cout << "U";
else
cout << " ";
cout << endl;
}
}
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;
cin.ignore();
#endif
return 0;
}

@ -0,0 +1,225 @@
# don't use this file directly. use the one in the root folder of the project
PROJECT (dfhack-library)
cmake_minimum_required(VERSION 2.6)
SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMake/Modules)
# disable warning, autosearch
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
message(SEND_ERROR "In-source builds are not allowed.")
endif("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
IF(NOT DEFINED CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.")
ENDIF(NOT DEFINED CMAKE_BUILD_TYPE)
SET( LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/output CACHE PATH "Output directory for the dfhack library" )
SET( EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/output CACHE PATH "Output directory for the dfhack tools" )
include_directories (${CMAKE_SOURCE_DIR}/library/include/)
include_directories (${CMAKE_SOURCE_DIR}/library/shm/)
include_directories (${CMAKE_SOURCE_DIR}/library/depends/md5/)
include_directories (${CMAKE_SOURCE_DIR}/library/depends/tinyxml/)
include_directories (${CMAKE_SOURCE_DIR}/library/depends/argstream/)
include_directories (${CMAKE_SOURCE_DIR}/library/private/)
SET(PROJECT_HDRS
include/dfhack/DFError.h
include/dfhack/DFMemInfo.h
include/dfhack/DFMemInfoManager.h
include/dfhack/DFProcessEnumerator.h
include/dfhack/DFProcess.h
include/dfhack/DFTileTypes.h
include/dfhack/DFTypes.h
include/dfhack/DFVector.h
include/dfhack-c/DFTypes_C.h
include/dfhack-c/DFContext_C.h
include/dfhack/DFIntegers.h
include/dfhack/modules/Buildings.h
include/dfhack/modules/Constructions.h
include/dfhack/modules/Creatures.h
include/dfhack/modules/Gui.h
include/dfhack/modules/Items.h
include/dfhack/modules/Maps.h
include/dfhack/modules/Materials.h
include/dfhack/modules/Position.h
include/dfhack/modules/Translation.h
include/dfhack/modules/Vegetation.h
include/dfhack/modules/WindowIO.h
include/dfhack/modules/World.h
)
SET(PROJECT_SRCS
DFMemInfo.cpp
DFMemInfoManager.cpp
DFContextManager.cpp
DFContext.cpp
ContextShared.cpp
DFContext_C.cpp
DFTypes_C.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/Buildings.cpp
modules/Constructions.cpp
modules/Creatures.cpp
modules/Gui.cpp
modules/Items.cpp
modules/Maps.cpp
modules/Materials.cpp
modules/Position.cpp
modules/Translation.cpp
modules/Vegetation.cpp
modules/World.cpp
modules/Buildings_C.cpp
modules/Constructions_C.cpp
modules/Creatures_C.cpp
modules/Gui_C.cpp
modules/Items_C.cpp
modules/Maps_C.cpp
modules/Position_C.cpp
modules/Materials_C.cpp
modules/Translation_C.cpp
modules/Vegetation_C.cpp
)
SET(PROJECT_HDRS_LINUX
)
SET(PROJECT_HDRS_WINDOWS
include/dfhack/DFstdint_win.h
)
SET(PROJECT_SRCS_LINUX
DFProcess-linux.cpp
DFProcess-linux-SHM.cpp
DFProcess-linux-wine.cpp
modules/WindowIO-linux.cpp
DFProcessEnumerator-linux.cpp
)
SET(PROJECT_SRCS_WINDOWS
DFProcess-windows.cpp
DFProcess-windows-SHM.cpp
modules/WindowIO-windows.cpp
DFProcessEnumerator-windows.cpp
)
IF(UNIX)
LIST(APPEND PROJECT_HDRS ${PROJECT_HDRS_LINUX})
LIST(APPEND PROJECT_SRCS ${PROJECT_SRCS_LINUX})
ELSE(UNIX)
LIST(APPEND PROJECT_HDRS ${PROJECT_HDRS_WINDOWS})
LIST(APPEND PROJECT_SRCS ${PROJECT_SRCS_WINDOWS})
ENDIF(UNIX)
SET_SOURCE_FILES_PROPERTIES( ${PROJECT_HDRS} PROPERTIES HEADER_FILE_ONLY TRUE )
LIST(APPEND PROJECT_SRCS ${PROJECT_HDRS})
SET( MEMXML_DATA_PATH . CACHE PATH "search path for Memory.xml")
# OPTION( VARIABLE "Description" Initial state)
#OPTION( WITH_FOO "Enable FOO support" ON )
#OPTION( WITH_BAR "Enable BAR component" OFF )
# Are we 64bit? (Damn you, ptrace()!)
IF( CMAKE_SIZEOF_VOID_P MATCHES 4 )
SET( HAVE_64_BIT 0 )
ELSE( CMAKE_SIZEOF_VOID_P MATCHES 4 )
SET( HAVE_64_BIT 1 )
ENDIF( CMAKE_SIZEOF_VOID_P MATCHES 4 )
CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/library/config.h.cmake ${CMAKE_SOURCE_DIR}/library/private/config.h )
ADD_DEFINITIONS(-DBUILD_DFHACK_LIB)
IF(UNIX)
add_definitions(-DLINUX_BUILD)
add_definitions(-DUSE_CONFIG_H)
find_library(X11_LIBRARY X11)
SET(CMAKE_CXX_FLAGS_DEBUG "-g -Wall")
SET(CMAKE_CXX_FLAGS "-fvisibility=hidden")
SET(PROJECT_LIBS ${X11_LIBRARY} rt ) #dfhack-md5 dfhack-tixml
ELSE(UNIX)
SET(PROJECT_LIBS psapi)
ENDIF(UNIX)
ADD_LIBRARY(dfhack SHARED ${PROJECT_SRCS})
SET_TARGET_PROPERTIES(dfhack PROPERTIES DEBUG_POSTFIX "-debug" )
TARGET_LINK_LIBRARIES(dfhack ${PROJECT_LIBS})
IF(UNIX)
install(TARGETS dfhack LIBRARY DESTINATION lib)
install(FILES ${CMAKE_SOURCE_DIR}/output/Memory.xml DESTINATION share/dfhack)
ENDIF(UNIX)
################################################################################
# DFCONNECT
###
SET(DFCONNECT_HDRS
shm/shms.h
shm/mod-core.h
shm/mod-maps.h
)
SET(PROJECT_SRCS
shm/mod-core.cpp
shm/mod-maps.cpp
#mod-creature40d.cpp
)
SET(PROJECT_HDRS_LINUX
)
SET(PROJECT_HDRS_WINDOWS
)
SET(PROJECT_SRCS_LINUX
shm/shms-linux.cpp
)
SET(PROJECT_SRCS_WINDOWS
shm/shms-windows.cpp
)
IF(UNIX)
LIST(APPEND PROJECT_HDRS ${PROJECT_HDRS_LINUX})
LIST(APPEND PROJECT_SRCS ${PROJECT_SRCS_LINUX})
ELSE(UNIX)
LIST(APPEND PROJECT_HDRS ${PROJECT_HDRS_WINDOWS})
LIST(APPEND PROJECT_SRCS ${PROJECT_SRCS_WINDOWS})
ENDIF(UNIX)
SET_SOURCE_FILES_PROPERTIES( ${PROJECT_HDRS} PROPERTIES HEADER_FILE_ONLY TRUE )
LIST(APPEND PROJECT_SRCS ${PROJECT_HDRS})
#IF(CMAKE_SIZEOF_VOID_P EQUAL 4)
IF(UNIX)
add_definitions(-DLINUX_BUILD)
SET(PROJECT_LIBS rt)
SET(CMAKE_CXX_FLAGS "-fvisibility=hidden")
ADD_LIBRARY(dfconnect SHARED ${PROJECT_SRCS})
TARGET_LINK_LIBRARIES(dfconnect ${PROJECT_LIBS})
ELSE(UNIX)
# SET(PROJECT_LIBS psapi)
ADD_LIBRARY(SDL SHARED ${PROJECT_SRCS})
TARGET_LINK_LIBRARIES(SDL ${PROJECT_LIBS})
ENDIF(UNIX)
#ENDIF(CMAKE_SIZEOF_VOID_P EQUAL 4)

@ -1,26 +1,27 @@
#include "DFCommonInternal.h" #include "Internal.h"
#include <shms.h> #include <shms.h>
#include <mod-core.h> #include <mod-core.h>
#include <mod-maps.h> #include <mod-maps.h>
#include <mod-creature40d.h> #include <mod-creature40d.h>
#include "private/APIPrivate.h" #include "private/ContextShared.h"
#include "DFMemInfo.h" #include "dfhack/DFMemInfo.h"
#include "DFProcess.h" #include "dfhack/DFProcess.h"
#include "modules/Materials.h" #include "dfhack/modules/Materials.h"
#include "modules/Creatures.h" #include "dfhack/modules/Creatures.h"
#include "modules/Maps.h" #include "dfhack/modules/Maps.h"
#include "modules/Position.h" #include "dfhack/modules/Position.h"
#include "modules/Translation.h" #include "dfhack/modules/Translation.h"
#include "modules/Vegetation.h" #include "dfhack/modules/Vegetation.h"
#include "modules/Gui.h" #include "dfhack/modules/Gui.h"
#include "modules/World.h" #include "dfhack/modules/World.h"
#include "modules/Buildings.h" #include "dfhack/modules/Buildings.h"
#include "modules/Constructions.h" #include "dfhack/modules/Constructions.h"
#include "dfhack/modules/WindowIO.h"
using namespace DFHack; using namespace DFHack;
APIPrivate::APIPrivate() DFContextShared::DFContextShared()
{ {
// init modules // init modules
creatures = 0; creatures = 0;
@ -34,9 +35,10 @@ APIPrivate::APIPrivate()
buildings = 0; buildings = 0;
constructions = 0; constructions = 0;
items = 0; items = 0;
windowio = 0;
} }
APIPrivate::~APIPrivate() DFContextShared::~DFContextShared()
{ {
if(creatures) delete creatures; if(creatures) delete creatures;
if(maps) delete maps; if(maps) delete maps;
@ -48,9 +50,10 @@ APIPrivate::~APIPrivate()
if(buildings) delete buildings; if(buildings) delete buildings;
if(constructions) delete constructions; if(constructions) delete constructions;
if(world) delete world; if(world) delete world;
if(windowio) delete windowio;
} }
bool APIPrivate::InitReadNames() bool DFContextShared::InitReadNames()
{ {
name_firstname_offset = offset_descriptor->getOffset("name_firstname"); name_firstname_offset = offset_descriptor->getOffset("name_firstname");
name_nickname_offset = offset_descriptor->getOffset("name_nickname"); name_nickname_offset = offset_descriptor->getOffset("name_nickname");
@ -58,7 +61,7 @@ bool APIPrivate::InitReadNames()
return true; return true;
} }
void APIPrivate::readName(t_name & name, uint32_t address) void DFContextShared::readName(t_name & name, uint32_t address)
{ {
p->readSTLString(address + name_firstname_offset , name.first_name, 128); p->readSTLString(address + name_firstname_offset , name.first_name, 128);
p->readSTLString(address + name_nickname_offset , name.nickname, 128); p->readSTLString(address + name_nickname_offset , name.nickname, 128);

@ -22,114 +22,82 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "DFCommonInternal.h" #include "Internal.h"
#include "DFProcess.h" #include "dfhack/DFProcess.h"
#include "DFProcessEnumerator.h" #include "dfhack/DFProcessEnumerator.h"
#include "DFHackAPI.h" #include "dfhack/DFContext.h"
#include "DFError.h" #include "dfhack/DFContext.h"
#include "dfhack/DFError.h"
#include <shms.h> #include <shms.h>
#include <mod-core.h> #include <mod-core.h>
#include <mod-maps.h> #include <mod-maps.h>
#include <mod-creature40d.h> #include <mod-creature40d.h>
#include "private/APIPrivate.h" #include "private/ContextShared.h"
#include "modules/Maps.h" #include "dfhack/modules/Maps.h"
#include "modules/Materials.h" #include "dfhack/modules/Materials.h"
#include "modules/Items.h" #include "dfhack/modules/Items.h"
#include "modules/Position.h" #include "dfhack/modules/Position.h"
#include "modules/Gui.h" #include "dfhack/modules/Gui.h"
#include "modules/World.h" #include "dfhack/modules/World.h"
#include "modules/Creatures.h" #include "dfhack/modules/Creatures.h"
#include "modules/Translation.h" #include "dfhack/modules/Translation.h"
#include "modules/Vegetation.h" #include "dfhack/modules/Vegetation.h"
#include "modules/Buildings.h" #include "dfhack/modules/Buildings.h"
#include "modules/Constructions.h" #include "dfhack/modules/Constructions.h"
#include "dfhack/modules/WindowIO.h"
using namespace DFHack; using namespace DFHack;
API::API (const string path_to_xml) Context::Context (Process* p) : d (new DFContextShared())
: d (new APIPrivate())
{ {
d->xml = QUOT (MEMXML_DATA_PATH); d->p = p;
d->xml += "/"; d->offset_descriptor = p->getDescriptor();
d->xml += path_to_xml;
d->pm = NULL;
d->p = 0;
d->shm_start = 0; d->shm_start = 0;
} }
API::~API() Context::~Context()
{ {
Detach(); Detach();
delete d; delete d;
} }
bool API::Attach() bool Context::isValid()
{ {
if(d->p != NULL) //FIXME: check for error states here
{ if(d->p->isIdentified())
return d->p->suspend(); return true;
} return false;
// 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) bool Context::Attach()
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()) if (!d->p->attach())
{ {
throw Error::CantAttach(); //throw Error::CantAttach();
//cerr << "couldn't attach to process" << endl; return false;
//return false; // couldn't attach to process, no go
} }
d->shm_start = d->p->getSHMStart(); d->shm_start = d->p->getSHMStart();
d->offset_descriptor = d->p->getDescriptor();
// process is attached, everything went just fine... hopefully // process is attached, everything went just fine... hopefully
return true; return true;
} }
bool API::Detach() bool Context::Detach()
{ {
if(!d->p)
return false;
if (!d->p->detach()) if (!d->p->detach())
{ {
return false; return false;
} }
if (d->pm != NULL)
{
delete d->pm;
}
d->pm = NULL;
d->p = NULL;
d->shm_start = 0; d->shm_start = 0;
d->offset_descriptor = NULL;
// invalidate all modules // invalidate all modules
if(d->creatures) if(d->creatures)
{ {
delete d->creatures; delete d->creatures;
d->creatures = 0; d->creatures = 0;
} }
if(d->creatures)
{
delete d->creatures;
d->creatures = 0;
}
if(d->maps) if(d->maps)
{ {
delete d->maps; delete d->maps;
@ -183,131 +151,134 @@ bool API::Detach()
return true; return true;
} }
bool API::isAttached() bool Context::isAttached()
{ {
return d->p != NULL; return d->p->isAttached();
} }
bool API::Suspend() bool Context::Suspend()
{ {
return d->p->suspend(); return d->p->suspend();
} }
bool API::AsyncSuspend() bool Context::AsyncSuspend()
{ {
return d->p->asyncSuspend(); return d->p->asyncSuspend();
} }
bool API::Resume() bool Context::Resume()
{ {
return d->p->resume(); return d->p->resume();
} }
bool API::ForceResume() bool Context::ForceResume()
{ {
return d->p->forceresume(); return d->p->forceresume();
} }
bool API::isSuspended() bool Context::isSuspended()
{ {
return d->p->isSuspended(); return d->p->isSuspended();
} }
void API::ReadRaw (const uint32_t offset, const uint32_t size, uint8_t *target) void Context::ReadRaw (const uint32_t offset, const uint32_t size, uint8_t *target)
{ {
d->p->read (offset, size, target); d->p->read (offset, size, target);
} }
void API::WriteRaw (const uint32_t offset, const uint32_t size, uint8_t *source) void Context::WriteRaw (const uint32_t offset, const uint32_t size, uint8_t *source)
{ {
d->p->write (offset, size, source); d->p->write (offset, size, source);
} }
memory_info *API::getMemoryInfo() memory_info *Context::getMemoryInfo()
{ {
return d->offset_descriptor; return d->offset_descriptor;
} }
Process * API::getProcess()
{
return d->p;
}
DFWindow * API::getWindow() Process * Context::getProcess()
{ {
return d->p->getWindow(); return d->p;
} }
/******************************************************************************* /*******************************************************************************
M O D U L E S M O D U L E S
*******************************************************************************/ *******************************************************************************/
Creatures * API::getCreatures() Creatures * Context::getCreatures()
{ {
if(!d->creatures) if(!d->creatures)
d->creatures = new Creatures(d); d->creatures = new Creatures(d);
return d->creatures; return d->creatures;
} }
Maps * API::getMaps() Maps * Context::getMaps()
{ {
if(!d->maps) if(!d->maps)
d->maps = new Maps(d); d->maps = new Maps(d);
return d->maps; return d->maps;
} }
Gui * API::getGui() Gui * Context::getGui()
{ {
if(!d->gui) if(!d->gui)
d->gui = new Gui(d); d->gui = new Gui(d);
return d->gui; return d->gui;
} }
World * API::getWorld() WindowIO * Context::getWindow()
{
if(!d->windowio)
d->windowio = new WindowIO(d);
return d->windowio;
}
World * Context::getWorld()
{ {
if(!d->world) if(!d->world)
d->world = new World(d); d->world = new World(d);
return d->world; return d->world;
} }
Position * API::getPosition() Position * Context::getPosition()
{ {
if(!d->position) if(!d->position)
d->position = new Position(d); d->position = new Position(d);
return d->position; return d->position;
} }
Materials * API::getMaterials() Materials * Context::getMaterials()
{ {
if(!d->materials) if(!d->materials)
d->materials = new Materials(d); d->materials = new Materials(d);
return d->materials; return d->materials;
} }
Items * API::getItems() Items * Context::getItems()
{ {
if(!d->items) if(!d->items)
d->items = new Items(d); d->items = new Items(d);
return d->items; return d->items;
} }
Translation * API::getTranslation() Translation * Context::getTranslation()
{ {
if(!d->translation) if(!d->translation)
d->translation = new Translation(d); d->translation = new Translation(d);
return d->translation; return d->translation;
} }
Vegetation * API::getVegetation() Vegetation * Context::getVegetation()
{ {
if(!d->vegetation) if(!d->vegetation)
d->vegetation = new Vegetation(d); d->vegetation = new Vegetation(d);
return d->vegetation; return d->vegetation;
} }
Buildings * API::getBuildings() Buildings * Context::getBuildings()
{ {
if(!d->buildings) if(!d->buildings)
d->buildings = new Buildings(d); d->buildings = new Buildings(d);
return d->buildings; return d->buildings;
} }
Constructions * API::getConstructions() Constructions * Context::getConstructions()
{ {
if(!d->constructions) if(!d->constructions)
d->constructions = new Constructions(d); d->constructions = new Constructions(d);

@ -0,0 +1,126 @@
/*
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 "Internal.h"
#include "dfhack/DFProcess.h"
#include "dfhack/DFProcessEnumerator.h"
#include "dfhack/DFMemInfoManager.h"
#include "dfhack/DFError.h"
#include "dfhack/DFContext.h"
#include "dfhack/DFContextManager.h"
#include <shms.h>
#include <mod-core.h>
#include <mod-maps.h>
#include <mod-creature40d.h>
#include "private/ContextShared.h"
using namespace DFHack;
namespace DFHack
{
class DFContextMgrPrivate
{
public:
DFContextMgrPrivate(){};
~DFContextMgrPrivate(){};
string xml; // path to xml
vector <Context *> contexts;
ProcessEnumerator * pEnum;
};
}
ContextManager::ContextManager (const string path_to_xml) : d (new DFContextMgrPrivate())
{
d->pEnum = 0;
d->xml = QUOT (MEMXML_DATA_PATH);
d->xml += "/";
d->xml += path_to_xml;
}
ContextManager::~ContextManager()
{
purge();
delete d;
}
uint32_t ContextManager::Refresh()
{
purge();
if(d->pEnum != 0)
d->pEnum = new ProcessEnumerator(d->xml);
else
{
delete d->pEnum;
d->pEnum = new ProcessEnumerator(d->xml);
}
d->pEnum->purge();
d->pEnum->findProcessess();
int numProcesses = d->pEnum->size();
for(int i = 0; i < numProcesses; i++)
{
Context * c = new Context(d->pEnum->operator[](i));
d->contexts.push_back(c);
}
return d->contexts.size();
}
uint32_t ContextManager::size()
{
return d->contexts.size();
}
Context * ContextManager::operator[](uint32_t index)
{
if (index < d->contexts.size())
return d->contexts[index];
return 0;
}
Context * ContextManager::getSingleContext()
{
if(!d->contexts.size())
{
Refresh();
}
for(int i = 0; i < d->contexts.size();i++)
{
if(d->contexts[i]->isValid())
{
return d->contexts[i];
}
}
throw DFHack::Error::NoProcess();
}
void ContextManager::purge(void)
{
for(int i = 0; i < d->contexts.size();i++)
delete d->contexts[i];
d->contexts.clear();
// process enumerator has to be destroyed after we detach from processes
// because it tracks and destroys them
if(d->pEnum)
{
delete d->pEnum;
d->pEnum = 0;
}
}

@ -0,0 +1,367 @@
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
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 "dfhack/DFPragma.h"
#include "dfhack/DFExport.h"
#include <string>
#include <vector>
#include <map>
#include "dfhack/DFIntegers.h"
#include "dfhack/DFTileTypes.h"
#include "dfhack/DFTypes.h"
//#include "dfhack/modules/WindowIO.h"
#include "dfhack/DFContextManager.h"
#include "dfhack/DFContext.h"
using namespace std;
using namespace DFHack;
#include "dfhack-c/DFContext_C.h"
#ifdef __cplusplus
extern "C" {
#endif
DFHackObject* ContextManager_Alloc(const char* path_to_xml)
{
DFHack::ContextManager* contextMgr = new DFHack::ContextManager(std::string(path_to_xml));
return (DFHackObject*)contextMgr;
}
//FIXME: X:\dfhack\DFHackContext_C.cpp:56: warning: deleting `DFHackObject* ' is undefined
//DC: Yeah, I forgot that trying to delete a void pointer might be a bad idea. This works now.
void ContextManager_Free(DFHackObject* contextMgr)
{
if(contextMgr != NULL)
{
DFHack::ContextManager* a = (DFHack::ContextManager*)contextMgr;
delete a;
contextMgr = NULL;
}
}
int ContextManager_Refresh(DFHackObject* contextMgr)
{
if(contextMgr != NULL)
{
return ((DFHack::ContextManager*)contextMgr)->Refresh();
}
return -1;
}
int ContextManager_size(DFHackObject* contextMgr, uint32_t* size)
{
if(contextMgr != NULL)
{
uint32_t result = ((DFHack::ContextManager*)contextMgr)->size();
*size = result;
return 1;
}
return -1;
}
int ContextManager_purge(DFHackObject* contextMgr)
{
if(contextMgr != NULL)
{
((DFHack::ContextManager*)contextMgr)->purge();
return 1;
}
return -1;
}
DFHackObject* ContextManager_getContext(DFHackObject* contextMgr, uint32_t index)
{
if(contextMgr != NULL)
{
DFHack::ContextManager* mgr = ((DFHack::ContextManager*)contextMgr);
if(index >= mgr->size())
return NULL;
return (DFHackObject*)((DFHack::Context*)((*mgr)[index]));
}
return NULL;
}
DFHackObject* ContextManager_getSingleContext(DFHackObject* contextMgr)
{
if(contextMgr != NULL)
{
return (DFHackObject*)((DFHack::ContextManager*)contextMgr)->getSingleContext();
}
return NULL;
}
void Context_Free(DFHackObject* context)
{
if(context != NULL)
{
DFHack::Context* c = (DFHack::Context*)context;
delete c;
context = NULL;
}
}
int Context_Attach(DFHackObject* context)
{
if(context != NULL)
{
return ((DFHack::Context*)context)->Attach();
}
return -1;
}
int Context_Detach(DFHackObject* context)
{
if(context != NULL)
{
return ((DFHack::Context*)context)->Detach();
}
return -1;
}
int Context_isAttached(DFHackObject* context)
{
if(context != NULL)
{
return ((DFHack::Context*)context)->isAttached();
}
return -1;
}
int Context_Suspend(DFHackObject* context)
{
if(context != NULL)
{
return ((DFHack::Context*)context)->Suspend();
}
return -1;
}
int Context_Resume(DFHackObject* context)
{
if(context != NULL)
{
return ((DFHack::Context*)context)->Resume();
}
return -1;
}
int Context_isSuspended(DFHackObject* context)
{
if(context != NULL)
{
return ((DFHack::Context*)context)->isSuspended();
}
return -1;
}
int Context_ForceResume(DFHackObject* context)
{
if(context != NULL)
{
return ((DFHack::Context*)context)->ForceResume();
}
return -1;
}
int Context_AsyncSuspend(DFHackObject* context)
{
if(context != NULL)
{
return ((DFHack::Context*)context)->AsyncSuspend();
}
return -1;
}
//module getters
DFHackObject* Context_getMemoryInfo(DFHackObject* context)
{
if(context != NULL)
{
return (DFHackObject*)((DFHack::Context*)context)->getMemoryInfo();
}
return NULL;
}
DFHackObject* Context_getProcess(DFHackObject* context)
{
if(context != NULL)
{
return (DFHackObject*)((DFHack::Context*)context)->getProcess();
}
return NULL;
}
DFHackObject* Context_getWindow(DFHackObject* context)
{
if(context != NULL)
{
return (DFHackObject*)((DFHack::Context*)context)->getWindow();
}
return NULL;
}
DFHackObject* Context_getCreatures(DFHackObject* context)
{
if(context != NULL)
{
return (DFHackObject*)((DFHack::Context*)context)->getCreatures();
}
return NULL;
}
DFHackObject* Context_getMaps(DFHackObject* context)
{
if(context != NULL)
{
return (DFHackObject*)((DFHack::Context*)context)->getMaps();
}
return NULL;
}
DFHackObject* Context_getGui(DFHackObject* context)
{
if(context != NULL)
{
return (DFHackObject*)((DFHack::Context*)context)->getGui();
}
return NULL;
}
DFHackObject* Context_getPosition(DFHackObject* context)
{
if(context != NULL)
{
return (DFHackObject*)((DFHack::Context*)context)->getPosition();
}
return NULL;
}
DFHackObject* Context_getMaterials(DFHackObject* context)
{
if(context != NULL)
{
return (DFHackObject*)((DFHack::Context*)context)->getMaterials();
}
return NULL;
}
DFHackObject* Context_getTranslation(DFHackObject* context)
{
if(context != NULL)
{
return (DFHackObject*)((DFHack::Context*)context)->getTranslation();
}
return NULL;
}
DFHackObject* Context_getVegetation(DFHackObject* context)
{
if(context != NULL)
{
return (DFHackObject*)((DFHack::Context*)context)->getVegetation();
}
return NULL;
}
DFHackObject* Context_getBuildings(DFHackObject* context)
{
if(context != NULL)
{
return (DFHackObject*)((DFHack::Context*)context)->getBuildings();
}
return NULL;
}
DFHackObject* Context_getConstructions(DFHackObject* context)
{
if(context != NULL)
{
return (DFHackObject*)((DFHack::Context*)context)->getConstructions();
}
return NULL;
}
DFHackObject* Context_getItems(DFHackObject* context)
{
if(context != NULL)
{
return (DFHackObject*)((DFHack::Context*)context)->getItems();
}
return NULL;
}
void Context_ReadRaw(DFHackObject* context, const uint32_t offset, const uint32_t size, uint8_t* target)
{
if(context != NULL)
{
((DFHack::Context*)context)->ReadRaw(offset, size, target);
}
}
void Context_WriteRaw(DFHackObject* context, const uint32_t offset, const uint32_t size, uint8_t* source)
{
if(context != NULL)
{
((DFHack::Context*)context)->WriteRaw(offset, size, source);
}
}
#ifdef __cplusplus
}
#endif

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

@ -22,10 +22,10 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "DFCommonInternal.h" #include "Internal.h"
#include "DFMemInfo.h" #include "dfhack/DFMemInfo.h"
#include "DFMemInfoManager.h" #include "dfhack/DFMemInfoManager.h"
#include "DFError.h" #include "dfhack/DFError.h"
using namespace DFHack; using namespace DFHack;

@ -21,11 +21,10 @@ must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source 3. This notice may not be removed or altered from any source
distribution. distribution.
*/ */
#include "DFCommonInternal.h" #include "Internal.h"
#include "DFProcess.h" #include "dfhack/DFProcess.h"
#include "DFWindow.h" #include "dfhack/DFMemInfo.h"
#include "DFMemInfo.h" #include "dfhack/DFError.h"
#include "DFError.h"
#include <errno.h> #include <errno.h>
#include <sys/shm.h> #include <sys/shm.h>
@ -53,7 +52,6 @@ class SHMProcess::Private
shm_addr = 0; shm_addr = 0;
//shm_addr_with_cl_idx = 0; //shm_addr_with_cl_idx = 0;
shm_ID = -1; shm_ID = -1;
window = NULL;
attached = false; attached = false;
identified = false; identified = false;
useYield = false; useYield = false;
@ -66,7 +64,6 @@ class SHMProcess::Private
}; };
~Private(){}; ~Private(){};
memory_info * memdescriptor; memory_info * memdescriptor;
DFWindow * window;
Process * self; Process * self;
pid_t process_ID; pid_t process_ID;
char *shm_addr; char *shm_addr;
@ -77,8 +74,6 @@ class SHMProcess::Private
int suspend_lock; int suspend_lock;
int attachmentIdx; int attachmentIdx;
bool attached; bool attached;
bool locked; bool locked;
bool identified; bool identified;
@ -290,8 +285,6 @@ SHMProcess::SHMProcess(uint32_t PID, vector< memory_info* >& known_versions)
// try to identify the DF version (md5 the binary, compare with known versions) // try to identify the DF version (md5 the binary, compare with known versions)
d->validate(known_versions); d->validate(known_versions);
d->window = new DFWindow(this);
// detach // detach
detach(); detach();
} }
@ -362,10 +355,6 @@ SHMProcess::~SHMProcess()
} }
if(d->memdescriptor) if(d->memdescriptor)
delete d->memdescriptor; delete d->memdescriptor;
if(d->window)
{
delete d->window;
}
delete d; delete d;
} }
@ -374,11 +363,6 @@ memory_info * SHMProcess::getDescriptor()
return d->memdescriptor; return d->memdescriptor;
} }
DFWindow * SHMProcess::getWindow()
{
return d->window;
}
int SHMProcess::getPID() int SHMProcess::getPID()
{ {
return d->process_ID; return d->process_ID;
@ -633,7 +617,7 @@ void SHMProcess::read (uint32_t src_address, uint32_t size, uint8_t *target_buff
D_SHMHDR->length = to_read; D_SHMHDR->length = to_read;
gcc_barrier gcc_barrier
d->SetAndWait(CORE_READ); d->SetAndWait(CORE_READ);
memcpy (target_buffer, D_SHMDATA(void) ,size); memcpy (target_buffer, D_SHMDATA(void) ,to_read);
// decrease size by bytes read // decrease size by bytes read
size -= to_read; size -= to_read;
// move the cursors // move the cursors

@ -21,13 +21,11 @@ must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source 3. This notice may not be removed or altered from any source
distribution. distribution.
*/ */
#include "DFCommonInternal.h" #include "Internal.h"
#include "DFProcess.h" #include "dfhack/DFProcess.h"
#include "DFWindow.h" #include "dfhack/DFMemInfo.h"
#include "DFMemInfo.h" #include "dfhack/DFError.h"
#include "DFError.h"
#include <errno.h> #include <errno.h>
#include <DFError.h>
#include <sys/ptrace.h> #include <sys/ptrace.h>
#include <stdio.h> #include <stdio.h>
using namespace DFHack; using namespace DFHack;
@ -39,7 +37,6 @@ class WineProcess::Private
{ {
my_descriptor = NULL; my_descriptor = NULL;
my_handle = NULL; my_handle = NULL;
my_window = NULL;
my_pid = 0; my_pid = 0;
attached = false; attached = false;
suspended = false; suspended = false;
@ -47,7 +44,6 @@ class WineProcess::Private
self = self_; self = self_;
}; };
~Private(){}; ~Private(){};
DFWindow* my_window;
memory_info * my_descriptor; memory_info * my_descriptor;
Process * self; Process * self;
pid_t my_handle; pid_t my_handle;
@ -109,7 +105,6 @@ WineProcess::WineProcess(uint32_t pid, vector <memory_info *> & known_versions)
// create wine process, add it to the vector // create wine process, add it to the vector
d->identified = d->validate(exe_link,pid,mem_name,known_versions); d->identified = d->validate(exe_link,pid,mem_name,known_versions);
d->my_window = new DFWindow(this);
return; return;
} }
} }
@ -175,8 +170,6 @@ WineProcess::~WineProcess()
// destroy our copy of the memory descriptor // destroy our copy of the memory descriptor
if(d->my_descriptor) if(d->my_descriptor)
delete d->my_descriptor; delete d->my_descriptor;
if(d->my_window)
delete d->my_window;
delete d; delete d;
} }
@ -185,11 +178,6 @@ memory_info * WineProcess::getDescriptor()
return d->my_descriptor; return d->my_descriptor;
} }
DFWindow * WineProcess::getWindow()
{
return d->my_window;
}
int WineProcess::getPID() int WineProcess::getPID()
{ {
return d->my_pid; return d->my_pid;
@ -514,7 +502,6 @@ void WineProcess::writeByte (uint32_t offset, uint8_t data)
// blah. I hate the kernel devs for crippling /proc/PID/mem. THIS IS RIDICULOUS // blah. I hate the kernel devs for crippling /proc/PID/mem. THIS IS RIDICULOUS
void WineProcess::write (uint32_t offset, uint32_t size, uint8_t *source) void WineProcess::write (uint32_t offset, uint32_t size, uint8_t *source)
{ {
uint32_t count = 0;
uint32_t indexptr = 0; uint32_t indexptr = 0;
while (size > 0) while (size > 0)
{ {

@ -21,11 +21,10 @@ must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source 3. This notice may not be removed or altered from any source
distribution. distribution.
*/ */
#include "DFCommonInternal.h" #include "Internal.h"
#include "DFProcess.h" #include "dfhack/DFProcess.h"
#include "DFWindow.h" #include "dfhack/DFMemInfo.h"
#include "DFMemInfo.h" #include "dfhack/DFError.h"
#include "DFError.h"
#include <errno.h> #include <errno.h>
#include <sys/ptrace.h> #include <sys/ptrace.h>
using namespace DFHack; using namespace DFHack;
@ -37,7 +36,6 @@ class NormalProcess::Private
{ {
my_descriptor = NULL; my_descriptor = NULL;
my_handle = NULL; my_handle = NULL;
my_window = NULL;
my_pid = 0; my_pid = 0;
attached = false; attached = false;
suspended = false; suspended = false;
@ -45,7 +43,7 @@ class NormalProcess::Private
self = self_; self = self_;
}; };
~Private(){}; ~Private(){};
DFWindow* my_window; Window* my_window;
memory_info * my_descriptor; memory_info * my_descriptor;
pid_t my_handle; pid_t my_handle;
uint32_t my_pid; uint32_t my_pid;
@ -92,7 +90,6 @@ NormalProcess::NormalProcess(uint32_t pid, vector< memory_info* >& known_version
{ {
// create linux process, add it to the vector // create linux process, add it to the vector
d->identified = d->validate(target_name,pid,mem_name,known_versions ); d->identified = d->validate(target_name,pid,mem_name,known_versions );
d->my_window = new DFWindow(this);
return; return;
} }
} }
@ -161,9 +158,6 @@ NormalProcess::~NormalProcess()
// destroy our copy of the memory descriptor // destroy our copy of the memory descriptor
if(d->my_descriptor) if(d->my_descriptor)
delete d->my_descriptor; delete d->my_descriptor;
// destroy data model. this is assigned by processmanager
if(d->my_window)
delete d->my_window;
delete d; delete d;
} }
@ -172,11 +166,6 @@ memory_info * NormalProcess::getDescriptor()
return d->my_descriptor; return d->my_descriptor;
} }
DFWindow * NormalProcess::getWindow()
{
return d->my_window;
}
int NormalProcess::getPID() int NormalProcess::getPID()
{ {
return d->my_pid; return d->my_pid;
@ -370,14 +359,14 @@ void NormalProcess::read (const uint32_t offset, const uint32_t size, uint8_t *t
{ {
if(result == -1) if(result == -1)
{ {
cerr << "pread failed: can't read " << size << " bytes at addres " << offset << endl; cerr << "pread failed: can't read 0x" << hex << size << " bytes at address 0x" << offset << endl;
cerr << "errno: " << errno << endl; cerr << "errno: " << errno << endl;
errno = 0; errno = 0;
throw Error::MemoryAccessDenied(); throw Error::MemoryAccessDenied();
} }
else else
{ {
read(offset + result, size - result, target + result); this->read(offset + result, size - result, target + result);
} }
} }
} }
@ -498,7 +487,6 @@ void NormalProcess::writeByte (uint32_t offset, uint8_t data)
// blah. I hate the kernel devs for crippling /proc/PID/mem. THIS IS RIDICULOUS // blah. I hate the kernel devs for crippling /proc/PID/mem. THIS IS RIDICULOUS
void NormalProcess::write (uint32_t offset, uint32_t size, uint8_t *source) void NormalProcess::write (uint32_t offset, uint32_t size, uint8_t *source)
{ {
uint32_t count = 0;
uint32_t indexptr = 0; uint32_t indexptr = 0;
while (size > 0) while (size > 0)
{ {

@ -21,11 +21,10 @@ must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source 3. This notice may not be removed or altered from any source
distribution. distribution.
*/ */
#include "DFCommonInternal.h" #include "Internal.h"
#include "DFProcess.h" #include "dfhack/DFProcess.h"
#include "DFWindow.h" #include "dfhack/DFMemInfo.h"
#include "DFMemInfo.h" #include "dfhack/DFError.h"
#include "DFError.h"
#include "shms.h" #include "shms.h"
#include "mod-core.h" #include "mod-core.h"
using namespace DFHack; using namespace DFHack;
@ -39,7 +38,6 @@ class SHMProcess::Private
memdescriptor = NULL; memdescriptor = NULL;
process_ID = 0; process_ID = 0;
shm_addr = 0; shm_addr = 0;
window = NULL;
attached = false; attached = false;
locked = false; locked = false;
identified = false; identified = false;
@ -51,7 +49,6 @@ class SHMProcess::Private
}; };
~Private(){}; ~Private(){};
memory_info * memdescriptor; memory_info * memdescriptor;
DFWindow * window;
SHMProcess * self; SHMProcess * self;
uint32_t process_ID; uint32_t process_ID;
char *shm_addr; char *shm_addr;
@ -300,7 +297,6 @@ SHMProcess::SHMProcess(uint32_t PID, vector <memory_info *> & known_versions)
throw Error::SHMVersionMismatch(); throw Error::SHMVersionMismatch();
} }
d->validate(known_versions); d->validate(known_versions);
d->window = new DFWindow(this);
// at this point, DF is attached and suspended, make it run // at this point, DF is attached and suspended, make it run
detach(); detach();
} }
@ -386,10 +382,6 @@ SHMProcess::~SHMProcess()
{ {
delete d->memdescriptor; delete d->memdescriptor;
} }
if(d->window)
{
delete d->window;
}
delete d; delete d;
} }
@ -398,11 +390,6 @@ memory_info * SHMProcess::getDescriptor()
return d->memdescriptor; return d->memdescriptor;
} }
DFWindow * SHMProcess::getWindow()
{
return d->window;
}
int SHMProcess::getPID() int SHMProcess::getPID()
{ {
return d->process_ID; return d->process_ID;
@ -691,7 +678,7 @@ void SHMProcess::read (uint32_t src_address, uint32_t size, uint8_t *target_buff
D_SHMHDR->length = to_read; D_SHMHDR->length = to_read;
full_barrier full_barrier
d->SetAndWait(CORE_READ); d->SetAndWait(CORE_READ);
memcpy (target_buffer, D_SHMDATA(void) ,size); memcpy (target_buffer, D_SHMDATA(void) ,to_read);
// decrease size by bytes read // decrease size by bytes read
size -= to_read; size -= to_read;
// move the cursors // move the cursors

@ -21,11 +21,10 @@ must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source 3. This notice may not be removed or altered from any source
distribution. distribution.
*/ */
#include "DFCommonInternal.h" #include "Internal.h"
#include "DFProcess.h" #include "dfhack/DFProcess.h"
#include "DFWindow.h" #include "dfhack/DFMemInfo.h"
#include "DFMemInfo.h" #include "dfhack/DFError.h"
#include "DFError.h"
using namespace DFHack; using namespace DFHack;
class NormalProcess::Private class NormalProcess::Private
@ -36,14 +35,12 @@ class NormalProcess::Private
my_descriptor = NULL; my_descriptor = NULL;
my_handle = NULL; my_handle = NULL;
my_main_thread = NULL; my_main_thread = NULL;
my_window = NULL;
my_pid = 0; my_pid = 0;
attached = false; attached = false;
suspended = false; suspended = false;
}; };
~Private(){}; ~Private(){};
memory_info * my_descriptor; memory_info * my_descriptor;
DFWindow * my_window;
HANDLE my_handle; HANDLE my_handle;
HANDLE my_main_thread; HANDLE my_main_thread;
uint32_t my_pid; uint32_t my_pid;
@ -147,10 +144,6 @@ NormalProcess::NormalProcess(uint32_t pid, vector <memory_info *> & known_versio
{ {
CloseHandle(hProcess); CloseHandle(hProcess);
} }
else
{
d->my_window = new DFWindow(this);
}
} }
/* /*
*/ */
@ -171,10 +164,6 @@ NormalProcess::~NormalProcess()
{ {
CloseHandle(d->my_main_thread); CloseHandle(d->my_main_thread);
} }
if(d->my_window)
{
delete d->my_window;
}
delete d; delete d;
} }
@ -183,11 +172,6 @@ memory_info * NormalProcess::getDescriptor()
return d->my_descriptor; return d->my_descriptor;
} }
DFWindow * NormalProcess::getWindow()
{
return d->my_window;
}
int NormalProcess::getPID() int NormalProcess::getPID()
{ {
return d->my_pid; return d->my_pid;
@ -438,7 +422,7 @@ const string NormalProcess::readCString (const uint32_t offset)
{ {
string temp; string temp;
char temp_c[256]; char temp_c[256];
DWORD read; SIZE_T read;
if(!ReadProcessMemory(d->my_handle, (int *) offset, temp_c, 254, &read)) if(!ReadProcessMemory(d->my_handle, (int *) offset, temp_c, 254, &read))
throw Error::MemoryAccessDenied(); throw Error::MemoryAccessDenied();
// needs to be 254+1 byte for the null term // needs to be 254+1 byte for the null term

@ -22,11 +22,11 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "DFCommonInternal.h" #include "Internal.h"
#include "DFProcessEnumerator.h" #include "dfhack/DFProcessEnumerator.h"
#include "DFProcess.h" #include "dfhack/DFProcess.h"
#include "DFMemInfo.h" #include "dfhack/DFMemInfo.h"
#include "DFMemInfoManager.h" #include "dfhack/DFMemInfoManager.h"
#include <sys/shm.h> #include <sys/shm.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/ipc.h> #include <sys/ipc.h>

@ -22,11 +22,11 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "DFCommonInternal.h" #include "Internal.h"
#include "DFProcessEnumerator.h" #include "dfhack/DFProcessEnumerator.h"
#include "DFProcess.h" #include "dfhack/DFProcess.h"
#include "DFMemInfo.h" #include "dfhack/DFMemInfo.h"
#include "DFMemInfoManager.h" #include "dfhack/DFMemInfoManager.h"
using namespace DFHack; using namespace DFHack;
class DFHack::ProcessEnumerator::Private class DFHack::ProcessEnumerator::Private

@ -0,0 +1,114 @@
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
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 "dfhack/DFIntegers.h"
#include <stdlib.h>
#include "string.h"
#include <vector>
#include <algorithm>
using namespace std;
#include "Internal.h"
#include "dfhack/DFTypes.h"
#include "dfhack-c/DFTypes_C.h"
#include "dfhack/modules/Materials.h"
using namespace DFHack;
#ifdef __cplusplus
extern "C" {
#endif
int8_t* (*alloc_byte_buffer_callback)(uint32_t) = NULL;
int16_t* (*alloc_short_buffer_callback)(uint32_t) = NULL;
int32_t* (*alloc_int_buffer_callback)(uint32_t) = NULL;
uint8_t* (*alloc_ubyte_buffer_callback)(uint32_t) = NULL;
uint16_t* (*alloc_ushort_buffer_callback)(uint32_t) = NULL;
uint32_t* (*alloc_uint_buffer_callback)(uint32_t) = NULL;
char* (*alloc_char_buffer_callback)(uint32_t) = NULL;
t_matgloss* (*alloc_matgloss_buffer_callback)(int) = NULL;
t_descriptor_color* (*alloc_descriptor_buffer_callback)(int) = NULL;
t_matglossOther* (*alloc_matgloss_other_buffer_callback)(int) = NULL;
c_colormodifier* (*alloc_empty_colormodifier_callback)(void) = NULL;
c_colormodifier* (*alloc_colormodifier_callback)(const char*, uint32_t) = NULL;
c_colormodifier* (*alloc_colormodifier_buffer_callback)(uint32_t) = NULL;
c_creaturecaste* (*alloc_empty_creaturecaste_callback)(void) = NULL;
c_creaturecaste* (*alloc_creaturecaste_callback)(const char*, const char*, const char*, const char*, uint32_t, uint32_t) = NULL;
c_creaturecaste* (*alloc_creaturecaste_buffer_callback)(uint32_t) = NULL;
c_creaturetype* (*alloc_empty_creaturetype_callback)(void) = NULL;
c_creaturetype* (*alloc_creaturetype_callback)(const char*, uint32_t, uint32_t, uint8_t, uint16_t, uint16_t, uint16_t) = NULL;
c_creaturetype* (*alloc_creaturetype_buffer_callback)(uint32_t) = NULL;
#ifdef __cplusplus
}
#endif
int ColorListConvert(t_colormodifier* src, c_colormodifier* dest)
{
if(src == NULL)
return -1;
dest = ((*alloc_colormodifier_callback)(src->part, src->colorlist.size()));
copy(src->colorlist.begin(), src->colorlist.end(), dest->colorlist);
return 1;
}
int CreatureCasteConvert(t_creaturecaste* src, c_creaturecaste* dest)
{
if(src == NULL)
return -1;
dest = ((*alloc_creaturecaste_callback)(src->rawname, src->singular, src->plural, src->adjective, src->ColorModifier.size(), src->bodypart.size()));
for(int i = 0; i < dest->colorModifierLength; i++)
ColorListConvert(&src->ColorModifier[i], &dest->ColorModifier[i]);
copy(src->bodypart.begin(), src->bodypart.end(), dest->bodypart);
return 1;
}
int CreatureTypeConvert(t_creaturetype* src, c_creaturetype* dest)
{
if(src == NULL)
return -1;
dest = ((*alloc_creaturetype_callback)(src->rawname, src->castes.size(), src->extract.size(), src->tile_character, src->tilecolor.fore, src->tilecolor.back, src->tilecolor.bright));
for(int i = 0; i < dest->castesCount; i++)
CreatureCasteConvert(&src->castes[i], &dest->castes[i]);
copy(src->extract.begin(), src->extract.end(), dest->extract);
return 1;
}

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

@ -0,0 +1,26 @@
#ifndef DFHACK_API_H
#define DFHACK_API_H
#include "dfhack/DFIntegers.h"
#include "dfhack/DFGlobal.h"
#include "dfhack/DFError.h"
#include "dfhack/DFContextManager.h"
#include "dfhack/DFContext.h"
#include "dfhack/DFMemInfo.h"
#include "dfhack/DFProcess.h"
#include "dfhack/DFTypes.h"
#include "dfhack/modules/Buildings.h"
#include "dfhack/modules/Materials.h"
#include "dfhack/modules/Position.h"
#include "dfhack/modules/Constructions.h"
#include "dfhack/modules/Creatures.h"
#include "dfhack/modules/Translation.h"
#include "dfhack/modules/World.h"
#include "dfhack/modules/Items.h"
#include "dfhack/modules/Vegetation.h"
#include "dfhack/modules/Maps.h"
#include "dfhack/DFMiscUtils.h"
#endif

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -22,8 +22,22 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "DFCommonInternal.h" #ifndef DFHACK_C_API
#include "DFTileTypes.h" #define DFHACK_C_API
using namespace DFHack; typedef void DFHackObject;
#include "dfhack/DFExport.h"
#include "dfhack/DFIntegers.h"
#include "dfhack-c/DFContext_C.h"
#include "dfhack-c/DFTypes_C.h"
#ifdef __cplusplus
extern "C" {
#endif
// some global stuff here
#ifdef __cplusplus
}
#endif
#endif

@ -0,0 +1,82 @@
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
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 DFHACK_C_CONTEXT
#define DFHACK_C_CONTEXT
#include "dfhack/DFExport.h"
#include "dfhack/DFIntegers.h"
typedef void DFHackObject;
#ifdef __cplusplus
extern "C" {
#endif
DFHACK_EXPORT DFHackObject* ContextManager_Alloc(const char* path_to_xml);
DFHACK_EXPORT void ContextManager_Free(DFHackObject* contextMgr);
DFHACK_EXPORT int ContextManager_Refresh(DFHackObject* contextMgr);
DFHACK_EXPORT int ContextManager_size(DFHackObject* contextMgr, uint32_t* size);
DFHACK_EXPORT int ContextManager_purge(DFHackObject* contextMgr);
DFHACK_EXPORT DFHackObject* ContextManager_getContext(DFHackObject* contextMgr, uint32_t index);
DFHACK_EXPORT DFHackObject* ContextManager_getSingleContext(DFHackObject* contextMgr);
DFHACK_EXPORT void Context_Free(DFHackObject* context);
DFHACK_EXPORT int Context_Attach(DFHackObject* context);
DFHACK_EXPORT int Context_Detach(DFHackObject* context);
DFHACK_EXPORT int Context_isAttached(DFHackObject* context);
DFHACK_EXPORT int Context_Suspend(DFHackObject* context);
DFHACK_EXPORT int Context_Resume(DFHackObject* context);
DFHACK_EXPORT int Context_isSuspended(DFHackObject* context);
DFHACK_EXPORT int Context_ForceResume(DFHackObject* context);
DFHACK_EXPORT int Context_AsyncSuspend(DFHackObject* context);
DFHACK_EXPORT DFHackObject* Context_getMemoryInfo(DFHackObject* context);
DFHACK_EXPORT DFHackObject* Context_getProcess(DFHackObject* context);
DFHACK_EXPORT DFHackObject* Context_getWindow(DFHackObject* context);
DFHACK_EXPORT DFHackObject* Context_getCreatures(DFHackObject* context);
DFHACK_EXPORT DFHackObject* Context_getMaps(DFHackObject* context);
DFHACK_EXPORT DFHackObject* Context_getGui(DFHackObject* context);
DFHACK_EXPORT DFHackObject* Context_getPosition(DFHackObject* context);
DFHACK_EXPORT DFHackObject* Context_getMaterials(DFHackObject* context);
DFHACK_EXPORT DFHackObject* Context_getTranslation(DFHackObject* context);
DFHACK_EXPORT DFHackObject* Context_getVegetation(DFHackObject* context);
DFHACK_EXPORT DFHackObject* Context_getBuildings(DFHackObject* context);
DFHACK_EXPORT DFHackObject* Context_getConstructions(DFHackObject* context);
DFHACK_EXPORT DFHackObject* Context_getItems(DFHackObject* context);
//these are DANGEROUS...can crash/segfault DF, turn the seas to blood, call up the Antichrist, etc
DFHACK_EXPORT void Context_ReadRaw(DFHackObject* context, const uint32_t offset, const uint32_t size, uint8_t* target);
DFHACK_EXPORT void Context_WriteRaw(DFHackObject* context, const uint32_t offset, const uint32_t size, uint8_t* source);
#ifdef __cplusplus
}
#endif
#endif

@ -0,0 +1,114 @@
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
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 TYPES_C_API
#define TYPES_C_API
#include "dfhack/DFExport.h"
#include "dfhack/DFIntegers.h"
#include "dfhack/DFTypes.h"
#include "dfhack/modules/Materials.h"
using namespace DFHack;
#ifdef __cplusplus
extern "C" {
#endif
DFHACK_EXPORT extern int8_t* (*alloc_byte_buffer_callback)(uint32_t);
DFHACK_EXPORT extern int16_t* (*alloc_short_buffer_callback)(uint32_t);
DFHACK_EXPORT extern int32_t* (*alloc_int_buffer_callback)(uint32_t);
DFHACK_EXPORT extern uint8_t* (*alloc_ubyte_buffer_callback)(uint32_t);
DFHACK_EXPORT extern uint16_t* (*alloc_ushort_buffer_callback)(uint32_t);
DFHACK_EXPORT extern uint32_t* (*alloc_uint_buffer_callback)(uint32_t);
DFHACK_EXPORT extern char* (*alloc_char_buffer_callback)(uint32_t);
DFHACK_EXPORT extern t_matgloss* (*alloc_matgloss_buffer_callback)(int);
DFHACK_EXPORT extern t_descriptor_color* (*alloc_descriptor_buffer_callback)(int);
DFHACK_EXPORT extern t_matglossOther* (*alloc_matgloss_other_buffer_callback)(int);
struct c_colormodifier
{
char part[128];
uint32_t* colorlist;
uint32_t colorlistLength;
};
DFHACK_EXPORT extern c_colormodifier* (*alloc_empty_colormodifier_callback)(void);
DFHACK_EXPORT extern c_colormodifier* (*alloc_colormodifier_callback)(const char*, uint32_t);
DFHACK_EXPORT extern c_colormodifier* (*alloc_colormodifier_buffer_callback)(uint32_t);
struct c_creaturecaste
{
char rawname[128];
char singular[128];
char plural[128];
char adjective[128];
c_colormodifier* ColorModifier;
uint32_t colorModifierLength;
t_bodypart* bodypart;
uint32_t bodypartLength;
};
DFHACK_EXPORT extern c_creaturecaste* (*alloc_empty_creaturecaste_callback)(void);
DFHACK_EXPORT extern c_creaturecaste* (*alloc_creaturecaste_callback)(const char*, const char*, const char*, const char*, uint32_t, uint32_t);
DFHACK_EXPORT extern c_creaturecaste* (*alloc_creaturecaste_buffer_callback)(uint32_t);
struct c_creaturetype
{
char rawname[128];
c_creaturecaste* castes;
uint32_t castesCount;
t_creatureextract* extract;
uint32_t extractCount;
uint8_t tile_character;
struct
{
uint16_t fore;
uint16_t back;
uint16_t bright;
} tilecolor;
};
DFHACK_EXPORT extern c_creaturetype* (*alloc_empty_creaturetype_callback)(void);
DFHACK_EXPORT extern c_creaturetype* (*alloc_creaturetype_callback)(const char*, uint32_t, uint32_t, uint8_t, uint16_t, uint16_t, uint16_t);
DFHACK_EXPORT extern c_creaturetype* (*alloc_creaturetype_buffer_callback)(uint32_t);
#ifdef __cplusplus
}
#endif
int CreatureTypeConvert(t_creaturetype* src, c_creaturetype* dest);
int CreatureCasteConvert(t_creaturecaste* src, c_creaturecaste* dest);
int ColorListConvert(t_colormodifier* src, c_colormodifier* dest);
#endif

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -25,11 +25,11 @@ distribution.
#ifndef BUILDINGS_C_API #ifndef BUILDINGS_C_API
#define BUILDINGS_C_API #define BUILDINGS_C_API
#include "Export.h" #include "dfhack/DFExport.h"
#include "integers.h" #include "dfhack/DFIntegers.h"
#include "DFTypes.h" #include "dfhack/DFTypes.h"
#include "modules/Buildings.h" #include "dfhack/modules/Buildings.h"
#include "DFHackAPI_C.h" #include "DFHack_C.h"
using namespace DFHack; using namespace DFHack;

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -25,11 +25,11 @@ distribution.
#ifndef CONSTRUCTIONS_C_API #ifndef CONSTRUCTIONS_C_API
#define CONSTRUCTIONS_C_API #define CONSTRUCTIONS_C_API
#include "Export.h" #include "dfhack/DFExport.h"
#include "integers.h" #include "dfhack/DFIntegers.h"
#include "DFTypes.h" #include "dfhack/DFTypes.h"
#include "modules/Constructions.h" #include "dfhack/modules/Constructions.h"
#include "DFHackAPI_C.h" #include "DFHack_C.h"
using namespace DFHack; using namespace DFHack;

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -25,12 +25,12 @@ distribution.
#ifndef CREATURES_C_API #ifndef CREATURES_C_API
#define CREATURES_C_API #define CREATURES_C_API
#include "Export.h" #include "dfhack/DFExport.h"
#include "integers.h" #include "dfhack/DFIntegers.h"
#include "DFTypes.h" #include "DFHack_C.h"
#include "modules/Materials.h" #include "dfhack/DFTypes.h"
#include "modules/Creatures.h" #include "dfhack/modules/Materials.h"
#include "DFHackAPI_C.h" #include "dfhack/modules/Creatures.h"
using namespace DFHack; using namespace DFHack;

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -25,10 +25,9 @@ distribution.
#ifndef GUI_C_API #ifndef GUI_C_API
#define GUI_C_API #define GUI_C_API
#include "Export.h" #include "dfhack/DFExport.h"
#include "integers.h" #include "dfhack/DFIntegers.h"
#include "DFTypes.h" #include "dfhack/DFTypes.h"
#include "DFHackAPI_C.h"
using namespace DFHack; using namespace DFHack;

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -25,20 +25,22 @@ distribution.
#ifndef ITEMS_C_API #ifndef ITEMS_C_API
#define ITEMS_C_API #define ITEMS_C_API
#include "Export.h" #include "dfhack/DFExport.h"
#include "integers.h" #include "dfhack/DFIntegers.h"
#include "DFTypes.h" #include "Internal.h"
#include "modules/Items.h"
#include "DFHackAPI_C.h"
using namespace DFHack; using namespace DFHack;
#include "dfhack/DFTypes.h"
#include "dfhack/modules/Items.h"
#include "DFHack_C.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
DFHACK_EXPORT char* Items_getItemDescription(DFHackObject* items, uint32_t itemptr, DFHackObject* mats, char* (*char_buffer_create)(int)); DFHACK_EXPORT char* Items_getItemDescription(DFHackObject* items, uint32_t itemptr, DFHackObject* mats);
DFHACK_EXPORT char* Items_getItemClass(DFHackObject* items, int32_t index, char* (*char_buffer_create)(int)); DFHACK_EXPORT char* Items_getItemClass(DFHackObject* items, int32_t index);
DFHACK_EXPORT int Items_getItemData(DFHackObject* items, uint32_t itemptr, t_item* item); DFHACK_EXPORT int Items_getItemData(DFHackObject* items, uint32_t itemptr, t_item* item);
#ifdef __cplusplus #ifdef __cplusplus

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -25,17 +25,17 @@ distribution.
#ifndef MAPS_C_API #ifndef MAPS_C_API
#define MAPS_C_API #define MAPS_C_API
#include "Export.h" #include "dfhack/DFExport.h"
#include "integers.h" #include "dfhack/DFIntegers.h"
#include <vector> #include <vector>
#include <map> #include <map>
#include <string> #include <string>
using namespace std; using namespace std;
#include "DFTypes.h" #include "dfhack/DFTypes.h"
#include "modules/Maps.h" #include "dfhack/modules/Maps.h"
#include "DFHackAPI_C.h" #include "DFHack_C.h"
using namespace DFHack; using namespace DFHack;

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -25,12 +25,12 @@ distribution.
#ifndef MATERIALS_C_API #ifndef MATERIALS_C_API
#define MATERIALS_C_API #define MATERIALS_C_API
#include "Export.h" #include "dfhack/DFExport.h"
#include "integers.h" #include "dfhack/DFIntegers.h"
#include "DFTypes.h" #include "dfhack/DFTypes.h"
#include "modules/Materials.h" #include "dfhack/modules/Materials.h"
#include "DFHackAPI_C.h" #include "DFHack_C.h"
#include "DFTypes_C.h" #include "dfhack-c/DFTypes_C.h"
using namespace DFHack; using namespace DFHack;
@ -38,10 +38,6 @@ using namespace DFHack;
extern "C" { extern "C" {
#endif #endif
typedef t_matgloss* (*MatglossBufferFunc)(int);
typedef t_descriptor_color* (*DescriptorColorBufferFunc)(int);
typedef t_matglossOther* (*MatglossOtherBufferFunc)(int);
DFHACK_EXPORT int Materials_ReadInorganicMaterials(DFHackObject* mat); DFHACK_EXPORT int Materials_ReadInorganicMaterials(DFHackObject* mat);
DFHACK_EXPORT int Materials_ReadOrganicMaterials(DFHackObject* mat); DFHACK_EXPORT int Materials_ReadOrganicMaterials(DFHackObject* mat);
DFHACK_EXPORT int Materials_ReadWoodMaterials(DFHackObject* mat); DFHACK_EXPORT int Materials_ReadWoodMaterials(DFHackObject* mat);
@ -64,20 +60,16 @@ DFHACK_EXPORT int Materials_getRaceExSize(DFHackObject* mat);
DFHACK_EXPORT int Materials_getColorSize(DFHackObject* mat); DFHACK_EXPORT int Materials_getColorSize(DFHackObject* mat);
DFHACK_EXPORT int Materials_getOtherSize(DFHackObject* mat); DFHACK_EXPORT int Materials_getOtherSize(DFHackObject* mat);
DFHACK_EXPORT int Materials_getInorganic(DFHackObject* mat, MatglossBufferFunc callback); DFHACK_EXPORT t_matgloss* Materials_getInorganic(DFHackObject* mat);
DFHACK_EXPORT int Materials_getOrganic(DFHackObject* mat, MatglossBufferFunc callback); DFHACK_EXPORT t_matgloss* Materials_getOrganic(DFHackObject* mat);
DFHACK_EXPORT int Materials_getTree(DFHackObject* mat, MatglossBufferFunc callback); DFHACK_EXPORT t_matgloss* Materials_getTree(DFHackObject* mat);
DFHACK_EXPORT int Materials_getPlant(DFHackObject* mat, MatglossBufferFunc callback); DFHACK_EXPORT t_matgloss* Materials_getPlant(DFHackObject* mat);
DFHACK_EXPORT int Materials_getRace(DFHackObject* mat, MatglossBufferFunc callback); DFHACK_EXPORT t_matgloss* Materials_getRace(DFHackObject* mat);
/*doomchild: DFHACK_EXPORT c_creaturetype* Materials_getRaceEx(DFHackObject* mat);
I haven't done getRaceEx yet, because I'm not sure about the best way to make the t_creaturetype struct
accessible from C.
*/
//DFHACK_EXPORT int Materials_getRaceEx(DFHackObject* mat, c_creaturetype* (*c_creaturetype_buffer_create)(c_creaturetype_descriptor*, int));
DFHACK_EXPORT int Materials_getColor(DFHackObject* mat, DescriptorColorBufferFunc callback); DFHACK_EXPORT t_descriptor_color* Materials_getColor(DFHackObject* mat);
DFHACK_EXPORT int Materials_getOther(DFHackObject* mat, MatglossOtherBufferFunc callback); DFHACK_EXPORT t_matglossOther* Materials_getOther(DFHackObject* mat);
#ifdef __cplusplus #ifdef __cplusplus
} }

@ -25,9 +25,8 @@ distribution.
#ifndef POSITION_C_API #ifndef POSITION_C_API
#define POSITION_C_API #define POSITION_C_API
#include "Export.h" #include "dfhack/DFExport.h"
#include "DFHack_C.h"
#include "DFHackAPI_C.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -25,11 +25,11 @@ distribution.
#ifndef TRANSLATION_C_API #ifndef TRANSLATION_C_API
#define TRANSLATION_C_API #define TRANSLATION_C_API
#include "Export.h" #include "dfhack/DFExport.h"
#include "integers.h" #include "dfhack/DFIntegers.h"
#include "DFTypes.h" #include "dfhack/DFTypes.h"
#include "modules/Translation.h" #include "dfhack/modules/Translation.h"
#include "DFHackAPI_C.h" #include "DFHack_C.h"
using namespace DFHack; using namespace DFHack;

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -25,11 +25,11 @@ distribution.
#ifndef VEGETATION_C_API #ifndef VEGETATION_C_API
#define VEGETATION_C_API #define VEGETATION_C_API
#include "Export.h" #include "dfhack/DFExport.h"
#include "integers.h" #include "dfhack/DFIntegers.h"
#include "DFTypes.h" #include "dfhack/DFTypes.h"
#include "modules/Vegetation.h" #include "dfhack/modules/Vegetation.h"
#include "DFHackAPI_C.h" #include "DFHack_C.h"
using namespace DFHack; using namespace DFHack;

@ -1,3 +1,4 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
@ -22,75 +23,60 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#ifndef SIMPLEAPI_H_INCLUDED #ifndef CONTEXT_H_INCLUDED
#define SIMPLEAPI_H_INCLUDED #define CONTEXT_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"
#include "DFExport.h"
namespace DFHack namespace DFHack
{ {
class APIPrivate;
class memory_info;
class Process;
// modules
class Maps;
class Creatures; class Creatures;
class Position; class Maps;
class Gui; class Gui;
class World; class World;
class Position;
class Materials; class Materials;
class Items;
class Translation; class Translation;
class Vegetation; class Vegetation;
class Buildings; class Buildings;
class Constructions; class Constructions;
class Items; class memory_info;
class DFContextShared;
class WindowIO;
class Process;
class DFHACK_EXPORT API class DFHACK_EXPORT Context
{ {
APIPrivate * const d; public:
public: Context(Process * p);
API(const std::string path_to_xml); ~Context();
~API();
/* bool isValid();
* Basic control over DF's process state
*/
bool Attach(); bool Attach();
bool Detach(); bool Detach();
bool isAttached(); bool isAttached();
/// stop DF from executing /// stop the tracked process
bool Suspend(); bool Suspend();
bool isSuspended(); bool isSuspended();
/// stop DF from executing, asynchronous, use with polling /// stop the tracked process, asynchronous
bool AsyncSuspend(); bool AsyncSuspend();
/// resume DF /// resume the tracked process
bool Resume(); bool Resume();
/// forces resume on Windows. This can be a bad thing with multiple DF tools running! /// forces resume on Windows. This can be a bad thing with multiple tools running!
bool ForceResume(); bool ForceResume();
memory_info *getMemoryInfo(); memory_info *getMemoryInfo();
Process * getProcess(); 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 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); void WriteRaw (const uint32_t offset, const uint32_t size, uint8_t *source);
// FIXME: this is crap.
// get the creatures module // get the creatures module
Creatures * getCreatures(); Creatures * getCreatures();
@ -109,7 +95,7 @@ namespace DFHack
// get the materials module // get the materials module
Materials * getMaterials(); Materials * getMaterials();
// get the items module // get the items module
Items * getItems(); Items * getItems();
// get the translation module // get the translation module
@ -124,6 +110,8 @@ namespace DFHack
// get the constructions module // get the constructions module
Constructions * getConstructions(); Constructions * getConstructions();
// get the Window management and I/O module
WindowIO * getWindow();
/* /*
* Effects like mist, dragonfire or dust * Effects like mist, dragonfire or dust
*/ */
@ -182,6 +170,9 @@ namespace DFHack
bool ReadAllMatgloss(vector< vector< string > > & all); bool ReadAllMatgloss(vector< vector< string > > & all);
*/ */
//bool ReadItemTypes(std::vector< std::vector< t_itemType > > & itemTypes); //bool ReadItemTypes(std::vector< std::vector< t_itemType > > & itemTypes);
private:
DFContextShared * d;
}; };
} // namespace DFHack }
#endif // SIMPLEAPI_H_INCLUDED #endif //CONTEXT_H_INCLUDED

@ -22,10 +22,31 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "Tranquility.h" #ifndef CONTEXTMANAGER_H_INCLUDED
#include "DFCommonInternal.h" #define CONTEXTMANAGER_H_INCLUDED
#include "DFMemInfo.h"
#include "DFProcess.h"
#include "DFVector.h"
using namespace DFHack;
#include "DFPragma.h"
#include "DFExport.h"
#include <string>
#include <vector>
#include <map>
namespace DFHack
{
class Context;
class DFContextMgrPrivate;
class DFHACK_EXPORT ContextManager
{
DFContextMgrPrivate * const d;
public:
ContextManager(const std::string path_to_xml);
~ContextManager();
uint32_t Refresh();
uint32_t size();
Context * operator[](uint32_t index);
Context * getSingleContext();
void purge(void);
};
} // namespace DFHack
#endif // CONTEXTMANAGER_H_INCLUDED

@ -25,7 +25,7 @@ distribution.
#ifndef ERROR_H_INCLUDED #ifndef ERROR_H_INCLUDED
#define ERROR_H_INCLUDED #define ERROR_H_INCLUDED
#include "Export.h" #include "DFExport.h"
#include <string> #include <string>
#include <sstream> #include <sstream>
#include <exception> #include <exception>

@ -1,6 +1,6 @@
#ifndef DFHACK_GLOBAL #ifndef DFHACK_GLOBAL
#define DFHACK_GLOBAL #define DFHACK_GLOBAL
#include "Export.h" #include "DFExport.h"
// globals, if any, should be placed here. // globals, if any, should be placed here.

@ -11,6 +11,6 @@ You can turn off the include by defining SKIP_DFHACK_STDINT
#ifndef _MSC_VER #ifndef _MSC_VER
#include <stdint.h> #include <stdint.h>
#else #else
#include "stdint_win.h" #include "DFstdint_win.h"
#endif #endif
#endif #endif

@ -25,9 +25,8 @@ distribution.
#ifndef MEMINFO_H_INCLUDED #ifndef MEMINFO_H_INCLUDED
#define MEMINFO_H_INCLUDED #define MEMINFO_H_INCLUDED
#include "Tranquility.h" #include "DFPragma.h"
#include "DFExport.h"
#include "Export.h"
#include <map> #include <map>
#include <vector> #include <vector>
#include <string> #include <string>
@ -45,9 +44,9 @@ namespace DFHack
*/ */
struct t_type struct t_type
{ {
t_type(uint32_t assign, uint32_t type, string classname) t_type(uint32_t assign, uint32_t type, std::string classname)
:classname(classname),assign(assign),type(type){}; :classname(classname),assign(assign),type(type){};
string classname; std::string classname;
uint32_t assign; uint32_t assign;
uint32_t type; uint32_t type;
}; };
@ -80,7 +79,7 @@ namespace DFHack
} }
subs.clear(); subs.clear();
} }
string classname; std::string classname;
uint32_t vtable; uint32_t vtable;
uint32_t assign;// index to typeclass array if multiclass. return value if not. uint32_t assign;// index to typeclass array if multiclass. return value if not.
uint32_t type_offset; // offset of type data for multiclass uint32_t type_offset; // offset of type data for multiclass
@ -106,52 +105,52 @@ namespace DFHack
void RebaseAddresses(const int32_t new_base); void RebaseAddresses(const int32_t new_base);
void RebaseAll(const int32_t new_base); void RebaseAll(const int32_t new_base);
uint32_t getBase () const; uint32_t getBase () const;
void setBase (const string&); void setBase (const std::string&);
void setBase (const uint32_t); void setBase (const uint32_t);
int32_t getOffset (const string&); int32_t getOffset (const std::string&);
uint32_t getAddress (const string&); uint32_t getAddress (const std::string&);
uint32_t getHexValue (const string&); uint32_t getHexValue (const std::string&);
int32_t getOffset (const char *); int32_t getOffset (const char *);
uint32_t getAddress (const char *); uint32_t getAddress (const char *);
uint32_t getHexValue (const char *); uint32_t getHexValue (const char *);
string getString (const string&); std::string getString (const std::string&);
string getProfession(const uint32_t) const; std::string getProfession(const uint32_t) const;
string getJob(const uint32_t) const; std::string getJob(const uint32_t) const;
string getSkill (const uint32_t) const; std::string getSkill (const uint32_t) const;
string getTrait (const uint32_t, const uint32_t) const; std::string getTrait (const uint32_t, const uint32_t) const;
string getTraitName(const uint32_t) const; std::string getTraitName(const uint32_t) const;
string getLabor (const uint32_t); std::string getLabor (const uint32_t);
void setVersion(const char *); void setVersion(const char *);
void setVersion(const string&); void setVersion(const std::string&);
string getVersion(); std::string getVersion();
void setOS(const char *); void setOS(const char *);
void setOS(const string&); void setOS(const std::string&);
void setOS(const OSType); void setOS(const OSType);
OSType getOS() const; OSType getOS() const;
void setOffset (const string &, const int32_t); void setOffset (const std::string &, const int32_t);
void setAddress (const string &, const uint32_t); void setAddress (const std::string &, const uint32_t);
void setHexValue (const string &, const uint32_t); void setHexValue (const std::string &, const uint32_t);
void setOffset (const string &, const char *); void setOffset (const std::string &, const char *);
void setAddress (const string &, const char *); void setAddress (const std::string &, const char *);
void setHexValue (const string &, const char *); void setHexValue (const std::string &, const char *);
void setString (const string &, const char *); void setString (const std::string &, const char *);
void setOffset (const string &, const string &); void setOffset (const std::string &, const std::string &);
void setAddress (const string &, const string &); void setAddress (const std::string &, const std::string &);
void setHexValue (const string &, const string &); void setHexValue (const std::string &, const std::string &);
void setString (const string &, const string &); void setString (const std::string &, const std::string &);
void setProfession(const string &, const string &); void setProfession(const std::string &, const std::string &);
void setJob(const string &, const string &); void setJob(const std::string &, const std::string &);
void setSkill(const string &, const string &); void setSkill(const std::string &, const std::string &);
void setTrait(const string &,const string &,const string &,const string &,const string &,const string &,const string &,const string &); void setTrait(const std::string &,const std::string &,const std::string &,const std::string &,const std::string &,const std::string &,const std::string &,const std::string &);
void setLabor(const string &, const string &); void setLabor(const std::string &, const std::string &);
void RebaseVTable(const int32_t offset); void RebaseVTable(const int32_t offset);
void setParentProcess(Process * _p); void setParentProcess(Process * _p);
@ -169,23 +168,23 @@ namespace DFHack
/* /*
* Get a ClassID when you know the classname. can fail if the class is not in the cache * Get a ClassID when you know the classname. can fail if the class is not in the cache
*/ */
bool resolveClassnameToClassID (const string classname, int32_t & classID); bool resolveClassnameToClassID (const std::string classname, int32_t & classID);
/* /*
* Get a vptr from a classname. Can fail if the type is not in the cache * Get a vptr from a classname. Can fail if the type is not in the cache
* limited to normal classes, variable-dependent types will resolve to the base class * limited to normal classes, variable-dependent types will resolve to the base class
*/ */
bool resolveClassnameToVPtr ( const string classname, uint32_t & vptr ); bool resolveClassnameToVPtr ( const std::string classname, uint32_t & vptr );
/* /*
* Get a classname from a previous classID. Can fail if the type is not in the cache (you use bogus classID) * Get a classname from a previous classID. Can fail if the type is not in the cache (you use bogus classID)
*/ */
bool resolveClassIDToClassname (const int32_t classID, string & classname); bool resolveClassIDToClassname (const int32_t classID, std::string & classname);
/* /*
* Get the internal classID->classname mapping (for speed). DO NOT MANIPULATE THE VECTOR! * Get the internal classID->classname mapping (for speed). DO NOT MANIPULATE THE VECTOR!
*/ */
const vector<string> * getClassIDMapping(); const vector<std::string> * getClassIDMapping();
}; };
} }
#endif // MEMINFO_H_INCLUDED #endif // MEMINFO_H_INCLUDED

@ -25,7 +25,7 @@ distribution.
#ifndef MEMINFO_MANAGER_H_INCLUDED #ifndef MEMINFO_MANAGER_H_INCLUDED
#define MEMINFO_MANAGER_H_INCLUDED #define MEMINFO_MANAGER_H_INCLUDED
#include "Tranquility.h" #include "DFPragma.h"
namespace DFHack namespace DFHack
{ {

@ -3,16 +3,16 @@
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include <climits> #include <climits>
#include <integers.h> #include <dfhack/DFIntegers.h>
#include <vector> #include <vector>
#include <sstream> #include <sstream>
#include <ctime> #include <ctime>
#include <cstdio> #include <cstdio>
using namespace std; using namespace std;
#include <DFProcess.h> #include <dfhack/DFProcess.h>
#include <DFMemInfo.h> #include <dfhack/DFMemInfo.h>
#include <DFVector.h> #include <dfhack/DFVector.h>
/* /*
* This is a header full of ugly, volatile things. * This is a header full of ugly, volatile things.
@ -58,11 +58,10 @@ void DumpDWordVector (const char * name, DFHack::Process *p, uint32_t addr)
address = absolute address of dump start address = absolute address of dump start
length = length in lines. 1 line = 16 bytes length = length in lines. 1 line = 16 bytes
*/ */
void hexdump (DFHack::API& DF, uint32_t address, uint32_t length) void hexdump (DFHack::Context *DF, uint32_t address, uint32_t length)
{ {
char *buf = new char[length * 16]; char *buf = new char[length * 16];
DF->ReadRaw(address, length * 16, (uint8_t *) buf);
DF.ReadRaw(address, length * 16, (uint8_t *) buf);
for (uint32_t i = 0; i < length; i++) for (uint32_t i = 0; i < length; i++)
{ {
// leading offset // leading offset
@ -74,7 +73,6 @@ void hexdump (DFHack::API& DF, uint32_t address, uint32_t length)
for(int k = 0; k < 4; k++) for(int k = 0; k < 4; k++)
{ {
int idx = i * 16 + j * 4 + k; int idx = i * 16 + j * 4 + k;
cout << hex << setw(2) << int(static_cast<unsigned char>(buf[idx])) << " "; cout << hex << setw(2) << int(static_cast<unsigned char>(buf[idx])) << " ";
} }
cout << " "; cout << " ";
@ -84,14 +82,14 @@ void hexdump (DFHack::API& DF, uint32_t address, uint32_t length)
delete buf; delete buf;
} }
void interleave_hex (DFHack::API& DF, vector < uint32_t > & addresses, uint32_t length) void interleave_hex (DFHack::Context* DF, vector < uint32_t > & addresses, uint32_t length)
{ {
vector <char * > bufs; vector <char * > bufs;
for(uint32_t counter = 0; counter < addresses.size(); counter ++) for(uint32_t counter = 0; counter < addresses.size(); counter ++)
{ {
char * buf = new char[length * 16]; char * buf = new char[length * 16];
DF.ReadRaw(addresses[counter], length * 16, (uint8_t *) buf); DF->ReadRaw(addresses[counter], length * 16, (uint8_t *) buf);
bufs.push_back(buf); bufs.push_back(buf);
} }
cout << setfill('0'); cout << setfill('0');

@ -25,15 +25,15 @@ distribution.
#ifndef PROCESS_H_INCLUDED #ifndef PROCESS_H_INCLUDED
#define PROCESS_H_INCLUDED #define PROCESS_H_INCLUDED
#include "Tranquility.h" #include "DFPragma.h"
#include "Export.h" #include "DFExport.h"
#include <iostream> #include <iostream>
namespace DFHack namespace DFHack
{ {
class memory_info; class memory_info;
class Process; class Process;
class DFWindow; class Window;
// structure describing a memory range // structure describing a memory range
struct DFHACK_EXPORT t_memrange struct DFHACK_EXPORT t_memrange
@ -122,8 +122,6 @@ namespace DFHack
// get the flattened Memory.xml entry of this process // get the flattened Memory.xml entry of this process
virtual memory_info *getDescriptor() = 0; virtual memory_info *getDescriptor() = 0;
// get the DF's window (first that can be found ~_~)
virtual DFWindow * getWindow() = 0;
// get the DF Process ID // get the DF Process ID
virtual int getPID() = 0; virtual int getPID() = 0;
// get module index by name and version. bool 1 = error // get module index by name and version. bool 1 = error
@ -195,7 +193,6 @@ namespace DFHack
bool getThreadIDs(vector<uint32_t> & threads ); bool getThreadIDs(vector<uint32_t> & threads );
void getMemRanges( vector<t_memrange> & ranges ); void getMemRanges( vector<t_memrange> & ranges );
memory_info *getDescriptor(); memory_info *getDescriptor();
DFWindow * getWindow();
int getPID(); int getPID();
// get module index by name and version. bool 1 = error // get module index by name and version. bool 1 = error
bool getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT) { OUTPUT=0; return false;}; bool getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT) { OUTPUT=0; return false;};
@ -267,7 +264,6 @@ namespace DFHack
bool getThreadIDs(vector<uint32_t> & threads ); bool getThreadIDs(vector<uint32_t> & threads );
void getMemRanges( vector<t_memrange> & ranges ); void getMemRanges( vector<t_memrange> & ranges );
memory_info *getDescriptor(); memory_info *getDescriptor();
DFWindow * getWindow();
int getPID(); int getPID();
// get module index by name and version. bool 1 = error // get module index by name and version. bool 1 = error
bool getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT); bool getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT);
@ -338,7 +334,6 @@ namespace DFHack
bool getThreadIDs(vector<uint32_t> & threads ); bool getThreadIDs(vector<uint32_t> & threads );
void getMemRanges( vector<t_memrange> & ranges ); void getMemRanges( vector<t_memrange> & ranges );
memory_info *getDescriptor(); memory_info *getDescriptor();
DFWindow * getWindow();
int getPID(); int getPID();
// get module index by name and version. bool 1 = error // get module index by name and version. bool 1 = error
bool getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT) {OUTPUT=0; return false;}; bool getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT) {OUTPUT=0; return false;};

@ -25,8 +25,8 @@ distribution.
#ifndef PROCESSMANAGER_H_INCLUDED #ifndef PROCESSMANAGER_H_INCLUDED
#define PROCESSMANAGER_H_INCLUDED #define PROCESSMANAGER_H_INCLUDED
#include "Tranquility.h" #include "DFPragma.h"
#include "Export.h" #include "DFExport.h"
class TiXmlElement; class TiXmlElement;

@ -25,7 +25,7 @@ distribution.
#ifndef TILETYPES_H_INCLUDED #ifndef TILETYPES_H_INCLUDED
#define TILETYPES_H_INCLUDED #define TILETYPES_H_INCLUDED
#include "Tranquility.h" #include "DFPragma.h"
namespace DFHack namespace DFHack
{ {

@ -25,8 +25,8 @@ distribution.
#ifndef TYPES_H_INCLUDED #ifndef TYPES_H_INCLUDED
#define TYPES_H_INCLUDED #define TYPES_H_INCLUDED
#include "Tranquility.h" #include "DFPragma.h"
#include "Export.h" #include "DFExport.h"
namespace DFHack namespace DFHack
{ {

@ -25,8 +25,8 @@ distribution.
#ifndef DFVECTOR_H_INCLUDED #ifndef DFVECTOR_H_INCLUDED
#define DFVECTOR_H_INCLUDED #define DFVECTOR_H_INCLUDED
#include "Tranquility.h" #include "DFPragma.h"
#include "Export.h" #include "DFExport.h"
namespace DFHack namespace DFHack
{ {
class Process; class Process;

@ -3,7 +3,7 @@
/* /*
* Buildings - also includes zones and stockpiles * Buildings - also includes zones and stockpiles
*/ */
#include "Export.h" #include "dfhack/DFExport.h"
namespace DFHack namespace DFHack
{ {
struct t_building struct t_building
@ -25,11 +25,11 @@ namespace DFHack
// FIXME: not complete, we need building presence bitmaps for stuff like farm plots and stockpiles, orientation (N,E,S,W) and state (open/closed) // FIXME: not complete, we need building presence bitmaps for stuff like farm plots and stockpiles, orientation (N,E,S,W) and state (open/closed)
}; };
class APIPrivate; class DFContextShared;
class DFHACK_EXPORT Buildings class DFHACK_EXPORT Buildings
{ {
public: public:
Buildings(APIPrivate * d); Buildings(DFContextShared * d);
~Buildings(); ~Buildings();
bool Start(uint32_t & numBuildings); bool Start(uint32_t & numBuildings);
// read one building at offset // read one building at offset

@ -3,7 +3,7 @@
/* /*
* DF constructions * DF constructions
*/ */
#include "Export.h" #include "dfhack/DFExport.h"
namespace DFHack namespace DFHack
{ {
// type of item the construction is made of // type of item the construction is made of
@ -39,11 +39,11 @@ namespace DFHack
uint32_t origin; uint32_t origin;
}; };
#pragma pack (pop) #pragma pack (pop)
class APIPrivate; class DFContextShared;
class DFHACK_EXPORT Constructions class DFHACK_EXPORT Constructions
{ {
public: public:
Constructions(APIPrivate * d); Constructions(DFContextShared * d);
~Constructions(); ~Constructions();
bool Start(uint32_t & numConstructions); bool Start(uint32_t & numConstructions);
bool Read (const uint32_t index, t_construction & constr); bool Read (const uint32_t index, t_construction & constr);

@ -3,7 +3,7 @@
/* /*
* Creatures * Creatures
*/ */
#include "Export.h" #include "dfhack/DFExport.h"
namespace DFHack namespace DFHack
{ {
/* /*
@ -353,12 +353,12 @@ namespace DFHack
uint32_t birth_time; uint32_t birth_time;
}; };
class APIPrivate; class DFContextShared;
struct t_creature; struct t_creature;
class DFHACK_EXPORT Creatures class DFHACK_EXPORT Creatures
{ {
public: public:
Creatures(DFHack::APIPrivate * d); Creatures(DFHack::DFContextShared * d);
~Creatures(); ~Creatures();
bool Start( uint32_t & numCreatures); bool Start( uint32_t & numCreatures);
bool Finish(); bool Finish();

@ -4,17 +4,17 @@
/* /*
* Gui: Query the DF's GUI state * Gui: Query the DF's GUI state
*/ */
#include "Export.h" #include "dfhack/DFExport.h"
namespace DFHack namespace DFHack
{ {
class APIPrivate; class DFContextShared;
struct t_viewscreen; struct t_viewscreen;
class DFHACK_EXPORT Gui class DFHACK_EXPORT Gui
{ {
public: public:
Gui(DFHack::APIPrivate * d); Gui(DFHack::DFContextShared * d);
~Gui(); ~Gui();
bool Start(); bool Start();
bool Finish(); bool Finish();

@ -3,10 +3,14 @@
/* /*
* Creatures * Creatures
*/ */
#include "Export.h" #include "dfhack/DFExport.h"
namespace DFHack namespace DFHack
{ {
class Context;
class DFContextShared;
enum accessor_type {ACCESSOR_CONSTANT, ACCESSOR_INDIRECT, ACCESSOR_DOUBLE_INDIRECT}; enum accessor_type {ACCESSOR_CONSTANT, ACCESSOR_INDIRECT, ACCESSOR_DOUBLE_INDIRECT};
/* this is used to store data about the way accessors work */ /* this is used to store data about the way accessors work */
@ -73,7 +77,7 @@ public:
class DFHACK_EXPORT Items class DFHACK_EXPORT Items
{ {
public: public:
Items(DFHack::APIPrivate * _d); Items(DFContextShared * _d);
~Items(); ~Items();
std::string getItemDescription(uint32_t itemptr, Materials * Materials); std::string getItemDescription(uint32_t itemptr, Materials * Materials);
std::string getItemClass(int32_t index); std::string getItemClass(int32_t index);

@ -5,7 +5,7 @@
#ifndef CL_MOD_MAPS #ifndef CL_MOD_MAPS
#define CL_MOD_MAPS #define CL_MOD_MAPS
#include "Export.h" #include "dfhack/DFExport.h"
namespace DFHack namespace DFHack
{ {
/*************************************************************************** /***************************************************************************
@ -255,13 +255,13 @@ namespace DFHack
C L I E N T M O D U L E C L I E N T M O D U L E
***************************************************************************/ ***************************************************************************/
class APIPrivate; class DFContextShared;
struct t_viewscreen; struct t_viewscreen;
class DFHACK_EXPORT Maps class DFHACK_EXPORT Maps
{ {
public: public:
Maps(DFHack::APIPrivate * d); Maps(DFHack::DFContextShared * d);
~Maps(); ~Maps();
bool Start(); bool Start();
bool Finish(); bool Finish();
@ -300,9 +300,8 @@ namespace DFHack
bool ReadGeology( std::vector < std::vector <uint16_t> >& assign ); bool ReadGeology( std::vector < std::vector <uint16_t> >& assign );
std::vector <t_feature> global_features; std::vector <t_feature> global_features;
// map between feature address and the read object // map between feature address and the read object
std::map <uint32_t, t_feature> local_feature_store; std::map <uint32_t, t_feature> local_feature_store;
// map between mangled coords and pointer to feature // map between mangled coords and pointer to feature
bool ReadGlobalFeatures( std::vector <t_feature> & features); bool ReadGlobalFeatures( std::vector <t_feature> & features);
bool ReadLocalFeatures( std::map <planecoord, std::vector<t_feature *> > & local_features ); bool ReadLocalFeatures( std::map <planecoord, std::vector<t_feature *> > & local_features );

@ -3,10 +3,10 @@
/* /*
* Creatures * Creatures
*/ */
#include "Export.h" #include "dfhack/DFExport.h"
namespace DFHack namespace DFHack
{ {
class APIPrivate; class DFContextShared;
struct t_matgloss struct t_matgloss
{ {
@ -119,7 +119,7 @@ namespace DFHack
class DFHACK_EXPORT Materials class DFHACK_EXPORT Materials
{ {
public: public:
Materials(DFHack::APIPrivate * _d); Materials(DFHack::DFContextShared * _d);
~Materials(); ~Materials();
std::vector<t_matgloss> inorganic; std::vector<t_matgloss> inorganic;

@ -3,7 +3,7 @@
/* /*
* View position and size and cursor position * View position and size and cursor position
*/ */
#include "Export.h" #include "dfhack/DFExport.h"
namespace DFHack namespace DFHack
{ {
#define NUM_HOTKEYS 16 #define NUM_HOTKEYS 16
@ -16,12 +16,12 @@ namespace DFHack
int32_t z; int32_t z;
}; };
class APIPrivate; class DFContextShared;
class DFHACK_EXPORT Position class DFHACK_EXPORT Position
{ {
public: public:
Position(APIPrivate * d); Position(DFContextShared * d);
~Position(); ~Position();
/* /*
* Cursor and window coords * Cursor and window coords

@ -3,10 +3,10 @@
/* /*
* DF translation tables and name translation * DF translation tables and name translation
*/ */
#include "Export.h" #include "dfhack/DFExport.h"
namespace DFHack namespace DFHack
{ {
class APIPrivate; class DFContextShared;
typedef std::vector< std::vector<std::string> > DFDict; typedef std::vector< std::vector<std::string> > DFDict;
typedef struct typedef struct
{ {
@ -17,7 +17,7 @@ namespace DFHack
class DFHACK_EXPORT Translation class DFHACK_EXPORT Translation
{ {
public: public:
Translation(APIPrivate * d); Translation(DFContextShared * d);
~Translation(); ~Translation();
bool Start(); bool Start();
bool Finish(); bool Finish();

@ -3,7 +3,7 @@
/* /*
* DF vegetation - stuff that grows and gets cut down or trampled by dwarves * DF vegetation - stuff that grows and gets cut down or trampled by dwarves
*/ */
#include "Export.h" #include "dfhack/DFExport.h"
namespace DFHack namespace DFHack
{ {
/* /*
@ -27,11 +27,11 @@ namespace DFHack
uint32_t address; uint32_t address;
}; };
class APIPrivate; class DFContextShared;
class DFHACK_EXPORT Vegetation class DFHACK_EXPORT Vegetation
{ {
public: public:
Vegetation(APIPrivate * d); Vegetation(DFContextShared * d);
~Vegetation(); ~Vegetation();
bool Start(uint32_t & numTrees); bool Start(uint32_t & numTrees);
bool Read (const uint32_t index, t_tree & shrubbery); bool Read (const uint32_t index, t_tree & shrubbery);

@ -25,8 +25,8 @@ distribution.
#ifndef KEYS_H_INCLUDED #ifndef KEYS_H_INCLUDED
#define KEYS_H_INCLUDED #define KEYS_H_INCLUDED
#include "Tranquility.h" #include "dfhack/DFPragma.h"
#include "Export.h" #include "dfhack/DFExport.h"
namespace DFHack namespace DFHack
{ {
@ -87,15 +87,15 @@ enum t_special
KEYPAD_DECIMAL_POINT, KEYPAD_DECIMAL_POINT,
NUM_SPECIALS NUM_SPECIALS
}; };
class DFContextShared;
class DFHACK_EXPORT DFWindow class DFHACK_EXPORT WindowIO
{ {
class Private; class Private;
private: private:
Private * d; Private * d;
public: public:
DFWindow(Process * p); WindowIO(DFHack::DFContextShared * d);
~DFWindow(); ~WindowIO();
void TypeStr (const char *input, int delay = 0, bool useShift = false); void TypeStr (const char *input, int delay = 0, bool useShift = false);
void TypeSpecial (t_special command, int count = 1, int delay = 0); void TypeSpecial (t_special command, int count = 1, int delay = 0);
}; };

@ -4,16 +4,16 @@
/* /*
* World: all kind of stuff related to the current world state * World: all kind of stuff related to the current world state
*/ */
#include "Export.h" #include "dfhack/DFExport.h"
namespace DFHack namespace DFHack
{ {
class APIPrivate; class DFContextShared;
class DFHACK_EXPORT World class DFHACK_EXPORT World
{ {
public: public:
World(DFHack::APIPrivate * d); World(DFHack::DFContextShared * d);
~World(); ~World();
bool Start(); bool Start();
bool Finish(); bool Finish();

@ -22,14 +22,15 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "DFCommonInternal.h" #include "Internal.h"
#include "../private/APIPrivate.h" #include "ContextShared.h"
#include "modules/Translation.h"
#include "DFMemInfo.h" #include "dfhack/DFMemInfo.h"
#include "DFProcess.h" #include "dfhack/DFProcess.h"
#include "DFVector.h" #include "dfhack/DFVector.h"
#include "DFTypes.h" #include "dfhack/DFTypes.h"
#include "modules/Buildings.h" //#include "dfhack/modules/Translation.h"
#include "dfhack/modules/Buildings.h"
using namespace DFHack; using namespace DFHack;
@ -58,13 +59,13 @@ struct Buildings::Private
uint32_t custom_workshop_name; uint32_t custom_workshop_name;
int32_t custom_workshop_id; int32_t custom_workshop_id;
DfVector <uint32_t> * p_bld; DfVector <uint32_t> * p_bld;
APIPrivate *d; DFContextShared *d;
Process * owner; Process * owner;
bool Inited; bool Inited;
bool Started; bool Started;
}; };
Buildings::Buildings(APIPrivate * d_) Buildings::Buildings(DFContextShared * d_)
{ {
d = new Private; d = new Private;
d->d = d_; d->d = d_;

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -22,17 +22,17 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "integers.h" #include "dfhack/DFIntegers.h"
#include <string> #include <string>
#include <map> #include <map>
#include "stdio.h" #include "stdio.h"
using namespace std; using namespace std;
#include "DFCommonInternal.h" #include "Internal.h"
#include "DFTypes.h" #include "dfhack/DFTypes.h"
#include "modules/Buildings.h" #include "dfhack/modules/Buildings.h"
#include "modules/Buildings_C.h" #include "dfhack-c/modules/Buildings_C.h"
using namespace DFHack; using namespace DFHack;

@ -22,14 +22,14 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "DFCommonInternal.h" #include "Internal.h"
#include "../private/APIPrivate.h" #include "ContextShared.h"
#include "modules/Translation.h"
#include "DFMemInfo.h" #include "dfhack/DFMemInfo.h"
#include "DFProcess.h" #include "dfhack/DFProcess.h"
#include "DFVector.h" #include "dfhack/DFVector.h"
#include "DFTypes.h" #include "dfhack/DFTypes.h"
#include "modules/Constructions.h" #include "dfhack/modules/Constructions.h"
using namespace DFHack; using namespace DFHack;
@ -39,13 +39,13 @@ struct Constructions::Private
// translation // translation
DfVector <uint32_t> * p_cons; DfVector <uint32_t> * p_cons;
APIPrivate *d; DFContextShared *d;
Process * owner; Process * owner;
bool Inited; bool Inited;
bool Started; bool Started;
}; };
Constructions::Constructions(APIPrivate * d_) Constructions::Constructions(DFContextShared * d_)
{ {
d = new Private; d = new Private;
d->d = d_; d->d = d_;

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -22,12 +22,12 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "integers.h" #include "dfhack/DFIntegers.h"
#include "DFCommonInternal.h" #include "Internal.h"
#include "DFTypes.h" #include "dfhack/DFTypes.h"
#include "modules/Constructions.h" #include "dfhack/modules/Constructions.h"
#include "modules/Constructions_C.h" #include "dfhack-c/modules/Constructions_C.h"
using namespace DFHack; using namespace DFHack;

@ -22,21 +22,21 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "DFCommonInternal.h" #include "Internal.h"
#include "../private/APIPrivate.h" #include "ContextShared.h"
#include "DFMemInfo.h" #include "dfhack/DFMemInfo.h"
#include "DFProcess.h" #include "dfhack/DFProcess.h"
#include "DFVector.h" #include "dfhack/DFVector.h"
#include "DFError.h" #include "dfhack/DFError.h"
#include "DFTypes.h" #include "dfhack/DFTypes.h"
// we connect to those // we connect to those
#include <shms.h> #include <shms.h>
#include <mod-core.h> #include <mod-core.h>
#include <mod-creature2010.h> #include <mod-creature2010.h>
#include "modules/Materials.h" #include "dfhack/modules/Materials.h"
#include "modules/Creatures.h" #include "dfhack/modules/Creatures.h"
#define SHMCREATURESHDR ((Creatures2010::shm_creature_hdr *)d->d->shm_start) #define SHMCREATURESHDR ((Creatures2010::shm_creature_hdr *)d->d->shm_start)
@ -55,11 +55,11 @@ struct Creatures::Private
uint32_t dwarf_race_index_addr; uint32_t dwarf_race_index_addr;
uint32_t dwarf_civ_id_addr; uint32_t dwarf_civ_id_addr;
DfVector <uint32_t> *p_cre; DfVector <uint32_t> *p_cre;
APIPrivate *d; DFContextShared *d;
Process *owner; Process *owner;
}; };
Creatures::Creatures(APIPrivate* _d) Creatures::Creatures(DFContextShared* _d)
{ {
d = new Private; d = new Private;
d->d = _d; d->d = _d;
@ -111,6 +111,7 @@ Creatures::Creatures(APIPrivate* _d)
creatures.name_words_offset = minfo->getOffset("name_words"); creatures.name_words_offset = minfo->getOffset("name_words");
d->dwarf_race_index_addr = minfo->getAddress("dwarf_race_index"); d->dwarf_race_index_addr = minfo->getAddress("dwarf_race_index");
d->dwarf_civ_id_addr = minfo->getAddress("dwarf_civ_id"); d->dwarf_civ_id_addr = minfo->getAddress("dwarf_civ_id");
/*
// upload offsets to the SHM // upload offsets to the SHM
if(p->getModuleIndex("Creatures2010",1,d->creature_module)) if(p->getModuleIndex("Creatures2010",1,d->creature_module))
{ {
@ -119,6 +120,7 @@ Creatures::Creatures(APIPrivate* _d)
const uint32_t cmd = Creatures2010::CREATURE_INIT + (d->creature_module << 16); const uint32_t cmd = Creatures2010::CREATURE_INIT + (d->creature_module << 16);
p->SetAndWait(cmd); p->SetAndWait(cmd);
} }
*/
d->Inited = true; d->Inited = true;
} }
catch (Error::MissingMemoryDefinition&) catch (Error::MissingMemoryDefinition&)
@ -158,6 +160,7 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
if(!d->Started) return false; if(!d->Started) return false;
// SHM fast path // SHM fast path
Process * p = d->owner; Process * p = d->owner;
/*
if(d->creature_module) if(d->creature_module)
{ {
SHMCREATURESHDR->index = index; SHMCREATURESHDR->index = index;
@ -166,7 +169,7 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
memcpy(&furball,SHMDATA(t_creature),sizeof(t_creature)); memcpy(&furball,SHMDATA(t_creature),sizeof(t_creature));
return true; return true;
} }
*/
// non-SHM slow path // non-SHM slow path
memory_info * minfo = d->d->offset_descriptor; memory_info * minfo = d->d->offset_descriptor;
@ -300,7 +303,7 @@ int32_t Creatures::ReadCreatureInBox (int32_t index, t_creature & furball,
return -1; return -1;
Process *p = d->owner; Process *p = d->owner;
/*
if(d->creature_module) if(d->creature_module)
{ {
// supply the module with offsets so it can work with them // supply the module with offsets so it can work with them
@ -317,7 +320,7 @@ int32_t Creatures::ReadCreatureInBox (int32_t index, t_creature & furball,
memcpy(&furball,SHMDATA(void),sizeof(t_creature)); memcpy(&furball,SHMDATA(void),sizeof(t_creature));
return SHMCREATURESHDR->index; return SHMCREATURESHDR->index;
} }
else else*/
{ {
uint16_t coords[3]; uint16_t coords[3];
uint32_t size = d->p_cre->size(); uint32_t size = d->p_cre->size();

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -22,19 +22,19 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "Export.h" #include "dfhack/DFExport.h"
#include "integers.h" #include "dfhack/DFIntegers.h"
#include <string> #include <string>
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
using namespace std; using namespace std;
#include "DFTypes.h" #include "dfhack/DFTypes.h"
#include "modules/Materials.h" #include "dfhack/modules/Materials.h"
#include "modules/Creatures.h" #include "dfhack/modules/Creatures.h"
#include "modules/Creatures_C.h" #include "dfhack-c/modules/Creatures_C.h"
#include "DFHackAPI_C.h" #include "DFHack_C.h"
using namespace DFHack; using namespace DFHack;

@ -22,12 +22,12 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "DFCommonInternal.h" #include "Internal.h"
#include "../private/APIPrivate.h" #include "ContextShared.h"
#include "modules/Gui.h" #include "dfhack/modules/Gui.h"
#include "DFProcess.h" #include "dfhack/DFProcess.h"
#include "DFMemInfo.h" #include "dfhack/DFMemInfo.h"
#include "DFTypes.h" #include "dfhack/DFTypes.h"
using namespace DFHack; using namespace DFHack;
@ -39,11 +39,11 @@ struct Gui::Private
uint32_t view_screen_offset; uint32_t view_screen_offset;
uint32_t current_cursor_creature_offset; uint32_t current_cursor_creature_offset;
uint32_t current_menu_state_offset; uint32_t current_menu_state_offset;
APIPrivate *d; DFContextShared *d;
Process * owner; Process * owner;
}; };
Gui::Gui(APIPrivate * _d) Gui::Gui(DFContextShared * _d)
{ {
d = new Private; d = new Private;

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -21,12 +21,14 @@ must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source 3. This notice may not be removed or altered from any source
distribution. distribution.
*/ */
#include <vector>
#include <string>
#include "DFHack_C.h"
#include "dfhack-c/modules/Gui_C.h"
#include "dfhack/DFIntegers.h"
#include "modules/Gui_C.h" #include "Internal.h"
#include "integers.h" #include "dfhack/modules/Gui.h"
#include "DFCommonInternal.h"
#include "modules/Gui.h"
using namespace DFHack; using namespace DFHack;
@ -66,7 +68,7 @@ int Gui_ReadPauseState(DFHackObject* gui)
int Gui_ReadViewScreen(DFHackObject* gui, t_viewscreen* viewscreen) int Gui_ReadViewScreen(DFHackObject* gui, t_viewscreen* viewscreen)
{ {
int result; //int result;
if(gui != NULL) if(gui != NULL)
{ {

@ -22,21 +22,21 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "DFCommonInternal.h" #include "Internal.h"
#include "../private/APIPrivate.h" #include "ContextShared.h"
#include "DFTypes.h" #include "dfhack/DFTypes.h"
#include "DFMemInfo.h" #include "dfhack/DFMemInfo.h"
#include "DFProcess.h" #include "dfhack/DFProcess.h"
#include "DFVector.h" #include "dfhack/DFVector.h"
#include "modules/Materials.h" #include "dfhack/modules/Materials.h"
#include "modules/Items.h" #include "dfhack/modules/Items.h"
using namespace DFHack; using namespace DFHack;
class Items::Private class Items::Private
{ {
public: public:
APIPrivate *d; DFContextShared *d;
Process * owner; Process * owner;
/* /*
bool Inited; bool Inited;
@ -44,7 +44,7 @@ class Items::Private
*/ */
}; };
Items::Items(APIPrivate * d_) Items::Items(DFContextShared * d_)
{ {
d = new Private; d = new Private;
d->d = d_; d->d = d_;

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -22,25 +22,30 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "integers.h" #include <map>
#include <vector>
#include <string> #include <string>
#include "dfhack/DFExport.h"
#include "dfhack/DFIntegers.h"
#include "DFHack_C.h"
#include "dfhack/DFTypes.h"
using namespace std; using namespace std;
using namespace DFHack;
#include "DFCommonInternal.h" #include "dfhack/DFProcess.h"
#include "DFTypes.h" #include "dfhack/modules/Materials.h"
#include "DFHackAPI.h" #include "dfhack/modules/Items.h"
#include "modules/Materials.h" #include "dfhack-c/DFTypes_C.h"
#include "modules/Items.h" #include "dfhack-c/modules/Items_C.h"
#include "modules/Items_C.h"
using namespace DFHack;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
char* Items_getItemDescription(DFHackObject* items, uint32_t itemptr, DFHackObject* mats, char* (*char_buffer_create)(int)) char* Items_getItemDescription(DFHackObject* items, uint32_t itemptr, DFHackObject* mats)
{ {
if(items != NULL && mats != NULL) if(items != NULL && mats != NULL)
{ {
@ -48,7 +53,7 @@ char* Items_getItemDescription(DFHackObject* items, uint32_t itemptr, DFHackObje
if(desc.size() > 0) if(desc.size() > 0)
{ {
char* buf = (*char_buffer_create)(desc.size()); char* buf = (*alloc_char_buffer_callback)(desc.size());
if(buf != NULL) if(buf != NULL)
{ {
@ -67,7 +72,7 @@ char* Items_getItemDescription(DFHackObject* items, uint32_t itemptr, DFHackObje
return NULL; return NULL;
} }
char* Items_getItemClass(DFHackObject* items, int32_t index, char* (*char_buffer_create)(int)) char* Items_getItemClass(DFHackObject* items, int32_t index)
{ {
if(items != NULL) if(items != NULL)
{ {
@ -75,7 +80,7 @@ char* Items_getItemClass(DFHackObject* items, int32_t index, char* (*char_buffer
if(iclass.size() > 0) if(iclass.size() > 0)
{ {
char* buf = (*char_buffer_create)(iclass.size()); char* buf = (*alloc_char_buffer_callback)(iclass.size());
if(buf != NULL) if(buf != NULL)
{ {

@ -22,16 +22,16 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "DFCommonInternal.h" #include "Internal.h"
#include <shms.h> #include <shms.h>
#include <mod-core.h> #include <mod-core.h>
#include <mod-maps.h> #include <mod-maps.h>
#include "../private/APIPrivate.h" #include "ContextShared.h"
#include "modules/Maps.h" #include "dfhack/modules/Maps.h"
#include "DFError.h" #include "dfhack/DFError.h"
#include "DFMemInfo.h" #include "dfhack/DFMemInfo.h"
#include "DFProcess.h" #include "dfhack/DFProcess.h"
#include "DFVector.h" #include "dfhack/DFVector.h"
#define SHMMAPSHDR ((Server::Maps::shm_maps_hdr *)d->d->shm_start) #define SHMMAPSHDR ((Server::Maps::shm_maps_hdr *)d->d->shm_start)
#define SHMCMD(num) ((shm_cmd *)d->d->shm_start)[num]->pingpong #define SHMCMD(num) ((shm_cmd *)d->d->shm_start)[num]->pingpong
@ -50,7 +50,7 @@ struct Maps::Private
uint32_t maps_module; uint32_t maps_module;
Server::Maps::maps_offsets offsets; Server::Maps::maps_offsets offsets;
APIPrivate *d; DFContextShared *d;
Process * owner; Process * owner;
bool Inited; bool Inited;
bool Started; bool Started;
@ -61,7 +61,7 @@ struct Maps::Private
vector<uint16_t> v_geology[eBiomeCount]; vector<uint16_t> v_geology[eBiomeCount];
}; };
Maps::Maps(APIPrivate* _d) Maps::Maps(DFContextShared* _d)
{ {
d = new Private; d = new Private;
d->d = _d; d->d = _d;
@ -707,8 +707,8 @@ bool Maps::ReadLocalFeatures( std::map <planecoord, std::vector<t_feature *> > &
uint32_t sizeof_vec = mem->getHexValue("sizeof_vector"); uint32_t sizeof_vec = mem->getHexValue("sizeof_vector");
const uint32_t sizeof_elem = 16; const uint32_t sizeof_elem = 16;
const uint32_t offset_elem = 4; const uint32_t offset_elem = 4;
const uint32_t main_mat_offset = 0x30; const uint32_t main_mat_offset = mem->getOffset("local_feature_mat"); // 0x30
const uint32_t sub_mat_offset = 0x34; const uint32_t sub_mat_offset = mem->getOffset("local_feature_submat"); // 0x34
local_features.clear(); local_features.clear();
@ -801,8 +801,8 @@ bool Maps::ReadGlobalFeatures( std::vector <t_feature> & features)
uint32_t global_feature_vector = mem->getAddress("global_feature_vector"); uint32_t global_feature_vector = mem->getAddress("global_feature_vector");
uint32_t global_feature_funcptr = mem->getOffset("global_feature_funcptr_"); uint32_t global_feature_funcptr = mem->getOffset("global_feature_funcptr_");
const uint32_t main_mat_offset = 0x34; const uint32_t main_mat_offset = mem->getOffset("global_feature_mat"); // 0x34
const uint32_t sub_mat_offset = 0x38; const uint32_t sub_mat_offset = mem->getOffset("global_feature_submat"); // 0x38
DfVector<uint32_t> p_features (p,global_feature_vector); DfVector<uint32_t> p_features (p,global_feature_vector);
features.clear(); features.clear();

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -22,17 +22,17 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "integers.h" #include "dfhack/DFIntegers.h"
#include <vector> #include <vector>
#include <map> #include <map>
#include <string> #include <string>
using namespace std; using namespace std;
#include "DFCommonInternal.h" #include "Internal.h"
#include "DFTypes.h" #include "dfhack/DFTypes.h"
#include "modules/Maps.h" #include "dfhack/modules/Maps.h"
#include "modules/Maps_C.h" #include "dfhack-c/modules/Maps_C.h"
using namespace DFHack; using namespace DFHack;

@ -22,20 +22,20 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "DFCommonInternal.h" #include "Internal.h"
#include "../private/APIPrivate.h" #include "ContextShared.h"
#include "DFTypes.h" #include "dfhack/DFTypes.h"
#include "modules/Materials.h" #include "dfhack/modules/Materials.h"
#include "DFMemInfo.h" #include "dfhack/DFMemInfo.h"
#include "DFProcess.h" #include "dfhack/DFProcess.h"
#include "DFVector.h" #include "dfhack/DFVector.h"
using namespace DFHack; using namespace DFHack;
class Materials::Private class Materials::Private
{ {
public: public:
APIPrivate *d; DFContextShared *d;
Process * owner; Process * owner;
/* /*
bool Inited; bool Inited;
@ -43,7 +43,7 @@ class Materials::Private
*/ */
}; };
Materials::Materials(APIPrivate * d_) Materials::Materials(DFContextShared * d_)
{ {
d = new Private; d = new Private;
d->d = d_; d->d = d_;
@ -265,26 +265,26 @@ bool Materials::ReadOthers(void)
bool Materials::ReadDescriptorColors (void) bool Materials::ReadDescriptorColors (void)
{ {
Process * p = d->owner; Process * p = d->owner;
DfVector <uint32_t> p_colors (p, p->getDescriptor()->getAddress ("descriptor_colors_vector")); DfVector <uint32_t> p_colors (p, p->getDescriptor()->getAddress ("descriptor_colors_vector"));
uint32_t size = p_colors.size(); uint32_t size = p_colors.size();
color.clear(); color.clear();
if(size == 0) if(size == 0)
return false; return false;
color.reserve(size); color.reserve(size);
for (uint32_t i = 0; i < size;i++) for (uint32_t i = 0; i < size;i++)
{ {
t_descriptor_color col; t_descriptor_color col;
p->readSTLString (p_colors[i] + p->getDescriptor()->getOffset ("descriptor_rawname"), col.id, 128); p->readSTLString (p_colors[i] + p->getDescriptor()->getOffset ("descriptor_rawname"), col.id, 128);
p->readSTLString (p_colors[i] + p->getDescriptor()->getOffset ("descriptor_name"), col.name, 128); p->readSTLString (p_colors[i] + p->getDescriptor()->getOffset ("descriptor_name"), col.name, 128);
col.r = p->readFloat( p_colors[i] + p->getDescriptor()->getOffset ("descriptor_color_r") ); col.r = p->readFloat( p_colors[i] + p->getDescriptor()->getOffset ("descriptor_color_r") );
col.v = p->readFloat( p_colors[i] + p->getDescriptor()->getOffset ("descriptor_color_v") ); col.v = p->readFloat( p_colors[i] + p->getDescriptor()->getOffset ("descriptor_color_v") );
col.b = p->readFloat( p_colors[i] + p->getDescriptor()->getOffset ("descriptor_color_b") ); col.b = p->readFloat( p_colors[i] + p->getDescriptor()->getOffset ("descriptor_color_b") );
color.push_back(col); color.push_back(col);
} }
return ReadNamesOnly(d->owner, d->owner->getDescriptor()->getAddress ("descriptor_all_colors"), alldesc ); return ReadNamesOnly(d->owner, d->owner->getDescriptor()->getAddress ("descriptor_all_colors"), alldesc );
return true; return true;
} }
bool Materials::ReadCreatureTypesEx (void) bool Materials::ReadCreatureTypesEx (void)
@ -364,20 +364,18 @@ bool Materials::ReadCreatureTypesEx (void)
mat.castes.push_back(caste); mat.castes.push_back(caste);
} }
mat.tile_character = p->readByte( p_races[i] + tile_offset ); mat.tile_character = p->readByte( p_races[i] + tile_offset );
mat.tilecolor.fore = p->readWord( p_races[i] + tile_color_offset ); mat.tilecolor.fore = p->readWord( p_races[i] + tile_color_offset );
mat.tilecolor.back = p->readWord( p_races[i] + tile_color_offset + 2 ); mat.tilecolor.back = p->readWord( p_races[i] + tile_color_offset + 2 );
mat.tilecolor.bright = p->readWord( p_races[i] + tile_color_offset + 4 ); mat.tilecolor.bright = p->readWord( p_races[i] + tile_color_offset + 4 );
DfVector <uint32_t> p_extract(p, p_races[i] + extract_vector_offset); DfVector <uint32_t> p_extract(p, p_races[i] + extract_vector_offset);
for(uint32_t j = 0; j < p_extract.size(); j++) for(uint32_t j = 0; j < p_extract.size(); j++)
{ {
t_creatureextract extract; t_creatureextract extract;
p->readSTLString( p_extract[j], extract.rawname, sizeof(extract.rawname)); p->readSTLString( p_extract[j], extract.rawname, sizeof(extract.rawname));
mat.extract.push_back(extract); mat.extract.push_back(extract);
} }
raceEx.push_back(mat); raceEx.push_back(mat);
} }
return true; return true;
@ -385,14 +383,14 @@ bool Materials::ReadCreatureTypesEx (void)
void Materials::ReadAllMaterials(void) void Materials::ReadAllMaterials(void)
{ {
this->ReadInorganicMaterials(); this->ReadInorganicMaterials();
this->ReadOrganicMaterials(); this->ReadOrganicMaterials();
this->ReadWoodMaterials(); this->ReadWoodMaterials();
this->ReadPlantMaterials(); this->ReadPlantMaterials();
this->ReadCreatureTypes(); this->ReadCreatureTypes();
this->ReadCreatureTypesEx(); this->ReadCreatureTypesEx();
this->ReadDescriptorColors(); this->ReadDescriptorColors();
this->ReadOthers(); this->ReadOthers();
} }
std::string Materials::getDescription(t_material & mat) std::string Materials::getDescription(t_material & mat)

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -22,18 +22,18 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "integers.h" #include "dfhack/DFIntegers.h"
#include <string> #include <string>
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
using namespace std; using namespace std;
#include "DFCommonInternal.h" #include "Internal.h"
#include "DFTypes.h" #include "dfhack/DFTypes.h"
#include "modules/Materials.h" #include "dfhack/modules/Materials.h"
#include "DFTypes_C.h" #include "dfhack-c/DFTypes_C.h"
#include "modules/Materials_C.h" #include "dfhack-c/modules/Materials_C.h"
using namespace DFHack; using namespace DFHack;
@ -225,7 +225,7 @@ int Materials_getOtherSize(DFHackObject* mat)
//vector getters //vector getters
int Materials_getInorganic(DFHackObject* mat, MatglossBufferFunc callback) t_matgloss* Materials_getInorganic(DFHackObject* mat)
{ {
if(mat != NULL) if(mat != NULL)
{ {
@ -233,25 +233,21 @@ int Materials_getInorganic(DFHackObject* mat, MatglossBufferFunc callback)
if(materials->inorganic.size() > 0) if(materials->inorganic.size() > 0)
{ {
t_matgloss* buf = ((*callback)(materials->inorganic.size())); t_matgloss* buf = ((*alloc_matgloss_buffer_callback)(materials->inorganic.size()));
if(buf != NULL) if(buf != NULL)
{ {
copy(materials->inorganic.begin(), materials->inorganic.end(), buf); copy(materials->inorganic.begin(), materials->inorganic.end(), buf);
return 1; return buf;
} }
else
return -1;
} }
else
return 0;
} }
return -1; return NULL;
} }
int Materials_getOrganic(DFHackObject* mat, MatglossBufferFunc callback) t_matgloss* Materials_getOrganic(DFHackObject* mat)
{ {
if(mat != NULL) if(mat != NULL)
{ {
@ -259,25 +255,21 @@ int Materials_getOrganic(DFHackObject* mat, MatglossBufferFunc callback)
if(materials->organic.size() > 0) if(materials->organic.size() > 0)
{ {
t_matgloss* buf = ((*callback)(materials->organic.size())); t_matgloss* buf = ((*alloc_matgloss_buffer_callback)(materials->organic.size()));
if(buf != NULL) if(buf != NULL)
{ {
copy(materials->organic.begin(), materials->organic.end(), buf); copy(materials->organic.begin(), materials->organic.end(), buf);
return 1; return buf;
} }
else
return -1;
} }
else
return 0;
} }
return -1; return NULL;
} }
int Materials_getTree(DFHackObject* mat, MatglossBufferFunc callback) t_matgloss* Materials_getTree(DFHackObject* mat)
{ {
if(mat != NULL) if(mat != NULL)
{ {
@ -285,25 +277,21 @@ int Materials_getTree(DFHackObject* mat, MatglossBufferFunc callback)
if(materials->tree.size() > 0) if(materials->tree.size() > 0)
{ {
t_matgloss* buf = ((*callback)(materials->tree.size())); t_matgloss* buf = ((*alloc_matgloss_buffer_callback)(materials->tree.size()));
if(buf != NULL) if(buf != NULL)
{ {
copy(materials->tree.begin(), materials->tree.end(), buf); copy(materials->tree.begin(), materials->tree.end(), buf);
return 1; return buf;
} }
else
return -1;
} }
else
return 0;
} }
return -1; return NULL;
} }
int Materials_getPlant(DFHackObject* mat, MatglossBufferFunc callback) t_matgloss* Materials_getPlant(DFHackObject* mat)
{ {
if(mat != NULL) if(mat != NULL)
{ {
@ -311,25 +299,21 @@ int Materials_getPlant(DFHackObject* mat, MatglossBufferFunc callback)
if(materials->plant.size() > 0) if(materials->plant.size() > 0)
{ {
t_matgloss* buf = ((*callback)(materials->plant.size())); t_matgloss* buf = ((*alloc_matgloss_buffer_callback)(materials->plant.size()));
if(buf != NULL) if(buf != NULL)
{ {
copy(materials->plant.begin(), materials->plant.end(), buf); copy(materials->plant.begin(), materials->plant.end(), buf);
return 1; return buf;
} }
else
return -1;
} }
else
return 0;
} }
return -1; return NULL;
} }
int Materials_getRace(DFHackObject* mat, MatglossBufferFunc callback) t_matgloss* Materials_getRace(DFHackObject* mat)
{ {
if(mat != NULL) if(mat != NULL)
{ {
@ -337,67 +321,46 @@ int Materials_getRace(DFHackObject* mat, MatglossBufferFunc callback)
if(materials->race.size() > 0) if(materials->race.size() > 0)
{ {
t_matgloss* buf = ((*callback)(materials->race.size())); t_matgloss* buf = ((*alloc_matgloss_buffer_callback)(materials->race.size()));
if(buf != NULL) if(buf != NULL)
{ {
copy(materials->race.begin(), materials->race.end(), buf); copy(materials->race.begin(), materials->race.end(), buf);
return 1; return buf;
} }
else
return -1;
} }
else
return 0;
} }
return -1; return NULL;
} }
//race_ex getter goes here... //race_ex getter goes here...
// int Materials_getRaceEx(DFHackObject* mat, c_creaturetype* (*c_creaturetype_buffer_create)(c_creaturetype_descriptor*, int)) c_creaturetype* Materials_getRaceEx(DFHackObject* mat)
// { {
// if(mat != NULL) if(mat != NULL)
// { {
// DFHack::Materials* materials = (DFHack::Materials*)mat; DFHack::Materials* materials = (DFHack::Materials*)mat;
int matSize = materials->raceEx.size();
// if(materials->raceEx.size() > 0)
// {
// std::vector<t_creaturetype> types = materials->raceEx;
// int typessize = types.size();
// c_creaturetype_descriptor* descriptors = (c_creaturetype_descriptor*)malloc(sizeof(c_creaturetype_descriptor) * typessize);
// for(int i = 0; i < typessize; i++)
// {
// descriptors[i].castesCount = types[i].castes.size();
// descriptors[i].extractCount = types[i].extract.size();
// }
// c_creaturetype* buf = ((*c_creaturetype_buffer_create)(descriptors, typessize));
// for(int i = 0; i < typessize; i++)
// {
// t_creaturetype current = types[i];
// strncpy(buf[i].rawname, current.rawname, 128);
// buf[i].rawname[127] = '\0';
// buf[i].tile_character = current.tile_character; if(matSize > 0)
// buf[i].tilecolor = current.tilecolor; {
c_creaturetype* buf = ((*alloc_creaturetype_buffer_callback)(matSize));
// current.extract.copy(buf[i].extract, current.extract.size()); if(buf != NULL)
// } {
for(int i = 0; i < matSize; i++)
CreatureTypeConvert(&materials->raceEx[i], &buf[i]);
// free(descriptors); return buf;
// } }
// } }
}
// return -1; return NULL;
// } }
int Materials_getColor(DFHackObject* mat, DescriptorColorBufferFunc callback) t_descriptor_color* Materials_getColor(DFHackObject* mat)
{ {
if(mat != NULL) if(mat != NULL)
{ {
@ -405,25 +368,21 @@ int Materials_getColor(DFHackObject* mat, DescriptorColorBufferFunc callback)
if(materials->color.size() > 0) if(materials->color.size() > 0)
{ {
t_descriptor_color* buf = ((*callback)(materials->color.size())); t_descriptor_color* buf = ((*alloc_descriptor_buffer_callback)(materials->color.size()));
if(buf != NULL) if(buf != NULL)
{ {
copy(materials->color.begin(), materials->color.end(), buf); copy(materials->color.begin(), materials->color.end(), buf);
return 1; return buf;
} }
else
return -1;
} }
else
return 0;
} }
return -1; return NULL;
} }
int Materials_getOther(DFHackObject* mat, MatglossOtherBufferFunc callback) t_matglossOther* Materials_getOther(DFHackObject* mat)
{ {
if(mat != NULL) if(mat != NULL)
{ {
@ -431,22 +390,18 @@ int Materials_getOther(DFHackObject* mat, MatglossOtherBufferFunc callback)
if(materials->other.size() > 0) if(materials->other.size() > 0)
{ {
t_matglossOther* buf = ((*callback)(materials->other.size())); t_matglossOther* buf = ((*alloc_matgloss_other_buffer_callback)(materials->other.size()));
if(buf != NULL) if(buf != NULL)
{ {
copy(materials->other.begin(), materials->other.end(), buf); copy(materials->other.begin(), materials->other.end(), buf);
return 1; return buf;
} }
else
return -1;
} }
else
return 0;
} }
return -1; return NULL;
} }
#ifdef __cplusplus #ifdef __cplusplus

@ -22,16 +22,13 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "DFCommonInternal.h" #include "Internal.h"
#include "../private/APIPrivate.h" #include "ContextShared.h"
#include "modules/Position.h" #include "dfhack/modules/Position.h"
#include "DFMemInfo.h" #include "dfhack/DFMemInfo.h"
#include "DFProcess.h" #include "dfhack/DFProcess.h"
using namespace DFHack; using namespace DFHack;
struct Position::Private struct Position::Private
{ {
uint32_t window_x_offset; uint32_t window_x_offset;
@ -45,16 +42,14 @@ struct Position::Private
uint32_t hotkey_xyz_offset; uint32_t hotkey_xyz_offset;
uint32_t hotkey_size; uint32_t hotkey_size;
APIPrivate *d; DFContextShared *d;
Process * owner; Process * owner;
bool Inited; bool Inited;
bool Started; bool Started;
bool StartedHotkeys; bool StartedHotkeys;
//uint32_t biome_stuffs;
//vector<uint16_t> v_geology[eBiomeCount];
}; };
Position::Position(APIPrivate * d_) Position::Position(DFContextShared * d_)
{ {
d = new Private; d = new Private;
d->d = d_; d->d = d_;
@ -88,7 +83,10 @@ Position::~Position()
bool Position::ReadHotkeys(t_hotkey hotkeys[]) bool Position::ReadHotkeys(t_hotkey hotkeys[])
{ {
if (!d->StartedHotkeys) return false; if (!d->StartedHotkeys)
{
return false;
}
uint32_t currHotkey = d->hotkey_start; uint32_t currHotkey = d->hotkey_start;
Process * p = d->owner; Process * p = d->owner;
@ -116,7 +114,10 @@ bool Position::getViewCoords (int32_t &x, int32_t &y, int32_t &z)
//FIXME: confine writing of coords to map bounds? //FIXME: confine writing of coords to map bounds?
bool Position::setViewCoords (const int32_t x, const int32_t y, const int32_t z) bool Position::setViewCoords (const int32_t x, const int32_t y, const int32_t z)
{ {
if (!d->Inited) return false; if (!d->Inited)
{
return false;
}
Process * p = d->owner; Process * p = d->owner;
p->writeDWord (d->window_x_offset, (uint32_t) x); p->writeDWord (d->window_x_offset, (uint32_t) x);

@ -22,11 +22,13 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "modules/Position_C.h" #include <vector>
#include "integers.h" #include <string>
#include "dfhack-c/modules/Position_C.h"
#include "dfhack/DFIntegers.h"
#include "DFCommonInternal.h" #include "Internal.h"
#include "modules/Position.h" #include "dfhack/modules/Position.h"
using namespace DFHack; using namespace DFHack;

@ -22,14 +22,13 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "DFCommonInternal.h" #include "Internal.h"
#include "../private/APIPrivate.h" #include "ContextShared.h"
#include "modules/Translation.h" #include "dfhack/modules/Translation.h"
#include "DFMemInfo.h" #include "dfhack/DFMemInfo.h"
#include "DFProcess.h" #include "dfhack/DFProcess.h"
#include "DFVector.h" #include "dfhack/DFVector.h"
#include "DFTypes.h" #include "dfhack/DFTypes.h"
#include "modules/Translation.h"
using namespace DFHack; using namespace DFHack;
@ -43,12 +42,12 @@ struct Translation::Private
// translation // translation
Dicts dicts; Dicts dicts;
APIPrivate *d; DFContextShared *d;
bool Inited; bool Inited;
bool Started; bool Started;
}; };
Translation::Translation(APIPrivate * d_) Translation::Translation(DFContextShared * d_)
{ {
d = new Private; d = new Private;
d->d = d_; d->d = d_;

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -22,15 +22,15 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "integers.h" #include "dfhack/DFIntegers.h"
#include <string> #include <string>
using namespace std; using namespace std;
#include "DFCommonInternal.h" #include "Internal.h"
#include "DFTypes.h" #include "dfhack/DFTypes.h"
#include "modules/Translation.h" #include "dfhack/modules/Translation.h"
#include "modules/Translation_C.h" #include "dfhack-c/modules/Translation_C.h"
using namespace DFHack; using namespace DFHack;

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