Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply new binary patch to Salem #6499

Merged
merged 5 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions changelog/snippets/other.6499.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
- (#6499) Apply new binary patch to Salem

Salem destroyer has special ability to move from water onto land. However in vanilla game this feature sometimes may cause problems with positioning of the unit and it's pathfinding. FAF introduced solution with a binary patch which makes it toggable ability to walk on land.
Copy link
Member

@Garanas Garanas Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not copy-paste the pull request description into the changelog snippet. They do not share the same audience. For a pull request description your audience is other programmers and/or contributors who (soon) have a decent idea of how things work. For the changelog the audience is your average joe, they won't understand all the technical details and they don't have to.

I think you can simplify this to:

- (#6499) Fix hard crash when exiting the game when a Salem is on land

The Cybran Tech 2 Destroyer (Salem) has the special ability to move from water onto land. There was a bug in a special, alternative implementation introduced by FAForever. Together with an assembly patch this bug is now fixed.

Interested in how assembly patches work? Reach out to the game team. You can find us easiest via the official Discord server.

The above would be of category 'fix'. The below would be of category 'feature':

- (#6499) Enable dynamic footprint changes for (modded) units

With thanks to an assembly patch the footprint changes that were previously unique to the Cybran Tech 2 Destroyer can now be applied to any unit. For more details, see the pull request on GitHub. 

Interested in how assembly patches work? Reach out to the game team. You can find us easiest via the official Discord server.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not correct to call it dynamic footprint change. Because internally game still uses both of them based on motion type (if both are provided). Here we are just forcing to use only one in particular for water.

But this solution had flows:
1. works only for salem: you can't make it work for other unit (mod one for example);
2. solution is unsafe: you can't restart game or replay because if any salem walks it just causes a crash;
3. solution uses weird way to do that toggle: it confuses doing this way;
4. this breaks filtering based on blueprint id.

With new assembly patch these flows are no more. This PR is about applying new assmbly fix.

## Description of the proposed changes
Applies patch changes and removes old ones.

## Testing done on the proposed changes
1. This patch can be applied to any other unit to achive same behavior (no example provided)
2. Start skirmish match. Spawn salem and make it walk. Restart match (not closing game). Spawn salem again and make it walk. Game works with no problems.
3. Function description isn't great since it relies on internal work of the game, but still it isn't done with `GetStat`.
4. Spawn 2 salems, make one of them go to land. Select one of them, press *ctrl-z* (select similar units) or with cltr-left-click, second one is selected too.


## Additional context
This change requires an asm [patch](https://github.com/FAForever/FA-Binary-Patches/pull/94).
14 changes: 0 additions & 14 deletions engine/Patches.lua

This file was deleted.

6 changes: 5 additions & 1 deletion engine/Sim/Unit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ end
function Unit:EnableManipulators(bone, Enable)
end

---Forces game to use AltFootprint for the unit
---@param state boolean
function Unit:ForceAltFootPrint(state)
end

--- Returns the unit's multiplier to a damage type
---@param damageTypeName DamageType
---@return number
Expand Down Expand Up @@ -269,7 +274,6 @@ end
---@param statName string
---@param defaultVal? number
---@return number
-- Special case for the Salem: GetStat("h1_SetSalemAmph", 0 or 1) will Disable/Enable amphibious mode
function Unit:GetStat(statName, defaultVal)
end

Expand Down
4 changes: 2 additions & 2 deletions units/URS0201/URS0201_script.lua
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ URS0201 = ClassUnit(CSeaUnit) {
CSeaUnit.OnScriptBitSet(self, bit)
if bit == 1 then
if self.Layer ~= 'Land' then
self:GetStat("h1_SetSalemAmph", 0)
self:ForceAltFootPrint(true)
else
self:SetScriptBit('RULEUTC_WeaponToggle', false)
end
Expand All @@ -183,7 +183,7 @@ URS0201 = ClassUnit(CSeaUnit) {
OnScriptBitClear = function(self, bit)
CSeaUnit.OnScriptBitClear(self, bit)
if bit == 1 then
self:GetStat("h1_SetSalemAmph", 1)
self:ForceAltFootPrint(false)
end
end,
}
Expand Down
7 changes: 7 additions & 0 deletions units/URS0201/URS0201_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,13 @@ UnitBlueprint{
BuildCostMass = 2250,
BuildTime = 10000,
},
AltFootprint = -- water only
{
SizeX = 2,
SizeZ = 8,
OccupancyCaps = 8,
MinWaterDepth = 1.5,
},
Footprint = {
SizeX = 2,
SizeZ = 8,
Expand Down
Loading