Savestate: Reset what older states lack instead of keeping pre-load values

Missing sections (videocodec, audiocodec, aac, mp3) and old-version
branches (impose, io, umd, gps, mic, display, font) left the session
before the load in place.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
Henrik RydgårdandClaude Opus 5.5 committed 2026-09-28 11:32:07 -06:00
1 parent 8663ce2a33
commit cd94e414cd
11 files changed
+65 -7

No files matched your search

+5 -1
View File
@@ -43,8 +43,12 @@ void __AACShutdown() {
void __AACDoState(PointerWrap &p) {
auto s = p.Section("sceAAC", 0, 1);
if (!s)
if (!s) {
if (p.mode == PointerWrap::MODE_READ) {
__AACShutdown();
}
return;
}
Do(p, g_aacMap);
}
+7 -1
View File
@@ -658,9 +658,15 @@ void Register_sceAudiocodec() {
void __sceAudiocodecDoState(PointerWrap &p){
auto s = p.Section("AudioList", 0, 2);
if (!s) {
oldStateLoaded = true;
if (p.mode == PointerWrap::MODE_READ) {
clearDecoders();
oldStateLoaded = true;
}
return;
}
if (p.mode == PointerWrap::MODE_READ) {
oldStateLoaded = false;
}
int count = (int)g_audioDecoderContexts.size();
Do(p, count);
+4
View File
@@ -299,6 +299,10 @@ void __DisplayDoState(PointerWrap &p) {
Do(p, lastFlipCycles);
Do(p, nextFlipCycles);
}
if (p.mode == p.MODE_READ) {
// Not saved. Start counting again rather than carry over the session before the load.
lastFlipsTooFrequent = 0;
}
gpu->DoState(p);
+3
View File
@@ -1107,6 +1107,9 @@ void __FontDoState(PointerWrap &p) {
Do(p, actionPostAllocCallback);
__KernelRestoreActionType(actionPostAllocCallback, PostAllocCallback::Create);
if (s >= 2) {
useAllocCallbacks = true;
}
Do(p, actionPostOpenCallback);
__KernelRestoreActionType(actionPostOpenCallback, PostOpenCallback::Create);
if (s >= 2) {
+3
View File
@@ -70,6 +70,9 @@ void __ImposeDoState(PointerWrap &p) {
if (s >= 2) {
Do(p, imposeChanges);
Do(p, imposeAvls);
} else if (p.mode == p.MODE_READ) {
imposeChanges = 0;
imposeAvls = 0;
}
}
+3
View File
@@ -726,6 +726,9 @@ void __IoDoState(PointerWrap &p) {
if (s >= 3) {
Do(p, lastMemStickState);
Do(p, lastMemStickFatState);
} else if (p.mode == p.MODE_READ) {
lastMemStickState = MemoryStick_State();
lastMemStickFatState = MemoryStick_FatState();
}
for (int i = 0; i < PSP_COUNT_FDS; ++i) {
+6 -1
View File
@@ -158,8 +158,13 @@ void __Mp3Shutdown() {
void __Mp3DoState(PointerWrap &p) {
auto s = p.Section("sceMp3", 0, 3);
if (!s)
if (!s) {
if (p.mode == PointerWrap::MODE_READ) {
__Mp3Shutdown();
resourceInited = false;
}
return;
}
if (s >= 2) {
Do(p, g_mp3Map);
+2
View File
@@ -109,6 +109,8 @@ void __UmdDoState(PointerWrap &p)
if (g_UMDReplacePermit && p.mode == p.MODE_READ) {
System_Notify(SystemNotification::UI);
}
} else if (p.mode == p.MODE_READ) {
g_UMDReplacePermit = false;
}
if (s > 2) {
Do(p, umdInsertChangeEvent);
+12 -4
View File
@@ -45,11 +45,19 @@ void __UsbGpsInit() {
}
void __UsbGpsDoState(PointerWrap &p) {
auto s = p.Section("sceUsbGps", 0, 1);
if (!s)
return;
const bool wasOn = gpsStatus == GPS_STATE_ON;
auto s = p.Section("sceUsbGps", 0, 1);
if (!s) {
// Older states didn't save it, so leave it off.
if (p.mode == p.MODE_READ) {
if (wasOn) {
System_GPSCommand("close");
}
gpsStatus = GPS_STATE_OFF;
}
return;
}
Do(p, gpsStatus);
if (p.mode == p.MODE_READ) {
if (gpsStatus == GPS_STATE_ON) {
+12
View File
@@ -126,6 +126,14 @@ void __UsbMicDoState(PointerWrap &p) {
eventMicBlockingResume = -1;
CoreTiming::RestoreRegisterEvent(eventMicBlockingResume, "MicBlockingResume", &__MicBlockingResume);
waitingThreads.clear();
// Nor was the mic, so leave it off.
if (Microphone::isMicStarted()) {
Microphone::stopMic();
}
numNeedSamples = 0;
curTargetAddr = 0;
readMicDataLength = 0;
micState = 0;
}
return;
}
@@ -146,6 +154,10 @@ void __UsbMicDoState(PointerWrap &p) {
if (s > 2) {
Do(p, curTargetAddr);
Do(p, readMicDataLength);
} else if (p.mode == p.MODE_READ) {
// The host mic thread writes to curTargetAddr, so don't leave the one from before the load.
curTargetAddr = 0;
readMicDataLength = 0;
}
if (!audioBuf && numNeedSamples > 0) {
audioBuf = new QueueBuf(numNeedSamples << 1);
+8
View File
@@ -194,6 +194,14 @@ void __VideocodecDoState(PointerWrap &p) {
auto s = p.Section("sceVideocodec", 0, 1);
if (!s) {
if (p.mode == p.MODE_READ) {
// A state from before this module. Don't keep the contexts and ME memory of the session
// before the load.
ClearContexts(false);
g_meRam.clear();
g_meRam.shrink_to_fit();
g_meAlloc.Shutdown();
}
return;
}