From c69b26b6611d90781b924cf78454f283c1cabaa2 Mon Sep 17 00:00:00 2001 From: Aaron Kimbrell Date: Thu, 1 Oct 2026 16:32:07 -0500 Subject: [PATCH] feat(entity): more of the client's object loading rules From ObjectLoader2 (DoObjectPreLoad / DoObjectComponentLoad): - componentWhitelist N keeps only that whitelist's registry components (ApplyComponentWhitelist; property models use 1). - No pet component for an object in an inventory (LWOPetComponent::Factory). - Havok vehicle physics: use_simple_physics makes simple physics instead, objectWorldState 2 none. - markedAsPhantom (any value) turns the registry's simple physics into phantom physics with that row, and doesn't count when the registry has phantom physics. - Vendors get a proximity monitor first when they have none; a mission offer's object gets one after the walk (113 LOTs gain one). Same bytes for every LOT. Co-Authored-By: Claude Opus 5.5 --- dGame/Entity.cpp | 58 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 11 deletions(-) diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index 2a7983e6e..04f42550a 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -320,9 +320,25 @@ void Entity::Initialize() { const bool hasModelBehaviors = !GetVar(u"inInventory") && HasVar(u"modelType") && HasVar(u"modelBehaviors"); int32_t modelPhysicsComponentID = -1; // If an entity is marked a phantom, simple physics is made into phantom phyics. - const bool markedAsPhantom = GetVar(u"markedAsPhantom"); + // DoObjectPreLoad: markedAsPhantom doesn't count when the registry has phantom physics + const bool markedAsPhantom = HasVar(u"markedAsPhantom") && compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PHANTOM_PHYSICS, -1) == -1; + + // ObjectLoader2::ApplyComponentWhitelist (0x0103e300): the config's componentWhitelist keeps only these registry + // components (the lists ObjectLoader2's constructor builds; property models use 1) + static constexpr std::array, 5> COMPONENT_WHITELISTS{ { + { eReplicaComponentType::CONTROLLABLE_PHYSICS, eReplicaComponentType::SIMPLE_PHYSICS, eReplicaComponentType::RENDER }, + { eReplicaComponentType::RENDER, eReplicaComponentType::DESTROYABLE, eReplicaComponentType::ITEM, eReplicaComponentType::BLUEPRINT, + eReplicaComponentType::MODEL, eReplicaComponentType::CONTROLLABLE_PHYSICS, eReplicaComponentType::SIMPLE_PHYSICS, eReplicaComponentType::SPAWNER }, + { eReplicaComponentType::RENDER, eReplicaComponentType::ITEM, eReplicaComponentType::BLUEPRINT }, + { eReplicaComponentType::PET, eReplicaComponentType::SKILL, eReplicaComponentType::DESTROYABLE, eReplicaComponentType::RENDER, eReplicaComponentType::CONTROLLABLE_PHYSICS }, + { eReplicaComponentType::CONTROLLABLE_PHYSICS, eReplicaComponentType::SIMPLE_PHYSICS, eReplicaComponentType::RENDER }, + } }; + const auto whitelistIndex = HasVar(u"componentWhitelist") ? GetVarAs(u"componentWhitelist") : -1; + const std::initializer_list* const whitelist = + whitelistIndex >= 0 && whitelistIndex < static_cast(COMPONENT_WHITELISTS.size()) ? &COMPONENT_WHITELISTS[whitelistIndex] : nullptr; for (const auto type : ClientComponentLoadOrder) { + if (whitelist && std::ranges::find(*whitelist, type) == whitelist->end()) continue; switch (type) { case eReplicaComponentType::POSSESSABLE: { const auto possessableComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::POSSESSABLE); @@ -349,7 +365,10 @@ void Entity::Initialize() { } case eReplicaComponentType::HAVOK_VEHICLE_PHYSICS: { const auto havokVehiclePhysicsComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::HAVOK_VEHICLE_PHYSICS); - if (havokVehiclePhysicsComponentID > 0) { + // The client makes simple physics instead for use_simple_physics, and none for objectWorldState 2 + if (havokVehiclePhysicsComponentID > 0 && HasVar(u"use_simple_physics")) { + if (!HasComponent(eReplicaComponentType::SIMPLE_PHYSICS)) AddComponent(havokVehiclePhysicsComponentID); + } else if (havokVehiclePhysicsComponentID > 0 && !(HasVar(u"objectWorldState") && GetVarAs(u"objectWorldState") == 2)) { auto* havokVehiclePhysicsComponent = AddComponent(havokVehiclePhysicsComponentID); havokVehiclePhysicsComponent->SetPosition(m_DefaultPosition); havokVehiclePhysicsComponent->SetRotation(m_DefaultRotation); @@ -368,14 +387,16 @@ void Entity::Initialize() { if (hasModelBehaviors) { // LWOSimplePhysicsComponent::Allocator (0x0104ded0): left to the model case if (simplePhysicsComponentID > 0) modelPhysicsComponentID = simplePhysicsComponentID; - } else if (!markedAsPhantom && simplePhysicsComponentID > 0) { - AddComponent(simplePhysicsComponentID); + } else if (simplePhysicsComponentID > 0) { + // markedAsPhantom makes its simple physics phantom physics (with the simple physics row) + if (markedAsPhantom) AddComponent(simplePhysicsComponentID)->SetPhysicsEffectActive(false); + else AddComponent(simplePhysicsComponentID); } break; } case eReplicaComponentType::PHANTOM_PHYSICS: { const auto phantomPhysicsComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PHANTOM_PHYSICS); - if (markedAsPhantom || phantomPhysicsComponentID > 0) { + if (phantomPhysicsComponentID > 0 && !HasComponent(eReplicaComponentType::PHANTOM_PHYSICS)) { AddComponent(phantomPhysicsComponentID)->SetPhysicsEffectActive(false); } break; @@ -423,9 +444,9 @@ void Entity::Initialize() { break; } case eReplicaComponentType::PET: { - if (petComponentID > 0) { - // LWOPetComponent::Factory (0x01031240): a pet that isn't in an inventory gets pathfinding control first - if (!GetVar(u"inInventory") && !HasComponent(eReplicaComponentType::PATHFINDING)) AddComponent(-1); + // LWOPetComponent::Factory (0x01031240): no pet in an inventory; otherwise pathfinding control first + if (petComponentID > 0 && !GetVar(u"inInventory")) { + if (!HasComponent(eReplicaComponentType::PATHFINDING)) AddComponent(-1); AddComponent(petComponentID); } break; @@ -540,17 +561,27 @@ void Entity::Initialize() { } case eReplicaComponentType::VENDOR: { const auto vendorID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::VENDOR); - if (vendorID > 0) AddComponent(vendorID); + // The vendor allocators add a proximity monitor first when there is none + if (vendorID > 0) { + if (!HasComponent(eReplicaComponentType::PROXIMITY_MONITOR)) AddComponent(-1); + AddComponent(vendorID); + } break; } case eReplicaComponentType::DONATION_VENDOR: { const auto donationVendorID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::DONATION_VENDOR, -1); - if (donationVendorID > -1) AddComponent(donationVendorID); + if (donationVendorID > -1) { + if (!HasComponent(eReplicaComponentType::PROXIMITY_MONITOR)) AddComponent(-1); + AddComponent(donationVendorID); + } break; } case eReplicaComponentType::ACHIEVEMENT_VENDOR: { const auto achievementVendorID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::ACHIEVEMENT_VENDOR, -1); - if (achievementVendorID > -1) AddComponent(achievementVendorID); + if (achievementVendorID > -1) { + if (!HasComponent(eReplicaComponentType::PROXIMITY_MONITOR)) AddComponent(-1); + AddComponent(achievementVendorID); + } break; } case eReplicaComponentType::SHOOTING_GALLERY: { @@ -947,6 +978,11 @@ void Entity::Initialize() { if (m_Character && HasComponent(eReplicaComponentType::CONTROLLABLE_PHYSICS)) { AddComponent(-1)->LoadFromSaveData(m_Character->GetXMLDoc()); } + // A mission offer's object gets a proximity monitor after the walk when it has none (the registry's mission offer; + // a character's is DLU's own) + if (!m_Character && HasComponent(eReplicaComponentType::MISSION_OFFER) && !HasComponent(eReplicaComponentType::PROXIMITY_MONITOR)) { + AddComponent(-1); + } const auto triggerInfo = GetVarAsString(u"trigger_id"); if (!triggerInfo.empty()) AddComponent(-1, triggerInfo);