mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2025-04-28 13:27:58 +03: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)
|
||||
return false;
|
||||
|
||||
auto message = AchievementManager::BinStatus == EAchStatus::IOError
|
||||
auto message = AchievementManager::BinStatus == EAchBinStatus::IOError
|
||||
? Localise("Title_Message_AchievementDataIOError")
|
||||
: 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.
|
||||
// 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);
|
||||
|
||||
g_corruptAchievementsMessageOpen = false;
|
||||
|
@ -139,7 +139,7 @@ void PressStartSaveLoadThreadMidAsmHook()
|
|||
if (!AchievementManager::LoadBinary())
|
||||
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.wait(true);
|
||||
|
|
|
@ -21,9 +21,9 @@ public:
|
|||
|
||||
char Signature[4] ACH_SIGNATURE;
|
||||
uint32_t Version{ ACH_VERSION };
|
||||
uint32_t Checksum;
|
||||
uint32_t Reserved;
|
||||
AchRecord Records[ACH_RECORDS];
|
||||
uint32_t Checksum{};
|
||||
uint32_t Reserved{};
|
||||
AchRecord Records[ACH_RECORDS]{};
|
||||
|
||||
bool VerifySignature() const;
|
||||
bool VerifyVersion() const;
|
||||
|
|
|
@ -90,7 +90,7 @@ bool AchievementManager::LoadBinary()
|
|||
{
|
||||
AchievementManager::Reset();
|
||||
|
||||
BinStatus = EAchStatus::Success;
|
||||
BinStatus = EAchBinStatus::Success;
|
||||
|
||||
auto dataPath = GetDataPath(true);
|
||||
|
||||
|
@ -100,7 +100,10 @@ bool AchievementManager::LoadBinary()
|
|||
dataPath = GetDataPath(false);
|
||||
|
||||
if (!std::filesystem::exists(dataPath))
|
||||
{
|
||||
BinStatus = EAchBinStatus::NoFile;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
std::error_code ec;
|
||||
|
@ -109,7 +112,7 @@ bool AchievementManager::LoadBinary()
|
|||
|
||||
if (fileSize != dataSize)
|
||||
{
|
||||
BinStatus = EAchStatus::BadFileSize;
|
||||
BinStatus = EAchBinStatus::BadFileSize;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -117,7 +120,7 @@ bool AchievementManager::LoadBinary()
|
|||
|
||||
if (!file)
|
||||
{
|
||||
BinStatus = EAchStatus::IOError;
|
||||
BinStatus = EAchBinStatus::IOError;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -127,7 +130,7 @@ bool AchievementManager::LoadBinary()
|
|||
|
||||
if (!data.VerifySignature())
|
||||
{
|
||||
BinStatus = EAchStatus::BadSignature;
|
||||
BinStatus = EAchBinStatus::BadSignature;
|
||||
file.close();
|
||||
return false;
|
||||
}
|
||||
|
@ -136,7 +139,7 @@ bool AchievementManager::LoadBinary()
|
|||
|
||||
if (!data.VerifyVersion())
|
||||
{
|
||||
BinStatus = EAchStatus::BadVersion;
|
||||
BinStatus = EAchBinStatus::BadVersion;
|
||||
file.close();
|
||||
return false;
|
||||
}
|
||||
|
@ -146,7 +149,7 @@ bool AchievementManager::LoadBinary()
|
|||
|
||||
if (!data.VerifyChecksum())
|
||||
{
|
||||
BinStatus = EAchStatus::BadChecksum;
|
||||
BinStatus = EAchBinStatus::BadChecksum;
|
||||
file.close();
|
||||
return false;
|
||||
}
|
||||
|
@ -160,7 +163,7 @@ bool AchievementManager::LoadBinary()
|
|||
|
||||
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!");
|
||||
return false;
|
||||
|
@ -181,7 +184,7 @@ bool AchievementManager::SaveBinary(bool ignoreStatus)
|
|||
file.write((const char*)&Data, sizeof(AchievementData));
|
||||
file.close();
|
||||
|
||||
BinStatus = EAchStatus::Success;
|
||||
BinStatus = EAchBinStatus::Success;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -2,10 +2,11 @@
|
|||
|
||||
#include <user/achievement_data.h>
|
||||
|
||||
enum class EAchStatus
|
||||
enum class EAchBinStatus
|
||||
{
|
||||
Unknown,
|
||||
Success,
|
||||
NoFile,
|
||||
IOError,
|
||||
BadFileSize,
|
||||
BadSignature,
|
||||
|
@ -17,7 +18,7 @@ class AchievementManager
|
|||
{
|
||||
public:
|
||||
static inline AchievementData Data{};
|
||||
static inline EAchStatus BinStatus{ EAchStatus::Unknown };
|
||||
static inline EAchBinStatus BinStatus{ EAchBinStatus::Unknown };
|
||||
|
||||
static std::filesystem::path GetDataPath(bool checkForMods)
|
||||
{
|
||||
|
|
|
@ -4,15 +4,10 @@ bool PersistentData::VerifySignature() const
|
|||
{
|
||||
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
|
||||
{
|
||||
return Header.Version <= EXT_VERSION;
|
||||
}
|
||||
|
||||
bool PersistentData::VerifyHeader() const
|
||||
{
|
||||
return Header.HeaderSize == sizeof(ExtHeader);
|
||||
return Version <= EXT_VERSION;
|
||||
}
|
||||
|
|
|
@ -20,18 +20,11 @@ enum class EDLCFlag
|
|||
class PersistentData
|
||||
{
|
||||
public:
|
||||
struct ExtHeader
|
||||
{
|
||||
char Signature[4] EXT_SIGNATURE;
|
||||
uint32_t Version{ EXT_VERSION };
|
||||
uint32_t HeaderSize{ sizeof(ExtHeader) };
|
||||
uint32_t Reserved;
|
||||
};
|
||||
|
||||
ExtHeader Header;
|
||||
bool DLCFlags[6];
|
||||
char Signature[4] EXT_SIGNATURE;
|
||||
uint32_t Version{ EXT_VERSION };
|
||||
uint64_t Reserved{};
|
||||
bool DLCFlags[6]{};
|
||||
|
||||
bool VerifySignature() const;
|
||||
bool VerifyVersion() const;
|
||||
bool VerifyHeader() const;
|
||||
};
|
||||
|
|
|
@ -5,10 +5,8 @@
|
|||
|
||||
bool PersistentStorageManager::ShouldDisplayDLCMessage(bool setOffendingDLCFlag)
|
||||
{
|
||||
auto result = false;
|
||||
|
||||
if (BinStatus != EBinStatus::Success)
|
||||
return result;
|
||||
if (BinStatus != EExtBinStatus::Success)
|
||||
return true;
|
||||
|
||||
static std::unordered_map<EDLCFlag, DLC> flags =
|
||||
{
|
||||
|
@ -20,6 +18,8 @@ bool PersistentStorageManager::ShouldDisplayDLCMessage(bool setOffendingDLCFlag)
|
|||
{ EDLCFlag::EmpireCityAndAdabat, DLC::EmpireCityAdabat }
|
||||
};
|
||||
|
||||
auto result = false;
|
||||
|
||||
for (auto& pair : flags)
|
||||
{
|
||||
if (!Data.DLCFlags[(int)pair.first] && Installer::checkDLCInstall(GetGamePath(), pair.second))
|
||||
|
@ -36,7 +36,7 @@ bool PersistentStorageManager::ShouldDisplayDLCMessage(bool setOffendingDLCFlag)
|
|||
|
||||
bool PersistentStorageManager::LoadBinary()
|
||||
{
|
||||
BinStatus = EBinStatus::Success;
|
||||
BinStatus = EExtBinStatus::Success;
|
||||
|
||||
auto dataPath = GetDataPath(true);
|
||||
|
||||
|
@ -46,7 +46,10 @@ bool PersistentStorageManager::LoadBinary()
|
|||
dataPath = GetDataPath(false);
|
||||
|
||||
if (!std::filesystem::exists(dataPath))
|
||||
{
|
||||
BinStatus = EExtBinStatus::NoFile;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
std::error_code ec;
|
||||
|
@ -55,7 +58,7 @@ bool PersistentStorageManager::LoadBinary()
|
|||
|
||||
if (fileSize != dataSize)
|
||||
{
|
||||
BinStatus = EBinStatus::BadFileSize;
|
||||
BinStatus = EExtBinStatus::BadFileSize;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -63,35 +66,26 @@ bool PersistentStorageManager::LoadBinary()
|
|||
|
||||
if (!file)
|
||||
{
|
||||
BinStatus = EBinStatus::IOError;
|
||||
BinStatus = EExtBinStatus::IOError;
|
||||
return false;
|
||||
}
|
||||
|
||||
PersistentData data{};
|
||||
|
||||
file.read((char*)&data.Header.Signature, sizeof(data.Header.Signature));
|
||||
file.read((char*)&data.Signature, sizeof(data.Signature));
|
||||
|
||||
if (!data.VerifySignature())
|
||||
{
|
||||
BinStatus = EBinStatus::BadSignature;
|
||||
BinStatus = EExtBinStatus::BadSignature;
|
||||
file.close();
|
||||
return false;
|
||||
}
|
||||
|
||||
file.read((char*)&data.Header.Version, sizeof(data.Header.Version));
|
||||
file.read((char*)&data.Version, sizeof(data.Version));
|
||||
|
||||
if (!data.VerifyVersion())
|
||||
{
|
||||
BinStatus = EBinStatus::BadVersion;
|
||||
file.close();
|
||||
return false;
|
||||
}
|
||||
|
||||
file.read((char*)&data.Header.HeaderSize, sizeof(data.Header.HeaderSize));
|
||||
|
||||
if (!data.VerifyHeader())
|
||||
{
|
||||
BinStatus = EBinStatus::BadHeader;
|
||||
BinStatus = EExtBinStatus::BadVersion;
|
||||
file.close();
|
||||
return false;
|
||||
}
|
||||
|
@ -120,7 +114,7 @@ bool PersistentStorageManager::SaveBinary()
|
|||
file.write((const char*)&Data, sizeof(PersistentData));
|
||||
file.close();
|
||||
|
||||
BinStatus = EBinStatus::Success;
|
||||
BinStatus = EExtBinStatus::Success;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -2,22 +2,22 @@
|
|||
|
||||
#include <user/persistent_data.h>
|
||||
|
||||
enum class EBinStatus
|
||||
enum class EExtBinStatus
|
||||
{
|
||||
Unknown,
|
||||
Success,
|
||||
NoFile,
|
||||
IOError,
|
||||
BadFileSize,
|
||||
BadSignature,
|
||||
BadVersion,
|
||||
BadHeader
|
||||
BadVersion
|
||||
};
|
||||
|
||||
class PersistentStorageManager
|
||||
{
|
||||
public:
|
||||
static inline PersistentData Data{};
|
||||
static inline EBinStatus BinStatus{ EBinStatus::Unknown };
|
||||
static inline EExtBinStatus BinStatus{ EExtBinStatus::Unknown };
|
||||
|
||||
static std::filesystem::path GetDataPath(bool checkForMods)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue