From 5aa246f6b0fb62b472386b9830c3734c6f27c9e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vuchener?= Date: Sat, 8 Apr 2023 12:33:24 +0200 Subject: [PATCH 01/32] plugins: include proto directory from current source directory Updated remotefortressreader for the new behavior. --- plugins/Plugins.cmake | 10 +++++----- plugins/remotefortressreader/CMakeLists.txt | 16 +--------------- plugins/remotefortressreader/proto/.gitignore | 3 +++ .../proto/AdventureControl.proto | 0 .../proto/DwarfControl.proto | 0 .../proto/ItemdefInstrument.proto | 0 .../proto/RemoteFortressReader.proto | 0 .../proto/ui_sidebar_mode.proto | 0 8 files changed, 9 insertions(+), 20 deletions(-) create mode 100644 plugins/remotefortressreader/proto/.gitignore rename plugins/{ => remotefortressreader}/proto/AdventureControl.proto (100%) rename plugins/{ => remotefortressreader}/proto/DwarfControl.proto (100%) rename plugins/{ => remotefortressreader}/proto/ItemdefInstrument.proto (100%) rename plugins/{ => remotefortressreader}/proto/RemoteFortressReader.proto (100%) rename plugins/{ => remotefortressreader}/proto/ui_sidebar_mode.proto (100%) diff --git a/plugins/Plugins.cmake b/plugins/Plugins.cmake index db7582c09..a0cea765f 100644 --- a/plugins/Plugins.cmake +++ b/plugins/Plugins.cmake @@ -6,11 +6,6 @@ if(UNIX) endif() endif() -include_directories("${dfhack_SOURCE_DIR}/library/include") -include_directories("${dfhack_SOURCE_DIR}/library/proto") -include_directories("${CMAKE_CURRENT_SOURCE_DIR}/proto") -include_directories("${dfhack_SOURCE_DIR}/library/depends/xgetopt") - macro(car var) set(${var} ${ARGV1}) endmacro() @@ -123,6 +118,11 @@ macro(dfhack_plugin) add_library(${PLUGIN_NAME} MODULE ${PLUGIN_SOURCES}) ide_folder(${PLUGIN_NAME} "Plugins") + target_include_directories(${PLUGIN_NAME} PRIVATE "${dfhack_SOURCE_DIR}/library/include") + target_include_directories(${PLUGIN_NAME} PRIVATE "${dfhack_SOURCE_DIR}/library/proto") + target_include_directories(${PLUGIN_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/proto") + target_include_directories(${PLUGIN_NAME} PRIVATE "${dfhack_SOURCE_DIR}/library/depends/xgetopt") + if(NUM_PROTO) add_dependencies(${PLUGIN_NAME} generate_proto_${PLUGIN_NAME}) target_link_libraries(${PLUGIN_NAME} dfhack protobuf-lite dfhack-version ${PLUGIN_LINK_LIBRARIES}) diff --git a/plugins/remotefortressreader/CMakeLists.txt b/plugins/remotefortressreader/CMakeLists.txt index 55525bc21..262d163f1 100644 --- a/plugins/remotefortressreader/CMakeLists.txt +++ b/plugins/remotefortressreader/CMakeLists.txt @@ -24,23 +24,9 @@ set(PROJECT_PROTO ui_sidebar_mode ) -set(PLUGIN_PROTOS) -foreach(pbuf ${PROJECT_PROTO}) - list(APPEND PLUGIN_PROTOS ${CMAKE_CURRENT_SOURCE_DIR}/../proto/${pbuf}.proto) -endforeach() - -string(REPLACE ".proto" ".pb.cc" PLUGIN_PROTO_SRCS "${PLUGIN_PROTOS}") -string(REPLACE ".proto" ".pb.h" PLUGIN_PROTO_HDRS "${PLUGIN_PROTOS}") -set_source_files_properties(${PLUGIN_PROTO_SRCS} ${PLUGIN_PROTO_HDRS} PROPERTIES GENERATED TRUE) - -set_source_files_properties( ${PROJECT_HDRS} ${PLUGIN_PROTO_HDRS} PROPERTIES HEADER_FILE_ONLY TRUE) - -# mash them together (headers are marked as headers and nothing will try to compile them) -list(APPEND PROJECT_SRCS ${PROJECT_HDRS} ${PLUGIN_PROTOS} ${PLUGIN_PROTO_SRCS} ${PLUGIN_PROTO_HDRS}) - if(UNIX AND NOT APPLE) set(PROJECT_LIBS ${PROJECT_LIBS} SDL) endif() # this makes sure all the stuff is put in proper places and linked to dfhack -dfhack_plugin(RemoteFortressReader ${PROJECT_SRCS} LINK_LIBRARIES protobuf-lite ${PROJECT_LIBS} COMPILE_FLAGS_MSVC "/FI\"Export.h\"" COMPILE_FLAGS_GCC "-include Export.h -Wno-misleading-indentation" ) +dfhack_plugin(RemoteFortressReader ${PROJECT_SRCS} LINK_LIBRARIES ${PROJECT_LIBS} PROTOBUFS ${PROJECT_PROTO}) diff --git a/plugins/remotefortressreader/proto/.gitignore b/plugins/remotefortressreader/proto/.gitignore new file mode 100644 index 000000000..befabf79d --- /dev/null +++ b/plugins/remotefortressreader/proto/.gitignore @@ -0,0 +1,3 @@ +*.pb.cc +*.pb.cc.rule +*.pb.h diff --git a/plugins/proto/AdventureControl.proto b/plugins/remotefortressreader/proto/AdventureControl.proto similarity index 100% rename from plugins/proto/AdventureControl.proto rename to plugins/remotefortressreader/proto/AdventureControl.proto diff --git a/plugins/proto/DwarfControl.proto b/plugins/remotefortressreader/proto/DwarfControl.proto similarity index 100% rename from plugins/proto/DwarfControl.proto rename to plugins/remotefortressreader/proto/DwarfControl.proto diff --git a/plugins/proto/ItemdefInstrument.proto b/plugins/remotefortressreader/proto/ItemdefInstrument.proto similarity index 100% rename from plugins/proto/ItemdefInstrument.proto rename to plugins/remotefortressreader/proto/ItemdefInstrument.proto diff --git a/plugins/proto/RemoteFortressReader.proto b/plugins/remotefortressreader/proto/RemoteFortressReader.proto similarity index 100% rename from plugins/proto/RemoteFortressReader.proto rename to plugins/remotefortressreader/proto/RemoteFortressReader.proto diff --git a/plugins/proto/ui_sidebar_mode.proto b/plugins/remotefortressreader/proto/ui_sidebar_mode.proto similarity index 100% rename from plugins/proto/ui_sidebar_mode.proto rename to plugins/remotefortressreader/proto/ui_sidebar_mode.proto From 52b869d908aa55410db0574610e64f69bb5502b6 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Fri, 14 Apr 2023 01:22:12 -0700 Subject: [PATCH 02/32] don't read cur_savegame.save_dir when invalid --- library/Core.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/Core.cpp b/library/Core.cpp index b1fe2d389..e9463ec51 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -2083,7 +2083,9 @@ void Core::handleLoadAndUnloadScripts(color_ostream& out, state_change_event eve if (!df::global::world) return; - std::string rawFolder = "save/" + (df::global::world->cur_savegame.save_dir) + "/init"; + + std::string rawFolder = !isWorldLoaded() ? "" : + "save/" + (df::global::world->cur_savegame.save_dir) + "/init"; auto i = table.find(event); if ( i != table.end() ) { From 5ace09fad0addc0fa02ff26bd27affa573fd39b1 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Fri, 14 Apr 2023 01:38:38 -0700 Subject: [PATCH 03/32] use the World module for the data read --- library/Core.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/library/Core.cpp b/library/Core.cpp index e9463ec51..c3c7bb7f2 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -2084,8 +2084,7 @@ void Core::handleLoadAndUnloadScripts(color_ostream& out, state_change_event eve if (!df::global::world) return; - std::string rawFolder = !isWorldLoaded() ? "" : - "save/" + (df::global::world->cur_savegame.save_dir) + "/init"; + std::string rawFolder = !isWorldLoaded() ? "" : "save/" + World::ReadWorldFolder() + "/init"; auto i = table.find(event); if ( i != table.end() ) { From 051baa4e6e2ad27d0a514bbf5da68b31f25ebb96 Mon Sep 17 00:00:00 2001 From: DFHack-Urist via GitHub Actions <63161697+DFHack-Urist@users.noreply.github.com> Date: Sat, 15 Apr 2023 07:12:55 +0000 Subject: [PATCH 04/32] Auto-update submodules library/xml: master --- library/xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/xml b/library/xml index e825025d3..43059670e 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit e825025d399d936548c77578d4a40eb23183af0c +Subproject commit 43059670e7d3338d9a164bc23d0c41994187de9c From ef380e9e1c7b4e019b4e0b31c65cf16f234043c7 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sat, 15 Apr 2023 15:49:36 -0700 Subject: [PATCH 05/32] don't reset planner panel minimized state --- docs/changelog.txt | 1 + plugins/lua/buildingplan/planneroverlay.lua | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index 351e13d76..975caf91f 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -38,6 +38,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: ## Fixes ## Misc Improvements +- `buildingplan`: minimized planner panel stays minimized until you change it again ## Documentation diff --git a/plugins/lua/buildingplan/planneroverlay.lua b/plugins/lua/buildingplan/planneroverlay.lua index 3e06ac79d..8f12c695f 100644 --- a/plugins/lua/buildingplan/planneroverlay.lua +++ b/plugins/lua/buildingplan/planneroverlay.lua @@ -729,7 +729,6 @@ function PlannerOverlay:onInput(keys) return true end self.selected = 1 - self.minimized = false self.subviews.hollow:setOption(false) self:reset() reset_counts_flag = true From af1d886a27a6f3c2cec8d3de1492c75d528aa74e Mon Sep 17 00:00:00 2001 From: DFHack-Urist via GitHub Actions <63161697+DFHack-Urist@users.noreply.github.com> Date: Sun, 16 Apr 2023 03:28:37 +0000 Subject: [PATCH 06/32] Auto-update submodules scripts: master --- scripts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts b/scripts index ec1a69788..7e7a1034c 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit ec1a69788fd6329008672523b622fd8b390fea73 +Subproject commit 7e7a1034c502909fdbb73398865958230da67c69 From c596df2bc57585993e7544908a3c1c8643e5d8dc Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sat, 15 Apr 2023 21:30:51 -0700 Subject: [PATCH 07/32] update new authors from 01 Feb 2023 - 15 Apr 2023 --- docs/about/Authors.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/about/Authors.rst b/docs/about/Authors.rst index 75b9eb4f7..020ed5e76 100644 --- a/docs/about/Authors.rst +++ b/docs/about/Authors.rst @@ -45,6 +45,7 @@ cjhammel cjhammel Clayton Hughes Clément Vuchener cvuchener Corey CoreyJ87 +Cubittus Cubittus daedsidog daedsidog Dan Amlund danamlund Daniel Brooks db48x @@ -133,6 +134,7 @@ Milo Christiansen milochristiansen MithrilTuxedo MithrilTuxedo mizipzor mizipzor moversti moversti +mrrho mrrho Murad Beybalaev Erquint Myk Taylor myk002 napagokc napagokc @@ -158,6 +160,7 @@ Petr Mrázek peterix Pfhreak Pfhreak Pierre Lulé plule Pierre-David Bélanger pierredavidbelanger +PopnROFL PopnROFL potato ppaawwll ppaawwll 🐇🐇🐇🐇 Priit Laes plaes @@ -201,6 +204,7 @@ SeerSkye SeerSkye seishuuu seishuuu Seth Woodworth sethwoodworth Shim Panze Shim-Panze +silverflyone silverflyone simon Simon Jackson sizeak Simon Lees simotek @@ -235,6 +239,7 @@ ViTuRaS ViTuRaS Vjek vjek Warmist warmist Wes Malone wesQ3 +Will H TSM-EVO Will Rogers wjrogers WoosterUK WoosterUK XianMaeve XianMaeve From 67f50eafb0cee72a96b2a890023b4859232c90ed Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sat, 15 Apr 2023 22:26:38 -0700 Subject: [PATCH 08/32] add alias and keybinding for toggling the keyboard cursor --- data/init/dfhack.keybindings.init | 3 +++ data/init/dfhack.tools.init | 1 + docs/changelog.txt | 1 + 3 files changed, 5 insertions(+) diff --git a/data/init/dfhack.keybindings.init b/data/init/dfhack.keybindings.init index 8ce0c3696..0fc596215 100644 --- a/data/init/dfhack.keybindings.init +++ b/data/init/dfhack.keybindings.init @@ -49,6 +49,9 @@ keybinding add Ctrl-H@dwarfmode autodump-destroy-here # apply blueprints to the map keybinding add Ctrl-Shift-Q@dwarfmode gui/quickfort +# toggle keyboard cursor +keybinding add Alt-K@dwarfmode toggle-kbd-cursor + # show information collected by dwarfmonitor #keybinding add Alt-M@dwarfmode/Default "dwarfmonitor prefs" #keybinding add Ctrl-F@dwarfmode/Default "dwarfmonitor stats" diff --git a/data/init/dfhack.tools.init b/data/init/dfhack.tools.init index aaf0cf277..8fd815559 100644 --- a/data/init/dfhack.tools.init +++ b/data/init/dfhack.tools.init @@ -144,3 +144,4 @@ enable \ alias add autounsuspend suspendmanager alias add gui/dig gui/design +alias add toggle-kbd-cursor lua "local flags4 = df.global.d_init.flags4 if flags4.KEYBOARD_CURSOR then flags4.KEYBOARD_CURSOR = false else local guidm = require('gui.dwarfmode') guidm.setCursorPos(guidm.Viewport.get():getCenter()) flags4.KEYBOARD_CURSOR = true end" diff --git a/docs/changelog.txt b/docs/changelog.txt index 351e13d76..3806dd125 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -38,6 +38,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: ## Fixes ## Misc Improvements +- ``toggle-kbd-cursor``: add hotkey for toggling the keyboard cursor (Alt-K) ## Documentation From 86845c5bbff2b58bd5b12f49d7184a4bafd5c36c Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sun, 16 Apr 2023 09:50:57 -0700 Subject: [PATCH 09/32] update author names as per feedback --- docs/about/Authors.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/about/Authors.rst b/docs/about/Authors.rst index 020ed5e76..cf74c6412 100644 --- a/docs/about/Authors.rst +++ b/docs/about/Authors.rst @@ -12,6 +12,7 @@ Name Github Other 8Z 8Z Abel abstern acwatkins acwatkins +Alex Blamey Cubittus Alexander Collins gearsix Alexander Gavrilov angavrilov ag Amber Brown hawkowl @@ -45,7 +46,6 @@ cjhammel cjhammel Clayton Hughes Clément Vuchener cvuchener Corey CoreyJ87 -Cubittus Cubittus daedsidog daedsidog Dan Amlund danamlund Daniel Brooks db48x @@ -204,7 +204,7 @@ SeerSkye SeerSkye seishuuu seishuuu Seth Woodworth sethwoodworth Shim Panze Shim-Panze -silverflyone silverflyone +Silver silverflyone simon Simon Jackson sizeak Simon Lees simotek From 1ec6d90e463cdb270f6f4828064ff5ce4ddb9b6a Mon Sep 17 00:00:00 2001 From: DFHack-Urist via GitHub Actions <63161697+DFHack-Urist@users.noreply.github.com> Date: Mon, 17 Apr 2023 01:06:59 +0000 Subject: [PATCH 10/32] Auto-update submodules scripts: master --- scripts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts b/scripts index 7e7a1034c..726e5633f 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit 7e7a1034c502909fdbb73398865958230da67c69 +Subproject commit 726e5633fd2aa1e0872a3f1553d8823505fca10e From 2dbfa37f54d74168b6f880d68c43617dadf13dd3 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sun, 16 Apr 2023 22:32:50 -0700 Subject: [PATCH 11/32] set version number for feedback release --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bb5c428a6..239892e76 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -191,8 +191,8 @@ if(NOT EXISTS ${dfhack_SOURCE_DIR}/library/xml/codegen.pl endif() # set up versioning. -set(DF_VERSION "50.08") -set(DFHACK_RELEASE "rc1") +set(DF_VERSION "50.07") +set(DFHACK_RELEASE "r2rc1") set(DFHACK_PRERELEASE TRUE) set(DFHACK_VERSION "${DF_VERSION}-${DFHACK_RELEASE}") From d1d521fbdb07eb72e57d2918b48d6c7cfd9a37b3 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sun, 16 Apr 2023 22:34:29 -0700 Subject: [PATCH 12/32] infrastructure for hiding the terminal console on startup --- docs/changelog.txt | 1 + library/Core.cpp | 9 +++++++++ library/lua/dfhack.lua | 7 +++++++ 3 files changed, 17 insertions(+) diff --git a/docs/changelog.txt b/docs/changelog.txt index f7a3102cc..3bb16251c 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -40,6 +40,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: ## Misc Improvements - `buildingplan`: minimized planner panel stays minimized until you change it again - ``toggle-kbd-cursor``: add hotkey for toggling the keyboard cursor (Alt-K) +- `gui/control-panel`: add option for hiding the terminal console by default ## Documentation diff --git a/library/Core.cpp b/library/Core.cpp index c3c7bb7f2..4f06c3d62 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -1314,6 +1314,15 @@ static void run_dfhack_init(color_ostream &out, Core *core) // load user overrides std::vector prefixes(1, "dfhack"); loadScriptFiles(core, out, prefixes, CONFIG_PATH + "init"); + + // if the option is set, hide the terminal + auto L = Lua::Core::State; + Lua::StackUnwinder top(L); + Lua::CallLuaModuleFunction(out, L, "dfhack", "getHideConsoleOnStartup", 0, 1, + Lua::DEFAULT_LUA_LAMBDA, [&](lua_State* L) { + if (lua_toboolean(L, -1)) + core->getConsole().hide(); + }, false); } // Load dfhack.init in a dedicated thread (non-interactive console mode) diff --git a/library/lua/dfhack.lua b/library/lua/dfhack.lua index aa33b62d6..bc543fd10 100644 --- a/library/lua/dfhack.lua +++ b/library/lua/dfhack.lua @@ -51,6 +51,13 @@ if dfhack.is_core_context then SC_UNPAUSED = 8 end +-- User-changeable options + +dfhack.HIDE_CONSOLE_ON_STARTUP = true +function dfhack.getHideConsoleOnStartup() + return dfhack.HIDE_CONSOLE_ON_STARTUP +end + -- Error handling safecall = dfhack.safecall From 16fbea4c1f2bd1e8eac9cbcfc6757eb659be1612 Mon Sep 17 00:00:00 2001 From: DFHack-Urist via GitHub Actions <63161697+DFHack-Urist@users.noreply.github.com> Date: Mon, 17 Apr 2023 05:56:19 +0000 Subject: [PATCH 13/32] Auto-update submodules scripts: master --- scripts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts b/scripts index 726e5633f..5fe9e423b 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit 726e5633fd2aa1e0872a3f1553d8823505fca10e +Subproject commit 5fe9e423bbd5cdb7c6e7e8f1051e3aa8d00c853a From a7aded65e44d95c592eb6713e2a1b9c94028c86d Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Mon, 17 Apr 2023 01:04:03 -0700 Subject: [PATCH 14/32] match new gems category --- library/modules/Materials.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/library/modules/Materials.cpp b/library/modules/Materials.cpp index d73b59922..7a1ef249f 100644 --- a/library/modules/Materials.cpp +++ b/library/modules/Materials.cpp @@ -439,6 +439,7 @@ bool MaterialInfo::matches(const df::dfhack_material_category &cat) const return true; if (cat.bits.milk && linear_index(material->reaction_product.id, std::string("CHEESE_MAT")) >= 0) return true; + TEST(gem, IS_GEM); return false; } From 77c2458900b9cc6d04b7cd9cdfaaaad4a0f7a433 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Mon, 17 Apr 2023 01:05:25 -0700 Subject: [PATCH 15/32] filter by gems (for windows) --- plugins/buildingplan/buildingplan.cpp | 9 +++++++++ plugins/lua/buildingplan.lua | 2 ++ plugins/lua/buildingplan/filterselection.lua | 1 + 3 files changed, 12 insertions(+) diff --git a/plugins/buildingplan/buildingplan.cpp b/plugins/buildingplan/buildingplan.cpp index 1d9f58416..e2f964a44 100644 --- a/plugins/buildingplan/buildingplan.cpp +++ b/plugins/buildingplan/buildingplan.cpp @@ -150,6 +150,7 @@ static const df::dfhack_material_category stone_cat(df::dfhack_material_category static const df::dfhack_material_category wood_cat(df::dfhack_material_category::mask_wood); static const df::dfhack_material_category metal_cat(df::dfhack_material_category::mask_metal); static const df::dfhack_material_category glass_cat(df::dfhack_material_category::mask_glass); +static const df::dfhack_material_category gem_cat(df::dfhack_material_category::mask_gem); static const df::dfhack_material_category clay_cat(df::dfhack_material_category::mask_clay); static const df::dfhack_material_category cloth_cat(df::dfhack_material_category::mask_cloth); static const df::dfhack_material_category silk_cat(df::dfhack_material_category::mask_silk); @@ -169,6 +170,9 @@ static void cache_matched(int16_t type, int32_t index) { } else if (mi.matches(glass_cat)) { DEBUG(status).print("cached glass material: %s (%d, %d)\n", mi.toString().c_str(), type, index); mat_cache.emplace(mi.toString(), std::make_pair(mi, "glass")); + } else if (mi.matches(gem_cat)) { + DEBUG(status).print("cached gem material: %s (%d, %d)\n", mi.toString().c_str(), type, index); + mat_cache.emplace(mi.toString(), std::make_pair(mi, "gem")); } else if (mi.matches(clay_cat)) { DEBUG(status).print("cached clay material: %s (%d, %d)\n", mi.toString().c_str(), type, index); mat_cache.emplace(mi.toString(), std::make_pair(mi, "clay")); @@ -800,6 +804,8 @@ static int setMaterialMaskFilter(lua_State *L) { mask |= metal_cat.whole; else if (cat == "glass") mask |= glass_cat.whole; + else if (cat == "gem") + mask |= gem_cat.whole; else if (cat == "clay") mask |= clay_cat.whole; else if (cat == "cloth") @@ -850,6 +856,7 @@ static int getMaterialMaskFilter(lua_State *L) { ret.emplace("wood", !bits || bits & wood_cat.whole); ret.emplace("metal", !bits || bits & metal_cat.whole); ret.emplace("glass", !bits || bits & glass_cat.whole); + ret.emplace("gem", !bits || bits & gem_cat.whole); ret.emplace("clay", !bits || bits & clay_cat.whole); ret.emplace("cloth", !bits || bits & cloth_cat.whole); ret.emplace("silk", !bits || bits & silk_cat.whole); @@ -897,6 +904,8 @@ static int setMaterialFilter(lua_State *L) { mask.whole |= metal_cat.whole; else if (mat.matches(glass_cat)) mask.whole |= glass_cat.whole; + else if (mat.matches(gem_cat)) + mask.whole |= gem_cat.whole; else if (mat.matches(clay_cat)) mask.whole |= clay_cat.whole; else if (mat.matches(cloth_cat)) diff --git a/plugins/lua/buildingplan.lua b/plugins/lua/buildingplan.lua index 2de467f7c..d64317eb0 100644 --- a/plugins/lua/buildingplan.lua +++ b/plugins/lua/buildingplan.lua @@ -111,6 +111,8 @@ function get_desc(filter) desc = 'Ballista part' elseif desc == 'Catapultpart' then desc = 'Catapult part' + elseif desc == 'Smallgem' then + desc = 'Small, cut gem' end return desc diff --git a/plugins/lua/buildingplan/filterselection.lua b/plugins/lua/buildingplan/filterselection.lua index 498c89c1e..968ad88d9 100644 --- a/plugins/lua/buildingplan/filterselection.lua +++ b/plugins/lua/buildingplan/filterselection.lua @@ -452,6 +452,7 @@ function QualityAndMaterialsPage:refresh() make_cat_choice('Wood', 'wood', 'CUSTOM_SHIFT_O', cats), make_cat_choice('Metal', 'metal', 'CUSTOM_SHIFT_M', cats), make_cat_choice('Glass', 'glass', 'CUSTOM_SHIFT_G', cats), + make_cat_choice('Gem', 'gem', 'CUSTOM_SHIFT_E', cats), make_cat_choice('Clay', 'clay', 'CUSTOM_SHIFT_C', cats), make_cat_choice('Cloth', 'cloth', 'CUSTOM_SHIFT_L', cats), make_cat_choice('Silk', 'silk', 'CUSTOM_SHIFT_K', cats), From b26d6a90ca9edd1b8b19185cea285eed4c03803b Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Mon, 17 Apr 2023 01:06:06 -0700 Subject: [PATCH 16/32] update structures head --- library/xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/xml b/library/xml index 43059670e..1413d3c67 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit 43059670e7d3338d9a164bc23d0c41994187de9c +Subproject commit 1413d3c67c5bd85e6afbef45d8b1ade6b8389ede From eb9e40a24d6023470725959f46f2d5fe3c83daf8 Mon Sep 17 00:00:00 2001 From: John Reid Date: Mon, 17 Apr 2023 10:43:14 +0200 Subject: [PATCH 17/32] Fix typo in Quickstart.rst Fixes a typo in Quickstart.rst: mangager -> manager --- docs/Quickstart.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Quickstart.rst b/docs/Quickstart.rst index 065ba6ecc..f4a022a9c 100644 --- a/docs/Quickstart.rst +++ b/docs/Quickstart.rst @@ -162,7 +162,7 @@ You can run them all from the launcher. First, let's import some useful manager orders to keep your fort stocked with basic necessities. Run ``orders import library/basic``. If you go to your -mangager orders screen, you can see all the orders that have been created for you. +manager orders screen, you can see all the orders that have been created for you. Note that you could have imported the orders directly from this screen as well, using the DFHack `overlay` widget at the bottom of the manager orders panel. From e9f6695aceb9918ff56b3c8596498cd44faee033 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Mon, 17 Apr 2023 09:39:15 -0700 Subject: [PATCH 18/32] infrastructure for hiding armok tools --- docs/Tags.rst | 2 +- docs/changelog.txt | 3 ++- library/lua/dfhack.lua | 5 +++++ library/lua/helpdb.lua | 17 +++++++++++++++-- plugins/hotkeys.cpp | 39 +++++++++++++++++++++++++++++++-------- plugins/lua/hotkeys.lua | 13 +++++++++++++ 6 files changed, 67 insertions(+), 12 deletions(-) diff --git a/docs/Tags.rst b/docs/Tags.rst index 5ff13d632..c7b284d07 100644 --- a/docs/Tags.rst +++ b/docs/Tags.rst @@ -21,7 +21,7 @@ for the tag assignment spreadsheet. "why" tags ---------- -- `armok `: Tools that give you complete control over an aspect of the game or provide access to information that the game intentionally keeps hidden. +- `armok `: Tools that give you complete control over an aspect of the game or provide access to information that the game intentionally keeps hidden. Players that do not wish to see these tools listed in DFHack command lists can hide them in the ``Preferences`` tab of `gui/control-panel`. - `auto `: Tools that run in the background and automatically manage routine, toilsome aspects of your fortress. - `bugfix `: Tools that fix specific bugs, either permanently or on-demand. - `design `: Tools that help you design your fort. diff --git a/docs/changelog.txt b/docs/changelog.txt index 3bb16251c..553fb3362 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -40,7 +40,8 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: ## Misc Improvements - `buildingplan`: minimized planner panel stays minimized until you change it again - ``toggle-kbd-cursor``: add hotkey for toggling the keyboard cursor (Alt-K) -- `gui/control-panel`: add option for hiding the terminal console by default +- `gui/control-panel`: add preference option for hiding the terminal console on startup +- `gui/control-panel`: add preference option for hiding "armok" tools in command lists ## Documentation diff --git a/library/lua/dfhack.lua b/library/lua/dfhack.lua index bc543fd10..78d978147 100644 --- a/library/lua/dfhack.lua +++ b/library/lua/dfhack.lua @@ -58,6 +58,11 @@ function dfhack.getHideConsoleOnStartup() return dfhack.HIDE_CONSOLE_ON_STARTUP end +dfhack.HIDE_ARMOK_TOOLS = false +function dfhack.getHideArmokTools() + return dfhack.HIDE_ARMOK_TOOLS +end + -- Error handling safecall = dfhack.safecall diff --git a/library/lua/helpdb.lua b/library/lua/helpdb.lua index a7ac6226f..4ce078a22 100644 --- a/library/lua/helpdb.lua +++ b/library/lua/helpdb.lua @@ -788,7 +788,11 @@ function ls(filter_str, skip_tags, show_dev_commands, exclude_strs) table.insert(excludes, {str=argparse.stringList(exclude_strs)}) end if not show_dev_commands then - table.insert(excludes, {tag='dev'}) + local dev_tags = {'dev', 'unavailable'} + if dfhack.getHideArmokTools() then + table.insert(dev_tags, 'armok') + end + table.insert(excludes, {tag=dev_tags}) end list_entries(skip_tags, include, excludes) end @@ -813,7 +817,16 @@ function tags(tag) local skip_tags = true local include = {entry_type={ENTRY_TYPES.COMMAND}, tag=tag} - list_entries(skip_tags, include) + + local excludes = {tag={}} + if tag ~= 'unavailable' then + table.insert(excludes.tag, 'unavailable') + end + if tag ~= 'armok' and dfhack.getHideArmokTools() then + table.insert(excludes.tag, 'armok') + end + + list_entries(skip_tags, include, excludes) end return _ENV diff --git a/plugins/hotkeys.cpp b/plugins/hotkeys.cpp index 788a4c02b..136ad7a9d 100644 --- a/plugins/hotkeys.cpp +++ b/plugins/hotkeys.cpp @@ -49,7 +49,22 @@ static int cleanupHotkeys(lua_State *) { return 0; } -static void add_binding_if_valid(const string &sym, const string &cmdline, df::viewscreen *screen, bool filtermenu) { +static bool should_hide_armok(color_ostream &out, const string &cmdline) { + bool should_hide = false; + + auto L = Lua::Core::State; + Lua::StackUnwinder top(L); + Lua::CallLuaModuleFunction(out, L, "plugins.hotkeys", "should_hide_armok", 1, 1, + [&](lua_State *L){ + Lua::Push(L, cmdline); + }, [&](lua_State *L){ + should_hide = lua_toboolean(L, -1); + }); + + return should_hide; +} + +static void add_binding_if_valid(color_ostream &out, const string &sym, const string &cmdline, df::viewscreen *screen, bool filtermenu) { if (!can_invoke(cmdline, screen)) return; @@ -59,6 +74,11 @@ static void add_binding_if_valid(const string &sym, const string &cmdline, df::v return; } + if (should_hide_armok(out, cmdline)) { + DEBUG(log).print("filtering out armok keybinding\n"); + return; + } + current_bindings[sym] = cmdline; sorted_keys.push_back(sym); string keyspec = sym + "@" + MENU_SCREEN_FOCUS_STRING; @@ -67,7 +87,7 @@ static void add_binding_if_valid(const string &sym, const string &cmdline, df::v Core::getInstance().AddKeyBinding(keyspec, binding); } -static void find_active_keybindings(df::viewscreen *screen, bool filtermenu) { +static void find_active_keybindings(color_ostream &out, df::viewscreen *screen, bool filtermenu) { DEBUG(log).print("scanning for active keybindings\n"); if (valid) cleanupHotkeys(NULL); @@ -103,7 +123,7 @@ static void find_active_keybindings(df::viewscreen *screen, bool filtermenu) { string::size_type colon_pos = invoke_cmd->find(":"); // colons at location 0 are for commands like ":lua" if (colon_pos == string::npos || colon_pos == 0) { - add_binding_if_valid(sym, *invoke_cmd, screen, filtermenu); + add_binding_if_valid(out, sym, *invoke_cmd, screen, filtermenu); } else { vector tokens; @@ -111,7 +131,7 @@ static void find_active_keybindings(df::viewscreen *screen, bool filtermenu) { string focus = tokens[0].substr(1); if(Gui::matchFocusString(focus)) { auto cmdline = trim(tokens[1]); - add_binding_if_valid(sym, cmdline, screen, filtermenu); + add_binding_if_valid(out, sym, cmdline, screen, filtermenu); } } } @@ -124,7 +144,10 @@ static void find_active_keybindings(df::viewscreen *screen, bool filtermenu) { } static int getHotkeys(lua_State *L) { - find_active_keybindings(Gui::getCurViewscreen(true), true); + color_ostream *out = Lua::GetOutput(L); + if (!out) + out = &Core::getInstance().getConsole(); + find_active_keybindings(*out, Gui::getCurViewscreen(true), true); Lua::PushVector(L, sorted_keys); Lua::Push(L, current_bindings); return 2; @@ -140,7 +163,7 @@ static void list(color_ostream &out) { DEBUG(log).print("listing active hotkeys\n"); bool was_valid = valid; if (!valid) - find_active_keybindings(Gui::getCurViewscreen(true), false); + find_active_keybindings(out, Gui::getCurViewscreen(true), false); out.print("Valid keybindings for the current focus:\n %s\n", join_strings("\n", Gui::getCurFocus(true)).c_str()); @@ -176,6 +199,8 @@ static command_result hotkeys_cmd(color_ostream &out, vector & paramete return Core::getInstance().runCommand(out, INVOKE_MENU_COMMAND ); } + CoreSuspender guard; + if (parameters[0] == "list") { list(out); return CR_OK; @@ -185,8 +210,6 @@ static command_result hotkeys_cmd(color_ostream &out, vector & paramete if (parameters.size() != 2 || parameters[0] != "invoke") return CR_WRONG_USAGE; - CoreSuspender guard; - int index = string_to_int(parameters[1], -1); if (index < 0) return CR_WRONG_USAGE; diff --git a/plugins/lua/hotkeys.lua b/plugins/lua/hotkeys.lua index 8edb70073..ec5699fe4 100644 --- a/plugins/lua/hotkeys.lua +++ b/plugins/lua/hotkeys.lua @@ -5,6 +5,19 @@ local helpdb = require('helpdb') local overlay = require('plugins.overlay') local widgets = require('gui.widgets') +local function get_command(cmdline) + local first_word = cmdline:trim():split(' +')[1] + if first_word:startswith(':') then first_word = first_word:sub(2) end + return first_word +end + +function should_hide_armok(cmdline) + local first_word = get_command(cmdline) + return dfhack.getHideArmokTools() and + helpdb.is_entry(first_word) and + helpdb.get_entry_tags(first_word).armok +end + -- ----------------- -- -- HotspotMenuWidget -- -- ----------------- -- From f6031e6a799fac2cd7d9b738e99d93d9eb5d2e7e Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Mon, 17 Apr 2023 13:04:42 -0700 Subject: [PATCH 19/32] refactor existing logic to use new function --- plugins/lua/hotkeys.lua | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/plugins/lua/hotkeys.lua b/plugins/lua/hotkeys.lua index ec5699fe4..b162f0c08 100644 --- a/plugins/lua/hotkeys.lua +++ b/plugins/lua/hotkeys.lua @@ -12,10 +12,10 @@ local function get_command(cmdline) end function should_hide_armok(cmdline) - local first_word = get_command(cmdline) + local command = get_command(cmdline) return dfhack.getHideArmokTools() and - helpdb.is_entry(first_word) and - helpdb.get_entry_tags(first_word).armok + helpdb.is_entry(command) and + helpdb.get_entry_tags(command).armok end -- ----------------- -- @@ -245,10 +245,9 @@ end function Menu:onSelect(_, choice) if not choice or #self.subviews == 0 then return end - local first_word = choice.command:trim():split(' +')[1] - if first_word:startswith(':') then first_word = first_word:sub(2) end - self.subviews.help.text_to_wrap = helpdb.is_entry(first_word) and - helpdb.get_entry_short_help(first_word) or 'Command not found' + local command = get_command(choice.command) + self.subviews.help.text_to_wrap = helpdb.is_entry(command) and + helpdb.get_entry_short_help(command) or 'Command not found' self.subviews.help_panel:updateLayout() end From 3307427718814d7f6109828a9b39a95ce0b6f7aa Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Mon, 17 Apr 2023 13:29:58 -0700 Subject: [PATCH 20/32] update wording (thanks Ozzatron!) --- docs/Tags.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/Tags.rst b/docs/Tags.rst index c7b284d07..ded15c4c2 100644 --- a/docs/Tags.rst +++ b/docs/Tags.rst @@ -21,7 +21,9 @@ for the tag assignment spreadsheet. "why" tags ---------- -- `armok `: Tools that give you complete control over an aspect of the game or provide access to information that the game intentionally keeps hidden. Players that do not wish to see these tools listed in DFHack command lists can hide them in the ``Preferences`` tab of `gui/control-panel`. +- `armok `: Tools which give the player god-like powers of any variety, such as control over game events, creating items from thin air, or viewing information the game intentionally keeps hidden. Players that do not wish to see these tools listed in DFHack command lists can hide them in the ``Preferences`` tab of `gui/control-panel`. + + - `auto `: Tools that run in the background and automatically manage routine, toilsome aspects of your fortress. - `bugfix `: Tools that fix specific bugs, either permanently or on-demand. - `design `: Tools that help you design your fort. From c30c59c261e5c64a7573511e676a31d8d9867502 Mon Sep 17 00:00:00 2001 From: DFHack-Urist via GitHub Actions <63161697+DFHack-Urist@users.noreply.github.com> Date: Tue, 18 Apr 2023 07:13:59 +0000 Subject: [PATCH 21/32] Auto-update submodules library/xml: master scripts: master --- library/xml | 2 +- scripts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library/xml b/library/xml index 1413d3c67..ae268954d 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit 1413d3c67c5bd85e6afbef45d8b1ade6b8389ede +Subproject commit ae268954da3cde1c4e08f6d62273a17aae0d94da diff --git a/scripts b/scripts index 5fe9e423b..6fba9905a 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit 5fe9e423bbd5cdb7c6e7e8f1051e3aa8d00c853a +Subproject commit 6fba9905a71f626ecc640fd3de988e147d16cb4e From 495c94127a47f660c5bc94ece7a080d1c3dcef68 Mon Sep 17 00:00:00 2001 From: DFHack-Urist via GitHub Actions <63161697+DFHack-Urist@users.noreply.github.com> Date: Tue, 18 Apr 2023 10:19:25 +0000 Subject: [PATCH 22/32] Auto-update submodules depends/xlsxio: dfhack --- depends/xlsxio | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depends/xlsxio b/depends/xlsxio index 439fdbc25..0a9945266 160000 --- a/depends/xlsxio +++ b/depends/xlsxio @@ -1 +1 @@ -Subproject commit 439fdbc259c13f23a3122e68ba35ad5a13bcd97c +Subproject commit 0a994526622c2201756e386ef98b44b193e25f06 From ed87075cb8b3875936c9823c8802d20b06f61e63 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Tue, 18 Apr 2023 05:40:51 -0500 Subject: [PATCH 23/32] cmake minimum version 3.21 forced by this being the lowest version that supports vs 2022 --- depends/clsocket | 2 +- depends/lua/CMakeLists.txt | 2 +- library/CMakeLists.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/depends/clsocket b/depends/clsocket index 6ed8aa464..d5e17c601 160000 --- a/depends/clsocket +++ b/depends/clsocket @@ -1 +1 @@ -Subproject commit 6ed8aa46462ea01a1122fc49422840a2facc9757 +Subproject commit d5e17c6012e7eefb0cbe3e130a56c24bd11f0094 diff --git a/depends/lua/CMakeLists.txt b/depends/lua/CMakeLists.txt index c3ff0c16f..efded915f 100644 --- a/depends/lua/CMakeLists.txt +++ b/depends/lua/CMakeLists.txt @@ -1,5 +1,5 @@ project(lua CXX) -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.21) set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -DLUA_USE_APICHECK") diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index a3fcb8b6f..31cfb007d 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -1,5 +1,5 @@ project(dfapi) -cmake_minimum_required(VERSION 2.8.12) +cmake_minimum_required(VERSION 3.21) # prevent CMake warnings about INTERFACE_LINK_LIBRARIES vs LINK_INTERFACE_LIBRARIES cmake_policy(SET CMP0022 NEW) From 649d72e658890246585e23f830b0142595c94e50 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Tue, 18 Apr 2023 08:28:00 -0700 Subject: [PATCH 24/32] add missed NO_LOGIC_SCREEN to the list adopt_region also kills the top viewscreen on transition --- library/lua/gui.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/library/lua/gui.lua b/library/lua/gui.lua index 64e203d3c..e425dbcf1 100644 --- a/library/lua/gui.lua +++ b/library/lua/gui.lua @@ -745,6 +745,7 @@ end local NO_LOGIC_SCREENS = { 'viewscreen_loadgamest', + 'viewscreen_adopt_regionst', 'viewscreen_export_regionst', 'viewscreen_choose_game_typest', 'viewscreen_worldst', From 150708f21db8a401a8e62f98f2c6e8ba8911d416 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Tue, 18 Apr 2023 05:00:36 -0500 Subject: [PATCH 25/32] build lanchdf with steam sdk --- .gitignore | 3 +++ CMakeLists.txt | 13 ++++++++++++ package/windows/CMakeLists.txt | 10 +++++---- package/windows/{launchdf.c => launchdf.cpp} | 22 ++++++++++++++++++-- 4 files changed, 42 insertions(+), 6 deletions(-) rename package/windows/{launchdf.c => launchdf.cpp} (76%) diff --git a/.gitignore b/.gitignore index e24f11252..a386b260a 100644 --- a/.gitignore +++ b/.gitignore @@ -80,3 +80,6 @@ tags # external plugins /plugins/CMakeLists.custom.txt + +# steam api +depends/steam diff --git a/CMakeLists.txt b/CMakeLists.txt index 239892e76..899063d9d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -312,6 +312,19 @@ if(WIN32) ${SDLREAL_DOWNLOAD_DIR}/SDLreal.dll "5a09604daca6b2b5ce049d79af935d6a") endif() + + # download Steam SDK + set (STEAMAPI_DIR ${dfhack_SOURCE_DIR}/depends/steam/) + download_file("https://partner.steamgames.com/downloads/steamworks_sdk_156.zip" + ${STEAMAPI_DIR}/steamworks_sdk_156.zip + "af5a579990dbe5ae4c1b0689260d001b") + file(ARCHIVE_EXTRACT + INPUT ${STEAMAPI_DIR}/steamworks_sdk_156.zip + DESTINATION ${STEAMAPI_DIR}) + set(STEAMAPI_LIBRARY "${STEAMAPI_DIR}/sdk/redistributable_bin/win64/steam_api64.lib") + set(STEAMAPI_SOURCE_DIR "${STEAMAPI_DIR}/sdk/public/steam") + set(STEAMAPI_SHARED_LIBRARY "${STEAMAPI_DIR}/sdk/redistributable_bin/win64/steam_api64.dll") + endif() if(APPLE) diff --git a/package/windows/CMakeLists.txt b/package/windows/CMakeLists.txt index a5877f117..42151e663 100644 --- a/package/windows/CMakeLists.txt +++ b/package/windows/CMakeLists.txt @@ -1,7 +1,9 @@ project(package_windows) if(WIN32) - add_executable(launchdf WIN32 launchdf.c) - install(TARGETS launchdf - DESTINATION ${DFHACK_DATA_DESTINATION}) -endif() + include_directories(${STEAMAPI_SOURCE_DIR}) + link_libraries(${STEAMAPI_LIBRARY}) + add_executable(launchdf WIN32 launchdf.cpp) + install(TARGETS launchdf DESTINATION ${DFHACK_DATA_DESTINATION}) + install(FILES ${STEAMAPI_SHARED_LIBRARY} DESTINATION ${DFHACK_DATA_DESTINATION}) +endif() \ No newline at end of file diff --git a/package/windows/launchdf.c b/package/windows/launchdf.cpp similarity index 76% rename from package/windows/launchdf.c rename to package/windows/launchdf.cpp index 992bf6636..804163960 100644 --- a/package/windows/launchdf.c +++ b/package/windows/launchdf.cpp @@ -1,13 +1,17 @@ #include #include +#include "steam_api.h" + +const uint32 DFHACK_STEAM_APPID = 2346660; static BOOL is_running_on_wine() { - static const char *(CDECL *pwine_get_version)(void); + typedef const char* (CDECL wine_get_version)(void); + static wine_get_version* pwine_get_version; HMODULE hntdll = GetModuleHandle("ntdll.dll"); if(!hntdll) return FALSE; - pwine_get_version = (void *)GetProcAddress(hntdll, "wine_get_version"); + pwine_get_version = (wine_get_version*) GetProcAddress(hntdll, "wine_get_version"); return !!pwine_get_version; } @@ -61,6 +65,20 @@ static BOOL launch_direct() { } int WINAPI wWinMain(HINSTANCE hi, HINSTANCE hpi, PWSTR cmd, int ns) { + + if (SteamAPI_RestartAppIfNecessary(DFHACK_STEAM_APPID)) // Replace with your App ID + { + return 1; + } + + if (!SteamAPI_Init()) + { + printf("Fatal Error - Steam must be running to play this game (SteamAPI_Init() failed).\n"); + return 1; + } + + return 0; + LPCWSTR err = is_running_on_wine() ? launch_via_steam_posix() : launch_via_steam_windows(); if (err && !launch_direct()) { From f336771284b152684cc4eb22cb6856330c649faf Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Tue, 18 Apr 2023 08:21:54 -0500 Subject: [PATCH 26/32] launchdf rewrite this rewrites launchdf so that the dfhack launcher attempts to linger while df is running --- CMakeLists.txt | 6 +- package/windows/launchdf.cpp | 171 +++++++++++++++++++++++++++++++---- 2 files changed, 155 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 899063d9d..cf5586dfd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -314,10 +314,10 @@ if(WIN32) endif() # download Steam SDK - set (STEAMAPI_DIR ${dfhack_SOURCE_DIR}/depends/steam/) - download_file("https://partner.steamgames.com/downloads/steamworks_sdk_156.zip" + set (STEAMAPI_DIR ${dfhack_SOURCE_DIR}/depends/steam) + file(DOWNLOAD "https://partner.steamgames.com/downloads/steamworks_sdk_156.zip" ${STEAMAPI_DIR}/steamworks_sdk_156.zip - "af5a579990dbe5ae4c1b0689260d001b") + EXPECTED_HASH MD5=af5a579990dbe5ae4c1b0689260d001b) file(ARCHIVE_EXTRACT INPUT ${STEAMAPI_DIR}/steamworks_sdk_156.zip DESTINATION ${STEAMAPI_DIR}) diff --git a/package/windows/launchdf.cpp b/package/windows/launchdf.cpp index 804163960..19128ead1 100644 --- a/package/windows/launchdf.cpp +++ b/package/windows/launchdf.cpp @@ -1,8 +1,12 @@ #include #include +#include #include "steam_api.h" +#include + const uint32 DFHACK_STEAM_APPID = 2346660; +const uint32 DF_STEAM_APPID = 975370; static BOOL is_running_on_wine() { typedef const char* (CDECL wine_get_version)(void); @@ -32,7 +36,7 @@ static LPCWSTR launch_via_steam_windows() { si.cb = sizeof(si); ZeroMemory(&pi, sizeof(pi)); - WCHAR steamPath[1024]; + WCHAR steamPath[1024] = L""; DWORD datasize = 1024; LONG retCode = RegGetValueW(HKEY_CURRENT_USER, L"SOFTWARE\\Valve\\Steam", @@ -43,16 +47,24 @@ static LPCWSTR launch_via_steam_windows() { WCHAR commandLine[1024] = L"steam.exe -applaunch 975370"; - if (CreateProcessW(steamPath, commandLine, - NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi) == 0) - return L"Could not launch Dwarf Fortress"; + BOOL res = CreateProcessW(steamPath, commandLine, + NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi); + + if (res) + { + WaitForSingleObject(pi.hProcess, INFINITE); - return NULL; + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); + return NULL; + } + else + { + return L"Could not launch Dwarf Fortress"; + } } -// this method doesn't properly attribute Steam playtime metrics to DF, -// but that's better than not having DF start at all. -static BOOL launch_direct() { +static LPCWSTR launch_direct() { STARTUPINFOW si; PROCESS_INFORMATION pi; @@ -60,31 +72,152 @@ static BOOL launch_direct() { si.cb = sizeof(si); ZeroMemory(&pi, sizeof(pi)); - return CreateProcessW(L"Dwarf Fortress.exe", + BOOL res = CreateProcessW(L"Dwarf Fortress.exe", NULL, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi); + + if (res) + { + WaitForSingleObject(pi.hProcess, INFINITE); + + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); + return NULL; + } + + return L"Could not launch via non-steam fallback method"; +} + +DWORD findDwarfFortressProcess() +{ + PROCESSENTRY32W entry; + entry.dwSize = sizeof(PROCESSENTRY32W); + + const auto snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL); + + if (!Process32FirstW(snapshot, &entry)) + { + CloseHandle(snapshot); + return -1; + } + + do { + std::wstring executableName(entry.szExeFile); + if (executableName == L"Dwarf Fortress.exe") + { + CloseHandle(snapshot); + return entry.th32ProcessID; + } + } while (Process32NextW(snapshot, &entry)); + + CloseHandle(snapshot); + return -1; } -int WINAPI wWinMain(HINSTANCE hi, HINSTANCE hpi, PWSTR cmd, int ns) { +int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nShowCmd) { - if (SteamAPI_RestartAppIfNecessary(DFHACK_STEAM_APPID)) // Replace with your App ID + // initialize steam context + if (SteamAPI_RestartAppIfNecessary(DFHACK_STEAM_APPID)) { - return 1; + exit(0); } - if (!SteamAPI_Init()) + if (!SteamAPI_Init()) + { + // could not initialize steam context, attempt fallback launch + LPCWSTR err = launch_direct(); + if (err != NULL) { - printf("Fatal Error - Steam must be running to play this game (SteamAPI_Init() failed).\n"); - return 1; + MessageBoxW(NULL, err, NULL, 0); + exit(1); } + exit(0); + } - return 0; + bool wine = is_running_on_wine(); - LPCWSTR err = is_running_on_wine() ? launch_via_steam_posix() : launch_via_steam_windows(); + if (wine) + { + // attempt launch via steam client + LPCWSTR err = launch_via_steam_posix(); + + if (err != NULL) + // steam client launch failed, attempt fallback launch + err = launch_direct(); - if (err && !launch_direct()) { - MessageBoxW(NULL, err, NULL, 0); + if (err != NULL) + { + MessageBoxW(NULL, err, NULL, 0); + exit(1); + } + exit(0); + } + + // steam detected and not running in wine + + bool df_installed = SteamApps()->BIsAppInstalled(DF_STEAM_APPID); + + if (!df_installed) + { + // Steam DF is not installed. Assume DF is installed in same directory as DFHack and do a fallback launch + LPCWSTR err = launch_direct(); + + if (err != NULL) + { + MessageBoxW(NULL, err, NULL, 0); + exit(1); + } + exit(0); + } + + // obtain DF app path + + char buf[2048] = ""; + + int b = SteamApps()->GetAppInstallDir(DFHACK_STEAM_APPID, (char*)&buf, 2048); + std::string dfhack_install_folder = (b != -1) ? std::string(buf) : ""; + + int b2 = SteamApps()->GetAppInstallDir(DF_STEAM_APPID, (char*)&buf, 2048); + std::string df_install_folder = (b != -1) ? std::string(buf) : ""; + + + if (df_install_folder != dfhack_install_folder) + { + // DF and DFHack are not installed in the same library + MessageBoxW(NULL, L"DFHack and Dwarf Fortress must be installed in the same Steam library.\nAborting.", NULL, 0); exit(1); } + DWORD df_pid = findDwarfFortressProcess(); + + if (df_pid == -1) + { + LPCWSTR err = launch_via_steam_windows(); + if (err != NULL) + { + MessageBoxW(NULL, err, NULL, 0); + exit(1); + } + int counter = 0; + + do { + if (counter++ > 60) + { + MessageBoxW(NULL, L"Dwarf Fortress took too long to launch, aborting", NULL, 0); + exit(1); + } + Sleep(1000); + df_pid = findDwarfFortressProcess(); + } while (df_pid == -1); + } + + HANDLE hDF = OpenProcess(PROCESS_QUERY_INFORMATION | SYNCHRONIZE, FALSE, df_pid); + + // in the future open an IPC connection so that we can proxy SteamAPI calls for the DFSteam module + + // this will eventuallyh need to become a loop with a WaitForMultipleObjects call + WaitForSingleObject(hDF, INFINITE); + + CloseHandle(hDF); + exit(0); } From dae549e3d1cc3dc775260c384eb3bd589981f662 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Tue, 18 Apr 2023 08:47:05 -0500 Subject: [PATCH 27/32] fix missing end of line --- package/windows/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/windows/CMakeLists.txt b/package/windows/CMakeLists.txt index 42151e663..309613f2e 100644 --- a/package/windows/CMakeLists.txt +++ b/package/windows/CMakeLists.txt @@ -6,4 +6,4 @@ if(WIN32) add_executable(launchdf WIN32 launchdf.cpp) install(TARGETS launchdf DESTINATION ${DFHACK_DATA_DESTINATION}) install(FILES ${STEAMAPI_SHARED_LIBRARY} DESTINATION ${DFHACK_DATA_DESTINATION}) -endif() \ No newline at end of file +endif() From ea01dae88fc3cdc5d1d9673102e2bb2977ff430a Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Tue, 18 Apr 2023 11:12:29 -0500 Subject: [PATCH 28/32] fix minor oops --- package/windows/launchdf.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package/windows/launchdf.cpp b/package/windows/launchdf.cpp index 19128ead1..a84465f53 100644 --- a/package/windows/launchdf.cpp +++ b/package/windows/launchdf.cpp @@ -173,11 +173,11 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, char buf[2048] = ""; - int b = SteamApps()->GetAppInstallDir(DFHACK_STEAM_APPID, (char*)&buf, 2048); - std::string dfhack_install_folder = (b != -1) ? std::string(buf) : ""; + int b1 = SteamApps()->GetAppInstallDir(DFHACK_STEAM_APPID, (char*)&buf, 2048); + std::string dfhack_install_folder = (b1 != -1) ? std::string(buf) : ""; int b2 = SteamApps()->GetAppInstallDir(DF_STEAM_APPID, (char*)&buf, 2048); - std::string df_install_folder = (b != -1) ? std::string(buf) : ""; + std::string df_install_folder = (b2 != -1) ? std::string(buf) : ""; if (df_install_folder != dfhack_install_folder) From 337c5eea2adb1be611afca3af7c796e6cdc1ba47 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Tue, 18 Apr 2023 18:42:42 -0500 Subject: [PATCH 29/32] changes to build process for dflaunch only build dflaunch on steam-specific builds only download steamworks SDK when building dflaunch get steam account from environment when downloading steamworks SDK --- .github/workflows/steam.yml | 4 +++- CMakeLists.txt | 12 ------------ build/win64/generate-MSVC-steam.bat | 4 ++++ package/windows/CMakeLists.txt | 30 ++++++++++++++++++++++++----- 4 files changed, 32 insertions(+), 18 deletions(-) create mode 100644 build/win64/generate-MSVC-steam.bat diff --git a/.github/workflows/steam.yml b/.github/workflows/steam.yml index aae1621af..a89249eab 100644 --- a/.github/workflows/steam.yml +++ b/.github/workflows/steam.yml @@ -38,7 +38,9 @@ jobs: ccache-win64-cross-msvc - name: Cross-compile win64 artifacts env: - CMAKE_EXTRA_ARGS: '-DBUILD_STONESENSE:BOOL=1' + CMAKE_EXTRA_ARGS: '-DBUILD_STONESENSE:BOOL=1 -DBUILD_DFLAUNCH:BOOL=1' + steam_username: ${{ secrets.STEAM_USERNAME }} + steam_password: ${{ secrets.STEAM_PASSWORD }} run: | cd build bash -x build-win64-from-linux.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index cf5586dfd..fca548ccf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -313,18 +313,6 @@ if(WIN32) "5a09604daca6b2b5ce049d79af935d6a") endif() - # download Steam SDK - set (STEAMAPI_DIR ${dfhack_SOURCE_DIR}/depends/steam) - file(DOWNLOAD "https://partner.steamgames.com/downloads/steamworks_sdk_156.zip" - ${STEAMAPI_DIR}/steamworks_sdk_156.zip - EXPECTED_HASH MD5=af5a579990dbe5ae4c1b0689260d001b) - file(ARCHIVE_EXTRACT - INPUT ${STEAMAPI_DIR}/steamworks_sdk_156.zip - DESTINATION ${STEAMAPI_DIR}) - set(STEAMAPI_LIBRARY "${STEAMAPI_DIR}/sdk/redistributable_bin/win64/steam_api64.lib") - set(STEAMAPI_SOURCE_DIR "${STEAMAPI_DIR}/sdk/public/steam") - set(STEAMAPI_SHARED_LIBRARY "${STEAMAPI_DIR}/sdk/redistributable_bin/win64/steam_api64.dll") - endif() if(APPLE) diff --git a/build/win64/generate-MSVC-steam.bat b/build/win64/generate-MSVC-steam.bat new file mode 100644 index 000000000..007bb1c08 --- /dev/null +++ b/build/win64/generate-MSVC-steam.bat @@ -0,0 +1,4 @@ +IF EXIST DF_PATH.txt SET /P _DF_PATH= Date: Tue, 18 Apr 2023 19:14:37 -0500 Subject: [PATCH 30/32] make release channel parameter optional --- .github/workflows/steam.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/steam.yml b/.github/workflows/steam.yml index a89249eab..cf41f861d 100644 --- a/.github/workflows/steam.yml +++ b/.github/workflows/steam.yml @@ -14,7 +14,7 @@ on: release_channel: description: Release channel type: string - required: true + required: false default: beta jobs: From 5c541a8317ab2d82bf1744e7fdff2acf6a5d32b2 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Tue, 18 Apr 2023 19:33:02 -0500 Subject: [PATCH 31/32] pass credentials into container (only when needed of course) --- build/build-win64-from-linux.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build/build-win64-from-linux.sh b/build/build-win64-from-linux.sh index 11f4dbbc5..c0559a999 100755 --- a/build/build-win64-from-linux.sh +++ b/build/build-win64-from-linux.sh @@ -41,6 +41,8 @@ fi if ! docker run --rm -i -v "$srcdir":/src -v "$srcdir/build/win64-cross/":/src/build \ -e BUILDER_UID=$builder_uid \ -e CCACHE_DIR=/src/build/ccache \ + -e steam_username \ + -e steam_password \ --name dfhack-win \ ghcr.io/dfhack/build-env:msvc \ bash -c "cd /src/build && dfhack-configure windows 64 Release -DCMAKE_INSTALL_PREFIX=/src/build/output cmake .. -DBUILD_DOCS=1 $CMAKE_EXTRA_ARGS && dfhack-make -j$jobs install" \ From acc408c168093af1b1c51e1a1abe04d8eb97b177 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Tue, 18 Apr 2023 21:52:57 -0500 Subject: [PATCH 32/32] change sdk download secret --- .github/workflows/steam.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/steam.yml b/.github/workflows/steam.yml index cf41f861d..71e56b662 100644 --- a/.github/workflows/steam.yml +++ b/.github/workflows/steam.yml @@ -39,8 +39,8 @@ jobs: - name: Cross-compile win64 artifacts env: CMAKE_EXTRA_ARGS: '-DBUILD_STONESENSE:BOOL=1 -DBUILD_DFLAUNCH:BOOL=1' - steam_username: ${{ secrets.STEAM_USERNAME }} - steam_password: ${{ secrets.STEAM_PASSWORD }} + steam_username: ${{ secrets.STEAM_SDK_USERNAME }} + steam_password: ${{ secrets.STEAM_SDK_PASSWORD }} run: | cd build bash -x build-win64-from-linux.sh