-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.cpp
More file actions
222 lines (179 loc) · 5.06 KB
/
config.cpp
File metadata and controls
222 lines (179 loc) · 5.06 KB
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#include "main.h"
#define CONFIG_FILE "config.ini"
static char mPluginPath[256];
static char mConfigPath[256];
static inline int IsCharSpecial(char j,bool bRight)
{
return (j == ' ' || j == '"' || j == '\t' || j == '\r' || j == '\n' || (bRight && j == ';'));
}
void TrimSpace(char *pneedle)
{
char *phaystack = pneedle;
char *pbuf = pneedle;
while(IsCharSpecial(*pbuf,false))
++pbuf;
while(*pbuf)
*phaystack++ = *pbuf++;
*phaystack = '\0';
while(phaystack > pneedle && *--phaystack && IsCharSpecial(*phaystack,true))
*phaystack = '\0';
}
static inline int clamp(int value,int _min,int _max)
{
return value < _min ? _min : (value > _max ? _max : value);
}
static inline float clamp(double value,float _min,float _max)
{
return value < _min ? _min : (value > _max ? _max : value);
}
int parse_settings(const char *setting,const char *value,TypeRead iType)
{
if(!strcmp(setting,"semiclip"))
semiclipData.semiclip = clamp(atoi(value),0,1);
else if(!strcmp(setting,"crouch"))
semiclipData.crouch = clamp(atoi(value),0,1);
else if(!strcmp(setting,"distance"))
semiclipData.distance = clamp(atof(value),64.0,200.0);
else if(!strcmp(setting,"transparency"))
{
int val = clamp(atoi(value),0,255);
semiclipData.transparency = (val > 254 ? 0 : val);
}
else if(!strcmp(setting,"time"))
semiclipData.time = clamp(atof(value),0.0,60.0);
else if(!strcmp(setting,"noteamflash"))
semiclipData.noteamflash = clamp(atoi(value),0,1);
else if(!strcmp(setting,"effects"))
semiclipData.effects = clamp(atoi(value),0,1);
else if(!strcmp(setting,"team"))
semiclipData.team = clamp(atoi(value),0,3);
else if(iType != READ_IN_GAME)
{
if(!strcmp(setting,"flashfix"))
semiclipData.flashfix = clamp(atoi(value),0,1);
else if(!strcmp(setting,"patch"))
semiclipData.patch = clamp(atoi(value),0,1);
}
else return 0;
return 1;
}
void print_settings()
{
static const char *szConditon[] = {
" (for all)",
" (only BLUE team)",
" (only RED team)",
" (only teammates)"
};
printf("\n\nusage: semiclip_option\n\n [command] [value] [description]\n\n");
printf(" semiclip %d - enable/disable semiclip\n",semiclipData.semiclip);
printf(" team %d - condition for teams %s\n",semiclipData.team,szConditon[semiclipData.team]);
printf(" patch %d - fix jamming on a mobile platform\n",semiclipData.patch);
printf(" crouch %d - allows jump to crouching players when semiclip works\n",semiclipData.crouch);
printf(" effects %d - effect of transparency of the player. Depends from distance between players\n",semiclipData.effects);
printf(" distance %0.0f - at what distance player can have transparency and semiclip\n",semiclipData.distance);
printf(" transparency %d - transparency of the player\n\n",semiclipData.transparency);
}
static int parse_config(const char *path,TypeRead iType)
{
FILE *fp;
fp = fopen(path,"rt");
if(!fp)
{
return 0;
}
char *value;
char buf[256];
while(!feof(fp))
{
if(!fgets(buf,sizeof(buf) - 1,fp))
break;
value = strchr(buf,'=');
if(value == NULL)
{
continue;
}
*(value++) = '\0';
TrimSpace(buf);
TrimSpace(value);
if(*buf == '\0' || *value == '\0' || parse_settings(buf,value,iType))
{
continue;
}
}
//forcing set settings not own for cs
char szDir[16];
GET_GAME_DIR(szDir);
if(strcmp(szDir,"valve") != 0)
{
semiclipData.team = 0;
semiclipData.time = 0.0f;
semiclipData.flashfix = 0;
semiclipData.noteamflash = 0;
}
else if(semiclipData.flashfix == 0)
semiclipData.noteamflash = 0;
return (fclose(fp) != EOF);
}
int load_config_maps()
{
char *tempMap;
char path[256];
char mapName[32];
g_bNotActive = false;
//read default settings
parse_config(mConfigPath,READ_IN_GAME);
strncpy(mapName,STRING(gpGlobals->mapname),sizeof(mapName) - 1);
tempMap = strchr(mapName,'_');
if(tempMap != NULL)
{
*tempMap = '\0';
snprintf(path,sizeof(path) - 1,"%smaps/prefix_%s.ini",mPluginPath,mapName);
//read settings with prefix maps
parse_config(path,READ_IN_GAME);
}
snprintf(path,sizeof(path) - 1,"%smaps/%s.ini",mPluginPath,STRING(gpGlobals->mapname));
//read settings with map name
parse_config(path,READ_IN_GAME);
if(!semiclipData.semiclip)
{
g_bNotActive = true;
g_pFunctionTable->pfnPM_Move = NULL;
g_pEnginefuncsTable_Post->pfnAlertMessage = NULL;
}
else
{
if(!semiclipData.time)
{
g_bNotActive = false;
g_pFunctionTable->pfnPM_Move = PM_Move;
g_pEnginefuncsTable_Post->pfnAlertMessage = NULL;
}
else g_pEnginefuncsTable_Post->pfnAlertMessage = AlertMessage;
}
return 1;
}
int load_config()
{
char *pos;
strcpy(mConfigPath,GET_PLUGIN_PATH(PLID));
pos = strrchr(mConfigPath,'/');
if(pos == NULL || *pos == '\0')
{
return 0;
}
*(pos + 1) = '\0';
strncpy(mPluginPath,mConfigPath,sizeof(mPluginPath) - 1);
strcat(mConfigPath,CONFIG_FILE);
//default settings
semiclipData.semiclip = 1;
semiclipData.time = 0.0f;
semiclipData.team = 3;
semiclipData.patch = 0;
semiclipData.crouch = 0;
semiclipData.flashfix = 0;
semiclipData.noteamflash = 0;
semiclipData.distance = 160.0f;
semiclipData.transparency = 100;
return parse_config(mConfigPath,READ_START);
}