From 57060e9b6f4e4e3f7f74496b3f4d34fa2732dda2 Mon Sep 17 00:00:00 2001 From: Gent S Date: Thu, 26 Nov 2020 11:03:42 -0500 Subject: [PATCH] Fix spawning in the unknown when no Resurrect 'Ems are nearby --- src/PlayerManager.cpp | 26 ++++++++++++++++---------- src/PlayerManager.hpp | 2 +- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/PlayerManager.cpp b/src/PlayerManager.cpp index 1023bd6..c77234f 100644 --- a/src/PlayerManager.cpp +++ b/src/PlayerManager.cpp @@ -702,7 +702,7 @@ void PlayerManager::revivePlayer(CNSocket* sock, CNPacketData* data) { if (plr == nullptr) return; - WarpLocation target = PlayerManager::getRespawnPoint(plr); + WarpLocation* target = PlayerManager::getRespawnPoint(plr); sP_CL2FE_REQ_PC_REGEN* reviveData = (sP_CL2FE_REQ_PC_REGEN*)data->buf; INITSTRUCT(sP_FE2CL_REP_PC_REGEN_SUCC, response); @@ -737,9 +737,15 @@ void PlayerManager::revivePlayer(CNSocket* sock, CNPacketData* data) { // Response parameters response.PCRegenData.iActiveNanoSlotNum = activeSlot; - response.PCRegenData.iX = move ? target.x : plr->x; - response.PCRegenData.iY = move ? target.y : plr->y; - response.PCRegenData.iZ = move ? target.z : plr->z; + if (move && target != nullptr) { + response.PCRegenData.iX = target->x; + response.PCRegenData.iY = target->y; + response.PCRegenData.iZ = target->z; + } else { + response.PCRegenData.iX = plr->x; + response.PCRegenData.iY = plr->y; + response.PCRegenData.iZ = plr->z; + } response.PCRegenData.iHP = plr->HP; response.iFusionMatter = plr->fusionmatter; response.bMoveLocation = 0; @@ -761,11 +767,11 @@ void PlayerManager::revivePlayer(CNSocket* sock, CNPacketData* data) { sendToViewable(sock, (void*)&resp2, P_FE2CL_PC_REGEN, sizeof(sP_FE2CL_PC_REGEN)); - if (!move) + if (!move || target == nullptr) return; ChunkManager::updatePlayerChunk(sock, plr->chunkPos, std::make_tuple(0, 0, 0)); // force player to reload chunks - updatePlayerPosition(sock, target.x, target.y, target.z, plr->instanceID, plr->angle); + updatePlayerPosition(sock, target->x, target->y, target->z, plr->instanceID, plr->angle); } void PlayerManager::enterPlayerVehicle(CNSocket* sock, CNPacketData* data) { @@ -875,14 +881,14 @@ std::string PlayerManager::getPlayerName(Player *plr, bool id) { return ret; } -WarpLocation PlayerManager::getRespawnPoint(Player *plr) { - WarpLocation best; +WarpLocation* PlayerManager::getRespawnPoint(Player *plr) { + WarpLocation* best = nullptr; uint32_t curDist, bestDist = UINT32_MAX; - for (auto targ : NPCManager::RespawnPoints) { + for (auto& targ : NPCManager::RespawnPoints) { curDist = sqrt(pow(plr->x - targ.x, 2) + pow(plr->y - targ.y, 2)); if (curDist < bestDist && targ.instanceID == MAPNUM(plr->instanceID)) { // only mapNum needs to match - best = targ; + best = &targ; bestDist = curDist; } } diff --git a/src/PlayerManager.hpp b/src/PlayerManager.hpp index e99ac65..25b0aad 100644 --- a/src/PlayerManager.hpp +++ b/src/PlayerManager.hpp @@ -52,7 +52,7 @@ namespace PlayerManager { Player *getPlayer(CNSocket* key); std::string getPlayerName(Player *plr, bool id=true); - WarpLocation getRespawnPoint(Player *plr); + WarpLocation* getRespawnPoint(Player *plr); bool isAccountInUse(int accountId); void exitDuplicate(int accountId);