From 8ae1e1bc6b1cbbd926bfc97d8be05483af094388 Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Sat, 3 Jun 2023 00:40:46 -0700 Subject: [PATCH] Fix: remove ability to buy items from a vendor if they don't sell said item (#1105) --- dGame/dComponents/VendorComponent.cpp | 4 ++++ dGame/dComponents/VendorComponent.h | 2 ++ dGame/dGameMessages/GameMessages.cpp | 9 +++++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/dGame/dComponents/VendorComponent.cpp b/dGame/dComponents/VendorComponent.cpp index c917878..e89cc92 100644 --- a/dGame/dComponents/VendorComponent.cpp +++ b/dGame/dComponents/VendorComponent.cpp @@ -134,3 +134,7 @@ void VendorComponent::SetupConstants() { m_RefreshTimeSeconds = vendorComps[0].refreshTimeSeconds; m_LootMatrixID = vendorComps[0].LootMatrixIndex; } + +bool VendorComponent::SellsItem(const LOT item) const { + return m_Inventory.find(item) != m_Inventory.end(); +} diff --git a/dGame/dComponents/VendorComponent.h b/dGame/dComponents/VendorComponent.h index bf372bf..cbff0cf 100644 --- a/dGame/dComponents/VendorComponent.h +++ b/dGame/dComponents/VendorComponent.h @@ -67,6 +67,8 @@ public: * Called on startup of vendor to setup the variables for the component. */ void SetupConstants(); + + bool SellsItem(const LOT item) const; private: /** * The buy scalar. diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index c178f6c..1646002 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -4733,12 +4733,17 @@ void GameMessages::HandleBuyFromVendor(RakNet::BitStream* inStream, Entity* enti const auto isCommendationVendor = entity->GetLOT() == 13806; - VendorComponent* vend = static_cast(entity->GetComponent(eReplicaComponentType::VENDOR)); + auto* vend = entity->GetComponent(); if (!vend && !isCommendationVendor) return; - InventoryComponent* inv = static_cast(player->GetComponent(eReplicaComponentType::INVENTORY)); + auto* inv = player->GetComponent(); if (!inv) return; + if (!isCommendationVendor && !vend->SellsItem(item)) { + Game::logger->Log("GameMessages", "User %llu %s tried to buy an item %i from a vendor when they do not sell said item", player->GetObjectID(), user->GetUsername().c_str(), item); + return; + } + CDComponentsRegistryTable* compRegistryTable = CDClientManager::Instance().GetTable(); CDItemComponentTable* itemComponentTable = CDClientManager::Instance().GetTable();