From ce2ca373589273fa96e52e90bd76da0fa943ed7a Mon Sep 17 00:00:00 2001 From: Alex Noir Date: Sun, 30 Jun 2024 06:06:55 +0300 Subject: [PATCH 1/6] Fixes shooting in adventure mode --- fix/shooting.lua | 34 +++++++++++++++++++++++++++++ internal/control-panel/registry.lua | 2 ++ 2 files changed, 36 insertions(+) create mode 100644 fix/shooting.lua diff --git a/fix/shooting.lua b/fix/shooting.lua new file mode 100644 index 0000000000..d4eecf5700 --- /dev/null +++ b/fix/shooting.lua @@ -0,0 +1,34 @@ +-- Fixes shooting/throwing options stacking on each other, causing null pointers and crashes +--@ enable = true +--@ module = true + +local aim_projectile = df.global.game.main_interface.adventure.aim_projectile + +local overlay = require('plugins.overlay') + +FixShootingOverlay = defclass(FixShootingOverlay, overlay.OverlayWidget) +FixShootingOverlay.ATTRS{ + desc='Adds keywords to conversation entries.', + default_enabled=true, + viewscreens={ + 'dungeonmode/Inventory', + 'dungeonmode/AimProjectile' + }, + frame={w=0, h=0}, + overlay_onupdate_max_freq_seconds=0, +} + +function FixShootingOverlay:overlay_onupdate() + if aim_projectile.open == false then + aim_projectile.shooter_it = nil + aim_projectile.ammo_it = nil + aim_projectile.thrown_it = nil + aim_projectile.shooting = false + elseif aim_projectile.shooting then + aim_projectile.thrown_it = nil + end +end + +OVERLAY_WIDGETS = { + fixshooting=FixShootingOverlay, +} \ No newline at end of file diff --git a/internal/control-panel/registry.lua b/internal/control-panel/registry.lua index 2d296e838f..b412e54f45 100644 --- a/internal/control-panel/registry.lua +++ b/internal/control-panel/registry.lua @@ -95,6 +95,8 @@ COMMANDS_BY_IDX = { {command='preserve-tombs', group='bugfix', mode='enable', default=true}, {command='reaction-gloves', help_command='tweak', group='bugfix', mode='tweak', default=true, desc='Fixes reactions not producing gloves in sets with correct handedness.'}, + {command='fix/shooting', group='bugfix', mode='tweak', default=true, + desc='Fixes shooting your weapon in adventure mode breaking your Throw action in increasibly dangerous ways.'}, -- gameplay tools {command='agitation-rebalance', group='gameplay', mode='enable'}, From e19c53734c460842e75feee537e11f8a23f9486c Mon Sep 17 00:00:00 2001 From: Alex Noir Date: Sun, 30 Jun 2024 16:35:38 +0300 Subject: [PATCH 2/6] Implement code review suggestions --- fix/shooting.lua | 6 ++---- internal/control-panel/registry.lua | 2 -- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/fix/shooting.lua b/fix/shooting.lua index d4eecf5700..78c78f7f19 100644 --- a/fix/shooting.lua +++ b/fix/shooting.lua @@ -1,5 +1,4 @@ -- Fixes shooting/throwing options stacking on each other, causing null pointers and crashes ---@ enable = true --@ module = true local aim_projectile = df.global.game.main_interface.adventure.aim_projectile @@ -8,17 +7,16 @@ local overlay = require('plugins.overlay') FixShootingOverlay = defclass(FixShootingOverlay, overlay.OverlayWidget) FixShootingOverlay.ATTRS{ - desc='Adds keywords to conversation entries.', + desc='Fixes Shooting your weapon breaking your Throw action.', default_enabled=true, viewscreens={ 'dungeonmode/Inventory', 'dungeonmode/AimProjectile' }, frame={w=0, h=0}, - overlay_onupdate_max_freq_seconds=0, } -function FixShootingOverlay:overlay_onupdate() +function FixShootingOverlay:onInput() if aim_projectile.open == false then aim_projectile.shooter_it = nil aim_projectile.ammo_it = nil diff --git a/internal/control-panel/registry.lua b/internal/control-panel/registry.lua index b412e54f45..2d296e838f 100644 --- a/internal/control-panel/registry.lua +++ b/internal/control-panel/registry.lua @@ -95,8 +95,6 @@ COMMANDS_BY_IDX = { {command='preserve-tombs', group='bugfix', mode='enable', default=true}, {command='reaction-gloves', help_command='tweak', group='bugfix', mode='tweak', default=true, desc='Fixes reactions not producing gloves in sets with correct handedness.'}, - {command='fix/shooting', group='bugfix', mode='tweak', default=true, - desc='Fixes shooting your weapon in adventure mode breaking your Throw action in increasibly dangerous ways.'}, -- gameplay tools {command='agitation-rebalance', group='gameplay', mode='enable'}, From 3bd5f5af3b7b2e00d91aa7e37e5693086133e0d4 Mon Sep 17 00:00:00 2001 From: Alex Noir Date: Sun, 30 Jun 2024 16:37:09 +0300 Subject: [PATCH 3/6] make script part of advtools --- advtools.lua | 2 ++ {fix => internal/advtools}/shooting.lua | 4 ---- 2 files changed, 2 insertions(+), 4 deletions(-) rename {fix => internal/advtools}/shooting.lua (93%) diff --git a/advtools.lua b/advtools.lua index 80fbb2b422..ec0a4de0a4 100644 --- a/advtools.lua +++ b/advtools.lua @@ -1,9 +1,11 @@ --@ module=true local convo = reqscript('internal/advtools/convo') +local shooting = reqscript('internal/advtools/shooting') OVERLAY_WIDGETS = { conversation=convo.AdvRumorsOverlay, + shooting=shooting.FixShootingOverlay, } if dfhack_flags.module then diff --git a/fix/shooting.lua b/internal/advtools/shooting.lua similarity index 93% rename from fix/shooting.lua rename to internal/advtools/shooting.lua index 78c78f7f19..7efc3195c4 100644 --- a/fix/shooting.lua +++ b/internal/advtools/shooting.lua @@ -26,7 +26,3 @@ function FixShootingOverlay:onInput() aim_projectile.thrown_it = nil end end - -OVERLAY_WIDGETS = { - fixshooting=FixShootingOverlay, -} \ No newline at end of file From e07bee3bcf9ac2fd7ff42b9c16618d9ac2af331b Mon Sep 17 00:00:00 2001 From: Alex Noir Date: Wed, 3 Jul 2024 00:52:25 +0300 Subject: [PATCH 4/6] fix_shooting --- advtools.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advtools.lua b/advtools.lua index ec0a4de0a4..ad73824723 100644 --- a/advtools.lua +++ b/advtools.lua @@ -5,7 +5,7 @@ local shooting = reqscript('internal/advtools/shooting') OVERLAY_WIDGETS = { conversation=convo.AdvRumorsOverlay, - shooting=shooting.FixShootingOverlay, + fix_shooting=shooting.FixShootingOverlay, } if dfhack_flags.module then From b3747f2ebcf151cc4a57f9c115cab72d7cf1c509 Mon Sep 17 00:00:00 2001 From: Alex Noir Date: Wed, 3 Jul 2024 00:54:59 +0300 Subject: [PATCH 5/6] add changelog entry --- changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.txt b/changelog.txt index 38f2477022..b935c27522 100644 --- a/changelog.txt +++ b/changelog.txt @@ -28,6 +28,7 @@ Template for new versions: ## New Tools - `advtools`: collection of useful commands and overlays for adventure mode +- `advtools`: added a fix for the shooting bug that corrupts throwing/shooting and can cause crashes between save loads - `pop-control`: (reinstated) limit the maximum size of migrant waves - `bodyswap`: (reinstated) take control of another unit in adventure mode - `gui/sitemap`: list and zoom to people, locations, and artifacts From 7abd6ed12f6caf9dae6ee838feca878f2b30b278 Mon Sep 17 00:00:00 2001 From: Myk Date: Tue, 2 Jul 2024 16:18:59 -0700 Subject: [PATCH 6/6] Update changelog.txt --- changelog.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.txt b/changelog.txt index 7fe6bc2427..747beb3640 100644 --- a/changelog.txt +++ b/changelog.txt @@ -28,7 +28,7 @@ Template for new versions: ## New Tools - `advtools`: collection of useful commands and overlays for adventure mode -- `advtools`: added a fix for the shooting bug that corrupts throwing/shooting and can cause crashes between save loads +- `advtools`: added an overlay that automatically fixes corrupt throwing/shooting state, preventing save/load crashes - `advtools`: advtools party - promotes one of your companions to become a controllable adventurer - `pop-control`: (reinstated) limit the maximum size of migrant waves - `bodyswap`: (reinstated) take control of another unit in adventure mode