From 8bc2a4e04bc58c0a01c77f1cf2b1d54379bc2e64 Mon Sep 17 00:00:00 2001 From: Ahmet Fatih Cengiz <37782582+afc-afc0@users.noreply.github.com> Date: Sun, 12 Apr 2026 01:49:05 -0400 Subject: [PATCH] bugfix(gui): Fix preferred starting cash not showing in combo box * Fixes #2583 Re-populate the starting cash combo box after applying user preferences from INI files in Skirmish, LAN and WOL game setup menus. Previously, the combo box was populated before preferences were applied, so non-standard starting cash values would not appear in the dropdown. Also fix undefined behavior in PopulateStartingCashComboBox where a past-the-end iterator was dereferenced when the starting cash value was not found in the standard list. --- .../GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp | 2 ++ .../GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp | 2 ++ .../GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp | 2 ++ GeneralsMD/Code/GameEngine/Source/GameNetwork/GUIUtil.cpp | 3 ++- 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp index 4072ce98ad5..b97598e9cb0 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp @@ -858,6 +858,8 @@ void LanGameOptionsMenuInit( WindowLayout *layout, void *userData ) slot->setNATBehavior(FirewallHelperClass::FIREWALL_TYPE_SIMPLE); game->setMap( pref.getPreferredMap() ); game->setStartingCash( pref.getStartingCash() ); + // TheSuperHackers @bugfix Re-populate starting cash combo box after applying user preferences. + PopulateStartingCashComboBox(comboBoxStartingCash, game); game->setSuperweaponRestriction( pref.getSuperweaponRestricted() ? 1 : 0 ); AsciiString lowerMap = pref.getPreferredMap(); lowerMap.toLower(); diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp index 580098b6af9..f9008d90ec5 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp @@ -1317,6 +1317,8 @@ void SkirmishGameOptionsMenuInit( WindowLayout *layout, void *userData ) } TheSkirmishGameInfo->setStartingCash( prefs.getStartingCash() ); + // TheSuperHackers @bugfix Re-populate starting cash combo box after applying user preferences. + PopulateStartingCashComboBox(comboBoxStartingCash, TheSkirmishGameInfo); TheSkirmishGameInfo->setSuperweaponRestriction( prefs.getSuperweaponRestricted() ? 1 : 0 ); TheSkirmishGameInfo->setMap(prefs.getPreferredMap()); diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp index f360ba9423b..5bfec543970 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp @@ -1377,6 +1377,8 @@ void WOLGameSetupMenuInit( WindowLayout *layout, void *userData ) // This should probably be enforced at the gamespy level as well, to prevent exploits. Int isUsingStats = TheGameSpyGame->getUseStats(); game->setStartingCash( isUsingStats? TheMultiplayerSettings->getDefaultStartingMoney() : customPref.getStartingCash() ); + // TheSuperHackers @bugfix Re-populate starting cash combo box after applying user preferences. + PopulateStartingCashComboBox(comboBoxStartingCash, game); game->setSuperweaponRestriction( isUsingStats? 0 : customPref.getSuperweaponRestricted() ? 1 : 0 ); if (isUsingStats) game->setOldFactionsOnly( 0 ); diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GUIUtil.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GUIUtil.cpp index 0df5ca5a057..e9a58d4ba76 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GUIUtil.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GUIUtil.cpp @@ -352,7 +352,8 @@ void PopulateStartingCashComboBox(GameWindow *comboBox, GameInfo *myGame) DEBUG_CRASH( ("Current selection for starting cash not found in list") ); currentSelectionIndex = GadgetComboBoxAddEntry(comboBox, formatMoneyForStartingCashComboBox( myGame->getStartingCash() ), comboBox->winGetEnabled() ? comboBox->winGetEnabledTextColor() : comboBox->winGetDisabledTextColor()); - GadgetComboBoxSetItemData(comboBox, currentSelectionIndex, (void *)it->countMoney() ); + // TheSuperHackers @bugfix Fix undefined behavior from dereferencing past-the-end iterator. + GadgetComboBoxSetItemData(comboBox, currentSelectionIndex, (void *)myGame->getStartingCash().countMoney() ); } GadgetComboBoxSetSelectedPos(comboBox, currentSelectionIndex);