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)
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.")
endif("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}")
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(SO_MAJOR_VERSION "0")
SET(SO_MINOR_VERSION "0")
SET(SO_BUILD_VERSION "1")
SET(SO_VERSION "${SO_MAJOR_VERSION}.${SO_MINOR_VERSION}.${SO_BUILD_VERSION}")
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/)
SET( LIBRARY_OUTPUT_PATH ${dfhack_SOURCE_DIR}/output CACHE PATH "Output directory for the dfhack library" )
SET( EXECUTABLE_OUTPUT_PATH ${dfhack_SOURCE_DIR}/output CACHE PATH "Output directory for the dfhack tools" )
SET( CMAKE_SWIG_OUTDIR ${dfhack_SOURCE_DIR}/output CACHE PATH "Global output directory for swig generated language wrappers" )
include_directories (${CMAKE_SOURCE_DIR}/dfhack/include/)
include_directories (${CMAKE_SOURCE_DIR}/dfhack/shm/)
include_directories (${CMAKE_SOURCE_DIR}/dfhack/depends/md5/)
include_directories (${CMAKE_SOURCE_DIR}/dfhack/depends/tinyxml/)
include_directories (${CMAKE_SOURCE_DIR}/dfhack/depends/argstream/)
add_subdirectory (dfhack)
add_subdirectory (dfhack/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)
add_subdirectory (library)
#add_subdirectory (dfhack/python)
add_subdirectory (tools/examples)
add_subdirectory (tools/playground)
add_subdirectory (tools/supported)

@ -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
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
-----
@ -79,6 +164,7 @@ be useful and are cross-platform just like the library itself.
- Your tool here: Write one ;)
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 <mod-core.h>
#include <mod-maps.h>
#include <mod-creature40d.h>
#include "private/APIPrivate.h"
#include "DFMemInfo.h"
#include "DFProcess.h"
#include "private/ContextShared.h"
#include "dfhack/DFMemInfo.h"
#include "dfhack/DFProcess.h"
#include "modules/Materials.h"
#include "modules/Creatures.h"
#include "modules/Maps.h"
#include "modules/Position.h"
#include "modules/Translation.h"
#include "modules/Vegetation.h"
#include "modules/Gui.h"
#include "modules/World.h"
#include "modules/Buildings.h"
#include "modules/Constructions.h"
#include "dfhack/modules/Materials.h"
#include "dfhack/modules/Creatures.h"
#include "dfhack/modules/Maps.h"
#include "dfhack/modules/Position.h"
#include "dfhack/modules/Translation.h"
#include "dfhack/modules/Vegetation.h"
#include "dfhack/modules/Gui.h"
#include "dfhack/modules/World.h"
#include "dfhack/modules/Buildings.h"
#include "dfhack/modules/Constructions.h"
#include "dfhack/modules/WindowIO.h"
using namespace DFHack;
APIPrivate::APIPrivate()
DFContextShared::DFContextShared()
{
// init modules
creatures = 0;
@ -34,9 +35,10 @@ APIPrivate::APIPrivate()
buildings = 0;
constructions = 0;
items = 0;
windowio = 0;
}
APIPrivate::~APIPrivate()
DFContextShared::~DFContextShared()
{
if(creatures) delete creatures;
if(maps) delete maps;
@ -48,9 +50,10 @@ APIPrivate::~APIPrivate()
if(buildings) delete buildings;
if(constructions) delete constructions;
if(world) delete world;
if(windowio) delete windowio;
}
bool APIPrivate::InitReadNames()
bool DFContextShared::InitReadNames()
{
name_firstname_offset = offset_descriptor->getOffset("name_firstname");
name_nickname_offset = offset_descriptor->getOffset("name_nickname");
@ -58,7 +61,7 @@ bool APIPrivate::InitReadNames()
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_nickname_offset , name.nickname, 128);

@ -22,114 +22,82 @@ must not be misrepresented as being the original software.
distribution.
*/
#include "DFCommonInternal.h"
#include "Internal.h"
#include "DFProcess.h"
#include "DFProcessEnumerator.h"
#include "DFHackAPI.h"
#include "DFError.h"
#include "dfhack/DFProcess.h"
#include "dfhack/DFProcessEnumerator.h"
#include "dfhack/DFContext.h"
#include "dfhack/DFContext.h"
#include "dfhack/DFError.h"
#include <shms.h>
#include <mod-core.h>
#include <mod-maps.h>
#include <mod-creature40d.h>
#include "private/APIPrivate.h"
#include "modules/Maps.h"
#include "modules/Materials.h"
#include "modules/Items.h"
#include "modules/Position.h"
#include "modules/Gui.h"
#include "modules/World.h"
#include "modules/Creatures.h"
#include "modules/Translation.h"
#include "modules/Vegetation.h"
#include "modules/Buildings.h"
#include "modules/Constructions.h"
#include "private/ContextShared.h"
#include "dfhack/modules/Maps.h"
#include "dfhack/modules/Materials.h"
#include "dfhack/modules/Items.h"
#include "dfhack/modules/Position.h"
#include "dfhack/modules/Gui.h"
#include "dfhack/modules/World.h"
#include "dfhack/modules/Creatures.h"
#include "dfhack/modules/Translation.h"
#include "dfhack/modules/Vegetation.h"
#include "dfhack/modules/Buildings.h"
#include "dfhack/modules/Constructions.h"
#include "dfhack/modules/WindowIO.h"
using namespace DFHack;
API::API (const string path_to_xml)
: d (new APIPrivate())
Context::Context (Process* p) : d (new DFContextShared())
{
d->xml = QUOT (MEMXML_DATA_PATH);
d->xml += "/";
d->xml += path_to_xml;
d->pm = NULL;
d->p = 0;
d->p = p;
d->offset_descriptor = p->getDescriptor();
d->shm_start = 0;
}
API::~API()
Context::~Context()
{
Detach();
delete d;
}
bool API::Attach()
bool Context::isValid()
{
if(d->p != NULL)
{
return d->p->suspend();
}
// detach all processes, destroy manager
if (d->pm == 0)
{
d->pm = new ProcessEnumerator (d->xml); // FIXME: handle bad XML better
}
else
{
d->pm->purge();
}
//FIXME: check for error states here
if(d->p->isIdentified())
return true;
return false;
}
// find a process (ProcessManager can find multiple when used properly)
if (!d->pm->findProcessess())
{
throw Error::NoProcess();
//cerr << "couldn't find a suitable process" << endl;
//return false;
}
d->p = (*d->pm) [0];
bool Context::Attach()
{
if (!d->p->attach())
{
throw Error::CantAttach();
//cerr << "couldn't attach to process" << endl;
//return false; // couldn't attach to process, no go
//throw Error::CantAttach();
return false;
}
d->shm_start = d->p->getSHMStart();
d->offset_descriptor = d->p->getDescriptor();
// process is attached, everything went just fine... hopefully
return true;
}
bool API::Detach()
bool Context::Detach()
{
if(!d->p)
return false;
if (!d->p->detach())
{
return false;
}
if (d->pm != NULL)
{
delete d->pm;
}
d->pm = NULL;
d->p = NULL;
d->shm_start = 0;
d->offset_descriptor = NULL;
// invalidate all modules
if(d->creatures)
{
delete d->creatures;
d->creatures = 0;
}
if(d->creatures)
{
delete d->creatures;
d->creatures = 0;
}
if(d->maps)
{
delete d->maps;
@ -183,131 +151,134 @@ bool API::Detach()
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();
}
bool API::AsyncSuspend()
bool Context::AsyncSuspend()
{
return d->p->asyncSuspend();
}
bool API::Resume()
bool Context::Resume()
{
return d->p->resume();
}
bool API::ForceResume()
bool Context::ForceResume()
{
return d->p->forceresume();
}
bool API::isSuspended()
bool Context::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);
}
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);
}
memory_info *API::getMemoryInfo()
memory_info *Context::getMemoryInfo()
{
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
*******************************************************************************/
Creatures * API::getCreatures()
Creatures * Context::getCreatures()
{
if(!d->creatures)
d->creatures = new Creatures(d);
return d->creatures;
}
Maps * API::getMaps()
Maps * Context::getMaps()
{
if(!d->maps)
d->maps = new Maps(d);
return d->maps;
}
Gui * API::getGui()
Gui * Context::getGui()
{
if(!d->gui)
d->gui = new Gui(d);
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)
d->world = new World(d);
return d->world;
}
Position * API::getPosition()
Position * Context::getPosition()
{
if(!d->position)
d->position = new Position(d);
return d->position;
}
Materials * API::getMaterials()
Materials * Context::getMaterials()
{
if(!d->materials)
d->materials = new Materials(d);
return d->materials;
}
Items * API::getItems()
Items * Context::getItems()
{
if(!d->items)
d->items = new Items(d);
return d->items;
}
Translation * API::getTranslation()
Translation * Context::getTranslation()
{
if(!d->translation)
d->translation = new Translation(d);
return d->translation;
}
Vegetation * API::getVegetation()
Vegetation * Context::getVegetation()
{
if(!d->vegetation)
d->vegetation = new Vegetation(d);
return d->vegetation;
}
Buildings * API::getBuildings()
Buildings * Context::getBuildings()
{
if(!d->buildings)
d->buildings = new Buildings(d);
return d->buildings;
}
Constructions * API::getConstructions()
Constructions * Context::getConstructions()
{
if(!d->constructions)
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.
*/
#include "DFCommonInternal.h"
#include "DFMemInfo.h"
#include "DFError.h"
#include "DFProcess.h"
#include "Internal.h"
#include "dfhack/DFMemInfo.h"
#include "dfhack/DFError.h"
#include "dfhack/DFProcess.h"
using namespace DFHack;

@ -22,10 +22,10 @@ must not be misrepresented as being the original software.
distribution.
*/
#include "DFCommonInternal.h"
#include "DFMemInfo.h"
#include "DFMemInfoManager.h"
#include "DFError.h"
#include "Internal.h"
#include "dfhack/DFMemInfo.h"
#include "dfhack/DFMemInfoManager.h"
#include "dfhack/DFError.h"
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
distribution.
*/
#include "DFCommonInternal.h"
#include "DFProcess.h"
#include "DFWindow.h"
#include "DFMemInfo.h"
#include "DFError.h"
#include "Internal.h"
#include "dfhack/DFProcess.h"
#include "dfhack/DFMemInfo.h"
#include "dfhack/DFError.h"
#include <errno.h>
#include <sys/shm.h>
@ -53,7 +52,6 @@ class SHMProcess::Private
shm_addr = 0;
//shm_addr_with_cl_idx = 0;
shm_ID = -1;
window = NULL;
attached = false;
identified = false;
useYield = false;
@ -66,7 +64,6 @@ class SHMProcess::Private
};
~Private(){};
memory_info * memdescriptor;
DFWindow * window;
Process * self;
pid_t process_ID;
char *shm_addr;
@ -77,8 +74,6 @@ class SHMProcess::Private
int suspend_lock;
int attachmentIdx;
bool attached;
bool locked;
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)
d->validate(known_versions);
d->window = new DFWindow(this);
// detach
detach();
}
@ -362,10 +355,6 @@ SHMProcess::~SHMProcess()
}
if(d->memdescriptor)
delete d->memdescriptor;
if(d->window)
{
delete d->window;
}
delete d;
}
@ -374,11 +363,6 @@ memory_info * SHMProcess::getDescriptor()
return d->memdescriptor;
}
DFWindow * SHMProcess::getWindow()
{
return d->window;
}
int SHMProcess::getPID()
{
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;
gcc_barrier
d->SetAndWait(CORE_READ);
memcpy (target_buffer, D_SHMDATA(void) ,size);
memcpy (target_buffer, D_SHMDATA(void) ,to_read);
// decrease size by bytes read
size -= to_read;
// 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
distribution.
*/
#include "DFCommonInternal.h"
#include "DFProcess.h"
#include "DFWindow.h"
#include "DFMemInfo.h"
#include "DFError.h"
#include "Internal.h"
#include "dfhack/DFProcess.h"
#include "dfhack/DFMemInfo.h"
#include "dfhack/DFError.h"
#include <errno.h>
#include <DFError.h>
#include <sys/ptrace.h>
#include <stdio.h>
using namespace DFHack;
@ -39,7 +37,6 @@ class WineProcess::Private
{
my_descriptor = NULL;
my_handle = NULL;
my_window = NULL;
my_pid = 0;
attached = false;
suspended = false;
@ -47,7 +44,6 @@ class WineProcess::Private
self = self_;
};
~Private(){};
DFWindow* my_window;
memory_info * my_descriptor;
Process * self;
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
d->identified = d->validate(exe_link,pid,mem_name,known_versions);
d->my_window = new DFWindow(this);
return;
}
}
@ -175,8 +170,6 @@ WineProcess::~WineProcess()
// destroy our copy of the memory descriptor
if(d->my_descriptor)
delete d->my_descriptor;
if(d->my_window)
delete d->my_window;
delete d;
}
@ -185,11 +178,6 @@ memory_info * WineProcess::getDescriptor()
return d->my_descriptor;
}
DFWindow * WineProcess::getWindow()
{
return d->my_window;
}
int WineProcess::getPID()
{
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
void WineProcess::write (uint32_t offset, uint32_t size, uint8_t *source)
{
uint32_t count = 0;
uint32_t indexptr = 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
distribution.
*/
#include "DFCommonInternal.h"
#include "DFProcess.h"
#include "DFWindow.h"
#include "DFMemInfo.h"
#include "DFError.h"
#include "Internal.h"
#include "dfhack/DFProcess.h"
#include "dfhack/DFMemInfo.h"
#include "dfhack/DFError.h"
#include <errno.h>
#include <sys/ptrace.h>
using namespace DFHack;
@ -37,7 +36,6 @@ class NormalProcess::Private
{
my_descriptor = NULL;
my_handle = NULL;
my_window = NULL;
my_pid = 0;
attached = false;
suspended = false;
@ -45,7 +43,7 @@ class NormalProcess::Private
self = self_;
};
~Private(){};
DFWindow* my_window;
Window* my_window;
memory_info * my_descriptor;
pid_t my_handle;
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
d->identified = d->validate(target_name,pid,mem_name,known_versions );
d->my_window = new DFWindow(this);
return;
}
}
@ -161,9 +158,6 @@ NormalProcess::~NormalProcess()
// destroy our copy of the memory descriptor
if(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;
}
@ -172,11 +166,6 @@ memory_info * NormalProcess::getDescriptor()
return d->my_descriptor;
}
DFWindow * NormalProcess::getWindow()
{
return d->my_window;
}
int NormalProcess::getPID()
{
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)
{
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;
errno = 0;
throw Error::MemoryAccessDenied();
}
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
void NormalProcess::write (uint32_t offset, uint32_t size, uint8_t *source)
{
uint32_t count = 0;
uint32_t indexptr = 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
distribution.
*/
#include "DFCommonInternal.h"
#include "DFProcess.h"
#include "DFWindow.h"
#include "DFMemInfo.h"
#include "DFError.h"
#include "Internal.h"
#include "dfhack/DFProcess.h"
#include "dfhack/DFMemInfo.h"
#include "dfhack/DFError.h"
#include "shms.h"
#include "mod-core.h"
using namespace DFHack;
@ -39,7 +38,6 @@ class SHMProcess::Private
memdescriptor = NULL;
process_ID = 0;
shm_addr = 0;
window = NULL;
attached = false;
locked = false;
identified = false;
@ -51,7 +49,6 @@ class SHMProcess::Private
};
~Private(){};
memory_info * memdescriptor;
DFWindow * window;
SHMProcess * self;
uint32_t process_ID;
char *shm_addr;
@ -300,7 +297,6 @@ SHMProcess::SHMProcess(uint32_t PID, vector <memory_info *> & known_versions)
throw Error::SHMVersionMismatch();
}
d->validate(known_versions);
d->window = new DFWindow(this);
// at this point, DF is attached and suspended, make it run
detach();
}
@ -386,10 +382,6 @@ SHMProcess::~SHMProcess()
{
delete d->memdescriptor;
}
if(d->window)
{
delete d->window;
}
delete d;
}
@ -398,11 +390,6 @@ memory_info * SHMProcess::getDescriptor()
return d->memdescriptor;
}
DFWindow * SHMProcess::getWindow()
{
return d->window;
}
int SHMProcess::getPID()
{
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;
full_barrier
d->SetAndWait(CORE_READ);
memcpy (target_buffer, D_SHMDATA(void) ,size);
memcpy (target_buffer, D_SHMDATA(void) ,to_read);
// decrease size by bytes read
size -= to_read;
// 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
distribution.
*/
#include "DFCommonInternal.h"
#include "DFProcess.h"
#include "DFWindow.h"
#include "DFMemInfo.h"
#include "DFError.h"
#include "Internal.h"
#include "dfhack/DFProcess.h"
#include "dfhack/DFMemInfo.h"
#include "dfhack/DFError.h"
using namespace DFHack;
class NormalProcess::Private
@ -36,14 +35,12 @@ class NormalProcess::Private
my_descriptor = NULL;
my_handle = NULL;
my_main_thread = NULL;
my_window = NULL;
my_pid = 0;
attached = false;
suspended = false;
};
~Private(){};
memory_info * my_descriptor;
DFWindow * my_window;
HANDLE my_handle;
HANDLE my_main_thread;
uint32_t my_pid;
@ -147,10 +144,6 @@ NormalProcess::NormalProcess(uint32_t pid, vector <memory_info *> & known_versio
{
CloseHandle(hProcess);
}
else
{
d->my_window = new DFWindow(this);
}
}
/*
*/
@ -171,10 +164,6 @@ NormalProcess::~NormalProcess()
{
CloseHandle(d->my_main_thread);
}
if(d->my_window)
{
delete d->my_window;
}
delete d;
}
@ -183,11 +172,6 @@ memory_info * NormalProcess::getDescriptor()
return d->my_descriptor;
}
DFWindow * NormalProcess::getWindow()
{
return d->my_window;
}
int NormalProcess::getPID()
{
return d->my_pid;
@ -438,7 +422,7 @@ const string NormalProcess::readCString (const uint32_t offset)
{
string temp;
char temp_c[256];
DWORD read;
SIZE_T read;
if(!ReadProcessMemory(d->my_handle, (int *) offset, temp_c, 254, &read))
throw Error::MemoryAccessDenied();
// needs to be 254+1 byte for the null term

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

@ -22,11 +22,11 @@ must not be misrepresented as being the original software.
distribution.
*/
#include "DFCommonInternal.h"
#include "DFProcessEnumerator.h"
#include "DFProcess.h"
#include "DFMemInfo.h"
#include "DFMemInfoManager.h"
#include "Internal.h"
#include "dfhack/DFProcessEnumerator.h"
#include "dfhack/DFProcess.h"
#include "dfhack/DFMemInfo.h"
#include "dfhack/DFMemInfoManager.h"
using namespace DFHack;
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
#include <string>
#include <integers.h>
#include <dfhack/DFIntegers.h>
//----------------------------------------------------------------------
//typedefs
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
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
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.
*/
#include "DFCommonInternal.h"
#include "DFTileTypes.h"
#ifndef DFHACK_C_API
#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
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
warranty. In no event will the authors be held liable for any
@ -25,11 +25,11 @@ distribution.
#ifndef BUILDINGS_C_API
#define BUILDINGS_C_API
#include "Export.h"
#include "integers.h"
#include "DFTypes.h"
#include "modules/Buildings.h"
#include "DFHackAPI_C.h"
#include "dfhack/DFExport.h"
#include "dfhack/DFIntegers.h"
#include "dfhack/DFTypes.h"
#include "dfhack/modules/Buildings.h"
#include "DFHack_C.h"
using namespace DFHack;

@ -1,6 +1,6 @@
/*
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
warranty. In no event will the authors be held liable for any
@ -25,11 +25,11 @@ distribution.
#ifndef CONSTRUCTIONS_C_API
#define CONSTRUCTIONS_C_API
#include "Export.h"
#include "integers.h"
#include "DFTypes.h"
#include "modules/Constructions.h"
#include "DFHackAPI_C.h"
#include "dfhack/DFExport.h"
#include "dfhack/DFIntegers.h"
#include "dfhack/DFTypes.h"
#include "dfhack/modules/Constructions.h"
#include "DFHack_C.h"
using namespace DFHack;

@ -1,6 +1,6 @@
/*
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
warranty. In no event will the authors be held liable for any
@ -25,12 +25,12 @@ distribution.
#ifndef CREATURES_C_API
#define CREATURES_C_API
#include "Export.h"
#include "integers.h"
#include "DFTypes.h"
#include "modules/Materials.h"
#include "modules/Creatures.h"
#include "DFHackAPI_C.h"
#include "dfhack/DFExport.h"
#include "dfhack/DFIntegers.h"
#include "DFHack_C.h"
#include "dfhack/DFTypes.h"
#include "dfhack/modules/Materials.h"
#include "dfhack/modules/Creatures.h"
using namespace DFHack;

@ -1,6 +1,6 @@
/*
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
warranty. In no event will the authors be held liable for any
@ -25,10 +25,9 @@ distribution.
#ifndef GUI_C_API
#define GUI_C_API
#include "Export.h"
#include "integers.h"
#include "DFTypes.h"
#include "DFHackAPI_C.h"
#include "dfhack/DFExport.h"
#include "dfhack/DFIntegers.h"
#include "dfhack/DFTypes.h"
using namespace DFHack;

@ -1,6 +1,6 @@
/*
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
warranty. In no event will the authors be held liable for any
@ -25,20 +25,22 @@ distribution.
#ifndef ITEMS_C_API
#define ITEMS_C_API
#include "Export.h"
#include "integers.h"
#include "DFTypes.h"
#include "modules/Items.h"
#include "DFHackAPI_C.h"
#include "dfhack/DFExport.h"
#include "dfhack/DFIntegers.h"
#include "Internal.h"
using namespace DFHack;
#include "dfhack/DFTypes.h"
#include "dfhack/modules/Items.h"
#include "DFHack_C.h"
#ifdef __cplusplus
extern "C" {
#endif
DFHACK_EXPORT char* Items_getItemDescription(DFHackObject* items, uint32_t itemptr, DFHackObject* mats, char* (*char_buffer_create)(int));
DFHACK_EXPORT char* Items_getItemClass(DFHackObject* items, int32_t index, 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);
DFHACK_EXPORT int Items_getItemData(DFHackObject* items, uint32_t itemptr, t_item* item);
#ifdef __cplusplus

@ -1,6 +1,6 @@
/*
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
warranty. In no event will the authors be held liable for any
@ -25,17 +25,17 @@ distribution.
#ifndef MAPS_C_API
#define MAPS_C_API
#include "Export.h"
#include "integers.h"
#include "dfhack/DFExport.h"
#include "dfhack/DFIntegers.h"
#include <vector>
#include <map>
#include <string>
using namespace std;
#include "DFTypes.h"
#include "modules/Maps.h"
#include "DFHackAPI_C.h"
#include "dfhack/DFTypes.h"
#include "dfhack/modules/Maps.h"
#include "DFHack_C.h"
using namespace DFHack;

@ -1,6 +1,6 @@
/*
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
warranty. In no event will the authors be held liable for any
@ -25,12 +25,12 @@ distribution.
#ifndef MATERIALS_C_API
#define MATERIALS_C_API
#include "Export.h"
#include "integers.h"
#include "DFTypes.h"
#include "modules/Materials.h"
#include "DFHackAPI_C.h"
#include "DFTypes_C.h"
#include "dfhack/DFExport.h"
#include "dfhack/DFIntegers.h"
#include "dfhack/DFTypes.h"
#include "dfhack/modules/Materials.h"
#include "DFHack_C.h"
#include "dfhack-c/DFTypes_C.h"
using namespace DFHack;
@ -38,10 +38,6 @@ using namespace DFHack;
extern "C" {
#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_ReadOrganicMaterials(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_getOtherSize(DFHackObject* mat);
DFHACK_EXPORT int Materials_getInorganic(DFHackObject* mat, MatglossBufferFunc callback);
DFHACK_EXPORT int Materials_getOrganic(DFHackObject* mat, MatglossBufferFunc callback);
DFHACK_EXPORT int Materials_getTree(DFHackObject* mat, MatglossBufferFunc callback);
DFHACK_EXPORT int Materials_getPlant(DFHackObject* mat, MatglossBufferFunc callback);
DFHACK_EXPORT int Materials_getRace(DFHackObject* mat, MatglossBufferFunc callback);
DFHACK_EXPORT t_matgloss* Materials_getInorganic(DFHackObject* mat);
DFHACK_EXPORT t_matgloss* Materials_getOrganic(DFHackObject* mat);
DFHACK_EXPORT t_matgloss* Materials_getTree(DFHackObject* mat);
DFHACK_EXPORT t_matgloss* Materials_getPlant(DFHackObject* mat);
DFHACK_EXPORT t_matgloss* Materials_getRace(DFHackObject* mat);
/*doomchild:
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 c_creaturetype* Materials_getRaceEx(DFHackObject* mat);
DFHACK_EXPORT int Materials_getColor(DFHackObject* mat, DescriptorColorBufferFunc callback);
DFHACK_EXPORT int Materials_getOther(DFHackObject* mat, MatglossOtherBufferFunc callback);
DFHACK_EXPORT t_descriptor_color* Materials_getColor(DFHackObject* mat);
DFHACK_EXPORT t_matglossOther* Materials_getOther(DFHackObject* mat);
#ifdef __cplusplus
}

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

@ -1,6 +1,6 @@
/*
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
warranty. In no event will the authors be held liable for any
@ -25,11 +25,11 @@ distribution.
#ifndef TRANSLATION_C_API
#define TRANSLATION_C_API
#include "Export.h"
#include "integers.h"
#include "DFTypes.h"
#include "modules/Translation.h"
#include "DFHackAPI_C.h"
#include "dfhack/DFExport.h"
#include "dfhack/DFIntegers.h"
#include "dfhack/DFTypes.h"
#include "dfhack/modules/Translation.h"
#include "DFHack_C.h"
using namespace DFHack;

@ -1,6 +1,6 @@
/*
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
warranty. In no event will the authors be held liable for any
@ -25,11 +25,11 @@ distribution.
#ifndef VEGETATION_C_API
#define VEGETATION_C_API
#include "Export.h"
#include "integers.h"
#include "DFTypes.h"
#include "modules/Vegetation.h"
#include "DFHackAPI_C.h"
#include "dfhack/DFExport.h"
#include "dfhack/DFIntegers.h"
#include "dfhack/DFTypes.h"
#include "dfhack/modules/Vegetation.h"
#include "DFHack_C.h"
using namespace DFHack;

@ -1,3 +1,4 @@
/*
www.sourceforge.net/projects/dfhack
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.
*/
#ifndef SIMPLEAPI_H_INCLUDED
#define SIMPLEAPI_H_INCLUDED
#include "Tranquility.h"
#include "Export.h"
#include <string>
#include <vector>
#include <map>
#include "integers.h"
#include "DFTileTypes.h"
#include "DFTypes.h"
#include "DFWindow.h"
#ifndef CONTEXT_H_INCLUDED
#define CONTEXT_H_INCLUDED
#include "DFExport.h"
namespace DFHack
{
class APIPrivate;
class memory_info;
class Process;
// modules
class Maps;
class Creatures;
class Position;
class Maps;
class Gui;
class World;
class Position;
class Materials;
class Items;
class Translation;
class Vegetation;
class Buildings;
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:
API(const std::string path_to_xml);
~API();
public:
Context(Process * p);
~Context();
/*
* Basic control over DF's process state
*/
bool isValid();
bool Attach();
bool Detach();
bool isAttached();
/// stop DF from executing
/// stop the tracked process
bool Suspend();
bool isSuspended();
/// stop DF from executing, asynchronous, use with polling
/// stop the tracked process, asynchronous
bool AsyncSuspend();
/// resume DF
/// resume the tracked process
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();
memory_info *getMemoryInfo();
Process * getProcess();
DFWindow * getWindow();
Process* getProcess();
/// read/write size bytes of raw data at offset. DANGEROUS, CAN SEGFAULT DF!
void ReadRaw (const uint32_t offset, const uint32_t size, uint8_t *target);
void WriteRaw (const uint32_t offset, const uint32_t size, uint8_t *source);
// FIXME: this is crap.
// get the creatures module
Creatures * getCreatures();
@ -109,7 +95,7 @@ namespace DFHack
// get the materials module
Materials * getMaterials();
// get the items module
// get the items module
Items * getItems();
// get the translation module
@ -124,6 +110,8 @@ namespace DFHack
// get the constructions module
Constructions * getConstructions();
// get the Window management and I/O module
WindowIO * getWindow();
/*
* Effects like mist, dragonfire or dust
*/
@ -182,6 +170,9 @@ namespace DFHack
bool ReadAllMatgloss(vector< vector< string > > & all);
*/
//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.
*/
#include "Tranquility.h"
#include "DFCommonInternal.h"
#include "DFMemInfo.h"
#include "DFProcess.h"
#include "DFVector.h"
using namespace DFHack;
#ifndef CONTEXTMANAGER_H_INCLUDED
#define CONTEXTMANAGER_H_INCLUDED
#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
#define ERROR_H_INCLUDED
#include "Export.h"
#include "DFExport.h"
#include <string>
#include <sstream>
#include <exception>

@ -1,6 +1,6 @@
#ifndef DFHACK_GLOBAL
#define DFHACK_GLOBAL
#include "Export.h"
#include "DFExport.h"
// 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
#include <stdint.h>
#else
#include "stdint_win.h"
#include "DFstdint_win.h"
#endif
#endif

@ -25,9 +25,8 @@ distribution.
#ifndef MEMINFO_H_INCLUDED
#define MEMINFO_H_INCLUDED
#include "Tranquility.h"
#include "Export.h"
#include "DFPragma.h"
#include "DFExport.h"
#include <map>
#include <vector>
#include <string>
@ -45,9 +44,9 @@ namespace DFHack
*/
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){};
string classname;
std::string classname;
uint32_t assign;
uint32_t type;
};
@ -80,7 +79,7 @@ namespace DFHack
}
subs.clear();
}
string classname;
std::string classname;
uint32_t vtable;
uint32_t assign;// index to typeclass array if multiclass. return value if not.
uint32_t type_offset; // offset of type data for multiclass
@ -106,52 +105,52 @@ namespace DFHack
void RebaseAddresses(const int32_t new_base);
void RebaseAll(const int32_t new_base);
uint32_t getBase () const;
void setBase (const string&);
void setBase (const std::string&);
void setBase (const uint32_t);
int32_t getOffset (const string&);
uint32_t getAddress (const string&);
uint32_t getHexValue (const string&);
int32_t getOffset (const std::string&);
uint32_t getAddress (const std::string&);
uint32_t getHexValue (const std::string&);
int32_t getOffset (const char *);
uint32_t getAddress (const char *);
uint32_t getHexValue (const char *);
string getString (const string&);
string getProfession(const uint32_t) const;
string getJob(const uint32_t) const;
string getSkill (const uint32_t) const;
string getTrait (const uint32_t, const uint32_t) const;
string getTraitName(const uint32_t) const;
string getLabor (const uint32_t);
std::string getString (const std::string&);
std::string getProfession(const uint32_t) const;
std::string getJob(const uint32_t) const;
std::string getSkill (const uint32_t) const;
std::string getTrait (const uint32_t, const uint32_t) const;
std::string getTraitName(const uint32_t) const;
std::string getLabor (const uint32_t);
void setVersion(const char *);
void setVersion(const string&);
string getVersion();
void setVersion(const std::string&);
std::string getVersion();
void setOS(const char *);
void setOS(const string&);
void setOS(const std::string&);
void setOS(const OSType);
OSType getOS() const;
void setOffset (const string &, const int32_t);
void setAddress (const string &, const uint32_t);
void setHexValue (const string &, const uint32_t);
void setOffset (const std::string &, const int32_t);
void setAddress (const std::string &, const uint32_t);
void setHexValue (const std::string &, const uint32_t);
void setOffset (const string &, const char *);
void setAddress (const string &, const char *);
void setHexValue (const string &, const char *);
void setString (const string &, const char *);
void setOffset (const std::string &, const char *);
void setAddress (const std::string &, const char *);
void setHexValue (const std::string &, const char *);
void setString (const std::string &, const char *);
void setOffset (const string &, const string &);
void setAddress (const string &, const string &);
void setHexValue (const string &, const string &);
void setString (const string &, const string &);
void setOffset (const std::string &, const std::string &);
void setAddress (const std::string &, const std::string &);
void setHexValue (const std::string &, const std::string &);
void setString (const std::string &, const std::string &);
void setProfession(const string &, const string &);
void setJob(const string &, const string &);
void setSkill(const string &, const string &);
void setTrait(const string &,const string &,const string &,const string &,const string &,const string &,const string &,const string &);
void setLabor(const string &, const string &);
void setProfession(const std::string &, const std::string &);
void setJob(const std::string &, const std::string &);
void setSkill(const std::string &, const std::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 std::string &, const std::string &);
void RebaseVTable(const int32_t offset);
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
*/
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
* 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)
*/
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!
*/
const vector<string> * getClassIDMapping();
const vector<std::string> * getClassIDMapping();
};
}
#endif // MEMINFO_H_INCLUDED

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

@ -3,16 +3,16 @@
#include <iostream>
#include <iomanip>
#include <climits>
#include <integers.h>
#include <dfhack/DFIntegers.h>
#include <vector>
#include <sstream>
#include <ctime>
#include <cstdio>
using namespace std;
#include <DFProcess.h>
#include <DFMemInfo.h>
#include <DFVector.h>
#include <dfhack/DFProcess.h>
#include <dfhack/DFMemInfo.h>
#include <dfhack/DFVector.h>
/*
* 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
length = length in lines. 1 line = 16 bytes
*/
void hexdump (DFHack::API& DF, uint32_t address, uint32_t length)
void hexdump (DFHack::Context *DF, uint32_t address, uint32_t length)
{
char *buf = new char[length * 16];
DF.ReadRaw(address, length * 16, (uint8_t *) buf);
DF->ReadRaw(address, length * 16, (uint8_t *) buf);
for (uint32_t i = 0; i < length; i++)
{
// leading offset
@ -74,7 +73,6 @@ void hexdump (DFHack::API& DF, uint32_t address, uint32_t length)
for(int k = 0; k < 4; k++)
{
int idx = i * 16 + j * 4 + k;
cout << hex << setw(2) << int(static_cast<unsigned char>(buf[idx])) << " ";
}
cout << " ";
@ -84,14 +82,14 @@ void hexdump (DFHack::API& DF, uint32_t address, uint32_t length)
delete buf;
}
void interleave_hex (DFHack::API& DF, vector < uint32_t > & addresses, uint32_t length)
void interleave_hex (DFHack::Context* DF, vector < uint32_t > & addresses, uint32_t length)
{
vector <char * > bufs;
for(uint32_t counter = 0; counter < addresses.size(); counter ++)
{
char * buf = new char[length * 16];
DF.ReadRaw(addresses[counter], length * 16, (uint8_t *) buf);
DF->ReadRaw(addresses[counter], length * 16, (uint8_t *) buf);
bufs.push_back(buf);
}
cout << setfill('0');

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

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

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

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

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

@ -3,7 +3,7 @@
/*
* Buildings - also includes zones and stockpiles
*/
#include "Export.h"
#include "dfhack/DFExport.h"
namespace DFHack
{
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)
};
class APIPrivate;
class DFContextShared;
class DFHACK_EXPORT Buildings
{
public:
Buildings(APIPrivate * d);
Buildings(DFContextShared * d);
~Buildings();
bool Start(uint32_t & numBuildings);
// read one building at offset

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

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

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

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

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

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

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

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

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

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

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

@ -1,6 +1,6 @@
/*
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
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.
*/
#include "integers.h"
#include "dfhack/DFIntegers.h"
#include <string>
#include <map>
#include "stdio.h"
using namespace std;
#include "DFCommonInternal.h"
#include "DFTypes.h"
#include "modules/Buildings.h"
#include "modules/Buildings_C.h"
#include "Internal.h"
#include "dfhack/DFTypes.h"
#include "dfhack/modules/Buildings.h"
#include "dfhack-c/modules/Buildings_C.h"
using namespace DFHack;

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

@ -1,6 +1,6 @@
/*
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
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.
*/
#include "integers.h"
#include "dfhack/DFIntegers.h"
#include "DFCommonInternal.h"
#include "DFTypes.h"
#include "modules/Constructions.h"
#include "modules/Constructions_C.h"
#include "Internal.h"
#include "dfhack/DFTypes.h"
#include "dfhack/modules/Constructions.h"
#include "dfhack-c/modules/Constructions_C.h"
using namespace DFHack;

@ -22,21 +22,21 @@ must not be misrepresented as being the original software.
distribution.
*/
#include "DFCommonInternal.h"
#include "../private/APIPrivate.h"
#include "Internal.h"
#include "ContextShared.h"
#include "DFMemInfo.h"
#include "DFProcess.h"
#include "DFVector.h"
#include "DFError.h"
#include "DFTypes.h"
#include "dfhack/DFMemInfo.h"
#include "dfhack/DFProcess.h"
#include "dfhack/DFVector.h"
#include "dfhack/DFError.h"
#include "dfhack/DFTypes.h"
// we connect to those
#include <shms.h>
#include <mod-core.h>
#include <mod-creature2010.h>
#include "modules/Materials.h"
#include "modules/Creatures.h"
#include "dfhack/modules/Materials.h"
#include "dfhack/modules/Creatures.h"
#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_civ_id_addr;
DfVector <uint32_t> *p_cre;
APIPrivate *d;
DFContextShared *d;
Process *owner;
};
Creatures::Creatures(APIPrivate* _d)
Creatures::Creatures(DFContextShared* _d)
{
d = new Private;
d->d = _d;
@ -111,6 +111,7 @@ Creatures::Creatures(APIPrivate* _d)
creatures.name_words_offset = minfo->getOffset("name_words");
d->dwarf_race_index_addr = minfo->getAddress("dwarf_race_index");
d->dwarf_civ_id_addr = minfo->getAddress("dwarf_civ_id");
/*
// upload offsets to the SHM
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);
p->SetAndWait(cmd);
}
*/
d->Inited = true;
}
catch (Error::MissingMemoryDefinition&)
@ -158,6 +160,7 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
if(!d->Started) return false;
// SHM fast path
Process * p = d->owner;
/*
if(d->creature_module)
{
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));
return true;
}
*/
// non-SHM slow path
memory_info * minfo = d->d->offset_descriptor;
@ -300,7 +303,7 @@ int32_t Creatures::ReadCreatureInBox (int32_t index, t_creature & furball,
return -1;
Process *p = d->owner;
/*
if(d->creature_module)
{
// 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));
return SHMCREATURESHDR->index;
}
else
else*/
{
uint16_t coords[3];
uint32_t size = d->p_cre->size();

@ -1,6 +1,6 @@
/*
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
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.
*/
#include "Export.h"
#include "integers.h"
#include "dfhack/DFExport.h"
#include "dfhack/DFIntegers.h"
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#include "DFTypes.h"
#include "modules/Materials.h"
#include "modules/Creatures.h"
#include "modules/Creatures_C.h"
#include "DFHackAPI_C.h"
#include "dfhack/DFTypes.h"
#include "dfhack/modules/Materials.h"
#include "dfhack/modules/Creatures.h"
#include "dfhack-c/modules/Creatures_C.h"
#include "DFHack_C.h"
using namespace DFHack;

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

@ -1,6 +1,6 @@
/*
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
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
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 "integers.h"
#include "DFCommonInternal.h"
#include "modules/Gui.h"
#include "Internal.h"
#include "dfhack/modules/Gui.h"
using namespace DFHack;
@ -66,7 +68,7 @@ int Gui_ReadPauseState(DFHackObject* gui)
int Gui_ReadViewScreen(DFHackObject* gui, t_viewscreen* viewscreen)
{
int result;
//int result;
if(gui != NULL)
{

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

@ -1,6 +1,6 @@
/*
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
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.
*/
#include "integers.h"
#include <map>
#include <vector>
#include <string>
#include "dfhack/DFExport.h"
#include "dfhack/DFIntegers.h"
#include "DFHack_C.h"
#include "dfhack/DFTypes.h"
using namespace std;
using namespace DFHack;
#include "DFCommonInternal.h"
#include "DFTypes.h"
#include "DFHackAPI.h"
#include "modules/Materials.h"
#include "modules/Items.h"
#include "modules/Items_C.h"
#include "dfhack/DFProcess.h"
#include "dfhack/modules/Materials.h"
#include "dfhack/modules/Items.h"
#include "dfhack-c/DFTypes_C.h"
#include "dfhack-c/modules/Items_C.h"
using namespace DFHack;
#ifdef __cplusplus
extern "C" {
#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)
{
@ -48,7 +53,7 @@ char* Items_getItemDescription(DFHackObject* items, uint32_t itemptr, DFHackObje
if(desc.size() > 0)
{
char* buf = (*char_buffer_create)(desc.size());
char* buf = (*alloc_char_buffer_callback)(desc.size());
if(buf != NULL)
{
@ -67,7 +72,7 @@ char* Items_getItemDescription(DFHackObject* items, uint32_t itemptr, DFHackObje
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)
{
@ -75,7 +80,7 @@ char* Items_getItemClass(DFHackObject* items, int32_t index, char* (*char_buffer
if(iclass.size() > 0)
{
char* buf = (*char_buffer_create)(iclass.size());
char* buf = (*alloc_char_buffer_callback)(iclass.size());
if(buf != NULL)
{

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

@ -1,6 +1,6 @@
/*
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
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.
*/
#include "integers.h"
#include "dfhack/DFIntegers.h"
#include <vector>
#include <map>
#include <string>
using namespace std;
#include "DFCommonInternal.h"
#include "DFTypes.h"
#include "modules/Maps.h"
#include "modules/Maps_C.h"
#include "Internal.h"
#include "dfhack/DFTypes.h"
#include "dfhack/modules/Maps.h"
#include "dfhack-c/modules/Maps_C.h"
using namespace DFHack;

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

@ -1,6 +1,6 @@
/*
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
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.
*/
#include "integers.h"
#include "dfhack/DFIntegers.h"
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#include "DFCommonInternal.h"
#include "DFTypes.h"
#include "modules/Materials.h"
#include "DFTypes_C.h"
#include "modules/Materials_C.h"
#include "Internal.h"
#include "dfhack/DFTypes.h"
#include "dfhack/modules/Materials.h"
#include "dfhack-c/DFTypes_C.h"
#include "dfhack-c/modules/Materials_C.h"
using namespace DFHack;
@ -225,7 +225,7 @@ int Materials_getOtherSize(DFHackObject* mat)
//vector getters
int Materials_getInorganic(DFHackObject* mat, MatglossBufferFunc callback)
t_matgloss* Materials_getInorganic(DFHackObject* mat)
{
if(mat != NULL)
{
@ -233,25 +233,21 @@ int Materials_getInorganic(DFHackObject* mat, MatglossBufferFunc callback)
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)
{
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)
{
@ -259,25 +255,21 @@ int Materials_getOrganic(DFHackObject* mat, MatglossBufferFunc callback)
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)
{
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)
{
@ -285,25 +277,21 @@ int Materials_getTree(DFHackObject* mat, MatglossBufferFunc callback)
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)
{
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)
{
@ -311,25 +299,21 @@ int Materials_getPlant(DFHackObject* mat, MatglossBufferFunc callback)
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)
{
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)
{
@ -337,67 +321,46 @@ int Materials_getRace(DFHackObject* mat, MatglossBufferFunc callback)
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)
{
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...
// int Materials_getRaceEx(DFHackObject* mat, c_creaturetype* (*c_creaturetype_buffer_create)(c_creaturetype_descriptor*, int))
// {
// if(mat != NULL)
// {
// DFHack::Materials* materials = (DFHack::Materials*)mat;
// 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';
c_creaturetype* Materials_getRaceEx(DFHackObject* mat)
{
if(mat != NULL)
{
DFHack::Materials* materials = (DFHack::Materials*)mat;
int matSize = materials->raceEx.size();
// buf[i].tile_character = current.tile_character;
// buf[i].tilecolor = current.tilecolor;
if(matSize > 0)
{
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)
{
@ -405,25 +368,21 @@ int Materials_getColor(DFHackObject* mat, DescriptorColorBufferFunc callback)
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)
{
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)
{
@ -431,22 +390,18 @@ int Materials_getOther(DFHackObject* mat, MatglossOtherBufferFunc callback)
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)
{
copy(materials->other.begin(), materials->other.end(), buf);
return 1;
return buf;
}
else
return -1;
}
else
return 0;
}
return -1;
return NULL;
}
#ifdef __cplusplus

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

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

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

@ -1,6 +1,6 @@
/*
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
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.
*/
#include "integers.h"
#include "dfhack/DFIntegers.h"
#include <string>
using namespace std;
#include "DFCommonInternal.h"
#include "DFTypes.h"
#include "modules/Translation.h"
#include "modules/Translation_C.h"
#include "Internal.h"
#include "dfhack/DFTypes.h"
#include "dfhack/modules/Translation.h"
#include "dfhack-c/modules/Translation_C.h"
using namespace DFHack;

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