From ad2aadc1fefdea7ba30a5edcdea4b0053d0018ba Mon Sep 17 00:00:00 2001 From: Aaron Kimbrell Date: Wed, 11 Nov 2026 06:55:23 -0600 Subject: [PATCH 1/5] fix(vendor): check the item's requirements when it is bought The vendor window checks an item's reqPrecondition in the vendor buy context (an unnamed function in LWOVendorComponent, through LWOItemComponent::StaticCheckUseRequirements) and greys out what the player does not meet, without a tooltip. The server sold the item whatever its requirements; a buy that fails them now gets the vendor's normal PURCHASE_FAIL, for both the vendor and the achievement vendor. Rows without the vendor buy bit (the thinking hat one, validContexts 252) still do not stop a purchase; the level ones (249) do. PreconditionExpression::Check takes the client's bShowTooltip flag, so this check sends no NotifyClientFailedPrecondition. Co-Authored-By: Claude Opus 5.5 --- .../Vendor/AchievementVendorComponent.cpp | 2 +- .../dComponents/Vendor/BaseVendorComponent.cpp | 11 +++++++++++ dGame/dComponents/Vendor/BaseVendorComponent.h | 5 +++++ dGame/dUtilities/Preconditions.cpp | 3 ++- dGame/dUtilities/Preconditions.h | 4 +++- tests/dGameTests/PreconditionCheckTests.cpp | 18 ++++++++++++++++++ 6 files changed, 40 insertions(+), 3 deletions(-) diff --git a/dGame/dComponents/Vendor/AchievementVendorComponent.cpp b/dGame/dComponents/Vendor/AchievementVendorComponent.cpp index ea2e42612..a92d3da91 100644 --- a/dGame/dComponents/Vendor/AchievementVendorComponent.cpp +++ b/dGame/dComponents/Vendor/AchievementVendorComponent.cpp @@ -65,7 +65,7 @@ void AchievementVendorComponent::Buy(Entity* buyer, LOT lot, uint32_t count) { } auto* inventoryComponent = buyer->GetComponent(); - if (!inventoryComponent) { + if (!inventoryComponent || !MeetsBuyRequirements(*buyer, itemComp.reqPrecondition)) { SendTransactionResult(buyer->GetObjectID(), buyer->GetSystemAddress(), eVendorTransactionResult::PURCHASE_FAIL); return; } diff --git a/dGame/dComponents/Vendor/BaseVendorComponent.cpp b/dGame/dComponents/Vendor/BaseVendorComponent.cpp index 0b50fe081..5cd26e6a0 100644 --- a/dGame/dComponents/Vendor/BaseVendorComponent.cpp +++ b/dGame/dComponents/Vendor/BaseVendorComponent.cpp @@ -19,6 +19,7 @@ #include "Item.h" #include "EconomyLedger.h" #include "VendorPricing.h" +#include "Preconditions.h" #include #include @@ -186,6 +187,11 @@ void BaseVendorComponent::Buy(Entity* buyer, LOT lot, uint32_t count) { int itemCompID = compRegistryTable->GetByIDAndType(lot, eReplicaComponentType::ITEM); CDItemComponent itemComp = itemComponentTable->GetItemComponentByID(itemCompID); + if (!MeetsBuyRequirements(*buyer, itemComp.reqPrecondition)) { + SendTransactionResult(buyer->GetObjectID(), buyer->GetSystemAddress(), eVendorTransactionResult::PURCHASE_FAIL); + return; + } + // Extra currency that needs to be deducted in case of crafting auto craftingCurrencies = CDItemComponentTable::ParseCraftingCurrencies(itemComp); for (const auto& [crafintCurrencyLOT, crafintCurrencyCount]: craftingCurrencies) { @@ -233,6 +239,11 @@ void BaseVendorComponent::Buy(Entity* buyer, LOT lot, uint32_t count) { SendTransactionResult(buyer->GetObjectID(), buyer->GetSystemAddress(), eVendorTransactionResult::PURCHASE_SUCCESS); } +bool BaseVendorComponent::MeetsBuyRequirements(Entity& buyer, const std::string& reqPrecondition) { + if (reqPrecondition.empty()) return true; + return PreconditionExpression(reqPrecondition).Check(&buyer, PreconditionContext::VendorBuy, false); +} + bool BaseVendorComponent::SetupItem(LOT item) { auto* itemComponentTable = CDClientManager::GetTable(); diff --git a/dGame/dComponents/Vendor/BaseVendorComponent.h b/dGame/dComponents/Vendor/BaseVendorComponent.h index 371fef081..aaa5f8cb1 100644 --- a/dGame/dComponents/Vendor/BaseVendorComponent.h +++ b/dGame/dComponents/Vendor/BaseVendorComponent.h @@ -58,6 +58,11 @@ public: void Buy(Entity* buyer, LOT lot, uint32_t count); + // Whether buyer meets the item's own requirements (reqPrecondition) for buying it. The vendor window checks them + // in the vendor buy context and greys the item out without a tooltip (an unnamed function in LWOVendorComponent, + // LWOItemComponent::StaticCheckUseRequirements). + static bool MeetsBuyRequirements(Entity& buyer, const std::string& reqPrecondition); + // SellToVendor / BuybackFromVendor from player (sent from sysAddr), for the item with object ID itemObjID. void SellToVendor(Entity& player, const SystemAddress& sysAddr, LWOOBJID itemObjID, int32_t count); void BuybackFromVendor(Entity& player, const SystemAddress& sysAddr, LWOOBJID itemObjID, int32_t count); diff --git a/dGame/dUtilities/Preconditions.cpp b/dGame/dUtilities/Preconditions.cpp index 6ce7984a8..a11cd3734 100644 --- a/dGame/dUtilities/Preconditions.cpp +++ b/dGame/dUtilities/Preconditions.cpp @@ -286,7 +286,7 @@ std::vector PreconditionExpression::GetItemCosts(Entity* player) const return costs; } -bool PreconditionExpression::Check(Entity* player, const PreconditionContext context) const { +bool PreconditionExpression::Check(Entity* player, const PreconditionContext context, const bool showTooltip) const { // LWOPreconditionComponent::msgCheckAllPreconditions: every group has to pass, a group passes with // any of its alternatives, and only the alternatives of a failed group are reported bool pass = true; @@ -298,6 +298,7 @@ bool PreconditionExpression::Check(Entity* player, const PreconditionContext con if (groupPasses) continue; pass = false; + if (!showTooltip) continue; for (const auto condition : group) { GameMessages::NotifyClientFailedPrecondition failedPrecondition; failedPrecondition.target = player->GetObjectID(); diff --git a/dGame/dUtilities/Preconditions.h b/dGame/dUtilities/Preconditions.h index ac4551282..cafc7af02 100644 --- a/dGame/dUtilities/Preconditions.h +++ b/dGame/dUtilities/Preconditions.h @@ -102,7 +102,9 @@ class PreconditionExpression final public: explicit PreconditionExpression(const std::string& conditions); - bool Check(Entity* player, PreconditionContext context = PreconditionContext::None) const; + // Whether every group passes. With showTooltip, the player is told which preconditions of a failed group they do + // not meet (NotifyClientFailedPrecondition); the client's CheckUseRequirements has the same flag (bShowTooltip). + bool Check(Entity* player, PreconditionContext context = PreconditionContext::None, bool showTooltip = true) const; // The item costs of the HasItem preconditions in this expression that the player meets std::vector GetItemCosts(Entity* player) const; diff --git a/tests/dGameTests/PreconditionCheckTests.cpp b/tests/dGameTests/PreconditionCheckTests.cpp index fb77f2904..76a68e235 100644 --- a/tests/dGameTests/PreconditionCheckTests.cpp +++ b/tests/dGameTests/PreconditionCheckTests.cpp @@ -4,6 +4,7 @@ #include "CDClientDatabase.h" #include "CDComponentsRegistryTable.h" #include "CDItemComponentTable.h" +#include "BaseVendorComponent.h" #include "Character.h" #include "DestroyableComponent.h" #include "Entity.h" @@ -135,3 +136,20 @@ TEST_F(PreconditionCheckTests, ItemsSoldToAVendorAreNotHeld) { EXPECT_FALSE(Preconditions::Check(player.get(), hasNone)); EXPECT_EQ(Preconditions::Get(hasFive).GetItemCost(player.get()), (ItemCost{ BRICK, 5 })); } + +// Buying from a vendor checks the item's requirements in the vendor buy context: rows without that bit (the thinking +// hat one, 252) do not stop a purchase; the level ones (249) and the everywhere ones do +TEST_F(PreconditionCheckTests, VendorBuyChecksTheItemsRequirementsInItsContext) { + const auto notAtVendors = Row(PreconditionType::HasItem, "6194", 1, 252); + const auto level = Row(PreconditionType::HasItem, "6194", 1, 249); + const auto everywhere = Row(PreconditionType::HasItem, "6194", 1, 255); + + EXPECT_TRUE(BaseVendorComponent::MeetsBuyRequirements(*player, "")); + EXPECT_TRUE(BaseVendorComponent::MeetsBuyRequirements(*player, std::to_string(notAtVendors))); + EXPECT_FALSE(BaseVendorComponent::MeetsBuyRequirements(*player, std::to_string(level))); + EXPECT_FALSE(BaseVendorComponent::MeetsBuyRequirements(*player, std::to_string(notAtVendors) + ";" + std::to_string(everywhere))); + + Give(eInventoryType::ITEMS, 1); + EXPECT_TRUE(BaseVendorComponent::MeetsBuyRequirements(*player, std::to_string(level))); + EXPECT_TRUE(BaseVendorComponent::MeetsBuyRequirements(*player, std::to_string(notAtVendors) + ";" + std::to_string(everywhere))); +} From 4dcd583c3f8053cbbe46a09190b088666a44ad19 Mon Sep 17 00:00:00 2001 From: Aaron Kimbrell Date: Wed, 11 Nov 2026 06:56:22 -0600 Subject: [PATCH 2/5] fix(rocket): cancelling a multi-zone launch takes the rocket off again A multi-zone entrance (the LUP launch pads) equips the player's rocket when used and opens the zone menu. Closing the menu without a launch, or dying with it open, fires the same "CancelLaunch" event at the entrance, locally and to the server (LWOMultiZoneEntranceComponent::MultiZoneEntranceSelected Run). Only the property entrance handled it, so the rocket stayed equipped there. Both now take it off. Co-Authored-By: Claude Opus 5.5 --- dGame/dGameMessages/ObjectMessages.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/dGame/dGameMessages/ObjectMessages.cpp b/dGame/dGameMessages/ObjectMessages.cpp index fc6f75a0e..7873c09e7 100644 --- a/dGame/dGameMessages/ObjectMessages.cpp +++ b/dGame/dGameMessages/ObjectMessages.cpp @@ -128,9 +128,10 @@ namespace GameMessages { }); } - // The property browser was closed without a launch, or the player died with it open - // (LWOPropertyEntranceComponent::onPropertyEntranceSelected) - if (args == u"CancelLaunch" && entity.HasComponent(eReplicaComponentType::PROPERTY_ENTRANCE)) { + // The property browser or the multi-zone menu was closed without a launch, or the player died with it open + // (LWOPropertyEntranceComponent::onPropertyEntranceSelected; + // LWOMultiZoneEntranceComponent::MultiZoneEntranceSelected, Run) + if (args == u"CancelLaunch" && (entity.HasComponent(eReplicaComponentType::PROPERTY_ENTRANCE) || entity.HasComponent(eReplicaComponentType::MULTI_ZONE_ENTRANCE))) { PropertyEntranceComponent::CancelLaunch(*player); } From 9bb1ecdd2271efe9091dba5118d4589ca3c36da9 Mon Sep 17 00:00:00 2001 From: Aaron Kimbrell Date: Wed, 11 Nov 2026 07:00:36 -0600 Subject: [PATCH 3/5] fix(trade): tell the requester what became of a trade request The client puts ServerTradeInitialReply in chat: "Trade invitation sent.", "User not in zone.", "Player out of range." or "Player already trading." (LWOTradeComponent::SendMessage). Live sent INVITESENT, with the invitee's name, to every trade request, also the one that accepts an invitation. The server sent none, so a request to a player not in the world went unanswered. A request to a player who is in a trade with someone else is now refused with ALREADYTRADING. Before, a second trade was made with that player in it, and which of the two their messages went to depended on map order. Out of range is not sent: there is no evidence of the distance. Co-Authored-By: Claude Opus 5.5 --- dGame/TradingManager.cpp | 6 ++++++ dGame/TradingManager.h | 15 +++++++++++++++ dGame/dGameMessages/TradeMessages.cpp | 18 +++++++++++++++++- .../dGameMessagesTests/TradeOfferTests.cpp | 14 ++++++++++++++ 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/dGame/TradingManager.cpp b/dGame/TradingManager.cpp index 0cd73e2db..d103c07c0 100644 --- a/dGame/TradingManager.cpp +++ b/dGame/TradingManager.cpp @@ -402,3 +402,9 @@ void TradingManager::NewTrade(LWOOBJID participantA, LWOOBJID participantB) { LOG("Created new trade between (%llu) <-> (%llu)", participantA, participantB); } + +eTradeInviteResult TradingManager::InviteResult(const bool inviteeFound, const Trade* const inviteeTrade, const LWOOBJID requester) { + if (!inviteeFound) return eTradeInviteResult::NOT_FOUND; + if (inviteeTrade && !inviteeTrade->IsParticipant(requester)) return eTradeInviteResult::ALREADY_TRADING; + return eTradeInviteResult::INVITE_SENT; +} diff --git a/dGame/TradingManager.h b/dGame/TradingManager.h index 9fbc14801..47f862205 100644 --- a/dGame/TradingManager.h +++ b/dGame/TradingManager.h @@ -30,6 +30,17 @@ struct HeldTradeItem { struct LwoNameValue; +// ServerTradeInitialReply's resultType: what became of a trade request, told to the player who sent it. The client +// puts it in chat ("Trade invitation sent.", "User not in zone.", "Player out of range.", "Player already trading."; +// LWOTradeComponent::SendMessage). +enum class eTradeInviteResult : int32_t { + NOT_FOUND = 0, + INVITE_SENT, + OUT_OF_RANGE, + ALREADY_TRADING, + GENERAL_ERROR +}; + class InventoryComponent; class Trade { @@ -130,6 +141,10 @@ public: void CancelTrade(const LWOOBJID canceller, LWOOBJID tradeId, const bool sendCancelMessage = true); void NewTrade(LWOOBJID participantA, LWOOBJID participantB); + // The reply to requester's trade request to an invitee who is (or is not) in this world: an invitee in a trade + // with someone else is already trading + static eTradeInviteResult InviteResult(bool inviteeFound, const Trade* inviteeTrade, LWOOBJID requester); + private: static TradingManager* m_Address; //For singleton method diff --git a/dGame/dGameMessages/TradeMessages.cpp b/dGame/dGameMessages/TradeMessages.cpp index bf7c5d34b..f4c287388 100644 --- a/dGame/dGameMessages/TradeMessages.cpp +++ b/dGame/dGameMessages/TradeMessages.cpp @@ -136,8 +136,22 @@ namespace GameMessages { } auto* invitee = Game::entityManager->GetEntity(i64Invitee); + const bool inviteeFound = invitee != nullptr && invitee->IsPlayer(); - if (invitee != nullptr && invitee->IsPlayer()) { + // Live told the requester what became of the request (ServerTradeInitialReply), also when the request + // accepts an invitation + const auto result = TradingManager::InviteResult(inviteeFound, inviteeFound ? TradingManager::Instance()->GetPlayerTrade(i64Invitee).get() : nullptr, entity.GetObjectID()); + const auto sendReply = [&]() { + ServerTradeInitialReply reply; + reply.target = entity.GetObjectID(); + reply.i64Invitee = i64Invitee; + reply.resultType = static_cast(result); + if (inviteeFound && invitee->GetCharacter()) reply.wsName = GeneralUtils::UTF8ToUTF16(invitee->GetCharacter()->GetName()); + reply.Send(sysAddr); + }; + if (result != eTradeInviteResult::INVITE_SENT) sendReply(); + + if (result == eTradeInviteResult::INVITE_SENT) { character = invitee->GetCharacter(); if (!character || !character->GetParentUser()) return; @@ -165,6 +179,8 @@ namespace GameMessages { TradingManager::Instance()->NewTrade(entity.GetObjectID(), i64Invitee); } + sendReply(); + ServerTradeInvite invite; invite.target = i64Invitee; invite.bNeedInvitePopUp = bNeedInvitePopUp; diff --git a/tests/dGameTests/dGameMessagesTests/TradeOfferTests.cpp b/tests/dGameTests/dGameMessagesTests/TradeOfferTests.cpp index 464049e92..1e61ea68b 100644 --- a/tests/dGameTests/dGameMessagesTests/TradeOfferTests.cpp +++ b/tests/dGameTests/dGameMessagesTests/TradeOfferTests.cpp @@ -162,3 +162,17 @@ TEST_F(TradeAcceptTest, AChangedOfferTakesBothAcceptsBack) { EXPECT_TRUE(trade.GetAccepted(20)); EXPECT_FALSE(trade.GetAccepted(10)); } + +// The requester hears what became of a trade request (ServerTradeInitialReply) +TEST_F(TradeAcceptTest, ATradeRequestIsAnsweredAsLiveAnsweredIt) { + EXPECT_EQ(TradingManager::InviteResult(false, nullptr, 10), eTradeInviteResult::NOT_FOUND); + EXPECT_EQ(TradingManager::InviteResult(true, nullptr, 10), eTradeInviteResult::INVITE_SENT); + + // Accepting an invitation is a request to the player who sent it, who is in a trade with the requester + Trade withRequester(1, 20, 10); + EXPECT_EQ(TradingManager::InviteResult(true, &withRequester, 10), eTradeInviteResult::INVITE_SENT); + + // An invitee in a trade with someone else stays in it + Trade withSomeoneElse(2, 20, 30); + EXPECT_EQ(TradingManager::InviteResult(true, &withSomeoneElse, 10), eTradeInviteResult::ALREADY_TRADING); +} From 85975b753eca0f401f0ff4c58c81abe50c3ff813 Mon Sep 17 00:00:00 2001 From: Aaron Kimbrell Date: Wed, 11 Nov 2026 07:00:53 -0600 Subject: [PATCH 4/5] fix(trade): tell both players a trade is about to be performed Once both players had given their final accept, live sent each an empty ServerTradeUpdate with bAboutToPerform set, and the client shows the trade as complete (LWOTradeComponent::SendMessage, "SetTradeComplete"). The server only sent the accepts that close the window. It now sends the update first, before the items move. Co-Authored-By: Claude Opus 5.5 --- dGame/TradingManager.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/dGame/TradingManager.cpp b/dGame/TradingManager.cpp index d103c07c0..364840a7e 100644 --- a/dGame/TradingManager.cpp +++ b/dGame/TradingManager.cpp @@ -150,6 +150,17 @@ void Trade::SetAccepted(LWOOBJID participant, bool value) { } if (m_AcceptedA && m_AcceptedB) { + // Live told the players the trade was about to be performed (an empty ServerTradeUpdate with + // bAboutToPerform); their clients show the trade as complete (LWOTradeComponent::SendMessage, + // "SetTradeComplete") + for (auto* const participant : { GetParticipantAEntity(), GetParticipantBEntity() }) { + if (!participant) continue; + GameMessages::ServerTradeUpdate aboutToPerform; + aboutToPerform.target = participant->GetObjectID(); + aboutToPerform.bAboutToPerform = true; + aboutToPerform.Send(participant->GetSystemAddress()); + } + auto* entityB = GetParticipantBEntity(); if (entityB != nullptr) { From 01fee0d2fcef1fc428531fdc7895c06e2996ed89 Mon Sep 17 00:00:00 2001 From: Aaron Kimbrell Date: Wed, 11 Nov 2026 07:10:16 -0600 Subject: [PATCH 5/5] fix(preconditions): a precondition of an unknown type fails LWOPreconditionComponent::CheckPrecondition fails a type it does not know and logs it; the server passed it. No row of the table has one, so nothing changes for the shipped data. Co-Authored-By: Claude Opus 5.5 --- dGame/dUtilities/Preconditions.cpp | 5 ++++- tests/dGameTests/PreconditionCheckTests.cpp | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/dGame/dUtilities/Preconditions.cpp b/dGame/dUtilities/Preconditions.cpp index a11cd3734..dbfabdf71 100644 --- a/dGame/dUtilities/Preconditions.cpp +++ b/dGame/dUtilities/Preconditions.cpp @@ -213,7 +213,10 @@ bool Precondition::CheckValue(Entity* player, const uint32_t value) const { case PreconditionType::DoesNotHaveFlag: return !character->GetPlayerFlag(value); default: - return true; // There are a couple more unknown preconditions. Always return true in this case. + // LWOPreconditionComponent::CheckPrecondition fails a type it does not know, and logs it. No row of + // the table has one. + LOG("Precondition with unknown type %i", static_cast(type)); + return false; } } diff --git a/tests/dGameTests/PreconditionCheckTests.cpp b/tests/dGameTests/PreconditionCheckTests.cpp index 76a68e235..ebe5b85c6 100644 --- a/tests/dGameTests/PreconditionCheckTests.cpp +++ b/tests/dGameTests/PreconditionCheckTests.cpp @@ -153,3 +153,8 @@ TEST_F(PreconditionCheckTests, VendorBuyChecksTheItemsRequirementsInItsContext) EXPECT_TRUE(BaseVendorComponent::MeetsBuyRequirements(*player, std::to_string(level))); EXPECT_TRUE(BaseVendorComponent::MeetsBuyRequirements(*player, std::to_string(notAtVendors) + ";" + std::to_string(everywhere))); } + +// A type the client does not know fails +TEST_F(PreconditionCheckTests, AnUnknownTypeFails) { + EXPECT_FALSE(Preconditions::Check(player.get(), Row(static_cast(99), "1", 1, 255))); +}