1
0
Fork 0
mirror of https://github.com/halpz/re3.git synced 2024-10-18 22:11:05 +00:00
This commit is contained in:
Nikolay Korolev 2021-08-08 17:29:57 +03:00
commit 68db861c45
8 changed files with 77 additions and 64 deletions

View file

@ -890,25 +890,17 @@ void CTheScripts::Shutdown()
} }
#ifdef USE_DEBUG_SCRIPT_LOADER #ifdef USE_DEBUG_SCRIPT_LOADER
int scriptToLoad = 0; int CTheScripts::ScriptToLoad = 0;
const char *scriptfile = "main.scm";
int open_script() int CTheScripts::OpenScript()
{ {
// glfwGetKey doesn't work because of CGame::Initialise is blocking CFileMgr::ChangeDir("\\");
CPad::UpdatePads(); switch (ScriptToLoad) {
if (CPad::GetPad(0)->GetChar('G')) case 0: return CFileMgr::OpenFile("DATA\\main.scm", "rb");
scriptToLoad = 0; case 1: return CFileMgr::OpenFile("DATA\\freeroam_lcs.scm", "rb");
if (CPad::GetPad(0)->GetChar('R')) case 2: return CFileMgr::OpenFile("DATA\\main_d.scm", "rb");
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"); return CFileMgr::OpenFile("DATA\\main.scm", "rb");
} }
#endif #endif
@ -949,10 +941,10 @@ bool CTheScripts::Init(bool loaddata)
NumberOfUsedObjects = 0; NumberOfUsedObjects = 0;
if (ScriptSpace) if (ScriptSpace)
Shutdown(); Shutdown();
CFileMgr::SetDir("DATA");
#ifdef USE_DEBUG_SCRIPT_LOADER #ifdef USE_DEBUG_SCRIPT_LOADER
int mainf = open_script(); int mainf = OpenScript();
#else #else
CFileMgr::SetDir("DATA");
int mainf = CFileMgr::OpenFile("main.scm", "rb"); int mainf = CFileMgr::OpenFile("main.scm", "rb");
#endif #endif
CFileMgr::Read(mainf, (char*)&MainScriptSize, sizeof(MainScriptSize)); CFileMgr::Read(mainf, (char*)&MainScriptSize, sizeof(MainScriptSize));
@ -1100,24 +1092,24 @@ void CTheScripts::Process()
static uint32 TimeToWaitTill; static uint32 TimeToWaitTill;
static bool AlreadyResetHealth; static bool AlreadyResetHealth;
switch (AllowMissionReplay) { switch (AllowMissionReplay) {
case 2: case MISSION_RETRY_STAGE_START_PROCESSING:
AllowMissionReplay = 3; AllowMissionReplay = MISSION_RETRY_STAGE_WAIT_FOR_DELAY;
TimeToWaitTill = CTimer::GetTimeInMilliseconds() + (AddExtraDeathDelay() > 1000 ? 4000 : 2500); TimeToWaitTill = CTimer::GetTimeInMilliseconds() + (AddExtraDeathDelay() > 1000 ? 4000 : 2500);
break; break;
case 3: case MISSION_RETRY_STAGE_WAIT_FOR_DELAY:
if (TimeToWaitTill < CTimer::GetTimeInMilliseconds()) if (TimeToWaitTill < CTimer::GetTimeInMilliseconds())
AllowMissionReplay = 4; AllowMissionReplay = MISSION_RETRY_STAGE_WAIT_FOR_MENU;
break; break;
case 4: case MISSION_RETRY_STAGE_WAIT_FOR_MENU:
AllowMissionReplay = 5; AllowMissionReplay = MISSION_RETRY_STAGE_WAIT_FOR_USER;
RetryMission(0, 0); RetryMission(MISSION_RETRY_TYPE_SUGGEST_TO_PLAYER);
break; break;
case 6: case MISSION_RETRY_STAGE_START_RESTARTING:
AllowMissionReplay = 7; AllowMissionReplay = MISSION_RETRY_STAGE_WAIT_FOR_TIMER_AFTER_RESTART;
AlreadyResetHealth = false; AlreadyResetHealth = false;
TimeToWaitTill = CTimer::GetTimeInMilliseconds() + 500; TimeToWaitTill = CTimer::GetTimeInMilliseconds() + 500;
break; break;
case 7: case MISSION_RETRY_STAGE_WAIT_FOR_TIMER_AFTER_RESTART:
if (!AlreadyResetHealth) { if (!AlreadyResetHealth) {
AlreadyResetHealth = true; AlreadyResetHealth = true;
CPlayerPed* pPlayerPed = FindPlayerPed(); CPlayerPed* pPlayerPed = FindPlayerPed();
@ -1128,7 +1120,7 @@ void CTheScripts::Process()
} }
} }
if (TimeToWaitTill < CTimer::GetTimeInMilliseconds()) { if (TimeToWaitTill < CTimer::GetTimeInMilliseconds()) {
AllowMissionReplay = 0; AllowMissionReplay = MISSION_RETRY_STAGE_NORMAL;
return; return;
} }
break; break;
@ -1764,11 +1756,11 @@ int8 CRunningScript::ProcessCommands0To99(int32 command)
CPlayerInfo* pPlayerInfo = &CWorld::Players[CWorld::PlayerInFocus]; CPlayerInfo* pPlayerInfo = &CWorld::Players[CWorld::PlayerInFocus];
#if 0 // makeing autosave is pointless and is a bit buggy #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) if (pPlayerInfo->m_pPed->GetPedState() != PED_DEAD && pPlayerInfo->m_WBState == WBSTATE_PLAYING && !m_bDeatharrestExecuted)
SaveGameForPause(1); SaveGameForPause(SAVE_TYPE_QUICKSAVE);
#endif #endif
oldTargetX = oldTargetY = 0.0f; oldTargetX = oldTargetY = 0.0f;
if (AllowMissionReplay == 1) if (AllowMissionReplay == MISSION_RETRY_STAGE_WAIT_FOR_SCRIPT_TO_TERMINATE)
AllowMissionReplay = 2; AllowMissionReplay = MISSION_RETRY_STAGE_START_PROCESSING;
// I am fairly sure they forgot to set return value here // I am fairly sure they forgot to set return value here
} }
#endif #endif
@ -2757,10 +2749,10 @@ int8 CRunningScript::ProcessCommands100To199(int32 command)
wchar* key = CTheScripts::GetTextByKeyFromScript(&m_nIp); wchar* key = CTheScripts::GetTextByKeyFromScript(&m_nIp);
#ifdef MISSION_REPLAY #ifdef MISSION_REPLAY
if (strcmp((char*)&CTheScripts::ScriptSpace[m_nIp - KEY_LENGTH_IN_SCRIPT], "M_FAIL") == 0) { if (strcmp((char*)&CTheScripts::ScriptSpace[m_nIp - KEY_LENGTH_IN_SCRIPT], "M_FAIL") == 0) {
if (AllowMissionReplay == 7) if (AllowMissionReplay == MISSION_RETRY_STAGE_WAIT_FOR_TIMER_AFTER_RESTART)
AllowMissionReplay = 0; AllowMissionReplay = MISSION_RETRY_STAGE_NORMAL;
if (CanAllowMissionReplay()) if (CanAllowMissionReplay())
AllowMissionReplay = 1; AllowMissionReplay = MISSION_RETRY_STAGE_WAIT_FOR_SCRIPT_TO_TERMINATE;
} }
#endif #endif
CollectParameters(&m_nIp, 2); CollectParameters(&m_nIp, 2);
@ -3428,7 +3420,7 @@ void CRunningScript::ReturnFromGosubOrFunction()
bool CRunningScript::CanAllowMissionReplay() bool CRunningScript::CanAllowMissionReplay()
{ {
if (AllowMissionReplay) if (AllowMissionReplay != MISSION_RETRY_STAGE_NORMAL)
return false; return false;
for (int i = 0; i < ARRAY_SIZE(MissionScripts); i++) { for (int i = 0; i < ARRAY_SIZE(MissionScripts); i++) {
if (!CGeneral::faststricmp(m_abScriptName, MissionScripts[i])) if (!CGeneral::faststricmp(m_abScriptName, MissionScripts[i]))
@ -3444,14 +3436,14 @@ uint32 AddExtraDeathDelay()
void RetryMission(int type, int unk) void RetryMission(int type, int unk)
{ {
if (type == 0) { if (type == MISSION_RETRY_TYPE_SUGGEST_TO_PLAYER) {
doingMissionRetry = true; doingMissionRetry = true;
FrontEndMenuManager.m_nCurrScreen = MENUPAGE_MISSION_RETRY; FrontEndMenuManager.m_nCurrScreen = MENUPAGE_MISSION_RETRY;
FrontEndMenuManager.RequestFrontEndStartUp(); FrontEndMenuManager.RequestFrontEndStartUp();
} }
else if (type == 2) { else if (type == MISSION_RETRY_TYPE_BEGIN_RESTARTING) {
doingMissionRetry = false; doingMissionRetry = false;
AllowMissionReplay = 6; AllowMissionReplay = MISSION_RETRY_STAGE_START_RESTARTING;
CTheScripts::MissionCleanUp.Process(); CTheScripts::MissionCleanUp.Process();
} }
} }

View file

@ -49,10 +49,6 @@ void FlushLog();
#define KEY_LENGTH_IN_SCRIPT (8) #define KEY_LENGTH_IN_SCRIPT (8)
#ifdef USE_DEBUG_SCRIPT_LOADER
extern const char* scriptfile;
#endif
//#define GTA_SCRIPT_COLLECTIVE //#define GTA_SCRIPT_COLLECTIVE
#define GET_INTEGER_PARAM(i) (ScriptParams[i]) #define GET_INTEGER_PARAM(i) (ScriptParams[i])
#define GET_FLOAT_PARAM(i) (*(float*)&ScriptParams[i]) #define GET_FLOAT_PARAM(i) (*(float*)&ScriptParams[i])
@ -674,6 +670,11 @@ public:
static bool IsFortStauntonDestroyed() { return FSDestroyedFlag && *(int32*)&ScriptSpace[FSDestroyedFlag] == 1; } 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 #ifdef USE_ADVANCED_SCRIPT_DEBUG_OUTPUT
static void LogAfterScriptInitializing(); static void LogAfterScriptInitializing();
static void LogBeforeScriptProcessing(); static void LogBeforeScriptProcessing();
@ -685,9 +686,6 @@ extern int ScriptParams[32];
VALIDATE_SIZE(uStackReturnValue, 4); VALIDATE_SIZE(uStackReturnValue, 4);
#ifdef USE_DEBUG_SCRIPT_LOADER
extern int scriptToLoad;
#endif
#ifdef MISSION_REPLAY #ifdef MISSION_REPLAY
extern int AllowMissionReplay; extern int AllowMissionReplay;
extern uint32 WaitForMissionActivate; extern uint32 WaitForMissionActivate;
@ -704,11 +702,24 @@ extern bool AlreadySavedGame;
#endif #endif
uint32 AddExtraDeathDelay(); uint32 AddExtraDeathDelay();
void RetryMission(int, int); void RetryMission(int, int unk = 0);
#endif
#ifdef USE_DEBUG_SCRIPT_LOADER enum {
extern int scriptToLoad; 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 #endif
extern int gScriptsFile; extern int gScriptsFile;

View file

@ -1384,12 +1384,12 @@ void CRunningScript::DoDeatharrestCheck()
if (!pPlayer->IsRestartingAfterDeath() && !pPlayer->IsRestartingAfterArrest()) if (!pPlayer->IsRestartingAfterDeath() && !pPlayer->IsRestartingAfterArrest())
return; return;
#ifdef MISSION_REPLAY #ifdef MISSION_REPLAY
if (AllowMissionReplay != 7 && AllowMissionReplay != 0) if (AllowMissionReplay != MISSION_RETRY_STAGE_WAIT_FOR_TIMER_AFTER_RESTART && AllowMissionReplay != MISSION_RETRY_STAGE_NORMAL)
return; return;
if (AllowMissionReplay == 7) if (AllowMissionReplay == MISSION_RETRY_STAGE_WAIT_FOR_TIMER_AFTER_RESTART)
AllowMissionReplay = 0; AllowMissionReplay = MISSION_RETRY_STAGE_NORMAL;
if (CanAllowMissionReplay()) if (CanAllowMissionReplay())
AllowMissionReplay = 1; AllowMissionReplay = MISSION_RETRY_STAGE_WAIT_FOR_SCRIPT_TO_TERMINATE;
#endif #endif
script_assert(m_nStackPointer > 0); script_assert(m_nStackPointer > 0);
while (m_nStackPointer > 1) while (m_nStackPointer > 1)

View file

@ -384,7 +384,7 @@ int8 CRunningScript::ProcessCommands1000To1099(int32 command)
if (CTheScripts::MissionSupportsMissionReplay(missionRetryScriptIndex)){ if (CTheScripts::MissionSupportsMissionReplay(missionRetryScriptIndex)){
if (!AlreadySavedGame) { if (!AlreadySavedGame) {
m_nIp = oldIp - 2; m_nIp = oldIp - 2;
SaveGameForPause(4); SaveGameForPause(SAVE_TYPE_QUICKSAVE_FOR_SCRIPT);
AlreadySavedGame = true; AlreadySavedGame = true;
return 0; return 0;
} }

View file

@ -1976,7 +1976,7 @@ CTheScripts::SwitchToMission(int32 mission)
missionRetryScriptIndex = mission; missionRetryScriptIndex = mission;
#ifdef USE_MISSION_REPLAY_OVERRIDE_FOR_NON_MOBILE_SCRIPT #ifdef USE_MISSION_REPLAY_OVERRIDE_FOR_NON_MOBILE_SCRIPT
if (CTheScripts::MissionSupportsMissionReplay(missionRetryScriptIndex)) { if (CTheScripts::MissionSupportsMissionReplay(missionRetryScriptIndex)) {
SaveGameForPause(4); SaveGameForPause(SAVE_TYPE_QUICKSAVE_FOR_SCRIPT);
} }
#endif #endif
#endif #endif

View file

@ -4634,7 +4634,7 @@ CMenuManager::ProcessUserInput(uint8 goDown, uint8 goUp, uint8 optionSelected, u
#ifdef USE_DEBUG_SCRIPT_LOADER #ifdef USE_DEBUG_SCRIPT_LOADER
if (m_nCurrScreen == MENUPAGE_START_MENU || m_nCurrScreen == MENUPAGE_NEW_GAME || m_nCurrScreen == MENUPAGE_NEW_GAME_RELOAD) { if (m_nCurrScreen == MENUPAGE_START_MENU || m_nCurrScreen == MENUPAGE_NEW_GAME || m_nCurrScreen == MENUPAGE_NEW_GAME_RELOAD) {
if (CPad::GetPad(0)->GetChar('R')) { if (CPad::GetPad(0)->GetChar('R')) {
scriptToLoad = 1; CTheScripts::ScriptToLoad = 1;
DoSettingsBeforeStartingAGame(); DoSettingsBeforeStartingAGame();
return; return;
} }
@ -4789,13 +4789,13 @@ CMenuManager::ProcessUserInput(uint8 goDown, uint8 goUp, uint8 optionSelected, u
#ifdef MISSION_REPLAY #ifdef MISSION_REPLAY
case MENUACTION_REJECT_RETRY: case MENUACTION_REJECT_RETRY:
doingMissionRetry = false; doingMissionRetry = false;
AllowMissionReplay = 0; AllowMissionReplay = MISSION_RETRY_STAGE_NORMAL;
RequestFrontEndShutDown(); RequestFrontEndShutDown();
break; break;
case MENUACTION_UNK114: case MENUACTION_UNK114:
doingMissionRetry = false; doingMissionRetry = false;
RequestFrontEndShutDown(); RequestFrontEndShutDown();
RetryMission(2, 0); RetryMission(MISSION_RETRY_TYPE_BEGIN_RESTARTING);
return; return;
#endif #endif
case MENUACTION_SAVEGAME: case MENUACTION_SAVEGAME:
@ -5451,14 +5451,14 @@ CMenuManager::ProcessFileActions()
break; break;
} }
if (doingMissionRetry) { if (doingMissionRetry) {
RetryMission(2, 0); RetryMission(MISSION_RETRY_TYPE_BEGIN_RESTARTING);
m_nCurrSaveSlot = SLOT_COUNT; m_nCurrSaveSlot = SLOT_COUNT;
doingMissionRetry = false; doingMissionRetry = false;
} }
#endif #endif
if (CheckSlotDataValid(m_nCurrSaveSlot)) { if (CheckSlotDataValid(m_nCurrSaveSlot)) {
#ifdef USE_DEBUG_SCRIPT_LOADER #ifdef USE_DEBUG_SCRIPT_LOADER
scriptToLoad = 0; CTheScripts::ScriptToLoad = 0;
#endif #endif
#ifdef XBOX_MESSAGE_SCREEN #ifdef XBOX_MESSAGE_SCREEN

View file

@ -1176,16 +1176,16 @@ void DisplaySaveResult(int unk, char* name)
bool SaveGameForPause(int type) 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); debug("SaveGameForPause failed during AllowMissionReplay %d", AllowMissionReplay);
return false; return false;
} }
if (type != 3 && WaitForSave > CTimer::GetTimeInMilliseconds()) { if (type != SAVE_TYPE_QUICKSAVE_FOR_MISSION_REPLAY && WaitForSave > CTimer::GetTimeInMilliseconds()) {
debug("SaveGameForPause failed WaitForSave"); debug("SaveGameForPause failed WaitForSave");
return false; return false;
} }
WaitForSave = 0; 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); DisplaySaveResult(3, CStats::LastMissionPassedName);
return false; return false;
} }

View file

@ -53,4 +53,14 @@ const char TopLineEmptyFile[] = "THIS FILE IS NOT VALID YET";
extern int8 IsQuickSave; // originally int extern int8 IsQuickSave; // originally int
bool SaveGameForPause(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 #endif