generated from ClaudiuHKS/AdvancedQuakeSounds
-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtick_rate_port_in_host_name.sp
169 lines (126 loc) · 3.53 KB
/
tick_rate_port_in_host_name.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
/**
* MAIN REQUIREMENTS
*/
#include <sourcemod>
#include <sdktools>
/**
* CUSTOM INFORMATION
*/
public Plugin myinfo =
{
name = "Tick Rate & Port In 'hostname'",
author = "CARAMEL® HACK",
description = "Adds Tick Rate & Port In 'hostname'",
version = __DATE__,
url = "https://hattrick.go.ro/",
};
/**
* GLOBAL VARIABLES
*/
static Handle g_hHostName = INVALID_HANDLE;
static bool g_bHostNameConVarChangeHooked = false;
/**
* CUSTOM PRIVATE FUNCTIONS
*/
static int _Get_Sv_Tick_Rate_()
{
return RoundToNearest(1.0 / GetTickInterval());
}
/**
* CUSTOM PUBLIC FORWARDS
*/
public void OnPluginStart()
{
OnMapStart();
OnConfigsExecuted();
}
public void OnMapStart()
{
if (g_hHostName == INVALID_HANDLE)
{
g_hHostName = FindConVar("hostname");
}
if (g_hHostName != INVALID_HANDLE)
{
if (!g_bHostNameConVarChangeHooked)
{
HookConVarChange(g_hHostName, _Con_Var_Change_);
g_bHostNameConVarChangeHooked = true;
}
}
}
public void OnConfigsExecuted()
{
static char szHostName[PLATFORM_MAX_PATH] = { 0, ... }, szHostPort[PLATFORM_MAX_PATH] = { 0, ... }, szTickRate[PLATFORM_MAX_PATH] = { 0, ... };
static ConVar hHostName = null, hHostPort = null;
static int nTickRate = 0;
nTickRate = _Get_Sv_Tick_Rate_();
IntToString(nTickRate, szTickRate, sizeof (szTickRate));
ServerCommand("exec %d_tickrate.cfg", nTickRate);
if (hHostName == null)
{
hHostName = FindConVar("hostname");
}
if (hHostPort == null)
{
hHostPort = FindConVar("hostport");
}
if (hHostName != null)
{
hHostName.GetString(szHostName, sizeof (szHostName));
}
if (hHostPort != null)
{
hHostPort.GetString(szHostPort, sizeof (szHostPort));
}
ReplaceString(szHostName, sizeof (szHostName), "<TICK>", szTickRate, false);
ReplaceString(szHostName, sizeof (szHostName), "<PORT>", szHostPort, false);
if (hHostName != null)
{
hHostName.SetString(szHostName, true, true);
}
}
public void OnMapEnd()
{
if (g_hHostName != INVALID_HANDLE)
{
if (g_bHostNameConVarChangeHooked)
{
UnhookConVarChange(g_hHostName, _Con_Var_Change_);
g_bHostNameConVarChangeHooked = false;
}
}
}
public void OnPluginEnd()
{
OnMapEnd();
}
/**
* CUSTOM PUBLIC HANDLERS
*/
public void _Con_Var_Change_(Handle hConVar, const char[] szOld, const char[] szNew)
{
static char szBuffer[PLATFORM_MAX_PATH] = { 0, ... }, szHostPort[PLATFORM_MAX_PATH] = { 0, ... }, szTickRate[PLATFORM_MAX_PATH] = { 0, ... };
static ConVar hHostPort = null;
static int nTickRate = 0;
if (hHostPort == null)
{
hHostPort = FindConVar("hostport");
}
if (hConVar == g_hHostName)
{
if (hHostPort != null)
{
hHostPort.GetString(szHostPort, sizeof (szHostPort));
nTickRate = _Get_Sv_Tick_Rate_();
IntToString(nTickRate, szTickRate, sizeof (szTickRate));
strcopy(szBuffer, sizeof (szBuffer), szNew);
ReplaceString(szBuffer, sizeof (szBuffer), "<TICK>", szTickRate, false);
ReplaceString(szBuffer, sizeof (szBuffer), "<PORT>", szHostPort, false);
if (strcmp(szNew, szBuffer))
{
SetConVarString(hConVar, szBuffer, true, true);
}
}
}
}