diff --git a/BigBaseV2/src/services/players/player.cpp b/BigBaseV2/src/services/players/player.cpp new file mode 100644 index 00000000..94c69b32 --- /dev/null +++ b/BigBaseV2/src/services/players/player.cpp @@ -0,0 +1,84 @@ +#include "player.hpp" +#include "CNetGamePlayer.hpp" +#include "services/friends/friends_service.hpp" + +namespace big +{ + player::player(CNetGamePlayer* net_game_player) + : m_net_game_player(net_game_player) + { + m_is_friend = friends_service::is_friend(net_game_player); + } + + CAutomobile* player::get_current_vehicle() const + { + if (const auto ped = this->get_ped(); ped != nullptr) + if (const auto vehicle = ped->m_vehicle; vehicle != nullptr) + return vehicle; + return nullptr; + } + + const char* player::get_name() const + { + return m_net_game_player == nullptr ? "" : m_net_game_player->get_name(); + } + + rage::netPlayerData* player::get_net_data() const + { + return m_net_game_player == nullptr ? nullptr : m_net_game_player->get_net_data(); + } + + CNetGamePlayer* player::get_net_game_player() const + { + return m_net_game_player; + } + + CPed* player::get_ped() const + { + if (const auto player_info = this->get_player_info(); player_info != nullptr) + if (const auto ped = player_info->m_ped; ped != nullptr) + return ped; + return nullptr; + } + + CPlayerInfo* player::get_player_info() const + { + if (m_net_game_player != nullptr && m_net_game_player->m_player_info != nullptr) + return m_net_game_player->m_player_info; + return nullptr; + } + + uint8_t player::id() const + { + return m_net_game_player == nullptr ? -1 : m_net_game_player->m_player_id; + } + + bool player::is_host() const + { + return m_net_game_player == nullptr ? false : m_net_game_player->is_host(); + } + + bool player::is_friend() const + { + return m_is_friend; + } + + + bool player::is_valid() const + { + return m_net_game_player == nullptr ? false : m_net_game_player->is_valid(); + } + + bool player::equals(const CNetGamePlayer* net_game_player) const + { + return net_game_player == m_net_game_player; + } + + std::string player::to_lowercase_identifier() const + { + std::string lower = this->get_name(); + std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower); + + return lower; + } +} diff --git a/BigBaseV2/src/services/players/player.hpp b/BigBaseV2/src/services/players/player.hpp new file mode 100644 index 00000000..93171010 --- /dev/null +++ b/BigBaseV2/src/services/players/player.hpp @@ -0,0 +1,45 @@ +#pragma once +#include "player_service.hpp" + +namespace big +{ + class player final + { + friend class player_service; + + CNetGamePlayer* m_net_game_player = nullptr; + std::string m_identifier; + bool m_is_friend; + + public: + explicit player(CNetGamePlayer* net_game_player); + ~player() = default; + + player(const player&) = default; + player(player&&) noexcept = default; + player& operator=(const player&) = default; + player& operator=(player&&) noexcept = default; + + float screen_position_x = -1.f; + float screen_position_y = -1.f; + + [[nodiscard]] CAutomobile* get_current_vehicle() const; + [[nodiscard]] const char* get_name() const; + [[nodiscard]] rage::netPlayerData* get_net_data() const; + [[nodiscard]] CNetGamePlayer* get_net_game_player() const; + [[nodiscard]] CPed* get_ped() const; + [[nodiscard]] CPlayerInfo* get_player_info() const; + + [[nodiscard]] uint8_t id() const; + + [[nodiscard]] bool is_friend() const; + [[nodiscard]] bool is_host() const; + [[nodiscard]] bool is_valid() const; + + protected: + bool equals(const CNetGamePlayer* net_game_player) const; + + [[nodiscard]] std::string to_lowercase_identifier() const; + + }; +} \ No newline at end of file diff --git a/BigBaseV2/src/services/players/player_service.cpp b/BigBaseV2/src/services/players/player_service.cpp index cfaa0de1..571cd4b8 100644 --- a/BigBaseV2/src/services/players/player_service.cpp +++ b/BigBaseV2/src/services/players/player_service.cpp @@ -1,89 +1,10 @@ #include "gta_util.hpp" #include "player_service.hpp" -#include "services/friends/friends_service.hpp" namespace big { - player::player(CNetGamePlayer* net_game_player) - : m_net_game_player(net_game_player) - { - m_is_friend = friends_service::is_friend(net_game_player); - } - - CAutomobile* player::get_current_vehicle() const - { - if (const auto ped = this->get_ped(); ped != nullptr) - if (const auto vehicle = ped->m_vehicle; vehicle != nullptr) - return vehicle; - return nullptr; - } - - const char* player::get_name() const - { - return m_net_game_player == nullptr ? "" : m_net_game_player->get_name(); - } - - rage::netPlayerData* player::get_net_data() const - { - return m_net_game_player == nullptr ? nullptr : m_net_game_player->get_net_data(); - } - - CNetGamePlayer* player::get_net_game_player() const - { - return m_net_game_player; - } - - CPed* player::get_ped() const - { - if (const auto player_info = this->get_player_info(); player_info != nullptr) - if (const auto ped = player_info->m_ped; ped != nullptr) - return ped; - return nullptr; - } - - CPlayerInfo* player::get_player_info() const - { - if (m_net_game_player != nullptr && m_net_game_player->m_player_info != nullptr) - return m_net_game_player->m_player_info; - return nullptr; - } - - uint8_t player::id() const - { - return m_net_game_player == nullptr ? -1 : m_net_game_player->m_player_id; - } - - bool player::is_host() const - { - return m_net_game_player == nullptr ? false : m_net_game_player->is_host(); - } - - bool player::is_friend() const - { - return m_is_friend; - } - - - bool player::is_valid() const - { - return m_net_game_player == nullptr ? false : m_net_game_player->is_valid(); - } - - bool player::equals(const CNetGamePlayer* net_game_player) const - { - return net_game_player == m_net_game_player; - } - - std::string player::to_lowercase_identifier() const - { - std::string lower = this->get_name(); - std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower); - - return lower; - } - player_service::player_service() - : m_selected_player(m_dummy) + : m_self(), m_selected_player(m_dummy) { g_player_service = this; diff --git a/BigBaseV2/src/services/players/player_service.hpp b/BigBaseV2/src/services/players/player_service.hpp index a8a0b192..9f7a7c6d 100644 --- a/BigBaseV2/src/services/players/player_service.hpp +++ b/BigBaseV2/src/services/players/player_service.hpp @@ -1,47 +1,9 @@ #pragma once +#include "player.hpp" namespace big { - class player_service; - class player final - { - friend player_service; - - CNetGamePlayer* m_net_game_player = nullptr; - std::string m_identifier; - bool m_is_friend; - - public: - explicit player(CNetGamePlayer* net_game_player); - ~player() = default; - - player(const player&) = default; - player(player&&) noexcept = default; - player& operator=(const player&) = default; - player& operator=(player&&) noexcept = default; - - float screen_position_x = -1.f; - float screen_position_y = -1.f; - - [[nodiscard]] CAutomobile* get_current_vehicle() const; - [[nodiscard]] const char* get_name() const; - [[nodiscard]] rage::netPlayerData* get_net_data() const; - [[nodiscard]] CNetGamePlayer* get_net_game_player() const; - [[nodiscard]] CPed* get_ped() const; - [[nodiscard]] CPlayerInfo* get_player_info() const; - - [[nodiscard]] uint8_t id() const; - - [[nodiscard]] bool is_friend() const; - [[nodiscard]] bool is_host() const; - [[nodiscard]] bool is_valid() const; - - protected: - bool equals(const CNetGamePlayer* net_game_player) const; - - [[nodiscard]] std::string to_lowercase_identifier() const; - - }; + class player; using player_ptr = std::shared_ptr; using players = std::map;