Skip to content

Commit

Permalink
Warn when long strings may crash scenario setup screen
Browse files Browse the repository at this point in the history
  • Loading branch information
f1rpo committed Jan 13, 2022
1 parent e54c140 commit acf333f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
17 changes: 17 additions & 0 deletions CvGameCoreDLL/CvInitCore.cpp
Expand Up @@ -587,6 +587,7 @@ void CvInitCore::resetPlayer(PlayerTypes eID,
m_aszCivPassword[eID].clear();
m_aszEmail[eID].clear();
m_aszSmtpHost[eID].clear();
m_uiTotalNameLength = 0; // advc.003k

m_abWhiteFlag.resetVal(eID);
m_aszFlagDecal[eID].clear();
Expand Down Expand Up @@ -1006,6 +1007,7 @@ void CvInitCore::setForceControl(ForceControlTypes eIndex, bool bOption)

void CvInitCore::setActivePlayer(PlayerTypes eActivePlayer)
{
m_uiTotalNameLength = 0; // advc.003k (tidier to reset this asap)
// <advc>
if (m_eActivePlayer == eActivePlayer)
return; // </advc>
Expand Down Expand Up @@ -1121,6 +1123,7 @@ void CvInitCore::setLeaderName(PlayerTypes eID, CvWString const& szLeaderName)
CvWString szName = szLeaderName;
gDLL->stripSpecialCharacters(szName);
m_aszLeaderName[eID] = szName;
countNameLength(szName); // advc.003k
}
else FAssertBounds(0, MAX_PLAYERS, eID);
gDLL->UI().setDirty(Score_DIRTY_BIT, true); // advc.001m
Expand Down Expand Up @@ -1157,6 +1160,7 @@ void CvInitCore::setCivDescription(PlayerTypes eID, CvWString const& szCivDescri
CvWString szName = szCivDescription;
gDLL->stripSpecialCharacters(szName);
m_aszCivDescription[eID] = szName;
countNameLength(szName); // advc.003k
}

CvWString const& CvInitCore::getCivDescriptionKey(PlayerTypes eID) const
Expand Down Expand Up @@ -1291,6 +1295,19 @@ void CvInitCore::setSmtpHost(PlayerTypes eID, CvString const& szHost)
m_aszSmtpHost[eID] = szHost;
}

// advc.003k:
void CvInitCore::countNameLength(CvWString const& kName)
{
#ifdef FASSERT_ENABLE
if (getActivePlayer() == NO_PLAYER && getScenario())
{
m_uiTotalNameLength += kName.length();
FAssertMsg(m_uiTotalNameLength < 1240, "Total length of LeaderName"
" and CivDesc strings might crash civ selection screen.");
}
#endif
}

void CvInitCore::setWhiteFlag(PlayerTypes eID, bool bWhiteFlag)
{
m_abWhiteFlag.set(eID, bWhiteFlag);
Expand Down
4 changes: 3 additions & 1 deletion CvGameCoreDLL/CvInitCore.h
Expand Up @@ -357,6 +357,7 @@ class CvInitCore /* advc.003e */ : boost::noncopyable
CvWString* m_aszCivPassword;
CvString* m_aszEmail;
CvString* m_aszSmtpHost;
size_t m_uiTotalNameLength; // advc.003k

CvWString* m_aszFlagDecal;
ArrayEnumMap<PlayerTypes,bool> m_abWhiteFlag;
Expand Down Expand Up @@ -394,6 +395,7 @@ class CvInitCore /* advc.003e */ : boost::noncopyable
void clearCustomMapOptions();
void refreshCustomMapOptions();
void updatePangaea(); // advc
void countNameLength(CvWString const& kName);

/*void clearVictories();
void refreshVictories();*/ // advc: Easier to understand w/o these
Expand All @@ -402,7 +404,7 @@ class CvInitCore /* advc.003e */ : boost::noncopyable
/* advc.003k: OK to increase the size of CvInitCore (and to update or remove this
assertion). Just make sure that new data members are added in the right place. */
BOOST_STATIC_ASSERT(sizeof(CvInitCore) ==
(sizeof(ArrayEnumMap<PlayerTypes,bool>) > 4 ? 444 : 420));
(sizeof(ArrayEnumMap<PlayerTypes,bool>) > 4 ? 448 : 424));
// advc: Custom Game screen probably relies on this
BOOST_STATIC_ASSERT(GAMEOPTION_LEAD_ANY_CIV == 7 && GAMEOPTION_ADVANCED_START == 0);

Expand Down

0 comments on commit acf333f

Please sign in to comment.