From cd9bbffebc3bd27f10c7ee4c91d049f29677c405 Mon Sep 17 00:00:00 2001 From: Ovahlord Date: Sun, 18 Mar 2018 15:17:36 +0100 Subject: [PATCH] Core/Players: refunding currency items will no longer affect the weekly cap or count towards achievements. *fixed a currency clonding exploit --- src/server/game/Entities/Player/Player.cpp | 19 +++++++++++-------- src/server/game/Entities/Player/Player.h | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index afa422b4de2..862cb620aa0 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -7210,7 +7210,7 @@ bool Player::HasCurrency(uint32 id, uint32 count) const return itr != _currencyStorage.end() && itr->second.totalCount >= count; } -void Player::ModifyCurrency(uint32 id, int32 count, bool printLog/* = true*/, bool ignoreMultipliers/* = false*/) +void Player::ModifyCurrency(uint32 id, int32 count, bool printLog/* = true*/, bool ignoreMultipliers/* = false*/, bool isRefund/* = false*/) { if (!count) return; @@ -7218,7 +7218,7 @@ void Player::ModifyCurrency(uint32 id, int32 count, bool printLog/* = true*/, bo CurrencyTypesEntry const* currency = sCurrencyTypesStore.LookupEntry(id); ASSERT(currency); - if (!ignoreMultipliers) + if (!ignoreMultipliers && !isRefund) count *= GetTotalAuraMultiplierByMiscValue(SPELL_AURA_MOD_CURRENCY_GAIN, id); int32 precision = currency->Flags & CURRENCY_FLAG_HIGH_PRECISION ? CURRENCY_PRECISION : 1; @@ -7246,7 +7246,10 @@ void Player::ModifyCurrency(uint32 id, int32 count, bool printLog/* = true*/, bo // count can't be more then weekCap if used (weekCap > 0) uint32 weekCap = GetCurrencyWeekCap(currency); - if (weekCap && count > int32(weekCap)) + if (!isRefund && weekCap && weekCap == oldWeekCount && count > 0) + return; + + if (!isRefund && weekCap && count > int32(weekCap)) count = weekCap; // count can't be more then totalCap if used (totalCap > 0) @@ -7262,8 +7265,8 @@ void Player::ModifyCurrency(uint32 id, int32 count, bool printLog/* = true*/, bo if (newWeekCount < 0) newWeekCount = 0; - // if we get more then weekCap just set to limit - if (weekCap && int32(weekCap) < newWeekCount) + // if we get more than weekCap just set to limit + if (!isRefund && weekCap && int32(weekCap) < newWeekCount) { newWeekCount = int32(weekCap); // weekCap - oldWeekCount always >= 0 as we set limit before! @@ -7286,9 +7289,9 @@ void Player::ModifyCurrency(uint32 id, int32 count, bool printLog/* = true*/, bo itr->second.state = PLAYERCURRENCY_CHANGED; itr->second.totalCount = newTotalCount; - itr->second.weekCount = newWeekCount; + itr->second.weekCount = isRefund ? oldWeekCount : newWeekCount; - if (count > 0) + if (!isRefund && count > 0) { UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_CURRENCY, id, count); if (hasSeasonCount) @@ -27418,7 +27421,7 @@ void Player::RefundItem(Item* item) continue; if (count && currencyid) - ModifyCurrency(currencyid, count); + ModifyCurrency(currencyid, count, false, false, true); } // Grant back money diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h index f0084f71974..9835e083268 100644 --- a/src/server/game/Entities/Player/Player.h +++ b/src/server/game/Entities/Player/Player.h @@ -1477,7 +1477,7 @@ class TC_GAME_API Player : public Unit, public GridObject * @param printLog used on SMSG_UPDATE_CURRENCY * @param ignore gain multipliers */ - void ModifyCurrency(uint32 id, int32 count, bool printLog = true, bool ignoreMultipliers = false); + void ModifyCurrency(uint32 id, int32 count, bool printLog = true, bool ignoreMultipliers = false, bool isRefund = false); void ApplyEquipCooldown(Item* pItem); void QuickEquipItem(uint16 pos, Item* pItem);