2020-07-08 20:52:20 -06:00
|
|
|
===========================
|
|
|
|
DFHack development overview
|
|
|
|
===========================
|
|
|
|
|
2020-07-08 21:38:18 -06:00
|
|
|
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.
|
2020-07-08 20:52:20 -06:00
|
|
|
|
2020-07-08 21:38:18 -06:00
|
|
|
Other pages that may be relevant include:
|
2020-07-08 20:52:20 -06:00
|
|
|
|
2020-07-08 21:38:18 -06:00
|
|
|
- `contributing`
|
|
|
|
- `documentation`
|
|
|
|
- `license`
|
2020-07-08 20:52:20 -06:00
|
|
|
|
|
|
|
|
2020-07-08 21:38:18 -06:00
|
|
|
.. contents:: Contents
|
|
|
|
:local:
|
2020-07-08 20:52:20 -06:00
|
|
|
|
2022-12-11 16:51:27 -07:00
|
|
|
Architecture diagrams
|
|
|
|
---------------------
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
.. image:: https://drive.google.com/uc?export=download&id=1-2yeNMC7WHgMfZ9iQsDQ0dEbLukd_xyU
|
|
|
|
:alt: DFHack logic injection diagram
|
|
|
|
:target: https://drive.google.com/file/d/1-2yeNMC7WHgMfZ9iQsDQ0dEbLukd_xyU
|
|
|
|
:align: center
|
|
|
|
|
|
|
|
.. image:: https://drive.google.com/uc?export=download&id=1--JoEQbzKpVUOkRKDD9HxvuCqtom780F
|
|
|
|
:alt: DFHack tool call graph
|
|
|
|
:target: https://drive.google.com/file/d/1--JoEQbzKpVUOkRKDD9HxvuCqtom780F
|
|
|
|
:align: center
|
2020-07-08 20:52:20 -06:00
|
|
|
|
2020-07-08 21:38:18 -06:00
|
|
|
Plugins
|
|
|
|
-------
|
2020-07-08 20:52:20 -06:00
|
|
|
|
2020-07-08 21:38:18 -06:00
|
|
|
DFHack plugins are written in C++ and located in the ``plugins`` folder.
|
|
|
|
Currently, documentation on how to write plugins is somewhat sparse. There are
|
2022-08-02 13:56:44 -06:00
|
|
|
templates that you can use to get started in the ``plugins/examples``
|
2020-07-08 21:38:18 -06:00
|
|
|
folder, and the source code of existing plugins can also be helpful.
|
2020-07-08 20:52:20 -06:00
|
|
|
|
2020-07-08 21:38:18 -06:00
|
|
|
If you want to compile a plugin that you have just added, you will need to add a
|
|
|
|
call to ``DFHACK_PLUGIN`` in ``plugins/CMakeLists.txt``.
|
|
|
|
|
|
|
|
Plugins have the ability to make one or more commands available to users of the
|
|
|
|
DFHack console. Examples include `3dveins` (which implements the ``3dveins``
|
|
|
|
command) and `reveal` (which implements ``reveal``, ``unreveal``, and several
|
|
|
|
other commands).
|
|
|
|
|
|
|
|
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
|
2022-08-03 17:18:22 -06:00
|
|
|
example ``skeleton`` plugin or ``PluginManager.cpp``.
|
2020-07-08 21:38:18 -06:00
|
|
|
|
2020-07-08 21:46:38 -06:00
|
|
|
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.
|
|
|
|
|
2022-07-10 00:01:31 -06:00
|
|
|
Run `plug` at the DFHack prompt for a list of all plugins included in DFHack.
|
2020-07-08 21:46:38 -06:00
|
|
|
|
2020-07-08 21:38:18 -06:00
|
|
|
Scripts
|
|
|
|
-------
|
|
|
|
|
|
|
|
DFHack scripts can currently be written in Lua or Ruby. The `Lua API <lua-api>`
|
|
|
|
is more complete and currently better-documented, however. Referring to existing
|
|
|
|
scripts as well as the API documentation can be helpful when developing new
|
|
|
|
scripts.
|
|
|
|
|
2022-07-22 15:38:16 -06:00
|
|
|
Scripts included in DFHack live in a separate
|
|
|
|
:source-scripts:`scripts repository <>`. This can be found in the ``scripts``
|
|
|
|
submodule if you have `cloned DFHack <compile-how-to-get-the-code>`, or the
|
|
|
|
``hack/scripts`` folder of an installed copy of DFHack.
|
2020-07-08 21:38:18 -06:00
|
|
|
|
|
|
|
Core
|
|
|
|
----
|
|
|
|
|
2020-07-08 21:46:38 -06:00
|
|
|
The `DFHack core <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.
|
2020-07-08 21:38:18 -06:00
|
|
|
|
|
|
|
Modules
|
|
|
|
-------
|
|
|
|
|
2020-07-08 21:46:38 -06:00
|
|
|
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
|
2020-07-08 21:38:18 -06:00
|
|
|
module, if there is one.
|
|
|
|
|
|
|
|
Several modules are also `exposed to Lua <lua-cpp-func-wrappers>`, although
|
|
|
|
some functions (and some entire modules) are currently only available in C++.
|
2020-07-08 20:52:20 -06:00
|
|
|
|
|
|
|
Remote access interface
|
|
|
|
-----------------------
|
|
|
|
|
2020-07-18 23:13:43 -06:00
|
|
|
DFHack provides a remote access interface that external tools can connect to and
|
|
|
|
use to interact with DF. See `remote` for more information.
|