Permalink
Browse files

Protect cheat mode also after loading game.

Used to be possible to enter cheat mode without the
special key command if you had loaded a savegame.

Closes ticket:4612, patch by Forgon.
  • Loading branch information...
perim committed Aug 27, 2017
1 parent 3a871f2 commit 4b91398c86a8d3e1e9c05787768508ad5929dcbc
Showing with 31 additions and 46 deletions.
  1. +4 −1 src/clparse.cpp
  2. +23 −28 src/game.cpp
  3. +3 −6 src/init.cpp
  4. +1 −1 src/keyedit.cpp
  5. +0 −9 src/keymap.cpp
  6. +0 −1 src/keymap.h
View
@@ -492,11 +492,14 @@ bool ParseCommandLine(int argc, const char **argv)
NetPlay.bComms = false;
bMultiPlayer = false;
bMultiMessages = false;
NetPlay.players[0].allocated = true;
for (int i = 0; i < MAX_PLAYERS; i++)
{
NET_InitPlayer(i, true, false);
}
//NET_InitPlayer deallocates Player 0, who must be allocated so that a later invocation of processDebugMappings does not trigger DEBUG mode
NetPlay.players[0].allocated = true;
if (!strcmp(token, "CAM_1A") || !strcmp(token, "CAM_2A") || !strcmp(token, "CAM_3A"))
{
game.type = CAMPAIGN;
View
@@ -1765,6 +1765,26 @@ static void setIniDroidOrder(WzConfig &ini, QString const &key, DroidOrder const
setIniStructureStats(ini, key + "/stats", order.psStats);
}
static void allocatePlayers()
{
for (int i = 0; i < MAX_PLAYERS; i++)
{
NetPlay.players[i].ai = saveGameData.sNetPlay.players[i].ai;
NetPlay.players[i].difficulty = saveGameData.sNetPlay.players[i].difficulty;
sstrcpy(NetPlay.players[i].name, saveGameData.sNetPlay.players[i].name);
if (saveGameData.sGame.skDiff[i] == UBYTE_MAX || (game.type == CAMPAIGN && i == 0))
{
NetPlay.players[i].allocated = true;
//processDebugMappings ensures game does not start in DEBUG mode
processDebugMappings(i, false);
}
else
{
NetPlay.players[i].allocated = false;
}
}
}
// -----------------------------------------------------------------------------------------
// UserSaveGame ... this is true when you are loading a players save game
bool loadGame(const char *pGameToLoad, bool keepObjects, bool freeMem, bool UserSaveGame)
@@ -1985,20 +2005,8 @@ bool loadGame(const char *pGameToLoad, bool keepObjects, bool freeMem, bool User
bMultiMessages = bMultiPlayer;
NetPlay.bComms = (saveGameData.sNetPlay).bComms;
for (i = 0; i < MAX_PLAYERS; i++)
{
NetPlay.players[i].ai = saveGameData.sNetPlay.players[i].ai;
NetPlay.players[i].difficulty = saveGameData.sNetPlay.players[i].difficulty;
sstrcpy(NetPlay.players[i].name, saveGameData.sNetPlay.players[i].name);
if (saveGameData.sGame.skDiff[i] == UBYTE_MAX || (game.type == CAMPAIGN && i == 0))
{
NetPlay.players[i].allocated = true;
}
else
{
NetPlay.players[i].allocated = false;
}
}
allocatePlayers();
if (bMultiPlayer)
{
@@ -3738,20 +3746,7 @@ bool gameLoadV(PHYSFS_file *fileHandle, unsigned int version)
powerSaved[i].extractedPower = saveGameData.power[i].extractedPower;
}
for (player = 0; player < MAX_PLAYERS; player++)
{
NetPlay.players[player].ai = saveGameData.sNetPlay.players[player].ai;
NetPlay.players[player].difficulty = saveGameData.sNetPlay.players[player].difficulty;
sstrcpy(NetPlay.players[player].name, saveGameData.sNetPlay.players[player].name);
if ((saveGameData.sGame.skDiff[player] == UBYTE_MAX || game.type == CAMPAIGN) && player == 0)
{
NetPlay.players[player].allocated = true;
}
else
{
NetPlay.players[player].allocated = false;
}
}
allocatePlayers();
IsScenario = false;
//copy the level name across
View
@@ -741,7 +741,7 @@ void systemShutdown()
shutdownEffectsSystem();
wzSceneEnd(nullptr); // Might want to end the "Main menu loop" or "Main game loop".
keyClearMappings();
keyMappings.clear();
// free up all the load functions (all the data should already have been freed)
resReleaseAll();
@@ -834,9 +834,7 @@ bool frontendInitialise(const char *ResourceFile)
return false;
}
// keymappings
// clear out any existing mappings
keyClearMappings();
// reinitialise key mappings
keyInitMappings(false);
// Set the default uncoloured cursor here, since it looks slightly
@@ -1098,8 +1096,7 @@ bool stageTwoInitialise()
return false;
}
// keymappings
keyClearMappings();
// reinitialise key mappings
keyInitMappings(false);
// Set the default uncoloured cursor here, since it looks slightly
View
@@ -191,7 +191,7 @@ bool runKeyMapEditor()
}
if (id == KM_DEFAULT)
{
keyClearMappings();
// reinitialise key mappings
keyInitMappings(true);
widgDelete(psWScreen, FRONTEND_BACKDROP); // readd the widgets
startKeyMapEditor(false);
View
@@ -268,7 +268,6 @@ void keyInitMappings(bool bForceDefaults)
processDebugMappings(n, false);
}
for (unsigned i = 0; i < NUM_QWERTY_KEYS; i++)
{
qwertyKeyMappings[i].psMapping = nullptr;
@@ -520,14 +519,6 @@ KEY_MAPPING *keyFindMapping(KEY_CODE metaCode, KEY_CODE subCode)
return mapping != keyMappings.end()? &*mapping : nullptr;
}
// ----------------------------------------------------------------------------------
/* clears the mappings list and frees the memory */
void keyClearMappings()
{
keyMappings.clear();
}
// ----------------------------------------------------------------------------------
/* Removes a mapping specified by a pointer */
static bool keyRemoveMappingPt(KEY_MAPPING *psToRemove)
View
@@ -55,7 +55,6 @@ struct KEY_MAPPING
KEY_MAPPING *keyAddMapping(KEY_STATUS status, KEY_CODE metaCode, KEY_CODE subcode, KEY_ACTION action, void (*pKeyMapFunc)(), const char *name);
KEY_MAPPING *keyGetMappingFromFunction(void (*function)());
KEY_MAPPING *keyFindMapping(KEY_CODE metaCode, KEY_CODE subCode);
void keyClearMappings();
void keyProcessMappings(bool bExclude);
void keyInitMappings(bool bForceDefaults);
KEY_CODE getLastSubKey();

0 comments on commit 4b91398

Please sign in to comment.