Skip to content

Commit

Permalink
tr1/game-flow: fix crash with /load and /play
Browse files Browse the repository at this point in the history
Resolves #2411.
  • Loading branch information
rr- committed Jan 29, 2025
1 parent 25a6d7e commit 66254db
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/tr1/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
- fixed health bar continuing to show when the inventory ring rotates (#1991, regression from 4.0)
- fixed header and arrows disappearing when the inventory ring rotates (#2352, regression from 4.4)
- fixed Story So Far feature not playing opening FMVs from the current level (#2360, regression from 4.2)
- fixed `/play` command crashing the game when used after loading a level (#2411, regression)
- fixed `/demo` command crashing the game if no demos are present (regression from 4.1)
- fixed Lara not being able to jump or stop swimming if the related responsive config options are enabled, but enhanced animations are not present (#2397, regression from 4.6)
- improved pause screen compatibility with PS1 (#2248)
Expand Down
6 changes: 6 additions & 0 deletions src/libtrx/game/phase/executor.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "game/game_flow.h"
#include "game/interpolation.h"
#include "game/output.h"
#include "game/savegame.h"
#include "game/shell.h"
#include "game/text.h"

Expand All @@ -27,6 +28,11 @@ static PHASE_CONTROL M_Control(PHASE *const phase, const int32_t nframes)
if (gf_override_cmd.action != GF_NOOP) {
const GF_COMMAND gf_cmd = gf_override_cmd;
GF_OverrideCommand((GF_COMMAND) { .action = GF_NOOP });

// A change in the game flow is not natural. Force features like death
// counter to break from the currently active savegame file.
Savegame_ClearCurrentSlot();

return (PHASE_CONTROL) { .action = PHASE_ACTION_END, .gf_cmd = gf_cmd };
}

Expand Down
1 change: 1 addition & 0 deletions src/libtrx/include/libtrx/game/savegame.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ extern int32_t Savegame_GetSlotCount(void);
extern bool Savegame_IsSlotFree(int32_t slot_num);
extern bool Savegame_Load(int32_t slot_num);
extern bool Savegame_Save(int32_t slot_num);
extern void Savegame_ClearCurrentSlot(void);
2 changes: 1 addition & 1 deletion src/tr1/game/inventory_ring/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ static GF_COMMAND M_Finish(INV_RING *const ring, const bool apply_changes)

case O_PHOTO_OPTION:
if (apply_changes) {
g_GameInfo.current_save_slot = -1;
Savegame_ClearCurrentSlot();
}
if (GF_GetGymLevel() != NULL) {
return (GF_COMMAND) {
Expand Down
4 changes: 2 additions & 2 deletions src/tr1/game/option/option_passport.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ static void M_NewGame(void)
} else {
g_GameInfo.save_initial_version = SAVEGAME_CURRENT_VERSION;
g_GameInfo.bonus_level_unlock = false;
g_GameInfo.current_save_slot = -1;
Savegame_ClearCurrentSlot();
g_GameInfo.passport_selection = PASSPORT_MODE_NEW_GAME;
}
} else if (m_PassportStatus.mode == PASSPORT_MODE_NEW_GAME) {
Expand All @@ -559,7 +559,7 @@ static void M_NewGame(void)
break;
}
g_GameInfo.bonus_level_unlock = false;
g_GameInfo.current_save_slot = -1;
Savegame_ClearCurrentSlot();
g_GameInfo.passport_selection = PASSPORT_MODE_NEW_GAME;
g_GameInfo.save_initial_version = SAVEGAME_CURRENT_VERSION;
} else if (
Expand Down
5 changes: 5 additions & 0 deletions src/tr1/game/savegame/savegame.c
Original file line number Diff line number Diff line change
Expand Up @@ -686,3 +686,8 @@ bool Savegame_RestartAvailable(int32_t slot_num)
SAVEGAME_INFO *savegame_info = &m_SavegameInfo[slot_num];
return savegame_info->features.restart;
}

void Savegame_ClearCurrentSlot(void)
{
g_GameInfo.current_save_slot = -1;
}
2 changes: 0 additions & 2 deletions src/tr1/game/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,6 @@ void Shell_Main(void)
m_ModPaths[m_ActiveMod].game_flow_path,
m_ModPaths[m_ActiveMod].game_strings_path);

g_GameInfo.current_save_slot = -1;

GF_COMMAND gf_cmd = GF_DoFrontendSequence();
bool loop_continue = !Shell_IsExiting();
while (loop_continue) {
Expand Down
4 changes: 4 additions & 0 deletions src/tr2/decomp/savegame.c
Original file line number Diff line number Diff line change
Expand Up @@ -1093,3 +1093,7 @@ int32_t S_LoadGame(const int32_t slot_num)
File_Close(fp);
return true;
}

void Savegame_ClearCurrentSlot(void)
{
}

0 comments on commit 66254db

Please sign in to comment.