44#include " ../../../commands/CommandsManager.h"
55#include " ../../../precacher/precacher.h"
66
7- #include " generated/classes.h"
8-
97PluginPlayer::PluginPlayer (std::string m_plugin_name, int m_playerId)
108{
119 REGISTER_CALLSTACK (this ->plugin_name , string_format (" PluginPlayer::PluginPlayer(m_plugin_name=\" %s\" , m_playerId=%d)" , m_plugin_name.c_str (), m_playerId));
@@ -14,123 +12,78 @@ PluginPlayer::PluginPlayer(std::string m_plugin_name, int m_playerId)
1412 this ->playerId = m_playerId;
1513}
1614
17- PluginPlayer::~PluginPlayer ()
18- {
19-
20- for (auto it = this ->ptrs .begin (); it != this ->ptrs .end (); ++it)
21- {
22- delete it->second ;
23- }
24- this ->ptrs .clear ();
25- }
15+ PluginPlayer::~PluginPlayer () {}
2616
27- GCBaseEntity* PluginPlayer::GetCBaseEntity ()
17+ GCBaseEntity PluginPlayer::GetCBaseEntity ()
2818{
2919 Player* player = g_playerManager->GetPlayer (this ->playerId );
30-
31- if (this ->ptrs .find (" CBaseEntity" ) == this ->ptrs .end ())
32- {
33- void * ptr = (void *)(new GCBaseEntity (player->GetPlayerPawn ()));
34- this ->ptrs .insert ({ " CBaseEntity" , ptr });
35- }
36- else {
37- if (((GCBaseEntity*)this ->ptrs .at (" CBaseEntity" ))->GetPtr () != (void *)player->GetPlayerPawn ()) {
38- delete this ->ptrs [" CBaseEntity" ];
39- this ->ptrs [" CBaseEntity" ] = (void *)(new GCBaseEntity (player->GetPlayerPawn ()));
40- }
20+ if (!player) {
21+ GCBaseEntity val (nullptr );
22+ return val;
4123 }
4224
43- return (GCBaseEntity*)this ->ptrs .at (" CBaseEntity" );
25+ GCBaseEntity val ((void *)player->GetPlayerPawn ());
26+ return val;
4427}
4528
46- GCBasePlayerController* PluginPlayer::GetCBasePlayerController ()
29+ GCBasePlayerController PluginPlayer::GetCBasePlayerController ()
4730{
4831 Player* player = g_playerManager->GetPlayer (this ->playerId );
49- if (this ->ptrs .find (" CBasePlayerController" ) == this ->ptrs .end ())
50- {
51- void * ptr = (void *)(new GCBasePlayerController (player->GetController ()));
52- this ->ptrs .insert ({ " CBasePlayerController" , ptr });
53- }
54- else {
55- if (((GCBasePlayerController*)this ->ptrs .at (" CBasePlayerController" ))->GetPtr () != (void *)player->GetController ()) {
56- delete this ->ptrs [" CBasePlayerController" ];
57- this ->ptrs [" CBasePlayerController" ] = (void *)(new GCBasePlayerController (player->GetController ()));
58- }
32+ if (!player) {
33+ GCBasePlayerController val (nullptr );
34+ return val;
5935 }
6036
61- return (GCBasePlayerController*)this ->ptrs .at (" CBasePlayerController" );
37+ GCBasePlayerController val ((void *)player->GetController ());
38+ return val;
6239}
6340
64- GCBasePlayerPawn* PluginPlayer::GetCBasePlayerPawn ()
41+ GCBasePlayerPawn PluginPlayer::GetCBasePlayerPawn ()
6542{
6643 Player* player = g_playerManager->GetPlayer (this ->playerId );
67- if (this ->ptrs .find (" CBasePlayerPawn" ) == this ->ptrs .end ())
68- {
69- void * ptr = (void *)(new GCBasePlayerPawn (player->GetPawn ()));
70- this ->ptrs .insert ({ " CBasePlayerPawn" , ptr });
71- }
72- else {
73- if (((GCBasePlayerPawn*)this ->ptrs .at (" CBasePlayerPawn" ))->GetPtr () != (void *)player->GetPawn ()) {
74- delete this ->ptrs [" CBasePlayerPawn" ];
75- this ->ptrs [" CBasePlayerPawn" ] = (void *)(new GCBasePlayerPawn (player->GetPawn ()));
76- }
44+ if (!player) {
45+ GCBasePlayerPawn val (nullptr );
46+ return val;
7747 }
7848
79- return (GCBasePlayerPawn*)this ->ptrs .at (" CBasePlayerPawn" );
49+ GCBasePlayerPawn val ((void *)player->GetPawn ());
50+ return val;
8051}
8152
82- GCCSPlayerController* PluginPlayer::GetCCSPlayerController ()
53+ GCCSPlayerController PluginPlayer::GetCCSPlayerController ()
8354{
8455 Player* player = g_playerManager->GetPlayer (this ->playerId );
85- if (this ->ptrs .find (" CCSPlayerController" ) == this ->ptrs .end ())
86- {
87- void * ptr = (void *)(new GCCSPlayerController (player->GetPlayerController ()));
88- this ->ptrs .insert ({ " CCSPlayerController" , ptr });
89- }
90- else {
91- if (((GCCSPlayerController*)this ->ptrs .at (" CCSPlayerController" ))->GetPtr () != (void *)player->GetPlayerController ()) {
92- delete this ->ptrs [" CCSPlayerController" ];
93- this ->ptrs [" CCSPlayerController" ] = (void *)(new GCCSPlayerController (player->GetPlayerController ()));
94- }
56+ if (!player) {
57+ GCCSPlayerController val (nullptr );
58+ return val;
9559 }
9660
97- return (GCCSPlayerController*)this ->ptrs .at (" CCSPlayerController" );
61+ GCCSPlayerController val ((void *)player->GetPlayerController ());
62+ return val;
9863}
9964
100- GCCSPlayerPawn* PluginPlayer::GetCCSPlayerPawn ()
65+ GCCSPlayerPawn PluginPlayer::GetCCSPlayerPawn ()
10166{
10267 Player* player = g_playerManager->GetPlayer (this ->playerId );
103- if (this ->ptrs .find (" CCSPlayerPawn" ) == this ->ptrs .end ())
104- {
105- void * ptr = (void *)(new GCCSPlayerPawn (player->GetPlayerPawn ()));
106- this ->ptrs .insert ({ " CCSPlayerPawn" , ptr });
107- }
108- else {
109- if (((GCCSPlayerPawn*)this ->ptrs .at (" CCSPlayerPawn" ))->GetPtr () != (void *)player->GetPlayerPawn ()) {
110- delete this ->ptrs [" CCSPlayerPawn" ];
111- this ->ptrs [" CCSPlayerPawn" ] = (void *)(new GCCSPlayerPawn (player->GetPlayerPawn ()));
112- }
68+ if (!player) {
69+ GCCSPlayerPawn val (nullptr );
70+ return val;
11371 }
11472
115- return (GCCSPlayerPawn*)this ->ptrs .at (" CCSPlayerPawn" );
73+ GCCSPlayerPawn val ((void *)player->GetPlayerPawn ());
74+ return val;
11675}
11776
118- GCCSPlayerPawnBase* PluginPlayer::GetCCSPlayerPawnBase ()
77+ GCCSPlayerPawnBase PluginPlayer::GetCCSPlayerPawnBase ()
11978{
12079 Player* player = g_playerManager->GetPlayer (this ->playerId );
121- if (this ->ptrs .find (" CCSPlayerPawnBase" ) == this ->ptrs .end ())
122- {
123- void * ptr = (void *)(new GCCSPlayerPawnBase (player->GetPlayerBasePawn ()));
124- this ->ptrs .insert ({ " CCSPlayerPawnBase" , ptr });
125- }
126- else {
127- if (((GCCSPlayerPawnBase*)this ->ptrs .at (" CCSPlayerPawnBase" ))->GetPtr () != (void *)player->GetPlayerBasePawn ()) {
128- delete this ->ptrs [" CCSPlayerPawnBase" ];
129- this ->ptrs [" CCSPlayerPawnBase" ] = (void *)(new GCCSPlayerPawnBase (player->GetPlayerBasePawn ()));
130- }
80+ if (!player) {
81+ GCCSPlayerPawnBase val (nullptr );
82+ return val;
13183 }
13284
133- return (GCCSPlayerPawnBase*)this ->ptrs .at (" CCSPlayerPawnBase" );
85+ GCCSPlayerPawnBase val ((void *)player->GetPlayerBasePawn ());
86+ return val;
13487}
13588
13689void PluginPlayer::Drop (int reason)
@@ -563,3 +516,21 @@ bool PluginPlayer::GetBunnyhop()
563516
564517 return self->bunnyhopState ;
565518}
519+
520+ bool PluginPlayer::IsValid ()
521+ {
522+ Player* self = g_playerManager->GetPlayer (this ->playerId );
523+ if (!self) return false ;
524+ if (self->IsFirstSpawn ()) return false ;
525+ if (self->IsFakeClient ()) return false ;
526+
527+ CBasePlayerController* controller = self->GetController ();
528+ if (!controller) return false ;
529+ if (controller->m_bIsHLTV ()) return false ;
530+ if (controller->m_iConnected () != CPlayerConnectedState::PlayerConnected) return false ;
531+
532+ CBasePlayerPawn* pawn = self->GetPawn ();
533+ if (!pawn) return false ;
534+
535+ return true ;
536+ }
0 commit comments