Make sure file hash does not include the | character due to emscripten using it to split a save request.

mac-build
sigonasr2 8 months ago
parent 2a9e698e0a
commit be15697fc8
  1. 5
      Adventures in Lestoria/SaveFile.cpp
  2. 4
      Adventures in Lestoria/olcUTIL_DataFile.h
  3. 5
      Adventures in Lestoria/util.cpp

@ -184,7 +184,7 @@ const void SaveFile::SaveGame(){
std::string fileHash=util::GetHash("save_file_path"_S+std::format("save.{:04}",saveFileID));
saveFile["Hash"].SetString(fileHash);
std::cout<<"Setting Hash to "<<fileHash<<". Writing to File..."<<std::endl;
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;
@ -298,6 +298,7 @@ void SaveFile::LoadFile(){
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)));
LOG("Expected vs Actual: "<<expectedFileHash<<std::endl<<fileHash<<std::endl)
return;
}
@ -595,7 +596,7 @@ const std::string SaveFile::CreateServerRequest(const SaveFileOperation::Operati
*/
const std::array uriReserved={';','/','?',':','@','&','=','+','$',',','-','_','.','!','~','*','\'','(',')','#'};
if(c>='A'&&c<='Z'||c>='a'&&c<='z'||c>='0'&&c<='9'||std::find(uriReserved.begin(),uriReserved.end(),c)!=uriReserved.end())return std::move(str)+c;
std::string convertedChar=std::format("%{:02x}",c);
std::for_each(convertedChar.begin(),convertedChar.end(),[](char&c){c=char(std::toupper(c));});
return std::move(str)+convertedChar;

@ -267,9 +267,11 @@ namespace olc::utils
// Value does not contain separator, so just write out
file << property.second.GetString(i) << ((nItems > 1) ? sSeperator : "");
}
std::cout<<"Written: "<<property.second.GetString(i)<<std::endl;
nItems--;
}
std::cout<<"Write newline."<<std::endl;
// Property written, move to next line
file << "\n";
}

@ -161,13 +161,14 @@ std::string util::GetHash(std::string fileName){
hashChar=hash[hashIndex];
}
char newChar=file.get();
if(newChar=='\r'||newChar=='\n')continue;
if(newChar=='\r'||newChar=='\f'||newChar=='\n')continue;
hashChar+=newChar*21-7;
hashChar^=hashIndex;
if(hashIndex>0)hashChar+=hash[hashIndex-1];
hashChar%=94;
hashChar+=32;
if(hashChar=='"'){hashChar+=60;}
if(hashChar=='"'||hashChar==',')hashChar+=60;
if(hashChar=='|')hashChar++; //FORBIDDEN CHARACTER IN EMSCRIPTEN BUILD!
if(hash.size()<std::numeric_limits<uint8_t>::max()){
hash+=hashChar;
}else{

Loading…
Cancel
Save