From 2886928f0b69bc245dd365b9d3d65ce7a47ab6a6 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Fri, 4 Mar 2016 17:02:00 +0100 Subject: [PATCH] Structureddata stuff in fastfiles --- src/Components/Modules/AntiCheat.cpp | 2 +- src/Components/Modules/AssetHandler.cpp | 1 + src/Components/Modules/AssetHandler.hpp | 1 + .../AssetInterfaces/IStructuredDataDefSet.cpp | 151 ++++++++++++++++++ .../AssetInterfaces/IStructuredDataDefSet.hpp | 13 ++ src/Components/Modules/Command.cpp | 26 +-- src/Components/Modules/FastFiles.cpp | 22 ++- src/Components/Modules/FastFiles.hpp | 3 +- src/Components/Modules/Maps.cpp | 2 +- src/Components/Modules/StructuredData.cpp | 23 +-- src/Components/Modules/StructuredData.hpp | 2 - 11 files changed, 196 insertions(+), 50 deletions(-) create mode 100644 src/Components/Modules/AssetInterfaces/IStructuredDataDefSet.cpp create mode 100644 src/Components/Modules/AssetInterfaces/IStructuredDataDefSet.hpp diff --git a/src/Components/Modules/AntiCheat.cpp b/src/Components/Modules/AntiCheat.cpp index 446d66d8..f319b244 100644 --- a/src/Components/Modules/AntiCheat.cpp +++ b/src/Components/Modules/AntiCheat.cpp @@ -133,7 +133,6 @@ namespace Components AntiCheat::AntiCheat() { AntiCheat::EmptyHash(); - QuickPatch::OnFrame(AntiCheat::Frame); #ifdef DEBUG Command::Add("penis", [] (Command::Params) @@ -141,6 +140,7 @@ namespace Components AntiCheat::CrashClient(); }); #else + QuickPatch::OnFrame(AntiCheat::Frame); QuickPatch::Once(AntiCheat::PatchWinAPI); #endif } diff --git a/src/Components/Modules/AssetHandler.cpp b/src/Components/Modules/AssetHandler.cpp index 06094078..390ebcc3 100644 --- a/src/Components/Modules/AssetHandler.cpp +++ b/src/Components/Modules/AssetHandler.cpp @@ -262,6 +262,7 @@ namespace Components AssetHandler::RegisterInterface(new Assets::IMaterialPixelShader()); AssetHandler::RegisterInterface(new Assets::IMaterialTechniqueSet()); AssetHandler::RegisterInterface(new Assets::IMaterialVertexShader()); + AssetHandler::RegisterInterface(new Assets::IStructuredDataDefSet()); AssetHandler::RegisterInterface(new Assets::IMaterialVertexDeclaration()); } diff --git a/src/Components/Modules/AssetHandler.hpp b/src/Components/Modules/AssetHandler.hpp index 469316ec..3be2d78c 100644 --- a/src/Components/Modules/AssetHandler.hpp +++ b/src/Components/Modules/AssetHandler.hpp @@ -68,4 +68,5 @@ namespace Components #include "AssetInterfaces\IMaterialPixelShader.hpp" #include "AssetInterfaces\IMaterialTechniqueSet.hpp" #include "AssetInterfaces\IMaterialVertexShader.hpp" +#include "AssetInterfaces\IStructuredDataDefSet.hpp" #include "AssetInterfaces\IMaterialVertexDeclaration.hpp" diff --git a/src/Components/Modules/AssetInterfaces/IStructuredDataDefSet.cpp b/src/Components/Modules/AssetInterfaces/IStructuredDataDefSet.cpp new file mode 100644 index 00000000..809c2483 --- /dev/null +++ b/src/Components/Modules/AssetInterfaces/IStructuredDataDefSet.cpp @@ -0,0 +1,151 @@ +#include + +namespace Assets +{ + void IStructuredDataDefSet::Save_StructuredDataEnumArray(Game::StructuredDataEnum* enums, int numEnums, Components::ZoneBuilder::Zone* builder) + { + Utils::Stream* buffer = builder->GetBuffer(); + + Game::StructuredDataEnum* destEnums = buffer->Dest(); + buffer->SaveArray(enums, numEnums); + + for (int i = 0; i < numEnums; ++i) + { + Game::StructuredDataEnum* destEnum = &destEnums[i]; + Game::StructuredDataEnum* enum_ = &enums[i]; + + if (enum_->indices) + { + Assert_Size(Game::StructuredDataEnumEntry, 8); + buffer->Align(Utils::Stream::ALIGN_4); + + Game::StructuredDataEnumEntry* destIndices = buffer->Dest(); + buffer->SaveArray(enum_->indices, enum_->numIndices); + + for (int j = 0; j < enum_->numIndices; ++j) + { + Game::StructuredDataEnumEntry* destIndex = &destIndices[j]; + Game::StructuredDataEnumEntry* index = &enum_->indices[j]; + + if (index->key) + { + buffer->SaveString(index->key); + destIndex->key = reinterpret_cast(-1); + } + } + + destEnum->indices = reinterpret_cast(-1); + } + } + } + + void IStructuredDataDefSet::Save_StructuredDataStructArray(Game::StructuredDataStruct* structs, int numStructs, Components::ZoneBuilder::Zone* builder) + { + Utils::Stream* buffer = builder->GetBuffer(); + + Game::StructuredDataStruct* destStructs = buffer->Dest(); + buffer->SaveArray(structs, numStructs); + + for (int i = 0; i < numStructs; ++i) + { + Game::StructuredDataStruct* destStruct = &destStructs[i]; + Game::StructuredDataStruct* struct_ = &structs[i]; + + if (struct_->property) + { + Assert_Size(Game::StructuredDataStructProperty, 16); + buffer->Align(Utils::Stream::ALIGN_4); + + Game::StructuredDataStructProperty* destProperties = buffer->Dest(); + buffer->SaveArray(struct_->property, struct_->numProperties); + + for (int j = 0; j < struct_->numProperties; ++j) + { + Game::StructuredDataStructProperty* destProperty = &destProperties[j]; + Game::StructuredDataStructProperty* property = &struct_->property[j]; + + if (property->name) + { + buffer->SaveString(property->name); + destProperty->name = reinterpret_cast(-1); + } + } + + destStruct->property = reinterpret_cast(-1); + } + } + } + + void IStructuredDataDefSet::Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) + { + Assert_Size(Game::StructuredDataDefSet, 12); + + Utils::Stream* buffer = builder->GetBuffer(); + Game::StructuredDataDefSet* asset = header.structuredData; + Game::StructuredDataDefSet* dest = buffer->Dest(); + buffer->Save(asset, sizeof(Game::StructuredDataDefSet)); + + buffer->PushBlock(Game::XFILE_BLOCK_VIRTUAL); + + if (asset->name) + { + buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name)); + dest->name = reinterpret_cast(-1); + } + + if (asset->data) + { + Assert_Size(Game::StructuredDataDef, 52); + buffer->Align(Utils::Stream::ALIGN_4); + + Game::StructuredDataDef* destDataArray = buffer->Dest(); + buffer->SaveArray(asset->data, asset->count); + + for (int i = 0; i < asset->count; ++i) + { + Game::StructuredDataDef* destData = &destDataArray[i]; + Game::StructuredDataDef* data = &asset->data[i]; + + if (data->enums) + { + Assert_Size(Game::StructuredDataEnum, 12); + buffer->Align(Utils::Stream::ALIGN_4); + + IStructuredDataDefSet::Save_StructuredDataEnumArray(data->enums, data->numEnums, builder); + destData->enums = reinterpret_cast(-1); + } + + if (data->structs) + { + Assert_Size(Game::StructuredDataStruct, 16); + buffer->Align(Utils::Stream::ALIGN_4); + + IStructuredDataDefSet::Save_StructuredDataStructArray(data->structs, data->numStructs, builder); + destData->structs = reinterpret_cast(-1); + } + + if (data->indexedArrays) + { + Assert_Size(Game::StructuredDataIndexedArray, 16); + buffer->Align(Utils::Stream::ALIGN_4); + + buffer->SaveArray(data->indexedArrays, data->numIndexedArrays); + destData->indexedArrays = reinterpret_cast(-1); + } + + if (data->enumArrays) + { + Assert_Size(Game::StructuredDataEnumedArray, 16); + buffer->Align(Utils::Stream::ALIGN_4); + + buffer->SaveArray(data->enumArrays, data->numEnumArrays); + destData->enumArrays = reinterpret_cast(-1); + } + } + + dest->data = reinterpret_cast(-1); + } + + buffer->PopBlock(); + } +} diff --git a/src/Components/Modules/AssetInterfaces/IStructuredDataDefSet.hpp b/src/Components/Modules/AssetInterfaces/IStructuredDataDefSet.hpp new file mode 100644 index 00000000..307da3e8 --- /dev/null +++ b/src/Components/Modules/AssetInterfaces/IStructuredDataDefSet.hpp @@ -0,0 +1,13 @@ +namespace Assets +{ + class IStructuredDataDefSet : public Components::AssetHandler::IAsset + { + public: + virtual Game::XAssetType GetType() override { return Game::XAssetType::ASSET_TYPE_STRUCTUREDDATADEF; }; + + virtual void Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override; + + void Save_StructuredDataEnumArray(Game::StructuredDataEnum* enums, int numEnums, Components::ZoneBuilder::Zone* builder); + void Save_StructuredDataStructArray(Game::StructuredDataStruct* structs, int numStructs, Components::ZoneBuilder::Zone* builder); + }; +} \ No newline at end of file diff --git a/src/Components/Modules/Command.cpp b/src/Components/Modules/Command.cpp index 41792bbc..3670db89 100644 --- a/src/Components/Modules/Command.cpp +++ b/src/Components/Modules/Command.cpp @@ -8,31 +8,15 @@ namespace Components char* Command::Params::operator[](size_t index) { - if (index >= this->Length()) - { - return ""; - } - - if (this->IsSV) - { - return Game::cmd_argv_sv[this->CommandId][index]; - } - else - { - return Game::cmd_argv[this->CommandId][index]; - } + if (index >= this->Length()) return ""; + if (this->IsSV) return Game::cmd_argv_sv[this->CommandId][index]; + else return Game::cmd_argv[this->CommandId][index]; } size_t Command::Params::Length() { - if (this->IsSV) - { - return Game::cmd_argc_sv[this->CommandId]; - } - else - { - return Game::cmd_argc[this->CommandId]; - } + if (this->IsSV) return Game::cmd_argc_sv[this->CommandId]; + else return Game::cmd_argc[this->CommandId]; } std::string Command::Params::Join(size_t startIndex) diff --git a/src/Components/Modules/FastFiles.cpp b/src/Components/Modules/FastFiles.cpp index c736ca54..0c1c61b3 100644 --- a/src/Components/Modules/FastFiles.cpp +++ b/src/Components/Modules/FastFiles.cpp @@ -16,9 +16,9 @@ namespace Components } // Load custom weapons, if present (force that later on) - if (FastFiles::Exists("weapons_mp")) + if (FastFiles::Exists("weapons_iw4x_mp")) { - data.push_back({ "weapons_mp", 1, 0 }); + data.push_back({ "weapons_iw4x_mp", 1, 0 }); } return FastFiles::LoadDLCUIZones(data.data(), data.size(), sync); @@ -33,9 +33,9 @@ namespace Components Game::XZoneInfo info = { nullptr, 2, 0 }; // Custom ui stuff - if (FastFiles::Exists("iw4x_ui_mp")) + if (FastFiles::Exists("ui_iw4x_mp")) { - info.name = "iw4x_ui_mp"; + info.name = "ui_iw4x_mp"; data.push_back(info); } else // Fallback @@ -50,6 +50,19 @@ namespace Components return FastFiles::LoadLocalizeZones(data.data(), data.size(), sync); } + void FastFiles::LoadGfxZones(Game::XZoneInfo *zoneInfo, unsigned int zoneCount, int sync) + { + std::vector data; + Utils::Merge(&data, zoneInfo, zoneCount); + + if (FastFiles::Exists("code_post_gfx_iw4x_mp")) + { + data.push_back({ "code_post_gfx_iw4x_mp", zoneInfo->allocFlags, zoneInfo->freeFlags }); + } + + Game::DB_LoadXAssets(data.data(), data.size(), sync); + } + // This has to be called every time fastfiles are loaded :D void FastFiles::LoadLocalizeZones(Game::XZoneInfo *zoneInfo, unsigned int zoneCount, int sync) { @@ -142,6 +155,7 @@ namespace Components { Utils::Hook(0x506BC7, FastFiles::LoadInitialZones, HOOK_CALL).Install()->Quick(); Utils::Hook(0x60B4AC, FastFiles::LoadDLCUIZones, HOOK_CALL).Install()->Quick(); + Utils::Hook(0x506B25, FastFiles::LoadGfxZones, HOOK_CALL).Install()->Quick(); } // basic checks (hash jumps, both normal and playlist) diff --git a/src/Components/Modules/FastFiles.hpp b/src/Components/Modules/FastFiles.hpp index 745e27ad..ceee7447 100644 --- a/src/Components/Modules/FastFiles.hpp +++ b/src/Components/Modules/FastFiles.hpp @@ -18,6 +18,7 @@ namespace Components static std::vector ZonePaths; static const char* GetZoneLocation(const char* file); static void LoadInitialZones(Game::XZoneInfo *zoneInfo, unsigned int zoneCount, int sync); - static void LoadDLCUIZones(Game::XZoneInfo *zoneInfo, unsigned int zoneCount, int sync); + static void LoadDLCUIZones(Game::XZoneInfo *zoneInfo, unsigned int zoneCount, int sync); + static void LoadGfxZones(Game::XZoneInfo *zoneInfo, unsigned int zoneCount, int sync); }; } diff --git a/src/Components/Modules/Maps.cpp b/src/Components/Modules/Maps.cpp index a202d249..45d3de4d 100644 --- a/src/Components/Modules/Maps.cpp +++ b/src/Components/Modules/Maps.cpp @@ -186,7 +186,7 @@ namespace Components //Maps::AddDependency("oilrig", "mp_subbase"); //Maps::AddDependency("gulag", "mp_subbase"); //Maps::AddDependency("invasion", "mp_rust"); - Maps::AddDependency("^(?!mp_).*", "dependencies_mp"); // All maps not starting with "mp_" + Maps::AddDependency("^(?!mp_).*", "dependencies_iw4x_mp"); // All maps not starting with "mp_" } Maps::~Maps() diff --git a/src/Components/Modules/StructuredData.cpp b/src/Components/Modules/StructuredData.cpp index 4dcf86e7..49b01986 100644 --- a/src/Components/Modules/StructuredData.cpp +++ b/src/Components/Modules/StructuredData.cpp @@ -88,20 +88,6 @@ namespace Components dataEnum->indices = StructuredData::Indices[type]; } - void StructuredData::DumpDataDef(Game::StructuredDataDefSet* dataDef) - { - if (!dataDef || !dataDef->data) return; - - json11::Json definition = - json11::Json::object - { - { "version", dataDef->data->version }, - //{ "enums", [ 0 ] }, - }; - - Utils::WriteFile(Utils::VA("raw/%s.json", dataDef->name), definition.dump()); - } - StructuredData* StructuredData::GetSingleton() { if (!StructuredData::Singleton) @@ -114,6 +100,9 @@ namespace Components StructuredData::StructuredData() { + // Only execute this when building zones + if (!ZoneBuilder::IsEnabled()) return; + StructuredData::Singleton = this; ZeroMemory(StructuredData::IndexCount, sizeof(StructuredData)); @@ -142,12 +131,6 @@ namespace Components return header; }); - Command::Add("dumpDataDef", [] (Command::Params params) - { - if (params.Length() < 2) return; - StructuredData::DumpDataDef(Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_STRUCTUREDDATADEF, params[1]).structuredData); - }); - // ---------- Weapons ---------- StructuredData::AddPlayerDataEntry(StructuredData::ENUM_WEAPONS, 1, "m40a3"); StructuredData::AddPlayerDataEntry(StructuredData::ENUM_WEAPONS, 2, "ak47classic"); diff --git a/src/Components/Modules/StructuredData.hpp b/src/Components/Modules/StructuredData.hpp index e720f1ba..40f6b766 100644 --- a/src/Components/Modules/StructuredData.hpp +++ b/src/Components/Modules/StructuredData.hpp @@ -33,8 +33,6 @@ namespace Components std::string name; int statOffset; }; - - static void DumpDataDef(Game::StructuredDataDefSet* dataDef); static void PatchPlayerDataEnum(Game::StructuredDataDefSet* data, PlayerDataType type, std::vector& entries); static StructuredData* GetSingleton();