From 1611c2bed7912e5f6c3bdf2355fac8dc7d72b2cd Mon Sep 17 00:00:00 2001 From: Zirk Date: Mon, 12 Oct 2026 19:55:37 -0700 Subject: [PATCH 1/2] [GearSwap] equip_sets_exit pretarget cleanup part 1 outgoing text does a good job identifying if an item action is a trade or regular item use, but this check should be reperformed in the event the user pretarget function changes the target, since the target being an NPC or not affects if the requested action is a trade or not. Pretarget will use this this trade determination to decide which item packet to assemble in the same manner as outgoing text to maintain consistency. filter_precast was upset that it only exists to do a single job, but an imposter was doing its job for it, so it ejected the imposter. The outgoing_action_category_table check is unnecessary as the only way this check can fail is if we do not have a valid unified prefix, but outgoing text already validated the prefix. Checking for the existence of command_registry[ts].proposed_packet was common to both item and action packet code paths, so it was pulled out to a common location to reduce code duplication. After filter_precast ejected the imposter, there was a situation where one filter_precast check was nested inside another filter_precast check, so the inner check was removed since it is guaranteed to evaluate to true. Dead code inside the action packet code path was deleted. This code is dead because its impossible for assemble_action_packet to return nil or false, and this is verifiable empirically because if the dead code were to ever execute, it is guaranteed to produce an error since it will concatenate nil with a string, and we'd have seen reports of this error by now. --- addons/GearSwap/flow.lua | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/addons/GearSwap/flow.lua b/addons/GearSwap/flow.lua index 1dc929389..74c70d8a4 100644 --- a/addons/GearSwap/flow.lua +++ b/addons/GearSwap/flow.lua @@ -216,6 +216,14 @@ function equip_sets_exit(swap_type, ts, val1) if command_registry[ts].new_target then val1.target = command_registry[ts].new_target -- Switch target, if it is requested. + + if val1.prefix == '/item' then + if val1.target.type ~= 'NONE' and bit.band(val1.target.spawn_type, 2) == 2 then + val1.action_type = 'Trade' + else + val1.action_type = 'Item' + end + end end if st_targs[val1.target.raw] then @@ -224,10 +232,10 @@ function equip_sets_exit(swap_type, ts, val1) end -- Compose a proposed packet for the given action (this should be possible after pretarget) - if val1.target.id and val1.target.index then + if filter_precast(val1) then if val1.prefix == '/item' then -- Item use packet handling here - if bit.band(val1.target.spawn_type, 2) == 2 and find_inventory_item(val1.id) then + if val1.action_type == 'Trade' and find_inventory_item(val1.id) then -- 0x36 packet if val1.target.distance <= 6 then command_registry[ts].proposed_packet = assemble_menu_item_packet(val1.target.id, val1.target.index, val1.id) @@ -238,25 +246,15 @@ function equip_sets_exit(swap_type, ts, val1) -- 0x37 packet command_registry[ts].proposed_packet = assemble_use_item_packet(val1.target.id, val1.target.index, val1.id) end - if not command_registry[ts].proposed_packet then - command_registry:delete_entry(ts) - end - elseif outgoing_action_category_table[unify_prefix[val1.prefix]] then - if filter_precast(val1) then - command_registry[ts].proposed_packet = assemble_action_packet(val1.target.id, val1.target.index, outgoing_action_category_table[unify_prefix[val1.prefix]], val1.id, command_registry[ts].target_arrow) - if not command_registry[ts].proposed_packet then - command_registry:delete_entry(ts) - - msg.debugging('Unable to create a packet for this command because the target is still invalid after pretarget (' .. storedcommand .. ' ' .. val1.target.raw .. ')') - storedcommand = nil - return storedcommand .. ' ' .. val1.target.raw - end - end else - msg.debugging('Hark, what weird prefix through yonder window breaks? ' .. tostring(val1.prefix)) + command_registry[ts].proposed_packet = assemble_action_packet(val1.target.id, val1.target.index, outgoing_action_category_table[unify_prefix[val1.prefix]], val1.id, command_registry[ts].target_arrow) end end + if not command_registry[ts].proposed_packet then + command_registry:delete_entry(ts) + end + if ts and command_registry[ts] then if not val1.target.name then -- Spells with invalid pass_through_targs, like using without a target From 7423cfc9b16924eb6d209d62d8e13dbb7cc13dde Mon Sep 17 00:00:00 2001 From: Zirk Date: Tue, 13 Oct 2026 14:50:51 -0700 Subject: [PATCH 2/2] [GearSwap] Woops had the proposed_packet check in slightly wrong spot --- addons/GearSwap/flow.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/GearSwap/flow.lua b/addons/GearSwap/flow.lua index 74c70d8a4..0ac688d83 100644 --- a/addons/GearSwap/flow.lua +++ b/addons/GearSwap/flow.lua @@ -249,10 +249,10 @@ function equip_sets_exit(swap_type, ts, val1) else command_registry[ts].proposed_packet = assemble_action_packet(val1.target.id, val1.target.index, outgoing_action_category_table[unify_prefix[val1.prefix]], val1.id, command_registry[ts].target_arrow) end - end - if not command_registry[ts].proposed_packet then - command_registry:delete_entry(ts) + if not command_registry[ts].proposed_packet then + command_registry:delete_entry(ts) + end end if ts and command_registry[ts] then