Making ready for adding plugins. Fixes all over the place, more removal of obsolete parts.

develop
Petr Mrázek 2011-06-20 01:12:07 +02:00
parent e0fb8f7c81
commit f2b91d3269
75 changed files with 173 additions and 7529 deletions

@ -1,282 +1,87 @@
# main project file. use it from a build sub-folder, see COMPILE for details
## some generic CMake magic
cmake_minimum_required(VERSION 2.8.0 FATAL_ERROR)
PROJECT (dfhack)
cmake_minimum_required(VERSION 2.8.4 FATAL_ERROR)
project(dfhack)
SET(CMAKE_MODULE_PATH
${dfhack_SOURCE_DIR}/CMake/Modules
${CMAKE_MODULE_PATH}
)
if("${dfhack_SOURCE_DIR}" STREQUAL "${dfhack_BINARY_DIR}")
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
message(FATAL_ERROR "In-source builds are not allowed.")
endif()
SET(DFHACK_CONSISTENCY 1)
set(CPACK_PACKAGE_VERSION_MAJOR "0")
set(CPACK_PACKAGE_VERSION_MINOR "5")
set(CPACK_PACKAGE_VERSION_PATCH "15")
set(DFHACK_VERSION_MAJOR "0")
set(DFHACK_VERSION_MINOR "31")
set(DFHACK_VERSION_PATCH "25")
set(DFHACK_REVISION "1")
set(DFHACK_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
set(CPACK_PACKAGE_VERSION ${DFHACK_VERSION})
set(CPACK_PACKAGE_NAME "dfhack")
SET(CPACK_PACKAGE_VENDOR "dethware.org")
SET(CPACK_PACKAGE_CONTACT "peterix@dethware.org")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Memory hacks for Dwarf Fortress")
SET(CPACK_PACKAGE_DESCRIPTION
"DFHack is a Dwarf Fortress memory access library and a set of basic
tools using this library. The library is a work in progress, so things
might change as more tools are written for it.
.
It is an attempt to unite the various ways tools access DF memory and
allow for easier development of new tools.")
## setting the build type
IF(NOT DEFINED CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")
SET(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel.")
SET(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Release RelWithDebInfo.")
ENDIF()
## put everything in one big ugly directory to make MSVC and KDevelop debuggers happy
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${dfhack_BINARY_DIR}/bin")
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${dfhack_BINARY_DIR}/bin")
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${dfhack_BINARY_DIR}/bin")
SET(DFHACK_OUTPUT_DIR "${dfhack_BINARY_DIR}/bin" CACHE STRING "Where should be the produced libraries and binaries stored.")
## where to put things during the build (force MSVC to behave)
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${DFHACK_OUTPUT_DIR})
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${DFHACK_OUTPUT_DIR})
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${DFHACK_OUTPUT_DIR})
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${DFHACK_OUTPUT_DIR})
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL ${DFHACK_OUTPUT_DIR})
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_MINSIZEREL ${DFHACK_OUTPUT_DIR})
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${DFHACK_OUTPUT_DIR})
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO ${DFHACK_OUTPUT_DIR})
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELWITHDEBINFO ${DFHACK_OUTPUT_DIR})
## where to install things (after the build is done, classic 'make install' or package structure)
# the dfhack libraries will be installed here:
SET(DFHACK_LIBRARY_DESTINATION .)
# the dfhack tools will be installed here:
SET(DFHACK_BINARY_DESTINATION .)
# Memory.xml goes here:
SET(DFHACK_DATA_DESTINATION .)
# Includes go here:
SET(DFHACK_INCLUDES_DESTINATION dev/include)
# the Windows .lib files go here:
IF(WIN32)
set (DFHACK_INST_DEFAULT "portable")
ELSE()
set (DFHACK_INST_DEFAULT "linux")
ENDIF()
SET( DFHACK_INSTALL ${DFHACK_INST_DEFAULT} CACHE STRING
"Choose the install type:
'portable' for a portable zip or tar.gz package (windows default)
'linux' for generic packaging and system installs on linux (linux default)
'ubuntu-10.10' for ubuntu maverick package.")
IF(${DFHACK_INSTALL} STREQUAL "portable")
# the dfhack libraries will be installed here:
SET(DFHACK_LIBRARY_DESTINATION .)
# the dfhack tools will be installed here:
SET(DFHACK_BINARY_DESTINATION .)
# Memory.xml goes here:
SET(DFHACK_DATA_DESTINATION .)
# Includes go here:
SET(DFHACK_INCLUDES_DESTINATION dev/include)
# the Windows .lib files go here:
IF(WIN32)
SET(DFHACK_DEVLIB_DESTINATION dev)
SET(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION .)
ENDIF()
IF(UNIX)
SET(CMAKE_INSTALL_RPATH "$ORIGIN")
ENDIF()
# documentation goes here:
SET(DFHACK_USERDOC_DESTINATION .)
SET(DFHACK_DEVDOC_DESTINATION dev)
SET(DFHACK_DOXYGEN_DESTINATION dev/doxygen)
ENDIF()
# generic linux package in a .tar.gz
IF(${DFHACK_INSTALL} STREQUAL "linux")
if(WIN32)
MESSAGE(FATAL_ERROR "WTF are you doing?")
endif()
# set RPATH to always point at the dfhack lib using relative path.
SET(CMAKE_INSTALL_RPATH "$ORIGIN/../lib/")
# the dfhack libraries will be installed here:
SET(DFHACK_LIBRARY_DESTINATION lib)
# the dfhack tools will be installed here:
SET(DFHACK_BINARY_DESTINATION bin)
# Memory.xml goes here:
SET(DFHACK_DATA_DESTINATION share/dfhack)
# Includes go here:
SET(DFHACK_INCLUDES_DESTINATION include)
# documentation goes here:
SET(DFHACK_USERDOC_DESTINATION share/dfhack/doc)
SET(DFHACK_DEVDOC_DESTINATION share/dfhack/doc)
SET(DFHACK_DOXYGEN_DESTINATION share/dfhack/doc/doxygen)
ENDIF()
IF(${DFHACK_INSTALL} STREQUAL "ubuntu-10.10" OR ${DFHACK_INSTALL} STREQUAL "debian")
if(WIN32)
MESSAGE(FATAL_ERROR "WTF are you doing?")
endif()
# set RPATH to always point at the dfhack lib using relative path.
SET(CMAKE_INSTALL_RPATH "$ORIGIN/../lib/")
# the dfhack libraries will be installed here:
SET(DFHACK_LIBRARY_DESTINATION usr/lib)
# the dfhack tools will be installed here:
SET(DFHACK_BINARY_DESTINATION usr/bin)
# Memory.xml goes here:
SET(DFHACK_DATA_DESTINATION usr/share/dfhack)
# Includes go here:
SET(DFHACK_INCLUDES_DESTINATION usr/include)
# documentation goes here:
SET(DFHACK_USERDOC_DESTINATION usr/share/dfhack/doc)
SET(DFHACK_DEVDOC_DESTINATION usr/share/dfhack/doc)
SET(DFHACK_DOXYGEN_DESTINATION usr/share/dfhack/doc/doxygen)
INSTALL(FILES
"${CMAKE_CURRENT_SOURCE_DIR}/package/${DFHACK_INSTALL}/99-dfhack.conf"
DESTINATION etc/sysctl.d)
ENDIF()
## some options for the user/developer to play with
OPTION(BUILD_DFHACK_LIBRARY "Build the library. Needed for all the tools." ON)
OPTION(BUILD_DFHACK_C_BINDINGS "Build the C portion of the library." ON)
OPTION(BUILD_DFHACK_PYTHON_BINDINGS "Build/install the python wrapper." ON)
IF(WIN32)
OPTION(BUILD_DFHACK_DEVEL "Build the developer stuff." OFF)
ENDIF()
IF(UNIX)
OPTION(BUILD_DFHACK_DEVEL "Build the developer stuff." ON)
SET(DFHACK_DEVLIB_DESTINATION dev)
SET(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION .)
ENDIF()
OPTION(BUILD_DFHACK_DOXYGEN "Create doxygen documentation for developers" ON)
OPTION(BUILD_DFHACK_SUPPORTED "Build the supported tools." ON)
OPTION(BUILD_DFHACK_EXAMPLES "Build example tools" OFF)
OPTION(BUILD_DFHACK_PLAYGROUND "Build tools from the playground folder" OFF)
include_directories (${dfhack_SOURCE_DIR}/library/include/)
include_directories (${dfhack_SOURCE_DIR}/library/shm/)
include_directories (${dfhack_SOURCE_DIR}/library/depends/argstream/)
include_directories (${dfhack_SOURCE_DIR}/library/depends/xgetopt/)
# handle curses library bull**** on multiple platforms.
IF(UNIX)
find_package(Curses QUIET)
if(Curses_FOUND)
add_library(curses SHARED IMPORTED)
set_property(TARGET curses PROPERTY IMPORTED_LOCATION ${Curses_LIBRARY})
include_directories (${Curses_INCLUDE_PATH})
endif()
ELSE()
add_library(curses SHARED IMPORTED)
set_property(TARGET curses PROPERTY IMPORTED_LOCATION ${dfhack_SOURCE_DIR}/pdcurses/pdcurses.dll)
set_property(TARGET curses PROPERTY IMPORTED_IMPLIB ${dfhack_SOURCE_DIR}/pdcurses/pdcurses.lib)
include_directories (${dfhack_SOURCE_DIR}/pdcurses)
add_custom_target( curses-copy
COMMAND "${CMAKE_COMMAND}" -E make_directory ${dfhack_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/
COMMAND "${CMAKE_COMMAND}" -E copy "${dfhack_SOURCE_DIR}/pdcurses/pdcurses.dll" ${dfhack_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/
DEPENDS "${dfhack_SOURCE_DIR}/pdcurses/pdcurses.dll")
SET(Curses_FOUND TRUE)
INSTALL(FILES "${dfhack_SOURCE_DIR}/pdcurses/pdcurses.dll" DESTINATION ${DFHACK_BINARY_DESTINATION})
SET(CMAKE_INSTALL_RPATH "$ORIGIN")
ENDIF()
# documentation goes here:
SET(DFHACK_USERDOC_DESTINATION .)
SET(DFHACK_DEVDOC_DESTINATION dev)
SET(DFHACK_DOXYGEN_DESTINATION dev/doxygen)
# macro to save on typing in the tool subdirs
# builds a tool, links it to the dfhack lib and makes sure the dependency
# LOCAL_DEPNAME is built first, in case there is one
MACRO(DFHACK_TOOL TOOL_NAME TOOL_SOURCES)
ADD_EXECUTABLE(${TOOL_NAME} ${TOOL_SOURCES})
TARGET_LINK_LIBRARIES(${TOOL_NAME} dfhack)
if(DEFINED LOCAL_DEPNAME)
ADD_DEPENDENCIES(${TOOL_NAME} ${LOCAL_DEPNAME})
endif()
install(TARGETS
${TOOL_NAME}
RUNTIME DESTINATION ${DFHACK_BINARY_DESTINATION})
ENDMACRO()
# same as above builds a curses tool instead of plain terminal one.
MACRO(DFHACK_CURSES_TOOL TOOL_NAME TOOL_SOURCES)
IF(Curses_FOUND)
ADD_EXECUTABLE(${TOOL_NAME} ${TOOL_SOURCES})
TARGET_LINK_LIBRARIES(${TOOL_NAME} dfhack curses)
if(DEFINED LOCAL_DEPNAME)
ADD_DEPENDENCIES(${TOOL_NAME} ${LOCAL_DEPNAME})
endif()
if(WIN32)
ADD_DEPENDENCIES(${TOOL_NAME} curses-copy)
ENDIF()
install(TARGETS
${TOOL_NAME}
RUNTIME DESTINATION ${DFHACK_BINARY_DESTINATION})
ELSE()
MESSAGE(STATUS "Wide-character ncurses library not found - " ${TOOL_NAME} "can't be built")
ENDIF()
ENDMACRO()
## some options for the user/developer to play with
OPTION(BUILD_LIBRARY "Build the library that goes into DF." ON)
OPTION(BUILD_PLUGINS "Build the library that goes into DF." ON)
IF(BUILD_DFHACK_LIBRARY)
IF(BUILD_LIBRARY)
add_subdirectory (library)
IF(BUILD_DFHACK_PYTHON_BINDINGS)
MESSAGE("TODO: write CMakeLists.txt for the python things.")
ENDIF()
IF(BUILD_DFHACK_SUPPORTED)
add_subdirectory (tools/supported)
ENDIF()
IF(BUILD_DFHACK_EXAMPLES)
add_subdirectory (tools/examples)
ENDIF()
IF(BUILD_DFHACK_PLAYGROUND)
add_subdirectory (tools/playground)
ENDIF()
## install the default documentation files
install(FILES LICENSE Readme.html DESTINATION ${DFHACK_USERDOC_DESTINATION})
endif()
IF(BUILD_DFHACK_DOXYGEN AND BUILD_DFHACK_DEVEL)
add_subdirectory (doc)
# Packaging with CPack!
IF(UNIX)
SET(CPACK_GENERATOR "TGZ")
ENDIF()
IF(${DFHACK_INSTALL} STREQUAL "portable")
IF(UNIX)
SET(CPACK_GENERATOR "TGZ")
ENDIF()
IF(WIN32)
SET(CPACK_GENERATOR "ZIP")
# this includes the MSVC C++ DLLs in the package. Doesn't work with Express versions in general.
INCLUDE(InstallRequiredSystemLibraries)
ENDIF()
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${DFHACK_VERSION}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
INCLUDE(CPack)
IF(WIN32)
SET(CPACK_GENERATOR "ZIP")
# this includes the MSVC C++ DLLs in the package. Doesn't work with Express versions in general.
# we should be fine with the stuff DF already has packaged... so, commenting out
# INCLUDE(InstallRequiredSystemLibraries)
ENDIF()
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${DFHACK_VERSION}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
INCLUDE(CPack)
#-------------------------------------------------------------------------------
# Figure out debian architecture
#-------------------------------------------------------------------------------
FUNCTION(GET_DEBIAN_ARCHITECTURE arch)
SET(dpkgarch)
FIND_PROGRAM(DPKG_CMD dpkg)
IF(NOT DPKG_CMD)
MESSAGE(STATUS "Can not find dpkg in your path, default to i386.")
SET(${arch} i386 PARENT_SCOPE)
ENDIF()
EXECUTE_PROCESS(COMMAND "${DPKG_CMD}" --print-architecture
OUTPUT_VARIABLE dpkgarch
OUTPUT_STRIP_TRAILING_WHITESPACE )
SET(${arch} ${dpkgarch} PARENT_SCOPE)
ENDFUNCTION()
IF(${DFHACK_INSTALL} STREQUAL "ubuntu-10.10" OR ${DFHACK_INSTALL} STREQUAL "debian")
SET(CPACK_GENERATOR "DEB")
#wtf, wtf, wtf. force them to be empty
set(CMAKE_INSTALL_PREFIX "" FORCE)
set(CPACK_INSTALL_PREFIX "")
SET(CPACK_PACKAGING_INSTALL_PREFIX "")
set(CPACK_SET_DESTDIR true)
SET(CPACK_DEBIAN_PACKAGE_SECTION "Games") # yep. magma.
SET(CPACK_DEBIAN_PACKAGE_PRIORITY "optional") # very.
SET(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) # find deps automatically! hopefully... maybe...
SET(INSTSCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/package/${DFHACK_INSTALL}")
SET(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${INSTSCRIPT}/postinst;${INSTSCRIPT}/preinst;${INSTSCRIPT}/postrm")
GET_DEBIAN_ARCHITECTURE(PKG_ARCHITECTURE)
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}_${DFHACK_VERSION}-${DFHACK_REVISION}_${DFHACK_INSTALL}-${PKG_ARCHITECTURE}")
INCLUDE(CPack)
ENDIF()

File diff suppressed because it is too large Load Diff

@ -1 +0,0 @@
DFHack tools for DF 31.21

@ -1,6 +0,0 @@
mkdir MINGW32-debug
cd MINGW32-debug
cmake ..\.. -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE:string=Debug
cmake-gui .
mingw32-make 2> ..\mingw-build-log.txt
pause

@ -1,7 +0,0 @@
mkdir MINGW32-release
cd MINGW32-release
cmake ..\.. -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE:string=Release
cmake-gui .
mingw32-make 2> ..\mingw-build-log.txt
pause

@ -1,5 +0,0 @@
mkdir VC2005
cd VC2005
echo Pre-generating a build folder
cmake ..\.. -G"Visual Studio 8 2005"
cmake-gui .

@ -1,5 +0,0 @@
mkdir VC2008
cd VC2008
echo Pre-generating a build folder
cmake ..\.. -G"Visual Studio 9 2008"
cmake-gui .

@ -1,55 +0,0 @@
#!/usr/bin/expect
# procedure to attempt connecting; result 0 if OK, 1 otherwise
proc connect {} {
expect "login:"
send "kitteh\r"
expect "password:"
send "a\r"
expect {
kitteh {return 0}
failed return 1
"invalid password" return 1
timeout return 1
connected
}
# timed out
return 1
}
# procedure to do build stuff; result 0 if OK, 1 otherwise
proc dobuild {} {
set timeout -1
send "pkg-win32.bat\r\n"
puts "\nBuilding...\n"
expect {
"BUILD OK" {return 0}
"MSVC ERROR" {return 1}
"CMAKE ERROR" {return 1}
"ENV ERROR" {return 1}
}
}
spawn telnet win7
set rez [connect]
if { $rez == 1 } {
puts "\nError connecting to server!\n"
exit 1
}
send "net use X: \\\\vboxsvr\\projects\r\n"
expect "The command completed successfully."
send "X:\r\n"
expect "X:"
send "cd X:\\dfhack\\build\r\n"
expect "build"
set buildrez [dobuild]
if { $buildrez == 1 } {
puts "\nThere was an error during build.\n"
} else {
puts "\nAll OK.\n"
}
send "exit\r"
expect eof
exit $buildrez

@ -1,7 +0,0 @@
#!/bin/sh
rm -r debian
mkdir debian
cd debian
cmake ../.. -DCMAKE_BUILD_TYPE="Release" -DDFHACK_INSTALL="debian" -DMEMXML_DATA_PATH="/usr/share/dfhack" -DBUILD_DFHACK_C_BINDINGS=ON -DBUILD_DFHACK_DEVEL=ON -DBUILD_DFHACK_DOXYGEN=OFF -DBUILD_DFHACK_EXAMPLES=OFF -DBUILD_DFHACK_PLAYGROUND=OFF -DBUILD_DFHACK_PYTHON_BINDINGS=ON
make package
mv *.deb ../

@ -1,7 +0,0 @@
#!/bin/sh
rm -r ubuntu64
mkdir ubuntu64
cd ubuntu64
cmake ../.. -DCMAKE_BUILD_TYPE="Release" -DDFHACK_INSTALL="ubuntu-10.10" -DMEMXML_DATA_PATH="/usr/share/dfhack" -DDFHACK_PACKAGE_DIR=".." -DBUILD_DFHACK_C_BINDINGS=ON -DBUILD_DFHACK_DEVEL=ON -DBUILD_DFHACK_DOXYGEN=OFF -DBUILD_DFHACK_EXAMPLES=OFF -DBUILD_DFHACK_PLAYGROUND=OFF -DBUILD_DFHACK_PYTHON_BINDINGS=ON
make package
mv *.deb ../

@ -1,7 +0,0 @@
#!/bin/sh
rm -r ubuntu
mkdir ubuntu
cd ubuntu
cmake ../.. -DCMAKE_BUILD_TYPE="Release" -DDFHACK_INSTALL="ubuntu-10.10" -DMEMXML_DATA_PATH="/usr/share/dfhack" -DDFHACK_PACKAGE_DIR=".." -DBUILD_DFHACK_C_BINDINGS=ON -DBUILD_DFHACK_DEVEL=ON -DBUILD_DFHACK_DOXYGEN=OFF -DBUILD_DFHACK_EXAMPLES=OFF -DBUILD_DFHACK_PLAYGROUND=OFF -DBUILD_DFHACK_PYTHON_BINDINGS=ON
make package
mv *.deb ../

@ -1,37 +0,0 @@
@ECHO OFF
rd /S /Q MSVC10
mkdir MSVC10
cd MSVC10
echo CLEANUP DONE
cmake ..\.. -G"Visual Studio 10" -DDFHACK_INSTALL="portable" -DMEMXML_DATA_PATH="." -DBUILD_DFHACK_C_BINDINGS=OFF -DBUILD_DFHACK_DEVEL=OFF -DBUILD_DFHACK_DOXYGEN=OFF -DBUILD_DFHACK_EXAMPLES=OFF -DBUILD_DFHACK_PLAYGROUND=OFF -DBUILD_DFHACK_PYTHON_BINDINGS=OFF > ..\pkg-win32-cmake.log
if errorlevel 1 goto cmakeerror
echo CMAKE OK
call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" > ..\pkg-win32-env.log
if errorlevel 1 goto enverror
echo ENV OK
msbuild PACKAGE.vcxproj /p:Configuration=Release /l:FileLogger,Microsoft.Build.Engine;logfile=..\pkg-win32-msbuild.log;encoding=utf-8 -noconsolelogger > NUL
if errorlevel 1 goto msvcerror
move /Y *.zip ..
echo BUILD OK
set errorlevel=0
goto end
:cmakeerror
echo CMAKE ERROR
set errorlevel=1
goto end
:enverror
echo ENV ERROR
set errorlevel=1
goto end
:msvcerror
echo MSVC ERROR
set errorlevel=1
goto end
:end

@ -1,14 +0,0 @@
#/bin/sh
# Remote into a virtualbox VM to build with MSVC.
# Very specific to my own local setup. ~px
# VARS. TODO: parametrize
export DFHACK_VER=0.5.7
export PKG=dfhack-bin-$DFHACK_VER
export TARGET=Release
# let's build it all
VBoxManage startvm "7 Prof"
sleep 20
expect linux-remote.expect $TARGET

@ -1,13 +0,0 @@
import context
__all__ = [ "buildings",
"constructions",
"context",
"creatures",
"dftypes",
"flags",
"gui",
"items",
"maps",
"materials",
"vegetation" ]

@ -1,34 +0,0 @@
from ctypes import *
from dftypes import *
import util
libdfhack.Buildings_GetCustomWorkshopType.argtypes = [ c_void_p, POINTER(CustomWorkshop) ]
class Buildings(object):
def __init__(self, ptr):
self._b_ptr = ptr
def start(self):
num = c_uint()
if libdfhack.Buildings_Start(self._b_ptr, byref(num)) > 0:
return int(num.value)
else:
return -1
def finish(self):
return libdfhack.Buildings_Finish(self._b_ptr) > 0
def read(self, index):
b = Building()
if libdfhack.Buildings_Read(self._b_ptr, c_uint(index), byref(b)) > 0:
return b
else:
return None
def read_custom_workshop_types(self):
return libdfhack.Buildings_ReadCustomWorkshopTypes(self._b_ptr)
def get_custom_workshop_type(self, custom_workshop):
return libdfhack.Buildings_GetCustomWorkshopType(self._b_ptr, byref(custom_workshop))

@ -1,25 +0,0 @@
from ctypes import c_uint, byref
from dftypes import libdfhack, Construction
class Constructions(object):
def __init__(self, ptr):
self._c_ptr = ptr
def start(self):
num = c_uint()
if libdfhack.Constructions_Start(self._c_ptr, byref(num)) > 0:
return int(num.value)
else:
return -1
def finish(self):
return libdfhack.Constructions_Finish(self._c_ptr) > 0
def read(self, index):
c = Construction()
if libdfhack.Constructions_Read(self._c_ptr, c_uint(index), byref(c)) > 0:
return c
else:
return None

@ -1,191 +0,0 @@
from ctypes import *
from dftypes 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_getCreatures.restype = c_void_p
libdfhack.Context_getMaps.restype = c_void_p
libdfhack.Context_getGui.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
libdfhack.Context_getWorld.restype = c_void_p
libdfhack.Context_getWindowIO.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._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
self._world_obj = None
self._window_io_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):
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
self._world_obj = None
self._window_io_obj = None
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 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
@property
def world(self):
import world
if self._world_obj is None:
self._world_obj = world.World(libdfhack.Context_getWorld(self._c_ptr))
return self._world_obj
@property
def window_io(self):
import window_io
if self._window_io_obj is None:
self._window_io_obj = window_io.WindowIO(libdfhack.Context_getWindowIO(self._c_ptr))
return self._window_io_obj

@ -1,73 +0,0 @@
from ctypes import *
from dftypes import libdfhack, Creature, Material
import util
libdfhack.Creatures_WriteLabors.argtypes = [ c_void_p, c_uint, POINTER(c_ubyte) ]
libdfhack.Creatures_ReadJob.restype = POINTER(Material)
libdfhack.Creatures_ReadInventoryIdx.restype = POINTER(c_uint)
libdfhack.Creatures_ReadInventoryPtr.restype = POINTER(c_uint)
class Creatures(object):
def __init__(self, ptr):
print ptr
self._c_ptr = ptr
self._d_race_index = None
self._d_civ_id = None
def start(self):
n = c_uint(0)
if libdfhack.Creatures_Start(self._c_ptr, byref(n)) > 0:
return int(n.value)
else:
return -1
def finish(self):
return libdfhack.Creatures_Finish(self._c_ptr) > 0
def read_creature(self, index):
c = Creature()
if libdfhack.Creatures_ReadCreature(self._c_ptr, c_int(index), byref(c)) > 0:
return c
else:
return None
def read_creature_in_box(self, index, pos1, pos2):
c = Creature()
x1, y1, z1 = c_uint(pos1[0]), c_uint(pos1[1]), c_uint(pos1[2])
x2, y2, z2 = c_uint(pos2[0]), c_uint(pos2[1]), c_uint(pos2[2])
retval = libdfhack.Creatures_ReadCreatureInBox(self._c_ptr, byref(c), x1, y1, z1, x2, y2, z2)
return (retval, c)
def write_labors(self, index, labors):
return libdfhack.Creatures_WriteLabors(self._c_ptr, c_uint(index), labors) > 0
def read_job(self, creature):
job_ptr = libdfhack.Creatures_ReadJob(self._c_ptr, byref(creature))
jobs = None
if id(job_ptr) in dftypes.pointer_dict:
jobs = dftypes.pointer_dict[id(job_ptr)][1]
del dftypes.pointer_dict[id(job_ptr)]
return jobs
@property
def dwarf_race_index(self):
if self._d_race_index is None:
self._d_race_index =libdfhack.Creatures_GetDwarfRaceIndex(self._c_ptr)
return self._d_race_index
@property
def dwarf_civ_id(self):
if self._d_civ_id is None:
self._d_civ_id = libdfhack.Creatures_GetDwarfCivId(self._c_ptr)
return self._d_civ_id

@ -1,152 +0,0 @@
from ctypes import *
from pydftypes import *
libdfhack.API_Alloc.restype = c_void_p
libdfhack.API_Free.argtypes = [ c_void_p ]
libdfhack.API_getMemoryInfo.restype = c_void_p
libdfhack.API_getProcess.restype = c_void_p
libdfhack.API_getWindow.restype = c_void_p
libdfhack.API_getCreatures.restype = c_void_p
libdfhack.API_getMaps.restype = c_void_p
libdfhack.API_getGui.restype = c_void_p
libdfhack.API_getMaterials.restype = c_void_p
libdfhack.API_getTranslation.restype = c_void_p
libdfhack.API_getVegetation.restype = c_void_p
libdfhack.API_getBuildings.restype = c_void_p
libdfhack.API_getConstructions.restype = c_void_p
libdfhack.API_getItems.restype = c_void_p
class API(object):
def __init__(self, memory_path):
self._api_ptr = libdfhack.API_Alloc(create_string_buffer(memory_path))
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.API_Free(self._api_ptr)
def attach(self):
return libdfhack.API_Attach(self._api_ptr) > 0
def detach(self):
return libdfhack.API_Detach(self._api_ptr) > 0
def suspend(self):
return libdfhack.API_Suspend(self._api_ptr) > 0
def resume(self):
return libdfhack.API_Resume(self._api_ptr) > 0
def force_resume(self):
return libdfhack.API_ForceResume(self._api_ptr) > 0
def async_suspend(self):
return libdfhack.API_AsyncSuspend(self._api_ptr) > 0
@property
def is_attached(self):
return libdfhack.API_isAttached(self._api_ptr) > 0
@property
def is_suspended(self):
return libdfhack.API_isSuspended(self._api_ptr) > 0
@property
def materials(self):
import materials
if self._mat_obj is None:
self._mat_obj = materials.Materials(libdfhack.API_getMaterials(self._api_ptr))
return self._mat_obj
@property
def maps(self):
import maps
if self._map_obj is None:
self._map_obj = maps.Maps(libdfhack.API_getMaps(self._api_ptr))
return self._map_obj
@property
def vegetation(self):
import vegetation
if self._veg_obj is None:
self._veg_obj = vegetation.Vegetation(libdfhack.API_getVegetation(self._api_ptr))
return self._veg_obj
@property
def buildings(self):
import buildings
if self._build_obj is None:
self._build_obj = buildings.Buildings(libdfhack.API_getBuildings(self._api_ptr))
return self._build_obj
@property
def creatures(self):
import creatures
if self._creature_obj is None:
self._creature_obj = creatures.Creatures(libdfhack.API_getCreatures(self._api_ptr))
return self._creature_obj
@property
def gui(self):
import gui
if self._gui_obj is None:
self._gui_obj = gui.Gui(libdfhack.API_getGui(self._api_ptr))
return self._gui_obj
@property
def items(self):
import items
if self._item_obj is None:
self._item_obj = items.Items(libdfhack.API_getItems(self._api_ptr))
return self._item_obj
@property
def translation(self):
import translation
if self._tran_obj is None:
self._tran_obj = translation.Translation(libdfhack.API_getTranslation(self._api_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()

@ -1,637 +0,0 @@
from ctypes import *
from flags import *
from enum import *
import util
from util import *
libdfhack = cdll.libdfhack
def _register_callback(name, func):
ptr = c_void_p.in_dll(libdfhack, name)
ptr.value = cast(func, c_void_p).value
_register_callback("alloc_byte_buffer_callback", alloc_byte_buffer)
_register_callback("alloc_ubyte_buffer_callback", alloc_ubyte_buffer)
_register_callback("alloc_short_buffer_callback", alloc_short_buffer)
_register_callback("alloc_ushort_buffer_callback", alloc_ushort_buffer)
_register_callback("alloc_int_buffer_callback", alloc_int_buffer)
_register_callback("alloc_uint_buffer_callback", alloc_uint_buffer)
_register_callback("alloc_char_buffer_callback", alloc_char_buffer)
_arr_create_func = CFUNCTYPE(c_void_p, c_int)
_dfhack_string = (c_char * 128)
TileTypes40d = ((c_int * 16) * 16)
BiomeIndices40d = c_ubyte * 16
Temperatures = ((c_ushort * 16) * 16)
Designations40d = ((DesignationFlags * 16) * 16)
Occupancies40d = ((OccupancyFlags * 16) * 16)
def wall_terrain_check(terrain):
return libdfhack.DFHack_isWallTerrain(terrain) > 0
def floor_terrain_check(terrain):
return libdfhack.DFHack_isFloorTerrain(terrain) > 0
def ramp_terrain_check(terrain):
return libdfhack.DFHack_isRampTerrain(terrain) > 0
def stair_terrain_check(terrain):
return libdfhack.DFHack_isStairTerrain(terrain) > 0
def open_terrain_check(terrain):
return libdfhack.DFHack_isOpenTerrain(terrain) > 0
def get_vegetation_type(terrain):
return libdfhack.DFHack_getVegetationType(terrain)
class Position2D(Structure):
_fields_ = [("x", c_ushort),
("y", c_ushort)]
class Position3D(Structure):
_fields_ = [("x", c_ushort),
("y", c_ushort),
("z", c_uint)]
class PlaneCoord(Union):
_fields_ = [("xyz", Position3D),
("dim", Position2D),
("comparate", c_ulong)]
def __cmp__(self, other):
if isinstance(other, PlaneCoord):
return self.comparate - other.comparate
else:
raise TypeError("argument must be of type %s" % type(self))
class Feature(Structure):
_fields_ = [("type", FeatureType),
("main_material", c_short),
("sub_material", c_short),
("discovered", c_byte),
("origin", c_uint)]
class FeatureMapNode(Structure):
_fields_ = [("coordinate", PlaneCoord),
("features", POINTER(Feature)),
("feature_length", c_uint)]
def _alloc_featuremap_buffer_callback(ptr, fmap_list, count):
arr_list = []
arr = (FeatureMapNode * count)()
for i, v in enumerate(arr):
f_count = int(fmap_list[i])
f_arr = (Feature * f_count)()
f_p = cast(f_arr, POINTER(Feature))
v.features = f_p
arr_list.extend((f_arr, f_p))
p = cast(arr, POINTER(FeatureMapNode))
ptr[0] = p
pointer_dict[addressof(arr)] = (ptr, arr, p, arr_list)
return 1
_alloc_featuremap_buffer_functype = CFUNCTYPE(c_int, POINTER(POINTER(FeatureMapNode)), uint_ptr, c_uint)
_alloc_featuremap_buffer_func = _alloc_featuremap_buffer_functype(_alloc_featuremap_buffer_callback)
_register_callback("alloc_featuremap_buffer_callback", _alloc_featuremap_buffer_func)
class Vein(Structure):
_fields_ = [("vtable", c_uint),
("type", c_int),
("assignment", c_short * 16),
("flags", c_uint),
("address_of", c_uint)]
_vein_ptr = POINTER(Vein)
def _alloc_vein_buffer_callback(ptr, count):
return util._allocate_array(ptr, Vein, count)
_vein_functype = CFUNCTYPE(c_int, POINTER(_vein_ptr), c_uint)
_vein_func = _vein_functype(_alloc_vein_buffer_callback)
_register_callback("alloc_vein_buffer_callback", _vein_func)
class FrozenLiquidVein(Structure):
_fields_ = [("vtable", c_uint),
("tiles", TileTypes40d),
("address_of", c_uint)]
_frozenvein_ptr = POINTER(FrozenLiquidVein)
def _alloc_frozenliquidvein_buffer_callback(ptr, count):
return util._allocate_array(ptr, FrozenLiquidVein, count)
_frozenliquidvein_functype = CFUNCTYPE(c_int, POINTER(_frozenvein_ptr), c_uint)
_frozenliquidvein_func = _frozenliquidvein_functype(_alloc_frozenliquidvein_buffer_callback)
_register_callback("alloc_frozenliquidvein_buffer_callback", _frozenliquidvein_func)
class SpatterVein(Structure):
_fields_ = [("vtable", c_uint),
("mat1", c_ushort),
("unk1", c_ushort),
("mat2", c_uint),
("mat3", c_ushort),
("intensity", ((c_ubyte * 16) * 16)),
("address_of", c_uint)]
_spattervein_ptr = POINTER(SpatterVein)
def _alloc_spattervein_buffer_callback(ptr, count):
return util._allocate_array(ptr, SpatterVein, count)
_spattervein_functype = CFUNCTYPE(c_int, POINTER(_spattervein_ptr), c_uint)
_spattervein_func = _spattervein_functype(_alloc_spattervein_buffer_callback)
_register_callback("alloc_spattervein_buffer_callback", _spattervein_func)
class GrassVein(Structure):
_fields_ = [("vtable", c_uint),
("material", c_uint),
("intensity", ((c_ubyte * 16) * 16)),
("address_of", c_uint)]
_grassvein_ptr = POINTER(GrassVein)
def _alloc_grassvein_buffer_callback(ptr, count):
return util._allocate_array(ptr, GrassVein, count)
_grassvein_functype = CFUNCTYPE(c_int, POINTER(_grassvein_ptr), c_uint)
_grassvein_func = _grassvein_functype(_alloc_grassvein_buffer_callback)
_register_callback("alloc_grassvein_buffer_callback", _grassvein_func)
class WorldConstruction(Structure):
_fields_ = [("vtable", c_uint),
("material", c_uint),
("assignment", c_ushort * 16),
("address_of", c_uint)]
_worldconstruction_ptr = POINTER(WorldConstruction)
def _alloc_worldconstruction_buffer_callback(ptr, count):
return util._allocate_array(ptr, WorldConstruction, count)
_worldconstruction_functype = CFUNCTYPE(c_int, POINTER(_worldconstruction_ptr), c_uint)
_worldconstruction_func = _worldconstruction_functype(_alloc_worldconstruction_buffer_callback)
_register_callback("alloc_worldconstruction_buffer_callback", _worldconstruction_func)
class MapBlock40d(Structure):
_fields_ = [("tiletypes", TileTypes40d),
("designation", Designations40d),
("occupancy", Occupancies40d),
("biome_indices", BiomeIndices40d),
("origin", c_uint),
("blockflags", BlockFlags),
("global_feature", c_short),
("local_feature", c_short)]
class ViewScreen(Structure):
_fields_ = [("type", c_int)]
class Matgloss(Structure):
_fields_ = [("id", _dfhack_string),
("fore", c_byte),
("back", c_byte),
("bright", c_byte),
("name", _dfhack_string)]
_matgloss_ptr = POINTER(Matgloss)
def _alloc_matgloss_buffer_callback(ptr, count):
return util._allocate_array(ptr, Matgloss, count)
_matgloss_functype = CFUNCTYPE(c_int, POINTER(_matgloss_ptr), c_uint)
_matgloss_func = _matgloss_functype(_alloc_matgloss_buffer_callback)
_register_callback("alloc_matgloss_buffer_callback", _matgloss_func)
class MatglossPair(Structure):
_fields_ = [("type", c_short),
("index", c_int)]
class DescriptorColor(Structure):
_fields_ = [("id", _dfhack_string),
("r", c_float),
("v", c_float),
("b", c_float),
("name", _dfhack_string)]
def _alloc_descriptor_buffer_callback(ptr, count):
return util._allocate_array(ptr, DescriptorColor, count)
_descriptor_functype = CFUNCTYPE(c_int, POINTER(POINTER(DescriptorColor)), c_uint)
_descriptor_func = _descriptor_functype(_alloc_descriptor_buffer_callback)
_register_callback("alloc_descriptor_buffer_callback", _descriptor_func)
class MatglossPlant(Structure):
_fields_ = [("id", _dfhack_string),
("fore", c_ubyte),
("back", c_ubyte),
("bright", c_ubyte),
("name", _dfhack_string),
("drink_name", _dfhack_string),
("food_name", _dfhack_string),
("extract_name", _dfhack_string)]
class MatglossOther(Structure):
_fields_ = [("rawname", c_char * 128)]
def _alloc_matgloss_other_buffer_callback(ptr, count):
return util._allocate_array(ptr, MatglossOther, count)
_matgloss_other_functype = CFUNCTYPE(c_int, POINTER(POINTER(MatglossOther)), c_uint)
_matgloss_other_func = _matgloss_other_functype(_alloc_matgloss_other_buffer_callback)
_register_callback("alloc_matgloss_other_buffer_callback", _matgloss_other_func)
class Building(Structure):
_fields_ = [("origin", c_uint),
("vtable", c_uint),
("x1", c_uint),
("y1", c_uint),
("x2", c_uint),
("y2", c_uint),
("z", c_uint),
("material", MatglossPair),
("type", c_uint)]
class CustomWorkshop(Structure):
_fields_ = [("index", c_uint),
("name", c_char * 256)]
def _alloc_custom_workshop_buffer_callback(ptr, count):
return util._allocate_array(ptr, CustomWorkshop, count)
_custom_workshop_functype = CFUNCTYPE(c_int, POINTER(POINTER(CustomWorkshop)), c_uint)
_custom_workshop_func = _custom_workshop_functype(_alloc_custom_workshop_buffer_callback)
_register_callback("alloc_customWorkshop_buffer_callback", _custom_workshop_func)
class Construction(Structure):
_fields_ = [("x", c_ushort),
("y", c_ushort),
("z", c_ushort),
("form", c_ushort),
("unk_8", c_ushort),
("mat_type", c_ushort),
("mat_idx", c_uint),
("unk3", c_ushort),
("unk4", c_ushort),
("unk5", c_ushort),
("unk6", c_uint),
("origin", c_uint)]
class Tree(Structure):
_fields_ = [("type", c_ushort),
("material", c_ushort),
("x", c_ushort),
("y", c_ushort),
("z", c_ushort),
("address", c_uint)]
def __str__(self):
water = ""
tree_type = "tree"
if self.type == 1 or self.type == 3:
water = "near-water"
if self.type == 2 or self.type == 3:
tree_type = "shrub"
s = "%d:%d = %s %s\nAddress: 0x%x\n" % (self.type, self.material, water, tree_type, self.address)
return s
def _alloc_tree_buffer_callback(ptr, count):
return util._allocate_array(ptr, Tree, count)
_alloc_tree_buffer_functype = CFUNCTYPE(c_int, POINTER(POINTER(Tree)), c_uint)
_alloc_tree_buffer_func = _alloc_tree_buffer_functype(_alloc_tree_buffer_callback)
_register_callback("alloc_tree_buffer_callback", _alloc_tree_buffer_func)
class Material(Structure):
_fields_ = [("itemType", c_short),
("subType", c_short),
("subIndex", c_short),
("index", c_int),
("flags", c_uint)]
def _alloc_material_buffer_callback(ptr, count):
return util._allocate_array(ptr, Material, count)
_material_functype = CFUNCTYPE(c_int, POINTER(POINTER(Material)), c_uint)
_material_func = _material_functype(_alloc_material_buffer_callback)
_register_callback("alloc_material_buffer_callback", _material_func)
class Skill(Structure):
_fields_ = [("id", c_uint),
("experience", c_uint),
("rating", c_uint)]
class Job(Structure):
_fields_ = [("active", c_byte),
("jobId", c_uint),
("jobType", c_ubyte),
("occupationPtr", c_uint)]
class Like(Structure):
_fields_ = [("type", c_short),
("itemClass", c_short),
("itemIndex", c_short),
("material", MatglossPair),
("active", c_byte)]
class Attribute(Structure):
_fields_ = [("level", c_uint),
("field_4", c_uint),
("field_8", c_uint),
("field_C", c_uint),
("leveldiff", c_uint),
("field_14", c_uint),
("field_18", c_uint)]
class Name(Structure):
_fields_ = [("first_name", _dfhack_string),
("nickname", _dfhack_string),
("words", (c_int * 7)),
("parts_of_speech", (c_ushort * 7)),
("language", c_uint),
("has_name", c_byte)]
class Note(Structure):
_fields_ = [("symbol", c_char),
("foreground", c_ushort),
("background", c_ushort),
("name", _dfhack_string),
("x", c_ushort),
("y", c_ushort),
("z", c_ushort)]
class Settlement(Structure):
_fields_ = [("origin", c_uint),
("name", Name),
("world_x", c_short),
("world_y", c_short),
("local_x1", c_short),
("local_x2", c_short),
("local_y1", c_short),
("local_y2", c_short)]
_NUM_CREATURE_TRAITS = 30
_NUM_CREATURE_LABORS = 102
class Soul(Structure):
_fields_ = [("numSkills", c_ubyte),
("skills", (Skill * 256)),
("traits", (c_ushort * _NUM_CREATURE_TRAITS)),
("analytical_ability", Attribute),
("focus", Attribute),
("willpower", Attribute),
("creativity", Attribute),
("intuition", Attribute),
("patience", Attribute),
("memory", Attribute),
("linguistic_ability", Attribute),
("spatial_sense", Attribute),
("musicality", Attribute),
("kinesthetic_sense", Attribute),
("empathy", Attribute),
("social_awareness", Attribute)]
_MAX_COLORS = 15
class Creature(Structure):
_fields_ = [("origin", c_uint),
("x", c_ushort),
("y", c_ushort),
("z", c_ushort),
("race", c_uint),
("civ", c_int),
("flags1", CreatureFlags1),
("flags2", CreatureFlags2),
("name", Name),
("mood", c_short),
("mood_skill", c_short),
("artifact_name", Name),
("profession", c_ubyte),
("custom_profession", _dfhack_string),
("labors", (c_ubyte * _NUM_CREATURE_LABORS)),
("current_job", Job),
("happiness", c_uint),
("id", c_uint),
("strength", Attribute),
("agility", Attribute),
("toughness", Attribute),
("endurance", Attribute),
("recuperation", Attribute),
("disease_resistance", Attribute),
("squad_leader_id", c_int),
("sex", c_ubyte),
("caste", c_ushort),
("pregnancy_timer", c_uint),
("has_default_soul", c_byte),
("defaultSoul", Soul),
("nbcolors", c_uint),
("color", (c_uint * _MAX_COLORS)),
("birth_year", c_int),
("birth_time", c_uint)]
class CreatureExtract(Structure):
_fields_ = [("rawname", _dfhack_string)]
class BodyPart(Structure):
_fields_ = [("id", _dfhack_string),
("category", _dfhack_string),
("single", _dfhack_string),
("plural", _dfhack_string)]
_bodypart_ptr = POINTER(BodyPart)
class ColorModifier(Structure):
_fields_ = [("part", _dfhack_string),
("colorlist", POINTER(c_uint)),
("colorlistLength", c_uint),
("startdate", c_uint),
("enddate", c_uint)]
def __init__(self):
self.colorlistLength = 0
_colormodifier_ptr = POINTER(ColorModifier)
class CreatureCaste(Structure):
_fields_ = [("rawname", _dfhack_string),
("singular", _dfhack_string),
("plural", _dfhack_string),
("adjective", _dfhack_string),
("color_modifier", _colormodifier_ptr),
("color_modifier_length", c_uint),
("bodypart", _bodypart_ptr),
("bodypart_length", c_uint),
("strength", Attribute),
("agility", Attribute),
("toughness", Attribute),
("endurance", Attribute),
("recuperation", Attribute),
("disease_resistance", Attribute),
("analytical_ability", Attribute),
("focus", Attribute),
("willpower", Attribute),
("creativity", Attribute),
("intuition", Attribute),
("patience", Attribute),
("memory", Attribute),
("linguistic_ability", Attribute),
("spatial_sense", Attribute),
("musicality", Attribute),
("kinesthetic_sense", Attribute)]
_creaturecaste_ptr = POINTER(CreatureCaste)
class TileColor(Structure):
_fields_ = [("fore", c_ushort),
("back", c_ushort),
("bright", c_ushort)]
class ColorDescriptor(Structure):
_fields_ = [("colorlistLength", c_uint)]
class CasteDescriptor(Structure):
_fields_ = [("color_descriptors", POINTER(ColorDescriptor)),
("colorModifierLength", c_uint),
("bodypartLength", c_uint)]
class CreatureTypeDescriptor(Structure):
_fields_ = [("caste_descriptors", POINTER(CasteDescriptor)),
("castesCount", c_uint),
("extractCount", c_uint)]
class CreatureType(Structure):
_fields_ = [("rawname", _dfhack_string),
("castes", _creaturecaste_ptr),
("castes_count", c_uint),
("extract", POINTER(CreatureExtract)),
("extract_count", c_uint),
("tile_character", c_ubyte),
("tilecolor", TileColor)]
_creaturetype_ptr = POINTER(CreatureType)
def _alloc_creaturetype_buffer(ptr, descriptors, count):
arr_list = []
c_arr = (CreatureType * count)()
for i, v in enumerate(c_arr):
v.castesCount = descriptors[i].castesCount
v_caste_arr = (CreatureCaste * v.castesCount)()
for j, v_c in enumerate(v_caste_arr):
caste_descriptor = descriptors[i].caste_descriptors[j]
v_c.colorModifierLength = caste_descriptor.colorModifierLength
c_color_arr = (ColorModifier * v_c.colorModifierLength)()
for k, c_c in enumerate(c_color_arr):
color_descriptor = caste_descriptor.color_descriptors[k]
c_c.colorlistLength = color_descriptor.colorlistLength
c_color_list_arr = (c_uint * c_c.colorlistLength)()
p = cast(c_color_list_arr, POINTER(c_uint))
c_c.colorlist = p
arr_list.extend((c_color_list_arr, p))
c_p = cast(c_color_arr, POINTER(ColorModifier))
v_c.colorModifier = c_p
v_c.bodypartLength = caste_descriptor.bodypartLength
c_bodypart_arr = (BodyPart * v_c.bodypartLength)()
b_p = cast(c_bodypart_arr, POINTER(BodyPart))
v_c.bodypart = b_p
arr_list.extend((c_color_arr, c_p, c_bodypart_arr, b_p))
v.extractCount = descriptors[i].extractCount
v_extract_arr = (CreatureExtract * v.extractCount)()
caste_p = cast(v_caste_arr, POINTER(CreatureCaste))
v.castes = caste_p
extract_p = cast(v_extract_arr, POINTER(CreatureExtract))
v.extract = extract_p
arr_list.extend((v_caste_arr, caste_p, v_extract_arr, extract_p))
p = cast(c_arr, _creaturetype_ptr)
ptr[0] = p
pointer_dict[addressof(c_arr)] = (ptr, c_arr, p, arr_list)
return 1
_alloc_creaturetype_buffer_functype = CFUNCTYPE(c_int, POINTER(_creaturetype_ptr), POINTER(CreatureTypeDescriptor), c_uint)
_alloc_creaturetype_buffer_func = _alloc_creaturetype_buffer_functype(_alloc_creaturetype_buffer)
_register_callback("alloc_creaturetype_buffer_callback", _alloc_creaturetype_buffer_func)
class GameModes(Structure):
_fields_ = [("control_mode", c_ubyte),
("game_mode", c_ubyte)]
class Hotkey(Structure):
_fields_ = [("name", (c_char * 10)),
("mode", c_short),
("x", c_int),
("y", c_int),
("z", c_int)]
_hotkey_ptr = POINTER(Hotkey)
def _alloc_hotkey_buffer_callback(ptr, count):
print "hotkey alloc: %d" % count
return util._allocate_array(ptr, Hotkey, count)
_hotkey_functype = CFUNCTYPE(c_int, POINTER(_hotkey_ptr), c_uint)
_hotkey_func = _hotkey_functype(_alloc_hotkey_buffer_callback)
_register_callback("alloc_hotkey_buffer_callback", _hotkey_func)
class MemRange(Structure):
_fields_ = [("start", c_ulong),
("end", c_ulong),
("name", (c_char * 1024)),
("read", c_uint, 1),
("write", c_uint, 1),
("execute", c_uint, 1),
("shared", c_uint, 1),
("valid", c_ubyte),
("buffer", POINTER(c_ubyte))]
_memrange_ptr = POINTER(MemRange)
def _alloc_memrange_buffer(ptr, descriptors, count):
arr_list = []
m_arr = (MemRange * count)()
for i, v in enumerate(m_arr):
buf_arr = (c_ubyte * int(descriptors[i]))()
buf_ptr = cast(buf_arr, POINTER(c_ubyte))
v.buffer = buf_ptr
arr_list.extend((buf_arr, buf_ptr))
p = cast(m_arr, _memrange_ptr)
ptr[0] = p
pointer_dict[addressof(m_arr)] = (ptr, m_arr, p, arr_list)
return 1
_alloc_memrange_buffer_functype = CFUNCTYPE(c_int, POINTER(_memrange_ptr), POINTER(c_uint), c_uint)
_alloc_memrange_buffer_func = _alloc_memrange_buffer_functype(_alloc_memrange_buffer)
_register_callback("alloc_memrange_buffer_callback", _alloc_memrange_buffer_func)

@ -1,156 +0,0 @@
#found this in the cookbook: http://code.activestate.com/recipes/576415/
from ctypes import c_uint
class C_EnumerationType(type(c_uint)):
def __new__(metacls, name, bases, dictionary):
if not "_members_" in dictionary:
_members_ = {}
for key, value in dictionary.iteritems():
if not key.startswith("_"):
_members_[key] = value
dictionary["_members_"] = _members_
cls = type(c_uint).__new__(metacls, name, bases, dictionary)
for key, value in cls._members_.iteritems():
globals()[key] = value
return cls
def __contains__(self, value):
return value in self._members_.values()
def __repr__(self):
return "<Enumeration %s>" % self.__name__
class C_Enumeration(c_uint):
__metaclass__ = C_EnumerationType
_members_ = {}
def __init__(self, value):
for key, value in self._members_.iteritems():
if v == value:
self.name = key
break
else:
raise ValueError("No enumeration member with value %r" % value)
c_uint.__init__(self, value)
def __repr__(self):
return "<member %s=%d of %r>" % (self.name, self.value, self.__class__)
@classmethod
def from_param(cls, param):
if isinstance(param, C_Enumeration):
if param.__class__ != cls:
raise ValueError("Cannot mix enumeration members")
else:
return param
else:
return cls(param)
FeatureType = C_EnumerationType("FeatureType",
(c_uint,),
{"Other" : 0,
"Adamantine_Tube" : 1,
"Underworld" : 2,
"Hell_Temple" : 3})
BiomeOffset = C_EnumerationType("BiomeOffset",
(c_uint,),
{"NorthWest" : 0,
"North" : 1,
"NorthEast" : 2,
"West" : 3,
"Here" : 4,
"East" : 5,
"SouthWest" : 6,
"South" : 7,
"SouthEast" : 8,
"BiomeCount" : 9})
TrafficType = C_EnumerationType("TrafficType",
(c_uint,),
{"Normal" : 0,
"Low" : 1,
"High" : 2,
"Restricted" : 3})
DesignationType = C_EnumerationType("DesignationType",
(c_uint,),
{"No" : 0,
"Default" : 1,
"UD_Stair" : 2,
"Channel" : 3,
"Ramp" : 4,
"D_Stair" : 5,
"U_Stair" : 6,
"Whatever" : 7})
LiquidType = C_EnumerationType("LiquidType",
(c_uint,),
{"Water" : 0,
"Magma" : 1})
#this list must stay in the same order as the one in dfhack/library/include/dfhack/modules/WindowIO.h!
_keys = ["ENTER",
"SPACE",
"BACK_SPACE",
"TAB",
"CAPS_LOCK",
"LEFT_SHIFT",
"RIGHT_SHIFT",
"LEFT_CONTROL",
"RIGHT_CONTROL",
"ALT",
"WAIT",
"ESCAPE",
"UP",
"DOWN",
"LEFT",
"RIGHT",
"F1",
"F2",
"F3",
"F4",
"F5",
"F6",
"F7",
"F8",
"F9",
"F10",
"F11",
"F12",
"PAGE_UP",
"PAGE_DOWN",
"INSERT",
"DFK_DELETE",
"HOME",
"END",
"KEYPAD_DIVIDE",
"KEYPAD_MULTIPLY",
"KEYPAD_SUBTRACT",
"KEYPAD_ADD,"
"KEYPAD_ENTER",
"KEYPAD_0",
"KEYPAD_1",
"KEYPAD_2",
"KEYPAD_3",
"KEYPAD_4",
"KEYPAD_5",
"KEYPAD_6",
"KEYPAD_7",
"KEYPAD_8",
"KEYPAD_9",
"KEYPAD_DECIMAL_POINT",
"NUM_SPECIALS"]
_key_dict = dict([(k, i) for i, k in enumerate(_keys)])
KeyType = C_EnumerationType("KeyType",
(c_uint,),
_key_dict)

@ -1,201 +0,0 @@
# -*- coding: utf-8 -*-
from ctypes import Structure, Union, c_uint
from enum import *
class DesignationStruct(Structure):
_fields_ = [("flow_size", c_uint, 3),
("pile", c_uint, 1),
("dig", DesignationType, 3),
("smooth", c_uint, 2),
("hidden", c_uint, 1),
("geolayer_index", c_uint, 4),
("light", c_uint, 1),
("subterranean", c_uint, 1),
("skyview", c_uint, 1),
("biome", c_uint, 4),
("liquid_type", c_uint, 1),
("water_table", c_uint, 1),
("rained", c_uint, 1),
("traffic", c_uint, 2),
("flow_forbid", c_uint, 1),
("liquid_static", c_uint, 1),
("feature_local", c_uint, 1),
("feature_global", c_uint, 1),
("water_stagnant", c_uint, 1),
("water_salt", c_uint, 1)]
class DesignationFlags(Union):
_fields_ = [("whole", c_uint, 32),
("bits", DesignationStruct)]
def __init__(self, initial = 0):
self.whole = initial
def __int__(self):
return self.whole
class OccupancyStruct(Structure):
_fields_ = [("building", c_uint, 3),
("unit", c_uint, 1),
("unit_grounded", c_uint, 1),
("item", c_uint, 1),
("splatter", c_uint, 26)]
class OccupancyFlags(Union):
_fields_ = [("whole", c_uint, 32),
("bits", OccupancyStruct)]
def __init__(self, initial = 0):
self.whole = initial
def __int__(self):
return self.whole
class CreatureStruct1(Structure):
_fields_ = [("move_state", c_uint, 1),
("dead", c_uint, 1),
("has_mood", c_uint, 1),
("had_mood", c_uint, 1),
("marauder", c_uint, 1),
("drowning", c_uint, 1),
("merchant", c_uint, 1),
("forest", c_uint, 1),
("left", c_uint, 1),
("rider", c_uint, 1),
("incoming", c_uint, 1),
("diplomat", c_uint, 1),
("zombie", c_uint, 1),
("skeleton", c_uint, 1),
("can_swap", c_uint, 1),
("on_ground", c_uint, 1),
("projectile", c_uint, 1),
("active_invader", c_uint, 1),
("hidden_in_ambush", c_uint, 1),
("invader_origin", c_uint, 1),
("coward", c_uint, 1),
("hidden_ambusher", c_uint, 1),
("invades", c_uint, 1),
("check_flows", c_uint, 1),
("ridden", c_uint, 1),
("caged", c_uint, 1),
("tame", c_uint, 1),
("chained", c_uint, 1),
("royal_guard", c_uint, 1),
("fortress_guard", c_uint, 1),
("suppress_wield", c_uint, 1),
("important_historical_figure", c_uint, 1)]
class CreatureFlags1(Union):
_fields_ = [("whole", c_uint, 32),
("bits", CreatureStruct1)]
def __init__(self, initial = 0):
self.whole = initial
def __int__(self):
return self.whole
class CreatureStruct2(Structure):
_fields_ = [("swimming", c_uint, 1),
("sparring", c_uint, 1),
("no_notify", c_uint, 1),
("unused", c_uint, 1),
("calculated_nerves", c_uint, 1),
("calculated_bodyparts", c_uint, 1),
("important_historical_figure", c_uint, 1),
("killed", c_uint, 1),
("cleanup_1", c_uint, 1),
("cleanup_2", c_uint, 1),
("cleanup_3", c_uint, 1),
("for_trade", c_uint, 1),
("trade_resolved", c_uint, 1),
("has_breaks", c_uint, 1),
("gutted", c_uint, 1),
("circulatory_spray", c_uint, 1),
("locked_in_for_trading", c_uint, 1),
("slaughter", c_uint, 1),
("underworld", c_uint, 1),
("resident", c_uint, 1),
("cleanup_4", c_uint, 1),
("calculated_insulation", c_uint, 1),
("visitor_uninvited", c_uint, 1),
("visitor", c_uint, 1),
("calculated_inventory", c_uint, 1),
("vision_good", c_uint, 1),
("vision_damaged", c_uint, 1),
("vision_missing", c_uint, 1),
("breathing_good", c_uint, 1),
("breathing_problem", c_uint, 1),
("roaming_wilderness_population_source", c_uint, 1),
("roaming_wilderness_population_source_not_a_map_feature", c_uint, 1)]
class CreatureFlags2(Union):
_fields_ = [("whole", c_uint, 32),
("bits", CreatureStruct2)]
def __init__(self, initial = 0):
self.whole = initial
def __int__(self):
return self.whole
class ItemStruct(Structure):
_fields_ = [("on_ground", c_uint, 1),
("in_job", c_uint, 1),
("in_inventory", c_uint, 1),
("u_ngrd1", c_uint, 1),
("in_workshop", c_uint, 1),
("u_ngrd2", c_uint, 1),
("u_ngrd3", c_uint, 1),
("rotten", c_uint, 1),
("unk1", c_uint, 1),
("u_ngrd4", c_uint, 1),
("unk2", c_uint, 1),
("u_ngrd5", c_uint, 1),
("unk3", c_uint, 1),
("u_ngrd6", c_uint, 1),
("narrow", c_uint, 1),
("u_ngrd7", c_uint, 1),
("worn", c_uint, 1),
("unk4", c_uint, 1),
("u_ngrd8", c_uint, 1),
("forbid", c_uint, 1),
("unk5", c_uint, 1),
("dump", c_uint, 1),
("on_fire", c_uint, 1),
("melt", c_uint, 1),
("hidden", c_uint, 1),
("u_ngrd9", c_uint, 1),
("unk6", c_uint, 1),
("unk7", c_uint, 1),
("unk8", c_uint, 1),
("unk9", c_uint, 1),
("unk10", c_uint, 1),
("unk11", c_uint, 1)]
class ItemFlags(Union):
_fields_ = [("whole", c_uint, 32),
("bits", ItemStruct)]
def __init__(self, initial = 0):
self.whole = initial
def __int__(self):
return self.whole
class BlockFlagStruct(Structure):
_fields_ = [("designated", c_uint, 1),
("unk_1", c_uint, 1),
("liquid_1", c_uint, 1),
("liquid_2", c_uint, 1),
("unk_2", c_uint, 28)]
class BlockFlags(Union):
_fields_ = [("whole", c_uint, 32),
("bits", BlockFlagStruct)]
def __init__(self, inital = 0):
self.whole = initial
def __int__(self):
return self.whole

@ -1,73 +0,0 @@
from ctypes import c_void_p, c_int, c_uint, byref
from dftypes import libdfhack, ViewScreen, Hotkey
from util import check_pointer_cache
libdfhack.Gui_getViewCoords.argtypes = [ c_void_p, POINTER(c_int), POINTER(c_int), POINTER(c_int) ]
libdfhack.Gui_setViewCoords.argtypes = [ c_void_p, c_int, c_int, c_int ]
libdfhack.Gui_getCursorCoords.argtypes = [ c_void_p, POINTER(c_int), POINTER(c_int), POINTER(c_int) ]
libdfhack.Gui_setCursorCoords.argtypes = [ c_void_p, c_int, c_int, c_int ]
libdfhack.Gui_getWindowSize.argtypes = [ c_void_p, POINTER(c_int), POINTER(c_int) ]
libdfhack.Gui_ReadViewScreen.argtypes = [ c_void_p, c_void_p ]
libdfhack.Gui_ReadHotkeys.restype = c_void_p
libdfhack.Gui_getScreenTiles.argtypes = [ c_void_p, c_int, c_int ]
libdfhack.Gui_getScreenTiles.restype = c_void_p
class Gui(object):
def __init__(self, ptr):
self._gui_ptr = ptr
def start(self):
return libdfhack.Gui_Start(self._gui_ptr) > 0
def finish(self):
return libdfhack.Gui_Finish(self._gui_ptr) > 0
def read_view_screen(self):
s = ViewScreen()
if libdfhack.Gui_ReadViewScreen(self._gui_ptr, byref(s)) > 0:
return s
else:
return None
def get_view_coords(self):
x, y, z = (0, 0, 0)
if libdfhack.Gui_getViewCoords(self._gui_ptr, byref(x), byref(y), byref(z)) > 0:
return (x, y, z)
else:
return (-1, -1, -1)
def set_view_coords(self, x, y, z):
libdfhack.Gui_setViewCoords(self._gui_ptr, x, y, z)
def get_cursor_coords(self):
x, y, z = (0, 0, 0)
if libdfhack.Gui_getCursorCoords(self._gui_ptr, byref(x), byref(y), byref(z)) > 0:
return (x, y, z)
else:
return (-1, -1, -1)
def set_cursor_coords(self, x, y, z):
libdfhack.Gui_setCursorCoords(self._gui_ptr, x, y, z)
def read_hotkeys(self):
return check_pointer_cache(libdfhack.Gui_ReadHotkeys(self._gui_ptr))
def get_screen_tiles(self, width, height):
return check_pointer_cache(libdfhack.Gui_getScreenTiles(self._gui_ptr, width, height))
@property
def window_size(self):
width, height = (0, 0)
if libdfhack.Gui_getWindowSize(self._gui_ptr, byref(width), byref(height)) > 0:
return (width, height)
else:
return (-1, -1)

@ -1,33 +0,0 @@
from ctypes import *
from dftypes import *
libdfhack.Items_getItemDescription.argtypes = [ c_void_p, c_uint, c_void_ptr, _arr_create_func ]
libdfhack.Items_getItemDescription.restype = c_char_p
libdfhack.Items_getItemClass.argtypes = [ c_void_p, c_int, _arr_create_func ]
libdfhack.Item_getItemClass.restype = c_char_p
class Items(object):
def __init__(self, ptr):
self._i_ptr = ptr
def get_item_description(self, itemptr, materials):
def get_callback(count):
item_string = create_string_buffer(count)
return byref(item_string)
item_string = None
callback = _arr_create_func(get_callback)
return libdfhack.Items_getItemDescription(self._i_ptr, itemptr, materials, callback)
def get_item_class(self, index):
def get_callback(count):
item_string = create_string_buffer(count)
return byref(item_string)
item_string = None
callback = _arr_create_func(get_callback)
return libdfhack.Items_getItemClass(self._i_ptr, index, callback)

@ -1,291 +0,0 @@
from ctypes import *
from dftypes import *
from util import _uintify, int_ptr, uint_ptr, check_pointer_cache
_MAX_DIM = 0x300
_MAX_DIM_SQR = _MAX_DIM * _MAX_DIM
libdfhack.Maps_getSize.argtypes = [ c_void_p, uint_ptr, uint_ptr, uint_ptr ]
libdfhack.Maps_getPosition.argtypes = [ c_void_p, int_ptr, int_ptr, int_ptr ]
libdfhack.Maps_ReadTileTypes.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(TileTypes40d) ]
libdfhack.Maps_WriteTileTypes.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(TileTypes40d) ]
libdfhack.Maps_ReadDesignations.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(Designations40d) ]
libdfhack.Maps_WriteDesignations.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(Designations40d) ]
libdfhack.Maps_ReadTemperatures.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(Temperatures) ]
libdfhack.Maps_WriteTemperatures.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(Temperatures) ]
libdfhack.Maps_ReadOccupancy.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(Occupancies40d) ]
libdfhack.Maps_WriteOccupancy.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(Occupancies40d) ]
libdfhack.Maps_ReadRegionOffsets.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(BiomeIndices40d) ]
libdfhack.Maps_ReadVegetation.restype = c_void_p
libdfhack.Maps_ReadStandardVeins.argtypes = [ c_void_p, c_uint, c_uint, c_uint ]
libdfhack.Maps_ReadFrozenVeins.argtypes = [ c_void_p, c_uint, c_uint, c_uint ]
libdfhack.Maps_ReadSpatterVeins.argtypes = [ c_void_p, c_uint, c_uint, c_uint ]
libdfhack.Maps_ReadGrassVeins.argtypes = [ c_void_p, c_uint, c_uint, c_uint ]
libdfhack.Maps_ReadWorldConstructions.argtypes = [ c_void_p, c_uint, c_uint, c_uint ]
libdfhack.Maps_ReadStandardVeins.restype = c_void_p
libdfhack.Maps_ReadFrozenVeins.restype = c_void_p
libdfhack.Maps_ReadSpatterVeins.restype = c_void_p
libdfhack.Maps_ReadGrassVeins.restype = c_void_p
libdfhack.Maps_ReadWorldConstructions.restype = c_void_p
libdfhack.Maps_ReadLocalFeatures.restype = c_void_p
class Maps(object):
def __init__(self, ptr):
self._map_ptr = ptr
def start(self):
return libdfhack.Maps_Start(self._map_ptr) > 0
def finish(self):
return libdfhack.Maps_Finish(self._map_ptr) > 0
def is_valid_block(self, x, y, z):
return libdfhack.Maps_isValidBlock(self._map_ptr, *_uintify(x, y, z)) > 0
def read_tile_types(self, x, y, z):
tt = TileTypes40d()
ux, uy, uz = _uintify(x, y, z)
if libdfhack.Maps_ReadTileTypes(self._map_ptr, ux, uy, uz, tt) > 0:
return tt
else:
return None
def write_tile_types(self, x, y, z, tt):
ux, uy, uz = _uintify(x, y, z)
return libdfhack.Maps_WriteTileTypes(self._map_ptr, ux, uy, uz, tt) > 0
def read_designations(self, x, y, z):
d = Designations40d()
ux, uy, uz = _uintify(x, y, z)
if libdfhack.Maps_ReadDesignations(self._map_ptr, ux, uy, uz, byref(d)) > 0:
return d
else:
return None
def write_designations(self, x, y, z, d):
ux, uy, uz = _uintify(x, y, z)
return libdfhack.Maps_WriteDesignations(self._map_ptr, ux, uy, uz, byref(d)) > 0
def read_temperatures(self, x, y, z):
t = Temperatures()
ux, uy, uz = _uintify(x, y, z)
if libdfhack.Maps_ReadDesignations(self._map_ptr, ux, uy, uz, t) > 0:
return t
else:
return None
def write_temperatures(self, x, y, z, t):
ux, uy, uz = _uintify(x, y, z)
return libdfhack.Maps_WriteDesignations(self._map_ptr, ux, uy, uz, t) > 0
def read_occupancy(self, x, y, z):
o = Occupancies40d()
ux, uy, uz = _uintify(x, y, z)
if libdfhack.Maps_ReadDesignations(self._map_ptr, ux, uy, uz, o) > 0:
return o
else:
return None
def write_occupancy(self, x, y, z, o):
ux, uy, uz = _uintify(x, y, z)
return libdfhack.Maps_WriteDesignations(self._map_ptr, ux, uy, uz, byref(o)) > 0
def read_dirty_bit(self, x, y, z):
bit = c_int(0)
ux, uy, uz = _uintify(x, y, z)
if libdfhack.Maps_ReadDirtyBit(self._map_ptr, ux, uy, uz, byref(bit)) > 0:
if bit > 0:
return True
else:
return False
else:
return None
def write_dirty_bit(self, x, y, z, dirty):
ux, uy, uz = _uintify(x, y, z)
return libdfhack.Maps_WriteDirtyBit(self._map_ptr, ux, uy, uz, c_int(dirty)) > 0
def read_features(self, x, y, z):
lf = c_short()
gf = c_short()
ux, uy, uz = _uintify(x, y, z)
libdfhack.Maps_ReadFeatures(self._map_ptr, ux, uy, uz, byref(lf), byref(fg))
return (lf, gf)
def write_local_feature(self, x, y, z, local_feature = -1):
ux, uy, uz = _uintify(x, y, z)
return libdfhack.Maps_WriteLocalFeature(self._map_ptr, ux, uy, uz, c_short(local_feature)) > 0
def write_global_feature(self, x, y, z, global_feature = -1):
ux, uy, uz = _uintify(x, y, z)
return libdfhack.Maps_WriteGlobalFeature(self._map_ptr, ux, uy, uz, c_short(global_feature)) > 0
def read_block_flags(self, x, y, z):
bf = BlockFlags()
ux, uy, uz = _uintify(x, y, z)
if libdfhack.Maps_ReadBlockFlags(self._map_ptr, ux, uy, uz, byref(bf)) > 0:
return bf
else:
return None
def write_block_flags(self, x, y, z, block_flags):
ux, uy, uz = _uintify(x, y, z)
return libdfhack.Maps_WriteBlockFlags(self._map_ptr, ux, uy, uz, block_flags) > 0
def read_region_offsets(self, x, y, z):
bi = BiomeIndices40d()
ux, uy, uz = _uintify(x, y, z)
if libdfhack.Maps_ReadRegionOffsets(self._map_ptr, ux, uy, uz, byref(bi)) > 0:
return bi
else:
return None
def read_veins(self, x, y, z):
ux, uy, uz = _uintify(x, y, z)
return check_pointer_cache(libdfhack.Maps_ReadStandardVeins(self._map_ptr, ux, uy, uz))
def read_frozen_veins(self, x, y, z):
ux, uy, uz = _uintify(x, y, z)
return check_pointer_cache(libdfhack.Maps_ReadFrozenVeins(self._map_ptr, ux, uy, uz))
def read_spatter_veins(self, x, y, z):
ux, uy, uz = _uintify(x, y, z)
return check_pointer_cache(libdfhack.Maps_ReadSpatterVeins(self._map_ptr, ux, uy, uz))
def read_grass_veins(self, x, y, z):
ux, uy, uz = _uintify(x, y, z)
return check_pointer_cache(libdfhack.Maps_ReadGrassVeins(self._map_ptr, ux, uy, uz))
def read_world_constructions(self, x, y, z):
ux, uy, uz = _uintify(x, y, z)
return check_pointer_cache(libdfhack.Maps_ReadWorldConstructions(self._map_ptr, ux, uy, uz))
def read_vegetation(self, x, y, z):
ux, uy, uz = _uintify(x, y, z)
return check_pointer_cache(libdfhack.Maps_ReadVegetation(self._map_ptr, ux, uy, uz))
def read_local_features(self):
f = libdfhack.Maps_ReadLocalFeatures(self._map_ptr)
feature_dict = {}
f_arr = check_pointer_cache(f, False)
if f_arr is not None:
for node in f_arr:
c = node.coordinate.xyz
coord = MapPoint(c.x, c.y, c.z)
f_list = [node.features[i] for i in xrange(node.feature_length)]
feature_dict[coord] = f_list
return feature_dict
@property
def size(self):
x, y, z = (c_uint(0), c_uint(0), c_uint(0))
retval = libdfhack.Maps_getSize(self._map_ptr, byref(x), byref(y), byref(z))
return (int(x.value), int(y.value), int(z.value))
@property
def position(self):
x, y, z = (c_int(0), c_int(0), c_int(0))
libdfhack.Maps_getPosition(self._map_ptr, byref(x), byref(y), byref(z))
return (int(x.value), int(y.value), int(z.value))
class MapPoint(object):
__slots__ = ["_x", "_y", "_z", "_cmp_val"]
def __init__(self, x = 0, y = 0, z = 0):
self._x, self._y, self._z = x, y, z
self._cmp_val = self._get_cmp_value()
def _val_set(self, which, val):
if which == 0:
self._x = val
elif which == 1:
self._y = val
elif which == 2:
self._z = val
self._cmp_val = self._get_cmp_value()
x = property(fget = lambda self: self._x, fset = lambda self, v: self._val_set(0, v))
y = property(fget = lambda self: self._y, fset = lambda self, v: self._val_set(1, v))
z = property(fget = lambda self: self._z, fset = lambda self, v: self._val_set(2, v))
def _get_cmp_value(self):
return (self.z * _MAX_DIM_SQR) + (self.y * _MAX_DIM) + self.x
#comparison operators
def __eq__(self, other):
return self.x == other.x and self.y == other.y and self.z == other.z
def __ne__(self, other):
return not self == other
def __lt__(self, other):
return self._cmp_val < other._cmp_val
def __le__(self, other):
return self < other or self == other
def __gt__(self, other):
return self._cmp_val > other._cmp_val
def __ge__(self, other):
return self > other or self == other
#arithmetic operators
def __add__(self, num):
return MapPoint(self.x, self.y, self.z + num)
def __sub__(self, num):
return MapPoint(self.x, self.y, self.z - num)
def __div__(self, num):
return MapPoint(self.x / num, self.y / num, self.z)
def __mul__(self, num):
return MapPoint(self.x * num, self.y * num, self.z)
def __mod__(self, num):
return MapPoint(self.x % num, self.y % num, self.z)

@ -1,166 +0,0 @@
from ctypes import *
import dftypes
from dftypes import libdfhack, Matgloss, CreatureType, DescriptorColor, MatglossOther
from util import check_pointer_cache
libdfhack.Materials_getInorganic.restype = c_void_p
libdfhack.Materials_getOrganic.restype = c_void_p
libdfhack.Materials_getTree.restype = c_void_p
libdfhack.Materials_getPlant.restype = c_void_p
libdfhack.Materials_getRace.restype = c_void_p
libdfhack.Materials_getRaceEx.restype = c_void_p
libdfhack.Materials_getColor.restype = c_void_p
libdfhack.Materials_getOther.restype = c_void_p
libdfhack.Materials_getAllDesc.restype = c_void_p
class Materials(object):
def __init__(self, ptr):
self._mat_ptr = ptr
self.inorganic = None
self.organic = None
self.tree = None
self.plant = None
self.race = None
self.race_ex = None
self.color = None
self.other = None
def _get_inorganic(self):
self.inorganic = check_pointer_cache(libdfhack.Materials_getInorganic(self._mat_ptr))
def _get_organic(self):
self.organic = check_pointer_cache(libdfhack.Materials_getOrganic(self._mat_ptr))
def _get_tree(self):
self.tree = check_pointer_cache(libdfhack.Materials_getTree(self._mat_ptr))
def _get_plant(self):
self.plant = check_pointer_cache(libdfhack.Materials_getPlant(self._mat_ptr))
def _get_race(self):
self.race = check_pointer_cache(libdfhack.Materials_getRace(self._mat_ptr))
def _get_race_ex(self):
self.race_ex = check_pointer_cache(libdfhack.Materials_getRaceEx(self._mat_ptr))
def _get_color(self):
self.color = check_pointer_cache(libdfhack.Materials_getColor(self._mat_ptr))
def _get_other(self):
self.other = check_pointer_cache(libdfhack.Materials_getOther(self._mat_ptr))
def _get_all(self):
self._get_inorganic()
self._get_organic()
self._get_tree()
self._get_plant()
self._get_race()
self._get_race_ex()
self._get_color()
self._get_other()
def _clear_all(self):
self.inorganic = None
self.organic = None
self.tree = None
self.plant = None
self.race = None
self.race_ex = None
self.color = None
self.other = None
def read_inorganic(self):
result = libdfhack.Materials_ReadInorganicMaterials(self._mat_ptr) > 0
if result == True:
self._get_inorganic()
else:
self.inorganic = None
return result
def read_organic(self):
result = libdfhack.Materials_ReadOrganicMaterials(self._mat_ptr) > 0
if result == True:
self._get_organic()
else:
self.organic = None
return result
def read_tree(self):
result = libdfhack.Materials_ReadWoodMaterials(self._mat_ptr) > 0
if result == True:
self._get_tree()
else:
self.tree = None
return result
def read_plant(self):
result = libdfhack.Materials_ReadPlantMaterials(self._mat_ptr) > 0
if result == True:
self._get_plant()
else:
self.plant = None
return result
def read_creature_types(self):
result = libdfhack.Materials_ReadCreatureTypes(self._mat_ptr) > 0
if result == True:
self._get_race()
else:
self.race = None
return result
def read_creature_types_ex(self):
result = libdfhack.Materials_ReadCreatureTypesEx(self._mat_ptr) > 0
if result == True:
self._get_race_ex()
else:
self.race_ex = None
return result
def read_descriptor_colors(self):
result = libdfhack.Materials_ReadDescriptorColors(self._mat_ptr) > 0
if result == True:
self._get_color()
else:
self.color = None
return result
def read_others(self):
result = libdfhack.Materials_ReadOthers(self._mat_ptr) > 0
if result == True:
self._get_other()
else:
self.other = None
return result
def read_all(self):
result = libdfhack.Materials_ReadAllMaterials(self._mat_ptr) > 0
if result == True:
self._get_all()
else:
self._clear_all()
return result
def get_type(self, material):
return libdfhack.Materials_getType(self._mat_ptr, byref(material))
def get_description(self, material):
return libdfhack.Materials_getDescription(self._mat_ptr, byref(material))

@ -1,135 +0,0 @@
from ctypes import *
from dftypes import libdfhack
from util import check_pointer_cache
libdfhack.Process_readQuad.argtypes = [ c_void_p, c_uint, POINTER(c_ulong) ]
libdfhack.Process_writeQuad.argtypes = [ c_void_p, c_uint, c_ulong ]
libdfhack.Process_readDWord.argtypes = [ c_void_p, c_uint, POINTER(c_uint) ]
libdfhack.Process_writeDWord.argtypes = [ c_void_p, c_uint, c_uint ]
libdfhack.Process_readWord.argtypes = [ c_void_p, c_uint, POINTER(c_ushort) ]
libdfhack.Process_writeWord.argtypes = [ c_void_p, c_uint, c_ushort ]
libdfhack.Process_readByte.argtypes = [ c_void_p, c_uint, POINTER(c_ubyte) ]
libdfhack.Process_writeByte.argtypes = [ c_void_p, c_uint, c_ubyte ]
libdfhack.Process_readFloat.argtypes = [ c_void_p, c_uint, POINTER(c_float) ]
libdfhack.Process_read.argtypes = [ c_void_p, c_uint, c_uint ]
libdfhack.Process_read.restype = c_void_p
libdfhack.Process_write.argtypes = [ c_void_p, c_uint, c_uint, POINTER(c_ubyte) ]
libdfhack.Process_getThreadIDs.restype = c_void_p
class Process(object):
def __init__(self, ptr):
self._p_ptr = ptr
def attach(self):
return libdfhack.Process_attach(self._p_ptr) > 0
def detach(self):
return libdfhack.Process_detach(self._p_ptr) > 0
def suspend(self):
return libdfhack.Process_suspend(self._p_ptr) > 0
def async_suspend(self):
return libdfhack.Process_asyncSuspend(self._p_ptr) > 0
def resume(self):
return libdfhack.Process_resume(self._p_ptr) > 0
def force_resume(self):
return libdfhack.Process_forceresume(self._p_ptr) > 0
def read_quad(self, address):
q = c_ulong(0)
if libdfhack.Process_readQuad(self._p_ptr, address, byref(q)) > 0:
return long(q.value)
else:
return -1
def write_quad(self, address, value):
return libdfhack.Process_writeQuad(self._p_ptr, address, value) > 0
def read_dword(self, address):
d = c_uint(0)
if libdfhack.Process_readDWord(self._p_ptr, address, byref(d)) > 0:
return int(d.value)
else:
return -1
def write_dword(self, address, value):
return libdfhack.Process_writeDWord(self._p_ptr, address, value) > 0
def read_word(self, address):
s = c_ushort(0)
if libdfhack.Process_readWord(self._p_ptr, address, byref(s)) > 0:
return int(s.value)
else:
return -1
def write_word(self, address, value):
return libdfhack.Process_writeWord(self._p_ptr, address, value) > 0
def read_byte(self, address):
b = c_ubyte(0)
if libdfhack.Process_readByte(self._p_ptr, address, byref(b)) > 0:
return int(b.value)
else:
return -1
def write_byte(self, address, value):
return libdfhack.Process_writeByte(self._p_ptr, address, value) > 0
def read_float(self, address):
f = c_float(0)
if libdfhack.Process_readFloat(self._p_ptr, address, byref(f)) > 0:
return float(f.value)
else:
return -1
def read(self, address, length):
return check_pointer_cache(libdfhack.Process_read(self._p_ptr, address, length))
def write(self, address, length, buffer):
libdfhack.Process_write(self._p_ptr, address, length, byref(buffer))
def get_thread_ids(self):
return check_pointer_cache(libdfhack.Process_getThreadIDs(self._p_ptr))
def set_and_wait(self, state):
return libdfhack.Process_SetAndWait(self._p_ptr, state) > 0
@property
def is_suspended(self):
return libdfhack.Process_isSuspended(self._p_ptr) > 0
@property
def is_attached(self):
return libdfhack.Process_isAttached(self._p_ptr) > 0
@property
def is_identified(self):
return libdfhack.Process_isIdentified(self._p_ptr) > 0
@property
def is_snapshot(self):
return libdfhack.Process_isSnapshot(self._p_ptr) > 0
@property
def pid(self):
p = c_int(0)
if libdfhack.Process_getPID(self._p_ptr, byref(p)) > 0:
return int(p.value)
else:
return -1

@ -1,88 +0,0 @@
from ctypes import *
int_ptr = POINTER(c_int)
uint_ptr = POINTER(c_uint)
short_ptr = POINTER(c_short)
ushort_ptr = POINTER(c_ushort)
byte_ptr = POINTER(c_byte)
ubyte_ptr = POINTER(c_ubyte)
pointer_dict = {}
def check_pointer_cache(address, return_as_list = True):
arr = None
if address in pointer_dict:
arr = pointer_dict[address][1]
del pointer_dict[address]
if return_as_list == True:
arr = [i for i in arr]
return arr
def _uintify(x, y, z):
return (c_uint(x), c_uint(y), c_uint(z))
def _allocate_array(ptr, t_type, count):
arr = (t_type * count)()
p = cast(arr, POINTER(t_type))
ptr[0] = p
pointer_dict[addressof(arr)] = (ptr, arr, p)
return 1
def _alloc_int_buffer(ptr, count):
return _allocate_array(ptr, c_int, count)
_int_functype = CFUNCTYPE(c_int, POINTER(POINTER(c_int)), c_uint)
alloc_int_buffer = _int_functype(_alloc_int_buffer)
def _alloc_uint_buffer(ptr, count):
return _allocate_array(ptr, c_uint, count)
_uint_functype = CFUNCTYPE(c_int, POINTER(POINTER(c_uint)), c_uint)
alloc_uint_buffer = _uint_functype(_alloc_uint_buffer)
def _alloc_short_buffer(ptr, count):
return _allocate_array(ptr, c_short, count)
_short_functype = CFUNCTYPE(c_int, POINTER(POINTER(c_short)), c_uint)
alloc_short_buffer = _short_functype(_alloc_short_buffer)
def _alloc_ushort_buffer(ptr, count):
return _allocate_array(ptr, c_ushort, count)
_ushort_functype = CFUNCTYPE(c_int, POINTER(POINTER(c_ushort)), c_uint)
alloc_ushort_buffer = _ushort_functype(_alloc_ushort_buffer)
def _alloc_byte_buffer(ptr, count):
return _allocate_array(ptr, c_byte, count)
_byte_functype = CFUNCTYPE(c_int, POINTER(POINTER(c_byte)), c_uint)
alloc_byte_buffer = _byte_functype(_alloc_byte_buffer)
def _alloc_ubyte_buffer(ptr, count):
return _allocate_array(ptr, c_ubyte, count)
_ubyte_functype = CFUNCTYPE(c_int, POINTER(POINTER(c_ubyte)), c_uint)
alloc_ubyte_buffer = _ubyte_functype(_alloc_ubyte_buffer)
def _alloc_char_buffer(ptr, count):
c = create_string_buffer(count)
p = cast(c, POINTER(c_char))
ptr[0] = p
pointer_dict[id(ptr[0])] = (ptr, c, p)
return 1
_char_functype = CFUNCTYPE(c_int, POINTER(POINTER(c_char)), c_uint)
alloc_char_buffer = _char_functype(_alloc_char_buffer)

@ -1,25 +0,0 @@
from ctypes import *
from dftypes import libdfhack, Tree
class Vegetation(object):
def __init__(self, ptr):
self._v_ptr = ptr
def start(self):
n = c_uint(0)
if libdfhack.Vegetation_Start(self._v_ptr, byref(n)) > 0:
return int(n.value)
else:
return -1
def finish(self):
return libdfhack.Vegetation_Finish(self._v_ptr) > 0
def read(self, index):
t = Tree()
if libdfhack.Vegetation_Read(self._v_ptr, c_uint(index), byref(t)) > 0:
return t
else:
return None

@ -1,26 +0,0 @@
from ctypes import *
from dftypes import libdfhack
libdfhack.WindowIO_TypeStr.argtypes = [ c_void_p, c_char_p, c_uint, c_byte ]
libdfhack.WindowIO_TypeSpecial.argtypes = [ c_void_p, c_uint, c_uint, c_uint, c_uint ]
class WindowIO(object):
def __init__(self, ptr):
self._window_io_ptr = ptr
def type_str(self, s, delay = 0, use_shift = False):
c_shift = c_byte(0)
c_delay = c_uint(delay)
c_s = c_char_p(s)
if use_shift is True:
c_shift = c_byte(1)
return libdfhack.WindowIO_TypeStr(self._window_io_ptr, c_s, c_delay, c_shift) > 0
def type_special(self, command, count = 1, delay = 0):
c_command = c_uint(command)
c_count = c_uint(count)
c_delay = c_uint(delay)
return libdfhack.WindowIO_TypeSpecial(self._window_io_ptr, c_command, c_count, c_delay) > 0

@ -1,80 +0,0 @@
from ctypes import *
from dftypes import libdfhack, GameModes
from util import _uintify, uint_ptr
libdfhack.World_ReadGameMode.argtypes = [ c_void_p, POINTER(GameModes) ]
class World(object):
def __init__(self, ptr):
self._world_ptr = ptr
def start(self):
return libdfhack.World_Start(self._world_ptr) > 0
def finish(self):
return libdfhack.World_Finish(self._world_ptr) > 0
def read_pause_state(self):
return libdfhack.World_ReadPauseState(self._world_ptr) > 0
def set_pause_state(self, pause_state):
p = c_byte(0)
if pause_state is not None and pause_state is not False:
p.value = 1
return libdfhack.World_SetPauseState(self._world_ptr, p) > 0
def read_current_tick(self):
tick = c_uint(0)
if libdfhack.World_ReadCurrentTick(self._world_ptr, byref(tick)) > 0:
return int(tick)
else:
return -1
def read_current_year(self):
year = c_uint(0)
if libdfhack.World_ReadCurrentYear(self._world_ptr, byref(year)) > 0:
return int(year)
else:
return -1
def read_current_month(self):
month = c_uint(0)
if libdfhack.World_ReadCurrentMonth(self._world_ptr, byref(month)) > 0:
return int(month)
else:
return -1
def read_current_day(self):
day = c_uint(0)
if libdfhack.World_ReadCurrentDay(self._world_ptr, byref(day)) > 0:
return int(day)
else:
return -1
def read_current_weather(self):
weather = c_ubyte(0)
if libdfhack.World_ReadCurrentWeather(self._world_ptr, byref(weather)) > 0:
return int(weather)
else:
return -1
def write_current_weather(self, weather):
return libdfhack.World_WriteCurrentWeather(self._world_ptr, c_ubyte(weather))
def read_game_mode(self):
game_modes = GameModes()
if libdfhack.World_ReadGameMode(self._world_ptr, byref(game_modes)) > 0:
return game_modes
else:
return None
def write_game_mode(self, game_mode):
return libdfhack.World_WriteGameMode(self._world_ptr, game_modes) > 0

@ -1,10 +1,10 @@
if(NOT DEFINED DFHACK_CONSISTENCY)
MESSAGE(FATAL_ERROR "Please build the whole thing, not parts. You can turn parts on/off using options.")
ENDIF()
PROJECT (dfhack-library)
PROJECT (dfapi)
cmake_minimum_required(VERSION 2.8)
## build options
OPTION(BUILD_DEVEL "Install/package files required for development (For SDK)." OFF)
OPTION(BUILD_DOXYGEN "Create/install/package doxygen documentation for DFHack (For SDK)." OFF)
include_directories (include)
include_directories (depends/md5)
include_directories (depends/tinyxml)
@ -96,11 +96,6 @@ ELSE()
LIST(APPEND PROJECT_SRCS ${PROJECT_SRCS_WINDOWS})
ENDIF()
IF(BUILD_DFHACK_C_BINDINGS)
LIST(APPEND PROJECT_HDRS ${PROJECT_C_HDRS})
LIST(APPEND PROJECT_SRCS ${PROJECT_C_SRCS})
ENDIF()
SET_SOURCE_FILES_PROPERTIES( ${PROJECT_HDRS} PROPERTIES HEADER_FILE_ONLY TRUE )
LIST(APPEND PROJECT_SRCS ${PROJECT_HDRS})
@ -109,12 +104,11 @@ ADD_DEFINITIONS(-DBUILD_DFHACK_LIB)
IF(UNIX)
add_definitions(-DLINUX_BUILD)
find_library(X11_LIBRARY X11)
SET(CMAKE_CXX_FLAGS_DEBUG "-g -Wall")
SET(CMAKE_CXX_FLAGS "-fvisibility=hidden -m32")
SET(CMAKE_C_FLAGS "-fvisibility=hidden -m32")
SET(PROJECT_LIBS ${X11_LIBRARY} rt )
SET(PROJECT_LIBS rt )
ELSE()
IF(MSVC)
SET(PROJECT_LIBS psapi ${dfhack_SOURCE_DIR}/library/depends/ntdll/ntdll.lib)
@ -141,7 +135,7 @@ install(TARGETS dfhack
install(FILES ${dfhack_SOURCE_DIR}/Memory.xml
DESTINATION ${DFHACK_DATA_DESTINATION}) #linux: share/dfhack
if(BUILD_DFHACK_DEVEL)
if(BUILD_DEVEL)
if(WIN32)
install(TARGETS dfhack
ARCHIVE DESTINATION ${DFHACK_DEVLIB_DESTINATION})
@ -151,4 +145,8 @@ if(BUILD_DFHACK_DEVEL)
install(DIRECTORY include/
DESTINATION ${DFHACK_INCLUDES_DESTINATION}
FILES_MATCHING PATTERN "*.h" ) #linux: include
# Building the docs
IF(BUILD_DOXYGEN)
add_subdirectory (doc)
ENDIF()
endif()

@ -117,6 +117,24 @@ DFhackCExport void SDL_DestroyMutex(DFMutex * mutex)
_SDL_DestroyMutex(mutex);
}
static void * (*_SDL_LoadFunction)(DFLibrary *handle, const char *name) = 0;
DFhackCExport void * SDL_LoadFunction(DFLibrary *handle, const char *name)
{
return _SDL_LoadFunction(handle, name);
}
static DFLibrary * (*_SDL_LoadObject)(const char *sofile) = 0;
DFhackCExport DFLibrary * SDL_LoadObject(const char *sofile)
{
return _SDL_LoadObject(sofile);
}
static void (*_SDL_UnloadObject)(DFLibrary * handle) = 0;
DFhackCExport void SDL_UnloadObject(DFLibrary * handle)
{
_SDL_UnloadObject(handle);
}
// hook - called at program exit
DFhackCExport void SDL_Quit(void)
{
@ -141,6 +159,9 @@ DFhackCExport int SDL_Init(uint32_t flags)
_SDL_DestroyMutex = (void (*)(DFMutex*))dlsym(RTLD_NEXT,"SDL_DestroyMutex");
_SDL_mutexP = (int (*)(DFMutex*))dlsym(RTLD_NEXT,"SDL_mutexP");
_SDL_mutexV = (int (*)(DFMutex*))dlsym(RTLD_NEXT,"SDL_mutexV");
_SDL_LoadFunction = (void*(*)(DFLibrary*, const char*))dlsym(RTLD_NEXT,"SDL_LoadFunction");
_SDL_LoadObject = (DFLibrary*(*)(const char*))dlsym(RTLD_NEXT,"SDL_LoadObject");
_SDL_UnloadObject = (void (*)(DFLibrary*))dlsym(RTLD_NEXT,"SDL_UnloadObject");
// check if we got them
if(_SDL_Init && _SDL_Quit && _SDL_CreateThread && _SDL_CreateMutex && _SDL_DestroyMutex && _SDL_mutexP && _SDL_mutexV)

@ -512,20 +512,20 @@ SDL_UnloadObject
extern DECLSPEC void SDLCALL SDL_UnloadObject(void *handle);
*/
static vPtr (*_SDL_LoadFunction)(void *handle, const char *name) = 0;
DFhackCExport vPtr SDL_LoadFunction(void *handle, const char *name)
static void * (*_SDL_LoadFunction)(DFLibrary *handle, const char *name) = 0;
DFhackCExport void * SDL_LoadFunction(DFLibrary *handle, const char *name)
{
return _SDL_LoadFunction(handle, name);
}
static vPtr (*_SDL_LoadObject)(const char *sofile) = 0;
DFhackCExport vPtr SDL_LoadObject(const char *sofile)
static DFLibrary * (*_SDL_LoadObject)(const char *sofile) = 0;
DFhackCExport DFLibrary * SDL_LoadObject(const char *sofile)
{
return _SDL_LoadObject(sofile);
}
static void (*_SDL_UnloadObject)(vPtr handle) = 0;
DFhackCExport void SDL_UnloadObject(vPtr handle)
static void (*_SDL_UnloadObject)(DFLibrary * handle) = 0;
DFhackCExport void SDL_UnloadObject(DFLibrary * handle)
{
_SDL_UnloadObject(handle);
}
@ -803,13 +803,13 @@ bool FirstCall()
// stuff for SDL_Image
_SDL_ClearError = (void (*)())GetProcAddress(realSDLlib,"SDL_ClearError");
_SDL_Error = (void (*)(int))GetProcAddress(realSDLlib,"SDL_Error");
_SDL_LoadFunction = (void*(*)(void*, const char*))GetProcAddress(realSDLlib,"SDL_LoadFunction");
_SDL_LoadObject = (void*(*)(const char*))GetProcAddress(realSDLlib,"SDL_LoadObject");
_SDL_LoadFunction = (void*(*)(DFLibrary*, const char*))GetProcAddress(realSDLlib,"SDL_LoadFunction");
_SDL_LoadObject = (DFLibrary*(*)(const char*))GetProcAddress(realSDLlib,"SDL_LoadObject");
_SDL_ReadBE32 = (uint32_t (*)(void*))GetProcAddress(realSDLlib,"SDL_ReadBE32");
_SDL_ReadLE16 = (uint16_t (*)(void*))GetProcAddress(realSDLlib,"SDL_ReadLE16");
_SDL_ReadLE32 = (uint32_t (*)(void*))GetProcAddress(realSDLlib,"SDL_ReadLE32");
_SDL_SetError = (void (*)(const char*, ...))GetProcAddress(realSDLlib,"SDL_SetError");
_SDL_UnloadObject = (void (*)(void*))GetProcAddress(realSDLlib,"SDL_UnloadObject");
_SDL_UnloadObject = (void (*)(DFLibrary*))GetProcAddress(realSDLlib,"SDL_UnloadObject");
_SDL_FillRect = (int (*)(void*,void*,uint32_t))GetProcAddress(realSDLlib,"SDL_FillRect");
// new in DF 0.31.04

@ -23,7 +23,6 @@ distribution.
*/
#include "Internal.h"
#include "PlatformInternal.h"
#include <string>
#include <vector>
@ -41,8 +40,8 @@ using namespace std;
#include "dfhack/modules/Gui.h"
#include "dfhack/modules/Vegetation.h"
#include "dfhack/modules/Maps.h"
#include <dfhack/modules/World.h>
#include "rlutil.h"
#include "dfhack/modules/World.h"
#include "dfhack/extra/rlutil.h"
#include <stdio.h>
using namespace DFHack;
@ -92,6 +91,7 @@ struct hideblock
uint32_t z;
uint8_t hiddens [16][16];
};
int reveal (void)
{
Core & c = DFHack::Core::getInstance();
@ -288,6 +288,7 @@ int Core::Shutdown ( void )
#define MODULE_GETTER(TYPE) \
TYPE * Core::get##TYPE() \
{ \
if(errorstate) return NULL;\
if(!s_mods.p##TYPE)\
{\
Module * mod = create##TYPE();\

@ -23,7 +23,8 @@ distribution.
*/
#include "Internal.h"
#include "PlatformInternal.h"
#include <dirent.h>
#include <errno.h>
#include <string>
#include <vector>
@ -33,14 +34,11 @@ distribution.
#include <cstring>
using namespace std;
#include <md5wrapper.h>
#include "dfhack/Process.h"
#include "dfhack/VersionInfoFactory.h"
#include "dfhack/VersionInfo.h"
#include "dfhack/Error.h"
#include <errno.h>
#include <sys/ptrace.h>
#include <sys/syscall.h>
#include <md5wrapper.h>
using namespace DFHack;
Process::Process(VersionInfoFactory * known_versions)

@ -23,7 +23,66 @@ distribution.
*/
#include "Internal.h"
#include "PlatformInternal.h"
#define _WIN32_WINNT 0x0501 // needed for INPUT struct
#define WINVER 0x0501 // OpenThread(), PSAPI, Toolhelp32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winnt.h>
#include <psapi.h>
#include <tlhelp32.h>
typedef LONG NTSTATUS;
#define STATUS_SUCCESS ((NTSTATUS)0x00000000L)
// FIXME: it is uncertain how these map to 64bit
typedef struct _DEBUG_BUFFER
{
HANDLE SectionHandle;
PVOID SectionBase;
PVOID RemoteSectionBase;
ULONG SectionBaseDelta;
HANDLE EventPairHandle;
ULONG Unknown[2];
HANDLE RemoteThreadHandle;
ULONG InfoClassMask;
ULONG SizeOfInfo;
ULONG AllocatedSize;
ULONG SectionSize;
PVOID ModuleInformation;
PVOID BackTraceInformation;
PVOID HeapInformation;
PVOID LockInformation;
PVOID Reserved[8];
} DEBUG_BUFFER, *PDEBUG_BUFFER;
typedef struct _DEBUG_HEAP_INFORMATION
{
ULONG Base; // 0×00
ULONG Flags; // 0×04
USHORT Granularity; // 0×08
USHORT Unknown; // 0x0A
ULONG Allocated; // 0x0C
ULONG Committed; // 0×10
ULONG TagCount; // 0×14
ULONG BlockCount; // 0×18
ULONG Reserved[7]; // 0x1C
PVOID Tags; // 0×38
PVOID Blocks; // 0x3C
} DEBUG_HEAP_INFORMATION, *PDEBUG_HEAP_INFORMATION;
// RtlQueryProcessDebugInformation.DebugInfoClassMask constants
#define PDI_MODULES 0x01
#define PDI_BACKTRACE 0x02
#define PDI_HEAPS 0x04
#define PDI_HEAP_TAGS 0x08
#define PDI_HEAP_BLOCKS 0x10
#define PDI_LOCKS 0x20
extern "C" __declspec(dllimport) NTSTATUS __stdcall RtlQueryProcessDebugInformation( IN ULONG ProcessId, IN ULONG DebugInfoClassMask, IN OUT PDEBUG_BUFFER DebugBuffer);
extern "C" __declspec(dllimport) PDEBUG_BUFFER __stdcall RtlCreateQueryDebugBuffer( IN ULONG Size, IN BOOLEAN EventPair);
extern "C" __declspec(dllimport) NTSTATUS __stdcall RtlDestroyQueryDebugBuffer( IN PDEBUG_BUFFER DebugBuffer);
#include <cstring>
#include <cstdio>
#include <cstdlib>

@ -35,12 +35,7 @@ IF(DOXYGEN_FOUND)
# with DOXYGEN_SOURCE_DIR we fill a list of directories and later we write it into
# the Doxyfile with a REGEX REPLACE (see below)
SET( DOXYGEN_SOURCE_DIR
"${dfhack_SOURCE_DIR}/doc/index.dxgen"
"${dfhack_SOURCE_DIR}/library/include"
"${dfhack_SOURCE_DIR}/library/include/dfhack"
"${dfhack_SOURCE_DIR}/library/include/dfhack/modules"
"${dfhack_SOURCE_DIR}/library/include/dfhack-c"
"${dfhack_SOURCE_DIR}/library/include/dfhack-c/modules"
"${dfhack_SOURCE_DIR}/library"
)
STRING(REGEX REPLACE ";" " " CMAKE_DOXYGEN_INPUT_LIST "${DOXYGEN_SOURCE_DIR}")

@ -600,7 +600,7 @@ FILE_PATTERNS = *.cpp \
# should be searched for input files as well. Possible values are YES and NO.
# If left blank NO is used.
RECURSIVE = NO
RECURSIVE = YES
# The EXCLUDE tag can be used to specify files and/or directories that should
# excluded from the INPUT source files. This way you can easily exclude a
@ -628,7 +628,7 @@ EXCLUDE_PATTERNS =
# wildcard * is used, a substring. Examples: ANamespace, AClass,
# AClass::ANamespace, ANamespace::*Test
EXCLUDE_SYMBOLS =
EXCLUDE_SYMBOLS = Private
# The EXAMPLE_PATH tag can be used to specify one or more files or
# directories that contain example code fragments that are included (see

@ -100,7 +100,10 @@ namespace DFHack
Core(Core const&); // Don't Implement
void operator=(Core const&); // Don't implement
bool errorstate;
// mutex for access to DF
DFMutex * AccessMutex;
// mutex for access to the Plugin storage
DFMutex * PluginMutex;
// FIXME: shouldn't be kept around like this
DFHack::VersionInfoFactory * vif;
// Module storage

@ -42,6 +42,7 @@ typedef void * fPtr;
typedef void * vPtr;
struct DFMutex;
struct DFThread;
struct DFLibrary;
// mutex and thread functions. We can call these.
DFhackCExport DFMutex * SDL_CreateMutex(void);
@ -50,6 +51,11 @@ DFhackCExport int SDL_mutexV(DFMutex *);
DFhackCExport void SDL_DestroyMutex(DFMutex *);
DFhackCExport DFThread *SDL_CreateThread(int (*fn)(void *), void *data);
// Functions for loading libraries and looking up exported symbols
DFhackCExport void * SDL_LoadFunction(DFLibrary *handle, const char *name);
DFhackCExport DFLibrary * SDL_LoadObject(const char *sofile);
DFhackCExport void SDL_UnloadObject(DFLibrary * handle);
// these functions are here because they call into DFHack::Core and therefore need to
// be declared as friend functions/known
DFhackCExport int SDL_NumJoysticks(void);

@ -94,7 +94,7 @@ namespace DFHack
};
/**
* Allows low-level access to the memory of an OS process. OS processes can be enumerated by \ref ProcessEnumerator
* Allows low-level access to the memory of an OS process.
* \ingroup grp_context
*/
class DFHACK_EXPORT Process
@ -163,7 +163,7 @@ namespace DFHack
};
/// read a byte
uint16_t readByte(const uint32_t address)
uint8_t readByte(const uint32_t address)
{
return *(uint8_t *)address;
}

@ -1,170 +0,0 @@
// This is just a graveyard of old 40d code. Things in here COULD be turned into modules, but it requires research.
bool API::InitReadEffects ( uint32_t & numeffects )
{
if(d->effectsInited)
FinishReadEffects();
int effects = 0;
try
{
effects = d->offset_descriptor->getAddress ("effects_vector");
}
catch(Error::AllMemdef)
{
return false;
}
d->effectsInited = true;
d->p_effect = new DfVector (d->p, effects);
numeffects = d->p_effect->getSize();
return true;
}
bool API::ReadEffect(const uint32_t index, t_effect_df40d & effect)
{
if(!d->effectsInited)
return false;
if(index >= d->p_effect->getSize())
return false;
// read pointer from vector at position
uint32_t temp = d->p_effect->at (index);
//read effect from memory
d->p->read (temp, sizeof (t_effect_df40d), (uint8_t *) &effect);
return true;
}
// use with care!
bool API::WriteEffect(const uint32_t index, const t_effect_df40d & effect)
{
if(!d->effectsInited)
return false;
if(index >= d->p_effect->getSize())
return false;
// read pointer from vector at position
uint32_t temp = d->p_effect->at (index);
// write effect to memory
d->p->write(temp,sizeof(t_effect_df40d), (uint8_t *) &effect);
return true;
}
void API::FinishReadEffects()
{
if(d->p_effect)
{
delete d->p_effect;
d->p_effect = NULL;
}
d->effectsInited = false;
}
bool API::InitReadNotes( uint32_t &numnotes )
{
try
{
memory_info * minfo = d->offset_descriptor;
int notes = minfo->getAddress ("notes");
d->note_foreground_offset = minfo->getOffset ("note_foreground");
d->note_background_offset = minfo->getOffset ("note_background");
d->note_name_offset = minfo->getOffset ("note_name");
d->note_xyz_offset = minfo->getOffset ("note_xyz");
d->p_notes = new DfVector (d->p, notes);
d->notesInited = true;
numnotes = d->p_notes->getSize();
return true;
}
catch (Error::AllMemdef&)
{
d->notesInited = false;
numnotes = 0;
throw;
}
}
bool API::ReadNote (const int32_t index, t_note & note)
{
if(!d->notesInited) return false;
// read pointer from vector at position
uint32_t temp = d->p_notes->at (index);
note.symbol = d->p->readByte(temp);
note.foreground = d->p->readWord(temp + d->note_foreground_offset);
note.background = d->p->readWord(temp + d->note_background_offset);
d->p->readSTLString (temp + d->note_name_offset, note.name, 128);
d->p->read (temp + d->note_xyz_offset, 3*sizeof (uint16_t), (uint8_t *) &note.x);
return true;
}
bool API::InitReadSettlements( uint32_t & numsettlements )
{
if(!d->InitReadNames()) return false;
try
{
memory_info * minfo = d->offset_descriptor;
int allSettlements = minfo->getAddress ("settlements");
int currentSettlement = minfo->getAddress("settlement_current");
d->settlement_name_offset = minfo->getOffset ("settlement_name");
d->settlement_world_xy_offset = minfo->getOffset ("settlement_world_xy");
d->settlement_local_xy_offset = minfo->getOffset ("settlement_local_xy");
d->p_settlements = new DfVector (d->p, allSettlements);
d->p_current_settlement = new DfVector(d->p, currentSettlement);
d->settlementsInited = true;
numsettlements = d->p_settlements->getSize();
return true;
}
catch (Error::AllMemdef&)
{
d->settlementsInited = false;
numsettlements = 0;
throw;
}
}
bool API::ReadSettlement(const int32_t index, t_settlement & settlement)
{
if(!d->settlementsInited) return false;
if(!d->p_settlements->getSize()) return false;
// read pointer from vector at position
uint32_t temp = d->p_settlements->at (index);
settlement.origin = temp;
d->readName(settlement.name, temp + d->settlement_name_offset);
d->p->read(temp + d->settlement_world_xy_offset, 2 * sizeof(int16_t), (uint8_t *) &settlement.world_x);
d->p->read(temp + d->settlement_local_xy_offset, 4 * sizeof(int16_t), (uint8_t *) &settlement.local_x1);
return true;
}
bool API::ReadCurrentSettlement(t_settlement & settlement)
{
if(!d->settlementsInited) return false;
if(!d->p_current_settlement->getSize()) return false;
uint32_t temp = d->p_current_settlement->at(0);
settlement.origin = temp;
d->readName(settlement.name, temp + d->settlement_name_offset);
d->p->read(temp + d->settlement_world_xy_offset, 2 * sizeof(int16_t), (uint8_t *) &settlement.world_x);
d->p->read(temp + d->settlement_local_xy_offset, 4 * sizeof(int16_t), (uint8_t *) &settlement.local_x1);
return true;
}
void API::FinishReadSettlements()
{
if(d->p_settlements)
{
delete d->p_settlements;
d->p_settlements = NULL;
}
if(d->p_current_settlement)
{
delete d->p_current_settlement;
d->p_current_settlement = NULL;
}
d->settlementsInited = false;
}
void API::FinishReadNotes()
{
if(d->p_notes)
{
delete d->p_notes;
d->p_notes = 0;
}
d->notesInited = false;
}

@ -32,10 +32,6 @@ distribution.
#define BUILD_DFHACK_LIB
#endif
// wizardry for adding quotes to macros
#define _QUOTEME(x) #x
#define QUOT(x) _QUOTEME(x)
// force large file support
#ifdef LINUX_BUILD
#define _FILE_OFFSET_BITS 64

@ -1,102 +0,0 @@
/*
https://github.com/peterix/dfhack
Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com)
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.
*/
#pragma once
#ifndef DFPLATFORMINTERNAL_H_INCLUDED
#define DFPLATFORMINTERNAL_H_INCLUDED
// platform includes and defines
#ifdef LINUX_BUILD
#include <sys/types.h>
#include <sys/ptrace.h>
#include <dirent.h>
#include <unistd.h>
#include <sys/stat.h>
#include <syscall.h>
#include <fcntl.h>
#include <sys/wait.h>
#else
// WINDOWS
#define _WIN32_WINNT 0x0501 // needed for INPUT struct
#define WINVER 0x0501 // OpenThread(), PSAPI, Toolhelp32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winnt.h>
#include <psapi.h>
#include <tlhelp32.h>
//#include <Dbghelp.h> // NOT present in mingw32
typedef LONG NTSTATUS;
#define STATUS_SUCCESS ((NTSTATUS)0x00000000L)
// FIXME: it is uncertain how these map to 64bit
typedef struct _DEBUG_BUFFER
{
HANDLE SectionHandle;
PVOID SectionBase;
PVOID RemoteSectionBase;
ULONG SectionBaseDelta;
HANDLE EventPairHandle;
ULONG Unknown[2];
HANDLE RemoteThreadHandle;
ULONG InfoClassMask;
ULONG SizeOfInfo;
ULONG AllocatedSize;
ULONG SectionSize;
PVOID ModuleInformation;
PVOID BackTraceInformation;
PVOID HeapInformation;
PVOID LockInformation;
PVOID Reserved[8];
} DEBUG_BUFFER, *PDEBUG_BUFFER;
typedef struct _DEBUG_HEAP_INFORMATION
{
ULONG Base; // 0×00
ULONG Flags; // 0×04
USHORT Granularity; // 0×08
USHORT Unknown; // 0x0A
ULONG Allocated; // 0x0C
ULONG Committed; // 0×10
ULONG TagCount; // 0×14
ULONG BlockCount; // 0×18
ULONG Reserved[7]; // 0x1C
PVOID Tags; // 0×38
PVOID Blocks; // 0x3C
} DEBUG_HEAP_INFORMATION, *PDEBUG_HEAP_INFORMATION;
// RtlQueryProcessDebugInformation.DebugInfoClassMask constants
#define PDI_MODULES 0x01
#define PDI_BACKTRACE 0x02
#define PDI_HEAPS 0x04
#define PDI_HEAP_TAGS 0x08
#define PDI_HEAP_BLOCKS 0x10
#define PDI_LOCKS 0x20
extern "C" __declspec(dllimport) NTSTATUS __stdcall RtlQueryProcessDebugInformation( IN ULONG ProcessId, IN ULONG DebugInfoClassMask, IN OUT PDEBUG_BUFFER DebugBuffer);
extern "C" __declspec(dllimport) PDEBUG_BUFFER __stdcall RtlCreateQueryDebugBuffer( IN ULONG Size, IN BOOLEAN EventPair);
extern "C" __declspec(dllimport) NTSTATUS __stdcall RtlDestroyQueryDebugBuffer( IN PDEBUG_BUFFER DebugBuffer);
#endif // WINDOWS
#endif // DFPLATFORMINTERNAL_H_INCLUDED

@ -1,9 +0,0 @@
project(dfoffsetedit)
cmake_minimum_required(VERSION 2.6)
find_package(Qt4 QUIET)
if(QT4_FOUND)
add_subdirectory (src)
else(QT4_FOUND)
MESSAGE(STATUS "Qt4 libraries not found - offset editor can't be built.")
endif(QT4_FOUND)

@ -1,25 +0,0 @@
include_directories(${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR})
set ( dfoffsetedit_SRCS
dfedit.cpp
memxmlModel.cpp
main.cpp
)
SET ( dfoffsetedit_UI
gui/main.ui
)
SET( dfoffsetedit_RCS
gui/resources.qrc
)
# this command will generate rules that will run rcc on all files from dfoffsetedit_RCS
# in result dfoffsetedit_RC_SRCS variable will contain paths to files produced by rcc
QT4_ADD_RESOURCES( dfoffsetedit_RC_SRCS ${dfoffsetedit_RCS} )
QT4_WRAP_UI(dfoffsetedit_UI_h ${dfoffsetedit_UI})
qt4_automoc(${dfoffsetedit_SRCS})
add_executable(dfoffsetedit ${dfoffsetedit_SRCS} ${dfoffsetedit_RC_SRCS} ${dfoffsetedit_UI_h})
target_link_libraries(dfoffsetedit ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTXML_LIBRARY} )

@ -1,95 +0,0 @@
#include "dfedit.h"
#include <QFileDialog>
#include <QDebug>
#include "memxmlModel.h"
dfedit::dfedit(QWidget *parent): QMainWindow(parent)
{
ui.setupUi(this);
connect(ui.actionOpen,SIGNAL(triggered(bool)),this,SLOT(slotOpen(bool)));
connect(ui.actionQuit,SIGNAL(triggered(bool)),this,SLOT(slotQuit(bool)));
connect(ui.actionRun_DF,SIGNAL(triggered(bool)),this,SLOT(slotRunDF(bool)));
connect(ui.actionSave,SIGNAL(triggered(bool)),this,SLOT(slotSave(bool)));
connect(ui.actionSave_As,SIGNAL(triggered(bool)),this,SLOT(slotSaveAs(bool)));
connect(ui.actionSetup_DF_executables,SIGNAL(triggered(bool)),this,SLOT(slotSetupDFs(bool)));
ui.actionOpen->setIcon(QIcon::fromTheme("document-open"));
ui.actionOpen->setIconText(tr("Open"));
ui.actionSave->setIcon(QIcon::fromTheme("document-save"));
ui.actionSave->setIconText(tr("Save"));
ui.actionSave_As->setIcon(QIcon::fromTheme("document-save-as"));
ui.actionSave_As->setIconText(tr("Save As"));
ui.actionRun_DF->setIcon(QIcon::fromTheme("system-run"));
ui.actionRun_DF->setIconText(tr("Run DF"));
ui.actionQuit->setIcon(QIcon::fromTheme("application-exit"));
ui.actionQuit->setIconText(tr("Run DF"));
}
dfedit::~dfedit()
{}
void dfedit::slotOpen(bool )
{
QFileDialog fd(this,tr("Locate the Memoxy.xml file"));
fd.setNameFilter(tr("Memory definition (*.xml)"));
fd.setFileMode(QFileDialog::ExistingFile);
fd.setAcceptMode(QFileDialog::AcceptOpen);
int result = fd.exec();
if(result == QDialog::Accepted)
{
QStringList files = fd.selectedFiles();
QString fileName = files[0];
QDomDocument doc("memxml");
QFile file(fileName);
if(!file.open(QIODevice::ReadOnly))
{
return;
}
if(!doc.setContent(&file))
{
file.close();
return;
}
mod = new MemXMLModel(doc,this);
ui.entryView->setModel(mod);
file.close();
}
}
void dfedit::slotQuit(bool )
{
close();
}
void dfedit::slotSave(bool )
{
// blah
}
void dfedit::slotRunDF(bool )
{
// blah
}
void dfedit::slotSaveAs(bool )
{
QFileDialog fd(this,tr("Choose file to save as..."));
fd.setNameFilter(tr("Memory definition (*.xml)"));
fd.setFileMode(QFileDialog::AnyFile);
fd.selectFile("Memory.xml");
fd.setAcceptMode(QFileDialog::AcceptSave);
int result = fd.exec();
if(result == QDialog::Accepted)
{
QStringList files = fd.selectedFiles();
QString file = files[0];
qDebug() << "File:" << file;
}
}
void dfedit::slotSetupDFs(bool )
{
// dialog showing all the versions in Memory.xml that lets the user set up ways to run those versions...
// currently unimplemented
}
#include "dfedit.moc"

@ -1,26 +0,0 @@
#ifndef dfedit_H
#define dfedit_H
#include <QtGui/QMainWindow>
#include "ui_main.h"
#include "memxmlModel.h"
class dfedit : public QMainWindow
{
Q_OBJECT
public:
dfedit(QWidget *parent = 0);
virtual ~dfedit();
private:
Ui::MainWindow ui;
MemXMLModel * mod;
public slots:
void slotOpen(bool);
void slotQuit(bool);
void slotSave(bool);
void slotSaveAs(bool);
void slotRunDF(bool);
void slotSetupDFs(bool);
};
#endif // dfedit_H

File diff suppressed because it is too large Load Diff

Before

Width:  |  Height:  |  Size: 114 KiB

@ -1,195 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>633</width>
<height>622</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<property name="windowIcon">
<iconset resource="resources.qrc">
<normaloff>:/main_icon/main_64.png</normaloff>:/main_icon/main_64.png</iconset>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QTreeView" name="entryView"/>
</item>
</layout>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<widget class="QToolBar" name="toolBar">
<property name="windowTitle">
<string>toolBar</string>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="actionOpen"/>
<addaction name="actionSave"/>
<addaction name="actionSave_As"/>
<addaction name="actionRun_DF"/>
</widget>
<widget class="QDockWidget" name="descriptioDock">
<property name="features">
<set>QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable</set>
</property>
<property name="allowedAreas">
<set>Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea</set>
</property>
<property name="windowTitle">
<string>Description</string>
</property>
<attribute name="dockWidgetArea">
<number>2</number>
</attribute>
<widget class="QWidget" name="dockWidgetContents">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="DescriptionPanel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>1</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<property name="lineWidth">
<number>1</number>
</property>
<property name="midLineWidth">
<number>0</number>
</property>
<property name="text">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:18px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:xx-large; font-weight:600;&quot;&gt;Title text&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Some other text.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textFormat">
<enum>Qt::AutoText</enum>
</property>
<property name="scaledContents">
<bool>false</bool>
</property>
<property name="alignment">
<set>Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QDockWidget" name="dockWidget">
<property name="floating">
<bool>false</bool>
</property>
<property name="features">
<set>QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable</set>
</property>
<property name="allowedAreas">
<set>Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea</set>
</property>
<property name="windowTitle">
<string>Entries</string>
</property>
<attribute name="dockWidgetArea">
<number>1</number>
</attribute>
<widget class="QWidget" name="dockWidgetContents_2">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QTreeView" name="structureView"/>
</item>
</layout>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>633</width>
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
<property name="title">
<string>File</string>
</property>
<addaction name="actionOpen"/>
<addaction name="actionSave"/>
<addaction name="actionSave_As"/>
<addaction name="actionQuit"/>
</widget>
<widget class="QMenu" name="menuSettings">
<property name="title">
<string>Settings</string>
</property>
<addaction name="actionSetup_DF_executables"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuSettings"/>
</widget>
<action name="actionOpen">
<property name="text">
<string>Open</string>
</property>
</action>
<action name="actionSave">
<property name="text">
<string>Save</string>
</property>
</action>
<action name="actionSave_As">
<property name="text">
<string>Save As</string>
</property>
</action>
<action name="actionQuit">
<property name="text">
<string>Quit</string>
</property>
</action>
<action name="actionRun_DF">
<property name="text">
<string>Run DF</string>
</property>
</action>
<action name="actionSetup_DF_executables">
<property name="text">
<string>Setup DF executables</string>
</property>
</action>
</widget>
<resources>
<include location="resources.qrc"/>
</resources>
<connections/>
</ui>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 718 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

@ -1,7 +0,0 @@
<RCC>
<qresource prefix="main_icon">
<file>main_64.png</file>
<file>main_16.png</file>
<file>main_32.png</file>
</qresource>
</RCC>

@ -1,11 +0,0 @@
#include <QtGui/QApplication>
#include "dfedit.h"
int main(int argc, char** argv)
{
QApplication app(argc, argv);
dfedit appGui;
appGui.show();
return app.exec();
}

@ -1,210 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2005-2006 Trolltech ASA. All rights reserved.
**
** This file was part of the example classes of the Qt Toolkit.
** Now it's being hacked into some other shape... :)
**
** This file may be used under the terms of the GNU General Public
** License version 2.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
** http://www.trolltech.com/products/qt/opensource.html
**
** If you are unsure which license is appropriate for your use, please
** review the following information:
** http://www.trolltech.com/products/qt/licensing.html or contact the
** sales department at sales@trolltech.com.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/
#include "memxmlModel.h"
#include <QtGui>
#include <QtXml>
#include <QDomNode>
#include <QHash>
class DomItem
{
public:
DomItem(QDomNode &node, int row, DomItem *parent = 0);
~DomItem();
DomItem *child(int i);
DomItem *parent();
QDomNode node() const;
int row();
private:
QDomNode domNode;
QHash<int,DomItem*> childItems;
DomItem *parentItem;
int rowNumber;
};
DomItem::DomItem(QDomNode &node, int row, DomItem *parent)
{
domNode = node;
// Record the item's location within its parent.
rowNumber = row;
parentItem = parent;
}
DomItem::~DomItem()
{
QHash<int,DomItem*>::iterator it;
for (it = childItems.begin(); it != childItems.end(); ++it)
delete it.value();
}
QDomNode DomItem::node() const
{
return domNode;
}
DomItem *DomItem::parent()
{
return parentItem;
}
DomItem *DomItem::child(int i)
{
if (childItems.contains(i))
return childItems[i];
if (i >= 0 && i < domNode.childNodes().count()) {
QDomNode childNode = domNode.childNodes().item(i);
DomItem *childItem = new DomItem(childNode, i, this);
childItems[i] = childItem;
return childItem;
}
return 0;
}
int DomItem::row()
{
return rowNumber;
}
MemXMLModel::MemXMLModel(QDomDocument document, QObject *parent)
: QAbstractItemModel(parent), domDocument(document)
{
rootItem = new DomItem(domDocument, 0);
}
MemXMLModel::~MemXMLModel()
{
delete rootItem;
}
int MemXMLModel::columnCount(const QModelIndex & parent) const
{
Q_UNUSED(parent);
return 3;
}
QVariant MemXMLModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (role != Qt::DisplayRole)
return QVariant();
DomItem *item = static_cast<DomItem*>(index.internalPointer());
QDomNode node = item->node();
QStringList attributes;
QDomNamedNodeMap attributeMap = node.attributes();
switch (index.column()) {
case 0:
return node.nodeName();
case 1:
for (int i = 0; (unsigned int)(i) < attributeMap.count(); ++i)
{
QDomNode attribute = attributeMap.item(i);
attributes << attribute.nodeName() + "=\"" +attribute.nodeValue() + "\"";
}
return attributes.join(" ");
case 2:
return node.nodeValue().split("\n").join(" ");
default:
return QVariant();
}
}
Qt::ItemFlags MemXMLModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
{
return Qt::ItemIsEnabled;
}
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
QVariant MemXMLModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
switch (section) {
case 0:
return tr("Name");
case 1:
return tr("Attributes");
case 2:
return tr("Value");
default:
return QVariant();
}
}
return QVariant();
}
QModelIndex MemXMLModel::index(int row, int column, const QModelIndex &parent) const
{
DomItem *parentItem;
if (!parent.isValid())
parentItem = rootItem;
else
parentItem = static_cast<DomItem*>(parent.internalPointer());
DomItem *childItem = parentItem->child(row);
if (childItem)
return createIndex(row, column, childItem);
else
return QModelIndex();
}
QModelIndex MemXMLModel::parent(const QModelIndex &child) const
{
if (!child.isValid())
return QModelIndex();
DomItem *childItem = static_cast<DomItem*>(child.internalPointer());
DomItem *parentItem = childItem->parent();
if (!parentItem || parentItem == rootItem)
return QModelIndex();
return createIndex(parentItem->row(), 0, parentItem);
}
int MemXMLModel::rowCount(const QModelIndex &parent) const
{
DomItem *parentItem;
if (!parent.isValid())
parentItem = rootItem;
else
parentItem = static_cast<DomItem*>(parent.internalPointer());
return parentItem->node().childNodes().count();
}
#include "memxmlModel.moc"

@ -1,30 +0,0 @@
#ifndef memxmlModel_H
#define memxmlModel_H
#include <qabstractitemmodel.h>
#include <qdom.h>
class DomItem;
class MemXMLModel : public QAbstractItemModel
{
Q_OBJECT
public:
MemXMLModel(QDomDocument document, QObject *parent = 0);
~MemXMLModel();
QVariant data(const QModelIndex &index, int role) const;
Qt::ItemFlags flags(const QModelIndex &index) const;
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const;
QModelIndex index(int row, int column,
const QModelIndex &parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex &child) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
private:
QDomDocument domDocument;
DomItem *rootItem;
};
#endif // memxmlModel

3
output/.gitignore vendored

@ -1,3 +0,0 @@
Debug
Release
RelWithDebInfo

@ -1,11 +0,0 @@
# -*- coding: utf-8 -*-
from pydfhack import API
DF = API("Memory.xml")
if DF.Attach():
Mats = DF.materials
stones = Mats.Read_Inorganic_Materials()
print "Dumping all stone"
for matgloss in stones:
print "ID %s, name %s" % (matgloss.id, matgloss.name)
DF.Detach()

@ -1,2 +0,0 @@
# some settings required for dfhack. fucks up local security...
kernel.randomize_va_space = 0

@ -1,2 +0,0 @@
#!/bin/sh
# do nothing. blah.

@ -1,2 +0,0 @@
#!/bin/sh

@ -1,6 +0,0 @@
# some settings required for dfhack. fucks up local security...
# shame on kernel devs and ubuntu people for not providing
# an /official/ way to manipulate things and just putting up roadblocks
# instead of proper design
kernel.randomize_va_space = 0
kernel.yama.ptrace_scope = 0

@ -1,13 +0,0 @@
#!/bin/sh
echo "Setting required kernel parameters."
# I actually do it three times, hoping to hammer this into Ubuntu's dense skull.
sysctl -w kernel.randomize_va_space=0
sysctl -w kernel.yama.ptrace_scope=0
if grep -q "kernel.yama.ptrace_scope=0" /etc/sysctl.conf
then
echo "Already installed into /etc/sysctl.conf, doing nothing."
else
echo "kernel.randomize_va_space=0" >> /etc/sysctl.conf
echo "kernel.yama.ptrace_scope=0" >> /etc/sysctl.conf
fi

@ -1,2 +0,0 @@
#!/bin/sh
# do nothing. blah.

@ -1,13 +0,0 @@
#!/bin/sh
DF_DIR=$(dirname "$0")
cd "${DF_DIR}"
export SDL_DISABLE_LOCK_KEYS=1 # Work around for bug in Debian/Ubuntu SDL patch.
#export SDL_VIDEO_CENTERED=1 # Centre the screen. Messes up resizing.
ldd dwarfort.exe | grep SDL_image | grep -qv "not found$"
if [ $? -eq 0 ]; then
mkdir unused_libs
mv libs/libSDL* unused_libs/
fi
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"./libs" # Update library search path.
export LD_PRELOAD="./libs/libdfconnect.so" # Hack DF!
./dwarfort.exe $* # Go, go, go! :)