From b6453376e43411bc16a69e784fadea148fe5cefd Mon Sep 17 00:00:00 2001 From: Jett <55758076+Jettford@users.noreply.github.com> Date: Sat, 11 Dec 2021 13:21:00 +0000 Subject: [PATCH 1/5] patched coin exploit --- dGame/Entity.cpp | 18 ++++++++++++++++++ dGame/Entity.h | 3 +++ dGame/Player.cpp | 9 +++++++++ dGame/Player.h | 6 ++++++ dGame/dGameMessages/GameMessages.cpp | 10 +++++++++- 5 files changed, 45 insertions(+), 1 deletion(-) diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index c98323a9..9f16d456 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -1644,6 +1644,24 @@ void Entity::PickupItem(const LWOOBJID& objectID) { droppedLoot.erase(objectID); } +bool Entity::PickupCoins(uint64_t count) { // bool because we are returning whether they can pick up the coins + if (!IsPlayer()) return false; + auto droppedcoins = static_cast(this)->GetDroppedCoins(); + if (count > droppedcoins) { + return false; + } else { + static_cast(this)->SetDroppedCoins(droppedcoins - count); + return true; + } +} + +void Entity::DropCoins(uint64_t count) { + if (!IsPlayer()) return; + auto droppedcoins = static_cast(this)->GetDroppedCoins(); + droppedcoins += count; + static_cast(this)->SetDroppedCoins(droppedcoins); +} + void Entity::AddChild(Entity* child) { m_ChildEntities.push_back(child); } diff --git a/dGame/Entity.h b/dGame/Entity.h index 01699a84..4b83b894 100644 --- a/dGame/Entity.h +++ b/dGame/Entity.h @@ -202,6 +202,9 @@ public: void AddLootItem(const Loot::Info& info); void PickupItem(const LWOOBJID& objectID); + bool PickupCoins(uint64_t count); + void DropCoins(uint64_t count); + void ScheduleKillAfterUpdate(Entity* murderer = nullptr); void TriggerEvent(std::string eveneventtID, Entity* optionalTarget = nullptr); void ScheduleDestructionAfterUpdate() { m_ShouldDestroyAfterUpdate = true; } diff --git a/dGame/Player.cpp b/dGame/Player.cpp index 9a158c8f..634d4a68 100644 --- a/dGame/Player.cpp +++ b/dGame/Player.cpp @@ -24,6 +24,7 @@ Player::Player(const LWOOBJID& objectID, const EntityInfo info, User* user, Enti m_GMLevel = m_Character->GetGMLevel(); m_SystemAddress = m_ParentUser->GetSystemAddress(); m_DroppedLoot = {}; + m_DroppedCoins = 0; m_GhostReferencePoint = NiPoint3::ZERO; m_GhostOverridePoint = NiPoint3::ZERO; @@ -290,6 +291,14 @@ const std::vector& Player::GetAllPlayers() return m_Players; } +uint64_t Player::GetDroppedCoins() { + return m_DroppedCoins; +} + +void Player::SetDroppedCoins(uint64_t value) { + m_DroppedCoins = value; +} + Player::~Player() { Game::logger->Log("Player", "Deleted player\n"); diff --git a/dGame/Player.h b/dGame/Player.h index abd811c5..bba01363 100644 --- a/dGame/Player.h +++ b/dGame/Player.h @@ -36,6 +36,8 @@ public: std::map& GetDroppedLoot(); + uint64_t GetDroppedCoins(); + /** * Setters */ @@ -52,6 +54,8 @@ public: void SetGhostOverride(bool value); + void SetDroppedCoins(uint64_t value); + /** * Wrapper for sending an in-game mail. * @@ -126,5 +130,7 @@ private: std::map m_DroppedLoot; + uint64_t m_DroppedCoins; + static std::vector m_Players; }; diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index c6b3c9bd..727c704c 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -1031,6 +1031,10 @@ void GameMessages::SendDropClientLoot(Entity* entity, const LWOOBJID& sourceID, entity->AddLootItem(info); } + if (item == LOT_NULL && currency != 0) { + entity->DropCoins(currency); + } + if (spawnPos != NiPoint3::ZERO) { bUsePosition = true; @@ -5232,8 +5236,12 @@ void GameMessages::HandlePickupCurrency(RakNet::BitStream* inStream, Entity* ent unsigned int currency; inStream->Read(currency); + if (currency == 0) return; + auto* ch = entity->GetCharacter(); - ch->SetCoins(ch->GetCoins() + currency); + if (entity->PickupCoins(currency)) { + ch->SetCoins(ch->GetCoins() + currency); + } } void GameMessages::HandleRequestDie(RakNet::BitStream* inStream, Entity* entity) { From 22de531ab3b43c1db358a6510b51370d35d22113 Mon Sep 17 00:00:00 2001 From: Jett <55758076+Jettford@users.noreply.github.com> Date: Sat, 11 Dec 2021 13:57:15 +0000 Subject: [PATCH 2/5] Changes asked for by Wincent --- dGame/Entity.cpp | 4 ++-- dGame/Entity.h | 4 ++-- dGame/dGameMessages/GameMessages.cpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index 9f16d456..089452ae 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -1644,7 +1644,7 @@ void Entity::PickupItem(const LWOOBJID& objectID) { droppedLoot.erase(objectID); } -bool Entity::PickupCoins(uint64_t count) { // bool because we are returning whether they can pick up the coins +bool Entity::CanPickupCoins(uint64_t count) { // bool because we are returning whether they can pick up the coins if (!IsPlayer()) return false; auto droppedcoins = static_cast(this)->GetDroppedCoins(); if (count > droppedcoins) { @@ -1655,7 +1655,7 @@ bool Entity::PickupCoins(uint64_t count) { // bool because we are returning whet } } -void Entity::DropCoins(uint64_t count) { +void Entity::RegisterCoinDrop(uint64_t count) { if (!IsPlayer()) return; auto droppedcoins = static_cast(this)->GetDroppedCoins(); droppedcoins += count; diff --git a/dGame/Entity.h b/dGame/Entity.h index 4b83b894..31b2b303 100644 --- a/dGame/Entity.h +++ b/dGame/Entity.h @@ -202,8 +202,8 @@ public: void AddLootItem(const Loot::Info& info); void PickupItem(const LWOOBJID& objectID); - bool PickupCoins(uint64_t count); - void DropCoins(uint64_t count); + bool CanPickupCoins(uint64_t count); + void RegisterCoinDrop(uint64_t count); void ScheduleKillAfterUpdate(Entity* murderer = nullptr); void TriggerEvent(std::string eveneventtID, Entity* optionalTarget = nullptr); diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index 727c704c..fad5d7de 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -1032,7 +1032,7 @@ void GameMessages::SendDropClientLoot(Entity* entity, const LWOOBJID& sourceID, } if (item == LOT_NULL && currency != 0) { - entity->DropCoins(currency); + entity->RegisterCoinDrop(currency); } if (spawnPos != NiPoint3::ZERO) { @@ -5239,7 +5239,7 @@ void GameMessages::HandlePickupCurrency(RakNet::BitStream* inStream, Entity* ent if (currency == 0) return; auto* ch = entity->GetCharacter(); - if (entity->PickupCoins(currency)) { + if (entity->CanPickupCoins(currency)) { ch->SetCoins(ch->GetCoins() + currency); } } From 6427b097ab9415e32d69768e519a777bc8f7679a Mon Sep 17 00:00:00 2001 From: Jett <55758076+Jettford@users.noreply.github.com> Date: Sat, 11 Dec 2021 14:22:39 +0000 Subject: [PATCH 3/5] Replace two casts with one --- dGame/Entity.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index 089452ae..0579035e 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -1646,11 +1646,12 @@ void Entity::PickupItem(const LWOOBJID& objectID) { bool Entity::CanPickupCoins(uint64_t count) { // bool because we are returning whether they can pick up the coins if (!IsPlayer()) return false; - auto droppedcoins = static_cast(this)->GetDroppedCoins(); + auto * player = static_cast(this); + auto droppedcoins = player->GetDroppedCoins(); if (count > droppedcoins) { return false; } else { - static_cast(this)->SetDroppedCoins(droppedcoins - count); + player->SetDroppedCoins(droppedcoins - count); return true; } } From 94e32a577348b119c65f79d9cd101f13a1d400cb Mon Sep 17 00:00:00 2001 From: Jett <55758076+Jettford@users.noreply.github.com> Date: Sat, 11 Dec 2021 14:24:25 +0000 Subject: [PATCH 4/5] replace the other double cast --- dGame/Entity.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index 0579035e..dbb44f2f 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -1658,9 +1658,10 @@ bool Entity::CanPickupCoins(uint64_t count) { // bool because we are returning w void Entity::RegisterCoinDrop(uint64_t count) { if (!IsPlayer()) return; - auto droppedcoins = static_cast(this)->GetDroppedCoins(); + auto * player = static_cast(this); + auto droppedcoins = player->GetDroppedCoins(); droppedcoins += count; - static_cast(this)->SetDroppedCoins(droppedcoins); + player->SetDroppedCoins(droppedcoins); } void Entity::AddChild(Entity* child) { From bb508e91c1d52de0b97b33edd1bbcf7721a9f08a Mon Sep 17 00:00:00 2001 From: wincent Date: Sat, 11 Dec 2021 17:33:54 +0100 Subject: [PATCH 5/5] Update the code style When applied this commit updates the code style used when validating coin pickups. --- dGame/Entity.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index dbb44f2f..ad9b8cd5 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -1644,24 +1644,24 @@ void Entity::PickupItem(const LWOOBJID& objectID) { droppedLoot.erase(objectID); } -bool Entity::CanPickupCoins(uint64_t count) { // bool because we are returning whether they can pick up the coins +bool Entity::CanPickupCoins(uint64_t count) { if (!IsPlayer()) return false; - auto * player = static_cast(this); - auto droppedcoins = player->GetDroppedCoins(); - if (count > droppedcoins) { + auto* player = static_cast(this); + auto droppedCoins = player->GetDroppedCoins(); + if (count > droppedCoins) { return false; } else { - player->SetDroppedCoins(droppedcoins - count); + player->SetDroppedCoins(droppedCoins - count); return true; } } void Entity::RegisterCoinDrop(uint64_t count) { if (!IsPlayer()) return; - auto * player = static_cast(this); - auto droppedcoins = player->GetDroppedCoins(); - droppedcoins += count; - player->SetDroppedCoins(droppedcoins); + auto* player = static_cast(this); + auto droppedCoins = player->GetDroppedCoins(); + droppedCoins += count; + player->SetDroppedCoins(droppedCoins); } void Entity::AddChild(Entity* child) {