Skip to content

Commit

Permalink
Fix invalid saves caused by incorrect checkpoints. Use scriptvar vari…
Browse files Browse the repository at this point in the history
…able name for autosaverestart
  • Loading branch information
Dextinfire committed Dec 2, 2024
1 parent c6d7430 commit 1c7ed4a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/games/cclcc/savesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ void SaveSystem::LoadMemoryNew(LoadProcess load) {
if (load == LoadProcess::LoadVars) {
ScrWork[SW_PLAYTIME] = WorkingSaveEntry->PlayTime;
ScrWork[SW_TITLE] = WorkingSaveEntry->SwTitle;
ScrWork[SW_AUTOSAVERESTART] = WorkingSaveEntry->SaveType;

memcpy(&FlagWork[50], WorkingSaveEntry->FlagWorkScript1, 50);
memcpy(&FlagWork[300], WorkingSaveEntry->FlagWorkScript2, 100);
Expand Down
13 changes: 9 additions & 4 deletions src/vm/inst_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -720,8 +720,7 @@ VmInstruction(InstDebugData) {
VmInstruction(InstAutoSave) {
StartInstruction;
auto quickSave = [&](int autosaveRestartCheck, int saveType) {
SaveSystem::SaveMemory();
if (ScrWork[2112] != autosaveRestartCheck) {
if (ScrWork[SW_AUTOSAVERESTART] != autosaveRestartCheck) {
int quicksaveEntries = SaveSystem::GetQuickSaveOpenSlot();
if (quicksaveEntries != -1) {
SaveIconDisplay::ShowFor(2.4f);
Expand All @@ -730,19 +729,25 @@ VmInstruction(InstAutoSave) {
}
}
SetFlag(1285, 1);
ScrWork[2112] = 0;
ScrWork[SW_AUTOSAVERESTART] = 0;
};

PopUint8(type);
switch (type) {
case 0: // QuickSave
if (ScrWork[SW_TITLE] == 0xffff) break;
SaveSystem::SaveMemory();
[[fallthrough]];
case 20:
if (ScrWork[SW_TITLE] == 0xffff) break;
quickSave(1, 1);
ImpLogSlow(LL_Warning, LC_VMStub,
"STUB instruction AutoSave(type: QuickSave)\n");
break;
case 1: // AutoSaveRestart (?)
if (ScrWork[SW_TITLE] == 0xffff) break;
SaveSystem::SaveMemory();
[[fallthrough]];
case 21:
if (ScrWork[SW_TITLE] == 0xffff) break;
quickSave(3, 3);
Expand All @@ -767,7 +772,7 @@ VmInstruction(InstAutoSave) {
if (ScrWork[SW_TITLE] != 0xffff) {
SaveSystem::SaveMemory();
SetFlag(1285, 1);
ScrWork[2112] = 0;
ScrWork[SW_AUTOSAVERESTART] = 0;
}
} break;
case 10: { // SetCheckpointId
Expand Down

0 comments on commit 1c7ed4a

Please sign in to comment.