From bc52d447ab9197b04eab69d0d8a9e4cf87fbcb0a Mon Sep 17 00:00:00 2001 From: Tiaansu Date: Tue, 17 Sep 2024 11:52:13 +0800 Subject: [PATCH] fix pickup restream issues and fix possible bug on actors --- src/manipulation/float.cpp | 16 ++++++++-- src/manipulation/int.cpp | 16 ++++++++-- src/natives/actors.cpp | 56 ++++++++++++++++++++++++++++++----- src/natives/miscellaneous.cpp | 18 +++++++++-- src/streamer.cpp | 4 +-- src/utility/misc.cpp | 18 +++++++++-- 6 files changed, 111 insertions(+), 17 deletions(-) diff --git a/src/manipulation/float.cpp b/src/manipulation/float.cpp index 6881a064..ac8ffd31 100644 --- a/src/manipulation/float.cpp +++ b/src/manipulation/float.cpp @@ -1110,7 +1110,13 @@ int Manipulation::setFloatData(AMX *amx, cell *params) } if (update) { - for (std::unordered_set::const_iterator w = p->second->worlds.begin(); w != p->second->worlds.end(); ++w) + std::unordered_set worlds = p->second->worlds; + if (worlds.empty()) + { + worlds.insert(-1); + } + + for (std::unordered_set::const_iterator w = worlds.begin(); w != worlds.end(); ++w) { std::unordered_map, int, pair_hash>::iterator i = core->getData()->internalPickups.find(std::make_pair(p->first, *w)); if (i != core->getData()->internalPickups.end()) @@ -1775,7 +1781,13 @@ int Manipulation::setFloatData(AMX *amx, cell *params) } if (update) { - for (std::unordered_set::const_iterator w = a->second->worlds.begin(); w != a->second->worlds.end(); ++w) + std::unordered_set worlds = a->second->worlds; + if (worlds.empty()) + { + worlds.insert(-1); + } + + for (std::unordered_set::const_iterator w = worlds.begin(); w != worlds.end(); ++w) { std::unordered_map, int, pair_hash>::iterator i = core->getData()->internalActors.find(std::make_pair(a->first, *w)); if (i != core->getData()->internalActors.end()) diff --git a/src/manipulation/int.cpp b/src/manipulation/int.cpp index 521a2a92..296eff1b 100644 --- a/src/manipulation/int.cpp +++ b/src/manipulation/int.cpp @@ -1225,7 +1225,13 @@ int Manipulation::setIntData(AMX *amx, cell *params) } if (update) { - for (std::unordered_set::const_iterator w = p->second->worlds.begin(); w != p->second->worlds.end(); ++w) + std::unordered_set worlds = p->second->worlds; + if (worlds.empty()) + { + worlds.insert(-1); + } + + for (std::unordered_set::const_iterator w = worlds.begin(); w != worlds.end(); ++w) { std::unordered_map, int, pair_hash>::iterator i = core->getData()->internalPickups.find(std::make_pair(p->first, *w)); if (i != core->getData()->internalPickups.end()) @@ -1736,7 +1742,13 @@ int Manipulation::setIntData(AMX *amx, cell *params) } if (update) { - for (std::unordered_set::const_iterator w = a->second->worlds.begin(); w != a->second->worlds.end(); ++w) + std::unordered_set worlds = a->second->worlds; + if (worlds.empty()) + { + worlds.insert(-1); + } + + for (std::unordered_set::const_iterator w = worlds.begin(); w != worlds.end(); ++w) { std::unordered_map, int, pair_hash>::iterator i = core->getData()->internalActors.find(std::make_pair(a->first, *w)); if (i != core->getData()->internalActors.end()) diff --git a/src/natives/actors.cpp b/src/natives/actors.cpp index bbfd6eca..c008e9b1 100644 --- a/src/natives/actors.cpp +++ b/src/natives/actors.cpp @@ -85,7 +85,13 @@ cell AMX_NATIVE_CALL Natives::IsDynamicActorStreamedIn(AMX *amx, cell *params) std::unordered_map::iterator a = core->getData()->actors.find(actorId); if (a != core->getData()->actors.end()) { - for (std::unordered_set::const_iterator w = a->second->worlds.begin(); w != a->second->worlds.end(); ++w) + std::unordered_set worlds = a->second->worlds; + if (worlds.empty()) + { + worlds.insert(-1); + } + + for (std::unordered_set::const_iterator w = worlds.begin(); w != worlds.end(); ++w) { std::unordered_map, int, pair_hash>::iterator i = core->getData()->internalActors.find(std::make_pair(actorId, *w)); if (i != core->getData()->internalActors.end()) @@ -169,7 +175,13 @@ cell AMX_NATIVE_CALL Natives::ApplyDynamicActorAnimation(AMX *amx, cell *params) a->second->anim->freeze = static_cast(params[8]) != 0; a->second->anim->time = static_cast(params[9]); - for (std::unordered_set::const_iterator w = a->second->worlds.begin(); w != a->second->worlds.end(); ++w) + std::unordered_set worlds = a->second->worlds; + if (worlds.empty()) + { + worlds.insert(-1); + } + + for (std::unordered_set::const_iterator w = worlds.begin(); w != worlds.end(); ++w) { std::unordered_map, int, pair_hash>::iterator i = core->getData()->internalActors.find(std::make_pair(a->first, *w)); if (i != core->getData()->internalActors.end()) @@ -190,7 +202,13 @@ cell AMX_NATIVE_CALL Natives::ClearDynamicActorAnimations(AMX *amx, cell *params { a->second->anim = NULL; - for (std::unordered_set::const_iterator w = a->second->worlds.begin(); w != a->second->worlds.end(); ++w) + std::unordered_set worlds = a->second->worlds; + if (worlds.empty()) + { + worlds.insert(-1); + } + + for (std::unordered_set::const_iterator w = worlds.begin(); w != worlds.end(); ++w) { std::unordered_map, int, pair_hash>::iterator i = core->getData()->internalActors.find(std::make_pair(a->first, *w)); if (i != core->getData()->internalActors.end()) @@ -223,7 +241,13 @@ cell AMX_NATIVE_CALL Natives::SetDynamicActorFacingAngle(AMX *amx, cell *params) { a->second->rotation = amx_ctof(params[2]); - for (std::unordered_set::const_iterator w = a->second->worlds.begin(); w != a->second->worlds.end(); ++w) + std::unordered_set worlds = a->second->worlds; + if (worlds.empty()) + { + worlds.insert(-1); + } + + for (std::unordered_set::const_iterator w = worlds.begin(); w != worlds.end(); ++w) { std::unordered_map, int, pair_hash>::iterator i = core->getData()->internalActors.find(std::make_pair(a->first, *w)); if (i != core->getData()->internalActors.end()) @@ -268,7 +292,13 @@ cell AMX_NATIVE_CALL Natives::SetDynamicActorPos(AMX *amx, cell *params) a->second->position[1] = amx_ctof(params[3]); a->second->position[2] = amx_ctof(params[4]); - for (std::unordered_set::const_iterator w = a->second->worlds.begin(); w != a->second->worlds.end(); ++w) + std::unordered_set worlds = a->second->worlds; + if (worlds.empty()) + { + worlds.insert(-1); + } + + for (std::unordered_set::const_iterator w = worlds.begin(); w != worlds.end(); ++w) { std::unordered_map, int, pair_hash>::iterator i = core->getData()->internalActors.find(std::make_pair(a->first, *w)); if (i != core->getData()->internalActors.end()) @@ -304,7 +334,13 @@ cell AMX_NATIVE_CALL Natives::SetDynamicActorHealth(AMX *amx, cell *params) { a->second->health = amx_ctof(params[2]); - for (std::unordered_set::const_iterator w = a->second->worlds.begin(); w != a->second->worlds.end(); ++w) + std::unordered_set worlds = a->second->worlds; + if (worlds.empty()) + { + worlds.insert(-1); + } + + for (std::unordered_set::const_iterator w = worlds.begin(); w != worlds.end(); ++w) { std::unordered_map, int, pair_hash>::iterator i = core->getData()->internalActors.find(std::make_pair(a->first, *w)); if (i != core->getData()->internalActors.end()) @@ -326,7 +362,13 @@ cell AMX_NATIVE_CALL Natives::SetDynamicActorInvulnerable(AMX *amx, cell *params { a->second->invulnerable = static_cast(params[2]) != 0; - for (std::unordered_set::const_iterator w = a->second->worlds.begin(); w != a->second->worlds.end(); ++w) + std::unordered_set worlds = a->second->worlds; + if (worlds.empty()) + { + worlds.insert(-1); + } + + for (std::unordered_set::const_iterator w = worlds.begin(); w != worlds.end(); ++w) { std::unordered_map, int, pair_hash>::iterator i = core->getData()->internalActors.find(std::make_pair(a->first, *w)); if (i != core->getData()->internalActors.end()) diff --git a/src/natives/miscellaneous.cpp b/src/natives/miscellaneous.cpp index a6be5671..51370ac2 100644 --- a/src/natives/miscellaneous.cpp +++ b/src/natives/miscellaneous.cpp @@ -2092,7 +2092,14 @@ cell AMX_NATIVE_CALL Natives::Streamer_SetItemPos(AMX *amx, cell *params) core->getGrid()->removePickup(p->second, true); } } - for (std::unordered_set::const_iterator w = p->second->worlds.begin(); w != p->second->worlds.end(); ++w) + + std::unordered_set worlds = p->second->worlds; + if (worlds.empty()) + { + worlds.insert(-1); + } + + for (std::unordered_set::const_iterator w = worlds.begin(); w != worlds.end(); ++w) { std::unordered_map, int, pair_hash>::iterator i = core->getData()->internalPickups.find(std::make_pair(p->first, *w)); if (i != core->getData()->internalPickups.end()) @@ -2255,7 +2262,14 @@ cell AMX_NATIVE_CALL Natives::Streamer_SetItemPos(AMX *amx, cell *params) core->getGrid()->removeActor(a->second, true); } } - for (std::unordered_set::const_iterator w = a->second->worlds.begin(); w != a->second->worlds.end(); ++w) + + std::unordered_set worlds = a->second->worlds; + if (worlds.empty()) + { + worlds.insert(-1); + } + + for (std::unordered_set::const_iterator w = worlds.begin(); w != worlds.end(); ++w) { std::unordered_map, int, pair_hash>::iterator i = core->getData()->internalActors.find(std::make_pair(a->first, *w)); if (i != core->getData()->internalActors.end()) diff --git a/src/streamer.cpp b/src/streamer.cpp index 93754b12..e0f32f94 100644 --- a/src/streamer.cpp +++ b/src/streamer.cpp @@ -634,7 +634,7 @@ void Streamer::discoverActors(Player &player, const std::vector &cel if (d == core->getData()->discoveredActors.end()) { const int playerWorldId = *w == -1 ? -1 : player.worldId; - if (doesPlayerSatisfyConditions(a->second->players, player.playerId, a->second->interiors, player.interiorId, a->second->worlds, playerWorldId, a->second->areas, player.internalAreas, a->second->inverseAreaChecking)) + if (doesPlayerSatisfyConditions(a->second->players, player.playerId, a->second->interiors, player.interiorId, worlds, playerWorldId, a->second->areas, player.internalAreas, a->second->inverseAreaChecking)) { if (a->second->comparableStreamDistance < STREAMER_STATIC_DISTANCE_CUTOFF || boost::geometry::comparable_distance(player.position, Eigen::Vector3f(a->second->position + a->second->positionOffset)) < (a->second->comparableStreamDistance * player.radiusMultipliers[STREAMER_TYPE_ACTOR])) { @@ -1088,7 +1088,7 @@ void Streamer::discoverPickups(Player &player, const std::vector &ce if (d == core->getData()->discoveredPickups.end()) { const int playerWorldId = *w == -1 ? -1 : player.worldId; - if (doesPlayerSatisfyConditions(p->second->players, player.playerId, p->second->interiors, player.interiorId, p->second->worlds, playerWorldId, p->second->areas, player.internalAreas, p->second->inverseAreaChecking)) + if (doesPlayerSatisfyConditions(p->second->players, player.playerId, p->second->interiors, player.interiorId, worlds, playerWorldId, p->second->areas, player.internalAreas, p->second->inverseAreaChecking)) { if (p->second->comparableStreamDistance < STREAMER_STATIC_DISTANCE_CUTOFF || boost::geometry::comparable_distance(player.position, Eigen::Vector3f(p->second->position + p->second->positionOffset)) < (p->second->comparableStreamDistance * player.radiusMultipliers[STREAMER_TYPE_PICKUP])) { diff --git a/src/utility/misc.cpp b/src/utility/misc.cpp index 49e1608e..2b90c97c 100644 --- a/src/utility/misc.cpp +++ b/src/utility/misc.cpp @@ -24,7 +24,14 @@ using namespace Utility; std::unordered_map::iterator Utility::destroyActor(std::unordered_map::iterator a) { Item::Actor::identifier.remove(a->first, core->getData()->actors.size()); - for (std::unordered_set::const_iterator w = a->second->worlds.begin(); w != a->second->worlds.end(); ++w) + + std::unordered_set worlds = a->second->worlds; + if (worlds.empty()) + { + worlds.insert(-1); + } + + for (std::unordered_set::const_iterator w = worlds.begin(); w != worlds.end(); ++w) { std::unordered_map, int, pair_hash>::iterator i = core->getData()->internalActors.find(std::make_pair(a->first, *w)); if (i != core->getData()->internalActors.end()) @@ -139,7 +146,14 @@ std::unordered_map::iterator Utility::destroyObject(std std::unordered_map::iterator Utility::destroyPickup(std::unordered_map::iterator p) { Item::Pickup::identifier.remove(p->first, core->getData()->pickups.size()); - for (std::unordered_set::const_iterator w = p->second->worlds.begin(); w != p->second->worlds.end(); ++w) + + std::unordered_set worlds = p->second->worlds; + if (worlds.empty()) + { + worlds.insert(-1); + } + + for (std::unordered_set::const_iterator w = worlds.begin(); w != worlds.end(); ++w) { std::unordered_map, int, pair_hash>::iterator i = core->getData()->internalPickups.find(std::make_pair(p->first, *w)); if (i != core->getData()->internalPickups.end())