DFHack development overview¶
DFHack has various components; this page provides an overview of some. If you are looking to develop a tool for DFHack, developing a script or plugin is likely the most straightforward choice.
Other pages that may be relevant include:
These two diagrams give a very high level overview of where DFHack injects itself in the DF call structure and how the pieces of DFHack itself fit together:
As seen in the diagram Dwarf Fortress utilizes the SDL library, this provides us with an easy to isolate injection point for DFHack.
DFHack plugins are written in C++ and located in the
Currently, documentation on how to write plugins is somewhat sparse. There are
templates that you can use to get started in the
folder, and the source code of existing plugins can also be helpful.
If you want to compile a plugin that you have just added, you will need to add a
Plugins have the ability to make one or more commands available to users of the
DFHack console. Examples include 3dveins (which implements the
command) and reveal (which implements
unreveal, and several
Plugins can also register handlers to run on every tick, and can interface with
the built-in enable and disable commands. For the full plugin API, see the
skeleton plugin or
Installed plugins live in the
hack/plugins folder of a DFHack installation,
and the load family of commands can be used to load a recompiled plugin
without restarting DF.
Run plug at the DFHack prompt for a list of all plugins included in DFHack.
DFHack scripts are written in Lua, with a well-documented library. Referring to existing scripts as well as the API documentation can be helpful when developing new scripts.
The DFHack core has a variety of low-level functions. It is responsible for hooking into DF (via SDL), providing a console, and providing an interface for plugins and scripts to interact with DF.
A lot of shared code to interact with DF in more complicated ways is contained in modules. For example, the Units module contains functions for checking various traits of units, changing nicknames properly, and more. Generally, code that is useful to multiple plugins and scripts should go in the appropriate module, if there is one.
Several modules are also exposed to Lua, although some functions (and some entire modules) are currently only available in C++.
DFHack provides a remote access interface that external tools can connect to and use to interact with DF. See DFHack remote interface for more information.