3 * =============================================================================
4 * SourceMod Counter-Strike:Source Extension
5 * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
32 #include "util_cstrike.h"
34 #include "extension.h"
35 #include "RegNatives.h"
37 #define REGISTER_ADDR(name, defaultret, code) \
39 if (!g_pGameConf->GetMemSig(name, &addr) || !addr) \
41 g_pSM->LogError(myself, "Failed to locate function."); \
45 g_RegNatives.Register(pWrapper);
47 void *GetWeaponInfo(int weaponID)
49 static ICallWrapper *pWrapper = NULL;
52 REGISTER_ADDR("GetWeaponInfo", NULL,
55 pass[0].flags = PASSFLAG_BYVAL; \
56 pass[0].type = PassType_Basic; \
57 pass[0].size = sizeof(int); \
58 retpass.flags = PASSFLAG_BYVAL; \
59 retpass.type = PassType_Basic; \
60 retpass.size = sizeof(void *); \
61 pWrapper = g_pBinTools->CreateCall(addr, CallConv_Cdecl, &retpass, pass, 1))
66 unsigned char vstk[sizeof(int)];
67 unsigned char *vptr = vstk;
69 *(int *)vptr = weaponID;
71 pWrapper->Execute(vstk, &info);
76 const char *GetTranslatedWeaponAlias(const char *weapon)
78 static ICallWrapper *pWrapper = NULL;
82 REGISTER_ADDR("GetTranslatedWeaponAlias", weapon,
85 pass[0].flags = PASSFLAG_BYVAL; \
86 pass[0].type = PassType_Basic; \
87 pass[0].size = sizeof(const char *); \
88 retpass.flags = PASSFLAG_BYVAL; \
89 retpass.type = PassType_Basic; \
90 retpass.size = sizeof(const char *); \
91 pWrapper = g_pBinTools->CreateCall(addr, CallConv_Cdecl, &retpass, pass, 1))
93 const char *ret = NULL;
95 unsigned char vstk[sizeof(const char *)];
96 unsigned char *vptr = vstk;
98 *(const char **)vptr = weapon;
100 pWrapper->Execute(vstk, &ret);
105 int AliasToWeaponID(const char *weapon)
107 static ICallWrapper *pWrapper = NULL;
111 REGISTER_ADDR("AliasToWeaponID", 0,
114 pass[0].flags = PASSFLAG_BYVAL; \
115 pass[0].type = PassType_Basic; \
116 pass[0].size = sizeof(const char *); \
117 retpass.flags = PASSFLAG_BYVAL; \
118 retpass.type = PassType_Basic; \
119 retpass.size = sizeof(int); \
120 pWrapper = g_pBinTools->CreateCall(addr, CallConv_Cdecl, &retpass, pass, 1))
124 unsigned char vstk[sizeof(const char *)];
125 unsigned char *vptr = vstk;
127 *(const char **)vptr = weapon;
129 pWrapper->Execute(vstk, &weaponID);
134 const char *WeaponIDToAlias(int weaponID)
136 static ICallWrapper *pWrapper = NULL;
140 REGISTER_ADDR("WeaponIDToAlias", 0,
143 pass[0].flags = PASSFLAG_BYVAL; \
144 pass[0].type = PassType_Basic; \
145 pass[0].size = sizeof(int); \
146 retpass.flags = PASSFLAG_BYVAL; \
147 retpass.type = PassType_Basic; \
148 retpass.size = sizeof(const char *); \
149 pWrapper = g_pBinTools->CreateCall(addr, CallConv_Cdecl, &retpass, pass, 1))
151 const char *ret = NULL;
153 unsigned char vstk[sizeof(int)];
154 unsigned char *vptr = vstk;
156 *(int *)vptr = GetRealWeaponID(weaponID);
158 pWrapper->Execute(vstk, &ret);
162 int GetRealWeaponID(int weaponId)
164 #if SOURCE_ENGINE == SE_CSGO
165 switch((SMCSWeapon)weaponId)
167 case SMCSWeapon_NONE:
168 return (int)CSGOWeapon_NONE;
169 case SMCSWeapon_DEAGLE:
170 return (int)CSGOWeapon_DEAGLE;
171 case SMCSWeapon_ELITE:
172 return (int)CSGOWeapon_ELITE;
173 case SMCSWeapon_FIVESEVEN:
174 return (int)CSGOWeapon_FIVESEVEN;
175 case SMCSWeapon_GLOCK:
176 return (int)CSGOWeapon_GLOCK;
177 case SMCSWeapon_P228:
178 return (int)CSGOWeapon_P228;
180 return (int)CSGOWeapon_USP;
181 case SMCSWeapon_AK47:
182 return (int)CSGOWeapon_AK47;
184 return (int)CSGOWeapon_AUG;
186 return (int)CSGOWeapon_AWP;
187 case SMCSWeapon_FAMAS:
188 return (int)CSGOWeapon_FAMAS;
189 case SMCSWeapon_G3SG1:
190 return (int)CSGOWeapon_G3SG1;
191 case SMCSWeapon_GALIL:
192 return (int)CSGOWeapon_GALIL;
193 case SMCSWeapon_GALILAR:
194 return (int)CSGOWeapon_GALILAR;
195 case SMCSWeapon_M249:
196 return (int)CSGOWeapon_M249;
198 return (int)CSGOWeapon_M3;
199 case SMCSWeapon_M4A1:
200 return (int)CSGOWeapon_M4A1;
201 case SMCSWeapon_MAC10:
202 return (int)CSGOWeapon_MAC10;
203 case SMCSWeapon_MP5NAVY:
204 return (int)CSGOWeapon_MP5NAVY;
206 return (int)CSGOWeapon_P90;
207 case SMCSWeapon_SCOUT:
208 return (int)CSGOWeapon_SCOUT;
209 case SMCSWeapon_SG550:
210 return (int)CSGOWeapon_SG550;
211 case SMCSWeapon_SG552:
212 return (int)CSGOWeapon_SG552;
214 return (int)CSGOWeapon_TMP;
215 case SMCSWeapon_UMP45:
216 return (int)CSGOWeapon_UMP45;
217 case SMCSWeapon_XM1014:
218 return (int)CSGOWeapon_XM1014;
219 case SMCSWeapon_BIZON:
220 return (int)CSGOWeapon_BIZON;
221 case SMCSWeapon_MAG7:
222 return (int)CSGOWeapon_MAG7;
223 case SMCSWeapon_NEGEV:
224 return (int)CSGOWeapon_NEGEV;
225 case SMCSWeapon_SAWEDOFF:
226 return (int)CSGOWeapon_SAWEDOFF;
227 case SMCSWeapon_TEC9:
228 return (int)CSGOWeapon_TEC9;
229 case SMCSWeapon_TASER:
230 return (int)CSGOWeapon_TASER;
231 case SMCSWeapon_HKP2000:
232 return (int)CSGOWeapon_HKP2000;
234 return (int)CSGOWeapon_MP7;
236 return (int)CSGOWeapon_MP9;
237 case SMCSWeapon_NOVA:
238 return (int)CSGOWeapon_NOVA;
239 case SMCSWeapon_P250:
240 return (int)CSGOWeapon_P250;
241 case SMCSWeapon_SCAR17:
242 return (int)CSGOWeapon_SCAR17;
243 case SMCSWeapon_SCAR20:
244 return (int)CSGOWeapon_SCAR20;
245 case SMCSWeapon_SG556:
246 return (int)CSGOWeapon_SG556;
247 case SMCSWeapon_SSG08:
248 return (int)CSGOWeapon_SSG08;
249 case SMCSWeapon_KNIFE_GG:
250 return (int)CSGOWeapon_KNIFE_GG;
251 case SMCSWeapon_KNIFE:
252 return (int)CSGOWeapon_KNIFE;
253 case SMCSWeapon_FLASHBANG:
254 return (int)CSGOWeapon_FLASHBANG;
255 case SMCSWeapon_HEGRENADE:
256 return (int)CSGOWeapon_HEGRENADE;
257 case SMCSWeapon_SMOKEGRENADE:
258 return (int)CSGOWeapon_SMOKEGRENADE;
259 case SMCSWeapon_MOLOTOV:
260 return (int)CSGOWeapon_MOLOTOV;
261 case SMCSWeapon_DECOY:
262 return (int)CSGOWeapon_DECOY;
263 case SMCSWeapon_INCGRENADE:
264 return (int)CSGOWeapon_INCGRENADE;
266 return (int)CSGOWeapon_C4;
267 case SMCSWeapon_KEVLAR:
268 return (int)CSGOWeapon_KEVLAR;
269 case SMCSWeapon_ASSAULTSUIT:
270 return (int)CSGOWeapon_ASSAULTSUIT;
271 case SMCSWeapon_NIGHTVISION:
272 return (int)CSGOWeapon_NVG;
273 case SMCSWeapon_DEFUSER:
274 return (int)CSGOWeapon_DEFUSER;
279 if (weaponId > 33 || weaponId < 0)
286 int GetFakeWeaponID(int weaponId)
288 #if SOURCE_ENGINE == SE_CSGO
289 switch((CSGOWeapon)weaponId)
291 case CSGOWeapon_NONE:
292 return (int)SMCSWeapon_NONE;
293 case CSGOWeapon_DEAGLE:
294 return (int)SMCSWeapon_DEAGLE;
295 case CSGOWeapon_ELITE:
296 return (int)SMCSWeapon_ELITE;
297 case CSGOWeapon_FIVESEVEN:
298 return (int)SMCSWeapon_FIVESEVEN;
299 case CSGOWeapon_GLOCK:
300 return (int)SMCSWeapon_GLOCK;
301 case CSGOWeapon_P228:
302 return (int)SMCSWeapon_P228;
304 return (int)SMCSWeapon_USP;
305 case CSGOWeapon_AK47:
306 return (int)SMCSWeapon_AK47;
308 return (int)SMCSWeapon_AUG;
310 return (int)SMCSWeapon_AWP;
311 case CSGOWeapon_FAMAS:
312 return (int)SMCSWeapon_FAMAS;
313 case CSGOWeapon_G3SG1:
314 return (int)SMCSWeapon_G3SG1;
315 case CSGOWeapon_GALIL:
316 return (int)SMCSWeapon_GALIL;
317 case CSGOWeapon_GALILAR:
318 return (int)SMCSWeapon_GALILAR;
319 case CSGOWeapon_M249:
320 return (int)SMCSWeapon_M249;
322 return (int)SMCSWeapon_M3;
323 case CSGOWeapon_M4A1:
324 return (int)SMCSWeapon_M4A1;
325 case CSGOWeapon_MAC10:
326 return (int)SMCSWeapon_MAC10;
327 case CSGOWeapon_MP5NAVY:
328 return (int)SMCSWeapon_MP5NAVY;
330 return (int)SMCSWeapon_P90;
331 case CSGOWeapon_SCOUT:
332 return (int)SMCSWeapon_SCOUT;
333 case CSGOWeapon_SG550:
334 return (int)SMCSWeapon_SG550;
335 case CSGOWeapon_SG552:
336 return (int)SMCSWeapon_SG552;
338 return (int)SMCSWeapon_TMP;
339 case CSGOWeapon_UMP45:
340 return (int)SMCSWeapon_UMP45;
341 case CSGOWeapon_XM1014:
342 return (int)SMCSWeapon_XM1014;
343 case CSGOWeapon_BIZON:
344 return (int)SMCSWeapon_BIZON;
345 case CSGOWeapon_MAG7:
346 return (int)SMCSWeapon_MAG7;
347 case CSGOWeapon_NEGEV:
348 return (int)SMCSWeapon_NEGEV;
349 case CSGOWeapon_SAWEDOFF:
350 return (int)SMCSWeapon_SAWEDOFF;
351 case CSGOWeapon_TEC9:
352 return (int)SMCSWeapon_TEC9;
353 case CSGOWeapon_TASER:
354 return (int)SMCSWeapon_TASER;
355 case CSGOWeapon_HKP2000:
356 return (int)SMCSWeapon_HKP2000;
358 return (int)SMCSWeapon_MP7;
360 return (int)SMCSWeapon_MP9;
361 case CSGOWeapon_NOVA:
362 return (int)SMCSWeapon_NOVA;
363 case CSGOWeapon_P250:
364 return (int)SMCSWeapon_P250;
365 case CSGOWeapon_SCAR17:
366 return (int)SMCSWeapon_SCAR17;
367 case CSGOWeapon_SCAR20:
368 return (int)SMCSWeapon_SCAR20;
369 case CSGOWeapon_SG556:
370 return (int)SMCSWeapon_SG556;
371 case CSGOWeapon_SSG08:
372 return (int)SMCSWeapon_SSG08;
373 case CSGOWeapon_KNIFE_GG:
374 return (int)SMCSWeapon_KNIFE_GG;
375 case CSGOWeapon_KNIFE:
376 return (int)SMCSWeapon_KNIFE;
377 case CSGOWeapon_FLASHBANG:
378 return (int)SMCSWeapon_FLASHBANG;
379 case CSGOWeapon_HEGRENADE:
380 return (int)SMCSWeapon_HEGRENADE;
381 case CSGOWeapon_SMOKEGRENADE:
382 return (int)SMCSWeapon_SMOKEGRENADE;
383 case CSGOWeapon_MOLOTOV:
384 return (int)SMCSWeapon_MOLOTOV;
385 case CSGOWeapon_DECOY:
386 return (int)SMCSWeapon_DECOY;
387 case CSGOWeapon_INCGRENADE:
388 return (int)SMCSWeapon_INCGRENADE;
390 return (int)SMCSWeapon_C4;
391 case CSGOWeapon_KEVLAR:
392 return (int)SMCSWeapon_KEVLAR;
393 case CSGOWeapon_ASSAULTSUIT:
394 return (int)SMCSWeapon_ASSAULTSUIT;
396 return (int)SMCSWeapon_NIGHTVISION;
397 case CSGOWeapon_DEFUSER:
398 return (int)SMCSWeapon_DEFUSER;
403 if (weaponId > 33 || weaponId < 0)
409 bool IsValidWeaponID(int id)
411 if (id == (int)SMCSWeapon_NONE || id > (int)SMCSWeapon_DEFUSER)
413 //Why are these even HERE!?! They dont exist in CS:GO but have valid ID's still
414 #if SOURCE_ENGINE == SE_CSGO
415 else if (id == (int)SMCSWeapon_P228 || id == (int)SMCSWeapon_SCOUT || id == (int)SMCSWeapon_SG550 || id == (int)SMCSWeapon_GALIL || id == (int)SMCSWeapon_SCAR17 ||
416 id == (int)SMCSWeapon_USP || id == (int)SMCSWeapon_M3 || id == (int)SMCSWeapon_MP5NAVY || id == (int)SMCSWeapon_TMP || id == (int)SMCSWeapon_SG552)
419 else if (id > (int)SMCSWeapon_NIGHTVISION || id < (int)SMCSWeapon_NONE)