mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2026-04-25 20:01:58 +00:00
Use uint32_t for version numbers
This commit is contained in:
parent
1fcb560fab
commit
3ad00fb5e3
10 changed files with 43 additions and 63 deletions
|
|
@ -213,7 +213,9 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
Config::Load();
|
||||
PersistentStorageManager::LoadBinary();
|
||||
|
||||
if (!PersistentStorageManager::LoadBinary())
|
||||
LOGFN_ERROR("Failed to load persistent storage binary... (status code {})", (int)PersistentStorageManager::BinStatus);
|
||||
|
||||
#if defined(_WIN32) && defined(UNLEASHED_RECOMP_D3D12)
|
||||
for (auto& dll : g_D3D12RequiredModules)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include <api/SWA.h>
|
||||
#include <install/update_checker.h>
|
||||
#include <locale/locale.h>
|
||||
#include <os/logger.h>
|
||||
#include <ui/fader.h>
|
||||
#include <ui/message_window.h>
|
||||
#include <user/achievement_manager.h>
|
||||
|
|
@ -135,7 +136,8 @@ void PressStartSaveLoadThreadMidAsmHook()
|
|||
g_faderBegun.wait(true);
|
||||
}
|
||||
|
||||
AchievementManager::Load();
|
||||
if (!AchievementManager::Load())
|
||||
LOGFN_ERROR("Failed to load achievement data... (status code {})", (int)AchievementManager::Status);
|
||||
|
||||
if (AchievementManager::Status != EAchStatus::Success)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ bool AchievementData::VerifySignature() const
|
|||
|
||||
bool AchievementData::VerifyVersion() const
|
||||
{
|
||||
return Version == AchVersion ACH_VERSION;
|
||||
return Version <= ACH_VERSION;
|
||||
}
|
||||
|
||||
bool AchievementData::VerifyChecksum()
|
||||
|
|
|
|||
|
|
@ -4,27 +4,12 @@
|
|||
|
||||
#define ACH_FILENAME "ACH-DATA"
|
||||
#define ACH_SIGNATURE { 'A', 'C', 'H', ' ' }
|
||||
#define ACH_VERSION { 1, 0, 0 }
|
||||
#define ACH_VERSION 1
|
||||
#define ACH_RECORDS 50
|
||||
|
||||
class AchievementData
|
||||
{
|
||||
public:
|
||||
struct AchVersion
|
||||
{
|
||||
uint8_t Major;
|
||||
uint8_t Minor;
|
||||
uint8_t Revision;
|
||||
uint8_t Reserved;
|
||||
|
||||
bool operator==(const AchVersion& other) const
|
||||
{
|
||||
return Major == other.Major &&
|
||||
Minor == other.Minor &&
|
||||
Revision == other.Revision;
|
||||
}
|
||||
};
|
||||
|
||||
#pragma pack(push, 1)
|
||||
struct AchRecord
|
||||
{
|
||||
|
|
@ -35,7 +20,7 @@ public:
|
|||
#pragma pack(pop)
|
||||
|
||||
char Signature[4] ACH_SIGNATURE;
|
||||
AchVersion Version ACH_VERSION;
|
||||
uint32_t Version{ ACH_VERSION };
|
||||
uint32_t Checksum;
|
||||
uint32_t Reserved;
|
||||
AchRecord Records[ACH_RECORDS];
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ void AchievementManager::Reset()
|
|||
Data = {};
|
||||
}
|
||||
|
||||
void AchievementManager::Load()
|
||||
bool AchievementManager::Load()
|
||||
{
|
||||
AchievementManager::Reset();
|
||||
|
||||
|
|
@ -100,7 +100,7 @@ void AchievementManager::Load()
|
|||
dataPath = GetDataPath(false);
|
||||
|
||||
if (!std::filesystem::exists(dataPath))
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::error_code ec;
|
||||
|
|
@ -110,7 +110,7 @@ void AchievementManager::Load()
|
|||
if (fileSize != dataSize)
|
||||
{
|
||||
Status = EAchStatus::BadFileSize;
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::ifstream file(dataPath, std::ios::binary);
|
||||
|
|
@ -118,7 +118,7 @@ void AchievementManager::Load()
|
|||
if (!file)
|
||||
{
|
||||
Status = EAchStatus::IOError;
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
AchievementData data{};
|
||||
|
|
@ -129,17 +129,16 @@ void AchievementManager::Load()
|
|||
{
|
||||
Status = EAchStatus::BadSignature;
|
||||
file.close();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
file.read((char*)&data.Version, sizeof(data.Version));
|
||||
|
||||
// TODO: upgrade in future if the version changes.
|
||||
if (!data.VerifyVersion())
|
||||
{
|
||||
Status = EAchStatus::BadVersion;
|
||||
file.close();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
file.seekg(0);
|
||||
|
|
@ -149,20 +148,22 @@ void AchievementManager::Load()
|
|||
{
|
||||
Status = EAchStatus::BadChecksum;
|
||||
file.close();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
memcpy(&Data, &data, dataSize);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void AchievementManager::Save(bool ignoreStatus)
|
||||
bool AchievementManager::Save(bool ignoreStatus)
|
||||
{
|
||||
if (!ignoreStatus && Status != EAchStatus::Success)
|
||||
{
|
||||
LOGN_WARNING("Achievement data will not be saved in this session!");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
LOGN("Saving achievements...");
|
||||
|
|
@ -172,7 +173,7 @@ void AchievementManager::Save(bool ignoreStatus)
|
|||
if (!file)
|
||||
{
|
||||
LOGN_ERROR("Failed to write achievement data.");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
Data.Checksum = Data.CalculateChecksum();
|
||||
|
|
@ -181,4 +182,6 @@ void AchievementManager::Save(bool ignoreStatus)
|
|||
file.close();
|
||||
|
||||
Status = EAchStatus::Success;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,6 @@ public:
|
|||
static void Unlock(uint16_t id);
|
||||
static void UnlockAll();
|
||||
static void Reset();
|
||||
static void Load();
|
||||
static void Save(bool ignoreStatus = false);
|
||||
static bool Load();
|
||||
static bool Save(bool ignoreStatus = false);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ bool PersistentData::VerifySignature() const
|
|||
|
||||
bool PersistentData::VerifyVersion() const
|
||||
{
|
||||
return Header.Version == ExtVersion EXT_VERSION;
|
||||
return Header.Version <= EXT_VERSION;
|
||||
}
|
||||
|
||||
bool PersistentData::VerifyHeader() const
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#define EXT_FILENAME "EXT-DATA"
|
||||
#define EXT_SIGNATURE { 'E', 'X', 'T', ' ' }
|
||||
#define EXT_VERSION { 1, 0, 0 }
|
||||
#define EXT_VERSION 1
|
||||
|
||||
enum class EDLCFlag
|
||||
{
|
||||
|
|
@ -20,25 +20,10 @@ enum class EDLCFlag
|
|||
class PersistentData
|
||||
{
|
||||
public:
|
||||
struct ExtVersion
|
||||
{
|
||||
uint8_t Major;
|
||||
uint8_t Minor;
|
||||
uint8_t Revision;
|
||||
uint8_t Reserved;
|
||||
|
||||
bool operator==(const ExtVersion& other) const
|
||||
{
|
||||
return Major == other.Major &&
|
||||
Minor == other.Minor &&
|
||||
Revision == other.Revision;
|
||||
}
|
||||
};
|
||||
|
||||
struct ExtHeader
|
||||
{
|
||||
char Signature[4] EXT_SIGNATURE;
|
||||
ExtVersion Version EXT_VERSION;
|
||||
uint32_t Version{ EXT_VERSION };
|
||||
uint32_t HeaderSize{ sizeof(ExtHeader) };
|
||||
uint32_t Reserved;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ bool PersistentStorageManager::ShouldDisplayDLCMessage(bool setOffendingDLCFlag)
|
|||
return result;
|
||||
}
|
||||
|
||||
void PersistentStorageManager::LoadBinary()
|
||||
bool PersistentStorageManager::LoadBinary()
|
||||
{
|
||||
BinStatus = EBinStatus::Success;
|
||||
|
||||
|
|
@ -46,7 +46,7 @@ void PersistentStorageManager::LoadBinary()
|
|||
dataPath = GetDataPath(false);
|
||||
|
||||
if (!std::filesystem::exists(dataPath))
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::error_code ec;
|
||||
|
|
@ -56,7 +56,7 @@ void PersistentStorageManager::LoadBinary()
|
|||
if (fileSize != dataSize)
|
||||
{
|
||||
BinStatus = EBinStatus::BadFileSize;
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::ifstream file(dataPath, std::ios::binary);
|
||||
|
|
@ -64,7 +64,7 @@ void PersistentStorageManager::LoadBinary()
|
|||
if (!file)
|
||||
{
|
||||
BinStatus = EBinStatus::IOError;
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
PersistentData data{};
|
||||
|
|
@ -75,17 +75,16 @@ void PersistentStorageManager::LoadBinary()
|
|||
{
|
||||
BinStatus = EBinStatus::BadSignature;
|
||||
file.close();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
file.read((char*)&data.Header.Version, sizeof(data.Header.Version));
|
||||
|
||||
// TODO: upgrade in future if the version changes.
|
||||
if (!data.VerifyVersion())
|
||||
{
|
||||
BinStatus = EBinStatus::BadVersion;
|
||||
file.close();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
file.read((char*)&data.Header.HeaderSize, sizeof(data.Header.HeaderSize));
|
||||
|
|
@ -94,7 +93,7 @@ void PersistentStorageManager::LoadBinary()
|
|||
{
|
||||
BinStatus = EBinStatus::BadHeader;
|
||||
file.close();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
file.seekg(0);
|
||||
|
|
@ -102,9 +101,11 @@ void PersistentStorageManager::LoadBinary()
|
|||
file.close();
|
||||
|
||||
memcpy(&Data, &data, dataSize);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void PersistentStorageManager::SaveBinary()
|
||||
bool PersistentStorageManager::SaveBinary()
|
||||
{
|
||||
LOGN("Saving persistent storage binary...");
|
||||
|
||||
|
|
@ -113,11 +114,13 @@ void PersistentStorageManager::SaveBinary()
|
|||
if (!file)
|
||||
{
|
||||
LOGN_ERROR("Failed to write persistent storage binary.");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
file.write((const char*)&Data, sizeof(PersistentData));
|
||||
file.close();
|
||||
|
||||
BinStatus = EBinStatus::Success;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,6 @@ public:
|
|||
}
|
||||
|
||||
static bool ShouldDisplayDLCMessage(bool setOffendingDLCFlag);
|
||||
static void LoadBinary();
|
||||
static void SaveBinary();
|
||||
static bool LoadBinary();
|
||||
static bool SaveBinary();
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue