From 639f8e184ad43b2ae4e51bd9466cfe9cc214573d Mon Sep 17 00:00:00 2001 From: Aeadoin <109764533+Aeadoin@users.noreply.github.com> Date: Wed, 30 Nov 2022 18:02:36 -0500 Subject: [PATCH] [Fix] Clamp Item Ldon Sell Back Rates. (#2592) * [Fix] Clamp ldonsellbackrates to prevent abuse. * Change cast to uint32 * Fix issues with Clamp not functioning correctly. * Fix missed clamp * change price is unsigned int to prevent potential overflow * Formatting * Formatting fix * Update client_packet.cpp * Update client_packet.cpp Co-authored-by: Alex King <89047260+Kinglykrab@users.noreply.github.com> --- zone/client_packet.cpp | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index a743639f3..3a7703e23 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -2211,7 +2211,14 @@ void Client::Handle_OP_AdventureMerchantSell(const EQApplicationPacket *app) } // 06/11/2016 This formula matches RoF2 client side calculation. - int32 price = (item->LDoNPrice + 1) * item->LDoNSellBackRate / 100; + uint32 price = EQ::Clamp( + price, + EQ::ClampUpper( + (item->LDoNPrice + 1) * item->LDoNSellBackRate / 100, + item->LDoNPrice + ), + item->LDoNPrice + ); if (price == 0) { @@ -2696,7 +2703,14 @@ void Client::Handle_OP_AltCurrencySell(const EQApplicationPacket *app) if (item->ID == inst->GetItem()->ID) { // 06/11/2016 This formula matches RoF2 client side calculation. - cost = (ml.alt_currency_cost + 1) * item->LDoNSellBackRate / 100; + cost = EQ::Clamp( + cost, + EQ::ClampUpper( + static_cast((ml.alt_currency_cost + 1) * item->LDoNSellBackRate / 100), + static_cast(ml.alt_currency_cost) + ), + static_cast(ml.alt_currency_cost) + ); found = true; break; } @@ -2801,7 +2815,14 @@ void Client::Handle_OP_AltCurrencySellSelection(const EQApplicationPacket *app) if (item->ID == inst->GetItem()->ID) { // 06/11/2016 This formula matches RoF2 client side calculation. - cost = (ml.alt_currency_cost + 1) * item->LDoNSellBackRate / 100; + cost = EQ::Clamp( + cost, + EQ::ClampUpper( + static_cast((ml.alt_currency_cost + 1) * item->LDoNSellBackRate / 100), + static_cast(ml.alt_currency_cost) + ), + static_cast(ml.alt_currency_cost) + ); found = true; break; }