From 6a4ee2b282c9c5a8e43445e353ac7cad3eec6a6c Mon Sep 17 00:00:00 2001 From: mentolixite Date: Tue, 5 Jul 2022 22:35:32 +0200 Subject: [PATCH] fix(ViewPlayer): Make "never wanted" feature independent for each player (#316) Co-authored-by: Yimura --- BigBaseV2/src/backend/backend.cpp | 6 +++++- BigBaseV2/src/backend/looped/looped.hpp | 5 ++++- BigBaseV2/src/backend/looped/player/player_never_wanted.cpp | 6 +++--- BigBaseV2/src/core/globals.hpp | 1 - BigBaseV2/src/services/players/player.hpp | 2 ++ BigBaseV2/src/services/players/player_service.hpp | 4 ++++ BigBaseV2/src/views/players/view_player.cpp | 2 +- 7 files changed, 19 insertions(+), 7 deletions(-) diff --git a/BigBaseV2/src/backend/backend.cpp b/BigBaseV2/src/backend/backend.cpp index 1e093440..ef7c0a1d 100644 --- a/BigBaseV2/src/backend/backend.cpp +++ b/BigBaseV2/src/backend/backend.cpp @@ -134,7 +134,11 @@ namespace big while (g_running) { - looped::player_never_wanted(); + g_player_service->iterate([](const player_entry &entry) + { + looped::player_never_wanted(entry.second); + }); + looped::player_spectate(); script::get_current()->yield(); diff --git a/BigBaseV2/src/backend/looped/looped.hpp b/BigBaseV2/src/backend/looped/looped.hpp index db95728d..521f6c6f 100644 --- a/BigBaseV2/src/backend/looped/looped.hpp +++ b/BigBaseV2/src/backend/looped/looped.hpp @@ -1,6 +1,9 @@ #pragma once + #include "common.hpp" +#include "services/players/player_service.hpp" + namespace big { class looped { @@ -16,7 +19,7 @@ namespace big static void tunables_disable_phone(); static void tunables_no_idle_kick(); - static void player_never_wanted(); + static void player_never_wanted(const player_ptr &player); static void player_spectate(); static void protections_replay_interface(); diff --git a/BigBaseV2/src/backend/looped/player/player_never_wanted.cpp b/BigBaseV2/src/backend/looped/player/player_never_wanted.cpp index 0e05e751..cc3ae7df 100644 --- a/BigBaseV2/src/backend/looped/player/player_never_wanted.cpp +++ b/BigBaseV2/src/backend/looped/player/player_never_wanted.cpp @@ -4,11 +4,11 @@ namespace big { - void looped::player_never_wanted() + void looped::player_never_wanted(const player_ptr &player) { - if (g->player.player_never_wanted && g_player_service->get_selected()->is_valid()) + if (player->never_wanted) { - globals::clear_wanted_player(g_player_service->get_selected()->id()); + globals::clear_wanted_player(player->id()); } } } diff --git a/BigBaseV2/src/core/globals.hpp b/BigBaseV2/src/core/globals.hpp index fe60b315..ba60aaa2 100644 --- a/BigBaseV2/src/core/globals.hpp +++ b/BigBaseV2/src/core/globals.hpp @@ -87,7 +87,6 @@ namespace big struct player { int character_slot = 1; - bool player_never_wanted = false; int set_level = 130; bool spectating = false; }; diff --git a/BigBaseV2/src/services/players/player.hpp b/BigBaseV2/src/services/players/player.hpp index 93171010..5b19e1ae 100644 --- a/BigBaseV2/src/services/players/player.hpp +++ b/BigBaseV2/src/services/players/player.hpp @@ -36,6 +36,8 @@ namespace big [[nodiscard]] bool is_host() const; [[nodiscard]] bool is_valid() const; + bool never_wanted = false; + protected: bool equals(const CNetGamePlayer* net_game_player) const; diff --git a/BigBaseV2/src/services/players/player_service.hpp b/BigBaseV2/src/services/players/player_service.hpp index 9f7a7c6d..f89e4cb0 100644 --- a/BigBaseV2/src/services/players/player_service.hpp +++ b/BigBaseV2/src/services/players/player_service.hpp @@ -6,6 +6,7 @@ namespace big class player; using player_ptr = std::shared_ptr; + using player_entry = std::pair; using players = std::map; class player_service final @@ -43,6 +44,9 @@ namespace big players& players() { return m_players; } + void iterate(const std::function< void(const player_entry &entry) > func) + { for (const auto &iter : m_players) func(iter); } + void set_selected(player_ptr plyr); }; diff --git a/BigBaseV2/src/views/players/view_player.cpp b/BigBaseV2/src/views/players/view_player.cpp index 1054ec1b..1aa05569 100644 --- a/BigBaseV2/src/views/players/view_player.cpp +++ b/BigBaseV2/src/views/players/view_player.cpp @@ -41,7 +41,7 @@ namespace big ImGui::SameLine(); - ImGui::Checkbox("Never Wanted", &g->player.player_never_wanted); + ImGui::Checkbox("Never Wanted", &g_player_service->get_selected()->never_wanted); components::button("Give Health", [] { g_pickup_service->give_player_health(g_player_service->get_selected()->id());