Skip to content

Commit e06f598

Browse files
authored
bugfix(gametext): Prevent crashing in WorldBuilder, MapCacheBuilder by moving updateWindowTitle() out of GameText class (#1396)
1 parent e89b48e commit e06f598

File tree

4 files changed

+144
-152
lines changed

4 files changed

+144
-152
lines changed

Generals/Code/GameEngine/Source/Common/GameEngine.cpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
#include "GameLogic/ScriptEngine.h"
8484
#include "GameLogic/SidesList.h"
8585

86+
#include "GameClient/ClientInstance.h"
8687
#include "GameClient/Display.h"
8788
#include "GameClient/FXList.h"
8889
#include "GameClient/GameClient.h"
@@ -171,6 +172,76 @@ extern CComModule _Module;
171172
//-------------------------------------------------------------------------------------------------
172173
static void updateTGAtoDDS();
173174

175+
//-------------------------------------------------------------------------------------------------
176+
static void updateWindowTitle()
177+
{
178+
// TheSuperHackers @tweak Now prints product and version information in the Window title.
179+
180+
DEBUG_ASSERTCRASH(TheVersion != NULL, ("TheVersion is NULL"));
181+
DEBUG_ASSERTCRASH(TheGameText != NULL, ("TheGameText is NULL"));
182+
183+
UnicodeString title;
184+
185+
if (rts::ClientInstance::getInstanceId() > 1u)
186+
{
187+
UnicodeString str;
188+
str.format(L"Instance:%.2u", rts::ClientInstance::getInstanceId());
189+
title.concat(str);
190+
}
191+
192+
UnicodeString productString = TheVersion->getUnicodeProductString();
193+
194+
if (!productString.isEmpty())
195+
{
196+
if (!title.isEmpty())
197+
title.concat(L" ");
198+
title.concat(productString);
199+
}
200+
201+
#if RTS_GENERALS
202+
const WideChar* defaultGameTitle = L"Command and Conquer Generals";
203+
#elif RTS_ZEROHOUR
204+
const WideChar* defaultGameTitle = L"Command and Conquer Generals Zero Hour";
205+
#endif
206+
UnicodeString gameTitle = TheGameText->FETCH_OR_SUBSTITUTE("GUI:Command&ConquerGenerals", defaultGameTitle);
207+
208+
if (!gameTitle.isEmpty())
209+
{
210+
UnicodeString gameTitleFinal;
211+
UnicodeString gameVersion = TheVersion->getUnicodeVersion();
212+
213+
if (productString.isEmpty())
214+
{
215+
gameTitleFinal = gameTitle;
216+
}
217+
else
218+
{
219+
UnicodeString gameTitleFormat = TheGameText->FETCH_OR_SUBSTITUTE("Version:GameTitle", L"for %ls");
220+
gameTitleFinal.format(gameTitleFormat.str(), gameTitle.str());
221+
}
222+
223+
if (!title.isEmpty())
224+
title.concat(L" ");
225+
title.concat(gameTitleFinal.str());
226+
title.concat(L" ");
227+
title.concat(gameVersion.str());
228+
}
229+
230+
if (!title.isEmpty())
231+
{
232+
AsciiString titleA;
233+
titleA.translate(title); //get ASCII version for Win 9x
234+
235+
extern HWND ApplicationHWnd; ///< our application window handle
236+
if (ApplicationHWnd) {
237+
//Set it twice because Win 9x does not support SetWindowTextW.
238+
::SetWindowText(ApplicationHWnd, titleA.str());
239+
::SetWindowTextW(ApplicationHWnd, title.str());
240+
}
241+
}
242+
}
243+
244+
//-------------------------------------------------------------------------------------------------
174245
Int GameEngine::getFramesPerSecondLimit( void )
175246
{
176247
return m_maxFPS;
@@ -337,6 +408,7 @@ void GameEngine::init()
337408
initSubsystem(TheDeepCRCSanityCheck, "TheDeepCRCSanityCheck", MSGNEW("GameEngineSubystem") DeepCRCSanityCheck, NULL, NULL, NULL, NULL);
338409
#endif // DEBUG_CRC
339410
initSubsystem(TheGameText, "TheGameText", CreateGameTextInterface(), NULL);
411+
updateWindowTitle();
340412
initSubsystem(TheScienceStore,"TheScienceStore", MSGNEW("GameEngineSubsystem") ScienceStore(), &xferCRC, "Data\\INI\\Default\\Science.ini", "Data\\INI\\Science.ini");
341413
initSubsystem(TheMultiplayerSettings,"TheMultiplayerSettings", MSGNEW("GameEngineSubsystem") MultiplayerSettings(), &xferCRC, "Data\\INI\\Default\\Multiplayer.ini", "Data\\INI\\Multiplayer.ini");
342414
initSubsystem(TheTerrainTypes,"TheTerrainTypes", MSGNEW("GameEngineSubsystem") TerrainTypeCollection(), &xferCRC, "Data\\INI\\Default\\Terrain.ini", "Data\\INI\\Terrain.ini");

Generals/Code/GameEngine/Source/GameClient/GameText.cpp

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
#include "GameClient/GameText.h"
4949
#include "Common/Language.h"
5050
#include "Common/Registry.h"
51-
#include "GameClient/ClientInstance.h"
5251
#include "GameClient/LanguageFilter.h"
5352
#include "Common/Debug.h"
5453
#include "Common/UnicodeString.h"
@@ -198,8 +197,6 @@ class GameTextManager : public GameTextInterface
198197
Bool parseMapStringFile( const char *filename );
199198
Bool readLine( char *buffer, Int max, File *file );
200199
Char readChar( File *file );
201-
202-
void updateWindowTitle();
203200
};
204201

205202
static int _cdecl compareLUT ( const void *, const void*);
@@ -373,8 +370,6 @@ void GameTextManager::init( void )
373370

374371
qsort( m_stringLUT, m_textCount, sizeof(StringLookUp), compareLUT );
375372

376-
updateWindowTitle();
377-
378373
}
379374

380375
//============================================================================
@@ -1468,77 +1463,6 @@ Char GameTextManager::readChar( File *file )
14681463
return 0;
14691464
}
14701465

1471-
//============================================================================
1472-
// GameTextManager::updateWindowTitle
1473-
//============================================================================
1474-
1475-
void GameTextManager::updateWindowTitle()
1476-
{
1477-
// TheSuperHackers @tweak Now prints product and version information in the Window title.
1478-
1479-
DEBUG_ASSERTCRASH(TheVersion != NULL, ("TheVersion is NULL"));
1480-
1481-
UnicodeString title;
1482-
1483-
if (rts::ClientInstance::getInstanceId() > 1u)
1484-
{
1485-
UnicodeString str;
1486-
str.format(L"Instance:%.2u", rts::ClientInstance::getInstanceId());
1487-
title.concat(str);
1488-
}
1489-
1490-
UnicodeString productString = TheVersion->getUnicodeProductString();
1491-
1492-
if (!productString.isEmpty())
1493-
{
1494-
if (!title.isEmpty())
1495-
title.concat(L" ");
1496-
title.concat(productString);
1497-
}
1498-
1499-
#if RTS_GENERALS
1500-
const WideChar* defaultGameTitle = L"Command and Conquer Generals";
1501-
#elif RTS_ZEROHOUR
1502-
const WideChar* defaultGameTitle = L"Command and Conquer Generals Zero Hour";
1503-
#endif
1504-
UnicodeString gameTitle = FETCH_OR_SUBSTITUTE("GUI:Command&ConquerGenerals", defaultGameTitle);
1505-
1506-
if (!gameTitle.isEmpty())
1507-
{
1508-
UnicodeString gameTitleFinal;
1509-
UnicodeString gameVersion = TheVersion->getUnicodeVersion();
1510-
1511-
if (productString.isEmpty())
1512-
{
1513-
gameTitleFinal = gameTitle;
1514-
}
1515-
else
1516-
{
1517-
UnicodeString gameTitleFormat = FETCH_OR_SUBSTITUTE("Version:GameTitle", L"for %ls");
1518-
gameTitleFinal.format(gameTitleFormat.str(), gameTitle.str());
1519-
}
1520-
1521-
if (!title.isEmpty())
1522-
title.concat(L" ");
1523-
title.concat(gameTitleFinal.str());
1524-
title.concat(L" ");
1525-
title.concat(gameVersion.str());
1526-
}
1527-
1528-
if (!title.isEmpty())
1529-
{
1530-
AsciiString titleA;
1531-
titleA.translate(title); //get ASCII version for Win 9x
1532-
1533-
extern HWND ApplicationHWnd; ///< our application window handle
1534-
if (ApplicationHWnd) {
1535-
//Set it twice because Win 9x does not support SetWindowTextW.
1536-
::SetWindowText(ApplicationHWnd, titleA.str());
1537-
::SetWindowTextW(ApplicationHWnd, title.str());
1538-
}
1539-
}
1540-
}
1541-
15421466
//============================================================================
15431467
// compareLUT
15441468
//============================================================================

GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
#include "GameLogic/ScriptEngine.h"
8686
#include "GameLogic/SidesList.h"
8787

88+
#include "GameClient/ClientInstance.h"
8889
#include "GameClient/Display.h"
8990
#include "GameClient/FXList.h"
9091
#include "GameClient/GameClient.h"
@@ -169,6 +170,76 @@ extern CComModule _Module;
169170
//-------------------------------------------------------------------------------------------------
170171
static void updateTGAtoDDS();
171172

173+
//-------------------------------------------------------------------------------------------------
174+
static void updateWindowTitle()
175+
{
176+
// TheSuperHackers @tweak Now prints product and version information in the Window title.
177+
178+
DEBUG_ASSERTCRASH(TheVersion != NULL, ("TheVersion is NULL"));
179+
DEBUG_ASSERTCRASH(TheGameText != NULL, ("TheGameText is NULL"));
180+
181+
UnicodeString title;
182+
183+
if (rts::ClientInstance::getInstanceId() > 1u)
184+
{
185+
UnicodeString str;
186+
str.format(L"Instance:%.2u", rts::ClientInstance::getInstanceId());
187+
title.concat(str);
188+
}
189+
190+
UnicodeString productString = TheVersion->getUnicodeProductString();
191+
192+
if (!productString.isEmpty())
193+
{
194+
if (!title.isEmpty())
195+
title.concat(L" ");
196+
title.concat(productString);
197+
}
198+
199+
#if RTS_GENERALS
200+
const WideChar* defaultGameTitle = L"Command and Conquer Generals";
201+
#elif RTS_ZEROHOUR
202+
const WideChar* defaultGameTitle = L"Command and Conquer Generals Zero Hour";
203+
#endif
204+
UnicodeString gameTitle = TheGameText->FETCH_OR_SUBSTITUTE("GUI:Command&ConquerGenerals", defaultGameTitle);
205+
206+
if (!gameTitle.isEmpty())
207+
{
208+
UnicodeString gameTitleFinal;
209+
UnicodeString gameVersion = TheVersion->getUnicodeVersion();
210+
211+
if (productString.isEmpty())
212+
{
213+
gameTitleFinal = gameTitle;
214+
}
215+
else
216+
{
217+
UnicodeString gameTitleFormat = TheGameText->FETCH_OR_SUBSTITUTE("Version:GameTitle", L"for %ls");
218+
gameTitleFinal.format(gameTitleFormat.str(), gameTitle.str());
219+
}
220+
221+
if (!title.isEmpty())
222+
title.concat(L" ");
223+
title.concat(gameTitleFinal.str());
224+
title.concat(L" ");
225+
title.concat(gameVersion.str());
226+
}
227+
228+
if (!title.isEmpty())
229+
{
230+
AsciiString titleA;
231+
titleA.translate(title); //get ASCII version for Win 9x
232+
233+
extern HWND ApplicationHWnd; ///< our application window handle
234+
if (ApplicationHWnd) {
235+
//Set it twice because Win 9x does not support SetWindowTextW.
236+
::SetWindowText(ApplicationHWnd, titleA.str());
237+
::SetWindowTextW(ApplicationHWnd, title.str());
238+
}
239+
}
240+
}
241+
242+
//-------------------------------------------------------------------------------------------------
172243
Int GameEngine::getFramesPerSecondLimit( void )
173244
{
174245
return m_maxFPS;
@@ -414,6 +485,7 @@ void GameEngine::init()
414485
initSubsystem(TheDeepCRCSanityCheck, "TheDeepCRCSanityCheck", MSGNEW("GameEngineSubystem") DeepCRCSanityCheck, NULL, NULL, NULL, NULL);
415486
#endif // DEBUG_CRC
416487
initSubsystem(TheGameText, "TheGameText", CreateGameTextInterface(), NULL);
488+
updateWindowTitle();
417489

418490
#ifdef DUMP_PERF_STATS///////////////////////////////////////////////////////////////////////////
419491
GetPrecisionTimer(&endTime64);//////////////////////////////////////////////////////////////////

GeneralsMD/Code/GameEngine/Source/GameClient/GameText.cpp

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
#include "GameClient/GameText.h"
4949
#include "Common/Language.h"
5050
#include "Common/Registry.h"
51-
#include "GameClient/ClientInstance.h"
5251
#include "GameClient/LanguageFilter.h"
5352
#include "Common/Debug.h"
5453
#include "Common/UnicodeString.h"
@@ -198,8 +197,6 @@ class GameTextManager : public GameTextInterface
198197
Bool parseMapStringFile( const char *filename );
199198
Bool readLine( char *buffer, Int max, File *file );
200199
Char readChar( File *file );
201-
202-
void updateWindowTitle();
203200
};
204201

205202
static int _cdecl compareLUT ( const void *, const void*);
@@ -373,8 +370,6 @@ void GameTextManager::init( void )
373370

374371
qsort( m_stringLUT, m_textCount, sizeof(StringLookUp), compareLUT );
375372

376-
updateWindowTitle();
377-
378373
}
379374

380375
//============================================================================
@@ -1468,77 +1463,6 @@ Char GameTextManager::readChar( File *file )
14681463
return 0;
14691464
}
14701465

1471-
//============================================================================
1472-
// GameTextManager::updateWindowTitle
1473-
//============================================================================
1474-
1475-
void GameTextManager::updateWindowTitle()
1476-
{
1477-
// TheSuperHackers @tweak Now prints product and version information in the Window title.
1478-
1479-
DEBUG_ASSERTCRASH(TheVersion != NULL, ("TheVersion is NULL"));
1480-
1481-
UnicodeString title;
1482-
1483-
if (rts::ClientInstance::getInstanceId() > 1u)
1484-
{
1485-
UnicodeString str;
1486-
str.format(L"Instance:%.2u", rts::ClientInstance::getInstanceId());
1487-
title.concat(str);
1488-
}
1489-
1490-
UnicodeString productString = TheVersion->getUnicodeProductString();
1491-
1492-
if (!productString.isEmpty())
1493-
{
1494-
if (!title.isEmpty())
1495-
title.concat(L" ");
1496-
title.concat(productString);
1497-
}
1498-
1499-
#if RTS_GENERALS
1500-
const WideChar* defaultGameTitle = L"Command and Conquer Generals";
1501-
#elif RTS_ZEROHOUR
1502-
const WideChar* defaultGameTitle = L"Command and Conquer Generals Zero Hour";
1503-
#endif
1504-
UnicodeString gameTitle = FETCH_OR_SUBSTITUTE("GUI:Command&ConquerGenerals", defaultGameTitle);
1505-
1506-
if (!gameTitle.isEmpty())
1507-
{
1508-
UnicodeString gameTitleFinal;
1509-
UnicodeString gameVersion = TheVersion->getUnicodeVersion();
1510-
1511-
if (productString.isEmpty())
1512-
{
1513-
gameTitleFinal = gameTitle;
1514-
}
1515-
else
1516-
{
1517-
UnicodeString gameTitleFormat = FETCH_OR_SUBSTITUTE("Version:GameTitle", L"for %ls");
1518-
gameTitleFinal.format(gameTitleFormat.str(), gameTitle.str());
1519-
}
1520-
1521-
if (!title.isEmpty())
1522-
title.concat(L" ");
1523-
title.concat(gameTitleFinal.str());
1524-
title.concat(L" ");
1525-
title.concat(gameVersion.str());
1526-
}
1527-
1528-
if (!title.isEmpty())
1529-
{
1530-
AsciiString titleA;
1531-
titleA.translate(title); //get ASCII version for Win 9x
1532-
1533-
extern HWND ApplicationHWnd; ///< our application window handle
1534-
if (ApplicationHWnd) {
1535-
//Set it twice because Win 9x does not support SetWindowTextW.
1536-
::SetWindowText(ApplicationHWnd, titleA.str());
1537-
::SetWindowTextW(ApplicationHWnd, title.str());
1538-
}
1539-
}
1540-
}
1541-
15421466
//============================================================================
15431467
// compareLUT
15441468
//============================================================================

0 commit comments

Comments
 (0)