From baa5578482bf5af9d3d8b15ec9270cd8cae80de5 Mon Sep 17 00:00:00 2001 From: Louvenarde Date: Fri, 30 Sep 2022 20:17:10 +0200 Subject: [PATCH] Add care package to ents --- src/Components/Modules/IMapEnts.cpp | 2 + src/Components/Modules/IclipMap_t.cpp | 6 +-- src/Game/Functions.cpp | 4 +- src/Utils/Entities.cpp | 72 ++++++++++++++++++++++++++- src/Utils/Entities.hpp | 1 + 5 files changed, 79 insertions(+), 6 deletions(-) diff --git a/src/Components/Modules/IMapEnts.cpp b/src/Components/Modules/IMapEnts.cpp index a91e927..39d007f 100644 --- a/src/Components/Modules/IMapEnts.cpp +++ b/src/Components/Modules/IMapEnts.cpp @@ -14,6 +14,8 @@ namespace Components std::string entString(ents->entityString, ents->numEntityChars - 1); Utils::Entities mapEnts(entString); + + mapEnts.addCarePackages(); mapEnts.deleteOldSchoolPickups(); if (mapEnts.convertTurrets()) diff --git a/src/Components/Modules/IclipMap_t.cpp b/src/Components/Modules/IclipMap_t.cpp index d7ebaaa..a601ef4 100644 --- a/src/Components/Modules/IclipMap_t.cpp +++ b/src/Components/Modules/IclipMap_t.cpp @@ -502,6 +502,7 @@ namespace Components const auto brushNodeIndex = clipMap->leafbrushNodesCount; const auto brushEdgeIndex = clipMap->numBrushEdges; const auto materialIndex = clipMap->numMaterials; + const auto cModelIndex = clipMap->numSubModels; // Materials constexpr auto matSize = sizeof(Game::IW3::dmaterial_t); @@ -579,12 +580,12 @@ namespace Components bounds.max(model.leaf.maxs); model.leaf.leafBrushNode = brushNodeIndex; + reallocatedCModels[cModelIndex + i] = model; } - clipMap->numSubModels++; + clipMap->numSubModels += 2; clipMap->cmodels = reallocatedCModels; - // Brushes constexpr auto brushSize = sizeof(Game::IW3::cbrush_t); @@ -636,7 +637,6 @@ namespace Components if (clipMap->brushEdges[i] == *reallocatedBrushes[j].baseAdjacentSide) { reallocatedBrushes[j].baseAdjacentSide = &clipMap->brushEdges[i]; - validated = true; break; } } diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index 305c1d6..414e99b 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -284,7 +284,7 @@ namespace Game { for (int i = 0; i < 3; ++i) { - out[i] = midPoint[i] - halfSize[i] * 2; + out[i] = midPoint[i] - halfSize[i]; } } @@ -292,7 +292,7 @@ namespace Game { for (int i = 0; i < 3; ++i) { - out[i] = midPoint[i] + halfSize[i] * 2; + out[i] = midPoint[i] + halfSize[i]; } } } diff --git a/src/Utils/Entities.cpp b/src/Utils/Entities.cpp index 92cd818..b9fa289 100644 --- a/src/Utils/Entities.cpp +++ b/src/Utils/Entities.cpp @@ -40,7 +40,10 @@ namespace Utils { std::string model = entity["model"]; - if (!model.empty() && model[0] != '*' && model[0] != '?') // Skip brushmodels + if (!model.empty() + && model[0] != '*' && model[0] != '?' // Skip brushmodels + && !model.starts_with("com_plasticcase_") // Skip care package (part of team zones) + ) { if (std::find(models->begin(), models->end(), model) == models->end()) { @@ -99,6 +102,73 @@ namespace Utils return hasVehicles; } + void Entities::addCarePackages() + { + auto subModelCount = 0; + + // We don't have a clipmap reference, so + Game::DB_EnumXAssetEntries(Game::XAssetType::ASSET_TYPE_CLIPMAP_PVS, [&subModelCount](Game::IW3::XAssetEntry* entry) { + if (entry && entry->asset.header.clipMap && subModelCount == 0) + { + // A clipmap is loaded, we may add the care packages + auto clipMap = entry->asset.header.clipMap; + + subModelCount = clipMap->numSubModels; + } + }, false); + + + if (subModelCount > 0) + { + // The last two static models will always be the care packages if we added them ourselves + auto countWithoutPackages = subModelCount - 2; + + // All values here taken from mp_rust + std::unordered_map airdropPalletBrushModel = + { + { "script_gameobjectname", "airdrop_pallet"}, + { "targetname", "iw3x_entity_carepackage"}, + { "classname", "script_brushmodel"}, + { "origin", "-5072 6560 858"}, + { "model", "*" + std::to_string(countWithoutPackages) } + }; + + std::unordered_map airdropPalletScriptModel = + { + { "ltOrigin", "-5072 6560.19 872.889"}, + { "target", "iw3x_entity_carepackage"}, + { "targetname", "airdrop_crate"}, + { "origin", "-5072 6560 858"}, + { "classname", "script_model"}, + { "model", "com_plasticcase_green_big_us_dirt"} + }; + + std::unordered_map carePackageBrushModel = + { + {"script_gameobjectname", "airdrop_pallet"}, + { "targetname", "iw3x_entity_airdroppallet"}, + { "classname", "script_brushmodel"}, + { "origin", "250 325 -299"}, + { "model", "*" + std::to_string(countWithoutPackages+1) } + }; + + std::unordered_map carePackageScriptModel = + { + { "ltOrigin", "249.7 324.886 -299.611"}, + { "target", "iw3x_entity_carepackage"}, + { "targetname", "care_package"}, + { "origin", "249.7 324.7 -314.5"}, + { "classname", "script_model"}, + { "model", "com_plasticcase_green_big_us_dirt"} + }; + + entities.push_back(airdropPalletBrushModel); + entities.push_back(airdropPalletScriptModel); + entities.push_back(carePackageBrushModel); + entities.push_back(carePackageScriptModel); + } + } + void Entities::deleteTriggers() { for (auto i = this->entities.begin(); i != this->entities.end();) diff --git a/src/Utils/Entities.hpp b/src/Utils/Entities.hpp index f85a2dd..44cbde6 100644 --- a/src/Utils/Entities.hpp +++ b/src/Utils/Entities.hpp @@ -17,6 +17,7 @@ namespace Utils void deleteOldSchoolPickups(); bool convertTurrets(); bool convertVehicles(); + void addCarePackages(); private: enum