Hi,
so i have been trying to add a native which calls
PHP Code:
CHL2MP_Player::InfectPlayer(float time)
got that all setup no compile errors however when i try to load it it gives the error
PHP Code:
undefined symbol: g_RegNatives
Thing is now as you can see there is no line information about it. I did it based on the cstrike extension using CS_RespawnPlayer and CS_SwitchTeam.
Game is ZPS if that any helps.
RegNatives.cpp
PHP Code:
#include "extension.h"
#include "RegNatives.h"
RegNatives g_RegNatives;
void RegNatives::Register(ICallWrapper *pWrapper)
{
m_List.push_back(pWrapper);
}
void RegNatives::UnregisterAll()
{
SourceHook::List<ICallWrapper *>::iterator iter;
for(iter = m_List.begin(); iter != m_List.end(); iter++)
{
(*iter)->Destroy();
}
m_List.clear();
}
RegNatives.h
PHP Code:
#ifndef _INCLUDE_ZPS_REGNATIVES_H
#define _INCLUDE_ZPS_REGNATIVES_H
#include <sh_list.h>
class RegNatives
{
public:
void Register(ICallWrapper *pWrapper);
void UnregisterAll();
private:
SourceHook::List<ICallWrapper *> m_List;
};
extern RegNatives g_RegNatives;
#endif
PHP Code:
g_RegNatives.UnregisterAll();
gets called in the
PHP Code:
NotifyInterfaceDrop
and on the
function.
In natives.cpp
PHP Code:
#define REGISTER_NATIVE_ADDR(name, code) \
void *addr; \
if (!g_pGameConf->GetMemSig(name, &addr) || !addr) \
{ \
return pContext->ThrowNativeError("Failed to locate function"); \
} \
code; \
g_RegNatives.Register(pWrapper);
#define GET_MEMSIG(name) \
if (!g_pGameConf->GetMemSig(name, &addr) || !addr) \
{ \
return pContext->ThrowNativeError("Failed to locate function"); \
}
inline CBaseEntity *GetCBaseEntity(int num, bool isplayer)
{
edict_t *pEdict = gamehelpers->EdictOfIndex(num);
if (!pEdict || pEdict->IsFree())
{
return NULL;
}
if (num > 0 && num <= playerhelpers->GetMaxClients())
{
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(pEdict);
if (!pPlayer || !pPlayer->IsConnected())
{
return NULL;
}
}
else if (isplayer)
{
return NULL;
}
IServerUnknown *pUnk;
if ((pUnk=pEdict->GetUnknown()) == NULL)
{
return NULL;
}
return pUnk->GetBaseEntity();
}
// Inside the Native function body
static ICallWrapper *pWrapper = NULL;
if(!pWrapper)
{
REGISTER_NATIVE_ADDR("CHL2MP_Player::InfectPlayer",
PassInfo pass[1]; \
pass[0].flags = PASSFLAG_BYVAL; \
pass[0].size = sizeof(float); \
pass[0].type = PassType_Float; \
pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, NULL, pass, 1));
}
I cannot post the entire extension as this is a private one (not made by me).