From 1084d8e1324d83ccb66636e5498b5db71cf8b055 Mon Sep 17 00:00:00 2001 From: William JCM Date: Fri, 30 Jul 2021 15:23:19 +0200 Subject: [PATCH] Profile: add support for reading OS unlocks. --- src/Profile/Profile.cpp | 52 +++++++++++++++++++++++++++++++++++++++++ src/Profile/Profile.h | 4 ++++ 2 files changed, 56 insertions(+) diff --git a/src/Profile/Profile.cpp b/src/Profile/Profile.cpp index 045d19b..b1e562b 100644 --- a/src/Profile/Profile.cpp +++ b/src/Profile/Profile.cpp @@ -111,6 +111,7 @@ void Profile::refreshValues() { getCarbonizedSkin(); getEngineUnlocks(); + getOsUnlocks(); } auto Profile::companyName() const -> std::string const& { @@ -1054,3 +1055,54 @@ void Profile::getEngineUnlocks() { _lastError = "The profile save seems to be corrupted or the game didn't release the handle on the file."; } } + +auto Profile::osInventory() -> Containers::ArrayView { + return _osInventory; +} + +auto Profile::moduleInventory() -> Containers::ArrayView { + return _moduleInventory; +} + +void Profile::getOsUnlocks() { + auto mmap = Utility::Directory::map(Utility::Directory::join(_profileDirectory, _filename)); + + auto iter = std::search(mmap.begin(), mmap.end(), &os_inventory_locator[0], &os_inventory_locator[29]); + + if(iter != mmap.end()) { + Int* int_iter = reinterpret_cast(iter + 0x37); + Int size = *(int_iter++); + + if(size > 0) { + _osInventory = Containers::Array{DefaultInit, std::size_t(size)}; + std::copy_n(int_iter, size, _osInventory.data()); + + Utility::Debug{} << "_osInventory:" << _osInventory; + + iter = std::search(mmap.begin(), mmap.end(), &module_inventory_locator[0], &module_inventory_locator[33]); + + if(iter == mmap.end()) { + return; + } + + int_iter = reinterpret_cast(iter + 0x3B); + size = *(int_iter++); + + if(size <= 0) { + return; + } + + _moduleInventory = Containers::Array{DefaultInit, std::size_t(size)}; + std::copy_n(int_iter, size, _moduleInventory.data()); + + Utility::Debug{} << "_moduleInventory:" << _moduleInventory; + } + else { + _lastError = "An array can't have a null or negative size."; + Utility::Fatal{EXIT_FAILURE} << _lastError.c_str(); + } + } + else { + _lastError = "The profile save seems to be corrupted or the game didn't release the handle on the file."; + } +} diff --git a/src/Profile/Profile.h b/src/Profile/Profile.h index b2c4cff..6f16116 100644 --- a/src/Profile/Profile.h +++ b/src/Profile/Profile.h @@ -147,6 +147,10 @@ class Profile { auto gearInventory() -> Containers::ArrayView; void getEngineUnlocks(); + auto osInventory() -> Containers::ArrayView; + auto moduleInventory() -> Containers::ArrayView; + void getOsUnlocks(); + private: std::string _profileDirectory; std::string _filename;