1.1 --- a/extensions/cstrike/util_cstrike.cpp Sat Feb 08 20:00:52 2014 -0500
1.2 +++ b/extensions/cstrike/util_cstrike.cpp Sat Feb 08 20:04:12 2014 -0500
1.3 @@ -44,8 +44,17 @@
1.4 code; \
1.5 g_RegNatives.Register(pWrapper);
1.6
1.7 +#define GET_MEMSIG(name, defaultret) \
1.8 + if (!g_pGameConf->GetMemSig(name, &addr) || !addr) \
1.9 + { \
1.10 + g_pSM->LogError(myself, "Failed to locate function."); \
1.11 + return defaultret;\
1.12 + }
1.13 +
1.14 void *GetWeaponInfo(int weaponID)
1.15 {
1.16 + void *info;
1.17 +#if SOURCE_ENGINE != SE_CSGO || !defined(WIN32)
1.18 static ICallWrapper *pWrapper = NULL;
1.19 if (!pWrapper)
1.20 {
1.21 @@ -61,8 +70,6 @@
1.22 pWrapper = g_pBinTools->CreateCall(addr, CallConv_Cdecl, &retpass, pass, 1))
1.23 }
1.24
1.25 - void *info;
1.26 -
1.27 unsigned char vstk[sizeof(int)];
1.28 unsigned char *vptr = vstk;
1.29
1.30 @@ -70,11 +77,30 @@
1.31
1.32 pWrapper->Execute(vstk, &info);
1.33
1.34 +
1.35 +#else
1.36 + static void *addr = NULL;
1.37 +
1.38 + if(!addr)
1.39 + {
1.40 + GET_MEMSIG("GetWeaponInfo", 0);
1.41 + }
1.42 +
1.43 + __asm
1.44 + {
1.45 + mov ecx, weaponID
1.46 + call addr
1.47 + mov info, eax
1.48 + }
1.49 +#endif
1.50 return info;
1.51 }
1.52
1.53 const char *GetTranslatedWeaponAlias(const char *weapon)
1.54 {
1.55 + const char *alias = NULL;
1.56 +
1.57 +#if SOURCE_ENGINE != SE_CSGO || !defined(WIN32)
1.58 static ICallWrapper *pWrapper = NULL;
1.59
1.60 if (!pWrapper)
1.61 @@ -90,20 +116,35 @@
1.62 retpass.size = sizeof(const char *); \
1.63 pWrapper = g_pBinTools->CreateCall(addr, CallConv_Cdecl, &retpass, pass, 1))
1.64 }
1.65 - const char *ret = NULL;
1.66
1.67 unsigned char vstk[sizeof(const char *)];
1.68 unsigned char *vptr = vstk;
1.69
1.70 *(const char **)vptr = weapon;
1.71
1.72 - pWrapper->Execute(vstk, &ret);
1.73 + pWrapper->Execute(vstk, &alias);
1.74 +#else
1.75 + static void *addr = NULL;
1.76 +
1.77 + if(!addr)
1.78 + {
1.79 + GET_MEMSIG("GetTranslatedWeaponAlias", weapon);
1.80 + }
1.81
1.82 - return ret;
1.83 + __asm
1.84 + {
1.85 + mov ecx, weapon
1.86 + call addr
1.87 + mov alias, eax
1.88 + }
1.89 +#endif
1.90 + return alias;
1.91 }
1.92
1.93 int AliasToWeaponID(const char *weapon)
1.94 {
1.95 + int weaponID = 0;
1.96 +#if SOURCE_ENGINE != SE_CSGO || !defined(WIN32)
1.97 static ICallWrapper *pWrapper = NULL;
1.98
1.99 if (!pWrapper)
1.100 @@ -119,7 +160,6 @@
1.101 retpass.size = sizeof(int); \
1.102 pWrapper = g_pBinTools->CreateCall(addr, CallConv_Cdecl, &retpass, pass, 1))
1.103 }
1.104 - int weaponID = 0;
1.105
1.106 unsigned char vstk[sizeof(const char *)];
1.107 unsigned char *vptr = vstk;
1.108 @@ -127,12 +167,28 @@
1.109 *(const char **)vptr = weapon;
1.110
1.111 pWrapper->Execute(vstk, &weaponID);
1.112 +#else
1.113 + static void *addr = NULL;
1.114
1.115 + if(!addr)
1.116 + {
1.117 + GET_MEMSIG("AliasToWeaponID", 0);
1.118 + }
1.119 +
1.120 + __asm
1.121 + {
1.122 + mov ecx, weapon
1.123 + call addr
1.124 + mov weaponID, eax
1.125 + }
1.126 +#endif
1.127 return weaponID;
1.128 }
1.129
1.130 const char *WeaponIDToAlias(int weaponID)
1.131 {
1.132 + const char *alias = NULL;
1.133 +#if SOURCE_ENGINE != SE_CSGO || !defined(WIN32)
1.134 static ICallWrapper *pWrapper = NULL;
1.135
1.136 if (!pWrapper)
1.137 @@ -148,16 +204,30 @@
1.138 retpass.size = sizeof(const char *); \
1.139 pWrapper = g_pBinTools->CreateCall(addr, CallConv_Cdecl, &retpass, pass, 1))
1.140 }
1.141 - const char *ret = NULL;
1.142
1.143 unsigned char vstk[sizeof(int)];
1.144 unsigned char *vptr = vstk;
1.145
1.146 *(int *)vptr = GetRealWeaponID(weaponID);
1.147
1.148 - pWrapper->Execute(vstk, &ret);
1.149 -
1.150 - return ret;
1.151 + pWrapper->Execute(vstk, &alias);
1.152 +#else
1.153 + static void *addr = NULL;
1.154 +
1.155 + if(!addr)
1.156 + {
1.157 + GET_MEMSIG("WeaponIDToAlias", 0);
1.158 + }
1.159 +
1.160 + int realWeaponID = GetRealWeaponID(weaponID);
1.161 + __asm
1.162 + {
1.163 + mov ecx, realWeaponID
1.164 + call addr
1.165 + mov alias, eax
1.166 + }
1.167 +#endif
1.168 + return alias;
1.169 }
1.170 int GetRealWeaponID(int weaponId)
1.171 {