Merge pull request #180 from OogwayUniverse/coin_exploit

Patched coin exploit
This commit is contained in:
Wincent Holm 2021-12-11 17:40:59 +01:00 committed by GitHub
commit 95d1c65011
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 1 deletions

View File

@ -1644,6 +1644,26 @@ void Entity::PickupItem(const LWOOBJID& objectID) {
droppedLoot.erase(objectID);
}
bool Entity::CanPickupCoins(uint64_t count) {
if (!IsPlayer()) return false;
auto* player = static_cast<Player*>(this);
auto droppedCoins = player->GetDroppedCoins();
if (count > droppedCoins) {
return false;
} else {
player->SetDroppedCoins(droppedCoins - count);
return true;
}
}
void Entity::RegisterCoinDrop(uint64_t count) {
if (!IsPlayer()) return;
auto* player = static_cast<Player*>(this);
auto droppedCoins = player->GetDroppedCoins();
droppedCoins += count;
player->SetDroppedCoins(droppedCoins);
}
void Entity::AddChild(Entity* child) {
m_ChildEntities.push_back(child);
}

View File

@ -202,6 +202,9 @@ public:
void AddLootItem(const Loot::Info& info);
void PickupItem(const LWOOBJID& objectID);
bool CanPickupCoins(uint64_t count);
void RegisterCoinDrop(uint64_t count);
void ScheduleKillAfterUpdate(Entity* murderer = nullptr);
void TriggerEvent(std::string eveneventtID, Entity* optionalTarget = nullptr);
void ScheduleDestructionAfterUpdate() { m_ShouldDestroyAfterUpdate = true; }

View File

@ -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*>& 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");

View File

@ -36,6 +36,8 @@ public:
std::map<LWOOBJID, Loot::Info>& 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<LWOOBJID, Loot::Info> m_DroppedLoot;
uint64_t m_DroppedCoins;
static std::vector<Player*> m_Players;
};

View File

@ -1031,6 +1031,10 @@ void GameMessages::SendDropClientLoot(Entity* entity, const LWOOBJID& sourceID,
entity->AddLootItem(info);
}
if (item == LOT_NULL && currency != 0) {
entity->RegisterCoinDrop(currency);
}
if (spawnPos != NiPoint3::ZERO) {
bUsePosition = true;
@ -5232,9 +5236,13 @@ void GameMessages::HandlePickupCurrency(RakNet::BitStream* inStream, Entity* ent
unsigned int currency;
inStream->Read(currency);
if (currency == 0) return;
auto* ch = entity->GetCharacter();
if (entity->CanPickupCoins(currency)) {
ch->SetCoins(ch->GetCoins() + currency);
}
}
void GameMessages::HandleRequestDie(RakNet::BitStream* inStream, Entity* entity) {
LWOOBJID killerID;