forked from Pelipoika/The-unfinished-and-abandoned
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GetCondition.sp
129 lines (104 loc) · 3.04 KB
/
GetCondition.sp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <sdktools>
#include <sdkhooks>
#include <tf2_stocks>
#pragma newdecls required;
public Plugin myinfo =
{
name = "[TF2] CTFPlayerShared::GetConditionDuration & GetConditionProvider",
author = "Pelipoika",
description = "",
version = "",
url = "http://www.sourcemod.net/plugins.php?author=Pelipoika&search=1"
};
public void OnPluginStart()
{
RegAdminCmd("sm_getmyconds", Command_Get, ADMFLAG_BAN);
}
#define Pointer Address
#define nullptr Address_Null
#define Address(%1) view_as<Address>(%1)
#define int(%1) view_as<int>(%1)
public Action Command_Get(int client, int argc)
{
if(client <= 0 || client > MaxClients || !IsClientInGame(client))
return Plugin_Handled;
PrintToServer("( Server ) Conditions for player ( %N )", client);
bool bAnyCondActive = false;
for (TFCond cond = TFCond_Zoomed; cond <= TFCond_CompetitiveWinner; cond++)
{
if(!TF2_IsPlayerInCondition(client, cond))
continue;
bAnyCondActive = true;
float flDuration = GetConditionDuration(client, cond);
int iProvider = GetConditionProvider(client, cond);
if (flDuration == TFCondDuration_Infinite)
{
if(iProvider == 0)
{
PrintToServer("( Server ) Condition %d - ( permanent cond )", cond);
}
else
{
PrintToServer("( Server ) Condition %d - ( permanent cond ) - ( provided by %d )", cond, iProvider);
}
}
else
{
if(iProvider == 0)
{
PrintToServer("( Server ) Condition %d - ( %.1f left )", cond, flDuration);
}
else
{
PrintToServer("( Server ) Condition %d - ( %.1f left ) - ( provided by %d )", cond, flDuration, iProvider);
}
}
}
if(!bAnyCondActive)
PrintToServer("( Server ) No active conditions");
return Plugin_Handled;
}
stock float GetConditionDuration(int client, TFCond cond)
{
int m_Shared = FindSendPropInfo("CTFPlayer", "m_Shared");
Address aCondSource = Address(ReadInt(GetEntityAddress(client) + Address(m_Shared + 8)));
Address aCondDuration = Address(int(aCondSource) + (int(cond) * 20) + (2 * 4));
float flDuration = 0.0;
if(TF2_IsPlayerInCondition(client, cond))
{
flDuration = view_as<float>(ReadInt(aCondDuration));
}
return flDuration;
}
stock int GetConditionProvider(int client, TFCond cond)
{
int m_Shared = FindSendPropInfo("CTFPlayer", "m_Shared");
Address aCondSource = Address(ReadInt(GetEntityAddress(client) + Address(m_Shared + 8)));
Address aCondProvider = Address(int(aCondSource) + (int(cond) * 20) + (3 * 4));
int iProvider = 0;
if(TF2_IsPlayerInCondition(client, cond))
{
iProvider = (ReadInt(aCondProvider) & 0xFFF);
}
return iProvider;
}
stock Pointer Transpose(Pointer pAddr, int iOffset)
{
return Address(int(pAddr) + iOffset);
}
stock int Dereference(Pointer pAddr, int iOffset = 0)
{
if(pAddr == nullptr)
{
return -1;
}
return ReadInt(Transpose(pAddr, iOffset));
}
stock int ReadInt(Pointer pAddr)
{
if(pAddr == nullptr)
{
return -1;
}
return LoadFromAddress(pAddr, NumberType_Int32);
}