diff --git a/CMakeLists.txt b/CMakeLists.txt index f7a50432b..e4dc7ab5e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/README b/README index 6f38709ef..56c5c4d7d 100644 --- a/README +++ b/README @@ -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 ------------------------- diff --git a/dfhack/CMakeLists.txt b/dfhack/CMakeLists.txt deleted file mode 100644 index f9a078363..000000000 --- a/dfhack/CMakeLists.txt +++ /dev/null @@ -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) diff --git a/dfhack/DFHackAPI_C.cpp b/dfhack/DFHackAPI_C.cpp deleted file mode 100644 index c92a530b0..000000000 --- a/dfhack/DFHackAPI_C.cpp +++ /dev/null @@ -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 -#include -#include -#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 diff --git a/dfhack/DFTypes_C.cpp b/dfhack/DFTypes_C.cpp deleted file mode 100644 index c5f39908f..000000000 --- a/dfhack/DFTypes_C.cpp +++ /dev/null @@ -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 -#include "string.h" -#include -#include - -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; -} \ No newline at end of file diff --git a/dfhack/include/DFHackAPI_C.h b/dfhack/include/DFHackAPI_C.h deleted file mode 100644 index bf4395895..000000000 --- a/dfhack/include/DFHackAPI_C.h +++ /dev/null @@ -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 diff --git a/dfhack/include/DFTypes_C.h b/dfhack/include/DFTypes_C.h deleted file mode 100644 index db078de44..000000000 --- a/dfhack/include/DFTypes_C.h +++ /dev/null @@ -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 diff --git a/dfhack/pydfhack.i b/dfhack/pydfhack.i deleted file mode 100644 index 86048dd32..000000000 --- a/dfhack/pydfhack.i +++ /dev/null @@ -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; -%template(PlantMatglossVector) std::vector; -%template(VeinVector) std::vector ; -%template(IceVeinVector) std::vector ; - -/* -This causes swig to generate BS uncompilable code -%template(GeologyAssign) std::vector < std::vector >; -*/ - -/* -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 & OUTPUT); - bool ReadWoodMatgloss (std::vector & OUTPUT); - bool ReadMetalMatgloss(std::vector & OUTPUT); - bool ReadPlantMatgloss(std::vector & OUTPUT); - /* - * SWIG reports that it can't wrap the second method here - */ - bool ReadPlantMatgloss (std::vector & OUTPUT); - bool ReadCreatureMatgloss(std::vector & OUTPUT); - - bool ReadGeology( std::vector < std::vector >& 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 & veins, std::vector & 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 &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 > & translations , std::vector< std::vector > & foreign_languages); - void FinishReadNameTables(); - - std::string TranslateName(const t_name & name,const std::vector< std::vector > & translations ,const std::vector< std::vector > & 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 \ No newline at end of file diff --git a/dfhack/python/c api/util.py b/dfhack/python/c api/util.py deleted file mode 100644 index d81b01ede..000000000 --- a/dfhack/python/c api/util.py +++ /dev/null @@ -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) diff --git a/dfhack/shm/CMakeLists.txt b/dfhack/shm/CMakeLists.txt deleted file mode 100644 index 2638a7e89..000000000 --- a/dfhack/shm/CMakeLists.txt +++ /dev/null @@ -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) diff --git a/examples/veccheck.cpp b/examples/veccheck.cpp deleted file mode 100644 index 05feb5c6b..000000000 --- a/examples/veccheck.cpp +++ /dev/null @@ -1,204 +0,0 @@ -// Just show some position data - -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace DFHack; -/* -int __userpurge get_feature_at(__int16 tZ, __int16 tY, int world_base, 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(block.designation[tileX][tileY].whole,cout); - cout << endl; - print_bits(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; -} diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt new file mode 100644 index 000000000..ce44079cf --- /dev/null +++ b/library/CMakeLists.txt @@ -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) + diff --git a/dfhack/APIPrivate.cpp b/library/ContextShared.cpp similarity index 60% rename from dfhack/APIPrivate.cpp rename to library/ContextShared.cpp index d4cb5d7fb..7798cc85f 100644 --- a/dfhack/APIPrivate.cpp +++ b/library/ContextShared.cpp @@ -1,26 +1,27 @@ -#include "DFCommonInternal.h" +#include "Internal.h" #include #include #include #include -#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); diff --git a/dfhack/DFHackAPI.cpp b/library/DFContext.cpp similarity index 84% rename from dfhack/DFHackAPI.cpp rename to library/DFContext.cpp index d4d22f321..fe2d5002e 100644 --- a/dfhack/DFHackAPI.cpp +++ b/library/DFContext.cpp @@ -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 #include #include #include -#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); diff --git a/library/DFContextManager.cpp b/library/DFContextManager.cpp new file mode 100644 index 000000000..636325bdc --- /dev/null +++ b/library/DFContextManager.cpp @@ -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 +#include +#include +#include +#include "private/ContextShared.h" + +using namespace DFHack; +namespace DFHack +{ + class DFContextMgrPrivate + { + public: + DFContextMgrPrivate(){}; + ~DFContextMgrPrivate(){}; + string xml; // path to xml + vector 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; + } +} \ No newline at end of file diff --git a/library/DFContext_C.cpp b/library/DFContext_C.cpp new file mode 100644 index 000000000..3de599df0 --- /dev/null +++ b/library/DFContext_C.cpp @@ -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 +#include +#include +#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 diff --git a/dfhack/DFMemInfo.cpp b/library/DFMemInfo.cpp similarity index 99% rename from dfhack/DFMemInfo.cpp rename to library/DFMemInfo.cpp index 7247bce47..8ac0a2c94 100644 --- a/dfhack/DFMemInfo.cpp +++ b/library/DFMemInfo.cpp @@ -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; diff --git a/dfhack/DFMemInfoManager.cpp b/library/DFMemInfoManager.cpp similarity index 98% rename from dfhack/DFMemInfoManager.cpp rename to library/DFMemInfoManager.cpp index 3059eca66..4b7f537e0 100644 --- a/dfhack/DFMemInfoManager.cpp +++ b/library/DFMemInfoManager.cpp @@ -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; diff --git a/dfhack/DFProcess-linux-SHM.cpp b/library/DFProcess-linux-SHM.cpp similarity index 98% rename from dfhack/DFProcess-linux-SHM.cpp rename to library/DFProcess-linux-SHM.cpp index 4b84d7086..d4f90db93 100644 --- a/dfhack/DFProcess-linux-SHM.cpp +++ b/library/DFProcess-linux-SHM.cpp @@ -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 #include @@ -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; @@ -76,16 +73,14 @@ class SHMProcess::Private int client_lock; int suspend_lock; int attachmentIdx; - - bool attached; bool locked; bool identified; bool useYield; - + bool validate(std::vector< memory_info* >& known_versions); - + bool Aux_Core_Attach(bool & versionOK, pid_t & PID); //bool waitWhile (uint32_t state); bool SetAndWait (uint32_t state); @@ -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 diff --git a/dfhack/DFProcess-linux-wine.cpp b/library/DFProcess-linux-wine.cpp similarity index 97% rename from dfhack/DFProcess-linux-wine.cpp rename to library/DFProcess-linux-wine.cpp index 18a1ca6fd..b9ef2339b 100644 --- a/dfhack/DFProcess-linux-wine.cpp +++ b/library/DFProcess-linux-wine.cpp @@ -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 -#include #include #include 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 & 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) { diff --git a/dfhack/DFProcess-linux.cpp b/library/DFProcess-linux.cpp similarity index 96% rename from dfhack/DFProcess-linux.cpp rename to library/DFProcess-linux.cpp index 9e5232995..343985a3d 100644 --- a/dfhack/DFProcess-linux.cpp +++ b/library/DFProcess-linux.cpp @@ -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 #include 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) { diff --git a/dfhack/DFProcess-windows-SHM.cpp b/library/DFProcess-windows-SHM.cpp similarity index 98% rename from dfhack/DFProcess-windows-SHM.cpp rename to library/DFProcess-windows-SHM.cpp index c0cc927f4..9a8bd8d4f 100644 --- a/dfhack/DFProcess-windows-SHM.cpp +++ b/library/DFProcess-windows-SHM.cpp @@ -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 & 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 diff --git a/dfhack/DFProcess-windows.cpp b/library/DFProcess-windows.cpp similarity index 97% rename from dfhack/DFProcess-windows.cpp rename to library/DFProcess-windows.cpp index 54254d235..da44a0f32 100644 --- a/dfhack/DFProcess-windows.cpp +++ b/library/DFProcess-windows.cpp @@ -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 & 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 diff --git a/dfhack/DFProcessEnumerator-linux.cpp b/library/DFProcessEnumerator-linux.cpp similarity index 95% rename from dfhack/DFProcessEnumerator-linux.cpp rename to library/DFProcessEnumerator-linux.cpp index 1f1e26eeb..3ee14ef80 100644 --- a/dfhack/DFProcessEnumerator-linux.cpp +++ b/library/DFProcessEnumerator-linux.cpp @@ -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 #include #include diff --git a/dfhack/DFProcessEnumerator-windows.cpp b/library/DFProcessEnumerator-windows.cpp similarity index 95% rename from dfhack/DFProcessEnumerator-windows.cpp rename to library/DFProcessEnumerator-windows.cpp index 4d078e2e3..bec67361d 100644 --- a/dfhack/DFProcessEnumerator-windows.cpp +++ b/library/DFProcessEnumerator-windows.cpp @@ -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 diff --git a/library/DFTypes_C.cpp b/library/DFTypes_C.cpp new file mode 100644 index 000000000..2a27ad292 --- /dev/null +++ b/library/DFTypes_C.cpp @@ -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 +#include "string.h" +#include +#include + +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; +} diff --git a/dfhack/config.h.cmake b/library/config.h.cmake similarity index 100% rename from dfhack/config.h.cmake rename to library/config.h.cmake diff --git a/dfhack/depends/argstream/argstream.h b/library/depends/argstream/argstream.h similarity index 100% rename from dfhack/depends/argstream/argstream.h rename to library/depends/argstream/argstream.h diff --git a/dfhack/depends/md5/CMakeLists.txt b/library/depends/md5/CMakeLists.txt similarity index 100% rename from dfhack/depends/md5/CMakeLists.txt rename to library/depends/md5/CMakeLists.txt diff --git a/dfhack/depends/md5/md5.cpp b/library/depends/md5/md5.cpp similarity index 100% rename from dfhack/depends/md5/md5.cpp rename to library/depends/md5/md5.cpp diff --git a/dfhack/depends/md5/md5.h b/library/depends/md5/md5.h similarity index 98% rename from dfhack/depends/md5/md5.h rename to library/depends/md5/md5.h index 91b43b861..af2864a10 100644 --- a/dfhack/depends/md5/md5.h +++ b/library/depends/md5/md5.h @@ -45,7 +45,7 @@ //---------------------------------------------------------------------- //STL includes #include -#include +#include //---------------------------------------------------------------------- //typedefs typedef unsigned char *POINTER; diff --git a/dfhack/depends/md5/md5wrapper.cpp b/library/depends/md5/md5wrapper.cpp similarity index 100% rename from dfhack/depends/md5/md5wrapper.cpp rename to library/depends/md5/md5wrapper.cpp diff --git a/dfhack/depends/md5/md5wrapper.h b/library/depends/md5/md5wrapper.h similarity index 100% rename from dfhack/depends/md5/md5wrapper.h rename to library/depends/md5/md5wrapper.h diff --git a/dfhack/depends/tinyxml/CMakeLists.txt b/library/depends/tinyxml/CMakeLists.txt similarity index 100% rename from dfhack/depends/tinyxml/CMakeLists.txt rename to library/depends/tinyxml/CMakeLists.txt diff --git a/dfhack/depends/tinyxml/tinystr.cpp b/library/depends/tinyxml/tinystr.cpp similarity index 100% rename from dfhack/depends/tinyxml/tinystr.cpp rename to library/depends/tinyxml/tinystr.cpp diff --git a/dfhack/depends/tinyxml/tinystr.h b/library/depends/tinyxml/tinystr.h similarity index 100% rename from dfhack/depends/tinyxml/tinystr.h rename to library/depends/tinyxml/tinystr.h diff --git a/dfhack/depends/tinyxml/tinyxml.cpp b/library/depends/tinyxml/tinyxml.cpp similarity index 100% rename from dfhack/depends/tinyxml/tinyxml.cpp rename to library/depends/tinyxml/tinyxml.cpp diff --git a/dfhack/depends/tinyxml/tinyxml.h b/library/depends/tinyxml/tinyxml.h similarity index 100% rename from dfhack/depends/tinyxml/tinyxml.h rename to library/depends/tinyxml/tinyxml.h diff --git a/dfhack/depends/tinyxml/tinyxmlerror.cpp b/library/depends/tinyxml/tinyxmlerror.cpp similarity index 100% rename from dfhack/depends/tinyxml/tinyxmlerror.cpp rename to library/depends/tinyxml/tinyxmlerror.cpp diff --git a/dfhack/depends/tinyxml/tinyxmlparser.cpp b/library/depends/tinyxml/tinyxmlparser.cpp similarity index 100% rename from dfhack/depends/tinyxml/tinyxmlparser.cpp rename to library/depends/tinyxml/tinyxmlparser.cpp diff --git a/library/include/DFHack.h b/library/include/DFHack.h new file mode 100644 index 000000000..22a332522 --- /dev/null +++ b/library/include/DFHack.h @@ -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 \ No newline at end of file diff --git a/dfhack/DFTileTypes.cpp b/library/include/DFHack_C.h similarity index 73% rename from dfhack/DFTileTypes.cpp rename to library/include/DFHack_C.h index 7ec2f781d..8eb381595 100644 --- a/dfhack/DFTileTypes.cpp +++ b/library/include/DFHack_C.h @@ -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 diff --git a/library/include/dfhack-c/DFContext_C.h b/library/include/dfhack-c/DFContext_C.h new file mode 100644 index 000000000..32ecca9e9 --- /dev/null +++ b/library/include/dfhack-c/DFContext_C.h @@ -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 diff --git a/library/include/dfhack-c/DFTypes_C.h b/library/include/dfhack-c/DFTypes_C.h new file mode 100644 index 000000000..18c8de3b3 --- /dev/null +++ b/library/include/dfhack-c/DFTypes_C.h @@ -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 diff --git a/dfhack/include/modules/Buildings_C.h b/library/include/dfhack-c/modules/Buildings_C.h similarity index 86% rename from dfhack/include/modules/Buildings_C.h rename to library/include/dfhack-c/modules/Buildings_C.h index 5ecd7e4e7..c69da83e0 100644 --- a/dfhack/include/modules/Buildings_C.h +++ b/library/include/dfhack-c/modules/Buildings_C.h @@ -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; diff --git a/dfhack/include/modules/Constructions_C.h b/library/include/dfhack-c/modules/Constructions_C.h similarity index 83% rename from dfhack/include/modules/Constructions_C.h rename to library/include/dfhack-c/modules/Constructions_C.h index 179ba8b3b..c34527b1d 100644 --- a/dfhack/include/modules/Constructions_C.h +++ b/library/include/dfhack-c/modules/Constructions_C.h @@ -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; diff --git a/dfhack/include/modules/Creatures_C.h b/library/include/dfhack-c/modules/Creatures_C.h similarity index 87% rename from dfhack/include/modules/Creatures_C.h rename to library/include/dfhack-c/modules/Creatures_C.h index e216c2a0f..93502ffe6 100644 --- a/dfhack/include/modules/Creatures_C.h +++ b/library/include/dfhack-c/modules/Creatures_C.h @@ -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; diff --git a/dfhack/include/modules/Gui_C.h b/library/include/dfhack-c/modules/Gui_C.h similarity index 87% rename from dfhack/include/modules/Gui_C.h rename to library/include/dfhack-c/modules/Gui_C.h index cccde45fe..0bd68f3fc 100644 --- a/dfhack/include/modules/Gui_C.h +++ b/library/include/dfhack-c/modules/Gui_C.h @@ -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; diff --git a/dfhack/include/modules/Items_C.h b/library/include/dfhack-c/modules/Items_C.h similarity index 78% rename from dfhack/include/modules/Items_C.h rename to library/include/dfhack-c/modules/Items_C.h index 201e7142a..0568e9088 100644 --- a/dfhack/include/modules/Items_C.h +++ b/library/include/dfhack-c/modules/Items_C.h @@ -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 diff --git a/dfhack/include/modules/Maps_C.h b/library/include/dfhack-c/modules/Maps_C.h similarity index 94% rename from dfhack/include/modules/Maps_C.h rename to library/include/dfhack-c/modules/Maps_C.h index d966c04f8..e37d3640a 100644 --- a/dfhack/include/modules/Maps_C.h +++ b/library/include/dfhack-c/modules/Maps_C.h @@ -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 #include #include 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; diff --git a/dfhack/include/modules/Materials_C.h b/library/include/dfhack-c/modules/Materials_C.h similarity index 62% rename from dfhack/include/modules/Materials_C.h rename to library/include/dfhack-c/modules/Materials_C.h index 448f045de..ef56ac627 100644 --- a/dfhack/include/modules/Materials_C.h +++ b/library/include/dfhack-c/modules/Materials_C.h @@ -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 } diff --git a/dfhack/include/modules/Position_C.h b/library/include/dfhack-c/modules/Position_C.h similarity index 96% rename from dfhack/include/modules/Position_C.h rename to library/include/dfhack-c/modules/Position_C.h index fb74fc647..3b2f1dc0b 100644 --- a/dfhack/include/modules/Position_C.h +++ b/library/include/dfhack-c/modules/Position_C.h @@ -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" { diff --git a/dfhack/include/modules/Translation_C.h b/library/include/dfhack-c/modules/Translation_C.h similarity index 85% rename from dfhack/include/modules/Translation_C.h rename to library/include/dfhack-c/modules/Translation_C.h index 37bd37a45..2e1aaf457 100644 --- a/dfhack/include/modules/Translation_C.h +++ b/library/include/dfhack-c/modules/Translation_C.h @@ -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; diff --git a/dfhack/include/modules/Vegetation_C.h b/library/include/dfhack-c/modules/Vegetation_C.h similarity index 83% rename from dfhack/include/modules/Vegetation_C.h rename to library/include/dfhack-c/modules/Vegetation_C.h index 5db1300e2..c57c3948a 100644 --- a/dfhack/include/modules/Vegetation_C.h +++ b/library/include/dfhack-c/modules/Vegetation_C.h @@ -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; diff --git a/dfhack/include/DFHackAPI.h b/library/include/dfhack/DFContext.h similarity index 83% rename from dfhack/include/DFHackAPI.h rename to library/include/dfhack/DFContext.h index 9f5d30b80..658d90ee1 100644 --- a/dfhack/include/DFHackAPI.h +++ b/library/include/dfhack/DFContext.h @@ -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 -#include -#include -#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 + diff --git a/dfhack/DFVector.cpp b/library/include/dfhack/DFContextManager.h similarity index 59% rename from dfhack/DFVector.cpp rename to library/include/dfhack/DFContextManager.h index c1ff06910..3337755d7 100644 --- a/dfhack/DFVector.cpp +++ b/library/include/dfhack/DFContextManager.h @@ -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 +#include +#include + +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 diff --git a/dfhack/include/DFError.h b/library/include/dfhack/DFError.h similarity index 99% rename from dfhack/include/DFError.h rename to library/include/dfhack/DFError.h index 34cd69839..d838c5623 100644 --- a/dfhack/include/DFError.h +++ b/library/include/dfhack/DFError.h @@ -25,7 +25,7 @@ distribution. #ifndef ERROR_H_INCLUDED #define ERROR_H_INCLUDED -#include "Export.h" +#include "DFExport.h" #include #include #include diff --git a/dfhack/include/Export.h b/library/include/dfhack/DFExport.h similarity index 100% rename from dfhack/include/Export.h rename to library/include/dfhack/DFExport.h diff --git a/dfhack/include/DFGlobal.h b/library/include/dfhack/DFGlobal.h similarity index 87% rename from dfhack/include/DFGlobal.h rename to library/include/dfhack/DFGlobal.h index aea5833b8..3fdc35716 100644 --- a/dfhack/include/DFGlobal.h +++ b/library/include/dfhack/DFGlobal.h @@ -1,6 +1,6 @@ #ifndef DFHACK_GLOBAL #define DFHACK_GLOBAL -#include "Export.h" +#include "DFExport.h" // globals, if any, should be placed here. diff --git a/dfhack/include/integers.h b/library/include/dfhack/DFIntegers.h similarity index 90% rename from dfhack/include/integers.h rename to library/include/dfhack/DFIntegers.h index 6cc2396c4..cb745b251 100644 --- a/dfhack/include/integers.h +++ b/library/include/dfhack/DFIntegers.h @@ -11,6 +11,6 @@ You can turn off the include by defining SKIP_DFHACK_STDINT #ifndef _MSC_VER #include #else - #include "stdint_win.h" + #include "DFstdint_win.h" #endif #endif diff --git a/dfhack/include/DFMemInfo.h b/library/include/dfhack/DFMemInfo.h similarity index 65% rename from dfhack/include/DFMemInfo.h rename to library/include/dfhack/DFMemInfo.h index 9066c116e..765483ecc 100644 --- a/dfhack/include/DFMemInfo.h +++ b/library/include/dfhack/DFMemInfo.h @@ -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 #include #include @@ -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 * getClassIDMapping(); + const vector * getClassIDMapping(); }; } #endif // MEMINFO_H_INCLUDED diff --git a/dfhack/include/DFMemInfoManager.h b/library/include/dfhack/DFMemInfoManager.h similarity index 98% rename from dfhack/include/DFMemInfoManager.h rename to library/include/dfhack/DFMemInfoManager.h index f35a7184f..99c34afe1 100644 --- a/dfhack/include/DFMemInfoManager.h +++ b/library/include/dfhack/DFMemInfoManager.h @@ -25,7 +25,7 @@ distribution. #ifndef MEMINFO_MANAGER_H_INCLUDED #define MEMINFO_MANAGER_H_INCLUDED -#include "Tranquility.h" +#include "DFPragma.h" namespace DFHack { diff --git a/dfhack/include/DFMiscUtils.h b/library/include/dfhack/DFMiscUtils.h similarity index 92% rename from dfhack/include/DFMiscUtils.h rename to library/include/dfhack/DFMiscUtils.h index c47d0bbf8..14f192e6a 100644 --- a/dfhack/include/DFMiscUtils.h +++ b/library/include/dfhack/DFMiscUtils.h @@ -3,16 +3,16 @@ #include #include #include -#include +#include #include #include #include #include using namespace std; -#include -#include -#include +#include +#include +#include /* * 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(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 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'); diff --git a/dfhack/include/Tranquility.h b/library/include/dfhack/DFPragma.h similarity index 100% rename from dfhack/include/Tranquility.h rename to library/include/dfhack/DFPragma.h diff --git a/dfhack/include/DFProcess.h b/library/include/dfhack/DFProcess.h similarity index 98% rename from dfhack/include/DFProcess.h rename to library/include/dfhack/DFProcess.h index 24df203fe..686d7cc40 100644 --- a/dfhack/include/DFProcess.h +++ b/library/include/dfhack/DFProcess.h @@ -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 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 & threads ); void getMemRanges( vector & 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 & threads ); void getMemRanges( vector & 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 & threads ); void getMemRanges( vector & 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;}; diff --git a/dfhack/include/DFProcessEnumerator.h b/library/include/dfhack/DFProcessEnumerator.h similarity index 97% rename from dfhack/include/DFProcessEnumerator.h rename to library/include/dfhack/DFProcessEnumerator.h index 517acf5ce..c40253c15 100644 --- a/dfhack/include/DFProcessEnumerator.h +++ b/library/include/dfhack/DFProcessEnumerator.h @@ -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; diff --git a/dfhack/include/DFTileTypes.h b/library/include/dfhack/DFTileTypes.h similarity index 99% rename from dfhack/include/DFTileTypes.h rename to library/include/dfhack/DFTileTypes.h index dc6912be4..920c1541f 100644 --- a/dfhack/include/DFTileTypes.h +++ b/library/include/dfhack/DFTileTypes.h @@ -25,7 +25,7 @@ distribution. #ifndef TILETYPES_H_INCLUDED #define TILETYPES_H_INCLUDED -#include "Tranquility.h" +#include "DFPragma.h" namespace DFHack { diff --git a/dfhack/include/DFTypes.h b/library/include/dfhack/DFTypes.h similarity index 99% rename from dfhack/include/DFTypes.h rename to library/include/dfhack/DFTypes.h index 458adb741..95ab11ccd 100644 --- a/dfhack/include/DFTypes.h +++ b/library/include/dfhack/DFTypes.h @@ -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 { diff --git a/dfhack/include/DFVector.h b/library/include/dfhack/DFVector.h similarity index 98% rename from dfhack/include/DFVector.h rename to library/include/dfhack/DFVector.h index 7d69330a8..c46c80492 100644 --- a/dfhack/include/DFVector.h +++ b/library/include/dfhack/DFVector.h @@ -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; diff --git a/dfhack/include/stdint_win.h b/library/include/dfhack/DFstdint_win.h similarity index 100% rename from dfhack/include/stdint_win.h rename to library/include/dfhack/DFstdint_win.h diff --git a/dfhack/include/modules/Buildings.h b/library/include/dfhack/modules/Buildings.h similarity index 92% rename from dfhack/include/modules/Buildings.h rename to library/include/dfhack/modules/Buildings.h index 1d27a6f41..a9dc04494 100644 --- a/dfhack/include/modules/Buildings.h +++ b/library/include/dfhack/modules/Buildings.h @@ -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 diff --git a/dfhack/include/modules/Constructions.h b/library/include/dfhack/modules/Constructions.h similarity index 91% rename from dfhack/include/modules/Constructions.h rename to library/include/dfhack/modules/Constructions.h index 4c705ed4c..e4f029591 100644 --- a/dfhack/include/modules/Constructions.h +++ b/library/include/dfhack/modules/Constructions.h @@ -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); diff --git a/dfhack/include/modules/Creatures.h b/library/include/dfhack/modules/Creatures.h similarity index 99% rename from dfhack/include/modules/Creatures.h rename to library/include/dfhack/modules/Creatures.h index bfa661084..7e0d48cb5 100644 --- a/dfhack/include/modules/Creatures.h +++ b/library/include/dfhack/modules/Creatures.h @@ -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(); diff --git a/dfhack/include/modules/Gui.h b/library/include/dfhack/modules/Gui.h similarity index 86% rename from dfhack/include/modules/Gui.h rename to library/include/dfhack/modules/Gui.h index 34aea8c69..abc33cff2 100644 --- a/dfhack/include/modules/Gui.h +++ b/library/include/dfhack/modules/Gui.h @@ -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(); diff --git a/dfhack/include/modules/Items.h b/library/include/dfhack/modules/Items.h similarity index 94% rename from dfhack/include/modules/Items.h rename to library/include/dfhack/modules/Items.h index 99a6a9046..90db2bbf6 100644 --- a/dfhack/include/modules/Items.h +++ b/library/include/dfhack/modules/Items.h @@ -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); diff --git a/dfhack/include/modules/Maps.h b/library/include/dfhack/modules/Maps.h similarity index 98% rename from dfhack/include/modules/Maps.h rename to library/include/dfhack/modules/Maps.h index 1a42fb480..cfdb31d43 100644 --- a/dfhack/include/modules/Maps.h +++ b/library/include/dfhack/modules/Maps.h @@ -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,10 +300,9 @@ namespace DFHack bool ReadGeology( std::vector < std::vector >& assign ); std::vector global_features; // map between feature address and the read object - std::map local_feature_store; - // map between mangled coords and pointer to feature - - + std::map local_feature_store; + // map between mangled coords and pointer to feature + bool ReadGlobalFeatures( std::vector & features); bool ReadLocalFeatures( std::map > & local_features ); /* diff --git a/dfhack/include/modules/Materials.h b/library/include/dfhack/modules/Materials.h similarity index 97% rename from dfhack/include/modules/Materials.h rename to library/include/dfhack/modules/Materials.h index 73641e10c..af2e16941 100644 --- a/dfhack/include/modules/Materials.h +++ b/library/include/dfhack/modules/Materials.h @@ -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 inorganic; diff --git a/dfhack/include/modules/Position.h b/library/include/dfhack/modules/Position.h similarity index 91% rename from dfhack/include/modules/Position.h rename to library/include/dfhack/modules/Position.h index 8ecf5bae6..b70387e66 100644 --- a/dfhack/include/modules/Position.h +++ b/library/include/dfhack/modules/Position.h @@ -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 diff --git a/dfhack/include/modules/Translation.h b/library/include/dfhack/modules/Translation.h similarity index 88% rename from dfhack/include/modules/Translation.h rename to library/include/dfhack/modules/Translation.h index 7027df61e..a7e186990 100644 --- a/dfhack/include/modules/Translation.h +++ b/library/include/dfhack/modules/Translation.h @@ -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 > 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(); diff --git a/dfhack/include/modules/Vegetation.h b/library/include/dfhack/modules/Vegetation.h similarity index 90% rename from dfhack/include/modules/Vegetation.h rename to library/include/dfhack/modules/Vegetation.h index 9408c9c0b..b81bb81c1 100644 --- a/dfhack/include/modules/Vegetation.h +++ b/library/include/dfhack/modules/Vegetation.h @@ -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); diff --git a/dfhack/include/DFWindow.h b/library/include/dfhack/modules/WindowIO.h similarity index 91% rename from dfhack/include/DFWindow.h rename to library/include/dfhack/modules/WindowIO.h index 99e5f37ba..146029ca0 100644 --- a/dfhack/include/DFWindow.h +++ b/library/include/dfhack/modules/WindowIO.h @@ -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); }; diff --git a/dfhack/include/modules/World.h b/library/include/dfhack/modules/World.h similarity index 83% rename from dfhack/include/modules/World.h rename to library/include/dfhack/modules/World.h index 6c3c12a4a..21300bfd5 100644 --- a/dfhack/include/modules/World.h +++ b/library/include/dfhack/modules/World.h @@ -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(); diff --git a/dfhack/modules/Buildings.cpp b/library/modules/Buildings.cpp similarity index 93% rename from dfhack/modules/Buildings.cpp rename to library/modules/Buildings.cpp index 33eb59e44..5d55163b3 100644 --- a/dfhack/modules/Buildings.cpp +++ b/library/modules/Buildings.cpp @@ -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 * 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_; diff --git a/dfhack/modules/Buildings_C.cpp b/library/modules/Buildings_C.cpp similarity index 90% rename from dfhack/modules/Buildings_C.cpp rename to library/modules/Buildings_C.cpp index 1c6631e38..18bd77922 100644 --- a/dfhack/modules/Buildings_C.cpp +++ b/library/modules/Buildings_C.cpp @@ -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 #include #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; diff --git a/dfhack/modules/Constructions.cpp b/library/modules/Constructions.cpp similarity index 88% rename from dfhack/modules/Constructions.cpp rename to library/modules/Constructions.cpp index 655bca6e1..535098fc5 100644 --- a/dfhack/modules/Constructions.cpp +++ b/library/modules/Constructions.cpp @@ -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 * 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_; diff --git a/dfhack/modules/Constructions_C.cpp b/library/modules/Constructions_C.cpp similarity index 85% rename from dfhack/modules/Constructions_C.cpp rename to library/modules/Constructions_C.cpp index 3b19b679e..93afdae01 100644 --- a/dfhack/modules/Constructions_C.cpp +++ b/library/modules/Constructions_C.cpp @@ -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; diff --git a/dfhack/modules/Creatures.cpp b/library/modules/Creatures.cpp similarity index 97% rename from dfhack/modules/Creatures.cpp rename to library/modules/Creatures.cpp index c083f5d8d..b7e39a95f 100644 --- a/dfhack/modules/Creatures.cpp +++ b/library/modules/Creatures.cpp @@ -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 #include #include -#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 *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(); diff --git a/dfhack/modules/Creatures_C.cpp b/library/modules/Creatures_C.cpp similarity index 89% rename from dfhack/modules/Creatures_C.cpp rename to library/modules/Creatures_C.cpp index 9b0624da3..1aac93110 100644 --- a/dfhack/modules/Creatures_C.cpp +++ b/library/modules/Creatures_C.cpp @@ -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 #include #include 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; diff --git a/dfhack/modules/Gui.cpp b/library/modules/Gui.cpp similarity index 91% rename from dfhack/modules/Gui.cpp rename to library/modules/Gui.cpp index c113c05bc..f017a04f3 100644 --- a/dfhack/modules/Gui.cpp +++ b/library/modules/Gui.cpp @@ -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; diff --git a/dfhack/modules/Gui_C.cpp b/library/modules/Gui_C.cpp similarity index 83% rename from dfhack/modules/Gui_C.cpp rename to library/modules/Gui_C.cpp index 8a8dc185d..586eb1dd0 100644 --- a/dfhack/modules/Gui_C.cpp +++ b/library/modules/Gui_C.cpp @@ -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 +#include +#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) { diff --git a/dfhack/modules/Items.cpp b/library/modules/Items.cpp similarity index 95% rename from dfhack/modules/Items.cpp rename to library/modules/Items.cpp index c01de5b0b..66e2720ac 100644 --- a/dfhack/modules/Items.cpp +++ b/library/modules/Items.cpp @@ -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_; diff --git a/dfhack/modules/Items_C.cpp b/library/modules/Items_C.cpp similarity index 75% rename from dfhack/modules/Items_C.cpp rename to library/modules/Items_C.cpp index a28b3f86a..3ac54c46a 100644 --- a/dfhack/modules/Items_C.cpp +++ b/library/modules/Items_C.cpp @@ -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 +#include #include +#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) { diff --git a/dfhack/modules/Maps.cpp b/library/modules/Maps.cpp similarity index 97% rename from dfhack/modules/Maps.cpp rename to library/modules/Maps.cpp index 6b8a7c51a..af0a8be9b 100644 --- a/dfhack/modules/Maps.cpp +++ b/library/modules/Maps.cpp @@ -22,16 +22,16 @@ must not be misrepresented as being the original software. distribution. */ -#include "DFCommonInternal.h" +#include "Internal.h" #include #include #include -#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 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 > & 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 & 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 p_features (p,global_feature_vector); features.clear(); diff --git a/dfhack/modules/Maps_C.cpp b/library/modules/Maps_C.cpp similarity index 96% rename from dfhack/modules/Maps_C.cpp rename to library/modules/Maps_C.cpp index d6a64daa4..ccac26447 100644 --- a/dfhack/modules/Maps_C.cpp +++ b/library/modules/Maps_C.cpp @@ -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 #include #include 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; diff --git a/dfhack/modules/Materials.cpp b/library/modules/Materials.cpp similarity index 86% rename from dfhack/modules/Materials.cpp rename to library/modules/Materials.cpp index 417b5a53c..3567bb0d0 100644 --- a/dfhack/modules/Materials.cpp +++ b/library/modules/Materials.cpp @@ -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 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 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 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 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) diff --git a/dfhack/modules/Materials_C.cpp b/library/modules/Materials_C.cpp similarity index 65% rename from dfhack/modules/Materials_C.cpp rename to library/modules/Materials_C.cpp index a78a8dab4..dee99fbaa 100644 --- a/dfhack/modules/Materials_C.cpp +++ b/library/modules/Materials_C.cpp @@ -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 #include #include 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; +c_creaturetype* Materials_getRaceEx(DFHackObject* mat) +{ + if(mat != NULL) + { + DFHack::Materials* materials = (DFHack::Materials*)mat; + int matSize = materials->raceEx.size(); - // if(materials->raceEx.size() > 0) - // { - // std::vector 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)); + if(matSize > 0) + { + c_creaturetype* buf = ((*alloc_creaturetype_buffer_callback)(matSize)); - // for(int i = 0; i < typessize; i++) - // { - // t_creaturetype current = types[i]; - - // strncpy(buf[i].rawname, current.rawname, 128); - // buf[i].rawname[127] = '\0'; - - // buf[i].tile_character = current.tile_character; - // buf[i].tilecolor = current.tilecolor; + if(buf != NULL) + { + for(int i = 0; i < matSize; i++) + CreatureTypeConvert(&materials->raceEx[i], &buf[i]); - // current.extract.copy(buf[i].extract, current.extract.size()); - // } - - // 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 diff --git a/dfhack/modules/Position.cpp b/library/modules/Position.cpp similarity index 91% rename from dfhack/modules/Position.cpp rename to library/modules/Position.cpp index 3fd867fd2..0d3ae1819 100644 --- a/dfhack/modules/Position.cpp +++ b/library/modules/Position.cpp @@ -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; @@ -39,22 +36,20 @@ struct Position::Private uint32_t window_z_offset; uint32_t cursor_xyz_offset; uint32_t window_dims_offset; - + uint32_t hotkey_start; uint32_t hotkey_mode_offset; 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 v_geology[eBiomeCount]; }; -Position::Position(APIPrivate * d_) +Position::Position(DFContextShared * d_) { d = new Private; d->d = d_; @@ -71,7 +66,7 @@ Position::Position(APIPrivate * d_) d->cursor_xyz_offset = mem->getAddress ("cursor_xyz"); d->window_dims_offset = mem->getAddress ("window_dims"); d->Started = true; - + d->hotkey_start = mem->getAddress("hotkey_start"); d->hotkey_mode_offset = mem->getOffset ("hotkey_mode"); d->hotkey_xyz_offset = mem->getOffset("hotkey_xyz"); @@ -88,10 +83,13 @@ 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; - + for(uint32_t i = 0 ; i < NUM_HOTKEYS ;i++) { p->readSTLString(currHotkey,hotkeys[i].name,10); @@ -106,7 +104,7 @@ bool Position::getViewCoords (int32_t &x, int32_t &y, int32_t &z) { if (!d->Inited) return false; Process * p = d->owner; - + p->readDWord (d->window_x_offset, (uint32_t &) x); p->readDWord (d->window_y_offset, (uint32_t &) y); p->readDWord (d->window_z_offset, (uint32_t &) z); @@ -116,9 +114,12 @@ 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); p->writeDWord (d->window_y_offset, (uint32_t) y); p->writeDWord (d->window_z_offset, (uint32_t) z); @@ -149,7 +150,7 @@ bool Position::setCursorCoords (const int32_t x, const int32_t y, const int32_t bool Position::getWindowSize (int32_t &width, int32_t &height) { if(!d->Inited) return false; - + int32_t coords[2]; d->owner->read (d->window_dims_offset, 2*sizeof (int32_t), (uint8_t *) coords); width = coords[0]; diff --git a/dfhack/modules/Position_C.cpp b/library/modules/Position_C.cpp similarity index 94% rename from dfhack/modules/Position_C.cpp rename to library/modules/Position_C.cpp index 79b63e708..72405d9b7 100644 --- a/dfhack/modules/Position_C.cpp +++ b/library/modules/Position_C.cpp @@ -22,11 +22,13 @@ must not be misrepresented as being the original software. distribution. */ -#include "modules/Position_C.h" -#include "integers.h" +#include +#include +#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; diff --git a/dfhack/modules/Translation.cpp b/library/modules/Translation.cpp similarity index 95% rename from dfhack/modules/Translation.cpp rename to library/modules/Translation.cpp index c59a92b57..80412c690 100644 --- a/dfhack/modules/Translation.cpp +++ b/library/modules/Translation.cpp @@ -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_; diff --git a/dfhack/modules/Translation_C.cpp b/library/modules/Translation_C.cpp similarity index 90% rename from dfhack/modules/Translation_C.cpp rename to library/modules/Translation_C.cpp index 017fb092e..e84e04c2a 100644 --- a/dfhack/modules/Translation_C.cpp +++ b/library/modules/Translation_C.cpp @@ -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 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; diff --git a/dfhack/modules/Vegetation.cpp b/library/modules/Vegetation.cpp similarity index 87% rename from dfhack/modules/Vegetation.cpp rename to library/modules/Vegetation.cpp index 72cbe1d41..6038e4d53 100644 --- a/dfhack/modules/Vegetation.cpp +++ b/library/modules/Vegetation.cpp @@ -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/Vegetation.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/Vegetation.h" +#include "dfhack/modules/Translation.h" using namespace DFHack; @@ -40,13 +41,13 @@ struct Vegetation::Private // translation DfVector * p_veg; - APIPrivate *d; + DFContextShared *d; Process * owner; bool Inited; bool Started; }; -Vegetation::Vegetation(APIPrivate * d_) +Vegetation::Vegetation(DFContextShared * d_) { d = new Private; d->owner = d_->p; diff --git a/dfhack/modules/Vegetation_C.cpp b/library/modules/Vegetation_C.cpp similarity index 84% rename from dfhack/modules/Vegetation_C.cpp rename to library/modules/Vegetation_C.cpp index a3ced1ab8..0a919c070 100644 --- a/dfhack/modules/Vegetation_C.cpp +++ b/library/modules/Vegetation_C.cpp @@ -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,11 +22,11 @@ must not be misrepresented as being the original software. distribution. */ -#include "integers.h" -#include "DFCommonInternal.h" -#include "DFTypes.h" -#include "modules/Vegetation.h" -#include "modules/Vegetation_C.h" +#include "dfhack/DFIntegers.h" +#include "Internal.h" +#include "dfhack/DFTypes.h" +#include "dfhack/modules/Vegetation.h" +#include "dfhack-c/modules/Vegetation_C.h" using namespace DFHack; diff --git a/dfhack/DFWindow-linux.cpp b/library/modules/WindowIO-linux.cpp similarity index 93% rename from dfhack/DFWindow-linux.cpp rename to library/modules/WindowIO-linux.cpp index bffe99de6..b8ff0cd13 100644 --- a/dfhack/DFWindow-linux.cpp +++ b/library/modules/WindowIO-linux.cpp @@ -21,11 +21,12 @@ 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 "DFWindow.h" +#include "Internal.h" +#include "dfhack/modules/WindowIO.h" #include //need for X11 functions #include +#include using namespace DFHack; @@ -84,7 +85,7 @@ const static KeySym ksTable[NUM_SPECIALS]= XK_KP_Decimal }; -class DFWindow::Private +class WindowIO::Private { public: Private(Process * _p) @@ -111,18 +112,18 @@ class DFWindow::Private }; // ctor -DFWindow::DFWindow (Process * p) +WindowIO::WindowIO (DFContextShared * csh) { - d = new Private(p); + d = new Private(csh->p); } // dtor -DFWindow::~DFWindow () +WindowIO::~WindowIO () { delete d; } -Window DFWindow::Private::EnumerateWindows (Display *display, Window rootWindow, const char *searchString) +Window WindowIO::Private::EnumerateWindows (Display *display, Window rootWindow, const char *searchString) { Window parent; Window *children; @@ -161,7 +162,7 @@ Window DFWindow::Private::EnumerateWindows (Display *display, Window rootWindow, return retWindow; } -bool DFWindow::Private::getDFWindow (Display *dpy, Window& dfWindow, Window & rootWindow) +bool WindowIO::Private::getDFWindow (Display *dpy, Window& dfWindow, Window & rootWindow) { // int numScreeens = ScreenCount(dpy); for (int i = 0;i < ScreenCount (dpy);i++) @@ -177,7 +178,7 @@ bool DFWindow::Private::getDFWindow (Display *dpy, Window& dfWindow, Window & ro return false; } -void DFWindow::Private::send_xkeyevent(Display *display, Window dfW,Window rootW, int keycode, int modstate, int is_press, useconds_t delay) +void WindowIO::Private::send_xkeyevent(Display *display, Window dfW,Window rootW, int keycode, int modstate, int is_press, useconds_t delay) { XKeyEvent event; @@ -199,7 +200,7 @@ void DFWindow::Private::send_xkeyevent(Display *display, Window dfW,Window rootW usleep(delay); } -void DFWindow::TypeStr (const char *input, int delay, bool useShift) +void WindowIO::TypeStr (const char *input, int delay, bool useShift) { Display *dpy = XOpenDisplay (NULL); // null opens the display in $DISPLAY Window dfWin; @@ -234,7 +235,7 @@ void DFWindow::TypeStr (const char *input, int delay, bool useShift) } } -void DFWindow::TypeSpecial (t_special command, int count, int delay) +void WindowIO::TypeSpecial (t_special command, int count, int delay) { if (command != WAIT) { diff --git a/dfhack/DFWindow-windows.cpp b/library/modules/WindowIO-windows.cpp similarity index 92% rename from dfhack/DFWindow-windows.cpp rename to library/modules/WindowIO-windows.cpp index 78e4ffc62..37c5eb08c 100644 --- a/dfhack/DFWindow-windows.cpp +++ b/library/modules/WindowIO-windows.cpp @@ -22,9 +22,10 @@ must not be misrepresented as being the original software. distribution. */ -#include "DFCommonInternal.h" -#include "DFWindow.h" -#include "DFProcess.h" +#include "Internal.h" +#include "ContextShared.h" +#include "dfhack/modules/WindowIO.h" +#include "dfhack/DFProcess.h" using namespace DFHack; // should always reflect the enum in DFkeys.h @@ -101,7 +102,7 @@ BOOL CALLBACK EnumWindowsProc (HWND hwnd, LPARAM lParam) return TRUE; } -class DFWindow::Private +class WindowIO::Private { public: Private(Process * _p) @@ -114,19 +115,19 @@ class DFWindow::Private }; // ctor -DFWindow::DFWindow (Process * p) +WindowIO::WindowIO (DFContextShared * schr) { - d = new Private(p); + d = new Private(schr->p); } // dtor -DFWindow::~DFWindow () +WindowIO::~WindowIO () { delete d; } // TODO: also investigate possible problems with UIPI on Vista and 7 -void DFWindow::TypeStr (const char *input, int delay, bool useShift) +void WindowIO::TypeStr (const char *input, int delay, bool useShift) { //sendmessage needs a window handle HWND, so have to get that from the process HANDLE HWND currentWindow = GetForegroundWindow(); @@ -163,7 +164,7 @@ void DFWindow::TypeStr (const char *input, int delay, bool useShift) Sleep (delay); } -void DFWindow::TypeSpecial (t_special command, int count, int delay) +void WindowIO::TypeSpecial (t_special command, int count, int delay) { if (command != WAIT) { diff --git a/dfhack/modules/World.cpp b/library/modules/World.cpp similarity index 91% rename from dfhack/modules/World.cpp rename to library/modules/World.cpp index fecb99712..47f4d200d 100644 --- a/dfhack/modules/World.cpp +++ b/library/modules/World.cpp @@ -34,12 +34,12 @@ FIXME: Japa said that he had to do this with the time stuff he got from here currentTickRel = (currentTick+9)-(((((currentMonth*28)+currentDay)*24)+currentHour)*50); */ -#include "DFCommonInternal.h" -#include "../private/APIPrivate.h" -#include "modules/World.h" -#include "DFProcess.h" -#include "DFMemInfo.h" -#include "DFTypes.h" +#include "Internal.h" +#include "ContextShared.h" +#include "dfhack/modules/World.h" +#include "dfhack/DFProcess.h" +#include "dfhack/DFMemInfo.h" +#include "dfhack/DFTypes.h" using namespace DFHack; @@ -49,11 +49,11 @@ struct World::Private bool Started; uint32_t year_offset; uint32_t tick_offset; - APIPrivate *d; + DFContextShared *d; Process * owner; }; -World::World(APIPrivate * _d) +World::World(DFContextShared * _d) { d = new Private; diff --git a/dfhack/private/APIPrivate.h b/library/private/ContextShared.h similarity index 95% rename from dfhack/private/APIPrivate.h rename to library/private/ContextShared.h index 12e11aa0d..f3c506880 100644 --- a/dfhack/private/APIPrivate.h +++ b/library/private/ContextShared.h @@ -42,15 +42,16 @@ namespace DFHack class Buildings; class ProcessEnumerator; class Process; + class WindowIO; class Vegetation; class Constructions; class memory_info; struct t_name; - class APIPrivate + class DFContextShared { public: - APIPrivate(); - ~APIPrivate(); + DFContextShared(); + ~DFContextShared(); // names, used by a few other modules. void readName(t_name & name, uint32_t address); @@ -79,6 +80,7 @@ namespace DFHack Vegetation * vegetation; Buildings * buildings; Constructions * constructions; + WindowIO * windowio; /* uint32_t item_material_offset; diff --git a/dfhack/include/DFCommonInternal.h b/library/private/Internal.h similarity index 95% rename from dfhack/include/DFCommonInternal.h rename to library/private/Internal.h index 92a43c3b5..3f5d561fa 100644 --- a/dfhack/include/DFCommonInternal.h +++ b/library/private/Internal.h @@ -25,7 +25,7 @@ distribution. #ifndef DFCOMMONINTERNAL_H_INCLUDED #define DFCOMMONINTERNAL_H_INCLUDED -// this makes everything that includes this file export symbols when using DFHACK_EXPORT (see Export.h) +// this makes everything that includes this file export symbols when using DFHACK_EXPORT (see DFExport.h) #ifndef BUILD_DFHACK_LIB #define BUILD_DFHACK_LIB #endif @@ -41,10 +41,10 @@ distribution. #endif // one file for globals -#include "DFGlobal.h" +#include "dfhack/DFGlobal.h" // one file for telling the MSVC compiler where it can shove its pointless warnings -#include "Tranquility.h" +#include "dfhack/DFPragma.h" // basic stl containers and IO stuff #include @@ -55,7 +55,7 @@ distribution. using namespace std; // C99 integer types -#include "integers.h" +#include "dfhack/DFIntegers.h" // C includes #include #include diff --git a/dfhack/python/CMakeLists.txt b/library/python/CMakeLists.txt similarity index 100% rename from dfhack/python/CMakeLists.txt rename to library/python/CMakeLists.txt diff --git a/dfhack/python/DF_API.cpp b/library/python/DF_API.cpp similarity index 99% rename from dfhack/python/DF_API.cpp rename to library/python/DF_API.cpp index 0965823dd..a65f8e065 100644 --- a/dfhack/python/DF_API.cpp +++ b/library/python/DF_API.cpp @@ -30,7 +30,7 @@ distribution. #include "integers.h" #include "DFTypes.h" -#include "DFHackAPI.h" +#include "DFContext.h" #include "DF_Imports.cpp" #include "DF_MemInfo.cpp" #include "DF_Position.cpp" @@ -68,7 +68,7 @@ struct DF_API PyObject* vegetation_type; PyObject* gui_type; - DFHack::API* api_Ptr; + DFHack::Context* api_Ptr; }; // API type Allocation, Deallocation, and Initialization @@ -110,7 +110,7 @@ static int DF_API_init(DF_API* self, PyObject* args, PyObject* kwds) return -1; if(memFileString) - self->api_Ptr = new DFHack::API(std::string(memFileString)); + self->api_Ptr = new DFHack::Context(std::string(memFileString)); else return -1; } diff --git a/dfhack/python/DF_Buildings.cpp b/library/python/DF_Buildings.cpp similarity index 99% rename from dfhack/python/DF_Buildings.cpp rename to library/python/DF_Buildings.cpp index 3bfaadd7a..2a1b9c51d 100644 --- a/dfhack/python/DF_Buildings.cpp +++ b/library/python/DF_Buildings.cpp @@ -28,7 +28,7 @@ distribution. #include "Python.h" #include #include -#include "integers.h" +#include "DFIntegers.h" using namespace std; diff --git a/dfhack/python/DF_Constructions.cpp b/library/python/DF_Constructions.cpp similarity index 100% rename from dfhack/python/DF_Constructions.cpp rename to library/python/DF_Constructions.cpp diff --git a/dfhack/python/DF_CreatureManager.cpp b/library/python/DF_CreatureManager.cpp similarity index 99% rename from dfhack/python/DF_CreatureManager.cpp rename to library/python/DF_CreatureManager.cpp index 6082b6263..b7071e804 100644 --- a/dfhack/python/DF_CreatureManager.cpp +++ b/library/python/DF_CreatureManager.cpp @@ -29,7 +29,7 @@ distribution. #include #include "stdio.h" #include -#include "integers.h" +#include "DFIntegers.h" #include "DFTypes.h" #include "modules/Materials.h" #include "modules/Creatures.h" diff --git a/dfhack/python/DF_CreatureType.cpp b/library/python/DF_CreatureType.cpp similarity index 100% rename from dfhack/python/DF_CreatureType.cpp rename to library/python/DF_CreatureType.cpp diff --git a/dfhack/python/DF_GUI.cpp b/library/python/DF_GUI.cpp similarity index 100% rename from dfhack/python/DF_GUI.cpp rename to library/python/DF_GUI.cpp diff --git a/dfhack/python/DF_Helpers.cpp b/library/python/DF_Helpers.cpp similarity index 100% rename from dfhack/python/DF_Helpers.cpp rename to library/python/DF_Helpers.cpp diff --git a/dfhack/python/DF_Imports.cpp b/library/python/DF_Imports.cpp similarity index 100% rename from dfhack/python/DF_Imports.cpp rename to library/python/DF_Imports.cpp diff --git a/dfhack/python/DF_Maps.cpp b/library/python/DF_Maps.cpp similarity index 100% rename from dfhack/python/DF_Maps.cpp rename to library/python/DF_Maps.cpp diff --git a/dfhack/python/DF_Material.cpp b/library/python/DF_Material.cpp similarity index 99% rename from dfhack/python/DF_Material.cpp rename to library/python/DF_Material.cpp index 97af851e2..75df503c6 100644 --- a/dfhack/python/DF_Material.cpp +++ b/library/python/DF_Material.cpp @@ -28,7 +28,7 @@ distribution. #include "Python.h" #include #include -#include "integers.h" +#include "DFIntegers.h" using namespace std; diff --git a/dfhack/python/DF_MemInfo.cpp b/library/python/DF_MemInfo.cpp similarity index 99% rename from dfhack/python/DF_MemInfo.cpp rename to library/python/DF_MemInfo.cpp index 16a830b41..b529af8da 100644 --- a/dfhack/python/DF_MemInfo.cpp +++ b/library/python/DF_MemInfo.cpp @@ -24,7 +24,7 @@ distribution. #ifndef __DF_MEMINFO__ #define __DF_MEMINFO__ -#include "Tranquility.h" +#include "DFPragma.h" #pragma GCC diagnostic ignored "-Wwrite-strings" #include "Python.h" @@ -32,8 +32,8 @@ distribution. using namespace std; -#include "Export.h" -#include "integers.h" +#include "DFExport.h" +#include "DFIntegers.h" #include "DFMemInfo.h" using namespace DFHack; diff --git a/dfhack/python/DF_Position.cpp b/library/python/DF_Position.cpp similarity index 100% rename from dfhack/python/DF_Position.cpp rename to library/python/DF_Position.cpp diff --git a/dfhack/python/DF_Translate.cpp b/library/python/DF_Translate.cpp similarity index 100% rename from dfhack/python/DF_Translate.cpp rename to library/python/DF_Translate.cpp diff --git a/dfhack/python/DF_Vegetation.cpp b/library/python/DF_Vegetation.cpp similarity index 99% rename from dfhack/python/DF_Vegetation.cpp rename to library/python/DF_Vegetation.cpp index ae8b6a016..748743a62 100644 --- a/dfhack/python/DF_Vegetation.cpp +++ b/library/python/DF_Vegetation.cpp @@ -26,7 +26,7 @@ distribution. #define __DFVEGETATION__ #include "Python.h" -#include "integers.h" +#include "DFIntegers.h" #include "modules/Vegetation.h" #include "DF_Helpers.cpp" diff --git a/dfhack/python/build-linux b/library/python/build-linux similarity index 100% rename from dfhack/python/build-linux rename to library/python/build-linux diff --git a/dfhack/python/build.bat b/library/python/build.bat similarity index 100% rename from dfhack/python/build.bat rename to library/python/build.bat diff --git a/dfhack/python/c api/buildings.py b/library/python/c api/buildings.py similarity index 100% rename from dfhack/python/c api/buildings.py rename to library/python/c api/buildings.py diff --git a/dfhack/python/c api/constructions.py b/library/python/c api/constructions.py similarity index 100% rename from dfhack/python/c api/constructions.py rename to library/python/c api/constructions.py diff --git a/library/python/c api/context.py b/library/python/c api/context.py new file mode 100644 index 000000000..592359f57 --- /dev/null +++ b/library/python/c api/context.py @@ -0,0 +1,195 @@ +from ctypes import * +from pydftypes import * + +libdfhack.ContextManager_Alloc.restype = c_void_p +libdfhack.ContextManager_Free.argtypes = [ c_void_p ] + +libdfhack.ContextManager_getContext.restype = c_void_p +libdfhack.ContextManager_getSingleContext.restype = c_void_p + +libdfhack.Context_Free.argtypes = [ c_void_p ] + +libdfhack.Context_getMemoryInfo.restype = c_void_p +libdfhack.Context_getProcess.restype = c_void_p +libdfhack.Context_getWindow.restype = c_void_p + +libdfhack.Context_getCreatures.restype = c_void_p +libdfhack.Context_getMaps.restype = c_void_p +libdfhack.Context_getGui.restype = c_void_p +libdfhack.Context_getPosition.restype = c_void_p +libdfhack.Context_getMaterials.restype = c_void_p +libdfhack.Context_getTranslation.restype = c_void_p +libdfhack.Context_getVegetation.restype = c_void_p +libdfhack.Context_getBuildings.restype = c_void_p +libdfhack.Context_getConstructions.restype = c_void_p +libdfhack.Context_getItems.restype = c_void_p + +class ContextManager(object): + def __init__(self, memory_path): + self._cm_ptr = libdfhack.ContextManager_Alloc(create_string_buffer(memory_path)) + + def __del__(self): + libdfhack.ContextManager_Free(self._cm_ptr) + + def refresh(self): + return libdfhack.ContextManager_Refresh(self._cm_ptr) > 0 + + def purge(self): + libdfhack.ContextManager_purge(self._cm_ptr) + + def get_context(self, index): + p = libdfhack.ContextManager_getContext(self._cm_ptr, index) + + if p: + return Context(p) + else: + return None + + def get_single_context(self): + p = libdfhack.ContextManager_getSingleContext(self._cm_ptr) + + if p: + return Context(p) + else: + return None + +class Context(object): + def __init__(self, ptr): + self._c_ptr = ptr + + self._pos_obj = None + self._mat_obj = None + self._map_obj = None + self._veg_obj = None + self._build_obj = None + self._con_obj = None + self._gui_obj = None + self._tran_obj = None + self._item_obj = None + self._creature_obj = None + + def __del__(self): + libdfhack.Context_Free(self._c_ptr) + + def attach(self): + return libdfhack.Context_Attach(self._c_ptr) > 0 + + def detach(self): + return libdfhack.Context_Detach(self._c_ptr) > 0 + + def suspend(self): + return libdfhack.Context_Suspend(self._c_ptr) > 0 + + def resume(self): + return libdfhack.Context_Resume(self._c_ptr) > 0 + + def force_resume(self): + return libdfhack.Context_ForceResume(self._c_ptr) > 0 + + def async_suspend(self): + return libdfhack.Context_AsyncSuspend(self._c_ptr) > 0 + + @property + def is_attached(self): + return libdfhack.Context_isAttached(self._c_ptr) > 0 + + @property + def is_suspended(self): + return libdfhack.Context_isSuspended(self._c_ptr) > 0 + + @property + def position(self): + import position + if self._pos_obj is None: + self._pos_obj = position.Position(libdfhack.Context_getPosition(self._c_ptr)) + + return self._pos_obj + + @property + def materials(self): + import materials + if self._mat_obj is None: + self._mat_obj = materials.Materials(libdfhack.Context_getMaterials(self._c_ptr)) + + return self._mat_obj + + @property + def maps(self): + import maps + if self._map_obj is None: + self._map_obj = maps.Maps(libdfhack.Context_getMaps(self._c_ptr)) + + return self._map_obj + + @property + def vegetation(self): + import vegetation + if self._veg_obj is None: + self._veg_obj = vegetation.Vegetation(libdfhack.Context_getVegetation(self._c_ptr)) + + return self._veg_obj + + @property + def buildings(self): + import buildings + if self._build_obj is None: + self._build_obj = buildings.Buildings(libdfhack.Context_getBuildings(self._c_ptr)) + + return self._build_obj + + @property + def creatures(self): + import creatures + if self._creature_obj is None: + self._creature_obj = creatures.Creatures(libdfhack.Context_getCreatures(self._c_ptr)) + + return self._creature_obj + + @property + def gui(self): + import gui + if self._gui_obj is None: + self._gui_obj = gui.Gui(libdfhack.Context_getGui(self._c_ptr)) + + return self._gui_obj + + @property + def items(self): + import items + if self._item_obj is None: + self._item_obj = items.Items(libdfhack.Context_getItems(self._c_ptr)) + + return self._item_obj + + @property + def translation(self): + import translation + if self._tran_obj is None: + self._tran_obj = translation.Translation(libdfhack.Context_getTranslation(self._c_ptr)) + + return self._tran_obj + +def reveal(): + df = API("Memory.xml") + df.attach() + + m = df.maps + + m.start() + + m_x, m_y, m_z = m.size + + for x in xrange(m_x): + for y in xrange(m_y): + for z in xrange(m_z): + if m.is_valid_block(x, y, z): + d = m.read_designations(x, y, z) + + for i in d: + for j in i: + j.bits.hidden = 0 + + m.write_designations(x, y, z, d) + + m.finish() + df.detach() diff --git a/dfhack/python/c api/creatures.py b/library/python/c api/creatures.py similarity index 100% rename from dfhack/python/c api/creatures.py rename to library/python/c api/creatures.py diff --git a/dfhack/python/c api/dfhack_api_ctypes.py b/library/python/c api/dfhack_api_ctypes.py similarity index 100% rename from dfhack/python/c api/dfhack_api_ctypes.py rename to library/python/c api/dfhack_api_ctypes.py diff --git a/dfhack/python/c api/enum.py b/library/python/c api/enum.py similarity index 100% rename from dfhack/python/c api/enum.py rename to library/python/c api/enum.py diff --git a/dfhack/python/c api/gui.py b/library/python/c api/gui.py similarity index 100% rename from dfhack/python/c api/gui.py rename to library/python/c api/gui.py diff --git a/dfhack/python/c api/items.py b/library/python/c api/items.py similarity index 100% rename from dfhack/python/c api/items.py rename to library/python/c api/items.py diff --git a/dfhack/python/c api/maps.py b/library/python/c api/maps.py similarity index 100% rename from dfhack/python/c api/maps.py rename to library/python/c api/maps.py diff --git a/dfhack/python/c api/materials.py b/library/python/c api/materials.py similarity index 100% rename from dfhack/python/c api/materials.py rename to library/python/c api/materials.py diff --git a/dfhack/python/c api/position.py b/library/python/c api/position.py similarity index 100% rename from dfhack/python/c api/position.py rename to library/python/c api/position.py diff --git a/dfhack/python/c api/pydfhackflags.py b/library/python/c api/pydfhackflags.py similarity index 100% rename from dfhack/python/c api/pydfhackflags.py rename to library/python/c api/pydfhackflags.py diff --git a/dfhack/python/c api/pydftypes.py b/library/python/c api/pydftypes.py similarity index 83% rename from dfhack/python/c api/pydftypes.py rename to library/python/c api/pydftypes.py index 479dafe1a..78a90e57f 100644 --- a/dfhack/python/c api/pydftypes.py +++ b/library/python/c api/pydftypes.py @@ -1,10 +1,18 @@ from ctypes import * -from collections import namedtuple from pydfhackflags import * from enum import * +from util import * libdfhack = cdll.libdfhack +libdfhack.alloc_byte_buffer_callback = alloc_byte_buffer +libdfhack.alloc_ubyte_buffer_callback = alloc_ubyte_buffer +libdfhack.alloc_short_buffer_callback = alloc_short_buffer +libdfhack.alloc_ushort_buffer_callback = alloc_ushort_buffer +libdfhack.alloc_int_buffer_callback = alloc_int_buffer +libdfhack.alloc_uint_buffer_callback = alloc_uint_buffer +libdfhack.alloc_char_buffer_callback = alloc_char_buffer + int_ptr = POINTER(c_int) uint_ptr = POINTER(c_uint) @@ -79,6 +87,13 @@ class Matgloss(Structure): ("bright", c_byte), ("name", c_char * 128)] +def _alloc_matgloss_buffer_callback(count): + allocated = _allocate_array(Matgloss, count) + + return allocated[1] + +libdfhack.alloc_matgloss_buffer_callback = CFUNCTYPE(POINTER(Matgloss), c_int)(_alloc_matgloss_buffer_callback) + class MatglossPair(Structure): _fields_ = [("type", c_short), ("index", c_int)] @@ -90,9 +105,23 @@ class DescriptorColor(Structure): ("b", c_float), ("name", c_char * 128)] +def _alloc_descriptor_buffer_callback(count): + allocated = _allocate_array(DescriptorColor, count) + + return allocated[1] + +libdfhack.alloc_descriptor_buffer_callback = CFUNCTYPE(POINTER(DescriptorColor), c_int)(_alloc_descriptor_buffer_callback) + class MatglossOther(Structure): _fields_ = [("rawname", c_char * 128)] +def _alloc_matgloss_other_buffer_callback(count): + allocated = _allocate_array(MatglossOther, count) + + return allocated[1] + +libdfhack.alloc_matgloss_other_buffer_callback = CFUNCTYPE(POINTER(MatglossOther), c_int)(_alloc_matgloss_other_buffer_callback) + class Building(Structure): _fields_ = [("origin", c_uint), ("vtable", c_uint), @@ -256,3 +285,19 @@ class BodyPart(Structure): ("category", (c_char * 128)), ("single", (c_char * 128)), ("plural", (c_char * 128))] + +class ColorModifier(Structure): + _fields_ = [("part", (c_char * 128)), + ("colorlist", POINTER(c_uint)), + ("colorlistLength", c_uint)] + + def __init__(self): + self.part[0] = '\0' + self.colorlistLength = 0 + +ColorModifierPtr = POINTER(ColorModifier) + +def _alloc_empty_colormodifier_callback(): + return ColorModifierPtr(ColorModifier()) + +libdfhack.alloc_empty_colormodifier_callback = CFUNCTYPE(ColorModifierPtr)(_alloc_empty_colormodifier_callback) diff --git a/library/python/c api/util.py b/library/python/c api/util.py new file mode 100644 index 000000000..4f3f06958 --- /dev/null +++ b/library/python/c api/util.py @@ -0,0 +1,66 @@ +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) + +def _alloc_int_buffer(count): + a = _allocate_array(c_int, count) + + return a[1] + +alloc_int_buffer = CFUNCTYPE(POINTER(c_int), c_uint)(_alloc_int_buffer) + +def _alloc_uint_buffer(count): + a = _allocate_array(c_uint, count) + + return a[1] + +alloc_uint_buffer = CFUNCTYPE(POINTER(c_uint), c_uint)(_alloc_uint_buffer) + +def _alloc_short_buffer(count): + a = _allocate_array(c_short, count) + + return a[1] + +alloc_short_buffer = CFUNCTYPE(POINTER(c_short), c_uint)(_alloc_short_buffer) + +def _alloc_ushort_buffer(count): + a = _allocate_array(c_ushort, count) + + return a[1] + +alloc_ushort_buffer = CFUNCTYPE(POINTER(c_ushort), c_uint)(_alloc_ushort_buffer) + +def _alloc_byte_buffer(count): + a = _allocate_array(c_byte, count) + + return a[1] + +alloc_byte_buffer = CFUNCTYPE(POINTER(c_byte), c_uint)(_alloc_byte_buffer) + +def _alloc_ubyte_buffer(count): + a = _allocate_array(c_ubyte, count) + + return a[1] + +alloc_ubyte_buffer = CFUNCTYPE(POINTER(c_ubyte), c_uint)(_alloc_ubyte_buffer) + +def _alloc_char_buffer(count): + c = create_string_buffer(count) + + ptr = c_void_p() + ptr = addressof(c) + + return ptr + +alloc_char_buffer = CFUNCTYPE(POINTER(c_char), c_uint)(_alloc_char_buffer) diff --git a/dfhack/python/c api/vegetation.py b/library/python/c api/vegetation.py similarity index 100% rename from dfhack/python/c api/vegetation.py rename to library/python/c api/vegetation.py diff --git a/dfhack/python/dfhack_api_ctypes.py b/library/python/dfhack_api_ctypes.py similarity index 100% rename from dfhack/python/dfhack_api_ctypes.py rename to library/python/dfhack_api_ctypes.py diff --git a/dfhack/python/examples/attachtest.py b/library/python/examples/attachtest.py similarity index 100% rename from dfhack/python/examples/attachtest.py rename to library/python/examples/attachtest.py diff --git a/dfhack/python/examples/miscutils.py b/library/python/examples/miscutils.py similarity index 100% rename from dfhack/python/examples/miscutils.py rename to library/python/examples/miscutils.py diff --git a/dfhack/python/examples/position.py b/library/python/examples/position.py similarity index 100% rename from dfhack/python/examples/position.py rename to library/python/examples/position.py diff --git a/dfhack/python/examples/settlementdump.py b/library/python/examples/settlementdump.py similarity index 100% rename from dfhack/python/examples/settlementdump.py rename to library/python/examples/settlementdump.py diff --git a/dfhack/python/examples/suspendtest.py b/library/python/examples/suspendtest.py similarity index 100% rename from dfhack/python/examples/suspendtest.py rename to library/python/examples/suspendtest.py diff --git a/dfhack/python/examples/treedump.py b/library/python/examples/treedump.py similarity index 100% rename from dfhack/python/examples/treedump.py rename to library/python/examples/treedump.py diff --git a/dfhack/python/ez_setup.py b/library/python/ez_setup.py similarity index 100% rename from dfhack/python/ez_setup.py rename to library/python/ez_setup.py diff --git a/dfhack/python/linsetup.py b/library/python/linsetup.py similarity index 100% rename from dfhack/python/linsetup.py rename to library/python/linsetup.py diff --git a/dfhack/python/pydfhack.cpp b/library/python/pydfhack.cpp similarity index 100% rename from dfhack/python/pydfhack.cpp rename to library/python/pydfhack.cpp diff --git a/dfhack/python/pydfhack/__init__.py b/library/python/pydfhack/__init__.py similarity index 100% rename from dfhack/python/pydfhack/__init__.py rename to library/python/pydfhack/__init__.py diff --git a/dfhack/python/pydfhack/blocks.py b/library/python/pydfhack/blocks.py similarity index 100% rename from dfhack/python/pydfhack/blocks.py rename to library/python/pydfhack/blocks.py diff --git a/dfhack/python/pydfhack/construction.py b/library/python/pydfhack/construction.py similarity index 100% rename from dfhack/python/pydfhack/construction.py rename to library/python/pydfhack/construction.py diff --git a/dfhack/python/pydfhack/creature.py b/library/python/pydfhack/creature.py similarity index 100% rename from dfhack/python/pydfhack/creature.py rename to library/python/pydfhack/creature.py diff --git a/dfhack/python/pydfhack/decorators.py b/library/python/pydfhack/decorators.py similarity index 100% rename from dfhack/python/pydfhack/decorators.py rename to library/python/pydfhack/decorators.py diff --git a/dfhack/python/pydfhack/gui.py b/library/python/pydfhack/gui.py similarity index 100% rename from dfhack/python/pydfhack/gui.py rename to library/python/pydfhack/gui.py diff --git a/dfhack/python/pydfhack/map.py b/library/python/pydfhack/map.py similarity index 100% rename from dfhack/python/pydfhack/map.py rename to library/python/pydfhack/map.py diff --git a/dfhack/python/pydfhack/materials.py b/library/python/pydfhack/materials.py similarity index 100% rename from dfhack/python/pydfhack/materials.py rename to library/python/pydfhack/materials.py diff --git a/dfhack/python/pydfhack/meminfo.py b/library/python/pydfhack/meminfo.py similarity index 100% rename from dfhack/python/pydfhack/meminfo.py rename to library/python/pydfhack/meminfo.py diff --git a/dfhack/python/pydfhack/mixins.py b/library/python/pydfhack/mixins.py similarity index 100% rename from dfhack/python/pydfhack/mixins.py rename to library/python/pydfhack/mixins.py diff --git a/dfhack/python/pydfhack/position.py b/library/python/pydfhack/position.py similarity index 100% rename from dfhack/python/pydfhack/position.py rename to library/python/pydfhack/position.py diff --git a/dfhack/python/pydfhack/pydfapi.py b/library/python/pydfhack/pydfapi.py similarity index 100% rename from dfhack/python/pydfhack/pydfapi.py rename to library/python/pydfhack/pydfapi.py diff --git a/dfhack/python/pydfhack/pydfhackflags.py b/library/python/pydfhack/pydfhackflags.py similarity index 100% rename from dfhack/python/pydfhack/pydfhackflags.py rename to library/python/pydfhack/pydfhackflags.py diff --git a/dfhack/python/pydfhack/pydftypes.py b/library/python/pydfhack/pydftypes.py similarity index 100% rename from dfhack/python/pydfhack/pydftypes.py rename to library/python/pydfhack/pydftypes.py diff --git a/dfhack/python/pydfhack/translation.py b/library/python/pydfhack/translation.py similarity index 100% rename from dfhack/python/pydfhack/translation.py rename to library/python/pydfhack/translation.py diff --git a/dfhack/python/pydfhack/vegetation.py b/library/python/pydfhack/vegetation.py similarity index 100% rename from dfhack/python/pydfhack/vegetation.py rename to library/python/pydfhack/vegetation.py diff --git a/dfhack/python/setup.py b/library/python/setup.py similarity index 100% rename from dfhack/python/setup.py rename to library/python/setup.py diff --git a/dfhack/python/test.py b/library/python/test.py similarity index 100% rename from dfhack/python/test.py rename to library/python/test.py diff --git a/dfhack/python/tools/shell.py b/library/python/tools/shell.py similarity index 100% rename from dfhack/python/tools/shell.py rename to library/python/tools/shell.py diff --git a/dfhack/python/tools/trees.py b/library/python/tools/trees.py similarity index 100% rename from dfhack/python/tools/trees.py rename to library/python/tools/trees.py diff --git a/dfhack/shm/mod-core.cpp b/library/shm/mod-core.cpp similarity index 98% rename from dfhack/shm/mod-core.cpp rename to library/shm/mod-core.cpp index 6a4397d1f..2fd54d6e9 100644 --- a/dfhack/shm/mod-core.cpp +++ b/library/shm/mod-core.cpp @@ -27,7 +27,7 @@ distribution. */ #include -#include "../library/integers.h" +#include "dfhack/DFIntegers.h" #include #include #include @@ -247,8 +247,8 @@ void InitModules (void) { // create the core module module_registry.push_back(InitCore()); - module_registry.push_back(DFHack::Maps::Init()); - module_registry.push_back(DFHack::Creatures::Init()); + module_registry.push_back(DFHack::Server::Maps::Init()); + //module_registry.push_back(DFHack::Server::Creatures::Init()); for(int i = 0; i < module_registry.size();i++) { fprintf(stderr,"Initialized module %s, version %d\n",module_registry[i].name.c_str(),module_registry[i].version); diff --git a/dfhack/shm/mod-core.h b/library/shm/mod-core.h similarity index 100% rename from dfhack/shm/mod-core.h rename to library/shm/mod-core.h diff --git a/dfhack/shm/mod-creature2010.h b/library/shm/mod-creature2010.h similarity index 100% rename from dfhack/shm/mod-creature2010.h rename to library/shm/mod-creature2010.h diff --git a/dfhack/shm/mod-creature40d.cpp b/library/shm/mod-creature40d.cpp similarity index 97% rename from dfhack/shm/mod-creature40d.cpp rename to library/shm/mod-creature40d.cpp index 35b17b57f..627719a0c 100644 --- a/dfhack/shm/mod-creature40d.cpp +++ b/library/shm/mod-creature40d.cpp @@ -1,11 +1,12 @@ #include #include -#include +#include #include "shms.h" #include "mod-core.h" #include "mod-creature40d.h" #include +#include #include #include @@ -14,7 +15,9 @@ extern char *shm; -namespace DFHack{ namespace Creatures{ // start of namespace +namespace DFHack{ + namespace Server{ + namespace Creatures{ // start of namespace #define SHMHDR ((shm_creature_hdr *)shm) #define SHMDATA(type) ((type *)(shm + SHM_HEADER)) @@ -191,4 +194,4 @@ DFPP_module Init( void ) return creatures; } -}} // end of namespace +}}} // end of namespace diff --git a/dfhack/shm/mod-creature40d.h b/library/shm/mod-creature40d.h similarity index 100% rename from dfhack/shm/mod-creature40d.h rename to library/shm/mod-creature40d.h diff --git a/dfhack/shm/mod-maps.cpp b/library/shm/mod-maps.cpp similarity index 85% rename from dfhack/shm/mod-maps.cpp rename to library/shm/mod-maps.cpp index dd00d2fb1..4274b47a2 100644 --- a/dfhack/shm/mod-maps.cpp +++ b/library/shm/mod-maps.cpp @@ -1,13 +1,15 @@ #include #include -#include +#include +#include #include "shms.h" #include "mod-core.h" #include "mod-maps.h" -#include +#include +#include using namespace DFHack; -using namespace DFHack::Maps; +using namespace DFHack::Server::Maps; #include #include @@ -17,7 +19,9 @@ extern char *shm; //TODO: circular buffer streaming primitives required //TODO: commands can fail without the proper offsets. Hot to handle that? -namespace DFHack{ namespace Maps{ // start of namespace +namespace DFHack{ + namespace Server{ // start of namespace + namespace Maps{ // start of namespace #define SHMHDR ((shm_maps_hdr *)shm) #define SHMCMD ((shm_cmd *)shm)->pingpong @@ -68,7 +72,10 @@ inline void ReadBlockByAddress (void * data) memcpy(&(SHMDATA(mapblock40d)->biome_indices), ((char *) block) + offsets.biome_stuffs, sizeof(SHMDATA(mapblock40d)->biome_indices)); SHMDATA(mapblock40d)->blockflags.whole = *block->ptr_to_dirty; - SHMDATA(mapblock40d)->origin = (uint32_t)block; + SHMDATA(mapblock40d)->local_feature = *(int16_t *)((char*) block + offsets.local_feature_offset); + SHMDATA(mapblock40d)->global_feature = *(int16_t *)((char*) block + offsets.global_feature_offset); + + SHMDATA(mapblock40d)->origin = (uint32_t)(uint64_t)block; // this is STUPID SHMHDR->error = false; } else @@ -90,7 +97,7 @@ void ReadBlockByCoords (void * data) only Z blocks can have NULL pointers? TODO: verify */ mblock * *** mapArray = *(mblock * ****)offsets.map_offset; - SHMHDR->address = (uint32_t) mapArray[SHMHDR->x][SHMHDR->y][SHMHDR->z]; + SHMHDR->address = (uint32_t) (uint64_t) mapArray[SHMHDR->x][SHMHDR->y][SHMHDR->z];// this is STUPID ReadBlockByAddress(data); // I wonder... will this inline properly? } @@ -120,4 +127,4 @@ DFPP_module Init( void ) return maps; } -}} // end of namespace +}}} // end of namespace diff --git a/dfhack/shm/mod-maps.h b/library/shm/mod-maps.h similarity index 98% rename from dfhack/shm/mod-maps.h rename to library/shm/mod-maps.h index 96403d311..aafc355cd 100644 --- a/dfhack/shm/mod-maps.h +++ b/library/shm/mod-maps.h @@ -25,8 +25,7 @@ distribution. #ifndef MOD_MAPS_H #define MOD_MAPS_H -// increment on every change -#include +#include "dfhack/DFTypes.h" namespace DFHack { @@ -34,8 +33,8 @@ namespace DFHack { namespace Maps { - -#define MAPS_VERSION 3 +// increment on every change +#define MAPS_VERSION 4 typedef struct { uint32_t map_offset;// = d->offset_descriptor->getAddress ("map_data"); diff --git a/dfhack/shm/readme.txt b/library/shm/readme.txt similarity index 100% rename from dfhack/shm/readme.txt rename to library/shm/readme.txt diff --git a/dfhack/shm/shms-linux.cpp b/library/shm/shms-linux.cpp similarity index 92% rename from dfhack/shm/shms-linux.cpp rename to library/shm/shms-linux.cpp index aa157c1be..9c601de12 100644 --- a/dfhack/shm/shms-linux.cpp +++ b/library/shm/shms-linux.cpp @@ -247,13 +247,27 @@ void SHM_Destroy ( void ) /******************************************************************************* * SDL part starts here * *******************************************************************************/ +// this is supported from 0.31.04 forward +DFhackCExport int SDL_NumJoysticks(void) +{ + if(errorstate) + return -1; + if(!inited) + { + SHM_Init(); + return -2; + } + SHM_Act(); + return -3; +} + // ptr to the real functions -static void (*_SDL_GL_SwapBuffers)(void) = 0; +//static void (*_SDL_GL_SwapBuffers)(void) = 0; static void (*_SDL_Quit)(void) = 0; static int (*_SDL_Init)(uint32_t flags) = 0; -static int (*_SDL_Flip)(void * some_ptr) = 0; - +//static int (*_SDL_Flip)(void * some_ptr) = 0; +/* // hook - called every tick in OpenGL mode of DF DFhackCExport void SDL_GL_SwapBuffers(void) { @@ -267,7 +281,8 @@ DFhackCExport void SDL_GL_SwapBuffers(void) _SDL_GL_SwapBuffers(); } } - +*/ +/* // hook - called every tick in the 2D mode of DF DFhackCExport int SDL_Flip(void * some_ptr) { @@ -282,6 +297,7 @@ DFhackCExport int SDL_Flip(void * some_ptr) } return 0; } +*/ // hook - called at program exit DFhackCExport void SDL_Quit(void) @@ -289,6 +305,7 @@ DFhackCExport void SDL_Quit(void) if(!errorstate) { SHM_Destroy(); + errorstate = true; } if(_SDL_Quit) { @@ -300,13 +317,13 @@ DFhackCExport void SDL_Quit(void) DFhackCExport int SDL_Init(uint32_t flags) { // find real functions - _SDL_GL_SwapBuffers = (void (*)( void )) dlsym(RTLD_NEXT, "SDL_GL_SwapBuffers"); + //_SDL_GL_SwapBuffers = (void (*)( void )) dlsym(RTLD_NEXT, "SDL_GL_SwapBuffers"); _SDL_Init = (int (*)( uint32_t )) dlsym(RTLD_NEXT, "SDL_Init"); - _SDL_Flip = (int (*)( void * )) dlsym(RTLD_NEXT, "SDL_Flip"); + //_SDL_Flip = (int (*)( void * )) dlsym(RTLD_NEXT, "SDL_Flip"); _SDL_Quit = (void (*)( void )) dlsym(RTLD_NEXT, "SDL_Quit"); // check if we got them - if(_SDL_GL_SwapBuffers && _SDL_Init && _SDL_Quit) + if(/*_SDL_GL_SwapBuffers &&*/ _SDL_Init && _SDL_Quit) { fprintf(stderr,"dfhack: hooking successful\n"); } @@ -314,13 +331,14 @@ DFhackCExport int SDL_Init(uint32_t flags) { // bail, this would be a disaster otherwise fprintf(stderr,"dfhack: something went horribly wrong\n"); + errorstate = true; exit(1); } - SHM_Init(); + //SHM_Init(); return _SDL_Init(flags); } - +//*/ /******************************************************************************* * NCURSES part starts here * *******************************************************************************/ @@ -331,11 +349,13 @@ DFhackCExport int refresh (void) { if(_refresh) { + /* if(!errorstate) { SHM_Act(); } counter ++; + */ return _refresh(); } return 0; @@ -348,11 +368,13 @@ DFhackCExport int endwin (void) if(!errorstate) { SHM_Destroy(); + errorstate = true; } if(_endwin) { return _endwin(); } + return 0; } typedef void WINDOW; @@ -361,7 +383,7 @@ static WINDOW * (*_initscr)(void) = 0; DFhackCExport WINDOW * initscr (void) { // find real functions - _refresh = (int (*)( void )) dlsym(RTLD_NEXT, "refresh"); + //_refresh = (int (*)( void )) dlsym(RTLD_NEXT, "refresh"); _endwin = (int (*)( void )) dlsym(RTLD_NEXT, "endwin"); _initscr = (WINDOW * (*)( void )) dlsym(RTLD_NEXT, "initscr"); // check if we got them @@ -375,6 +397,6 @@ DFhackCExport WINDOW * initscr (void) fprintf(stderr,"dfhack: something went horribly wrong\n"); exit(1); } - SHM_Init(); + //SHM_Init(); return _initscr(); -} \ No newline at end of file +} diff --git a/dfhack/shm/shms-windows.cpp b/library/shm/shms-windows.cpp similarity index 87% rename from dfhack/shm/shms-windows.cpp rename to library/shm/shms-windows.cpp index 97f5462dd..007612438 100644 --- a/dfhack/shm/shms-windows.cpp +++ b/library/shm/shms-windows.cpp @@ -33,7 +33,7 @@ distribution. #define DFhackCExport extern "C" __declspec(dllexport) -#include "../library/integers.h" +#include "dfhack/DFIntegers.h" #include #include #include "shms.h" @@ -50,7 +50,7 @@ HANDLE DFCLMutex[SHM_MAX_CLIENTS]; HANDLE DFCLSuspendMutex[SHM_MAX_CLIENTS]; int held_DFCLSuspendMutex[SHM_MAX_CLIENTS]; int numheld = SHM_MAX_CLIENTS; - +bool FirstCall(); void OS_lockSuspendLock(int which) { @@ -108,7 +108,7 @@ void SHM_Init ( void ) // check that we do this only once per process if(inited) { - //MessageBox(0,"SDL_Init was called twice or more!","FUN", MB_OK); + MessageBox(0,"SHM_Init was called twice or more!","FUN", MB_OK); return; } inited = true; @@ -717,21 +717,41 @@ SDL_GL_SwapBuffers void SDLCALL SDL_GL_SwapBuffers(void); */ + +// hook - called at program exit static void (*_SDL_Quit)(void) = 0; DFhackCExport void SDL_Quit(void) { fprintf(stderr,"Quitting!\n"); - SHM_Destroy(); - _SDL_Quit(); + if(!errorstate) + { + SHM_Destroy(); + errorstate = true; + } + if(_SDL_Quit) + { + _SDL_Quit(); + } +} +// this is supported from 0.31.04 forward +DFhackCExport int SDL_NumJoysticks(void) +{ + if(errorstate) + return -1; + if(!inited) + { + SHM_Init(); + return -2; + } + SHM_Act(); + return -3; } static void (*_SDL_GL_SwapBuffers)(void) = 0; DFhackCExport void SDL_GL_SwapBuffers(void) { - if(!errorstate) - { - SHM_Act(); - } + if(!inited) + FirstCall(); _SDL_GL_SwapBuffers(); } @@ -739,26 +759,120 @@ DFhackCExport void SDL_GL_SwapBuffers(void) static int (*_SDL_Flip)(void * some_ptr) = 0; DFhackCExport int SDL_Flip(void * some_ptr) { - if(_SDL_Flip) - { - if(!errorstate) - { - SHM_Act(); - } - return _SDL_Flip(some_ptr); - } - return 0; + if(!inited) + FirstCall(); + return _SDL_Flip(some_ptr); } static int (*_SDL_Init)(uint32_t flags) = 0; DFhackCExport int SDL_Init(uint32_t flags) +{ + if(!inited) + FirstCall(); + return _SDL_Init(flags); +} + +/* +MORE CRAP +*/ +static void * (*_SDL_CreateSemaphore)(uint32_t initial_value) = 0; +DFhackCExport void *SDL_CreateSemaphore(uint32_t initial_value) +{ + if(!inited) + FirstCall(); + return _SDL_CreateSemaphore(initial_value); +} + +static void * (*_SDL_CreateThread)(int (*fn)(void *), void *data) = 0; +DFhackCExport void *SDL_CreateThread(int (*fn)(void *), void *data) +{ + if(!inited) + FirstCall(); + return _SDL_CreateThread(fn,data); +} + + +static void (*_SDL_Delay)(uint32_t ms) = 0; +DFhackCExport void SDL_Delay(uint32_t ms) +{ + if(!inited) + FirstCall(); + _SDL_Delay(ms); +} + +static void (*_SDL_DestroySemaphore)(void *sem) = 0; +DFhackCExport void SDL_DestroySemaphore(void *sem) +{ + if(!inited) + FirstCall(); + _SDL_DestroySemaphore(sem); +} + +static uint8_t (*_SDL_GetAppState)(void) = 0; +DFhackCExport uint8_t SDL_GetAppState(void) +{ + if(!inited) + FirstCall(); + return _SDL_GetAppState(); +} + +static uint8_t (*_SDL_GetMouseState)(int *, int *) = 0; +DFhackCExport uint8_t SDL_GetMouseState(int *x, int *y) +{ + if(!inited) + FirstCall(); + return _SDL_GetMouseState(x,y); +} + +static int (*_SDL_InitSubSystem)(uint32_t flags) = 0; +DFhackCExport int SDL_InitSubSystem(uint32_t flags) +{ + if(!inited) + FirstCall(); + return _SDL_InitSubSystem(flags); +} + +static int (*_SDL_SemPost)(void *sem) = 0; +DFhackCExport int SDL_SemPost(void *sem) +{ + if(!inited) + FirstCall(); + return _SDL_SemPost(sem); +} + +static int (*_SDL_SemTryWait)(void *sem) = 0; +DFhackCExport int SDL_SemTryWait(void *sem) +{ + if(!inited) + FirstCall(); + return _SDL_SemTryWait(sem); +} + +static int (*_SDL_SemWait)(void *sem) = 0; +DFhackCExport int SDL_SemWait(void *sem) +{ + if(!inited) + FirstCall(); + return _SDL_SemWait(sem); +} + +static uint32_t (*_SDL_ThreadID)(void) = 0; +DFhackCExport uint32_t SDL_ThreadID(void) +{ + if(!inited) + FirstCall(); + return _SDL_ThreadID(); +} + +// this has to be thread-safe. Let's hope it is. +bool FirstCall() { HMODULE realSDLlib = LoadLibrary("SDLreal.dll"); if(!realSDLlib) { MessageBox(0,"Can't load SDLreal.dll\n","Error", MB_OK); fprintf(stderr, "Can't load SDLreal.dll\n"); - return -1; + return 0; } // stuff for DF _SDL_AddTimer = (void*(*)(uint32_t, void*, void*)) GetProcAddress(realSDLlib,"SDL_AddTimer"); @@ -816,7 +930,19 @@ DFhackCExport int SDL_Init(uint32_t flags) _SDL_UnloadObject = (void (*)(void*))GetProcAddress(realSDLlib,"SDL_UnloadObject"); _SDL_FillRect = (int (*)(void*,void*,uint32_t))GetProcAddress(realSDLlib,"SDL_FillRect"); + // new in DF 0.31.04 + _SDL_CreateSemaphore = (void* (*)(uint32_t))GetProcAddress(realSDLlib,"SDL_CreateSemaphore"); + _SDL_CreateThread = (void* (*)(int (*fn)(void *), void *data))GetProcAddress(realSDLlib,"SDL_CreateThread"); + _SDL_Delay = (void (*)(uint32_t))GetProcAddress(realSDLlib,"SDL_Delay"); + _SDL_DestroySemaphore = (void (*)(void *))GetProcAddress(realSDLlib,"SDL_DestroySemaphore"); + _SDL_GetAppState = (uint8_t (*)(void))GetProcAddress(realSDLlib,"SDL_GetAppState"); + _SDL_GetMouseState = (uint8_t (*)(int *, int *))GetProcAddress(realSDLlib,"SDL_GetMouseState"); + _SDL_InitSubSystem = (int (*)(uint32_t))GetProcAddress(realSDLlib,"SDL_InitSubSystem"); + _SDL_SemPost = (int (*)(void *))GetProcAddress(realSDLlib,"SDL_SemPost"); + _SDL_SemTryWait = (int (*)(void *))GetProcAddress(realSDLlib,"SDL_SemTryWait"); + _SDL_SemWait = (int (*)(void *))GetProcAddress(realSDLlib,"SDL_SemWait"); + _SDL_ThreadID = (uint32_t (*)(void))GetProcAddress(realSDLlib,"SDL_ThreadID"); + fprintf(stderr,"Initized HOOKS!\n"); - SHM_Init(); - return _SDL_Init(flags); + return 1; } diff --git a/dfhack/shm/shms.h b/library/shm/shms.h similarity index 100% rename from dfhack/shm/shms.h rename to library/shm/shms.h diff --git a/output/Memory.xml b/output/Memory.xml index b6d866ddf..fa97b261a 100755 --- a/output/Memory.xml +++ b/output/Memory.xml @@ -1069,9 +1069,12 @@ size=212 WORLD + 0x54374
0x16AF4FC
0x100 + 0x34 + 0x38 WORLD + 0x54440
0x16AF5C8
- + 0x30 + 0x34 + + + 1d759a11af258263ef5c139d6d9a3e15 + Basic things + ============ + 0xC + 0x0 + 0x4 + + + +
0x92D00C0
0x0165B188 + + Position and window dimensions + ============================== +
0x8cd3b18
0xe32798 +
0x8cd3b1c
0xe60838 +
0x8cd3b20
0xe60814 +
0x8b17370
0xae82cc + +
0x9464d6c
0x17f5ab8 + GUI State + ========= +
0x92c971c
0x146e45f + + Map stuff + ========= +
0x9322d20
WORLD + 0x52C60 + 0x08 + 0x20 + 0x24 + 0x006A + 0x026C + 0x066c + 0x156c + 0x176c + 0x1D6C + 0x0D6c + + Map Features + ============ + WORLD + 0x5487C +
0x932493C
+ 0x94 + 0x28 + 0x2C + WORLD + 0x548F4 +
0x93249B4
+ 0x24 + 0x28 + + * map size in blocks * +
0x9322d34
0x016ad738 +
0x9322d38
0x016ad73C +
0x9322d3C
0x016ad740 + + * map size in tiles * +
0x9322d40
0x016ad744 +
0x9322d44
0x016ad748 +
0x9322d48
0x016ad74C + + * region coords * + WORLD + 0x525C8 +
0x9322d4C
0x016ad750 + WORLD + 0x525CC +
0x9322d50
0x016ad754 + WORLD + 0x525D0 +
0x9322d54
0x016ad758 + + * World size * (WORDs) + WORLD + 0x542E0 +
0x93243A0
0x016AEDD4 + WORLD + 0x542E2 +
0x93243A2
0x016AEDD6 + WORLD + 0x54894 +
0x9324954
FIX 0x16AF52C + WORLD + 0x548B8 +
0x9324978
FIX 0x16AF574 + + values for the region structure + =============================== + 0x58 0x64 FIX + 0x54 0x60 FIX + geoblock offsets + ================ + 0x4 vector + 0x4 vector + + Name struct + =========== + 0x0 + 0x4 + 0x8 + + Creatures + ========= +
0x092E3AA0
+
0x092CB608
+
0x092CB5FC
+ 0x0 + 0x6c + 0x3c * + 0x44 * + 0x90 + 0x8C * + 0x90 * + 0x110 + 0xA6 * + 0x114 + 0XB4 * + 0X1F4 + 0X21C + + 0x18C * + 0x19C * + 0x1A0 * + 0x464 + 0x390 from chmod + 0x394 the skill that will be increased at the end of the mood (or not) + 0x604 + 0x6D4 + 0x774 + 0x0740 + 0x0758 + 0x834 + + Souls + ===== + 0x0 + 0x1F4 + 0x224 + 0x88 + + Castes + ====== + 0x70 + 0x64 + 0x68 + 0x51C + 0xACC + 0x654 + + Body Parts + ========== + 0x0 + 0x1C + 0x44 + 0x78 + 0x90 + + Job structure + ============= + 0x0 Incrementaly assigned + 0x8 seems to be just like the old occupations + 0xa4 + + Job materials + ============= + 0x0 like mood materials, 0=bars, 4=stone, 5=wood, 57=cloth, 54=leather ... + 0x2 subsubtype ? + 0x4 subtype ? + 0x8 index of material (for example, 2 is for silver) + 0x18 set only for shell / bone mood requirements ? + + Materials + ========= + soil, stone, metal + inorganics vector +
0x9324e68
0x16afd04 + + wood and plant matter +
0x9324E74
+ + plant matter +
0x9324E80
+ + just wood +
0x9324E98
+ + creature types actually used for creatures, +
0x09324F14
+ 0x138 + 0x1A14 + 0xE0 + 0xF6 + + Translations + ============ + WORLD + 0x54E50 +
23
+ WORLD + 0x54E80 +
24
+ 0x4C + + Constructions + ============= + WORLD + 0x84 +
0x92D0144
0x165b290 + 0x14 + + + Time + ==== +
0x92C9688
+
0x92C9680
+
diff --git a/examples/CMakeLists.txt b/tools/examples/CMakeLists.txt similarity index 68% rename from examples/CMakeLists.txt rename to tools/examples/CMakeLists.txt index 1276e4b38..3662181b4 100644 --- a/examples/CMakeLists.txt +++ b/tools/examples/CMakeLists.txt @@ -5,10 +5,6 @@ IF(UNIX) add_definitions(-DLINUX_BUILD) ENDIF(UNIX) -# attachtest - 100x attach/detach, suspend/resume -ADD_EXECUTABLE(dfattachtest attachtest.cpp) -TARGET_LINK_LIBRARIES(dfattachtest dfhack) - # buildingsdump - dump buildings and their raw data filtered by type ADD_EXECUTABLE(dfbuildingsdump buildingsdump.cpp) TARGET_LINK_LIBRARIES(dfbuildingsdump dfhack) @@ -17,10 +13,6 @@ TARGET_LINK_LIBRARIES(dfbuildingsdump dfhack) ADD_EXECUTABLE(dfconstructiondump construction_dump.cpp) TARGET_LINK_LIBRARIES(dfconstructiondump dfhack) -# a benchmark program, reads the map 1000x -ADD_EXECUTABLE(dfexpbench expbench.cpp) -TARGET_LINK_LIBRARIES(dfexpbench dfhack) - # creaturedump - basic creature dump - a test of the creature related exports ADD_EXECUTABLE(dfcreaturedump creaturedump.cpp) TARGET_LINK_LIBRARIES(dfcreaturedump dfhack) @@ -33,11 +25,6 @@ TARGET_LINK_LIBRARIES(dfmaterialtest dfhack) ADD_EXECUTABLE(dfposition position.cpp) TARGET_LINK_LIBRARIES(dfposition dfhack) -# suspendtest - test if suspend works. df should stop responding when suspended -# by dfhack -ADD_EXECUTABLE(dfsuspend suspendtest.cpp) -TARGET_LINK_LIBRARIES(dfsuspend dfhack) - # itemdump - dump the item under the cursor ADD_EXECUTABLE(dfitemdump dfitemdump.cpp) TARGET_LINK_LIBRARIES(dfitemdump dfhack) @@ -47,20 +34,11 @@ TARGET_LINK_LIBRARIES(dfitemdump dfhack) ADD_EXECUTABLE(dfhotkeynotedump hotkeynotedump.cpp) TARGET_LINK_LIBRARIES(dfhotkeynotedump dfhack) -# findnameindexes -# Author: belal -#ADD_EXECUTABLE(dffindnameindexes findnameindexes.cpp) -#TARGET_LINK_LIBRARIES(dffindnameindexes dfhack) - # settlementdump - dumps the settlements on the loaded map # Author: belal # ADD_EXECUTABLE(dfsettlementdump settlementdump.cpp) # TARGET_LINK_LIBRARIES(dfsettlementdump dfhack) -# veccheck - read vector values at address -ADD_EXECUTABLE(dfvecc veccheck.cpp) -TARGET_LINK_LIBRARIES(dfvecc dfhack) - # treedump - dump them trees! ADD_EXECUTABLE(dftreedump treedump.cpp) TARGET_LINK_LIBRARIES(dftreedump dfhack) @@ -69,15 +47,6 @@ TARGET_LINK_LIBRARIES(dftreedump dfhack) ADD_EXECUTABLE(dfspatterdump spatterdump.cpp) TARGET_LINK_LIBRARIES(dfspatterdump dfhack) -# catsplosion - Accelerates pregnancy -# Author: Zhentar -ADD_EXECUTABLE(dfcatsplosion catsplosion.cpp) -TARGET_LINK_LIBRARIES(dfcatsplosion dfhack) - -# flows - check flows impact on fps -ADD_EXECUTABLE(dfflows flows.cpp) -TARGET_LINK_LIBRARIES(dfflows dfhack) - IF(UNIX) SET(CURSES_NEED_WIDE "YES") SET(CURSES_NEED_NCURSES "NO") @@ -112,30 +81,4 @@ IF(UNIX) ELSE(CURSES_FOUND) MESSAGE(STATUS "Wide-character ncurses library not found - veinlook can't be built") ENDIF(CURSES_FOUND) -ENDIF(UNIX) - -# renamer - change the custom names and professions of creatures, sends keys to -# df directly -# Author: belal -#ADD_EXECUTABLE(dfrenamer renamer.cpp) -#TARGET_LINK_LIBRARIES(dfrenamer dfhack) - -IF(UNIX) -install(TARGETS -dfattachtest -#dfexpbench -#dfcreaturedump -#dfbuildingsdump -dfmaterialtest -dfposition -dfsuspend -#dfitemdump -#dfhotkeynotedump -#dffindnameindexes -#dfsettlementdump -#dfrenamer -dfvecc -#dfcatsplosion -RUNTIME DESTINATION bin -) -ENDIF(UNIX) +ENDIF(UNIX) \ No newline at end of file diff --git a/examples/buildingsdump.cpp b/tools/examples/buildingsdump.cpp similarity index 86% rename from examples/buildingsdump.cpp rename to tools/examples/buildingsdump.cpp index 5ba7d8357..1f0be6fc7 100644 --- a/examples/buildingsdump.cpp +++ b/tools/examples/buildingsdump.cpp @@ -4,21 +4,10 @@ #include #include #include -#include #include using namespace std; -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include int main (int argc,const char* argv[]) { @@ -47,10 +36,12 @@ int main (int argc,const char* argv[]) map custom_workshop_types; - DFHack::API DF ("Memory.xml"); + DFHack::ContextManager DFMgr ("Memory.xml"); + DFHack::Context *DF; try { - DF.Attach(); + DF = DFMgr.getSingleContext(); + DF->Attach(); } catch (exception& e) { @@ -61,9 +52,9 @@ int main (int argc,const char* argv[]) return 1; } - DFHack::memory_info * mem = DF.getMemoryInfo(); - DFHack::Buildings * Bld = DF.getBuildings(); - DFHack::Position * Pos = DF.getPosition(); + DFHack::memory_info * mem = DF->getMemoryInfo(); + DFHack::Buildings * Bld = DF->getBuildings(); + DFHack::Position * Pos = DF->getPosition(); uint32_t numBuildings; if(Bld->Start(numBuildings)) @@ -107,7 +98,12 @@ int main (int argc,const char* argv[]) { DFHack::t_building temp; Bld->Read(i, temp); - if((uint32_t)x >= temp.x1 && (uint32_t)x <= temp.x2 && (uint32_t)y >= temp.y1 && (uint32_t)y <= temp.y2 && (uint32_t)z == temp.z) + if( (uint32_t)x >= temp.x1 + && (uint32_t)x <= temp.x2 + && (uint32_t)y >= temp.y1 + && (uint32_t)y <= temp.y2 + && (uint32_t)z == temp.z + ) { string typestr; mem->resolveClassIDToClassname(temp.type, typestr); @@ -142,7 +138,7 @@ int main (int argc,const char* argv[]) cerr << "buildings not supported for this DF version" << endl; } - DF.Detach(); + DF->Detach(); #ifndef LINUX_BUILD cout << "Done. Press any key to continue" << endl; cin.ignore(); diff --git a/examples/construction_dump.cpp b/tools/examples/construction_dump.cpp similarity index 82% rename from examples/construction_dump.cpp rename to tools/examples/construction_dump.cpp index 3596059f6..a48b4e6a9 100644 --- a/examples/construction_dump.cpp +++ b/tools/examples/construction_dump.cpp @@ -3,32 +3,23 @@ #include #include #include -#include #include #include #include #include using namespace std; -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - +#include using namespace DFHack; int main (int numargs, const char ** args) { - DFHack::API DF("Memory.xml"); + DFHack::ContextManager DFMgr("Memory.xml"); + DFHack::Context* DF; try { - DF.Attach(); + DF = DFMgr.getSingleContext(); + DF->Attach(); } catch (exception& e) { @@ -39,10 +30,10 @@ int main (int numargs, const char ** args) return 1; } - DFHack::Position *Pos = DF.getPosition(); + DFHack::Position *Pos = DF->getPosition(); - DFHack::Constructions *Cons = DF.getConstructions(); - DFHack::Materials *Mats = DF.getMaterials(); + DFHack::Constructions *Cons = DF->getConstructions(); + DFHack::Materials *Mats = DF->getMaterials(); Mats->ReadInorganicMaterials(); uint32_t numConstr; Cons->Start(numConstr); diff --git a/examples/creaturedump.cpp b/tools/examples/creaturedump.cpp similarity index 95% rename from examples/creaturedump.cpp rename to tools/examples/creaturedump.cpp index decd218fb..f8b63b51f 100644 --- a/examples/creaturedump.cpp +++ b/tools/examples/creaturedump.cpp @@ -2,22 +2,11 @@ #include #include -#include #include #include using namespace std; -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include enum likeType { @@ -140,7 +129,7 @@ likeType printLike40d(DFHack::t_like like, const matGlosses & mat,const vector< } */ -void printCreature(DFHack::API & DF, const DFHack::t_creature & creature) +void printCreature(DFHack::Context * DF, const DFHack::t_creature & creature) { uint32_t dayoflife; cout << "address: " << hex << creature.origin << dec << " creature type: " << Materials->raceEx[creature.race].rawname @@ -162,8 +151,8 @@ void printCreature(DFHack::API & DF, const DFHack::t_creature & creature) addendl = true; } - DFHack::Translation *Tran = DF.getTranslation(); - DFHack::memory_info *mem = DF.getMemoryInfo(); + DFHack::Translation *Tran = DF->getTranslation(); + DFHack::memory_info *mem = DF->getMemoryInfo(); string transName = Tran->TranslateName(creature.name,false); if(!transName.empty()) @@ -398,10 +387,12 @@ void printCreature(DFHack::API & DF, const DFHack::t_creature & creature) int main (int numargs, char ** args) { DFHack::World * World; - DFHack::API DF("Memory.xml"); + DFHack::ContextManager DFMgr("Memory.xml"); + DFHack::Context* DF; try { - DF.Attach(); + DF = DFMgr.getSingleContext(); + DF->Attach(); } catch (exception& e) { @@ -415,12 +406,12 @@ int main (int numargs, char ** args) if(numargs == 2) check = args[1]; - Creatures = DF.getCreatures(); - Materials = DF.getMaterials(); - World = DF.getWorld(); + Creatures = DF->getCreatures(); + Materials = DF->getMaterials(); + World = DF->getWorld(); current_year = World->ReadCurrentYear(); current_tick = World->ReadCurrentTick(); - DFHack::Translation * Tran = DF.getTranslation(); + DFHack::Translation * Tran = DF->getTranslation(); uint32_t numCreatures; if(!Creatures->Start(numCreatures)) @@ -440,7 +431,7 @@ int main (int numargs, char ** args) return 1; } - mem = DF.getMemoryInfo(); + mem = DF->getMemoryInfo(); Materials->ReadAllMaterials(); if(!Tran->Start()) @@ -476,7 +467,7 @@ int main (int numargs, char ** args) printCreature(DF,currentCreature); */ Creatures->Finish(); - DF.Detach(); + DF->Detach(); #ifndef LINUX_BUILD cout << "Done. Press any key to continue" << endl; cin.ignore(); diff --git a/examples/dfitemdump.cpp b/tools/examples/dfitemdump.cpp similarity index 94% rename from examples/dfitemdump.cpp rename to tools/examples/dfitemdump.cpp index 01b734e06..0ed6413b2 100644 --- a/examples/dfitemdump.cpp +++ b/tools/examples/dfitemdump.cpp @@ -7,18 +7,10 @@ #include #include #include -#include #include using namespace std; -#include -#include -#include -#include -#include -#include -#include -#include +#include DFHack::Materials * Materials; @@ -26,13 +18,14 @@ DFHack::Items * Items; int main () { - DFHack::API DF("Memory.xml"); DFHack::Process * p; unsigned int i,j; - + DFHack::ContextManager DFMgr("Memory.xml"); + DFHack::Context * DF; try { - DF.Attach(); + DF = DFMgr.getSingleContext(); + DF->Attach(); } catch (exception& e) { @@ -43,13 +36,13 @@ int main () return 1; } - DFHack::memory_info * mem = DF.getMemoryInfo(); - Materials = DF.getMaterials(); + DFHack::memory_info * mem = DF->getMemoryInfo(); + Materials = DF->getMaterials(); Materials->ReadAllMaterials(); - p = DF.getProcess(); + p = DF->getProcess(); DFHack::DfVector p_items (p, p->getDescriptor()->getAddress ("items_vector")); uint32_t size = p_items.size(); - Items = DF.getItems(); + Items = DF->getItems(); printf("type\tvtable\tname\tquality\tdecorate\n"); diff --git a/examples/fake-curses.h.cmake b/tools/examples/fake-curses.h.cmake similarity index 100% rename from examples/fake-curses.h.cmake rename to tools/examples/fake-curses.h.cmake diff --git a/examples/hotkeynotedump.cpp b/tools/examples/hotkeynotedump.cpp similarity index 82% rename from examples/hotkeynotedump.cpp rename to tools/examples/hotkeynotedump.cpp index 83707eaa3..2e35f2796 100644 --- a/examples/hotkeynotedump.cpp +++ b/tools/examples/hotkeynotedump.cpp @@ -2,22 +2,19 @@ // Or Hot Keynote Dump? :P #include #include -#include #include using namespace std; - -#include -#include -#include -#include +#include int main (void) { - DFHack::API DF("Memory.xml"); + DFHack::ContextManager DFMgr("Memory.xml"); + DFHack::Context * DF; try { - DF.Attach(); + DF = DFMgr.getSingleContext(); + DF->Attach(); } catch (exception& e) { @@ -28,8 +25,8 @@ int main (void) return 1; } - DFHack::memory_info * mem = DF.getMemoryInfo(); - DFHack::Position * Pos = DF.getPosition(); + DFHack::memory_info * mem = DF->getMemoryInfo(); + DFHack::Position * Pos = DF->getPosition(); // get stone matgloss mapping /* uint32_t numNotes; @@ -59,7 +56,7 @@ int main (void) "\ttext: " << hotkeys[i].name << endl; } //DF.FinishReadNotes(); - DF.Detach(); + DF->Detach(); #ifndef LINUX_BUILD cout << "Done. Press any key to continue" << endl; cin.ignore(); diff --git a/examples/materialtest.cpp b/tools/examples/materialtest.cpp similarity index 92% rename from examples/materialtest.cpp rename to tools/examples/materialtest.cpp index 16fdeaf01..65426e4ba 100644 --- a/examples/materialtest.cpp +++ b/tools/examples/materialtest.cpp @@ -2,19 +2,12 @@ #include #include -#include #include #include #include using namespace std; -#include -#include -#include -#include -#include -#include -#include +#include int main (int numargs, const char ** args) { @@ -24,10 +17,13 @@ int main (int numargs, const char ** args) istringstream input (args[1],istringstream::in); input >> std::hex >> addr; } - DFHack::API DF("Memory.xml"); + + DFHack::ContextManager DFMgr("Memory.xml"); + DFHack::Context * DF; try { - DF.Attach(); + DF = DFMgr.getSingleContext(); + DF->Attach(); } catch (exception& e) { @@ -38,9 +34,9 @@ int main (int numargs, const char ** args) return 1; } - DFHack::Process* p = DF.getProcess(); - DFHack::memory_info* mem = DF.getMemoryInfo(); - DFHack::Materials *Materials = DF.getMaterials(); + DFHack::Process* p = DF->getProcess(); + DFHack::memory_info* mem = DF->getMemoryInfo(); + DFHack::Materials *Materials = DF->getMaterials(); cout << "----==== Inorganic ====----" << endl; Materials->ReadInorganicMaterials (); diff --git a/examples/position.cpp b/tools/examples/position.cpp similarity index 83% rename from examples/position.cpp rename to tools/examples/position.cpp index 4e1787477..5f666ec4e 100644 --- a/examples/position.cpp +++ b/tools/examples/position.cpp @@ -2,23 +2,22 @@ #include #include -#include #include #include using namespace std; -#include -#include -#include +#include int main (void) { - DFHack::API DF("Memory.xml"); DFHack::Position * Position = 0; + DFHack::ContextManager DFMgr("Memory.xml"); + DFHack::Context * DF; try { - DF.Attach(); - Position = DF.getPosition(); + DF = DFMgr.getSingleContext(); + DF->Attach(); + Position = DF->getPosition(); } catch (exception& e) { @@ -45,7 +44,7 @@ int main (void) cerr << "cursor and window parameters are unsupported on your version of DF" << endl; } - if(!DF.Detach()) + if(!DF->Detach()) { cerr << "Can't detach from DF" << endl; } diff --git a/examples/settlementdump.cpp b/tools/examples/settlementdump.cpp similarity index 92% rename from examples/settlementdump.cpp rename to tools/examples/settlementdump.cpp index fdabed6c9..5424d423c 100644 --- a/examples/settlementdump.cpp +++ b/tools/examples/settlementdump.cpp @@ -11,7 +11,7 @@ using namespace std; #include -void printSettlement(DFHack::API & DF, const DFHack::t_settlement & settlement, const vector< vector > &englishWords, const vector< vector > &foreignWords) +void printSettlement(DFHack::ContextManager & DF, const DFHack::t_settlement & settlement, const vector< vector > &englishWords, const vector< vector > &foreignWords) { cout << "First name: " << settlement.name.first_name << endl << "Nickname: " << settlement.name.nickname << endl; cout << settlement.name.words[0] << " " << settlement.name.words[1] << " " << settlement.name.words[2] << " " @@ -31,7 +31,7 @@ void printSettlement(DFHack::API & DF, const DFHack::t_settlement & settlement, int main (int argc,const char* argv[]) { - DFHack::API DF("Memory.xml"); + DFHack::ContextManager DF("Memory.xml"); try { DF.Attach(); diff --git a/examples/spatterdump.cpp b/tools/examples/spatterdump.cpp similarity index 91% rename from examples/spatterdump.cpp rename to tools/examples/spatterdump.cpp index bf8d58dd0..3d3b92102 100644 --- a/examples/spatterdump.cpp +++ b/tools/examples/spatterdump.cpp @@ -3,25 +3,13 @@ #include #include #include -#include #include #include #include #include using namespace std; -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include using namespace DFHack; @@ -83,10 +71,12 @@ int main (int numargs, const char ** args) vector IceVeinVector; vector splatter; - DFHack::API DF("Memory.xml"); + DFHack::ContextManager DFMgr("Memory.xml"); + DFHack::Context * DF; try { - DF.Attach(); + DF = DFMgr.getSingleContext(); + DF->Attach(); } catch (exception& e) { @@ -97,9 +87,9 @@ int main (int numargs, const char ** args) return 1; } - DFHack::Maps *Maps =DF.getMaps(); - DFHack::Position *Pos =DF.getPosition(); - DFHack::Materials *Mats =DF.getMaterials(); + DFHack::Maps *Maps =DF->getMaps(); + DFHack::Position *Pos =DF->getPosition(); + DFHack::Materials *Mats =DF->getMaterials(); Mats->ReadCreatureTypes(); diff --git a/examples/treedump.cpp b/tools/examples/treedump.cpp similarity index 78% rename from examples/treedump.cpp rename to tools/examples/treedump.cpp index de5bd54f4..7e54db674 100644 --- a/examples/treedump.cpp +++ b/tools/examples/treedump.cpp @@ -3,24 +3,13 @@ #include #include #include -#include #include #include #include #include using namespace std; -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include int main (int numargs, const char ** args) { @@ -30,10 +19,12 @@ int main (int numargs, const char ** args) istringstream input (args[1],istringstream::in); input >> std::hex >> addr; } - DFHack::API DF("Memory.xml"); + DFHack::ContextManager DFMgr("Memory.xml"); + DFHack::Context * DF; try { - DF.Attach(); + DF = DFMgr.getSingleContext(); + DF->Attach(); } catch (exception& e) { @@ -44,11 +35,11 @@ int main (int numargs, const char ** args) return 1; } - DFHack::Process* p = DF.getProcess(); - DFHack::memory_info* mem = DF.getMemoryInfo(); - DFHack::Position * pos = DF.getPosition(); - DFHack::Vegetation * v = DF.getVegetation(); - DFHack::Materials * mat = DF.getMaterials(); + DFHack::Process* p = DF->getProcess(); + DFHack::memory_info* mem = DF->getMemoryInfo(); + DFHack::Position * pos = DF->getPosition(); + DFHack::Vegetation * v = DF->getVegetation(); + DFHack::Materials * mat = DF->getMaterials(); mat->ReadOrganicMaterials(); int32_t x,y,z; diff --git a/examples/veinlook.cpp b/tools/examples/veinlook.cpp similarity index 97% rename from examples/veinlook.cpp rename to tools/examples/veinlook.cpp index a51c9899d..63ad703bf 100644 --- a/examples/veinlook.cpp +++ b/tools/examples/veinlook.cpp @@ -1,4 +1,3 @@ -#include #include // for memset #include #include @@ -16,20 +15,14 @@ using namespace std; #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include + using namespace DFHack; string error; -API * pDF = 0; +Context * pDF = 0; struct t_tempz @@ -239,7 +232,7 @@ int pickColor(int tiletype) address = absolute address of dump start length = length in bytes */ -void hexdump (DFHack::API& DF, uint32_t address, uint32_t length, int filenum) +void hexdump (DFHack::Context* DF, uint32_t address, uint32_t length, int filenum) { uint32_t reallength; uint32_t lines; @@ -254,7 +247,7 @@ void hexdump (DFHack::API& DF, uint32_t address, uint32_t length, int filenum) myfile.open (name.c_str()); - DF.ReadRaw(address, reallength, (uint8_t *) buf); + DF->ReadRaw(address, reallength, (uint8_t *) buf); for (int i = 0; i < lines; i++) { // leading offset @@ -412,10 +405,10 @@ void do_features(Process* p, uint32_t blockaddr, uint32_t blockX, uint32_t block } } */ -void do_features(API& DF, mapblock40d * block, uint32_t blockX, uint32_t blockY, int printX, int printY, vector &stonetypes) +void do_features(Context* DF, mapblock40d * block, uint32_t blockX, uint32_t blockY, int printX, int printY, vector &stonetypes) { - Maps * Maps = DF.getMaps(); - Process * p = DF.getProcess(); + Maps * Maps = DF->getMaps(); + Process * p = DF->getProcess(); if(!Maps) return; vector global_features; @@ -549,13 +542,14 @@ main(int argc, char *argv[]) DFHack::Maps * Maps = 0; - DFHack::API DF("Memory.xml"); + DFHack::ContextManager DFMgr("Memory.xml"); + DFHack::Context* DF; try { - DF.Attach(); - Mats = DF.getMaterials(); - Maps = DF.getMaps(); - pDF = &DF; + pDF = DF = DFMgr.getSingleContext(); + DF->Attach(); + Mats = DF->getMaterials(); + Maps = DF->getMaps(); } catch (exception& e) { @@ -566,12 +560,11 @@ main(int argc, char *argv[]) finish(0); } - Process* p = DF.getProcess(); + Process* p = DF->getProcess(); // init the map if(!Maps->Start()) { error = "Can't find a map to look at."; - pDF = 0; finish(0); } @@ -587,13 +580,14 @@ main(int argc, char *argv[]) pDF = 0; finish(0); } - + /* if(!Mats->ReadCreatureTypes()) { error = "Can't read stone types."; pDF = 0; finish(0); } + */ /* // get region geology if(!DF.ReadGeology( layerassign )) @@ -630,7 +624,7 @@ main(int argc, char *argv[]) e_tempmode temperature = TEMP_NO; // resume so we don't block DF while we wait for input - DF.Resume(); + DF->Resume(); for (;;) { @@ -696,6 +690,10 @@ main(int argc, char *argv[]) case 'm': temperature = TEMP_2; break; + case 27: // escape key + DF->Detach(); + return 0; + break; default: break; } @@ -719,7 +717,7 @@ main(int argc, char *argv[]) dirtybit = 0; // Supend, read/write data - DF.Suspend(); + DF->Suspend(); uint32_t effectnum; /* if(DF.InitReadEffects(effectnum)) @@ -795,7 +793,7 @@ main(int argc, char *argv[]) } } // Resume, print stuff to the terminal - DF.Resume(); + DF->Resume(); for(int i = -1; i <= 1; i++) for(int j = -1; j <= 1; j++) { mapblock40d * Block = &blocks[i+1][j+1]; diff --git a/tools/incrementalsearch.cpp b/tools/incrementalsearch.cpp deleted file mode 100644 index 50cadefb4..000000000 --- a/tools/incrementalsearch.cpp +++ /dev/null @@ -1,227 +0,0 @@ -// this will be an incremental search tool in the future. now it is just a memory region dump thing - -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -#ifndef LINUX_BUILD - #define WINVER 0x0500 - // this one prevents windows from infecting the global namespace with filth - #define NOMINMAX - #define WIN32_LEAN_AND_MEAN - #include -#endif - -#include -#include -#include -#include -#include - -//TODO: lots of optimization -void searchLoop(DFHack::API & DF, vector & ranges, int size, int alignment) -{ - int32_t test1; - int32_t test2; - vector found; - vector newfound; - found.reserve(100000); - newfound.reserve(100000); - - //bool initial = 1; - cout << "search ready - insert integers, 'p' for results" << endl; - - string select; - while (1) - { - cout << ">>"; - DF.Detach(); - std::getline(cin, select); - DF.Attach(); - if(select == "p") - { - cout << "Found addresses:" << endl; - for(int i = 0; i < found.size();i++) - { - cout << hex << "0x" << found[i] << endl; - } - } - else if(sscanf(select.c_str(),"%d", &test1) == 1) - { - newfound.clear(); - bool initial = found.empty(); - - if(initial) - { - // for each range - for (int i = 0; i < ranges.size();i++) - { - // can't read? range is invalid to us - if(!ranges[i].read) - continue; - - //loop - for(uint64_t offset = ranges[i].start;offset <= ranges[i].end - size; offset+=alignment) - { - DF.ReadRaw(offset, size, (uint8_t *) &test2); - if(test1 == test2 ) - found.push_back(offset); - } - } - cout << "found " << found.size() << " addresses" << endl; - } - else - { - for(int j = 0; j < found.size();j++) - { - DF.ReadRaw(found[j], size, (uint8_t *) &test2); - if(test1 == test2) - { - newfound.push_back(found[j]); - } - } - - cout << "matched " << newfound.size() << " addresses out of " << found.size() << endl; - found = newfound; - } - } - else break; - } -} - -int main (void) -{ - string select; - DFHack::API DF("Memory.xml"); - try - { - DF.Attach(); - } - catch (exception& e) - { - cerr << e.what() << endl; - #ifndef LINUX_BUILD - cin.ignore(); - #endif - return 1; - } - DFHack::Process * p = DF.getProcess(); - vector ranges; - vector selected_ranges; - p->getMemRanges(ranges); - cout << "Which range to search? (default is 1-4)" << endl; - for(int i = 0; i< ranges.size();i++) - { - cout << dec << "(" << i << ") "; - ranges[i].print(); - } - - try_again_ranges: - cout << ">>"; - std::getline(cin, select); - int start, end; - if(select.empty()) - { - // empty input, assume default. observe the length of the memory range vector - // these are hardcoded values, intended for my convenience only - if(p->getDescriptor()->getOS() == DFHack::memory_info::OS_WINDOWS) - { - start = min(11, (int)ranges.size()); - end = min(14, (int)ranges.size()); - } - else if(p->getDescriptor()->getOS() == DFHack::memory_info::OS_LINUX) - { - start = min(11, (int)ranges.size()); - end = min(14, (int)ranges.size()); - } - else - { - start = 1; - end = 1; - } - } - // I like the C variants here. much less object clutter - else if(sscanf(select.c_str(), "%d-%d", &start, &end) == 2) - { - start = min(start, (int)ranges.size()); - end = min(end, (int)ranges.size()); - } - else - { - goto try_again_ranges; // yes, this is a goto. bite me. - } - end++; - cout << "selected ranges:" <>"; - std::getline(cin, select); - int size; - if(select.empty()) - { - size = 4; - } - else if( sscanf(select.c_str(), "%d", &size) == 1 ) - { - if(/*size != 8 &&*/ size != 4 && size != 2 && size != 1) - { - goto try_again_size; - } - } - else - { - goto try_again_size; - } - - // input / validation of variable alignment (default is to use the same alignment as size) - try_again_align: - cout << "Variable alignment (1,2,4 bytes, default is " << size << ")" << endl; - cout << ">>"; - std::getline(cin, select); - int alignment = size; - if(select.empty()) - { - alignment = size; - } - else if( sscanf(select.c_str(), "%d", &alignment) == 1 ) - { - if(/*alignment != 8 &&*/ alignment != 4 && alignment != 2 && alignment != 1) - { - goto try_again_align; - } - } - else - { - goto try_again_align; - } - - searchLoop(DF,selected_ranges, size, alignment); - - // initial value - // cycle until you get only a few offsets (~10?) - - if(!DF.Detach()) - { - cerr << "Can't detach from DF" << endl; - return 1; - } - #ifndef LINUX_BUILD - cout << "Done. Press any key to continue" << endl; - cin.ignore(); - #endif - return 0; -} diff --git a/tools/moodump.cpp b/tools/moodump.cpp deleted file mode 100644 index 9b61c0701..000000000 --- a/tools/moodump.cpp +++ /dev/null @@ -1,130 +0,0 @@ -#include -#include -#include -#include -#include -using namespace std; - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -DFHack::Materials * Materials; -DFHack::memory_info *mem; -vector< vector > englishWords; -vector< vector > foreignWords; - -int main (int numargs, char ** args) -{ - DFHack::API DF("Memory.xml"); - DFHack::Process * p; - try - { - DF.Attach(); - } - catch (exception& e) - { - cerr << e.what() << endl; - #ifndef LINUX_BUILD - cin.ignore(); - #endif - return 1; - } - p = DF.getProcess(); - string check = ""; - if(numargs == 2) - check = args[1]; - - DFHack::Creatures * Creatures = DF.getCreatures(); - Materials = DF.getMaterials(); - DFHack::Translation * Tran = DF.getTranslation(); - - uint32_t numCreatures; - if(!Creatures->Start(numCreatures)) - { - cerr << "Can't get creatures" << endl; - #ifndef LINUX_BUILD - cin.ignore(); - #endif - return 1; - } - if(!numCreatures) - { - cerr << "No creatures to print" << endl; - #ifndef LINUX_BUILD - cin.ignore(); - #endif - return 1; - } - mem = DF.getMemoryInfo(); - - if(!Materials->ReadInorganicMaterials()) - { - cerr << "Can't get the inorganics types." << endl; - return 1; - } - - if(!Materials->ReadCreatureTypesEx()) - { - cerr << "Can't get the creature types." << endl; - return 1; - } - - if(!Tran->Start()) - { - cerr << "Can't get name tables" << endl; - return 1; - } - vector addrs; - //DF.InitViewAndCursor(); - for(uint32_t i = 0; i < numCreatures; i++) - { - DFHack::t_creature temp; - unsigned int current_job; - unsigned int mat_start; - unsigned int mat_end; - unsigned int j,k; - unsigned int matptr; - - Creatures->ReadCreature(i,temp); - if(temp.mood>=0) - { - current_job = p->readDWord(temp.origin + 0x390); - if(current_job == 0) - continue; - mat_start = p->readDWord(current_job + 0xa4 + 4*3); - mat_end = p->readDWord(current_job + 0xa4 + 4*4); - for(j=mat_start;jreadDWord(j); - for(k=0;k<4;k++) - printf("%.4X ", p->readWord(matptr + k*2)); - for(k=0;k<3;k++) - printf("%.8X ", p->readDWord(matptr + k*4 + 0x8)); - for(k=0;k<2;k++) - printf("%.4X ", p->readWord(matptr + k*2 + 0x14)); - for(k=0;k<3;k++) - printf("%.8X ", p->readDWord(matptr + k*4 + 0x18)); - for(k=0;k<4;k++) - printf("%.2X ", p->readByte(matptr + k + 0x24)); - for(k=0;k<6;k++) - printf("%.8X ", p->readDWord(matptr + k*4 + 0x28)); - for(k=0;k<4;k++) - printf("%.2X ", p->readByte(matptr + k + 0x40)); - for(k=0;k<9;k++) - printf("%.8X ", p->readDWord(matptr + k*4 + 0x44)); - printf(" [%p]\n", matptr); - } - } - } - Creatures->Finish(); - DF.Detach(); - return 0; -} - diff --git a/tools/playground/CMakeLists.txt b/tools/playground/CMakeLists.txt new file mode 100644 index 000000000..ee43d8c20 --- /dev/null +++ b/tools/playground/CMakeLists.txt @@ -0,0 +1,58 @@ +# don't use this file directly. use the one in the root folder of the project + +# this is required to ensure we use the right configuration for the system. +IF(UNIX) +add_definitions(-DLINUX_BUILD) +ENDIF(UNIX) + +# a creature mood dump hack. has hardcoded offsets +ADD_EXECUTABLE(dfmoodump moodump.cpp) +TARGET_LINK_LIBRARIES(dfmoodump dfhack) + +# for trying out some 'stuff' +ADD_EXECUTABLE(dftest test.cpp) +TARGET_LINK_LIBRARIES(dftest dfhack) + +# bauxite - turn all mechanisms into bauxite mechanisms +# Author: Alex Legg +#ADD_EXECUTABLE(dfbauxite dfbauxite.cpp) +#TARGET_LINK_LIBRARIES(dfbauxite dfhack) + +# digger - designate for digging by tile class +# Author: mizipzor +ADD_EXECUTABLE(dfdigger digger.cpp) +TARGET_LINK_LIBRARIES(dfdigger dfhack) + +# digger2 - designate for digging from a text file +# Author: rOut +ADD_EXECUTABLE(dfdigger2 digger2.cpp) +TARGET_LINK_LIBRARIES(dfdigger2 dfhack) + +# itemdesignator - change some item designations (dump, forbid, on-fire) for all +# items of a given type and material +# Author: belal +#ADD_EXECUTABLE(dfitemdesignator itemdesignator.cpp) +#TARGET_LINK_LIBRARIES(dfitemdesignator dfhack) + +# incrementalsearch - a bit like cheat engine, only DF-specific, very basic +# and Linux-only +IF(UNIX) + ADD_EXECUTABLE(dfincremental incrementalsearch.cpp) + TARGET_LINK_LIBRARIES(dfincremental dfhack) +ENDIF(UNIX) + +# catsplosion - Accelerates pregnancy +# Author: Zhentar +ADD_EXECUTABLE(dfcatsplosion catsplosion.cpp) +TARGET_LINK_LIBRARIES(dfcatsplosion dfhack) + +# findnameindexes +# Author: belal +#ADD_EXECUTABLE(dffindnameindexes findnameindexes.cpp) +#TARGET_LINK_LIBRARIES(dffindnameindexes dfhack) + +# renamer - change the custom names and professions of creatures, sends keys to +# df directly +# Author: belal +#ADD_EXECUTABLE(dfrenamer renamer.cpp) +#TARGET_LINK_LIBRARIES(dfrenamer dfhack) \ No newline at end of file diff --git a/examples/catsplosion.cpp b/tools/playground/catsplosion.cpp similarity index 91% rename from examples/catsplosion.cpp rename to tools/playground/catsplosion.cpp index 27f8c8fa5..08d5c8961 100644 --- a/examples/catsplosion.cpp +++ b/tools/playground/catsplosion.cpp @@ -4,7 +4,6 @@ // and due within 2 in-game hours... #include -#include #include #include #include @@ -15,14 +14,8 @@ #include using namespace std; -#include -#include -#include -#include -#include +#include #include -#include -#include using namespace DFHack; @@ -68,10 +61,12 @@ int main ( int argc, char** argv ) s_creatures.push_back("CAT"); } - DFHack::API DF("Memory.xml"); + DFHack::ContextManager DFMgr("Memory.xml"); + DFHack::Context *DF; try { - DF.Attach(); + DF = DFMgr.getSingleContext(); + DF->Attach(); } catch (exception& e) { @@ -82,10 +77,10 @@ int main ( int argc, char** argv ) return 1; } - proc = DF.getProcess(); - mem = DF.getMemoryInfo(); - DFHack::Materials *Mats = DF.getMaterials(); - DFHack::Creatures *Cre = DF.getCreatures(); + proc = DF->getProcess(); + mem = DF->getMemoryInfo(); + DFHack::Materials *Mats = DF->getMaterials(); + DFHack::Creatures *Cre = DF->getCreatures(); creature_pregnancy_offset = mem->getOffset("creature_pregnancy"); if(!Mats->ReadCreatureTypesEx()) @@ -168,7 +163,7 @@ int main ( int argc, char** argv ) cout << totalchanged << " pregnancies accelerated. Total creatures checked: " << totalcount << "." << endl; Cre->Finish(); - DF.Detach(); + DF->Detach(); #ifndef LINUX_BUILD cout << "Done. Press any key to continue" << endl; cin.ignore(); diff --git a/tools/dfbauxite.cpp b/tools/playground/dfbauxite.cpp similarity index 97% rename from tools/dfbauxite.cpp rename to tools/playground/dfbauxite.cpp index c0012854d..3a2fdb978 100644 --- a/tools/dfbauxite.cpp +++ b/tools/playground/dfbauxite.cpp @@ -15,14 +15,13 @@ Based on code from and uses DFHack - www.sourceforge.net/projects/dfhack using namespace std; -#include -#include +#include +#include #include #include #include #include #include -#include using namespace DFHack; @@ -40,7 +39,7 @@ int main () int items; int found = 0, converted = 0; - DFHack::API DF("Memory.xml"); + DFHack::ContextManager DF("Memory.xml"); try { DF.Attach(); diff --git a/tools/digger.cpp b/tools/playground/digger.cpp similarity index 97% rename from tools/digger.cpp rename to tools/playground/digger.cpp index c3054941b..380e1e8c3 100644 --- a/tools/digger.cpp +++ b/tools/playground/digger.cpp @@ -5,7 +5,6 @@ // TODO add a sort of "sub-target" to dig() to make it able to designate stone as well #include -#include #include #include #include @@ -13,11 +12,9 @@ #include using namespace std; -#include -#include -#include +#include +#include #include -#include // counts the occurances of a certain element in a vector // used to determine of a given tile is a target @@ -327,10 +324,11 @@ int main (int argc, char** argv) } else { - DFHack::API DF("Memory.xml"); + DFHack::ContextManager DFMgr("Memory.xml"); + DFHack::Context *DF = DFMgr.getSingleContext(); try { - DF.Attach(); + DF->Attach(); } catch (exception& e) { @@ -340,14 +338,14 @@ int main (int argc, char** argv) #endif return 1; } - DFHack::Maps *Maps = DF.getMaps(); + DFHack::Maps *Maps = DF->getMaps(); if (Maps && Maps->Start()) { int count = dig(Maps, targets, max, origin[0],origin[1],origin[2], verbose); cout << count << " targets designated" << endl; Maps->Finish(); - if (!DF.Detach()) + if (!DF->Detach()) { cerr << "Unable to detach DF process" << endl; } diff --git a/tools/digger2.cpp b/tools/playground/digger2.cpp similarity index 94% rename from tools/digger2.cpp rename to tools/playground/digger2.cpp index 2fb30a997..91507bcc1 100644 --- a/tools/digger2.cpp +++ b/tools/playground/digger2.cpp @@ -13,22 +13,20 @@ #include #include -#include #include +#include #include #include #include #include +using namespace std; -#include -#include -#include #include -#include -#include - +#include +#include #define BLOCK_SIZE 16 + void dig(DFHack::Maps* layers, DFHack::Position* position, ::std::vector< ::std::string >& dig_map, bool verbose = false) { int32_t x_cent; int32_t y_cent; @@ -141,10 +139,11 @@ int main(int argc, char** argv) { } dig_map.resize(dig_map.size() - 1); - DFHack::API DF("Memory.xml"); + DFHack::ContextManager DFMgr("Memory.xml"); + DFHack::Context * DF = DFMgr.getSingleContext(); try { - DF.Attach(); + DF->Attach(); } catch (::std::exception& e) { ::std::cerr << e.what() << ::std::endl; #ifndef LINUX_BUILD @@ -153,15 +152,15 @@ int main(int argc, char** argv) { return 1; } - DFHack::Maps *layers = DF.getMaps(); + DFHack::Maps *layers = DF->getMaps(); if (layers && layers->Start()) { - dig(layers, DF.getPosition(), dig_map, true); + dig(layers, DF->getPosition(), dig_map, true); ::std::cout << "Finished digging" << ::std::endl; layers->Finish(); - if (!DF.Detach()) { + if (!DF->Detach()) { ::std::cerr << "Unable to detach DF process" << ::std::endl; } diff --git a/examples/findnameindexes.cpp b/tools/playground/findnameindexes.cpp similarity index 94% rename from examples/findnameindexes.cpp rename to tools/playground/findnameindexes.cpp index 5dfbeaf0d..6a52a2c24 100644 --- a/examples/findnameindexes.cpp +++ b/tools/playground/findnameindexes.cpp @@ -1,5 +1,8 @@ -// Dwarf fortress names are a complicated beast, in objects they are displayed as indexes into the language vectors -// use this tool if you are trying to find what the indexes are for a displayed name, so you can then search for it in your object +// Dwarf fortress names are a complicated beast, in objects they are displayed +// as indexes into the language vectors +// +// use this tool if you are trying to find what the indexes are for a displayed +// name, so you can then search for it in your object #include #include @@ -45,7 +48,7 @@ uint32_t endian_swap(uint32_t x) int main (void) { - DFHack::API DF("Memory.xml"); + DFHack::ContextManager DF("Memory.xml"); try { DF.Attach(); diff --git a/tools/playground/incrementalsearch.cpp b/tools/playground/incrementalsearch.cpp new file mode 100644 index 000000000..cc047466c --- /dev/null +++ b/tools/playground/incrementalsearch.cpp @@ -0,0 +1,369 @@ +// this will be an incremental search tool in the future. now it is just a memory region dump thing + +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +#ifndef LINUX_BUILD + #define WINVER 0x0500 + // this one prevents windows from infecting the global namespace with filth + #define NOMINMAX + #define WIN32_LEAN_AND_MEAN + #include +#endif + +#include + +//TODO: lots of optimization +void searchLoop(DFHack::ContextManager & DFMgr, vector & ranges, int size, int alignment) +{ + int32_t test1; + int32_t test2; + vector found; + vector newfound; + found.reserve(100000); + newfound.reserve(100000); + //bool initial = 1; + cout << "search ready - insert integers, 'p' for results" << endl; + string select; + while (1) + { + cout << ">>"; + std::getline(cin, select); + if(select == "p") + { + cout << "Found addresses:" << endl; + for(int i = 0; i < found.size();i++) + { + cout << hex << "0x" << found[i] << endl; + } + } + else if(sscanf(select.c_str(),"%d", &test1) == 1) + { + // refresh the list of processes, get first suitable, attach + DFMgr.Refresh(); + DFHack::Context * DF = DFMgr.getSingleContext(); + DF->Attach(); + + newfound.clear(); + bool initial = found.empty(); + if(initial) + { + // for each range + for (int i = 0; i < ranges.size();i++) + { + // can't read? range is invalid to us + if(!ranges[i].read) + continue; + //loop + for(uint64_t offset = ranges[i].start;offset <= ranges[i].end - size; offset+=alignment) + { + DF->ReadRaw(offset, size, (uint8_t *) &test2); + if(test1 == test2 ) + found.push_back(offset); + } + } + cout << "found " << found.size() << " addresses" << endl; + } + else + { + for(int j = 0; j < found.size();j++) + { + DF->ReadRaw(found[j], size, (uint8_t *) &test2); + if(test1 == test2) + { + newfound.push_back(found[j]); + } + } + cout << "matched " << newfound.size() << " addresses out of " << found.size() << endl; + found = newfound; + } + DF->Detach(); + } + else break; + } +} + +typedef struct +{ + uint32_t start; + uint32_t finish; + uint32_t alloc_finish; +} vecTriplet; + +void searchLoopVector(DFHack::ContextManager & DFMgr, vector & ranges, uint32_t element_size) +{ + vecTriplet load; + uint32_t length; + vector found; + vector newfound; + found.reserve(100000); + newfound.reserve(100000); + //bool initial = 1; + cout << "search ready - insert vector length" << endl; + string select; + while (1) + { + cout << ">>"; + std::getline(cin, select); + if(select == "p") + { + cout << "Found vectors:" << endl; + for(int i = 0; i < found.size();i++) + { + cout << hex << "0x" << found[i] << endl; + } + } + else if(sscanf(select.c_str(),"%d", &length) == 1) + { + // refresh the list of processes, get first suitable, attach + DFMgr.Refresh(); + DFHack::Context * DF = DFMgr.getSingleContext(); + DF->Attach(); + + // clear the list of found addresses + found.clear(); + + // for each range + for (int i = 0; i < ranges.size();i++) + { + // can't read? range is invalid to us + if(!ranges[i].read) + continue; + //loop + for(uint64_t offset = ranges[i].start;offset <= ranges[i].end - sizeof(vecTriplet); offset+=4) + { + DF->ReadRaw(offset, sizeof(vecTriplet), (uint8_t *) &load); + if(load.start <= load.finish && load.finish <= load.alloc_finish) + if((load.finish - load.start) / element_size == length) + found.push_back(offset); + } + } + cout << "found " << found.size() << " addresses" << endl; + + // detach again + DF->Detach(); + } + else + { + break; + } + } +} +void mkcopy(DFHack::ContextManager & DFMgr, vector & ranges, uint32_t element_size) +{ + DFMgr.Refresh(); + DFHack::Context * DF = DFMgr.getSingleContext(); + DF->Attach(); + for (int i = 0; i < ranges.size();i++) + { + // can't read? range is invalid to us + if(!ranges[i].read) + continue; + char * buffah = (char *) malloc(ranges[i].end - ranges[i].start); + if(buffah) + { + DF->ReadRaw(ranges[i].start,ranges[i].end - ranges[i].start, (uint8_t *) buffah); + cerr << "buffer for range " << i << " allocated and filled" << endl; + free(buffah); + cerr << "and freed" << endl; + } + else + cerr << "buffer for range " << i << " failed to allocate" << endl; + //loop + /* + for(uint64_t offset = ranges[i].start;offset <= ranges[i].end - sizeof(vecTriplet); offset+=4) + { + DF->ReadRaw(offset, sizeof(vecTriplet), (uint8_t *) &load); + if(load.start <= load.finish && load.finish <= load.alloc_finish) + if((load.finish - load.start) / element_size == length) + found.push_back(offset); + } + */ + } + DF->Detach(); + DFMgr.purge(); +} + +int main (void) +{ + string select; + DFHack::ContextManager DFMgr("Memory.xml"); + DFHack::Context * DF = DFMgr.getSingleContext(); + try + { + DF->Attach(); + } + catch (exception& e) + { + cerr << e.what() << endl; + #ifndef LINUX_BUILD + cin.ignore(); + #endif + return 1; + } + DFHack::Process * p = DF->getProcess(); + vector ranges; + vector selected_ranges; + p->getMemRanges(ranges); + cout << "Which range to search? (default is 1-4)" << endl; + for(int i = 0; i< ranges.size();i++) + { + cout << dec << "(" << i << ") "; + ranges[i].print(); + } + + try_again_ranges: + cout << ">>"; + std::getline(cin, select); + int start, end; + if(select.empty()) + { + // empty input, assume default. observe the length of the memory range vector + // these are hardcoded values, intended for my convenience only + if(p->getDescriptor()->getOS() == DFHack::memory_info::OS_WINDOWS) + { + start = min(11, (int)ranges.size()); + end = min(14, (int)ranges.size()); + } + else if(p->getDescriptor()->getOS() == DFHack::memory_info::OS_LINUX) + { + start = min(11, (int)ranges.size()); + end = min(14, (int)ranges.size()); + } + else + { + start = 1; + end = 1; + } + } + // I like the C variants here. much less object clutter + else if(sscanf(select.c_str(), "%d-%d", &start, &end) == 2) + { + start = min(start, (int)ranges.size()); + end = min(end, (int)ranges.size()); + } + else + { + goto try_again_ranges; // yes, this is a goto. bite me. + } + end++; + cout << "selected ranges:" <>"; + std::getline(cin, select); + int mode; + if(select.empty()) + { + mode = 1; + } + else if( sscanf(select.c_str(), "%d", &mode) == 1 ) + { + if(mode != 1 && mode != 2 && mode != 3) + { + goto try_again_type; + } + } + else + { + goto try_again_type; + } + if(mode == 1) + { + // input / validation of variable size + try_again_size: + cout << "Select searched variable size (1,2,4 bytes, default is 4)" << endl; + cout << ">>"; + std::getline(cin, select); + int size; + if(select.empty()) + { + size = 4; + } + else if( sscanf(select.c_str(), "%d", &size) == 1 ) + { + if(/*size != 8 &&*/ size != 4 && size != 2 && size != 1) + { + goto try_again_size; + } + } + else + { + goto try_again_size; + } + + // input / validation of variable alignment (default is to use the same alignment as size) + try_again_align: + cout << "Variable alignment (1,2,4 bytes, default is " << size << ")" << endl; + cout << ">>"; + std::getline(cin, select); + int alignment = size; + if(select.empty()) + { + alignment = size; + } + else if( sscanf(select.c_str(), "%d", &alignment) == 1 ) + { + if(/*alignment != 8 &&*/ alignment != 4 && alignment != 2 && alignment != 1) + { + goto try_again_align; + } + } + else + { + goto try_again_align; + } + // we detach, searchLoop looks for the process again. + DF->Detach(); + searchLoop(DFMgr, selected_ranges, size, alignment); + } + else if(mode == 2)// vector + { + // input / validation of variable size + try_again_vsize: + cout << "Select searched vector item size (in bytes, default is 4)" << endl; + cout << ">>"; + std::getline(cin, select); + uint32_t size; + if(select.empty()) + { + size = 4; + } + else if( sscanf(select.c_str(), "%d", &size) == 1 ) + { + if(size == 0) + { + goto try_again_vsize; + } + } + else + { + goto try_again_vsize; + } + // we detach, searchLoop looks for the process again. + DF->Detach(); + searchLoopVector(DFMgr, selected_ranges,size); + } + else if(mode == 3)// string + { + mkcopy(DFMgr, selected_ranges,0); + //searchLoopString(DF, selected_ranges); + } + #ifndef LINUX_BUILD + cout << "Done. Press any key to continue" << endl; + cin.ignore(); + #endif + return 0; +} diff --git a/tools/itemdesignator.cpp b/tools/playground/itemdesignator.cpp similarity index 99% rename from tools/itemdesignator.cpp rename to tools/playground/itemdesignator.cpp index ad51ea00c..35e1cfdf6 100644 --- a/tools/itemdesignator.cpp +++ b/tools/playground/itemdesignator.cpp @@ -189,7 +189,7 @@ void printItem(DFHack::t_item item, const string & typeString,const matGlosses & int main () { - DFHack::API DF ("Memory.xml"); + DFHack::ContextManager DF ("Memory.xml"); cout << "This utility lets you mass-designate items by type and material." << endl << "Like set on fire all MICROCLINE item_stone..." << endl << "Some unusual combinations might be untested and cause the program to crash..."<< endl diff --git a/tools/playground/moodump.cpp b/tools/playground/moodump.cpp new file mode 100644 index 000000000..a6cffd854 --- /dev/null +++ b/tools/playground/moodump.cpp @@ -0,0 +1,119 @@ +#include +#include +#include +#include +using namespace std; +#include + +DFHack::Materials * Materials; +DFHack::memory_info *mem; +vector< vector > englishWords; +vector< vector > foreignWords; + +int main (int numargs, char ** args) +{ + DFHack::ContextManager DFMgr("Memory.xml"); + DFHack::Context *DF = DFMgr.getSingleContext(); + DFHack::Process * p; + try + { + DF->Attach(); + } + catch (exception& e) + { + cerr << e.what() << endl; + #ifndef LINUX_BUILD + cin.ignore(); + #endif + return 1; + } + p = DF->getProcess(); + string check = ""; + if(numargs == 2) + check = args[1]; + + DFHack::Creatures * Creatures = DF->getCreatures(); + Materials = DF->getMaterials(); + DFHack::Translation * Tran = DF->getTranslation(); + + uint32_t numCreatures; + if(!Creatures->Start(numCreatures)) + { + cerr << "Can't get creatures" << endl; + #ifndef LINUX_BUILD + cin.ignore(); + #endif + return 1; + } + if(!numCreatures) + { + cerr << "No creatures to print" << endl; + #ifndef LINUX_BUILD + cin.ignore(); + #endif + return 1; + } + mem = DF->getMemoryInfo(); + + if(!Materials->ReadInorganicMaterials()) + { + cerr << "Can't get the inorganics types." << endl; + return 1; + } + if(!Materials->ReadCreatureTypesEx()) + { + cerr << "Can't get the creature types." << endl; + return 1; + } + if(!Tran->Start()) + { + cerr << "Can't get name tables" << endl; + return 1; + } + vector addrs; + //DF.InitViewAndCursor(); + for(uint32_t i = 0; i < numCreatures; i++) + { + DFHack::t_creature temp; + unsigned int current_job; + unsigned int mat_start; + unsigned int mat_end; + unsigned int j,k; + unsigned int matptr; + + Creatures->ReadCreature(i,temp); + if(temp.mood>=0) + { + current_job = p->readDWord(temp.origin + 0x390); + if(current_job == 0) + continue; + mat_start = p->readDWord(current_job + 0xa4 + 4*3); + mat_end = p->readDWord(current_job + 0xa4 + 4*4); + for(j=mat_start;jreadDWord(j); + for(k=0;k<4;k++) + printf("%.4X ", p->readWord(matptr + k*2)); + for(k=0;k<3;k++) + printf("%.8X ", p->readDWord(matptr + k*4 + 0x8)); + for(k=0;k<2;k++) + printf("%.4X ", p->readWord(matptr + k*2 + 0x14)); + for(k=0;k<3;k++) + printf("%.8X ", p->readDWord(matptr + k*4 + 0x18)); + for(k=0;k<4;k++) + printf("%.2X ", p->readByte(matptr + k + 0x24)); + for(k=0;k<6;k++) + printf("%.8X ", p->readDWord(matptr + k*4 + 0x28)); + for(k=0;k<4;k++) + printf("%.2X ", p->readByte(matptr + k + 0x40)); + for(k=0;k<9;k++) + printf("%.8X ", p->readDWord(matptr + k*4 + 0x44)); + printf(" [%p]\n", matptr); + } + } + } + Creatures->Finish(); + DF->Detach(); + return 0; +} + diff --git a/examples/renamer.cpp b/tools/playground/renamer.cpp similarity index 95% rename from examples/renamer.cpp rename to tools/playground/renamer.cpp index 927c620c7..c08fb0bfc 100644 --- a/examples/renamer.cpp +++ b/tools/playground/renamer.cpp @@ -22,7 +22,7 @@ vector< vector > foreignWords; uint32_t numCreatures; vector creaturestypes; -void printDwarves(DFHack::API & DF) +void printDwarves(DFHack::ContextManager & DF) { int dwarfCounter = 0; DFHack::Creatures * c = DF.getCreatures(); @@ -57,7 +57,7 @@ void printDwarves(DFHack::API & DF) } } -bool getDwarfSelection(DFHack::API & DF, DFHack::t_creature & toChange,string & changeString, string & commandString,int & eraseAmount,int &dwarfNum,bool &isName) +bool getDwarfSelection(DFHack::ContextManager & DF, DFHack::t_creature & toChange,string & changeString, string & commandString,int & eraseAmount,int &dwarfNum,bool &isName) { static string lastText; bool dwarfSuccess = false; @@ -142,7 +142,7 @@ bool getDwarfSelection(DFHack::API & DF, DFHack::t_creature & toChange,string & return true; } -bool waitTillChanged(DFHack::API &DF, int creatureToCheck, string changeValue, bool isName) +bool waitTillChanged(DFHack::ContextManager &DF, int creatureToCheck, string changeValue, bool isName) { DFHack::DFWindow * w = DF.getWindow(); DF.Suspend(); @@ -181,7 +181,7 @@ bool waitTillChanged(DFHack::API &DF, int creatureToCheck, string changeValue, b } -bool waitTillScreenState(DFHack::API &DF, string screenState,bool EqualTo=true) +bool waitTillScreenState(DFHack::ContextManager &DF, string screenState,bool EqualTo=true) { DFHack::DFWindow * w = DF.getWindow(); DFHack::t_viewscreen current; @@ -207,7 +207,7 @@ bool waitTillScreenState(DFHack::API &DF, string screenState,bool EqualTo=true) } -bool waitTillCursorState(DFHack::API &DF, bool On) +bool waitTillCursorState(DFHack::ContextManager &DF, bool On) { DFHack::DFWindow * w = DF.getWindow(); int32_t x,y,z; @@ -232,7 +232,7 @@ bool waitTillCursorState(DFHack::API &DF, bool On) } -bool waitTillMenuState(DFHack::API &DF, uint32_t menuState,bool EqualTo=true) +bool waitTillMenuState(DFHack::ContextManager &DF, uint32_t menuState,bool EqualTo=true) { int tryCount = 0; DFHack::DFWindow * w = DF.getWindow(); @@ -256,7 +256,7 @@ bool waitTillMenuState(DFHack::API &DF, uint32_t menuState,bool EqualTo=true) } -bool moveToBaseWindow(DFHack::API &DF) +bool moveToBaseWindow(DFHack::ContextManager &DF) { DFHack::DFWindow * w = DF.getWindow(); DFHack::t_viewscreen current; @@ -283,7 +283,7 @@ bool moveToBaseWindow(DFHack::API &DF) } -bool setCursorToCreature(DFHack::API &DF) +bool setCursorToCreature(DFHack::ContextManager &DF) { DFHack::DFWindow * w = DF.getWindow(); int32_t x,y,z; @@ -306,7 +306,7 @@ bool setCursorToCreature(DFHack::API &DF) int main (void) { - DFHack::API DF("Memory.xml"); + DFHack::ContextManager DF("Memory.xml"); DFHack::Creatures *c; DFHack::Materials *m; try diff --git a/tools/playground/test.cpp b/tools/playground/test.cpp new file mode 100644 index 000000000..e62b35d2a --- /dev/null +++ b/tools/playground/test.cpp @@ -0,0 +1,38 @@ +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +#include +using namespace DFHack; + +int main (int numargs, const char ** args) +{ + DFHack::ContextManager DFMgr("Memory.xml"); + DFHack::Context * DF; + try + { + DF = DFMgr.getSingleContext(); + DF->Attach(); + } + catch (exception& e) + { + cerr << e.what() << endl; + #ifndef LINUX_BUILD + cin.ignore(); + #endif + return 1; + } + + // DO STUFF HERE + + #ifndef LINUX_BUILD + cout << "Done. Press any key to continue" << endl; + cin.ignore(); + #endif + return 0; +} diff --git a/tools/CMakeLists.txt b/tools/supported/CMakeLists.txt similarity index 50% rename from tools/CMakeLists.txt rename to tools/supported/CMakeLists.txt index 611a638a4..c8b278997 100644 --- a/tools/CMakeLists.txt +++ b/tools/supported/CMakeLists.txt @@ -9,10 +9,6 @@ ENDIF(UNIX) ADD_EXECUTABLE(dfreveal reveal.cpp) TARGET_LINK_LIBRARIES(dfreveal dfhack) -# a reveal clone -ADD_EXECUTABLE(dfmoodump moodump.cpp) -TARGET_LINK_LIBRARIES(dfmoodump dfhack) - # prospector - produces a list of available materials and their quantities ADD_EXECUTABLE(dfprospector prospector.cpp) TARGET_LINK_LIBRARIES(dfprospector dfhack) @@ -33,50 +29,41 @@ TARGET_LINK_LIBRARIES(dfunstuck dfhack) ADD_EXECUTABLE(dfprobe probe.cpp) TARGET_LINK_LIBRARIES(dfprobe dfhack) -IF(UNIX) -# incrementalsearch - a bit like cheat engine, only DF-specific, very basic -# and Linux-only -ADD_EXECUTABLE(dfincremental incrementalsearch.cpp) -TARGET_LINK_LIBRARIES(dfincremental dfhack) -ENDIF(UNIX) +# attachtest - 100x attach/detach, suspend/resume +ADD_EXECUTABLE(dfattachtest attachtest.cpp) +TARGET_LINK_LIBRARIES(dfattachtest dfhack) -# bauxite - turn all mechanisms into bauxite mechanisms -# Author: Alex Legg -#ADD_EXECUTABLE(dfbauxite dfbauxite.cpp) -#TARGET_LINK_LIBRARIES(dfbauxite dfhack) +# a benchmark program, reads the map 1000x +ADD_EXECUTABLE(dfexpbench expbench.cpp) +TARGET_LINK_LIBRARIES(dfexpbench dfhack) -# digger - designate for digging by tile class -# Author: mizipzor -ADD_EXECUTABLE(dfdigger digger.cpp) -TARGET_LINK_LIBRARIES(dfdigger dfhack) +# suspendtest - test if suspend works. df should stop responding when suspended +# by dfhack +ADD_EXECUTABLE(dfsuspend suspendtest.cpp) +TARGET_LINK_LIBRARIES(dfsuspend dfhack) -# digger2 - designate for digging from a text file -# Author: rOut -ADD_EXECUTABLE(dfdigger2 digger2.cpp) -TARGET_LINK_LIBRARIES(dfdigger2 dfhack) +# flows - check flows impact on fps +ADD_EXECUTABLE(dfflows flows.cpp) +TARGET_LINK_LIBRARIES(dfflows dfhack) -# itemdesignator - change some item designations (dump, forbid, on-fire) for all -# items of a given type and material -# Author: belal -#ADD_EXECUTABLE(dfitemdesignator itemdesignator.cpp) -#TARGET_LINK_LIBRARIES(dfitemdesignator dfhack) - -# a magma creation tool -# Author: Aleric +# liquids manipulation tool +# Original author: Aleric ADD_EXECUTABLE(dfliquids liquids.cpp) TARGET_LINK_LIBRARIES(dfliquids dfhack) IF(UNIX) install(TARGETS -#dfbauxite -#dfcleanmap -#dfdigger -dfincremental -#dfitemdesignator -#dfmagma_create -dfprospector dfreveal -dfmoodump +dfprospector +dfvdig +dfcleanmap +dfunstuck +dfprobe +dfattachtest +dfexpbench +dfsuspend +dfflows +dfliquids RUNTIME DESTINATION bin ) ENDIF(UNIX) diff --git a/examples/attachtest.cpp b/tools/supported/attachtest.cpp similarity index 86% rename from examples/attachtest.cpp rename to tools/supported/attachtest.cpp index 440bbfc5a..83cf426a0 100644 --- a/examples/attachtest.cpp +++ b/tools/supported/attachtest.cpp @@ -3,23 +3,22 @@ #include #include -#include #include #include using namespace std; -#include -#include -#include +#include int main (void) { time_t start, end; double time_diff; - DFHack::API DF("Memory.xml"); + DFHack::ContextManager DFMgr("Memory.xml"); + DFHack::Context* DF; try { - DF.Attach(); - DF.Detach(); + DF = DFMgr.getSingleContext(); + DF->Attach(); + DF->Detach(); } catch (exception& e) { @@ -67,17 +66,17 @@ int main (void) cout << "attach tests done in " << time_diff << " seconds." << endl; */ cout << "Testing suspend/resume" << endl; - DF.Attach(); + DF->Attach(); time(&start); for (int i = 0; i < 1000; i++) { - DF.Suspend(); + DF->Suspend(); if(i%10 == 0) cout << i / 10 << "%" << endl; - DF.Resume(); + DF->Resume(); } time(&end); - DF.Detach(); + DF->Detach(); time_diff = difftime(end, start); cout << "suspend tests done in " << time_diff << " seconds." << endl; diff --git a/tools/cleanmap.cpp b/tools/supported/cleanmap.cpp similarity index 67% rename from tools/cleanmap.cpp rename to tools/supported/cleanmap.cpp index a85432d5f..78081f7fd 100644 --- a/tools/cleanmap.cpp +++ b/tools/supported/cleanmap.cpp @@ -1,15 +1,12 @@ // Map cleaner. Removes all the snow, mud spills, blood and vomit from map tiles. #include -#include #include +#include +#include using namespace std; -#include -#include -#include -#include -#include +#include int main (void) { @@ -18,10 +15,11 @@ int main (void) uint32_t bytes_read = 0; vector splatter; - DFHack::API DF("Memory.xml"); + DFHack::ContextManager DFMgr("Memory.xml"); + DFHack::Context *DF = DFMgr.getSingleContext(); try { - DF.Attach(); + DF->Attach(); } catch (exception& e) { @@ -31,7 +29,7 @@ int main (void) #endif return 1; } - DFHack::Maps *Mapz = DF.getMaps(); + DFHack::Maps *Mapz = DF->getMaps(); // init the map if(!Mapz->Start()) @@ -64,25 +62,14 @@ int main (void) { uint32_t addr = vein.address_of; uint32_t offset = offsetof(DFHack::t_spattervein, intensity); - DF.WriteRaw(addr + offset,sizeof(zeroes),(uint8_t *) zeroes); + DF->WriteRaw(addr + offset,sizeof(zeroes),(uint8_t *) zeroes); } } - /* - // read block designations - DF.ReadOccupancy(x,y,z, &occupancies); - // change the hidden flag to 0 - for (uint32_t i = 0; i < 16;i++) for (uint32_t j = 0; j < 16;j++) - { - occupancies[i][j].unibits.splatter = 0; - } - // write the designations back - DF.WriteOccupancy(x,y,z, &occupancies); - */ } } } } - DF.Detach(); + DF->Detach(); #ifndef LINUX_BUILD cout << "Done. Press any key to continue" << endl; cin.ignore(); diff --git a/examples/expbench.cpp b/tools/supported/expbench.cpp similarity index 92% rename from examples/expbench.cpp rename to tools/supported/expbench.cpp index 579f7ab4a..9141e83f3 100644 --- a/examples/expbench.cpp +++ b/tools/supported/expbench.cpp @@ -1,7 +1,6 @@ // This program exports the entire map from DF. Takes roughly 6.6 seconds for 1000 cycles on my Linux machine. ~px #include -#include #include #include #include @@ -9,9 +8,7 @@ using namespace std; -#include -#include -#include +#include void print_progress (int current, int total) { @@ -50,11 +47,13 @@ int main (int numargs, char** args) uint64_t bytes_read = 0; DFHack::mapblock40d Block; DFHack::Maps *Maps = 0; - DFHack::API DF("Memory.xml"); + DFHack::ContextManager DFMgr("Memory.xml"); + DFHack::Context *DF; try { - DF.Attach(); - Maps = DF.getMaps(); + DF = DFMgr.getSingleContext(); + DF->Attach(); + Maps = DF->getMaps(); } catch (exception& e) { @@ -92,7 +91,7 @@ int main (int numargs, char** args) } Maps->Finish(); } - DF.Detach(); + DF->Detach(); time(&end); time_diff = difftime(end, start); cout << num_blocks << " blocks read" << endl; diff --git a/examples/flows.cpp b/tools/supported/flows.cpp similarity index 82% rename from examples/flows.cpp rename to tools/supported/flows.cpp index 352a16da2..989cae319 100644 --- a/examples/flows.cpp +++ b/tools/supported/flows.cpp @@ -1,23 +1,24 @@ -// This is a reveal program. It reveals the map. +// This tool counts static tiles and active flows of water and magma. #include -#include #include using namespace std; -#include -#include -#include +#include int main (void) { uint32_t x_max,y_max,z_max; DFHack::designations40d designations; - DFHack::API DF("Memory.xml"); + DFHack::ContextManager DFMgr("Memory.xml"); + DFHack::Context * DF; + DFHack::Maps *Maps; try { - DF.Attach(); + DF = DFMgr.getSingleContext(); + DF->Attach(); + Maps = DF->getMaps(); } catch (exception& e) { @@ -27,8 +28,6 @@ int main (void) #endif return 1; } - - DFHack::Maps *Maps =DF.getMaps(); // init the map if(!Maps->Start()) { @@ -42,7 +41,7 @@ int main (void) Maps->getSize(x_max,y_max,z_max); // walk the map, count flowing tiles, magma, water uint32_t flow1=0, flow2=0, flowboth=0, water=0, magma=0; - cout << "Counting flows and liquids ."; + cout << "Counting flows and liquids ..."; for(uint32_t x = 0; x< x_max;x++) { for(uint32_t y = 0; y< y_max;y++) @@ -66,18 +65,19 @@ int main (void) if (designations[i][j].bits.liquid_type == DFHack::liquid_water) water++; } - // Maps->WriteDesignations(x, y, z, &designations); - // Maps->WriteBlockFlags(x, y, z, bflags); - cout << "."; } } } } - cout << endl << "Done." << endl; cout << "Blocks with liquid_1=true: " << flow1 << endl; cout << "Blocks with liquid_2=true: " << flow2 << endl; cout << "Blocks with both: " << flowboth << endl; cout << "Water tiles: " << water << endl; cout << "Magma tiles: " << magma << endl; + + cout << endl << "Done." << endl; + #ifndef LINUX_BUILD + cin.ignore(); + #endif return 0; } diff --git a/tools/liquids.cpp b/tools/supported/liquids.cpp similarity index 97% rename from tools/liquids.cpp rename to tools/supported/liquids.cpp index 2253048dc..d125c7ad1 100644 --- a/tools/liquids.cpp +++ b/tools/supported/liquids.cpp @@ -2,15 +2,12 @@ // enable magma buildings at this time. #include -#include #include +#include using namespace std; -#include -#include -#include -#include -#include +#include +#include int main (void) { @@ -20,14 +17,16 @@ int main (void) DFHack::t_temperatures temp1,temp2; uint32_t x_max,y_max,z_max; - DFHack::API DF("Memory.xml"); + DFHack::ContextManager DFMgr("Memory.xml"); + DFHack::Context *DF; DFHack::Maps * Maps; DFHack::Position * Position; try { - DF.Attach(); - Maps = DF.getMaps(); - Position = DF.getPosition(); + DF=DFMgr.getSingleContext(); + DF->Attach(); + Maps = DF->getMaps(); + Position = DF->getPosition(); } catch (exception& e) { @@ -46,7 +45,7 @@ int main (void) while(!end) { Maps->getSize(x_max,y_max,z_max); - DF.Resume(); + DF->Resume(); string command = ""; cout <<"[" << mode << ":" << amount << ":" << flowmode << "]# "; getline(cin, command); @@ -145,7 +144,7 @@ int main (void) amount = 7; else if(command.empty()) { - DF.Suspend(); + DF->Suspend(); do { if(!Maps->Start()) @@ -303,7 +302,7 @@ int main (void) } while (0); } } - DF.Detach(); + DF->Detach(); #ifndef LINUX_BUILD cout << "Done. Press any key to continue" << endl; cin.ignore(); diff --git a/tools/probe.cpp b/tools/supported/probe.cpp similarity index 87% rename from tools/probe.cpp rename to tools/supported/probe.cpp index 643d5b513..4353d48ba 100644 --- a/tools/probe.cpp +++ b/tools/supported/probe.cpp @@ -3,34 +3,24 @@ #include #include #include -#include #include #include #include #include using namespace std; -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include using namespace DFHack; int main (int numargs, const char ** args) { - DFHack::API DF("Memory.xml"); + DFHack::ContextManager DFMgr("Memory.xml"); + DFHack::Context *DF = DFMgr.getSingleContext(); + try { - DF.Attach(); + DF->Attach(); } catch (exception& e) { @@ -41,10 +31,10 @@ int main (int numargs, const char ** args) return 1; } - DFHack::Position *Pos = DF.getPosition(); - DFHack::memory_info* mem = DF.getMemoryInfo(); - DFHack::Maps *Maps = DF.getMaps(); - DFHack::Process * p = DF.getProcess(); + DFHack::Position *Pos = DF->getPosition(); + DFHack::memory_info* mem = DF->getMemoryInfo(); + DFHack::Maps *Maps = DF->getMaps(); + DFHack::Process * p = DF->getProcess(); uint32_t designatus = mem->getOffset("map_data_designation"); uint32_t block_feature1 = mem->getOffset("map_data_feature_local"); uint32_t block_feature2 = mem->getOffset("map_data_feature_global"); diff --git a/tools/prospector.cpp b/tools/supported/prospector.cpp similarity index 96% rename from tools/prospector.cpp rename to tools/supported/prospector.cpp index 4f36ffe8c..514be1e3e 100644 --- a/tools/prospector.cpp +++ b/tools/supported/prospector.cpp @@ -8,7 +8,6 @@ // TODO: GUI #include -#include #include // for memset #include #include @@ -16,11 +15,8 @@ #include using namespace std; -#include -#include -#include -#include -#include +#include +#include int main (int argc, const char* argv[]) { @@ -62,10 +58,12 @@ int main (int argc, const char* argv[]) vector< vector > layerassign; - DFHack::API DF("Memory.xml"); + DFHack::ContextManager DFMgr("Memory.xml"); + DFHack::Context *DF; try { - DF.Attach(); + DF = DFMgr.getSingleContext(); + DF->Attach(); } catch (exception& e) { @@ -77,8 +75,8 @@ int main (int argc, const char* argv[]) } - DFHack::Maps * Maps = DF.getMaps(); - DFHack::Materials * Mats = DF.getMaterials(); + DFHack::Maps * Maps = DF->getMaps(); + DFHack::Materials * Mats = DF->getMaterials(); // init the map if(!Maps->Start()) @@ -291,7 +289,7 @@ int main (int argc, const char* argv[]) cout << Mats->inorganic[p->first].id << " : " << p->second << endl; } } - DF.Detach(); + DF->Detach(); #ifndef LINUX_BUILD cout << "Done. Press any key to continue" << endl; cin.ignore(); diff --git a/tools/reveal.cpp b/tools/supported/reveal.cpp similarity index 90% rename from tools/reveal.cpp rename to tools/supported/reveal.cpp index 82da1b2fe..66ec3d92f 100644 --- a/tools/reveal.cpp +++ b/tools/supported/reveal.cpp @@ -1,14 +1,11 @@ // This is a reveal program. It reveals the map. #include -#include #include +#include using namespace std; -#include -#include -#include - +#include struct hideblock { @@ -23,10 +20,12 @@ int main (void) uint32_t x_max,y_max,z_max; DFHack::designations40d designations; - DFHack::API DF("Memory.xml"); + DFHack::ContextManager DFMgr("Memory.xml"); + DFHack::Context *DF; try { - DF.Attach(); + DF = DFMgr.getSingleContext(); + DF->Attach(); } catch (exception& e) { @@ -37,7 +36,7 @@ int main (void) return 1; } - DFHack::Maps *Maps =DF.getMaps(); + DFHack::Maps *Maps =DF->getMaps(); // init the map if(!Maps->Start()) { @@ -80,14 +79,14 @@ int main (void) } } // FIXME: force game pause here! - DF.Detach(); + DF->Detach(); cout << "Map revealed. Close window/force exit to keep it that way." << endl; cout << "Press any key to unreveal. Don't close DF or unpause in that case!" << endl; cin.ignore(); cout << "Unrevealing... please wait." << endl; // FIXME: do some consistency checks here! - DF.Attach(); - Maps = DF.getMaps(); + DF->Attach(); + Maps = DF->getMaps(); Maps->Start(); for(int i = 0; i < hidesaved.size();i++) { diff --git a/examples/suspendtest.cpp b/tools/supported/suspendtest.cpp similarity index 79% rename from examples/suspendtest.cpp rename to tools/supported/suspendtest.cpp index 70cbe1816..ea29de7eb 100644 --- a/examples/suspendtest.cpp +++ b/tools/supported/suspendtest.cpp @@ -2,22 +2,21 @@ #include #include -#include #include #include #include using namespace std; -#include -#include - +#include int main (void) { string blah; - DFHack::API DF("Memory.xml"); + DFHack::ContextManager DFMgr("Memory.xml"); + DFHack::Context * DF; try { - DF.Attach(); + DF = DFMgr.getSingleContext(); + DF->Attach(); } catch (exception& e) { @@ -30,23 +29,23 @@ int main (void) cout << "Attached, DF should be suspended now" << endl; getline(cin, blah); - DF.Resume(); + DF->Resume(); cout << "Resumed, DF should be running" << endl; getline(cin, blah); - DF.Suspend(); + DF->Suspend(); cout << "Suspended, DF should be suspended now" << endl; getline(cin, blah); - DF.Resume(); + DF->Resume(); cout << "Resumed, testing ForceResume. Suspend using SysInternals Process Explorer" << endl; getline(cin, blah); - DF.ForceResume(); + DF->ForceResume(); cout << "ForceResumed. DF should be running." << endl; getline(cin, blah); - if(!DF.Detach()) + if(!DF->Detach()) { cerr << "Can't detach from DF" << endl; return 1; diff --git a/tools/unstuck.cpp b/tools/supported/unstuck.cpp similarity index 72% rename from tools/unstuck.cpp rename to tools/supported/unstuck.cpp index 6788e954b..2a74c3f0f 100644 --- a/tools/unstuck.cpp +++ b/tools/supported/unstuck.cpp @@ -2,22 +2,21 @@ #include #include -#include #include #include #include using namespace std; -#include -#include - +#include int main (void) { string blah; - DFHack::API DF("Memory.xml"); + DFHack::ContextManager DFMgr("Memory.xml"); + DFHack::Context *DF; try { - DF.Attach(); + DF = DFMgr.getSingleContext(); + DF->Attach(); } catch (exception& e) { @@ -27,12 +26,12 @@ int main (void) #endif return 1; } - - DF.ForceResume(); + + DF->ForceResume(); cout << "DF should be running again :)" << endl; getline(cin, blah); - if(!DF.Detach()) + if(!DF->Detach()) { cerr << "Can't detach from DF" << endl; return 1; diff --git a/tools/vdig.cpp b/tools/supported/vdig.cpp similarity index 96% rename from tools/vdig.cpp rename to tools/supported/vdig.cpp index f1cd1b706..80cab23e7 100644 --- a/tools/vdig.cpp +++ b/tools/supported/vdig.cpp @@ -1,5 +1,4 @@ #include -#include #include // for memset #include #include @@ -9,13 +8,8 @@ #include using namespace std; -#include -#include -#include -#include -#include -#include -#include +#include +#include #include #define MAX_DIM 0x300 @@ -289,11 +283,13 @@ int main (int argc, char* argv[]) cout << as.errorLog(); return 1; } - - DFHack::API DF("Memory.xml"); + + DFHack::ContextManager DFMgr("Memory.xml"); + DFHack::Context * DF; try { - DF.Attach(); + DF = DFMgr.getSingleContext(); + DF->Attach(); } catch (exception& e) { @@ -305,15 +301,15 @@ int main (int argc, char* argv[]) } uint32_t x_max,y_max,z_max; - DFHack::Maps * Maps = DF.getMaps(); - DFHack::Materials * Mats = DF.getMaterials(); - DFHack::Position * Pos = DF.getPosition(); + DFHack::Maps * Maps = DF->getMaps(); + DFHack::Materials * Mats = DF->getMaterials(); + DFHack::Position * Pos = DF->getPosition(); // init the map if(!Maps->Start()) { cerr << "Can't init map. Make sure you have a map loaded in DF." << endl; - DF.Detach(); + DF->Detach(); #ifndef LINUX_BUILD cin.ignore(); #endif @@ -329,16 +325,16 @@ int main (int argc, char* argv[]) while(cx == -30000) { cerr << "Cursor is not active. Point the cursor at a vein." << endl; - DF.Resume(); + DF->Resume(); cin.ignore(); - DF.Suspend(); + DF->Suspend(); Pos->getCursorCoords(cx,cy,cz); } Point xy ((uint32_t)cx,(uint32_t)cy,cz); if(xy.x == 0 || xy.x == tx_max - 1 || xy.y == 0 || xy.y == ty_max - 1) { cerr << "I won't dig the borders. That would be cheating!" << endl; - DF.Detach(); + DF->Detach(); #ifndef LINUX_BUILD cin.ignore(); #endif @@ -355,7 +351,7 @@ int main (int argc, char* argv[]) { cerr << "This tile is non-vein. Bye :)" << endl; delete MCache; - DF.Detach(); + DF->Detach(); #ifndef LINUX_BUILD cin.ignore(); #endif @@ -469,7 +465,7 @@ int main (int argc, char* argv[]) } MCache->WriteAll(); delete MCache; - DF.Detach(); + DF->Detach(); #ifndef LINUX_BUILD cout << "Done. Press any key to continue" << endl; cin.ignore();