1.1 --- a/extensions/cstrike/forwards.cpp Sun May 27 16:51:29 2012 -0400
1.2 +++ b/extensions/cstrike/forwards.cpp Sat May 26 18:31:23 2012 -0400
1.3 @@ -1,5 +1,6 @@
1.4 #include "extension.h"
1.5 #include "forwards.h"
1.6 +#include "util_cstrike.h"
1.7
1.8 bool g_pTerminateRoundDetoured = false;
1.9 bool g_pCSWeaponDropDetoured = false;
1.10 @@ -37,11 +38,27 @@
1.11 lastclient = -1;
1.12 return 0;
1.13 }
1.14 +
1.15 +#if SOURCE_ENGINE == SE_CSGO
1.16 + int defaultprice = -1;
1.17 + if (g_iPriceOffset != -1 && g_PriceDetoured)
1.18 + {
1.19 + defaultprice = CallPriceForwardCSGO(client, weapon);
1.20 + }
1.21 +#endif
1.22 +
1.23 int val = DETOUR_MEMBER_CALL(DetourHandleBuy)(weapon);
1.24 +
1.25 +#if SOURCE_ENGINE == SE_CSGO
1.26 + if (defaultprice != -1)
1.27 + SetWeaponPrice(weapon, defaultprice);
1.28 +#endif
1.29 +
1.30 lastclient = -1;
1.31 return val;
1.32 }
1.33
1.34 +#if SOURCE_ENGINE != SE_CSGO
1.35 DETOUR_DECL_MEMBER0(DetourWeaponPrice, int)
1.36 {
1.37 int price = DETOUR_MEMBER_CALL(DetourWeaponPrice)();
1.38 @@ -53,6 +70,7 @@
1.39
1.40 return CallPriceForward(lastclient, weapon_name, price);
1.41 }
1.42 +#endif
1.43
1.44 DETOUR_DECL_MEMBER2(DetourTerminateRound, void, float, delay, int, reason)
1.45 {
1.46 @@ -79,6 +97,7 @@
1.47
1.48 return DETOUR_MEMBER_CALL(DetourTerminateRound)(orgdelay, orgreason);
1.49 }
1.50 +
1.51 DETOUR_DECL_MEMBER3(DetourCSWeaponDrop, void, CBaseEntity *, weapon, bool, something, bool, toss)
1.52 {
1.53 if (g_pIgnoreCSWeaponDropDetour)
1.54 @@ -102,6 +121,7 @@
1.55
1.56 return;
1.57 }
1.58 +
1.59 bool CreateWeaponPriceDetour()
1.60 {
1.61 if (weaponNameOffset == -1)
1.62 @@ -112,6 +132,29 @@
1.63 return false;
1.64 }
1.65 }
1.66 +
1.67 +#if SOURCE_ENGINE == SE_CSGO
1.68 + if (g_iPriceOffset == -1)
1.69 + {
1.70 + if (!g_pGameConf->GetOffset("WeaponPrice", &g_iPriceOffset))
1.71 + {
1.72 + g_iPriceOffset = -1;
1.73 + g_pSM->LogError(myself, "Failed to get WeaponPrice offset - Disabled OnGetWeaponPrice forward");
1.74 + return false;
1.75 + }
1.76 + }
1.77 + if (!CreateHandleBuyDetour())
1.78 + {
1.79 + g_pSM->LogError(myself, "HandleCommand_Buy_Internal failed to detour, disabled OnGetWeaponPrice forward.");
1.80 + return false;
1.81 + }
1.82 + else
1.83 + {
1.84 + g_PriceDetoured = true;
1.85 + return true;
1.86 + }
1.87 +#else
1.88 +
1.89 DWeaponPrice = DETOUR_CREATE_MEMBER(DetourWeaponPrice, "GetWeaponPrice");
1.90
1.91 if (DWeaponPrice != NULL)
1.92 @@ -129,6 +172,7 @@
1.93 g_pSM->LogError(myself, "GetWeaponPrice detour could not be initialized - Disabled OnGetWeaponPrice forward.");
1.94
1.95 return false;
1.96 +#endif
1.97 }
1.98
1.99 bool CreateTerminateRoundDetour()
1.100 @@ -179,13 +223,14 @@
1.101
1.102 void RemoveWeaponPriceDetour()
1.103 {
1.104 +#if SOURCE_ENGINE != SE_CSGO
1.105 if (DWeaponPrice != NULL)
1.106 {
1.107 DWeaponPrice->Destroy();
1.108 DWeaponPrice = NULL;
1.109 }
1.110 g_PriceDetoured = false;
1.111 -
1.112 +#endif
1.113 }
1.114
1.115 void RemoveHandleBuyDetour()
1.116 @@ -220,6 +265,85 @@
1.117 }
1.118 g_pCSWeaponDropDetoured = false;
1.119 }
1.120 +
1.121 +#if SOURCE_ENGINE == SE_CSGO
1.122 +bool SetWeaponPrice(int weaponID, int price)
1.123 +{
1.124 + void *info = GetWeaponInfo(weaponID);
1.125 + if (!info)
1.126 + {
1.127 + return false;
1.128 + }
1.129 + *(int *)((intptr_t)info+g_iPriceOffset) = price;
1.130 + return true;
1.131 +}
1.132 +
1.133 +bool SetWeaponPrice(const char *weapon, int price)
1.134 +{
1.135 + const char *weaponalias = GetTranslatedWeaponAlias(weapon);
1.136 + int weaponID = AliasToWeaponID(weaponalias);
1.137 + if (weaponID <= 0)
1.138 + {
1.139 + return false;
1.140 + }
1.141 + void *info = GetWeaponInfo(weaponID);
1.142 + if (!info)
1.143 + {
1.144 + return false;
1.145 + }
1.146 + *(int *)((intptr_t)info+g_iPriceOffset) = price;
1.147 + return true;
1.148 +
1.149 +}
1.150 +
1.151 +int CallPriceForwardCSGO(int client, const char *weapon, int price)
1.152 +{
1.153 + int changedprice = price;
1.154 + cell_t result = Pl_Continue;
1.155 +
1.156 + g_pPriceForward->PushCell(client);
1.157 + g_pPriceForward->PushString(weapon);
1.158 + g_pPriceForward->PushCellByRef(&changedprice);
1.159 + g_pPriceForward->Execute(&result);
1.160 +
1.161 + if (result == Pl_Continue)
1.162 + return price;
1.163 +
1.164 + return changedprice;
1.165 +}
1.166 +
1.167 +int CallPriceForwardCSGO(int client, const char *weapon)
1.168 +{
1.169 + const char *weaponalias = GetTranslatedWeaponAlias(weapon);
1.170 + int weaponID = AliasToWeaponID(weaponalias);
1.171 + if (weaponID <= 0)
1.172 + {
1.173 + return -1;
1.174 + }
1.175 + void *info = GetWeaponInfo(weaponID);
1.176 + if (!info)
1.177 + {
1.178 + return -1;
1.179 + }
1.180 + const char *weapon_name = (const char *)((intptr_t)info + weaponNameOffset);
1.181 + int price = *(int *)((intptr_t)info + g_iPriceOffset);
1.182 + int changedprice = price;
1.183 + cell_t result = Pl_Continue;
1.184 +
1.185 + g_pPriceForward->PushCell(client);
1.186 + g_pPriceForward->PushString(weapon_name);
1.187 + g_pPriceForward->PushCellByRef(&changedprice);
1.188 + g_pPriceForward->Execute(&result);
1.189 +
1.190 + if (result == Pl_Continue)
1.191 + return -1;
1.192 + if (SetWeaponPrice(weaponID, changedprice))
1.193 + return price;
1.194 + else
1.195 + return -1;
1.196 +}
1.197 +#else
1.198 +
1.199 int CallPriceForward(int client, const char *weapon_name, int price)
1.200 {
1.201 int changedprice = price;
1.202 @@ -236,3 +360,4 @@
1.203
1.204 return changedprice;
1.205 }
1.206 +#endif