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