From 073b90aa42cda3918a71d20d08199bf0d9b2d66e Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Fri, 14 Feb 2025 00:05:35 -0800 Subject: [PATCH 1/5] Update `IssueAggressiveMove` param annotation It can target entities too --- engine/Sim.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/engine/Sim.lua b/engine/Sim.lua index 666da4fd85..7003f0a8c7 100644 --- a/engine/Sim.lua +++ b/engine/Sim.lua @@ -727,11 +727,11 @@ end function IsUnit(object) end ---- Orders a group of units to attack-move to a position +--- Orders a group of units to attack-move to a target ---@param units Unit[] ----@param position Vector +---@param target Unit | Vector | Prop | Blip ---@return SimCommand -function IssueAggressiveMove(units, position) +function IssueAggressiveMove(units, target) end --- Orders a group of units to attack a target From b5c8c2d0b1ce54225d82f10f17f81989568de744 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Fri, 14 Feb 2025 00:12:08 -0800 Subject: [PATCH 2/5] Add string autocomplete for the UnitQueueDataToCommand --- lua/sim/commands/shared.lua | 49 ++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/lua/sim/commands/shared.lua b/lua/sim/commands/shared.lua index 31db2c8ad3..2346b1d0a4 100644 --- a/lua/sim/commands/shared.lua +++ b/lua/sim/commands/shared.lua @@ -20,12 +20,53 @@ --** SOFTWARE. --****************************************************************************************************** +---@alias DistributeOrderInfoCommandName +---| "Stop" # 1 +---| "Move" # 2 +---| "Dive" # 3 +---| "FormMove" # 4 +---| "BuildSiloTactical" # 5 +---| "BuildSiloNuke" # 6 +---| "BuildFactory" # 7 +---| "BuildMobile" # 8 +---| "BuildAssist" # 9 +---| "Attack" # 10 +---| "FormAttack" # 11 +---| "Nuke" # 12 +---| "Tactical" # 13 +---| "Teleport" # 14 +---| "Guard" # 15 +---| "Patrol" # 16 +---| "Ferry" # 17 +---| "FormPatrol" # 18 +---| "Reclaim" # 19 +---| "Repair" # 20 +---| "Capture" # 21 +---| "TransportLoadUnits" # 22 +---| "TransportReverseLoadUnits" # 23 +---| "TransportUnloadUnits" # 24 +---| "TransportUnloadSpecificUnits" # 25 +---| "DetachFromTransport" # 26 +---| "Upgrade" # 27 +---| "Script" # 28 +---| "AssistCommander" # 29 +---| "KillSelf" # 30 +---| "DestroySelf" # 31 +---| "Sacrifice" # 32 +---| "Pause" # 33 +---| "OverCharge" # 34 +---| "AggressiveMove" # 35 +---| "FormAggressiveMove" # 36 +---| "AssistMove" # 37 +---| "SpecialAction" # 38 +---| "Dock" # 39 + ---@class DistributeOrderInfo ---@field Callback? fun(units: Unit[], target: Vector | Entity, arg3?: any, arg4?: any): boolean ----@field Type string # Describes the intended order, useful for debugging ----@field BatchOrders boolean # When set, assigns orders to groups of units ----@field FullRedundancy boolean # When set, attempts to add full redundancy when reasonable by assigning multiple orders to each group ----@field Redundancy number # When set, assigns orders to individual units. Number of orders assigned is equal to the redundancy factor +---@field Type DistributeOrderInfoCommandName # Describes the intended order, useful for debugging +---@field BatchOrders boolean # When set, assigns orders to groups of units +---@field FullRedundancy boolean # When set, attempts to add full redundancy when reasonable by assigning multiple orders to each group +---@field Redundancy number # When set, assigns orders to individual units. Number of orders assigned is equal to the redundancy factor -- upvalue scope for performance local IssueNuke = IssueNuke From b455cfb4d8c18d2df45299c985268f087c7ce307 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Fri, 14 Feb 2025 00:54:17 -0800 Subject: [PATCH 3/5] Close automated attack move loophole thanks to an engine patch the sim can inspect unit command queues, and that means the attack move callback no longer needs to rely on lua scripted position data --- lua/SimCallbacks.lua | 20 ++++++++++++++++++-- lua/ui/game/commandmode.lua | 20 ++------------------ 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lua/SimCallbacks.lua b/lua/SimCallbacks.lua index 824e7a6522..c81a7204bb 100644 --- a/lua/SimCallbacks.lua +++ b/lua/SimCallbacks.lua @@ -17,6 +17,7 @@ local SimPing = import("/lua/simping.lua") local SimTriggers = import("/lua/scenariotriggers.lua") local SUtils = import("/lua/ai/sorianutilities.lua") local ScenarioFramework = import("/lua/scenarioframework.lua") +local UnitQueueDataToCommand = import("/lua/sim/commands/shared.lua").UnitQueueDataToCommand -- upvalue table operations for performance local TableInsert = table.insert @@ -26,6 +27,7 @@ local TableMerged = table.merged -- upvalue scope for performance local type = type +local TableGetn = table.getn local Vector = Vector local IsEntity = IsEntity local GetEntityById = GetEntityById @@ -264,14 +266,28 @@ Callbacks.ValidateAssist = function(data, units) end end +--- Attack move doesn't exist as a command mode, so this callback substitutes that. +---@param data { Clear: boolean } +---@param units Unit[] Callbacks.AttackMove = function(data, units) - -- exclude structures as it makes no sense to apply a move command to them + -- exclude structures as they can't move and there is no sim command to issue attack move rally points for factories local allNonStructures = EntityCategoryFilterDown(categories.ALLUNITS - categories.STRUCTURE, units) + -- Verify that the user manually clicked to issue the command, and use that position. + -- assume all units in the selection were given the same order, so we only need to check one unit + local commandQueue = allNonStructures[1]:GetCommandQueue() + local lastcommand = commandQueue[TableGetn(commandQueue)] + LOG(repr(lastcommand), debug.traceback()) + -- dummy script task should be used, although we can't check the script task's type + if UnitQueueDataToCommand[lastcommand.commandType].Type ~= "Script" then return end + -- script tasks issued without a target have x,y,z = 0 + local x, y, z = lastcommand.x, lastcommand.y, lastcommand.z + if x == 0 and y == 0 and z == 0 then return end + if data.Clear then IssueClearCommands(allNonStructures) end - IssueAggressiveMove(allNonStructures, data.Target) + IssueAggressiveMove(allNonStructures, { x, y, z }) end --tells a unit to toggle its pointer diff --git a/lua/ui/game/commandmode.lua b/lua/ui/game/commandmode.lua index c59db097eb..fb7e865e09 100644 --- a/lua/ui/game/commandmode.lua +++ b/lua/ui/game/commandmode.lua @@ -603,24 +603,8 @@ end local function OnScriptIssued(command) if command.LuaParams then if command.LuaParams.TaskName == 'AttackMove' then - local avgPoint = { 0, 0 } - for _, unit in command.Units do - avgPoint[1] = avgPoint[1] + unit:GetPosition()[1] - avgPoint[2] = avgPoint[2] + unit:GetPosition()[3] - end - avgPoint[1] = avgPoint[1] / TableGetN(command.Units) - avgPoint[2] = avgPoint[2] / TableGetN(command.Units) - - avgPoint[1] = command.Target.Position[1] - avgPoint[1] - avgPoint[2] = command.Target.Position[3] - avgPoint[2] - - local rotation = MathAtan(avgPoint[1] / avgPoint[2]) - rotation = rotation * 180 / MathPi - if avgPoint[2] < 0 then - rotation = rotation + 180 - end - local cb = { Func = "AttackMove", Args = { Target = command.Target.Position, Rotation = rotation, - Clear = command.Clear } } + ---@type SimCallback + local cb = { Func = "AttackMove", Args = { Clear = command.Clear } } SimCallback(cb, true) elseif command.LuaParams.Enhancement then EnhancementQueueFile.enqueueEnhancement(command.Units, command.LuaParams.Enhancement) From 3df319431d7085abac750d2978cb4f52508f1a9a Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Fri, 14 Feb 2025 00:54:38 -0800 Subject: [PATCH 4/5] Document command node drag behavior --- lua/ui/game/commandgraph.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lua/ui/game/commandgraph.lua b/lua/ui/game/commandgraph.lua index c77f30224d..b55d7bff1d 100644 --- a/lua/ui/game/commandgraph.lua +++ b/lua/ui/game/commandgraph.lua @@ -5,6 +5,10 @@ --* Copyright © 2006 Gas Powered Games, Inc. All rights reserved. --***************************************************************************** +-- About dragging command graph nodes: +-- If the target of an order is a unit/blip, its node will snap to units/blips in the same army. +-- If the target of an order is a prop, its node cannot be dragged. + local UIUtil = import("/lua/ui/uiutil.lua") local Group = import("/lua/maui/group.lua").Group local Bitmap = import("/lua/maui/bitmap.lua").Bitmap From 24679733ec4d6b015c828af45b9a4932fea9caf2 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Fri, 14 Feb 2025 01:05:16 -0800 Subject: [PATCH 5/5] Create fix.6653.md --- changelog/snippets/fix.6653.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/snippets/fix.6653.md diff --git a/changelog/snippets/fix.6653.md b/changelog/snippets/fix.6653.md new file mode 100644 index 0000000000..528b893984 --- /dev/null +++ b/changelog/snippets/fix.6653.md @@ -0,0 +1 @@ +- (#6653) Close a loophole that allowed UI lua to issue attack move orders.