DFHack Documentation
repository·develop·Indexed 24 days ago
https://github.com/dfhack/dfhackA memory access library and toolset for Dwarf Fortress that provides developers and modders with scripts and plugins to extend and manipulate the game. Includes documentation on built-in commands like quickfort, alias, and keybinding, as well as guides for adding custom Lua scripts, managing blueprints, and using the C++ and Lua map data interfaces.
What's inside DFHack
- DFHack is a memory access library for Dwarf Fortress. It is distributed alongside a collection of scripts and plugins that provide a wide range of tools and functional enhancements for the game.
Overview of DFHack
developDFHack is a memory editing library forDwarf Fortressthat provides a unified, cross-platform environment for developing tools to extend the game. The default distribution includes various tools such as bugfixes, interface improvements, automation tools, and modding tools. It also supports third-party tools.Overview of DFHack Build Dependencies
developDFHack requires several system-level dependencies to build successfully. Some libraries are included as Git submodules and require no action, but the following must be installed on your system:
- Build System: CMake (v3.21+ recommended) and a build tool like
ninja(recommended) ormake. - Compiler:
- Linux: GCC 10 or newer.
- Windows: Microsoft Visual C++ 2022 toolchain (MSVC v143).
- macOS: GCC 4.8 or 7 is recommended.
- Perl 5: Required for code generation (converts XML memory structures into C++ headers and Lua wrappers). Requires
XML::LibXMLandXML::LibXSLT. - Python 3: Required for building documentation via
Sphinx. - Git: Required for contributions.
- Optional Dependencies:
ccache: Strongly recommended to improve build times.OpenGL headers: Required to buildstonesense.zlib: Used forxlsxreader-api->quickfort.
- Build System: CMake (v3.21+ recommended) and a build tool like
Overview of the DFHack Lua API
developDFHack provides extensive support for the Lua scripting language, allowing developers to interact with the game and DFHack itself. The API provides access to:
- Raw data structures used by Dwarf Fortress.
- High-level C++ functions for accessing these structures and interacting with DFHack.
- Functions exported by C++ plugins.
Lua code can be used in two primary ways:
- As scripts: Executed via the DFHack command line prompt, behaving similarly to native C++ commands.
- Via C++ plugins: Invoked directly by plugins written in C++.
Note: This documentation refers specifically to the DFHack Lua API. For information regarding the native Dwarf Fortress Lua API, refer to the Dwarf Fortress Wiki.
Manage buildings with dfhack.buildings
developThedfhack.buildingsmodule provides functions for querying, creating, and manipulating building instances in the game world. It includes high-level functions for checking placement validity, managing stockpile contents, and low-level functions for manual building allocation and construction.Understand the DFHack documentation system
developDFHack documentation is written in
reStructuredText (reST)format and compiled usingSphinx. The documentation is rendered in two ways:- HTML: For viewing in a web browser (available online at
docs.dfhack.org). - Text: For in-game viewing via the
helpandlscommands. In-game help text is read from the installed location inhack/docsunder the DF directory.
Note that documentation compilation is disabled by default in the build process due to Python and Sphinx dependencies. If you are using a downloaded release binary, you only need to build the docs if you are modifying them and want to see changes reflected in-game.
- HTML: For viewing in a web browser (available online at
Understand DFHack CI and Release Workflows
developDFHack uses GitHub workflows to manage continuous integration (CI) validation and release automation. These workflows are defined in YAML files located in the
.github/workflows/directory.Key characteristics:
- Inheritance: Submodules (like
scriptsanddf-structures) can inherit CI logic from the mainDFHack/dfhackrepository to maintain consistency across the organization. - Caching: The project uses GitHub's 10GB cache per repository to speed up builds. Caches are namespaced by key prefixes (e.g.,
gcc-11-releasevsgcc-11-test) to prevent collisions and ensure build speed.
- Inheritance: Submodules (like
Use RemoteFortressReader for remote fortress visualization
developRemoteFortressReader is a plugin that provides an API for real-time remote fortress visualization. It is primarily used as the backend for Armok Vision. It allows for retrieving art image chunks from the fortress data.Configure stockpile settings for stockpiles and quickfort
developThe
data/dfhack-config/stockpiles/directory contains configuration settings used by thestockpilesandquickforttools. These settings allow you to define how items are organized and stored within your fortress.To customize your stockpile behavior, place your configuration files in this directory. For detailed usage instructions, refer to the official documentation for each tool:
- stockpiles: For managing item stockpiles and organization.
- quickfort: For automated fortress construction and resource management.
Use the jobutils plugin to manage workshop jobs
developThe
jobutilsplugin provides commands to inspect and modify details of workshop jobs, such as changing the materials or item types of specific components within a job.Key commands include:
job: Inspect the current job.job list: List all jobs in the selected workshop.job-duplicate: Duplicate the highlighted job (requires being inqmode with a workshop or furnace selected).job-material <inorganic-token>: Change the material of a selected job (inqmode) or jump to a material when choosing building components (inbmode). This only works for inorganic materials.job item-material <item-idx> <material[:subtoken]>: Replace the material ID of a specific item within a job.job item-type <item-idx> <type[:subtype]>: Replace the item type ID of a specific item within a job.
Use the sort tool to search and sort interface lists
developThe
sorttool provides search and sorting functionality for various lists within the Dwarf Fortress interface. This functionality is implemented viaoverlaywidgets.To manage these overlays:
- Move widgets: Use the
gui/overlaycommand. - Enable/Disable widgets: Use the
gui/control-panelcommand.
- Move widgets: Use the
Reverse engineering tools for DF memory
developSeveral third-party tools can be used to analyze DF memory across different platforms:
Cross-platform
- Ghidra: A Java-based framework. Custom DFHack Ghidra scripts (
.javafiles) are available in thedf_miscrepository. - IDA Freeware 7.0: Supports 32-bit and 64-bit executables. Some
.idcscripts are available in thedf_miscrepository. - Hopper: Available on macOS and some Linux distributions.
Windows-specific
- Cheat Engine: Historically used for research.
- Ghidra: A Java-based framework. Custom DFHack Ghidra scripts (