Skip to content

bugfix(specialpower): Fix Special Power ready state during construction#1461

Open
xezon wants to merge 3 commits into
TheSuperHackers:mainfrom
xezon:xezon/fix-special-power-update-under-construction
Open

bugfix(specialpower): Fix Special Power ready state during construction#1461
xezon wants to merge 3 commits into
TheSuperHackers:mainfrom
xezon:xezon/fix-special-power-update-under-construction

Conversation

@xezon

@xezon xezon commented Aug 15, 2025

Copy link
Copy Markdown

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

  • Have Mauller test this
  • Replicate in Generals

@xezon xezon requested a review from Mauller August 15, 2025 20:01
@xezon xezon added Major Severity: Minor < Major < Critical < Blocker ThisProject The issue was introduced by this project, or this task is specific to this project NoRetail This fix or change is not applicable with Retail game compatibility labels Aug 15, 2025
@xezon

xezon commented Aug 15, 2025

Copy link
Copy Markdown
Author

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.

@xezon xezon force-pushed the xezon/fix-special-power-update-under-construction branch from 20617ca to 060b423 Compare August 15, 2025 20:04
@xezon xezon added the Bug Something is not working right, typically is user facing label Aug 20, 2025
DEBUG_ASSERTCRASH(m_availableOnFrame == UINT_MAX,
("Unexpected state. Function must be called only after OBJECT_STATUS_UNDER_CONSTRUCTION was completed"));

m_availableOnFrame = 0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

shouldn't this be m_availableOnFrame = TheGameLogic->getFrame(); ?

@xezon xezon Oct 11, 2025

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Would it not be enough to just return false with initiateIntentToDoSpecialPower?

@Skyaero42

Copy link
Copy Markdown

It crashes the game for me (RETAIL_COMPATIBLE_CRC = 0

image

@xezon

xezon commented Oct 11, 2025

Copy link
Copy Markdown
Author

Well that is not good. What do you do?

@Skyaero42

Copy link
Copy Markdown

So I build 1 complete nuke and 1 scaffold nuke, group them in the same team. Then use a hotkey (like F).

  • In retail it then shows the red nuke outline. When pressing left button, nothing happens
  • In non-retail, it also shows the red nuke outline. When pressing the left button, the game crashes.

So what I have been doing is not exactly the exploit, but something is still not right

@xezon xezon force-pushed the xezon/fix-special-power-update-under-construction branch from 060b423 to 6e3da22 Compare October 12, 2025 11:36
@xezon

xezon commented Oct 12, 2025

Copy link
Copy Markdown
Author

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.

@Skyaero42

Skyaero42 commented Oct 12, 2025

Copy link
Copy Markdown

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 SelectionXlat.cpp, as grouping of buildings is not allowed since #1347. - And yes, that does make it a lot harder to crash/exploit the game with the bug(s) that this PR is trying to resolve.

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.

00000077.zip

@xezon

xezon commented Nov 8, 2025

Copy link
Copy Markdown
Author

I am unable to shoot the missile when 2 silos are selected.

I tested with
RETAIL_COMPATIBLE_BUG 0
RETAIL_COMPATIBLE_CRC 0
RETAIL_COMPATIBLE_XFER_SAVE 0

I need a video or step by step guide.

@xezon xezon force-pushed the xezon/fix-special-power-update-under-construction branch from 6e3da22 to 9351133 Compare November 8, 2025 11:56
@xezon xezon requested a review from Skyaero42 November 8, 2025 13:30
@xezon

xezon commented Nov 8, 2025

Copy link
Copy Markdown
Author

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.

@Skyaero42

Skyaero42 commented Nov 8, 2025

Copy link
Copy Markdown

With retail compatibility on and off, I can still do this:

2025-11-08.19-36-48.mp4

You 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:

  1. Download this replay: https://github.com/user-attachments/files/22874036/00000077.zip
  2. Press 1 to select the scaffold and build nuke together
  3. click the fire nuke icon (it is not ready, you can click it anyways)
    (in the video at around 0:15 there is an assert firing, hence the freeze)
    4 click anywhere.

@xezon

xezon commented Nov 9, 2025

Copy link
Copy Markdown
Author

I cannot reproduce this bug. When pressing 1, the Control Bar does not show this button.

I also tested with Control Bar Pro 1.2. Can you reproduce it with unmodified game data?

shot_20251109_104339_1

@xezon xezon force-pushed the xezon/fix-special-power-update-under-construction branch from 60b7d98 to b80c622 Compare November 9, 2025 09:46
@xezon

xezon commented Nov 9, 2025

Copy link
Copy Markdown
Author

Rebased on main.

@Skyaero42

Copy link
Copy Markdown

I cannot reproduce this bug. When pressing 1, the Control Bar does not show this button.

I also tested with Control Bar Pro 1.2. Can you reproduce it with unmodified game data?

I've reinstalled the game from Steam, removed all the Genpatcher stuff and I can still do what I showed in the video.
May investigate later on my end figuring out whats going on.

@xezon

xezon commented Nov 9, 2025

Copy link
Copy Markdown
Author

Ok I wonder where this behavior difference comes from.

@xezon

xezon commented Nov 25, 2025

Copy link
Copy Markdown
Author

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?

@Skyaero42

Copy link
Copy Markdown

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.

@xezon

xezon commented Nov 30, 2025

Copy link
Copy Markdown
Author

Mysteriuos things happening on your PC.

@Skyaero42

Skyaero42 commented Dec 6, 2025

Copy link
Copy Markdown

Found the issue. I had a custom commandbutton.ini in Data/ini, which added OK_FOR_MULTI_SELECT to special powers. I don't know why I had it (possible because of testing a long time ago).

image

This means somebody can still launch the scaffold nuke if the modify their commandbutton.ini. How would you like to approach this?

CommandButton.zip

@Mauller

Mauller commented Dec 6, 2025

Copy link
Copy Markdown

Yes this is the way to perform this action that causes the crash.

@Skyaero42

Copy link
Copy Markdown

This means somebody can still launch the scaffold nuke if the modify their commandbutton.ini. How would you like to approach this?

How shall we continue?

So

  • if you make a code change that allows you to group multiple buildings
  • and if you make the above change in commandbutton.ini

you can still launch a nuke from a scaffold. This will not mismatch in game

I can

  • Approve this PR and create a bug report for the above 'cheat'
  • Or we fix the cheat in this PR. Somewhere there must be a scaffold / nuke timer check missing allowing the launch.

@xezon

xezon commented Jan 11, 2026

Copy link
Copy Markdown
Author

I have not retested this with your exploit. I will do that when coming back to this.

Skyaero42
Skyaero42 previously approved these changes Jan 11, 2026

@Skyaero42 Skyaero42 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Current state is approved, see comment above.

@xezon xezon force-pushed the xezon/fix-special-power-update-under-construction branch from b80c622 to 9d25c7f Compare February 24, 2026 21:56
@greptile-apps

greptile-apps Bot commented Feb 24, 2026

Copy link
Copy Markdown

Greptile Summary

This PR refactors special power initialization to fix ready state issues during construction by postponing initialization until construction completes.

Key Changes:

  • Added Object::onConstructionCompleted() to centralize construction completion signaling
  • Introduced SpecialPowerModule::init() and initCountdown() helper methods to defer initialization
  • Modified special power module to initialize at ~0u frame during construction (non-retail mode)
  • Replaced direct construction status clearing with onConstructionCompleted() calls throughout codebase
  • Added crash prevention guards in retail-compatible mode for special power update modules

Issues Found:

  • Module initialization order dependency in MissileLauncherBuildingUpdate.cpp:56-57 - constructor now assumes SpecialPowerModule exists, but modules are created in INI file order
  • Multiple comments reference 2025 instead of 2026 (violates date policy)

Confidence Score: 3/5

  • This PR has a potential module initialization ordering bug that could cause crashes
  • Score reflects a critical logic issue in MissileLauncherBuildingUpdate.cpp where the constructor assumes m_specialPowerModule exists, but module creation order depends on INI file definitions. The original lazy initialization was safer. Additionally, multiple style violations with outdated dates.
  • Pay close attention to MissileLauncherBuildingUpdate.cpp - verify module ordering in INI files or revert to lazy initialization

Important Files Changed

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

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

12 files reviewed, 6 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +56 to +57
m_specialPowerModule = getObject()->getSpecialPowerModule(d->m_specialPowerTemplate);
DEBUG_ASSERTCRASH(m_specialPowerModule, ("Missing special power"));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

@greptile-apps

greptile-apps Bot commented Feb 24, 2026

Copy link
Copy Markdown
Additional Comments (1)

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/MissileLauncherBuildingUpdate.cpp
Date in comment references 2025, should be 2026

	// 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)

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: 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();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

d is not a good name for a variable. I would suggest data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something is not working right, typically is user facing Major Severity: Minor < Major < Critical < Blocker NoRetail This fix or change is not applicable with Retail game compatibility ThisProject The issue was introduced by this project, or this task is specific to this project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants