Example #1
0
bool CreateWeaponPriceDetour()
{
	if (weaponNameOffset == -1)
	{
		if (!g_pGameConf->GetOffset("WeaponName", &weaponNameOffset))
		{
			smutils->LogError(myself, "Could not find WeaponName offset - Disabled OnGetWeaponPrice forward");
			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)
	{
		if (!CreateHandleBuyDetour())
		{
			g_pSM->LogError(myself, "GetWeaponPrice detour could not be initialized - HandleCommand_Buy_Internal failed to detour, disabled OnGetWeaponPrice forward.");
			return false;
		}
		DWeaponPrice->EnableDetour();
		g_PriceDetoured = true;
		return true;
	}

	g_pSM->LogError(myself, "GetWeaponPrice detour could not be initialized - Disabled OnGetWeaponPrice forward.");

	return false;
#endif
}
Example #2
0
void CStrike::OnPluginLoaded(IPlugin *plugin)
{
	if (!m_WeaponPriceDetourEnabled && g_pPriceForward->GetFunctionCount())
	{
		m_WeaponPriceDetourEnabled = CreateWeaponPriceDetour();
		if (m_WeaponPriceDetourEnabled)
			m_HandleBuyDetourEnabled = true;
	}
	if (!m_TerminateRoundDetourEnabled && g_pTerminateRoundForward->GetFunctionCount())
	{
		m_TerminateRoundDetourEnabled = CreateTerminateRoundDetour();
	}
	if (!m_HandleBuyDetourEnabled && g_pHandleBuyForward->GetFunctionCount())
	{
		m_HandleBuyDetourEnabled = CreateHandleBuyDetour();
	}
	if (!m_CSWeaponDetourEnabled && g_pCSWeaponDropForward->GetFunctionCount())
	{
		m_CSWeaponDetourEnabled = CreateCSWeaponDropDetour();
	}
}