Skip to content

Commit 499f543

Browse files
committed
fix(player): Invalid CBaseEntity, CBasePlayerController, ...
1 parent 9b9b9f7 commit 499f543

File tree

1 file changed

+44
-13
lines changed

1 file changed

+44
-13
lines changed

src/plugins/core/scripting/player.cpp

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,78 +26,109 @@ PluginPlayer::~PluginPlayer()
2626

2727
GCBaseEntity* PluginPlayer::GetCBaseEntity()
2828
{
29+
Player* player = g_playerManager->GetPlayer(this->playerId);
30+
2931
if (this->ptrs.find("CBaseEntity") == this->ptrs.end())
3032
{
31-
Player* player = g_playerManager->GetPlayer(this->playerId);
32-
3333
void* ptr = (void*)(new GCBaseEntity(player->GetPlayerPawn()));
3434
this->ptrs.insert({ "CBaseEntity", ptr });
3535
}
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+
}
41+
}
3642

3743
return (GCBaseEntity*)this->ptrs.at("CBaseEntity");
3844
}
3945

4046
GCBasePlayerController* PluginPlayer::GetCBasePlayerController()
4147
{
48+
Player* player = g_playerManager->GetPlayer(this->playerId);
4249
if (this->ptrs.find("CBasePlayerController") == this->ptrs.end())
4350
{
44-
Player* player = g_playerManager->GetPlayer(this->playerId);
45-
4651
void* ptr = (void*)(new GCBasePlayerController(player->GetController()));
4752
this->ptrs.insert({ "CBasePlayerController", ptr });
4853
}
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+
}
59+
}
4960

5061
return (GCBasePlayerController*)this->ptrs.at("CBasePlayerController");
5162
}
5263

5364
GCBasePlayerPawn* PluginPlayer::GetCBasePlayerPawn()
5465
{
66+
Player* player = g_playerManager->GetPlayer(this->playerId);
5567
if (this->ptrs.find("CBasePlayerPawn") == this->ptrs.end())
5668
{
57-
Player* player = g_playerManager->GetPlayer(this->playerId);
58-
5969
void* ptr = (void*)(new GCBasePlayerPawn(player->GetPawn()));
6070
this->ptrs.insert({ "CBasePlayerPawn", ptr });
6171
}
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+
}
77+
}
6278

6379
return (GCBasePlayerPawn*)this->ptrs.at("CBasePlayerPawn");
6480
}
6581

6682
GCCSPlayerController* PluginPlayer::GetCCSPlayerController()
6783
{
84+
Player* player = g_playerManager->GetPlayer(this->playerId);
6885
if (this->ptrs.find("CCSPlayerController") == this->ptrs.end())
6986
{
70-
Player* player = g_playerManager->GetPlayer(this->playerId);
71-
72-
void* ptr = (void*)(new GCBaseEntity(player->GetPlayerController()));
87+
void* ptr = (void*)(new GCCSPlayerController(player->GetPlayerController()));
7388
this->ptrs.insert({ "CCSPlayerController", ptr });
7489
}
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+
}
95+
}
7596

7697
return (GCCSPlayerController*)this->ptrs.at("CCSPlayerController");
7798
}
7899

79100
GCCSPlayerPawn* PluginPlayer::GetCCSPlayerPawn()
80101
{
102+
Player* player = g_playerManager->GetPlayer(this->playerId);
81103
if (this->ptrs.find("CCSPlayerPawn") == this->ptrs.end())
82104
{
83-
Player* player = g_playerManager->GetPlayer(this->playerId);
84-
85105
void* ptr = (void*)(new GCCSPlayerPawn(player->GetPlayerPawn()));
86106
this->ptrs.insert({ "CCSPlayerPawn", ptr });
87107
}
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+
}
113+
}
88114

89115
return (GCCSPlayerPawn*)this->ptrs.at("CCSPlayerPawn");
90116
}
91117

92118
GCCSPlayerPawnBase* PluginPlayer::GetCCSPlayerPawnBase()
93119
{
120+
Player* player = g_playerManager->GetPlayer(this->playerId);
94121
if (this->ptrs.find("CCSPlayerPawnBase") == this->ptrs.end())
95122
{
96-
Player* player = g_playerManager->GetPlayer(this->playerId);
97-
98123
void* ptr = (void*)(new GCCSPlayerPawnBase(player->GetPlayerBasePawn()));
99124
this->ptrs.insert({ "CCSPlayerPawnBase", ptr });
100125
}
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+
}
131+
}
101132

102133
return (GCCSPlayerPawnBase*)this->ptrs.at("CCSPlayerPawnBase");
103134
}

0 commit comments

Comments
 (0)