Skip to content

Fix unit commands#1

Open
leviathan400 wants to merge 8 commits into
masterfrom
fix-unit-commands
Open

Fix unit commands#1
leviathan400 wants to merge 8 commits into
masterfrom
fix-unit-commands

Conversation

@leviathan400

Copy link
Copy Markdown

This fixes a class of Unit::Do* orders that called a raw GetMapObject()->Cmd*() thunk directly instead of going through ProcessCommandPacket. The direct calls crash the engine (or no-op the order) a tick later; routing them through the command-packet path, the same one every other working Do* order uses - fixes it and stays multiplayer-deterministic. All verified in-game on and confirmed with a before/after in a TethysAPI smoke-test mission.

  • Fix Unit::DoMove() to issue a CommandType::Move command packet instead of the raw CmdMove().
  • Fix Unit::DoDock() to issue a CommandType::Dock command packet instead of the raw CmdDock().
  • Fix Unit::DoMiningRoute() command packet header (numUnits = 1, unit id in unitID[0]).
  • Fix Unit::DoDumpCargo() to issue a CommandType::DumpCargo command packet instead of the raw CmdDumpCargo().
  • Fix Unit::DoTransferCargo() to issue a CommandType::TransferCargo command packet instead of the raw CmdTransferCargo().

The direct GetMapObject()->CmdMove() thunk leaves the unit's move/waypoint state uninitialized; the next ProcessUnits pass calls through a garbage pointer (EXCEPTION_ACCESS_VIOLATION, eip in the heap). Route the order through ProcessCommandPacket (CommandType::Move), the same path DoStandGround/DoAttack already use.
Same class of bug as DoMove: the direct GetMapObject()->CmdDock() thunk never docks the unit and leaves command state corrupted. Route the order through ProcessCommandPacket (CommandType::Dock, which uses MoveCommand with the structure's dock tile as the waypoint).
numUnits (a uint8 count) was set to the unit id and the id was written to unitID[1], leaving unitID[0] = 0, so the engine matched the route to no unit and Cargo Trucks never moved. Set numUnits = 1; unitID[0] = id_, matching every other Do* command builder.
The direct GetMapObject()->CmdDumpCargo() thunk corrupts command state and the engine faults a tick later (EXCEPTION_ACCESS_VIOLATION). Route through DoSimpleCommand(CommandType::DumpCargo), the same path the sibling DoLoadCargo/DoUnloadCargo already use - DumpCargo is already handled in DoSimpleCommand's switch.
The direct GetMapObject()->CmdTransferCargo() thunk corrupts command state and the engine faults a tick later. Route through ProcessCommandPacket (CommandType::TransferCargo, which uses TransferCargoCommand: unitID, bay, unknown=0).
Add 0.8.3 change log entry for the five Do* command-packet fixes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant