Skip to content

Commit

Permalink
Merge branch 'develop' into adv-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
myk002 committed Nov 29, 2024
2 parents 67fde2e + 326475c commit 35480a5
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ endif()

if(WIN32)
set(MSVC_MIN_VER 1930)
set(MSVC_MAX_VER 1941)
set(MSVC_MAX_VER 1942)
if(NOT MSVC)
message(SEND_ERROR "No MSVC found! MSVC 2022 version ${MSVC_MIN_VER} to ${MSVC_MAX_VER} is required.")
elseif((MSVC_VERSION LESS MSVC_MIN_VER) OR (MSVC_VERSION GREATER MSVC_MAX_VER))
Expand Down
6 changes: 2 additions & 4 deletions build/build-win64-from-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ if [[ $(id -u) -eq 0 ]]; then
chown -R $builder_uid win64-cross
fi

# Assumes you built a container image called dfhack-build-msvc from
# https://github.com/BenLubar/build-env/tree/master/msvc, see
# docs/dev/compile/Compile.rst.
# Pulls the MSVC build env container from the GitHub registry
#
# NOTE: win64-cross is mounted in /src/build due to the hardcoded `cmake ..` in
# the Dockerfile
Expand All @@ -44,7 +42,7 @@ if ! docker run --rm -i -v "$srcdir":/src -v "$srcdir/build/win64-cross/":/src/b
-e steam_username \
-e steam_password \
--name dfhack-win \
ghcr.io/dfhack/build-env:msvc \
ghcr.io/dfhack/build-env:master \
bash -c "cd /src/build && dfhack-configure windows 64 Release -DCMAKE_INSTALL_PREFIX=/src/build/output -DBUILD_DOCS=1 $CMAKE_EXTRA_ARGS && dfhack-make -j$jobs install" \
; then
echo
Expand Down
8 changes: 8 additions & 0 deletions docs/Core.rst
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,14 @@ used regardless of whether you run Dwarf Fortress from its own app or DFHack's.
counted towards your hours, see the DFHack stub launcher ``--nowait`` option
below.

- ``--skip-size-check``: DFHack normally verifies the sizes of important game
on startup and shuts down if a discrepancy is detected. This is intended to
reduce the risk of misalignments in these structures leading to crashes or
other misbehavior. This option bypasses the check. This option should
normally only be used to facilitate DFHack development. This option will
**not** enable DFHack to be used usefully with a version of DF with which
DFHack has not been aligned.

Options passed to the DFHack Steam stub launcher
------------------------------------------------

Expand Down
8 changes: 3 additions & 5 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ Template for new versions:
# Future

## New Tools
- `infinite-sky`: (reinstated, renamed from ``infiniteSky``) tool for automatically creating new z-levels of sky to build in
- `forceequip`: (reinstated) Forcibly move items into a unit's inventory
- `infinite-sky`: (reinstated, renamed from ``infiniteSky``) automatically create new z-levels of sky to build in
- `forceequip`: (reinstated) forcibly move items into a unit's inventory

## New Features
- `tweak`: ``realistic-melting``: change melting return for inorganic armor parts, shields, weapons, trap components and tools to stop smelters from creating metal, bring melt return for adamantine in line with other metals to ~95% of forging cost. wear reduces melt return by 10% per level
Expand All @@ -63,10 +63,10 @@ Template for new versions:
- `autobutcher`: don't run a scanning and marking cycle on the first tick of a fortress to allow for all custom configuration to be set first
- `nestboxes`: don't consider eggs to be infertile just because the mother has left the nest; eggs can still hatch in this situation
- `timestream`: adjust the incubation counter on fertile eggs so they hatch at the expected time
- `timestream`: fix potential crash in birthday tracking
- `logistics`: don't ignore rotten items when applying stockpile logistics operations (e.g. autodump, autoclaim, etc.)

## Misc Improvements
- DFHack now verifies that critical DF data structures have known sizes and refuses to start if there is a mismatch
- DFHack text edit fields now delete the character at the cursor when you hit the Delete key
- DFHack text edit fields now move the cursor by one word left or right with Ctrl-Left and Ctrl-Right
- DFHack text edit fields now move the cursor to the beginning or end of the line with Home and End
Expand All @@ -81,12 +81,10 @@ Template for new versions:
- The error message that comes up if there is a version mismatch between DF and the installed DFHack now informs you which DF versions are supported by the installed version of DFHack

## API

- ``DFHack::Units``: new function ``setPathGoal``
- ``Units::setAutomaticProfessions``: bay12-provided entry point to assign labors based on work details

## Lua

- ``dfhack.units``: new function ``setPathGoal``
- ``widgets.TabBar``: updated to allow for horizontal scrolling of tabs when there are too many to fit in the available space

Expand Down
2 changes: 1 addition & 1 deletion docs/dev/compile/Compile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ Step 1: prepare a build container
On your Linux host, install and run the docker daemon and then run these commands::

xhost +local:root
docker run -it --env="DISPLAY" --env="QT_X11_NO_MITSHM=1" --volume=/tmp/.X11-unix:/tmp/.X11-unix --user buildmaster --name dfhack-win ghcr.io/dfhack/build-env:msvc
docker run -it --env="DISPLAY" --env="QT_X11_NO_MITSHM=1" --volume=/tmp/.X11-unix:/tmp/.X11-unix --user buildmaster --name dfhack-win ghcr.io/dfhack/build-env:master

The ``xhost`` command and ``--env`` parameters are there so you can eventually
run Dwarf Fortress from the container and have it display on your host.
Expand Down
40 changes: 39 additions & 1 deletion library/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ void get_commands(color_ostream &con, std::vector<std::string> &commands) {
static bool try_autocomplete(color_ostream &con, const std::string &first, std::string &completed)
{
std::vector<std::string> commands, possible;
get_commands(con, commands);

for (auto &command : commands)
if (command.substr(0, first.size()) == first)
possible.push_back(command);
Expand Down Expand Up @@ -1645,6 +1645,44 @@ bool Core::InitMainThread() {
// Init global object pointers
df::global::InitGlobals();

// check key game structure sizes against the global table
// this check is (silently) skipped if either `game` or `global_table` is not defined
// to faciliate the linux symbol discovery process (which runs without any symbols)
// or if --skip-size-check is discovered on the command line

if (df::global::global_table && df::global::game &&
df::global::game->command_line.original.find("--skip-size-check") == std::string::npos)
{
std::stringstream msg;
bool gt_error = false;
static const std::map<const std::string, const size_t> sizechecks{
{ "world", sizeof(df::world) },
{ "game", sizeof(df::gamest) },
{ "plotinfo", sizeof(df::plotinfost) },
};

for (auto& gte : *df::global::global_table)
{
// this will exit the loop when the terminator is hit, in the event the global table size in structures is incorrect
if (gte.address == nullptr || gte.name == nullptr)
break;
std::string name{ gte.name };
if (sizechecks.contains(name) && gte.size != sizechecks.at(name))
{
msg << "Global '" << name << "' size mismatch: is " << gte.size << ", expected " << sizechecks.at(name) << "\n";
gt_error = true;
}
}

if (gt_error)
{
msg << "DFHack cannot safely run under these conditions.\n";
fatal(msg.str(), "DFHack fatal error");
errorstate = true;
return false;
}
}

perf_counters.reset();

return true;
Expand Down
2 changes: 1 addition & 1 deletion library/xml
12 changes: 12 additions & 0 deletions test/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,15 @@ function test.getHackPath_chdir()
expect.eq(clean_path(dfhack.getHackPath()), clean_path(fs.getcwd()))
end)
end

-- validates that the size in df.globals.xml is correct
function test.global_table_size()
local elem_size = df.global_table_entry:sizeof()
local actual_arr_size = 0
while df._displace(df.global.global_table[0], actual_arr_size, elem_size).address do
actual_arr_size = actual_arr_size + 1
end
local declared_arr_size = df.global.global_table:sizeof() // elem_size
expect.eq(declared_arr_size, actual_arr_size,
('global_table size mismatch: expected: %d, actual: %d'):format(declared_arr_size, actual_arr_size))
end

0 comments on commit 35480a5

Please sign in to comment.