Update CStrike extension and gamedata on windows for latest CS:GO update (irc, r= psychonic)
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 #define GET_MEMSIG(name, defaultret) \
48 if (!g_pGameConf->GetMemSig(name, &addr) || !addr) \
50 g_pSM->LogError(myself, "Failed to locate function."); \
54 void *GetWeaponInfo(int weaponID)
57 #if SOURCE_ENGINE != SE_CSGO || !defined(WIN32)
58 static ICallWrapper *pWrapper = NULL;
61 REGISTER_ADDR("GetWeaponInfo", NULL,
64 pass[0].flags = PASSFLAG_BYVAL; \
65 pass[0].type = PassType_Basic; \
66 pass[0].size = sizeof(int); \
67 retpass.flags = PASSFLAG_BYVAL; \
68 retpass.type = PassType_Basic; \
69 retpass.size = sizeof(void *); \
70 pWrapper = g_pBinTools->CreateCall(addr, CallConv_Cdecl, &retpass, pass, 1))
73 unsigned char vstk[sizeof(int)];
74 unsigned char *vptr = vstk;
76 *(int *)vptr = weaponID;
78 pWrapper->Execute(vstk, &info);
82 static void *addr = NULL;
86 GET_MEMSIG("GetWeaponInfo", 0);
99 const char *GetTranslatedWeaponAlias(const char *weapon)
101 const char *alias = NULL;
103 #if SOURCE_ENGINE != SE_CSGO || !defined(WIN32)
104 static ICallWrapper *pWrapper = NULL;
108 REGISTER_ADDR("GetTranslatedWeaponAlias", weapon,
111 pass[0].flags = PASSFLAG_BYVAL; \
112 pass[0].type = PassType_Basic; \
113 pass[0].size = sizeof(const char *); \
114 retpass.flags = PASSFLAG_BYVAL; \
115 retpass.type = PassType_Basic; \
116 retpass.size = sizeof(const char *); \
117 pWrapper = g_pBinTools->CreateCall(addr, CallConv_Cdecl, &retpass, pass, 1))
120 unsigned char vstk[sizeof(const char *)];
121 unsigned char *vptr = vstk;
123 *(const char **)vptr = weapon;
125 pWrapper->Execute(vstk, &alias);
127 static void *addr = NULL;
131 GET_MEMSIG("GetTranslatedWeaponAlias", weapon);
144 int AliasToWeaponID(const char *weapon)
147 #if SOURCE_ENGINE != SE_CSGO || !defined(WIN32)
148 static ICallWrapper *pWrapper = NULL;
152 REGISTER_ADDR("AliasToWeaponID", 0,
155 pass[0].flags = PASSFLAG_BYVAL; \
156 pass[0].type = PassType_Basic; \
157 pass[0].size = sizeof(const char *); \
158 retpass.flags = PASSFLAG_BYVAL; \
159 retpass.type = PassType_Basic; \
160 retpass.size = sizeof(int); \
161 pWrapper = g_pBinTools->CreateCall(addr, CallConv_Cdecl, &retpass, pass, 1))
164 unsigned char vstk[sizeof(const char *)];
165 unsigned char *vptr = vstk;
167 *(const char **)vptr = weapon;
169 pWrapper->Execute(vstk, &weaponID);
171 static void *addr = NULL;
175 GET_MEMSIG("AliasToWeaponID", 0);
188 const char *WeaponIDToAlias(int weaponID)
190 const char *alias = NULL;
191 #if SOURCE_ENGINE != SE_CSGO || !defined(WIN32)
192 static ICallWrapper *pWrapper = NULL;
196 REGISTER_ADDR("WeaponIDToAlias", 0,
199 pass[0].flags = PASSFLAG_BYVAL; \
200 pass[0].type = PassType_Basic; \
201 pass[0].size = sizeof(int); \
202 retpass.flags = PASSFLAG_BYVAL; \
203 retpass.type = PassType_Basic; \
204 retpass.size = sizeof(const char *); \
205 pWrapper = g_pBinTools->CreateCall(addr, CallConv_Cdecl, &retpass, pass, 1))
208 unsigned char vstk[sizeof(int)];
209 unsigned char *vptr = vstk;
211 *(int *)vptr = GetRealWeaponID(weaponID);
213 pWrapper->Execute(vstk, &alias);
215 static void *addr = NULL;
219 GET_MEMSIG("WeaponIDToAlias", 0);
222 int realWeaponID = GetRealWeaponID(weaponID);
225 mov ecx, realWeaponID
232 int GetRealWeaponID(int weaponId)
234 #if SOURCE_ENGINE == SE_CSGO
235 switch((SMCSWeapon)weaponId)
237 case SMCSWeapon_NONE:
238 return (int)CSGOWeapon_NONE;
239 case SMCSWeapon_DEAGLE:
240 return (int)CSGOWeapon_DEAGLE;
241 case SMCSWeapon_ELITE:
242 return (int)CSGOWeapon_ELITE;
243 case SMCSWeapon_FIVESEVEN:
244 return (int)CSGOWeapon_FIVESEVEN;
245 case SMCSWeapon_GLOCK:
246 return (int)CSGOWeapon_GLOCK;
247 case SMCSWeapon_P228:
248 return (int)CSGOWeapon_P228;
250 return (int)CSGOWeapon_USP;
251 case SMCSWeapon_AK47:
252 return (int)CSGOWeapon_AK47;
254 return (int)CSGOWeapon_AUG;
256 return (int)CSGOWeapon_AWP;
257 case SMCSWeapon_FAMAS:
258 return (int)CSGOWeapon_FAMAS;
259 case SMCSWeapon_G3SG1:
260 return (int)CSGOWeapon_G3SG1;
261 case SMCSWeapon_GALIL:
262 return (int)CSGOWeapon_GALIL;
263 case SMCSWeapon_GALILAR:
264 return (int)CSGOWeapon_GALILAR;
265 case SMCSWeapon_M249:
266 return (int)CSGOWeapon_M249;
268 return (int)CSGOWeapon_M3;
269 case SMCSWeapon_M4A1:
270 return (int)CSGOWeapon_M4A1;
271 case SMCSWeapon_MAC10:
272 return (int)CSGOWeapon_MAC10;
273 case SMCSWeapon_MP5NAVY:
274 return (int)CSGOWeapon_MP5NAVY;
276 return (int)CSGOWeapon_P90;
277 case SMCSWeapon_SCOUT:
278 return (int)CSGOWeapon_SCOUT;
279 case SMCSWeapon_SG550:
280 return (int)CSGOWeapon_SG550;
281 case SMCSWeapon_SG552:
282 return (int)CSGOWeapon_SG552;
284 return (int)CSGOWeapon_TMP;
285 case SMCSWeapon_UMP45:
286 return (int)CSGOWeapon_UMP45;
287 case SMCSWeapon_XM1014:
288 return (int)CSGOWeapon_XM1014;
289 case SMCSWeapon_BIZON:
290 return (int)CSGOWeapon_BIZON;
291 case SMCSWeapon_MAG7:
292 return (int)CSGOWeapon_MAG7;
293 case SMCSWeapon_NEGEV:
294 return (int)CSGOWeapon_NEGEV;
295 case SMCSWeapon_SAWEDOFF:
296 return (int)CSGOWeapon_SAWEDOFF;
297 case SMCSWeapon_TEC9:
298 return (int)CSGOWeapon_TEC9;
299 case SMCSWeapon_TASER:
300 return (int)CSGOWeapon_TASER;
301 case SMCSWeapon_HKP2000:
302 return (int)CSGOWeapon_HKP2000;
304 return (int)CSGOWeapon_MP7;
306 return (int)CSGOWeapon_MP9;
307 case SMCSWeapon_NOVA:
308 return (int)CSGOWeapon_NOVA;
309 case SMCSWeapon_P250:
310 return (int)CSGOWeapon_P250;
311 case SMCSWeapon_SCAR17:
312 return (int)CSGOWeapon_SCAR17;
313 case SMCSWeapon_SCAR20:
314 return (int)CSGOWeapon_SCAR20;
315 case SMCSWeapon_SG556:
316 return (int)CSGOWeapon_SG556;
317 case SMCSWeapon_SSG08:
318 return (int)CSGOWeapon_SSG08;
319 case SMCSWeapon_KNIFE_GG:
320 return (int)CSGOWeapon_KNIFE_GG;
321 case SMCSWeapon_KNIFE:
322 return (int)CSGOWeapon_KNIFE;
323 case SMCSWeapon_FLASHBANG:
324 return (int)CSGOWeapon_FLASHBANG;
325 case SMCSWeapon_HEGRENADE:
326 return (int)CSGOWeapon_HEGRENADE;
327 case SMCSWeapon_SMOKEGRENADE:
328 return (int)CSGOWeapon_SMOKEGRENADE;
329 case SMCSWeapon_MOLOTOV:
330 return (int)CSGOWeapon_MOLOTOV;
331 case SMCSWeapon_DECOY:
332 return (int)CSGOWeapon_DECOY;
333 case SMCSWeapon_INCGRENADE:
334 return (int)CSGOWeapon_INCGRENADE;
336 return (int)CSGOWeapon_C4;
337 case SMCSWeapon_KEVLAR:
338 return (int)CSGOWeapon_KEVLAR;
339 case SMCSWeapon_ASSAULTSUIT:
340 return (int)CSGOWeapon_ASSAULTSUIT;
341 case SMCSWeapon_NIGHTVISION:
342 return (int)CSGOWeapon_NVG;
343 case SMCSWeapon_DEFUSER:
344 return (int)CSGOWeapon_DEFUSER;
346 return (int)CSGOWeapon_NONE;
349 if (weaponId > (int)SMCSWeapon_NIGHTVISION || weaponId < (int)SMCSWeapon_NONE)
350 return (int)SMCSWeapon_NONE;
356 int GetFakeWeaponID(int weaponId)
358 #if SOURCE_ENGINE == SE_CSGO
359 switch((CSGOWeapon)weaponId)
361 case CSGOWeapon_NONE:
362 return (int)SMCSWeapon_NONE;
363 case CSGOWeapon_DEAGLE:
364 return (int)SMCSWeapon_DEAGLE;
365 case CSGOWeapon_ELITE:
366 return (int)SMCSWeapon_ELITE;
367 case CSGOWeapon_FIVESEVEN:
368 return (int)SMCSWeapon_FIVESEVEN;
369 case CSGOWeapon_GLOCK:
370 return (int)SMCSWeapon_GLOCK;
371 case CSGOWeapon_P228:
372 return (int)SMCSWeapon_P228;
374 return (int)SMCSWeapon_USP;
375 case CSGOWeapon_AK47:
376 return (int)SMCSWeapon_AK47;
378 return (int)SMCSWeapon_AUG;
380 return (int)SMCSWeapon_AWP;
381 case CSGOWeapon_FAMAS:
382 return (int)SMCSWeapon_FAMAS;
383 case CSGOWeapon_G3SG1:
384 return (int)SMCSWeapon_G3SG1;
385 case CSGOWeapon_GALIL:
386 return (int)SMCSWeapon_GALIL;
387 case CSGOWeapon_GALILAR:
388 return (int)SMCSWeapon_GALILAR;
389 case CSGOWeapon_M249:
390 return (int)SMCSWeapon_M249;
392 return (int)SMCSWeapon_M3;
393 case CSGOWeapon_M4A1:
394 return (int)SMCSWeapon_M4A1;
395 case CSGOWeapon_MAC10:
396 return (int)SMCSWeapon_MAC10;
397 case CSGOWeapon_MP5NAVY:
398 return (int)SMCSWeapon_MP5NAVY;
400 return (int)SMCSWeapon_P90;
401 case CSGOWeapon_SCOUT:
402 return (int)SMCSWeapon_SCOUT;
403 case CSGOWeapon_SG550:
404 return (int)SMCSWeapon_SG550;
405 case CSGOWeapon_SG552:
406 return (int)SMCSWeapon_SG552;
408 return (int)SMCSWeapon_TMP;
409 case CSGOWeapon_UMP45:
410 return (int)SMCSWeapon_UMP45;
411 case CSGOWeapon_XM1014:
412 return (int)SMCSWeapon_XM1014;
413 case CSGOWeapon_BIZON:
414 return (int)SMCSWeapon_BIZON;
415 case CSGOWeapon_MAG7:
416 return (int)SMCSWeapon_MAG7;
417 case CSGOWeapon_NEGEV:
418 return (int)SMCSWeapon_NEGEV;
419 case CSGOWeapon_SAWEDOFF:
420 return (int)SMCSWeapon_SAWEDOFF;
421 case CSGOWeapon_TEC9:
422 return (int)SMCSWeapon_TEC9;
423 case CSGOWeapon_TASER:
424 return (int)SMCSWeapon_TASER;
425 case CSGOWeapon_HKP2000:
426 return (int)SMCSWeapon_HKP2000;
428 return (int)SMCSWeapon_MP7;
430 return (int)SMCSWeapon_MP9;
431 case CSGOWeapon_NOVA:
432 return (int)SMCSWeapon_NOVA;
433 case CSGOWeapon_P250:
434 return (int)SMCSWeapon_P250;
435 case CSGOWeapon_SCAR17:
436 return (int)SMCSWeapon_SCAR17;
437 case CSGOWeapon_SCAR20:
438 return (int)SMCSWeapon_SCAR20;
439 case CSGOWeapon_SG556:
440 return (int)SMCSWeapon_SG556;
441 case CSGOWeapon_SSG08:
442 return (int)SMCSWeapon_SSG08;
443 case CSGOWeapon_KNIFE_GG:
444 return (int)SMCSWeapon_KNIFE_GG;
445 case CSGOWeapon_KNIFE:
446 return (int)SMCSWeapon_KNIFE;
447 case CSGOWeapon_FLASHBANG:
448 return (int)SMCSWeapon_FLASHBANG;
449 case CSGOWeapon_HEGRENADE:
450 return (int)SMCSWeapon_HEGRENADE;
451 case CSGOWeapon_SMOKEGRENADE:
452 return (int)SMCSWeapon_SMOKEGRENADE;
453 case CSGOWeapon_MOLOTOV:
454 return (int)SMCSWeapon_MOLOTOV;
455 case CSGOWeapon_DECOY:
456 return (int)SMCSWeapon_DECOY;
457 case CSGOWeapon_INCGRENADE:
458 return (int)SMCSWeapon_INCGRENADE;
460 return (int)SMCSWeapon_C4;
461 case CSGOWeapon_KEVLAR:
462 return (int)SMCSWeapon_KEVLAR;
463 case CSGOWeapon_ASSAULTSUIT:
464 return (int)SMCSWeapon_ASSAULTSUIT;
466 return (int)SMCSWeapon_NIGHTVISION;
467 case CSGOWeapon_DEFUSER:
468 return (int)SMCSWeapon_DEFUSER;
470 return (int)SMCSWeapon_NONE;
473 if (weaponId > (int)SMCSWeapon_NIGHTVISION || weaponId < (int)SMCSWeapon_NONE)
474 return (int)SMCSWeapon_NONE;
479 bool IsValidWeaponID(int id)
481 if (id <= (int)SMCSWeapon_NONE)
483 //Why are these even HERE!?! They dont exist in CS:GO but have valid ID's still
484 #if SOURCE_ENGINE == SE_CSGO
485 else if (id > (int)SMCSWeapon_DEFUSER || id == (int)SMCSWeapon_P228 || id == (int)SMCSWeapon_SCOUT || id == (int)SMCSWeapon_SG550 || id == (int)SMCSWeapon_GALIL ||
486 id == (int)SMCSWeapon_SCAR17 || id == (int)SMCSWeapon_USP || id == (int)SMCSWeapon_M3 || id == (int)SMCSWeapon_MP5NAVY || id == (int)SMCSWeapon_TMP || id == (int)SMCSWeapon_SG552)
489 else if (id > (int)SMCSWeapon_NIGHTVISION)