Semi-tested fix for CS:GO GetWeaponPrice on Linux.

This commit is contained in:
Nicholas Hastings
2016-11-29 10:42:05 -05:00
parent 90cefa9daf
commit c4487b74ee
3 changed files with 61 additions and 59 deletions
+42 -34
View File
@@ -230,50 +230,58 @@ const char *WeaponIDToAlias(int weaponID)
return alias;
}
#if SOURCE_ENGINE == SE_CSGO && defined(WIN32)
#if SOURCE_ENGINE == SE_CSGO
void *GetWeaponPriceFunction()
{
static void *pGetWeaponPriceAddress = NULL;
if(pGetWeaponPriceAddress == NULL)
static void *pGetWeaponPriceAddress = nullptr;
if (pGetWeaponPriceAddress)
{
void *pAddress = NULL;
int offset = 0;
int callOffset = 0;
const char* byteCheck = NULL;
return pGetWeaponPriceAddress;
}
if(!g_pGameConf->GetMemSig("GetWeaponPrice", &pAddress) || pAddress == NULL)
{
g_pSM->LogError(myself, "Failed to get GetWeaponPrice address.");
return NULL;
}
void *pAddress = nullptr;
int offset = 0;
int callOffset = 0;
const char* byteCheck = nullptr;
if(!g_pGameConf->GetOffset("GetWeaponPriceFunc", &offset))
{
g_pSM->LogError(myself, "Failed to get GetWeaponPriceFunc offset.");
return NULL;
}
if (!g_pGameConf->GetMemSig("GetWeaponPrice", &pAddress) || !pAddress)
{
g_pSM->LogError(myself, "Failed to get GetWeaponPrice address.");
return nullptr;
}
byteCheck = g_pGameConf->GetKeyValue("GetWeaponPriceByteCheck");
if (!g_pGameConf->GetOffset("GetWeaponPriceFunc", &offset))
{
// If no offset specified, assume that GetWeaponPrice is the func we want, and not just our
// helper to find the real one.
pGetWeaponPriceAddress = pAddress;
return pGetWeaponPriceAddress;
}
if(byteCheck == NULL)
{
g_pSM->LogError(myself, "Failed to get GetWeaponPriceByteCheck keyvalue.");
return NULL;
}
#if defined( _WIN32 )
byteCheck = g_pGameConf->GetKeyValue("GetWeaponPriceByteCheck");
#elif defined( _LINUX )
byteCheck = g_pGameConf->GetKeyValue("GetWeaponPriceByteCheck_Linux");
#else
// We don't compile for csgo on mac anymore
#error Unsupported platform
#endif
if (byteCheck == nullptr)
{
g_pSM->LogError(myself, "Failed to get GetWeaponPriceByteCheck keyvalue.");
return nullptr;
}
uint8_t iByte = strtoul(byteCheck, NULL, 16);
uint8_t iByte = strtoul(byteCheck, nullptr, 16);
if (iByte != *(uint8_t *)((intptr_t)pAddress + (offset-1)))
{
g_pSM->LogError(myself, "GetWeaponPrice Byte check failed.");
return nullptr;
}
if(iByte != *(uint8_t *)((intptr_t)pAddress + (offset-1)))
{
g_pSM->LogError(myself, "GetWeaponPrice Byte check failed.");
return NULL;
}
callOffset = *(uint32_t *)((intptr_t)pAddress + offset);
callOffset = *(uint32_t *)((intptr_t)pAddress + offset);
pGetWeaponPriceAddress = (void *)((intptr_t)pAddress + offset + callOffset + sizeof(int));
}
pGetWeaponPriceAddress = (void *)((intptr_t)pAddress + offset + callOffset + sizeof(int));
return pGetWeaponPriceAddress;
}