forked from lazhoroni/Plugins-for-CSGO-Servers
-
Notifications
You must be signed in to change notification settings - Fork 1
/
drk_ratefix.sp
115 lines (97 loc) · 3.19 KB
/
drk_ratefix.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
#pragma semicolon 1
#include <sdktools>
#pragma newdecls required
ConVar net_forcerate;
Address engine;
Handle hGetPlayerNetInfo;
int m_RateOffset;
public Plugin myinfo =
{
name = "Rate Ayarlari",
author = "ImPossibLe",
description = "DrK # GaminG",
version = "1.0",
url = ""
}
public void OnPluginStart()
{
net_forcerate = CreateConVar("net_forcerate", "307200");
Handle hGameConf = LoadGameConfigFile("net_forcerate.games");
if (!hGameConf)
SetFailState("Failed to find net_forcerate.games.txt gamedata file.");
// Grab all the required info from the gamedata file.
char sInterfaceName[64];
if(!GameConfGetKeyValue(hGameConf, "INTERFACEVERSION_VENGINESERVER", sInterfaceName, sizeof(sInterfaceName)))
{
CloseHandle(hGameConf);
SetFailState("Failed to get INTERFACEVERSION_VENGINESERVER interface name");
}
m_RateOffset = GameConfGetOffset(hGameConf, "m_Rate");
if (m_RateOffset == -1)
{
CloseHandle(hGameConf);
SetFailState("Failed to find m_Rate offset in gamedata.");
}
// Prepare a call to CreateInterface.
StartPrepSDKCall(SDKCall_Static);
if(!PrepSDKCall_SetFromConf(hGameConf, SDKConf_Signature, "CreateInterface"))
{
CloseHandle(hGameConf);
SetFailState("Failed to find CreateInterface symbol.");
}
PrepSDKCall_AddParameter(SDKType_String, SDKPass_Pointer);
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Pointer, VDECODE_FLAG_ALLOWNULL);
PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain);
Handle hCreateInterface = EndPrepSDKCall();
if (!hCreateInterface)
{
CloseHandle(hGameConf);
SetFailState("Failed to create SDK call for CreateInterface.");
}
// Get the IVEngineServer pointer
engine = view_as<Address>(SDKCall(hCreateInterface, sInterfaceName, 0));
if (engine == Address_Null)
{
CloseHandle(hGameConf);
SetFailState("Failed to get IVEngineServer interface pointer.");
}
// Prepare a call to IVEngineServer::GetPlayerNetInfo
StartPrepSDKCall(SDKCall_Raw);
if (!PrepSDKCall_SetFromConf(hGameConf, SDKConf_Virtual, "GetPlayerNetInfo"))
{
CloseHandle(hGameConf);
SetFailState("Failed to find GetPlayerNetInfo offset.");
}
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain);
hGetPlayerNetInfo = EndPrepSDKCall();
if (!hGetPlayerNetInfo)
{
CloseHandle(hGameConf);
SetFailState("Failed to create SDK call for IVEngineServer::GetPlayerNetInfo.");
}
CloseHandle(hGameConf);
}
public void OnClientSettingsChanged(int client)
{
if (IsFakeClient(client))
return;
int forcerate = net_forcerate.IntValue;
if (forcerate > 0)
SetRate(client, forcerate);
}
void SetRate(int client, int forcerate)
{
Address netchannel = GetPlayerNetInfo(client);
if (netchannel == Address_Null)
return;
Address rateaddr = netchannel + view_as<Address>(m_RateOffset);
if (LoadFromAddress(rateaddr, NumberType_Int32) != GetClientDataRate(client))
LogError("Rate offset might be wrong. Actual rate: %d, Rate at offset: %d", GetClientDataRate(client), LoadFromAddress(rateaddr, NumberType_Int32));
else
StoreToAddress(rateaddr, forcerate, NumberType_Int32);
}
Address GetPlayerNetInfo(int client)
{
return view_as<Address>(SDKCall(hGetPlayerNetInfo, engine, client));
}