komashchenko / PTaH

Additional CS:GO Hooks and Natives
GNU General Public License v3.0
78 stars 42 forks source link

Add Windows support for GetEconItemViewFromWeapon #1

Closed GoD-Tony closed 8 years ago

GoD-Tony commented 8 years ago

The function CBaseCombatWeapon::GetEconItemView is inlined on Windows and must be grabbed directly from the member variable with an offset. This should fix the issue for CS:GO.

komashchenko commented 8 years ago

God-Tony what you think about this variant win and lin?

static cell_t PTaH_GetEconItemViewFromWeapon(IPluginContext *pContext, const cell_t *params)
{
    CBaseEntity *pEntity = gamehelpers->ReferenceToEntity(params[1]);
    if(!pEntity)
    {
        return pContext->ThrowNativeError("Entity %d is invalid", params[1]);
    }

    IServerNetworkable *pNet = ((IServerUnknown *)pEntity)->GetNetworkable();
    if (!pNet || !UTIL_ContainsDataTable(pNet->GetServerClass()->m_pTable, "DT_BaseCombatWeapon"))
    {
        return pContext->ThrowNativeError("Entity %d is not weapon", params[1]);
    }

    int offset = -1;

    if(!g_pGameConf[GameConf_PTaH]->GetOffset("m_hEconItemView", &offset) || offset == -1)
    {
        smutils->LogError(myself, "Failed to get m_hEconItemView offset");
        return 0;
    }

    return (intptr_t)pEntity + offset;
}
GoD-Tony commented 8 years ago

@komashchenko:

  1. It's your choice if you want to use the offset on Linux as well. It might break less using the function's signature & symbol though.
  2. You should probably cache the result of GetOffset so it doesn't have to be checked every time.

Otherwise it looks good!