diff --git a/src/Components/Modules/StructuredData.cpp b/src/Components/Modules/StructuredData.cpp index 3b1ddec1..b883d4ef 100644 --- a/src/Components/Modules/StructuredData.cpp +++ b/src/Components/Modules/StructuredData.cpp @@ -116,8 +116,39 @@ namespace Components } } + bool StructuredData::UpdateVersionOffsets(Game::StructuredDataDefSet *set, Game::StructuredDataBuffer *buffer, Game::StructuredDataDef *whatever) + { + Game::StructuredDataDef* newDef = &set->defs[0]; + Game::StructuredDataDef* oldDef = &set->defs[0]; + + for(unsigned int i = 0; i < set->defCount; ++i) + { + if(newDef->version < set->defs[i].version) + { + newDef = &set->defs[i]; + } + + if(set->defs[i].version == *reinterpret_cast(buffer->data)) + { + oldDef = &set->defs[i]; + } + } + + if (newDef->version >= 159 && oldDef->version <= 158) + { + // this should move the data 320 bytes infront + std::memmove(&buffer->data[3963], &buffer->data[3643], oldDef->size - 3643); + } + + // StructuredData_UpdateVersion + return Utils::Hook::Call(0x456830)(set, buffer, whatever); + } + StructuredData::StructuredData() { + // Correctly upgrade stats + Utils::Hook(0x42F088, StructuredData::UpdateVersionOffsets, HOOK_CALL).install()->quick(); + // 15 or more custom classes Utils::Hook::Set(0x60A2FE, NUM_CUSTOM_CLASSES); @@ -127,7 +158,7 @@ namespace Components AssetHandler::OnLoad([] (Game::XAssetType type, Game::XAssetHeader asset, std::string filename, bool* /*restrict*/) { // Only intercept playerdatadef loading - if (filename != "mp/playerdata.def" || type != Game::XAssetType::ASSET_TYPE_STRUCTUREDDATADEF) return; + if (type != Game::XAssetType::ASSET_TYPE_STRUCTUREDDATADEF || filename != "mp/playerdata.def") return; // Store asset Game::StructuredDataDefSet* data = asset.structuredData; diff --git a/src/Components/Modules/StructuredData.hpp b/src/Components/Modules/StructuredData.hpp index 1cc39833..41bfd714 100644 --- a/src/Components/Modules/StructuredData.hpp +++ b/src/Components/Modules/StructuredData.hpp @@ -31,6 +31,8 @@ namespace Components #endif private: + static bool UpdateVersionOffsets(Game::StructuredDataDefSet *set, Game::StructuredDataBuffer *buffer, Game::StructuredDataDef *oldDef); + static void PatchPlayerDataEnum(Game::StructuredDataDef* data, PlayerDataType type, std::vector& entries); static void PatchAdditionalData(Game::StructuredDataDef* data, std::unordered_map& patches); diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index c8d6e5b9..87450fa4 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -1554,6 +1554,12 @@ namespace Game StructuredDataDef *defs; }; + struct StructuredDataBuffer + { + char *data; + size_t size; // 8188 + }; + typedef struct { StructuredDataDef* data;