diff options
author | Nikolay Korolev <nickvnuk@gmail.com> | 2021-08-08 16:29:57 +0200 |
---|---|---|
committer | Nikolay Korolev <nickvnuk@gmail.com> | 2021-08-08 16:29:57 +0200 |
commit | 68db861c45755f3b5996895003ba638f7f6ace05 (patch) | |
tree | 392706931d0ef3c44fdc12290ba786208553e935 | |
parent | merge (diff) | |
parent | merge (diff) | |
download | re3-68db861c45755f3b5996895003ba638f7f6ace05.tar re3-68db861c45755f3b5996895003ba638f7f6ace05.tar.gz re3-68db861c45755f3b5996895003ba638f7f6ace05.tar.bz2 re3-68db861c45755f3b5996895003ba638f7f6ace05.tar.lz re3-68db861c45755f3b5996895003ba638f7f6ace05.tar.xz re3-68db861c45755f3b5996895003ba638f7f6ace05.tar.zst re3-68db861c45755f3b5996895003ba638f7f6ace05.zip |
-rw-r--r-- | src/control/Script.cpp | 72 | ||||
-rw-r--r-- | src/control/Script.h | 33 | ||||
-rw-r--r-- | src/control/Script5.cpp | 8 | ||||
-rw-r--r-- | src/control/Script6.cpp | 2 | ||||
-rw-r--r-- | src/control/ScriptDebug.cpp | 2 | ||||
-rw-r--r-- | src/core/Frontend.cpp | 10 | ||||
-rw-r--r-- | src/save/GenericGameStorage.cpp | 6 | ||||
-rw-r--r-- | src/save/GenericGameStorage.h | 10 |
8 files changed, 78 insertions, 65 deletions
diff --git a/src/control/Script.cpp b/src/control/Script.cpp index 130cd568..e01743e2 100644 --- a/src/control/Script.cpp +++ b/src/control/Script.cpp @@ -890,25 +890,17 @@ void CTheScripts::Shutdown() } #ifdef USE_DEBUG_SCRIPT_LOADER -int scriptToLoad = 0; -const char *scriptfile = "main.scm"; +int CTheScripts::ScriptToLoad = 0; -int open_script() +int CTheScripts::OpenScript() { - // glfwGetKey doesn't work because of CGame::Initialise is blocking - CPad::UpdatePads(); - if (CPad::GetPad(0)->GetChar('G')) - scriptToLoad = 0; - if (CPad::GetPad(0)->GetChar('R')) - scriptToLoad = 1; - if (CPad::GetPad(0)->GetChar('D')) - scriptToLoad = 2; - switch (scriptToLoad) { - case 0: scriptfile = "main.scm"; break; - case 1: scriptfile = "freeroam_lcs.scm"; break; - case 2: scriptfile = "main_d.scm"; break; - } - return CFileMgr::OpenFile(scriptfile, "rb"); + CFileMgr::ChangeDir("\\"); + switch (ScriptToLoad) { + case 0: return CFileMgr::OpenFile("DATA\\main.scm", "rb"); + case 1: return CFileMgr::OpenFile("DATA\\freeroam_lcs.scm", "rb"); + case 2: return CFileMgr::OpenFile("DATA\\main_d.scm", "rb"); + } + return CFileMgr::OpenFile("DATA\\main.scm", "rb"); } #endif @@ -949,10 +941,10 @@ bool CTheScripts::Init(bool loaddata) NumberOfUsedObjects = 0; if (ScriptSpace) Shutdown(); - CFileMgr::SetDir("DATA"); #ifdef USE_DEBUG_SCRIPT_LOADER - int mainf = open_script(); + int mainf = OpenScript(); #else + CFileMgr::SetDir("DATA"); int mainf = CFileMgr::OpenFile("main.scm", "rb"); #endif CFileMgr::Read(mainf, (char*)&MainScriptSize, sizeof(MainScriptSize)); @@ -1100,24 +1092,24 @@ void CTheScripts::Process() static uint32 TimeToWaitTill; static bool AlreadyResetHealth; switch (AllowMissionReplay) { - case 2: - AllowMissionReplay = 3; + case MISSION_RETRY_STAGE_START_PROCESSING: + AllowMissionReplay = MISSION_RETRY_STAGE_WAIT_FOR_DELAY; TimeToWaitTill = CTimer::GetTimeInMilliseconds() + (AddExtraDeathDelay() > 1000 ? 4000 : 2500); break; - case 3: + case MISSION_RETRY_STAGE_WAIT_FOR_DELAY: if (TimeToWaitTill < CTimer::GetTimeInMilliseconds()) - AllowMissionReplay = 4; + AllowMissionReplay = MISSION_RETRY_STAGE_WAIT_FOR_MENU; break; - case 4: - AllowMissionReplay = 5; - RetryMission(0, 0); + case MISSION_RETRY_STAGE_WAIT_FOR_MENU: + AllowMissionReplay = MISSION_RETRY_STAGE_WAIT_FOR_USER; + RetryMission(MISSION_RETRY_TYPE_SUGGEST_TO_PLAYER); break; - case 6: - AllowMissionReplay = 7; + case MISSION_RETRY_STAGE_START_RESTARTING: + AllowMissionReplay = MISSION_RETRY_STAGE_WAIT_FOR_TIMER_AFTER_RESTART; AlreadyResetHealth = false; TimeToWaitTill = CTimer::GetTimeInMilliseconds() + 500; break; - case 7: + case MISSION_RETRY_STAGE_WAIT_FOR_TIMER_AFTER_RESTART: if (!AlreadyResetHealth) { AlreadyResetHealth = true; CPlayerPed* pPlayerPed = FindPlayerPed(); @@ -1128,7 +1120,7 @@ void CTheScripts::Process() } } if (TimeToWaitTill < CTimer::GetTimeInMilliseconds()) { - AllowMissionReplay = 0; + AllowMissionReplay = MISSION_RETRY_STAGE_NORMAL; return; } break; @@ -1764,11 +1756,11 @@ int8 CRunningScript::ProcessCommands0To99(int32 command) CPlayerInfo* pPlayerInfo = &CWorld::Players[CWorld::PlayerInFocus]; #if 0 // makeing autosave is pointless and is a bit buggy if (pPlayerInfo->m_pPed->GetPedState() != PED_DEAD && pPlayerInfo->m_WBState == WBSTATE_PLAYING && !m_bDeatharrestExecuted) - SaveGameForPause(1); + SaveGameForPause(SAVE_TYPE_QUICKSAVE); #endif oldTargetX = oldTargetY = 0.0f; - if (AllowMissionReplay == 1) - AllowMissionReplay = 2; + if (AllowMissionReplay == MISSION_RETRY_STAGE_WAIT_FOR_SCRIPT_TO_TERMINATE) + AllowMissionReplay = MISSION_RETRY_STAGE_START_PROCESSING; // I am fairly sure they forgot to set return value here } #endif @@ -2757,10 +2749,10 @@ int8 CRunningScript::ProcessCommands100To199(int32 command) wchar* key = CTheScripts::GetTextByKeyFromScript(&m_nIp); #ifdef MISSION_REPLAY if (strcmp((char*)&CTheScripts::ScriptSpace[m_nIp - KEY_LENGTH_IN_SCRIPT], "M_FAIL") == 0) { - if (AllowMissionReplay == 7) - AllowMissionReplay = 0; + if (AllowMissionReplay == MISSION_RETRY_STAGE_WAIT_FOR_TIMER_AFTER_RESTART) + AllowMissionReplay = MISSION_RETRY_STAGE_NORMAL; if (CanAllowMissionReplay()) - AllowMissionReplay = 1; + AllowMissionReplay = MISSION_RETRY_STAGE_WAIT_FOR_SCRIPT_TO_TERMINATE; } #endif CollectParameters(&m_nIp, 2); @@ -3428,7 +3420,7 @@ void CRunningScript::ReturnFromGosubOrFunction() bool CRunningScript::CanAllowMissionReplay() { - if (AllowMissionReplay) + if (AllowMissionReplay != MISSION_RETRY_STAGE_NORMAL) return false; for (int i = 0; i < ARRAY_SIZE(MissionScripts); i++) { if (!CGeneral::faststricmp(m_abScriptName, MissionScripts[i])) @@ -3444,14 +3436,14 @@ uint32 AddExtraDeathDelay() void RetryMission(int type, int unk) { - if (type == 0) { + if (type == MISSION_RETRY_TYPE_SUGGEST_TO_PLAYER) { doingMissionRetry = true; FrontEndMenuManager.m_nCurrScreen = MENUPAGE_MISSION_RETRY; FrontEndMenuManager.RequestFrontEndStartUp(); } - else if (type == 2) { + else if (type == MISSION_RETRY_TYPE_BEGIN_RESTARTING) { doingMissionRetry = false; - AllowMissionReplay = 6; + AllowMissionReplay = MISSION_RETRY_STAGE_START_RESTARTING; CTheScripts::MissionCleanUp.Process(); } } diff --git a/src/control/Script.h b/src/control/Script.h index 589127e5..bc16c99d 100644 --- a/src/control/Script.h +++ b/src/control/Script.h @@ -49,10 +49,6 @@ void FlushLog(); #define KEY_LENGTH_IN_SCRIPT (8) -#ifdef USE_DEBUG_SCRIPT_LOADER -extern const char* scriptfile; -#endif - //#define GTA_SCRIPT_COLLECTIVE #define GET_INTEGER_PARAM(i) (ScriptParams[i]) #define GET_FLOAT_PARAM(i) (*(float*)&ScriptParams[i]) @@ -674,6 +670,11 @@ public: static bool IsFortStauntonDestroyed() { return FSDestroyedFlag && *(int32*)&ScriptSpace[FSDestroyedFlag] == 1; } +#ifdef USE_DEBUG_SCRIPT_LOADER + static int ScriptToLoad; + static int OpenScript(); +#endif + #ifdef USE_ADVANCED_SCRIPT_DEBUG_OUTPUT static void LogAfterScriptInitializing(); static void LogBeforeScriptProcessing(); @@ -685,9 +686,6 @@ extern int ScriptParams[32]; VALIDATE_SIZE(uStackReturnValue, 4); -#ifdef USE_DEBUG_SCRIPT_LOADER -extern int scriptToLoad; -#endif #ifdef MISSION_REPLAY extern int AllowMissionReplay; extern uint32 WaitForMissionActivate; @@ -704,11 +702,24 @@ extern bool AlreadySavedGame; #endif uint32 AddExtraDeathDelay(); -void RetryMission(int, int); -#endif +void RetryMission(int, int unk = 0); -#ifdef USE_DEBUG_SCRIPT_LOADER -extern int scriptToLoad; +enum { + MISSION_RETRY_TYPE_SUGGEST_TO_PLAYER = 0, + MISSION_RETRY_TYPE_1, + MISSION_RETRY_TYPE_BEGIN_RESTARTING +}; + +enum { + MISSION_RETRY_STAGE_NORMAL = 0, + MISSION_RETRY_STAGE_WAIT_FOR_SCRIPT_TO_TERMINATE, + MISSION_RETRY_STAGE_START_PROCESSING, + MISSION_RETRY_STAGE_WAIT_FOR_DELAY, + MISSION_RETRY_STAGE_WAIT_FOR_MENU, + MISSION_RETRY_STAGE_WAIT_FOR_USER, + MISSION_RETRY_STAGE_START_RESTARTING, + MISSION_RETRY_STAGE_WAIT_FOR_TIMER_AFTER_RESTART, +}; #endif extern int gScriptsFile; diff --git a/src/control/Script5.cpp b/src/control/Script5.cpp index abf1c993..174df06a 100644 --- a/src/control/Script5.cpp +++ b/src/control/Script5.cpp @@ -1384,12 +1384,12 @@ void CRunningScript::DoDeatharrestCheck() if (!pPlayer->IsRestartingAfterDeath() && !pPlayer->IsRestartingAfterArrest()) return; #ifdef MISSION_REPLAY - if (AllowMissionReplay != 7 && AllowMissionReplay != 0) + if (AllowMissionReplay != MISSION_RETRY_STAGE_WAIT_FOR_TIMER_AFTER_RESTART && AllowMissionReplay != MISSION_RETRY_STAGE_NORMAL) return; - if (AllowMissionReplay == 7) - AllowMissionReplay = 0; + if (AllowMissionReplay == MISSION_RETRY_STAGE_WAIT_FOR_TIMER_AFTER_RESTART) + AllowMissionReplay = MISSION_RETRY_STAGE_NORMAL; if (CanAllowMissionReplay()) - AllowMissionReplay = 1; + AllowMissionReplay = MISSION_RETRY_STAGE_WAIT_FOR_SCRIPT_TO_TERMINATE; #endif script_assert(m_nStackPointer > 0); while (m_nStackPointer > 1) diff --git a/src/control/Script6.cpp b/src/control/Script6.cpp index bc3b4278..8dcabd30 100644 --- a/src/control/Script6.cpp +++ b/src/control/Script6.cpp @@ -384,7 +384,7 @@ int8 CRunningScript::ProcessCommands1000To1099(int32 command) if (CTheScripts::MissionSupportsMissionReplay(missionRetryScriptIndex)){ if (!AlreadySavedGame) { m_nIp = oldIp - 2; - SaveGameForPause(4); + SaveGameForPause(SAVE_TYPE_QUICKSAVE_FOR_SCRIPT); AlreadySavedGame = true; return 0; } diff --git a/src/control/ScriptDebug.cpp b/src/control/ScriptDebug.cpp index 1c357f5a..cdf9f7cd 100644 --- a/src/control/ScriptDebug.cpp +++ b/src/control/ScriptDebug.cpp @@ -1976,7 +1976,7 @@ CTheScripts::SwitchToMission(int32 mission) missionRetryScriptIndex = mission; #ifdef USE_MISSION_REPLAY_OVERRIDE_FOR_NON_MOBILE_SCRIPT if (CTheScripts::MissionSupportsMissionReplay(missionRetryScriptIndex)) { - SaveGameForPause(4); + SaveGameForPause(SAVE_TYPE_QUICKSAVE_FOR_SCRIPT); } #endif #endif diff --git a/src/core/Frontend.cpp b/src/core/Frontend.cpp index dc2e1e02..3fb4bcbc 100644 --- a/src/core/Frontend.cpp +++ b/src/core/Frontend.cpp @@ -4634,7 +4634,7 @@ CMenuManager::ProcessUserInput(uint8 goDown, uint8 goUp, uint8 optionSelected, u #ifdef USE_DEBUG_SCRIPT_LOADER if (m_nCurrScreen == MENUPAGE_START_MENU || m_nCurrScreen == MENUPAGE_NEW_GAME || m_nCurrScreen == MENUPAGE_NEW_GAME_RELOAD) { if (CPad::GetPad(0)->GetChar('R')) { - scriptToLoad = 1; + CTheScripts::ScriptToLoad = 1; DoSettingsBeforeStartingAGame(); return; } @@ -4789,13 +4789,13 @@ CMenuManager::ProcessUserInput(uint8 goDown, uint8 goUp, uint8 optionSelected, u #ifdef MISSION_REPLAY case MENUACTION_REJECT_RETRY: doingMissionRetry = false; - AllowMissionReplay = 0; + AllowMissionReplay = MISSION_RETRY_STAGE_NORMAL; RequestFrontEndShutDown(); break; case MENUACTION_UNK114: doingMissionRetry = false; RequestFrontEndShutDown(); - RetryMission(2, 0); + RetryMission(MISSION_RETRY_TYPE_BEGIN_RESTARTING); return; #endif case MENUACTION_SAVEGAME: @@ -5451,14 +5451,14 @@ CMenuManager::ProcessFileActions() break; } if (doingMissionRetry) { - RetryMission(2, 0); + RetryMission(MISSION_RETRY_TYPE_BEGIN_RESTARTING); m_nCurrSaveSlot = SLOT_COUNT; doingMissionRetry = false; } #endif if (CheckSlotDataValid(m_nCurrSaveSlot)) { #ifdef USE_DEBUG_SCRIPT_LOADER - scriptToLoad = 0; + CTheScripts::ScriptToLoad = 0; #endif #ifdef XBOX_MESSAGE_SCREEN diff --git a/src/save/GenericGameStorage.cpp b/src/save/GenericGameStorage.cpp index 90a5711e..3db2de59 100644 --- a/src/save/GenericGameStorage.cpp +++ b/src/save/GenericGameStorage.cpp @@ -1176,16 +1176,16 @@ void DisplaySaveResult(int unk, char* name) bool SaveGameForPause(int type) { - if (AllowMissionReplay != 0 && AllowMissionReplay != 7) { + if (AllowMissionReplay != MISSION_RETRY_STAGE_NORMAL && AllowMissionReplay != MISSION_RETRY_STAGE_WAIT_FOR_TIMER_AFTER_RESTART) { debug("SaveGameForPause failed during AllowMissionReplay %d", AllowMissionReplay); return false; } - if (type != 3 && WaitForSave > CTimer::GetTimeInMilliseconds()) { + if (type != SAVE_TYPE_QUICKSAVE_FOR_MISSION_REPLAY && WaitForSave > CTimer::GetTimeInMilliseconds()) { debug("SaveGameForPause failed WaitForSave"); return false; } WaitForSave = 0; - if (gGameState != GS_PLAYING_GAME || (CTheScripts::bAlreadyRunningAMissionScript && type != 5)) { + if (gGameState != GS_PLAYING_GAME || (CTheScripts::bAlreadyRunningAMissionScript && type != SAVE_TYPE_QUICKSAVE_FOR_SCRIPT_ON_A_MISSION)) { DisplaySaveResult(3, CStats::LastMissionPassedName); return false; } diff --git a/src/save/GenericGameStorage.h b/src/save/GenericGameStorage.h index b2bf7a24..bebf426a 100644 --- a/src/save/GenericGameStorage.h +++ b/src/save/GenericGameStorage.h @@ -53,4 +53,14 @@ const char TopLineEmptyFile[] = "THIS FILE IS NOT VALID YET"; extern int8 IsQuickSave; // originally int bool SaveGameForPause(int); + +enum { + SAVE_TYPE_NORMAL, + SAVE_TYPE_QUICKSAVE, + SAVE_TYPE_2, + SAVE_TYPE_QUICKSAVE_FOR_MISSION_REPLAY, + SAVE_TYPE_QUICKSAVE_FOR_SCRIPT, + SAVE_TYPE_QUICKSAVE_FOR_SCRIPT_ON_A_MISSION +}; + #endif |