Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions GeneralsMD/Code/GameEngine/Include/Common/Upgrade.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ class UpgradeCenter : public SubsystemInterface
void reset( void ); ///< subsystem interface
void update( void ) { } ///< subsystem interface

void deleteAllUpgrades();
UpgradeTemplate *firstUpgradeTemplate( void ); ///< return the first upgrade template
const UpgradeTemplate *findUpgradeByKey( NameKeyType key ) const; ///< find upgrade by name key
const UpgradeTemplate *findUpgrade( const AsciiString& name ) const; ///< find and return upgrade by name
Expand Down
50 changes: 33 additions & 17 deletions GeneralsMD/Code/GameEngine/Source/Common/System/Upgrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "Common/Upgrade.h"
#include "Common/Player.h"
#include "Common/Xfer.h"
#include "Common/XferCRC.h"
#include "GameClient/InGameUI.h"
#include "GameClient/Image.h"

Expand Down Expand Up @@ -236,23 +237,7 @@ UpgradeCenter::UpgradeCenter( void )
//-------------------------------------------------------------------------------------------------
UpgradeCenter::~UpgradeCenter( void )
{

// delete all the upgrades loaded from the INI database
UpgradeTemplate *next;
while( m_upgradeList )
{

// get next
next = m_upgradeList->friend_getNext();

// delete head of list
deleteInstance(m_upgradeList);

// set head to next element
m_upgradeList = next;

}

deleteAllUpgrades();
}

//-------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -284,6 +269,17 @@ void UpgradeCenter::init( void )
//-------------------------------------------------------------------------------------------------
void UpgradeCenter::reset( void )
{
// TheSuperHackers @bugfix helmutbuhler 26/10/2025
// When a custom map with a map.ini overrides some upgrades, we need to undo that here
// to avoid mismatches. For now we just reload the original ini files.
deleteAllUpgrades();
init();
XferCRC xferCRC;
xferCRC.open("lightCRC");
INI ini;
ini.loadFileDirectory("Data\\INI\\Default\\Upgrade", INI_LOAD_OVERWRITE, &xferCRC);
ini.loadFileDirectory("Data\\INI\\Upgrade", INI_LOAD_OVERWRITE, &xferCRC);
Copy link

Choose a reason for hiding this comment

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

I suggest take a look at INI_LOAD_CREATE_OVERRIDES to see if this problem can be properly fixed by using INI overrides. I suspect that there are more systems that currently do not handle overrides correctly.

map.ini is loaded with this special flag for this very purpose.

	sprintf(fullFledgeFilename, "%s\\map.ini", filename);
	if (TheFileSystem->doesFileExist(fullFledgeFilename)) {
		DEBUG_LOG(("Loading map.ini"));
		INI ini;
		ini.load( AsciiString(fullFledgeFilename), INI_LOAD_CREATE_OVERRIDES, NULL );
	}

Copy link
Author

Choose a reason for hiding this comment

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

Yes, I noticed that too, but I'm not sure what the purpose of this is. Is it just to save some loading time between games? If so, I'd suggest to remove this whole override idea and simply reload the ini state. That should simplify the code quite a bit and eliminate the possibility for mismatches due to oversights.


if( TheMappedImageCollection && !buttonImagesCached )
{
UpgradeTemplate *upgrade;
Expand All @@ -295,6 +291,26 @@ void UpgradeCenter::reset( void )
}
}

void UpgradeCenter::deleteAllUpgrades()
{
// delete all the upgrades loaded from the INI database
UpgradeTemplate *next;
while( m_upgradeList )
{
// get next
next = m_upgradeList->friend_getNext();

// delete head of list
deleteInstance(m_upgradeList);

// set head to next element
m_upgradeList = next;
}
m_upgradeList = NULL;
m_nextTemplateMaskBit = 0;
buttonImagesCached = FALSE;
}

//-------------------------------------------------------------------------------------------------
/** Find upgrade matching name key */
//-------------------------------------------------------------------------------------------------
Expand Down
Loading