fix(inventory): nothing is used while stunned from using items, as the client

LWOInventoryComponent_Common::msgUseNonEquipmentItem (0x00cdeba0) asks
GetStunned first and uses nothing when canUseItem is false
(LWOControllablePhysComponent::msgGetStunned 0x00be0df0: stunned from
using items, or dead). The server now counts the use-item stun of every
SetStunned it sends for an entity as msgSetStunned (0x00bf1d10) does
(push/pop, never below 0, characters only, unless immune and not
bIgnoreImmunity), and checks it with IsDead before using an item. The
server never checked either.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-10-02 10:54:35 -05:00
parent a538f32382
commit 02c96b08bd
6 changed files with 131 additions and 1 deletions

View File

@@ -38,6 +38,7 @@
#include "ModuleAssemblyComponent.h"
#include "HavokVehiclePhysicsComponent.h"
#include "CharacterComponent.h"
#include "ControllablePhysicsComponent.h"
#include "dZoneManager.h"
#include "PropertyManagementComponent.h"
#include "DestroyableComponent.h"
@@ -2407,8 +2408,17 @@ void InventoryComponent::OnClientItemConsumed(const GameMessages::ClientItemCons
void InventoryComponent::OnUseNonEquipmentItem(const GameMessages::UseNonEquipmentItem& msg) {
auto* item = FindItemById(msg.itemToUse);
if (!item) return;
if (item) item->UseNonEquip(item);
// As LWOInventoryComponent_Common::msgUseNonEquipmentItem (0x00cdeba0): nothing is used while GetStunned says
// canUseItem is false (LWOControllablePhysComponent::msgGetStunned 0x00be0df0: stunned from using items, or dead)
auto* const physics = m_Parent->GetComponent<ControllablePhysicsComponent>();
GameMessages::IsDead isDead{};
isDead.target = m_Parent->GetObjectID();
const bool dead = m_Parent->HandleMsg(isDead) && isDead.bDead;
if (physics && (physics->GetStunnedFromUsingItems() || dead)) return;
item->UseNonEquip(item);
}
void InventoryComponent::OnUpdateInventoryGroup(const GameMessages::UpdateInventoryGroup& msg) {

View File

@@ -370,6 +370,13 @@ void ControllablePhysicsComponent::DeactivateBubbleBuff() {
Game::entityManager->SerializeEntity(m_Parent);
};
void ControllablePhysicsComponent::ApplyStun(const GameMessages::SetStunned& stun) {
// Only characters are stunned from using items
if (!stun.bCantUseItem || !m_Parent->IsPlayer()) return;
if (!stun.bIgnoreImmunity && m_ImmuneToStunUseItemCount > 0) return;
m_StunnedUseItemCount = std::max(0, m_StunnedUseItemCount + (stun.StateChangeType == eStateChangeType::PUSH ? 1 : -1));
}
void ControllablePhysicsComponent::SetStunImmunity(
const eStateChangeType state,
const LWOOBJID originator,

View File

@@ -19,6 +19,9 @@ namespace tinyxml2 {
class Entity;
class dpEntity;
enum class eStateChangeType : uint32_t;
namespace GameMessages {
struct SetStunned;
}
/**
* Handles the movement of controllable Entities, e.g. enemies and players
@@ -289,6 +292,11 @@ public:
const bool GetImmuneToStunTurn() { return m_ImmuneToStunTurnCount > 0;};
const bool GetImmuneToStunUseItem() { return m_ImmuneToStunUseItemCount > 0;};
// A SetStunned sent for this entity, counted as LWOControllablePhysComponent::msgSetStunned (0x00bf1d10) counts it.
// Only the use-item stun is kept: the server checks it before using an item (msgGetStunned 0x00be0df0).
void ApplyStun(const GameMessages::SetStunned& stun);
bool GetStunnedFromUsingItems() const { return m_StunnedUseItemCount > 0; }
private:
// The save's physics state (LoadFromSaveData), then where the character comes into the world
void ReadSaveData(const tinyxml2::XMLDocument& doc);
@@ -421,6 +429,9 @@ private:
int32_t m_ImmuneToStunMoveCount;
int32_t m_ImmuneToStunTurnCount;
int32_t m_ImmuneToStunUseItemCount;
// Stuns from using items (ApplyStun)
int32_t m_StunnedUseItemCount = 0;
};
#endif // CONTROLLABLEPHYSICSCOMPONENT_H