From 1d5442edcd1fb1775647e93104eb142c8fc00ddf Mon Sep 17 00:00:00 2001 From: louist103 Date: Thu, 28 Apr 2022 22:16:05 -0400 Subject: [PATCH] some work --- soh/soh/Enhancements/savestates.cpp | 24 +++++++++++++----------- soh/soh/Enhancements/savestates.h | 1 + 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/soh/soh/Enhancements/savestates.cpp b/soh/soh/Enhancements/savestates.cpp index 57deadb12..594e43cd4 100644 --- a/soh/soh/Enhancements/savestates.cpp +++ b/soh/soh/Enhancements/savestates.cpp @@ -14,6 +14,9 @@ #include #include "z64map_mark.h" + +extern "C" GlobalContext* gGlobalCtx; + // FROM z_lights.c // I didn't feel like moving it into a header file. #define LIGHTS_BUFFER_SIZE 32 @@ -130,7 +133,6 @@ void SaveState::LoadSeqScriptState(void) { (u8*)((uintptr_t)info->seqScriptStateCopy[i].stack[2] + (uintptr_t)gAudioHeap); gAudioContext.seqPlayers[i].scriptState.stack[3] = (u8*)((uintptr_t)info->seqScriptStateCopy[i].stack[3] + (uintptr_t)gAudioHeap); - } } @@ -169,11 +171,11 @@ void SaveStateMgr::ProcessSaveStateRequests(void) { if (this->states.contains(request.slot)) { this->states[request.slot]->Load(); } else { - //TODO log invalid state + SPDLOG_ERROR("Invalid SaveState slot: {}", request.type); } break; - [[unlikely]] default: - //TODO fix logging + [[unlikely]] default: + SPDLOG_ERROR("Invalid SaveState request type: {}", request.type); break; } this->requests.pop(); @@ -181,6 +183,10 @@ void SaveStateMgr::ProcessSaveStateRequests(void) { } SaveStateReturn SaveStateMgr::AddRequest(const SaveStateRequest request) { + if (gGlobalCtx == nullptr) { + return SaveStateReturn::FAIL_WRONG_GAMESTATE; + } + std::unique_lock Lock(this->mutex); switch (request.type) { @@ -191,11 +197,12 @@ SaveStateReturn SaveStateMgr::AddRequest(const SaveStateRequest request) { if (states.contains(request.slot)) { requests.push(request); } else { + SPDLOG_ERROR("Invalid SaveState slot: {}", request.type); return SaveStateReturn::FAIL_INVALID_SLOT; } break; - [[unlikely]] default: - //TODO fix logging + [[unlikely]] default: + SPDLOG_ERROR("Invalid SaveState request type: {}", request.type); break; } @@ -203,8 +210,6 @@ SaveStateReturn SaveStateMgr::AddRequest(const SaveStateRequest request) { } void SaveState::Save(void) { - //this->SetHeader(); - memcpy(&info->sysHeapCopy, gSystemHeap, SYSTEM_HEAP_SIZE /* sizeof(gSystemHeap) */); memcpy(&info->audioHeapCopy, gAudioHeap, AUDIO_HEAP_SIZE /* sizeof(gAudioContext) */); @@ -252,7 +257,6 @@ void SaveState::Load(void) { memcpy(&sMatrixStack, &info->mtxStackCopy, sizeof(MtxF) * 20); memcpy(&sCurrentMatrix, &info->currentMtxCopy, sizeof(MtxF)); sWarpTimerTarget = info->blueWarpTimerCopy; - //TODO RNG seed memcpy(gActiveSounds, info->gActiveSoundsCopy, sizeof(gActiveSounds)); memcpy(gSoundBankMuted, &info->gSoundBankMutedCopy, sizeof(info->gSoundBankMutedCopy)); @@ -265,10 +269,8 @@ void SaveState::Load(void) { sizeof(info->gAudioSfxSwapTarget_copy)); memcpy(gAudioSfxSwapMode, &info->gAudioSfxSwapMode_copy, sizeof(info->gAudioSfxSwapMode_copy)); - Audio_ResetSounds(); D_801755D0 = info->D_801755D0_copy; sLoadedMarkDataTable = info->sLoadedMarkDataTableCopy; - } diff --git a/soh/soh/Enhancements/savestates.h b/soh/soh/Enhancements/savestates.h index 01c15dff6..aa57ea78c 100644 --- a/soh/soh/Enhancements/savestates.h +++ b/soh/soh/Enhancements/savestates.h @@ -17,6 +17,7 @@ enum class SaveStateReturn { FAIL_FILE_NOT_OPENED, FAIL_INVALID_MAGIC, FAIL_INVALID_SIZE, + FAIL_WRONG_GAMESTATE, }; typedef struct SaveStateHeader {