From 5f37402597b303ea105b51e52ac4489bc50e8bc9 Mon Sep 17 00:00:00 2001 From: DaymareOn Date: Sat, 5 Mar 2022 09:45:37 +0000 Subject: [PATCH] fix: load and save DHDT files --- hdtSMP64/main.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/hdtSMP64/main.cpp b/hdtSMP64/main.cpp index 777dc94..4fd2fc6 100644 --- a/hdtSMP64/main.cpp +++ b/hdtSMP64/main.cpp @@ -602,20 +602,30 @@ extern "C" { } // If we receive a SaveGame message, we serialize our data and save it in our dedicated save files. - if (msg && msg->type == SKSEMessagingInterface::kMessage_SaveGame) { + if (msg && msg->type == SKSEMessagingInterface::kMessage_SaveGame) + { std::string save_name = reinterpret_cast(msg->data); std::ofstream ofs(OVERRIDE_SAVE_PATH + save_name + ".dhdt", std::ios::out); - auto data = hdt::Override::OverrideManager::GetSingleton()->Serialize(); - ofs << data.str(); + if (ofs && ofs.is_open()) + { + auto data = hdt::Override::OverrideManager::GetSingleton()->Serialize(); + ofs << data.str(); + } } // If we receive a PreLoadGame message, we take our data in our dedicated save files and deserialize it. - if (msg && msg->type == SKSEMessagingInterface::kMessage_PreLoadGame) { + if (msg && msg->type == SKSEMessagingInterface::kMessage_PreLoadGame) + { std::string save_name = reinterpret_cast(msg->data); + save_name = save_name.substr(0, save_name.find_last_of(".")); + std::ifstream ifs(OVERRIDE_SAVE_PATH + save_name + ".dhdt", std::ios::in); - std::stringstream data; - data << ifs.rdbuf(); - hdt::Override::OverrideManager::GetSingleton()->Deserialize(data); + if (ifs && ifs.is_open()) + { + std::stringstream data; + data << ifs.rdbuf(); + hdt::Override::OverrideManager::GetSingleton()->Deserialize(data); + } } }); }