Added support for CS:GO to cstrike extension (bug 5299, r=asherkin).
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "extension.h"
|
||||
#include "forwards.h"
|
||||
#include "util_cstrike.h"
|
||||
|
||||
bool g_pTerminateRoundDetoured = false;
|
||||
bool g_pCSWeaponDropDetoured = false;
|
||||
@@ -37,11 +38,27 @@ DETOUR_DECL_MEMBER1(DetourHandleBuy, int, const char *, weapon)
|
||||
lastclient = -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
int defaultprice = -1;
|
||||
if (g_iPriceOffset != -1 && g_PriceDetoured)
|
||||
{
|
||||
defaultprice = CallPriceForwardCSGO(client, weapon);
|
||||
}
|
||||
#endif
|
||||
|
||||
int val = DETOUR_MEMBER_CALL(DetourHandleBuy)(weapon);
|
||||
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
if (defaultprice != -1)
|
||||
SetWeaponPrice(weapon, defaultprice);
|
||||
#endif
|
||||
|
||||
lastclient = -1;
|
||||
return val;
|
||||
}
|
||||
|
||||
#if SOURCE_ENGINE != SE_CSGO
|
||||
DETOUR_DECL_MEMBER0(DetourWeaponPrice, int)
|
||||
{
|
||||
int price = DETOUR_MEMBER_CALL(DetourWeaponPrice)();
|
||||
@@ -53,6 +70,7 @@ DETOUR_DECL_MEMBER0(DetourWeaponPrice, int)
|
||||
|
||||
return CallPriceForward(lastclient, weapon_name, price);
|
||||
}
|
||||
#endif
|
||||
|
||||
DETOUR_DECL_MEMBER2(DetourTerminateRound, void, float, delay, int, reason)
|
||||
{
|
||||
@@ -79,6 +97,7 @@ DETOUR_DECL_MEMBER2(DetourTerminateRound, void, float, delay, int, reason)
|
||||
|
||||
return DETOUR_MEMBER_CALL(DetourTerminateRound)(orgdelay, orgreason);
|
||||
}
|
||||
|
||||
DETOUR_DECL_MEMBER3(DetourCSWeaponDrop, void, CBaseEntity *, weapon, bool, something, bool, toss)
|
||||
{
|
||||
if (g_pIgnoreCSWeaponDropDetour)
|
||||
@@ -102,6 +121,7 @@ DETOUR_DECL_MEMBER3(DetourCSWeaponDrop, void, CBaseEntity *, weapon, bool, somet
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
bool CreateWeaponPriceDetour()
|
||||
{
|
||||
if (weaponNameOffset == -1)
|
||||
@@ -112,6 +132,29 @@ bool CreateWeaponPriceDetour()
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
if (g_iPriceOffset == -1)
|
||||
{
|
||||
if (!g_pGameConf->GetOffset("WeaponPrice", &g_iPriceOffset))
|
||||
{
|
||||
g_iPriceOffset = -1;
|
||||
g_pSM->LogError(myself, "Failed to get WeaponPrice offset - Disabled OnGetWeaponPrice forward");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!CreateHandleBuyDetour())
|
||||
{
|
||||
g_pSM->LogError(myself, "HandleCommand_Buy_Internal failed to detour, disabled OnGetWeaponPrice forward.");
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_PriceDetoured = true;
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
|
||||
DWeaponPrice = DETOUR_CREATE_MEMBER(DetourWeaponPrice, "GetWeaponPrice");
|
||||
|
||||
if (DWeaponPrice != NULL)
|
||||
@@ -129,6 +172,7 @@ bool CreateWeaponPriceDetour()
|
||||
g_pSM->LogError(myself, "GetWeaponPrice detour could not be initialized - Disabled OnGetWeaponPrice forward.");
|
||||
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CreateTerminateRoundDetour()
|
||||
@@ -179,13 +223,14 @@ bool CreateCSWeaponDropDetour()
|
||||
|
||||
void RemoveWeaponPriceDetour()
|
||||
{
|
||||
#if SOURCE_ENGINE != SE_CSGO
|
||||
if (DWeaponPrice != NULL)
|
||||
{
|
||||
DWeaponPrice->Destroy();
|
||||
DWeaponPrice = NULL;
|
||||
}
|
||||
g_PriceDetoured = false;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void RemoveHandleBuyDetour()
|
||||
@@ -220,6 +265,85 @@ void RemoveCSWeaponDropDetour()
|
||||
}
|
||||
g_pCSWeaponDropDetoured = false;
|
||||
}
|
||||
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
bool SetWeaponPrice(int weaponID, int price)
|
||||
{
|
||||
void *info = GetWeaponInfo(weaponID);
|
||||
if (!info)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
*(int *)((intptr_t)info+g_iPriceOffset) = price;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SetWeaponPrice(const char *weapon, int price)
|
||||
{
|
||||
const char *weaponalias = GetTranslatedWeaponAlias(weapon);
|
||||
int weaponID = AliasToWeaponID(weaponalias);
|
||||
if (weaponID <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
void *info = GetWeaponInfo(weaponID);
|
||||
if (!info)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
*(int *)((intptr_t)info+g_iPriceOffset) = price;
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
int CallPriceForwardCSGO(int client, const char *weapon, int price)
|
||||
{
|
||||
int changedprice = price;
|
||||
cell_t result = Pl_Continue;
|
||||
|
||||
g_pPriceForward->PushCell(client);
|
||||
g_pPriceForward->PushString(weapon);
|
||||
g_pPriceForward->PushCellByRef(&changedprice);
|
||||
g_pPriceForward->Execute(&result);
|
||||
|
||||
if (result == Pl_Continue)
|
||||
return price;
|
||||
|
||||
return changedprice;
|
||||
}
|
||||
|
||||
int CallPriceForwardCSGO(int client, const char *weapon)
|
||||
{
|
||||
const char *weaponalias = GetTranslatedWeaponAlias(weapon);
|
||||
int weaponID = AliasToWeaponID(weaponalias);
|
||||
if (weaponID <= 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
void *info = GetWeaponInfo(weaponID);
|
||||
if (!info)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
const char *weapon_name = (const char *)((intptr_t)info + weaponNameOffset);
|
||||
int price = *(int *)((intptr_t)info + g_iPriceOffset);
|
||||
int changedprice = price;
|
||||
cell_t result = Pl_Continue;
|
||||
|
||||
g_pPriceForward->PushCell(client);
|
||||
g_pPriceForward->PushString(weapon_name);
|
||||
g_pPriceForward->PushCellByRef(&changedprice);
|
||||
g_pPriceForward->Execute(&result);
|
||||
|
||||
if (result == Pl_Continue)
|
||||
return -1;
|
||||
if (SetWeaponPrice(weaponID, changedprice))
|
||||
return price;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
|
||||
int CallPriceForward(int client, const char *weapon_name, int price)
|
||||
{
|
||||
int changedprice = price;
|
||||
@@ -236,3 +360,4 @@ int CallPriceForward(int client, const char *weapon_name, int price)
|
||||
|
||||
return changedprice;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user