Add in some achievement icons and file hashing saving/loading of save files. Release Build 8515.
This commit is contained in:
@@ -178,7 +178,14 @@ const void SaveFile::SaveGame(){
|
||||
saveSystemFile["Fullscreen"].SetBool(game->IsFullscreen());
|
||||
#pragma endregion
|
||||
|
||||
saveFile["Hash"].SetString("");
|
||||
|
||||
utils::datafile::Write(saveFile,"save_file_path"_S+std::format("save.{:04}",saveFileID));
|
||||
|
||||
std::string fileHash=util::GetHash("save_file_path"_S+std::format("save.{:04}",saveFileID));
|
||||
saveFile["Hash"].SetString(fileHash);
|
||||
|
||||
utils::datafile::Write(saveFile,"save_file_path"_S+std::format("save.{:04}",saveFileID)); //Once the hash has been computed and added, save the file a second time.
|
||||
utils::datafile::Write(saveSystemFile,"save_file_path"_S+"system.conf");
|
||||
utils::datafile metadata;
|
||||
if(onlineMode){
|
||||
@@ -279,6 +286,24 @@ void SaveFile::LoadFile(){
|
||||
|
||||
if(std::filesystem::exists(loadFilename)){
|
||||
utils::datafile::Read(loadFile,"save_file_path"_S+std::format("save.{:04}",saveFileID));
|
||||
if(!loadFile.HasProperty("Hash")){
|
||||
LOG(std::format("WARNING! Filehash for file {} does not exist!","save_file_path"_S+std::format("save.{:04}",saveFileID)));
|
||||
return;
|
||||
}
|
||||
if(loadFile.HasProperty("Hash")){
|
||||
std::string expectedFileHash=loadFile["Hash"].GetString();
|
||||
loadFile["Hash"].SetString("");
|
||||
utils::datafile::Write(loadFile,"save_file_path"_S+std::format("save.{:04}",saveFileID));
|
||||
std::string fileHash=util::GetHash("save_file_path"_S+std::format("save.{:04}",saveFileID));
|
||||
|
||||
if(expectedFileHash!=fileHash){
|
||||
LOG(std::format("WARNING! Filehash for file {} was not identified as proper! Will not load this file!","save_file_path"_S+std::format("save.{:04}",saveFileID)));
|
||||
return;
|
||||
}
|
||||
|
||||
loadFile["Hash"].SetString(expectedFileHash); //Now write the hash back into the file since we tampered with it.
|
||||
utils::datafile::Write(loadFile,"save_file_path"_S+std::format("save.{:04}",saveFileID));
|
||||
}
|
||||
game->ResetGame();
|
||||
for(auto&[key,data]:loadFile["Items"].GetOrderedKeys()){
|
||||
std::weak_ptr<Item>newItem=Inventory::AddItem(data["Item Name"].GetString(),data["Amt"].GetInt());
|
||||
|
||||
Reference in New Issue
Block a user