@ -191,9 +191,6 @@ const void SaveFile::SaveGame(){
saveSystemFile [ " Fullscreen " ] . SetBool ( game - > IsFullscreen ( ) ) ;
saveSystemFile [ " Fullscreen " ] . SetBool ( game - > IsFullscreen ( ) ) ;
# pragma endregion
# pragma endregion
saveFile [ " Hash " ] . SetString ( " " ) ;
for ( auto & [ mapName , chunks ] : game - > minimap . GetChunkData ( ) ) {
for ( auto & [ mapName , chunks ] : game - > minimap . GetChunkData ( ) ) {
size_t chunkInd = 0 ;
size_t chunkInd = 0 ;
for ( auto & chunk : chunks ) {
for ( auto & chunk : chunks ) {
@ -203,25 +200,30 @@ const void SaveFile::SaveGame(){
}
}
# pragma region Save save file and prep File Hash
# pragma region Save save file and prep File Hash
utils : : datafile : : Write ( saveFile , " save_file_path " _S + std : : format ( " save.{:04} " , saveFileID ) ) ;
bool fileNoHashWrittenSuccessfully { false } ;
bool fileHashWrittenSuccessfully { false } ;
while ( ! fileNoHashWrittenSuccessfully | | ! fileHashWrittenSuccessfully ) {
saveFile [ " Hash " ] . SetString ( " " ) ;
fileNoHashWrittenSuccessfully = 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 ) ) ;
std : : string fileHash = util : : GetHash ( " save_file_path " _S + std : : format ( " save.{:04} " , saveFileID ) ) ;
saveFile [ " Hash " ] . SetString ( fileHash ) ;
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.
fileHashWrittenSuccessfully = 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.
}
# pragma endregion
# pragma endregion
//WARNING! DO NOT WRITE ANY CODE BELOW HERE!!!!! THE HASH HAS ALREADY BEEN WRITTEN.
//WARNING! DO NOT WRITE ANY CODE BELOW HERE!!!!! THE HASH HAS ALREADY BEEN WRITTEN.
//FILES BECOME CORRUPTED IF THE SAVE FILE IS MODIFIED FROM HERE ONWARDS.
//FILES BECOME CORRUPTED IF THE SAVE FILE IS MODIFIED FROM HERE ONWARDS.
}
}
utils : : datafile : : Write ( saveSystemFile , " save_file_path " _S + " system.conf " ) ;
while ( ! utils : : datafile : : Write ( saveSystemFile , " save_file_path " _S + " system.conf " ) ) ;
utils : : datafile metadata ;
utils : : datafile metadata ;
if ( onlineMode ) {
if ( onlineMode ) {
if ( std : : filesystem : : exists ( " save_file_path " _S + " metadata.dat " + " _online " ) ) {
if ( std : : filesystem : : exists ( " save_file_path " _S + " metadata.dat " + " _online " ) ) {
utils : : datafile : : Read ( metadata , " save_file_path " _S + " metadata.dat " + " _online " ) ;
while ( ! utils : : datafile : : Read ( metadata , " save_file_path " _S + " metadata.dat " + " _online " ) ) ;
}
}
} else {
} else {
if ( std : : filesystem : : exists ( " save_file_path " _S + " metadata.dat " ) ) {
if ( std : : filesystem : : exists ( " save_file_path " _S + " metadata.dat " ) ) {
utils : : datafile : : Read ( metadata , " save_file_path " _S + " metadata.dat " ) ;
while ( ! utils : : datafile : : Read ( metadata , " save_file_path " _S + " metadata.dat " ) ) ;
}
}
}
}
metadata . GetProperty ( std : : format ( " save{} " , saveFileID ) ) . SetReal ( game - > GetRunTime ( ) , 0U ) ;
metadata . GetProperty ( std : : format ( " save{} " , saveFileID ) ) . SetReal ( game - > GetRunTime ( ) , 0U ) ;
@ -230,9 +232,9 @@ const void SaveFile::SaveGame(){
metadata . GetProperty ( std : : format ( " save{} " , saveFileID ) ) . SetString ( game - > GetPlayer ( ) - > GetClassName ( ) , 3U ) ;
metadata . GetProperty ( std : : format ( " save{} " , saveFileID ) ) . SetString ( game - > GetPlayer ( ) - > GetClassName ( ) , 3U ) ;
metadata . GetProperty ( std : : format ( " save{} " , saveFileID ) ) . SetString ( std : : string ( SaveFile : : GetSaveFileName ( ) ) , 4U ) ;
metadata . GetProperty ( std : : format ( " save{} " , saveFileID ) ) . SetString ( std : : string ( SaveFile : : GetSaveFileName ( ) ) , 4U ) ;
if ( ! onlineMode ) {
if ( ! onlineMode ) {
utils : : datafile : : Write ( metadata , " save_file_path " _S + " metadata.dat " ) ;
while ( ! utils : : datafile : : Write ( metadata , " save_file_path " _S + " metadata.dat " ) ) ;
} else {
} else {
utils : : datafile : : Write ( metadata , " save_file_path " _S + " metadata.dat " + " _online " ) ;
while ( ! utils : : datafile : : Write ( metadata , " save_file_path " _S + " metadata.dat " + " _online " ) ) ;
}
}
utils : : datafile : : INITIAL_SETUP_COMPLETE = true ;
utils : : datafile : : INITIAL_SETUP_COMPLETE = true ;
@ -327,8 +329,13 @@ void SaveFile::LoadFile(){
}
}
if ( loadFile . HasProperty ( " Hash " ) ) {
if ( loadFile . HasProperty ( " Hash " ) ) {
std : : string expectedFileHash = loadFile [ " Hash " ] . GetString ( ) ;
std : : string expectedFileHash = loadFile [ " Hash " ] . GetString ( ) ;
bool fileNoHashWrittenSuccessfully { false } ;
bool fileHashWrittenSuccessfully { false } ;
while ( ! fileNoHashWrittenSuccessfully | | ! fileHashWrittenSuccessfully ) {
fileNoHashWrittenSuccessfully = false ;
fileHashWrittenSuccessfully = false ;
loadFile [ " Hash " ] . SetString ( " " ) ;
loadFile [ " Hash " ] . SetString ( " " ) ;
utils : : datafile : : Write ( loadFile , " save_file_path " _S + std : : format ( " save.{:04} " , saveFileID ) ) ;
fileNoHashWrittenSuccessfully = utils : : datafile : : Write ( loadFile , " save_file_path " _S + std : : format ( " save.{:04} " , saveFileID ) ) ;
auto trim = [ ] ( std : : string & s )
auto trim = [ ] ( std : : string & s )
{
{
@ -345,7 +352,8 @@ void SaveFile::LoadFile(){
}
}
loadFile [ " Hash " ] . SetString ( expectedFileHash ) ; //Now write the hash back into the file since we tampered with it.
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 ) ) ;
fileHashWrittenSuccessfully = utils : : datafile : : Write ( loadFile , " save_file_path " _S + std : : format ( " save.{:04} " , saveFileID ) ) ;
}
}
}
}
}
game - > ResetGame ( ) ;
game - > ResetGame ( ) ;