@@ -8,7 +8,9 @@ bool g_pIgnoreTerminateDetour = false;
8
8
bool g_pIgnoreCSWeaponDropDetour = false ;
9
9
bool g_PriceDetoured = false ;
10
10
bool g_HandleBuyDetoured = false ;
11
+ #if SOURCE_ENGINE != SE_CSGO
11
12
int lastclient = -1 ;
13
+ #endif
12
14
13
15
IForward *g_pHandleBuyForward = NULL ;
14
16
IForward *g_pPriceForward = NULL ;
@@ -22,10 +24,77 @@ CDetour *DCSWeaponDrop = NULL;
22
24
int weaponNameOffset = -1 ;
23
25
24
26
#if SOURCE_ENGINE == SE_CSGO
25
- DETOUR_DECL_MEMBER3 (DetourHandleBuy, int , int , iUnknown, const char *, weapon, bool , bRebuy)
27
+ DETOUR_DECL_MEMBER3 (DetourHandleBuy, int , int , iLoadoutSlot, void *, pWpnDataRef, bool , bRebuy)
28
+ {
29
+ int client = gamehelpers->EntityToBCompatRef (reinterpret_cast <CBaseEntity *>(this ));
30
+
31
+ CEconItemView *pView = GetEconItemView (this , iLoadoutSlot);
32
+
33
+ if (!pView)
34
+ {
35
+ return DETOUR_MEMBER_CALL (DetourHandleBuy)(iLoadoutSlot, pWpnDataRef, bRebuy);
36
+ }
37
+
38
+ void *pWpnData = GetCCSWeaponData (pView);
39
+
40
+ if (!pWpnData)
41
+ {
42
+ return DETOUR_MEMBER_CALL (DetourHandleBuy)(iLoadoutSlot, pWpnDataRef, bRebuy);
43
+ }
44
+
45
+ const char *szClassname = *(const char **)((intptr_t )pWpnData + weaponNameOffset);
46
+
47
+ char weaponName[128 ];
48
+
49
+ if (strstr (szClassname, " knife" ))
50
+ {
51
+ Q_strncpy (weaponName, " knife" , sizeof (weaponName));
52
+ }
53
+ else
54
+ {
55
+ const char *underscore = strstr (szClassname, " _" );
56
+ if (underscore)
57
+ {
58
+ Q_strncpy (weaponName, (const char *)((intptr_t )underscore + 1 ), sizeof (weaponName));
59
+ }
60
+ else
61
+ {
62
+ Q_strncpy (weaponName, szClassname, sizeof (weaponName));
63
+ }
64
+ }
65
+
66
+ cell_t result = Pl_Continue;
67
+
68
+ g_pHandleBuyForward->PushCell (client);
69
+ g_pHandleBuyForward->PushString (weaponName);
70
+ g_pHandleBuyForward->Execute (&result);
71
+
72
+ if (result != Pl_Continue)
73
+ {
74
+ return 0 ;
75
+ }
76
+
77
+ int originalPrice = 0 ;
78
+
79
+ if (g_iPriceOffset != -1 )
80
+ {
81
+ originalPrice = *(int *)((intptr_t )pWpnData + g_iPriceOffset);
82
+
83
+ int changedPrice = CallPriceForward (client, weaponName, originalPrice);
84
+
85
+ if (originalPrice != changedPrice)
86
+ *(int *)((intptr_t )pWpnData + g_iPriceOffset) = changedPrice;
87
+ }
88
+
89
+ int ret = DETOUR_MEMBER_CALL (DetourHandleBuy)(iLoadoutSlot, pWpnDataRef, bRebuy);
90
+
91
+ if (g_iPriceOffset != -1 )
92
+ *(int *)((intptr_t )pWpnData + g_iPriceOffset) = originalPrice;
93
+
94
+ return ret;
95
+ }
26
96
#else
27
97
DETOUR_DECL_MEMBER1 (DetourHandleBuy, int , const char *, weapon)
28
- #endif
29
98
{
30
99
int client = gamehelpers->EntityToBCompatRef (reinterpret_cast <CBaseEntity *>(this ));
31
100
@@ -43,31 +112,17 @@ DETOUR_DECL_MEMBER1(DetourHandleBuy, int, const char *, weapon)
43
112
return 0 ;
44
113
}
45
114
46
- #if SOURCE_ENGINE == SE_CSGO
47
- int val = DETOUR_MEMBER_CALL (DetourHandleBuy)(iUnknown, weapon, bRebuy);
48
- #else
49
115
int val = DETOUR_MEMBER_CALL (DetourHandleBuy)(weapon);
50
- # endif
116
+
51
117
lastclient = -1 ;
52
118
return val;
53
119
}
120
+ #endif
54
121
55
122
#if SOURCE_ENGINE != SE_CSGO
56
123
DETOUR_DECL_MEMBER0 (DetourWeaponPrice, int )
57
- #elif defined(WIN32)
58
- DETOUR_DECL_MEMBER2 (DetourWeaponPrice, int , CEconItemView *, pEconItem, int , iUnknown)
59
- #else
60
- DETOUR_DECL_MEMBER3 (DetourWeaponPrice, int , CEconItemView *, pEconItem, int , iUnknown, float , fUnknown )
61
- #endif
62
124
{
63
-
64
- #if SOURCE_ENGINE != SE_CSGO
65
125
int price = DETOUR_MEMBER_CALL (DetourWeaponPrice)();
66
- #elif defined(WIN32)
67
- int price = DETOUR_MEMBER_CALL (DetourWeaponPrice)(pEconItem, iUnknown);
68
- #else
69
- int price = DETOUR_MEMBER_CALL (DetourWeaponPrice)(pEconItem, iUnknown, fUnknown );
70
- #endif
71
126
72
127
if (lastclient == -1 )
73
128
return price;
@@ -76,6 +131,7 @@ DETOUR_DECL_MEMBER3(DetourWeaponPrice, int, CEconItemView *, pEconItem, int, iUn
76
131
77
132
return CallPriceForward (lastclient, weapon_name, price);
78
133
}
134
+ #endif
79
135
80
136
#if SOURCE_ENGINE != SE_CSGO || !defined(WIN32)
81
137
DETOUR_DECL_MEMBER2 (DetourTerminateRound, void , float , delay, int , reason)
@@ -179,6 +235,7 @@ DETOUR_DECL_MEMBER3(DetourCSWeaponDrop, void, CBaseEntity *, weapon, bool, bDrop
179
235
180
236
bool CreateWeaponPriceDetour ()
181
237
{
238
+ #if SOURCE_ENGINE != SE_CSGO
182
239
if (weaponNameOffset == -1 )
183
240
{
184
241
if (!g_pGameConf->GetOffset (" WeaponName" , &weaponNameOffset))
@@ -188,18 +245,7 @@ bool CreateWeaponPriceDetour()
188
245
}
189
246
}
190
247
191
- #if SOURCE_ENGINE == SE_CSGO
192
- void *pGetWeaponPriceAddress = GetWeaponPriceFunction ();
193
-
194
- if (!pGetWeaponPriceAddress)
195
- {
196
- g_pSM->LogError (myself, " GetWeaponPrice detour could not be initialized - Disabled OnGetWeaponPrice forward." );
197
- }
198
-
199
- DWeaponPrice = DETOUR_CREATE_MEMBER (DetourWeaponPrice, pGetWeaponPriceAddress);
200
- #else
201
248
DWeaponPrice = DETOUR_CREATE_MEMBER (DetourWeaponPrice, " GetWeaponPrice" );
202
- #endif
203
249
if (DWeaponPrice != NULL )
204
250
{
205
251
if (!CreateHandleBuyDetour ())
@@ -211,7 +257,27 @@ bool CreateWeaponPriceDetour()
211
257
g_PriceDetoured = true ;
212
258
return true ;
213
259
}
260
+ #else
261
+ if (g_iPriceOffset == -1 )
262
+ {
263
+ if (!g_pGameConf->GetOffset (" WeaponPrice" , &g_iPriceOffset))
264
+ {
265
+ smutils->LogError (myself, " Could not find WeaponPrice offset - Disabled OnGetWeaponPrice forward" );
266
+ return false ;
267
+ }
268
+ }
214
269
270
+ if (!CreateHandleBuyDetour ())
271
+ {
272
+ g_pSM->LogError (myself, " GetWeaponPrice detour could not be initialized - HandleCommand_Buy_Internal failed to detour, disabled OnGetWeaponPrice forward." );
273
+ return false ;
274
+ }
275
+ else
276
+ {
277
+ g_PriceDetoured = true ;
278
+ return true ;
279
+ }
280
+ #endif
215
281
g_pSM->LogError (myself, " GetWeaponPrice detour could not be initialized - Disabled OnGetWeaponPrice forward." );
216
282
217
283
return false ;
@@ -236,6 +302,16 @@ bool CreateHandleBuyDetour()
236
302
if (g_HandleBuyDetoured)
237
303
return true ;
238
304
305
+ #if SOURCE_ENGINE == SE_CSGO
306
+ if (weaponNameOffset == -1 )
307
+ {
308
+ if (!g_pGameConf->GetOffset (" WeaponName" , &weaponNameOffset))
309
+ {
310
+ smutils->LogError (myself, " Could not find WeaponName offset - Disabled OnBuyCommand forward" );
311
+ return false ;
312
+ }
313
+ }
314
+ #endif
239
315
DHandleBuy = DETOUR_CREATE_MEMBER (DetourHandleBuy, " HandleCommand_Buy_Internal" );
240
316
241
317
if (DHandleBuy != NULL )
@@ -305,6 +381,7 @@ void RemoveCSWeaponDropDetour()
305
381
}
306
382
g_pCSWeaponDropDetoured = false ;
307
383
}
384
+
308
385
int CallPriceForward (int client, const char *weapon_name, int price)
309
386
{
310
387
int changedprice = price;
0 commit comments