mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2026-04-26 04:11:36 +00:00
persistent_data: remove header size field
This commit is contained in:
parent
9b866168c4
commit
f57d0ba49a
8 changed files with 45 additions and 59 deletions
|
|
@ -65,7 +65,7 @@ static bool ProcessCorruptAchievementsMessage()
|
||||||
if (!g_corruptAchievementsMessageOpen)
|
if (!g_corruptAchievementsMessageOpen)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
auto message = AchievementManager::BinStatus == EAchStatus::IOError
|
auto message = AchievementManager::BinStatus == EAchBinStatus::IOError
|
||||||
? Localise("Title_Message_AchievementDataIOError")
|
? Localise("Title_Message_AchievementDataIOError")
|
||||||
: Localise("Title_Message_AchievementDataCorrupt");
|
: Localise("Title_Message_AchievementDataCorrupt");
|
||||||
|
|
||||||
|
|
@ -73,7 +73,7 @@ static bool ProcessCorruptAchievementsMessage()
|
||||||
{
|
{
|
||||||
// Create a new save file if the file was successfully loaded and failed validation.
|
// Create a new save file if the file was successfully loaded and failed validation.
|
||||||
// If the file couldn't be opened, restarting may fix this error, so it isn't worth clearing the data for.
|
// If the file couldn't be opened, restarting may fix this error, so it isn't worth clearing the data for.
|
||||||
if (AchievementManager::BinStatus != EAchStatus::IOError)
|
if (AchievementManager::BinStatus != EAchBinStatus::IOError)
|
||||||
AchievementManager::SaveBinary(true);
|
AchievementManager::SaveBinary(true);
|
||||||
|
|
||||||
g_corruptAchievementsMessageOpen = false;
|
g_corruptAchievementsMessageOpen = false;
|
||||||
|
|
@ -139,7 +139,7 @@ void PressStartSaveLoadThreadMidAsmHook()
|
||||||
if (!AchievementManager::LoadBinary())
|
if (!AchievementManager::LoadBinary())
|
||||||
LOGFN_ERROR("Failed to load achievement data... (status code {})", (int)AchievementManager::BinStatus);
|
LOGFN_ERROR("Failed to load achievement data... (status code {})", (int)AchievementManager::BinStatus);
|
||||||
|
|
||||||
if (AchievementManager::BinStatus != EAchStatus::Success)
|
if (AchievementManager::BinStatus != EAchBinStatus::Success)
|
||||||
{
|
{
|
||||||
g_corruptAchievementsMessageOpen = true;
|
g_corruptAchievementsMessageOpen = true;
|
||||||
g_corruptAchievementsMessageOpen.wait(true);
|
g_corruptAchievementsMessageOpen.wait(true);
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,9 @@ public:
|
||||||
|
|
||||||
char Signature[4] ACH_SIGNATURE;
|
char Signature[4] ACH_SIGNATURE;
|
||||||
uint32_t Version{ ACH_VERSION };
|
uint32_t Version{ ACH_VERSION };
|
||||||
uint32_t Checksum;
|
uint32_t Checksum{};
|
||||||
uint32_t Reserved;
|
uint32_t Reserved{};
|
||||||
AchRecord Records[ACH_RECORDS];
|
AchRecord Records[ACH_RECORDS]{};
|
||||||
|
|
||||||
bool VerifySignature() const;
|
bool VerifySignature() const;
|
||||||
bool VerifyVersion() const;
|
bool VerifyVersion() const;
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ bool AchievementManager::LoadBinary()
|
||||||
{
|
{
|
||||||
AchievementManager::Reset();
|
AchievementManager::Reset();
|
||||||
|
|
||||||
BinStatus = EAchStatus::Success;
|
BinStatus = EAchBinStatus::Success;
|
||||||
|
|
||||||
auto dataPath = GetDataPath(true);
|
auto dataPath = GetDataPath(true);
|
||||||
|
|
||||||
|
|
@ -100,7 +100,10 @@ bool AchievementManager::LoadBinary()
|
||||||
dataPath = GetDataPath(false);
|
dataPath = GetDataPath(false);
|
||||||
|
|
||||||
if (!std::filesystem::exists(dataPath))
|
if (!std::filesystem::exists(dataPath))
|
||||||
|
{
|
||||||
|
BinStatus = EAchBinStatus::NoFile;
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
|
|
@ -109,7 +112,7 @@ bool AchievementManager::LoadBinary()
|
||||||
|
|
||||||
if (fileSize != dataSize)
|
if (fileSize != dataSize)
|
||||||
{
|
{
|
||||||
BinStatus = EAchStatus::BadFileSize;
|
BinStatus = EAchBinStatus::BadFileSize;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -117,7 +120,7 @@ bool AchievementManager::LoadBinary()
|
||||||
|
|
||||||
if (!file)
|
if (!file)
|
||||||
{
|
{
|
||||||
BinStatus = EAchStatus::IOError;
|
BinStatus = EAchBinStatus::IOError;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -127,7 +130,7 @@ bool AchievementManager::LoadBinary()
|
||||||
|
|
||||||
if (!data.VerifySignature())
|
if (!data.VerifySignature())
|
||||||
{
|
{
|
||||||
BinStatus = EAchStatus::BadSignature;
|
BinStatus = EAchBinStatus::BadSignature;
|
||||||
file.close();
|
file.close();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -136,7 +139,7 @@ bool AchievementManager::LoadBinary()
|
||||||
|
|
||||||
if (!data.VerifyVersion())
|
if (!data.VerifyVersion())
|
||||||
{
|
{
|
||||||
BinStatus = EAchStatus::BadVersion;
|
BinStatus = EAchBinStatus::BadVersion;
|
||||||
file.close();
|
file.close();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -146,7 +149,7 @@ bool AchievementManager::LoadBinary()
|
||||||
|
|
||||||
if (!data.VerifyChecksum())
|
if (!data.VerifyChecksum())
|
||||||
{
|
{
|
||||||
BinStatus = EAchStatus::BadChecksum;
|
BinStatus = EAchBinStatus::BadChecksum;
|
||||||
file.close();
|
file.close();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -160,7 +163,7 @@ bool AchievementManager::LoadBinary()
|
||||||
|
|
||||||
bool AchievementManager::SaveBinary(bool ignoreStatus)
|
bool AchievementManager::SaveBinary(bool ignoreStatus)
|
||||||
{
|
{
|
||||||
if (!ignoreStatus && BinStatus != EAchStatus::Success)
|
if (!ignoreStatus && BinStatus != EAchBinStatus::Success)
|
||||||
{
|
{
|
||||||
LOGN_WARNING("Achievement data will not be saved in this session!");
|
LOGN_WARNING("Achievement data will not be saved in this session!");
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -181,7 +184,7 @@ bool AchievementManager::SaveBinary(bool ignoreStatus)
|
||||||
file.write((const char*)&Data, sizeof(AchievementData));
|
file.write((const char*)&Data, sizeof(AchievementData));
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
BinStatus = EAchStatus::Success;
|
BinStatus = EAchBinStatus::Success;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,11 @@
|
||||||
|
|
||||||
#include <user/achievement_data.h>
|
#include <user/achievement_data.h>
|
||||||
|
|
||||||
enum class EAchStatus
|
enum class EAchBinStatus
|
||||||
{
|
{
|
||||||
Unknown,
|
Unknown,
|
||||||
Success,
|
Success,
|
||||||
|
NoFile,
|
||||||
IOError,
|
IOError,
|
||||||
BadFileSize,
|
BadFileSize,
|
||||||
BadSignature,
|
BadSignature,
|
||||||
|
|
@ -17,7 +18,7 @@ class AchievementManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static inline AchievementData Data{};
|
static inline AchievementData Data{};
|
||||||
static inline EAchStatus BinStatus{ EAchStatus::Unknown };
|
static inline EAchBinStatus BinStatus{ EAchBinStatus::Unknown };
|
||||||
|
|
||||||
static std::filesystem::path GetDataPath(bool checkForMods)
|
static std::filesystem::path GetDataPath(bool checkForMods)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -4,15 +4,10 @@ bool PersistentData::VerifySignature() const
|
||||||
{
|
{
|
||||||
char sig[4] = EXT_SIGNATURE;
|
char sig[4] = EXT_SIGNATURE;
|
||||||
|
|
||||||
return memcmp(Header.Signature, sig, sizeof(Header.Signature)) == 0;
|
return memcmp(Signature, sig, sizeof(Signature)) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PersistentData::VerifyVersion() const
|
bool PersistentData::VerifyVersion() const
|
||||||
{
|
{
|
||||||
return Header.Version <= EXT_VERSION;
|
return Version <= EXT_VERSION;
|
||||||
}
|
|
||||||
|
|
||||||
bool PersistentData::VerifyHeader() const
|
|
||||||
{
|
|
||||||
return Header.HeaderSize == sizeof(ExtHeader);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,18 +20,11 @@ enum class EDLCFlag
|
||||||
class PersistentData
|
class PersistentData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
struct ExtHeader
|
char Signature[4] EXT_SIGNATURE;
|
||||||
{
|
uint32_t Version{ EXT_VERSION };
|
||||||
char Signature[4] EXT_SIGNATURE;
|
uint64_t Reserved{};
|
||||||
uint32_t Version{ EXT_VERSION };
|
bool DLCFlags[6]{};
|
||||||
uint32_t HeaderSize{ sizeof(ExtHeader) };
|
|
||||||
uint32_t Reserved;
|
|
||||||
};
|
|
||||||
|
|
||||||
ExtHeader Header;
|
|
||||||
bool DLCFlags[6];
|
|
||||||
|
|
||||||
bool VerifySignature() const;
|
bool VerifySignature() const;
|
||||||
bool VerifyVersion() const;
|
bool VerifyVersion() const;
|
||||||
bool VerifyHeader() const;
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,8 @@
|
||||||
|
|
||||||
bool PersistentStorageManager::ShouldDisplayDLCMessage(bool setOffendingDLCFlag)
|
bool PersistentStorageManager::ShouldDisplayDLCMessage(bool setOffendingDLCFlag)
|
||||||
{
|
{
|
||||||
auto result = false;
|
if (BinStatus != EExtBinStatus::Success)
|
||||||
|
return true;
|
||||||
if (BinStatus != EBinStatus::Success)
|
|
||||||
return result;
|
|
||||||
|
|
||||||
static std::unordered_map<EDLCFlag, DLC> flags =
|
static std::unordered_map<EDLCFlag, DLC> flags =
|
||||||
{
|
{
|
||||||
|
|
@ -20,6 +18,8 @@ bool PersistentStorageManager::ShouldDisplayDLCMessage(bool setOffendingDLCFlag)
|
||||||
{ EDLCFlag::EmpireCityAndAdabat, DLC::EmpireCityAdabat }
|
{ EDLCFlag::EmpireCityAndAdabat, DLC::EmpireCityAdabat }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
auto result = false;
|
||||||
|
|
||||||
for (auto& pair : flags)
|
for (auto& pair : flags)
|
||||||
{
|
{
|
||||||
if (!Data.DLCFlags[(int)pair.first] && Installer::checkDLCInstall(GetGamePath(), pair.second))
|
if (!Data.DLCFlags[(int)pair.first] && Installer::checkDLCInstall(GetGamePath(), pair.second))
|
||||||
|
|
@ -36,7 +36,7 @@ bool PersistentStorageManager::ShouldDisplayDLCMessage(bool setOffendingDLCFlag)
|
||||||
|
|
||||||
bool PersistentStorageManager::LoadBinary()
|
bool PersistentStorageManager::LoadBinary()
|
||||||
{
|
{
|
||||||
BinStatus = EBinStatus::Success;
|
BinStatus = EExtBinStatus::Success;
|
||||||
|
|
||||||
auto dataPath = GetDataPath(true);
|
auto dataPath = GetDataPath(true);
|
||||||
|
|
||||||
|
|
@ -46,7 +46,10 @@ bool PersistentStorageManager::LoadBinary()
|
||||||
dataPath = GetDataPath(false);
|
dataPath = GetDataPath(false);
|
||||||
|
|
||||||
if (!std::filesystem::exists(dataPath))
|
if (!std::filesystem::exists(dataPath))
|
||||||
|
{
|
||||||
|
BinStatus = EExtBinStatus::NoFile;
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
|
|
@ -55,7 +58,7 @@ bool PersistentStorageManager::LoadBinary()
|
||||||
|
|
||||||
if (fileSize != dataSize)
|
if (fileSize != dataSize)
|
||||||
{
|
{
|
||||||
BinStatus = EBinStatus::BadFileSize;
|
BinStatus = EExtBinStatus::BadFileSize;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -63,35 +66,26 @@ bool PersistentStorageManager::LoadBinary()
|
||||||
|
|
||||||
if (!file)
|
if (!file)
|
||||||
{
|
{
|
||||||
BinStatus = EBinStatus::IOError;
|
BinStatus = EExtBinStatus::IOError;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
PersistentData data{};
|
PersistentData data{};
|
||||||
|
|
||||||
file.read((char*)&data.Header.Signature, sizeof(data.Header.Signature));
|
file.read((char*)&data.Signature, sizeof(data.Signature));
|
||||||
|
|
||||||
if (!data.VerifySignature())
|
if (!data.VerifySignature())
|
||||||
{
|
{
|
||||||
BinStatus = EBinStatus::BadSignature;
|
BinStatus = EExtBinStatus::BadSignature;
|
||||||
file.close();
|
file.close();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
file.read((char*)&data.Header.Version, sizeof(data.Header.Version));
|
file.read((char*)&data.Version, sizeof(data.Version));
|
||||||
|
|
||||||
if (!data.VerifyVersion())
|
if (!data.VerifyVersion())
|
||||||
{
|
{
|
||||||
BinStatus = EBinStatus::BadVersion;
|
BinStatus = EExtBinStatus::BadVersion;
|
||||||
file.close();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
file.read((char*)&data.Header.HeaderSize, sizeof(data.Header.HeaderSize));
|
|
||||||
|
|
||||||
if (!data.VerifyHeader())
|
|
||||||
{
|
|
||||||
BinStatus = EBinStatus::BadHeader;
|
|
||||||
file.close();
|
file.close();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -120,7 +114,7 @@ bool PersistentStorageManager::SaveBinary()
|
||||||
file.write((const char*)&Data, sizeof(PersistentData));
|
file.write((const char*)&Data, sizeof(PersistentData));
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
BinStatus = EBinStatus::Success;
|
BinStatus = EExtBinStatus::Success;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,22 +2,22 @@
|
||||||
|
|
||||||
#include <user/persistent_data.h>
|
#include <user/persistent_data.h>
|
||||||
|
|
||||||
enum class EBinStatus
|
enum class EExtBinStatus
|
||||||
{
|
{
|
||||||
Unknown,
|
Unknown,
|
||||||
Success,
|
Success,
|
||||||
|
NoFile,
|
||||||
IOError,
|
IOError,
|
||||||
BadFileSize,
|
BadFileSize,
|
||||||
BadSignature,
|
BadSignature,
|
||||||
BadVersion,
|
BadVersion
|
||||||
BadHeader
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class PersistentStorageManager
|
class PersistentStorageManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static inline PersistentData Data{};
|
static inline PersistentData Data{};
|
||||||
static inline EBinStatus BinStatus{ EBinStatus::Unknown };
|
static inline EExtBinStatus BinStatus{ EExtBinStatus::Unknown };
|
||||||
|
|
||||||
static std::filesystem::path GetDataPath(bool checkForMods)
|
static std::filesystem::path GetDataPath(bool checkForMods)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue