diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index fc00439a9..0d5902846 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -99,6 +99,7 @@ #include "PetCreatorComponent.h" #include "HFLightDirectionGadgetComponent.h" #include "SpawnerComponent.h" +#include "BBBComponent.h" #include "ExhibitComponent.h" #include "PathfindingComponent.h" #include "PhysicsSystemComponent.h" @@ -929,6 +930,12 @@ void Entity::DoObjectComponentLoad(ObjectLoadState& state) { if (id > -1) AddComponent(id); break; } + case eReplicaComponentType::BBB: { + // DoObjectPreLoad gives a character (LOT 1) one with id 0; any other object the registry's + const auto id = m_TemplateID == 1 ? 0 : state.GetComponentID(eReplicaComponentType::BBB, -1); + if (id > -1) AddComponent(id); + break; + } case eReplicaComponentType::ROCKET_LANDING: { // LWORocketAnimationControlComponent: the client makes it from the registry const auto id = state.GetComponentID(eReplicaComponentType::ROCKET_LANDING, -1); @@ -1301,7 +1308,7 @@ namespace { PHANTOM_PHYSICS, SOUND_TRIGGER, RACING_SOUND_TRIGGER, BUFF, DESTROYABLE, COLLECTIBLE, PET, PLAYER_FORCED_MOVEMENT, CHARACTER, INVENTORY, SCRIPT, SKILL, BASE_COMBAT_AI, ITEM, QUICK_BUILD, MOVING_PLATFORM, SWITCH, VENDOR, DONATION_VENDOR, ACHIEVEMENT_VENDOR, - BOUNCER, SCRIPTED_ACTIVITY, SHOOTING_GALLERY, RACING_CONTROL, LUP_EXHIBIT, MODEL, RENDER, MINI_GAME_CONTROL, + BOUNCER, SCRIPTED_ACTIVITY, SHOOTING_GALLERY, RACING_CONTROL, LUP_EXHIBIT, MODEL, RENDER, MINI_GAME_CONTROL, BBB, }; }(); @@ -1343,11 +1350,6 @@ void Entity::WriteComponents(RakNet::BitStream& outBitStream, eReplicaPacketType } component->Serialize(outBitStream, bIsInitialUpdate); } - - // BBB Component, unused currently - // Need to to write0 so that is serialized correctly - // TODO: Implement BBB Component - outBitStream.Write0(); } void Entity::UpdateXMLDoc(tinyxml2::XMLDocument& doc) { diff --git a/dGame/dComponents/BBBComponent.h b/dGame/dComponents/BBBComponent.h new file mode 100644 index 000000000..ae214c835 --- /dev/null +++ b/dGame/dComponents/BBBComponent.h @@ -0,0 +1,31 @@ +#ifndef BBBCOMPONENT_H +#define BBBCOMPONENT_H + +#include "BitStream.h" +#include "Component.h" +#include "dCommonVars.h" +#include "eReplicaComponentType.h" + +/** + * The BBB component (76), as the client's LWOBBBComponent: DoObjectPreLoad gives every character one (and the registry + * any object listing it). It sends whether there is a metadata source item, then the item's ID. + */ +class BBBComponent final : public Component { +public: + static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::BBB; + + BBBComponent(Entity* parent, const int32_t componentID) : Component(parent, componentID) {} + + // LWOBBBComponent::Deserialize 0x00bd6690 + void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override { + outBitStream.Write(m_MetadataSourceItem != LWOOBJID_EMPTY); + if (m_MetadataSourceItem != LWOOBJID_EMPTY) outBitStream.Write(m_MetadataSourceItem); + } + + void SetMetadataSourceItem(const LWOOBJID item) { m_MetadataSourceItem = item; } + +private: + LWOOBJID m_MetadataSourceItem = LWOOBJID_EMPTY; +}; + +#endif // BBBCOMPONENT_H diff --git a/tests/dGameTests/dComponentsTests/ReplicaComponentOrderTests.cpp b/tests/dGameTests/dComponentsTests/ReplicaComponentOrderTests.cpp index d9fad33aa..6430eefb9 100644 --- a/tests/dGameTests/dComponentsTests/ReplicaComponentOrderTests.cpp +++ b/tests/dGameTests/dComponentsTests/ReplicaComponentOrderTests.cpp @@ -283,10 +283,8 @@ namespace { miniGameControlComponent->Serialize(outBitStream, bIsInitialUpdate); } - // BBB Component, unused currently - // Need to to write0 so that is serialized correctly - // TODO: Implement BBB Component - outBitStream.Write0(); + // The BBB component (characters): no metadata source item + if (entity.GetLOT() == 1) outBitStream.Write0(); }