bugfix(specialpower): Fix Special Power ready state during construction#1461
bugfix(specialpower): Fix Special Power ready state during construction#1461xezon wants to merge 3 commits into
Conversation
|
I tested this on local player and AI Player and Special Powers worked correctly. @Mauller please check if this solves all the issues that you have seen. |
20617ca to
060b423
Compare
| DEBUG_ASSERTCRASH(m_availableOnFrame == UINT_MAX, | ||
| ("Unexpected state. Function must be called only after OBJECT_STATUS_UNDER_CONSTRUCTION was completed")); | ||
|
|
||
| m_availableOnFrame = 0; |
There was a problem hiding this comment.
shouldn't this be m_availableOnFrame = TheGameLogic->getFrame(); ?
There was a problem hiding this comment.
It has been a long time and I do not remember if this was intentional. I tend to believe it was intentionally 0. We can try TheGameLogic->getFrame() and see if that works.
There was a problem hiding this comment.
using zero or the current frame at this point should work either way, when init is called it will call initCountdown(); which will set m_availableOnFrame into the future where it needs to be for the countdown to work.
There was a problem hiding this comment.
The main thing to prevent the bugged behaviour is making sure that the m_availableOnFrame is set into the far future while a building is still under construciton or a unit is not ready yet etc.
This then prevents the exploit that can crash the game.
There was a problem hiding this comment.
Would it not be enough to just return false with initiateIntentToDoSpecialPower?
|
Well that is not good. What do you do? |
|
So I build 1 complete nuke and 1 scaffold nuke, group them in the same team. Then use a hotkey (like F).
So what I have been doing is not exactly the exploit, but something is still not right |
060b423 to
6e3da22
Compare
|
I do not understand how you are doing this. I cannot add 2 buildings to the same team. I have made additional changes that hopefully fix it while keeping retail compatibility. |
|
It doesn't crash anymore, but now I can launch a nuke from a scaffold. To be able to group buildings, you need to comment out line 1200 and 1217 in Alternatively, here is a replay with pre-grouped buildings. Press 1, click on the fire nuke icon (even when it is not finished) and fire the nuke from scaffold. |
|
I am unable to shoot the missile when 2 silos are selected. I tested with I need a video or step by step guide. |
6e3da22 to
9351133
Compare
|
I have applied more changes, but have lost track of what is going on with RETAIL_COMPATIBLE_CRC. Things look ok with RETAIL_COMPATIBLE_CRC 0, but I could be wrong. Code is very messy as usual, which makes it cumbersome. |
|
With retail compatibility on and off, I can still do this: 2025-11-08.19-36-48.mp4You cannot manually group buildings as we fixed that bug. However with cheat engines there are still ways around it, or just disable the code that prevents it. To help out, I already created a replay that has the buildings grouped. Steps:
|
60b7d98 to
b80c622
Compare
|
Rebased on main. |
I've reinstalled the game from Steam, removed all the Genpatcher stuff and I can still do what I showed in the video. |
|
Ok I wonder where this behavior difference comes from. |
|
Unclear to me how to advance with this change. Can you perhaps debug this and tell me what code path the Superweapon takes to by-pass the ready timer conditions? |
|
Update: On my laptop I cannot launch the nuke, on my PC I can. Both are supposed to be clean installs. Will compare files to see if there is a difference. |
|
Mysteriuos things happening on your PC. |
|
Yes this is the way to perform this action that causes the crash. |
How shall we continue? So
you can still launch a nuke from a scaffold. This will not mismatch in game I can
|
|
I have not retested this with your exploit. I will do that when coming back to this. |
Skyaero42
left a comment
There was a problem hiding this comment.
Current state is approved, see comment above.
b80c622 to
9d25c7f
Compare
|
| Filename | Overview |
|---|---|
| GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp | Implemented onConstructionCompleted() to clear construction flags and notify all special power modules |
| GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp | Refactored initialization to postpone until construction completes; added guards against using powers during construction |
| GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/BattlePlanUpdate.cpp | Added retail-compatible crash prevention guard; contains outdated date in comment (2025 vs 2026) |
| GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/MissileLauncherBuildingUpdate.cpp | Moved special power module initialization to constructor; potential module initialization order issue; outdated date in comment |
Last reviewed commit: 9d25c7f
| m_specialPowerModule = getObject()->getSpecialPowerModule(d->m_specialPowerTemplate); | ||
| DEBUG_ASSERTCRASH(m_specialPowerModule, ("Missing special power")); |
There was a problem hiding this comment.
Initializing m_specialPowerModule in the constructor can fail if module initialization order varies. Modules are created in INI file order (Object.cpp:403-410), so SpecialPowerModule may not exist yet when this constructor runs. The original lazy initialization in update() was safer.
Check that SpecialPowerModule is always defined before MissileLauncherBuildingUpdate in all INI files, or revert to lazy initialization.
Prompt To Fix With AI
This is a comment left during a code review.
Path: GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/MissileLauncherBuildingUpdate.cpp
Line: 56-57
Comment:
Initializing `m_specialPowerModule` in the constructor can fail if module initialization order varies. Modules are created in INI file order (Object.cpp:403-410), so `SpecialPowerModule` may not exist yet when this constructor runs. The original lazy initialization in `update()` was safer.
Check that `SpecialPowerModule` is always defined before `MissileLauncherBuildingUpdate` in all INI files, or revert to lazy initialization.
How can I resolve this? If you propose a fix, please make it concise.
Additional Comments (1)
Context Used: Rule from Why: ... (source) Prompt To Fix With AIThis is a comment left during a code review.
Path: GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/MissileLauncherBuildingUpdate.cpp
Line: 209
Comment:
Date in comment references 2025, should be 2026
```suggestion
// TheSuperHackers @bugfix Mauller 29/06/2026 prevent a game crash when told to launch before ready to do so
```
**Context Used:** Rule from `dashboard` - What: Flag newly created code comments that reference dates prior to the current year (2026).
Why: ... ([source](https://app.greptile.com/review/custom-context?memory=fd72a556-4fd8-4db4-8b08-8e51516a64ad))
How can I resolve this? If you propose a fix, please make it concise. |
| //------------------------------------------------------------------------------------------------- | ||
| MissileLauncherBuildingUpdate::MissileLauncherBuildingUpdate( Thing *thing, const ModuleData* moduleData ) : SpecialPowerUpdateModule( thing, moduleData ) | ||
| { | ||
| const MissileLauncherBuildingUpdateModuleData* d = getMissileLauncherBuildingUpdateModuleData(); |
There was a problem hiding this comment.
d is not a good name for a variable. I would suggest data



This change is an alternative to #1444 and attempts to fix the Special Power ready state during construction. To do that, it postpones the Special Power initialization until the construction is signaled done.
TODO