-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
stac_memory.sp
executable file
·207 lines (179 loc) · 5.72 KB
/
stac_memory.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
Gamedata
*/
void DoStACGamedata()
{
// Our base gamedata file
stac_gamedata = LoadGameConfigFile("stac");
if (!stac_gamedata)
{
SetFailState("Failed to load StAC gamedata.");
return;
}
// MEMORY OFFSETS
/*
Memory offsets
*/
{
// offset from client's signon state, offset from CBaseClient::this (?)
Offset_SignonState = view_as<Address>( GameConfGetOffset(stac_gamedata, "Offset_SignonState") );
// Hack, see gamedata
Offset_IClient_HACK = view_as<Address>( GameConfGetOffset(stac_gamedata, "Offset_IClient_HACK") );
}
// SIGNATURES
/*
CNetChan::ProcessPacket - for getting client's signonstate
*/
{
Handle hProcessPacket = DHookCreateFromConf(stac_gamedata, "CNetChan::ProcessPacket");
if (!hProcessPacket)
{
SetFailState("Failed to setup detour for CNetChan::ProcessPacket");
}
// detour
if ( !DHookEnableDetour(hProcessPacket, false, Detour_CNetChan__ProcessPacket) )
{
SetFailState("Failed to detour CNetChan::ProcessPacket.");
}
PrintToServer("CNetChan::ProcessPacket detoured!");
}
/*
CBasePlayer::ProcessUsercmds - for eating usercmds from players who aren't signed on
*/
{
Handle CBasePlayer__ProcessUsercmds = DHookCreateFromConf( stac_gamedata, "CBasePlayer::ProcessUsercmds" );
if ( !CBasePlayer__ProcessUsercmds )
{
SetFailState( "Failed to setup detour for CBasePlayer::ProcessUsercmds" );
}
// detour
if ( !DHookEnableDetour( CBasePlayer__ProcessUsercmds, false, Detour_CBasePlayer__ProcessUsercmds ) )
{
SetFailState( "Failed to detour CBasePlayer::ProcessUsercmds." );
}
PrintToServer( "CBasePlayer::ProcessUsercmds detoured!" );
}
// VTABLE OFFSETS
/*
CBaseClient::GetPlayerSlot - for converting IClient* to ent idx
*/
{
StartPrepSDKCall( SDKCall_Raw );
PrepSDKCall_SetFromConf( stac_gamedata, SDKConf_Virtual, "CBaseClient::GetPlayerSlot" );
PrepSDKCall_SetReturnInfo( SDKType_PlainOldData, SDKPass_Plain );
SDKCall_GetPlayerSlot = EndPrepSDKCall();
if ( SDKCall_GetPlayerSlot != INVALID_HANDLE )
{
PrintToServer( "CBaseClient::GetPlayerSlot set up!" );
}
else
{
SetFailState( "Failed to get CBaseClient::GetPlayerSlot offset." );
}
}
/*
CNetChan::GetMsgHandler - for converting CNetChan::this* to a IClient*
*/
{
StartPrepSDKCall( SDKCall_Raw );
PrepSDKCall_SetFromConf( stac_gamedata, SDKConf_Virtual, "CNetChan::GetMsgHandler" );
PrepSDKCall_SetReturnInfo( SDKType_PlainOldData, SDKPass_Plain );
SDKCall_GetMsgHandler = EndPrepSDKCall();
if ( SDKCall_GetMsgHandler != INVALID_HANDLE )
{
PrintToServer( "CNetChan::GetMsgHandler set up!" );
}
else
{
SetFailState( "Failed to get CNetChan::GetMsgHandler offset." );
}
}
/*
CNetChan::GetTimeSinceLastReceived
*/
{
StartPrepSDKCall( SDKCall_Raw );
PrepSDKCall_SetFromConf( stac_gamedata, SDKConf_Virtual, "CNetChan::GetTimeSinceLastReceived" );
PrepSDKCall_SetReturnInfo(SDKType_Float, SDKPass_Plain);
SDKCall_GetTimeSinceLastReceived = EndPrepSDKCall();
if ( SDKCall_GetTimeSinceLastReceived != INVALID_HANDLE )
{
PrintToServer( "CNetChan::GetTimeSinceLastReceived set up!" );
}
else
{
SetFailState( "Failed to get CNetChan::GetTimeSinceLastReceived offset." );
}
}
// ENTPROP OFFSETS
/* ent flags */
Offset_m_fFlags = FindSendPropInfo("CTFPlayer", "m_fFlags");
if ( Offset_m_fFlags == -1 )
{
SetFailState( "Failed to get CTFPlayer::m_fFlags offset." );
}
}
public MRESReturn Detour_CBasePlayer__ProcessUsercmds(int entity, DHookParam hParams)
{
// Could this ever throw? We may one day find out...
if (IsFakeClient(entity))
{
return MRES_Ignored;
}
if (signonStateFor[entity] <= SIGNONSTATE_SPAWN)
{
return MRES_Supercede;
}
return MRES_Ignored;
}
public MRESReturn Detour_CNetChan__ProcessPacket(Address pThis, DHookParam hParams)
{
// Get our client idx and iclient ptr
Address icl_ptr;
int cl;
if (!GetClientFromNetChan(pThis, icl_ptr, cl) || !icl_ptr || cl <= 0 )
{
StacLog("bunk addr in procpacket dtor");
return MRES_Ignored;
}
// TODO: do this in a SetSignonState detour?
// ^ no, would break on lateload
int signonState = GetSignonState(icl_ptr);
signonStateFor[cl] = signonState;
timeSinceLastRecvFor[cl] = SDKCall(SDKCall_GetTimeSinceLastReceived, pThis);
return MRES_Ignored;
}
bool GetClientFromNetChan(Address pThis, Address& IClient, int& client)
{
IClient = Address_Null;
client = -1;
// sanity check
if (!pThis)
{
StacLog("null pThis??");
return false;
}
IClient = SDKCall( SDKCall_GetMsgHandler, pThis );
// Clients will be null when connecting and disconnecting
if (!IClient)
{
StacLog("null iclient??");
return false;
}
// Client's ent index is always GetPlayerSlot() + 1
client = SDKCall(SDKCall_GetPlayerSlot, IClient) + 1;
return true;
}
Address DerefPtr(Address addr)
{
return view_as<Address>( LoadFromAddress(addr, NumberType_Int32) );
}
int GetSignonState(Address IClient)
{
if (!IClient)
{
return -1;
}
int signonState = view_as<int>( DerefPtr( (IClient - Offset_IClient_HACK) + Offset_SignonState ) );
return signonState;
}