fix(logic): Improve validation of building placement for Sneak Attack#2533
fix(logic): Improve validation of building placement for Sneak Attack#2533stephanmeesters wants to merge 6 commits intoTheSuperHackers:mainfrom
Conversation
|
| Filename | Overview |
|---|---|
| GeneralsMD/Code/GameEngine/Source/Common/RTS/ActionManager.cpp | Core anti-cheat fix: SPECIAL_SNEAK_ATTACK moved from shroud-only check to full isLocationLegalToBuild validation mirroring InGameUI:1688; bib cleanup side effect not addressed |
| GeneralsMD/Code/GameEngine/Include/Common/BuildAssistant.h | Const-correctness: builderObject parameter tightened from Object* to const Object* |
| GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp | Const propagation: builderObject and AIUpdateInterface* now const-qualified |
| Generals/Code/GameEngine/Include/Common/BuildAssistant.h | Same const-correctness fix applied to vanilla Generals header |
| Generals/Code/GameEngine/Source/Common/System/BuildAssistant.cpp | Same const-correctness propagation applied to vanilla Generals BuildAssistant |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[canDoSpecialPowerAtLocation] --> B{mod != nullptr?}
B -- No --> Z[return false]
B -- Yes --> C[Switch 1: Terrain check\ne.g. paradrop on water]
C --> D[Switch 2: Shroud check\nfor damaging powers]
D -- other powers --> Y[return shroud/map result]
D -- SNEAK_ATTACK removed --> E[Switch 3: Building placement NEW]
E --> F{RETAIL_COMPATIBLE_CRC?}
F -- Yes --> G[Shroud-only check\nold behavior preserved]
F -- No --> H[getReferenceThingTemplate]
H -- null --> I[return FALSE]
H -- valid --> J[isLocationLegalToBuild\nUSE_QUICK_PATHFIND\nTERRAIN_RESTRICTIONS\nCLEAR_PATH\nNO_OBJECT_OVERLAP\nSHROUD_REVEALED\nIGNORE_STEALTHED\nSame flags as InGameUI:1688]
J --> K{== LBC_OK?}
K -- Yes --> L[return true]
K -- No --> M[return false]
Prompt To Fix All With AI
This is a comment left during a code review.
Path: GeneralsMD/Code/GameEngine/Source/Common/RTS/ActionManager.cpp
Line: 1605-1613
Comment:
**Missing `removeAllBibs()` cleanup after `isLocationLegalToBuild`**
`isLocationLegalToBuild` adds bib visual feedback as a documented side effect — `AIPlayer.cpp:694` notes: `// isLocationLegalToBuild adds bib feedback, turn it off. jba.` Every other call site in `AIPlayer` and `AISkirmishPlayer` follows up with `TheTerrainVisual->removeAllBibs()`. Since `canDoSpecialPowerAtLocation` runs on all clients (per the PR description), stray bibs will briefly appear on every client's screen each time a Sneak Attack placement is validated.
```suggestion
Bool const result = TheBuildAssistant->isLocationLegalToBuild(
loc, referenceThing, angle,
BuildAssistant::USE_QUICK_PATHFIND |
BuildAssistant::TERRAIN_RESTRICTIONS |
BuildAssistant::CLEAR_PATH |
BuildAssistant::NO_OBJECT_OVERLAP |
BuildAssistant::SHROUD_REVEALED |
BuildAssistant::IGNORE_STEALTHED,
obj, nullptr) == LBC_OK;
TheTerrainVisual->removeAllBibs();
return result;
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (4): Last reviewed commit: "Replicate to Generals" | Re-trigger Greptile
| if (!referenceThing) | ||
| return FALSE; | ||
|
|
||
| return TheBuildAssistant->isLocationLegalToBuild(loc, |
There was a problem hiding this comment.
Not entirely sure what the convention is, but I would prefer
- the
locparameter on its own line too - The parameters indented only once (2 spaces / 1 tab)
| if (!referenceThing) | ||
| return FALSE; | ||
|
|
||
| return TheBuildAssistant->isLocationLegalToBuild( |
There was a problem hiding this comment.
Is fine, but also could format like so:
const Real angle = thing->getPlacementViewAngle();
return TheBuildAssistant->isLocationLegalToBuild(
loc, thing, angle,
BuildAssistant::USE_QUICK_PATHFIND |
BuildAssistant::TERRAIN_RESTRICTIONS |
BuildAssistant::CLEAR_PATH |
BuildAssistant::NO_OBJECT_OVERLAP |
BuildAssistant::SHROUD_REVEALED |
BuildAssistant::IGNORE_STEALTHED,
obj, nullptr) == LBC_OK;Is perhaps a tiny bit easier to read and debug and in line with how the rest of the code base writes this function.
b6b2dfa to
8e5fd24
Compare
This PR fixes potential cheating in the placement of a Sneak Attack, where the validity of the building placement was only checked locally. This means a Sneak Attack could be placed in the fog, on top of any other building, steep mountain slope, water etc. A second check is placed that runs on all clients and mirrors the first check at
InGameUI:1688.Todo