Skip to content

Commit

Permalink
fix!: stop corrupting saves (#19)
Browse files Browse the repository at this point in the history
* fix!: stop corrupting saves

- This was seen only on AE. Our code for saving DHDT data through SKSE
  serialization for AE was faulty.
  We don't yet understand why, so our solution is to implement our own
  saves for DHDT.
- No save files for non-DHDT users

Co-authored-by: SesamePaste233 <[email protected]>
  • Loading branch information
DaymareOn and SesamePaste233 authored Mar 7, 2022
1 parent 32d97f5 commit c1e3ab5
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions hdtSMP64/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,26 +592,42 @@ extern "C" {
mm->MenuOpenCloseEventDispatcher()->AddEventSink(&hdt::g_freezeEventHandler);
hdt::checkOldPlugins();
hdt::loadConfig();

// I think we only have _DEBUG now...
#ifdef DEBUG
hdt::g_armorAttachEventDispatcher.addListener(&hdt::g_eventDebugLogger);
GetEventDispatcherList()->unk1B8.AddEventSink(&hdt::g_eventDebugLogger);
GetEventDispatcherList()->unk840.AddEventSink(&hdt::g_eventDebugLogger);
#endif
}

});
}

const SKSESerializationInterface* srlz_intfc = reinterpret_cast<SKSESerializationInterface*>(skse->QueryInterface(kInterface_Serialization));
if (srlz_intfc) {
//Initialize all Serializer Module
hdt::Override::OverrideManager::GetSingleton();

srlz_intfc->SetUniqueID(hdt::g_PluginHandle, 'FHDT');
// 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)
{
auto data = hdt::Override::OverrideManager::GetSingleton()->Serialize();
if (!data.str().empty()) {
std::string save_name = reinterpret_cast<char*>(msg->data);
std::ofstream ofs(OVERRIDE_SAVE_PATH + save_name + ".dhdt", std::ios::out);
if(ofs && ofs.is_open())
ofs << data.str();
}
}

srlz_intfc->SetSaveCallback(hdt::g_PluginHandle, hdt::SerializerBase::Save);
// 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)
{
std::string save_name = reinterpret_cast<char*>(msg->data);
save_name = save_name.substr(0, save_name.find_last_of("."));

srlz_intfc->SetLoadCallback(hdt::g_PluginHandle, hdt::SerializerBase::Load);
std::ifstream ifs(OVERRIDE_SAVE_PATH + save_name + ".dhdt", std::ios::in);
if (ifs && ifs.is_open())
{
std::stringstream data;
data << ifs.rdbuf();
hdt::Override::OverrideManager::GetSingleton()->Deserialize(data);
}
}
});
}

ObScriptCommand* hijackedCommand = nullptr;
Expand Down

0 comments on commit c1e3ab5

Please sign in to comment.