本文整理汇总了C++中IPluginFunction类的典型用法代码示例。如果您正苦于以下问题:C++ IPluginFunction类的具体用法?C++ IPluginFunction怎么用?C++ IPluginFunction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IPluginFunction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sm_CallFinish
static cell_t sm_CallFinish(IPluginContext *pContext, const cell_t *params)
{
int err = SP_ERROR_NOT_RUNNABLE;
cell_t *result;
if (!s_CallStarted)
{
return pContext->ThrowNativeError("Cannot finish call when there is no call in progress");
}
pContext->LocalToPhysAddr(params[1], &result);
if (s_pFunction)
{
IPluginFunction *pFunction = s_pFunction;
ResetCall();
err = pFunction->Execute(result);
} else if (s_pForward) {
IForward *pForward = s_pForward;
ResetCall();
err = pForward->Execute(result, NULL);
}
return err;
}
示例2: Execute
static int Execute(const char *file)
{
ICompilation *co = g_engine2.StartCompilation();
if (!co) {
fprintf(stderr, "Could not create a compilation context\n");
return 1;
}
int err;
AutoT<IPluginRuntime> rt(g_engine2.LoadPlugin(co, file, &err));
if (!rt) {
fprintf(stderr, "Could not load plugin: %s\n", g_engine1.GetErrorString(err));
return 1;
}
BindNative(rt, "print", Print);
BindNative(rt, "printnum", PrintNum);
BindNative(rt, "printnums", PrintNums);
BindNative(rt, "printfloat", PrintFloat);
BindNative(rt, "donothing", DoNothing);
IPluginFunction *fun = rt->GetFunctionByName("main");
if (!fun)
return 0;
IPluginContext *cx = rt->GetDefaultContext();
int result = fun->Execute2(cx, &err);
if (err != SP_ERROR_NONE) {
fprintf(stderr, "Error executing main(): %s\n", g_engine1.GetErrorString(err));
return 1;
}
return result;
}
示例3: OnEmitAmbientSound
void SoundHooks::OnEmitAmbientSound(CEntityIndex index, const Vector &pos, const char *samp, float vol,
soundlevel_t soundlevel, int fFlags, int pitch, float delay)
{
int entindex = index.Get();
#else
void SoundHooks::OnEmitAmbientSound(int entindex, const Vector &pos, const char *samp, float vol,
soundlevel_t soundlevel, int fFlags, int pitch, float delay)
{
#endif
SoundHookIter iter;
IPluginFunction *pFunc;
cell_t vec[3] = {sp_ftoc(pos.x), sp_ftoc(pos.y), sp_ftoc(pos.z)};
cell_t res = static_cast<ResultType>(Pl_Continue);
char buffer[PLATFORM_MAX_PATH];
strcpy(buffer, samp);
for (iter=m_AmbientFuncs.begin(); iter!=m_AmbientFuncs.end(); iter++)
{
pFunc = (*iter);
pFunc->PushStringEx(buffer, sizeof(buffer), SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK);
pFunc->PushCellByRef(&entindex);
pFunc->PushFloatByRef(&vol);
pFunc->PushCellByRef(reinterpret_cast<cell_t *>(&soundlevel));
pFunc->PushCellByRef(&pitch);
pFunc->PushArray(vec, 3, SM_PARAM_COPYBACK);
pFunc->PushCellByRef(&fFlags);
pFunc->PushFloatByRef(&delay);
g_InSoundHook = true;
pFunc->Execute(&res);
g_InSoundHook = false;
switch (res)
{
case Pl_Handled:
case Pl_Stop:
{
RETURN_META(MRES_SUPERCEDE);
}
case Pl_Changed:
{
Vector vec2;
vec2.x = sp_ctof(vec[0]);
vec2.y = sp_ctof(vec[1]);
vec2.z = sp_ctof(vec[2]);
#if SOURCE_ENGINE == SE_DOTA
RETURN_META_NEWPARAMS(MRES_IGNORED, &IVEngineServer::EmitAmbientSound,
(CEntityIndex(entindex), vec2, buffer, vol, soundlevel, fFlags, pitch, delay));
#else
RETURN_META_NEWPARAMS(MRES_IGNORED, &IVEngineServer::EmitAmbientSound,
(entindex, vec2, buffer, vol, soundlevel, fFlags, pitch, delay));
#endif
}
}
}
}
示例4: sort_adtarray_custom
int sort_adtarray_custom(const void *elem1, const void *elem2)
{
cell_t result = 0;
IPluginFunction *pf = g_SortInfoADT.pFunc;
pf->PushCell(((cell_t) ((cell_t *) elem1 - g_SortInfoADT.array_base)) / g_SortInfoADT.array_bsize);
pf->PushCell(((cell_t) ((cell_t *) elem2 - g_SortInfoADT.array_base)) / g_SortInfoADT.array_bsize);
pf->PushCell(g_SortInfoADT.array_hndl);
pf->PushCell(g_SortInfoADT.hndl);
pf->Execute(&result);
return result;
}
示例5: sizeof
void SoundHooks::OnEmitSound2(IRecipientFilter &filter, int iEntIndex, int iChannel, const char *pSample,
float flVolume, float flAttenuation, int iFlags, int iPitch, const Vector *pOrigin,
const Vector *pDirection, CUtlVector<Vector> *pUtlVecOrigins, bool bUpdatePositions,
float soundtime, int speakerentity)
{
SoundHookIter iter;
IPluginFunction *pFunc;
cell_t res = static_cast<ResultType>(Pl_Continue);
cell_t sndlevel = static_cast<cell_t>(ATTN_TO_SNDLVL(flAttenuation));
char buffer[PLATFORM_MAX_PATH];
strcpy(buffer, pSample);
for (iter=m_NormalFuncs.begin(); iter!=m_NormalFuncs.end(); iter++)
{
int players[64], size;
size = _FillInPlayers(players, &filter);
pFunc = (*iter);
pFunc->PushArray(players, 64, SM_PARAM_COPYBACK);
pFunc->PushCellByRef(&size);
pFunc->PushStringEx(buffer, sizeof(buffer), SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK);
pFunc->PushCellByRef(&iEntIndex);
pFunc->PushCellByRef(&iChannel);
pFunc->PushFloatByRef(&flVolume);
pFunc->PushCellByRef(&sndlevel);
pFunc->PushCellByRef(&iPitch);
pFunc->PushCellByRef(&iFlags);
g_InSoundHook = true;
pFunc->Execute(&res);
g_InSoundHook = false;
switch (res)
{
case Pl_Handled:
case Pl_Stop:
{
RETURN_META(MRES_SUPERCEDE);
}
case Pl_Changed:
{
CellRecipientFilter crf;
crf.Initialize(players, size);
RETURN_META_NEWPARAMS(
MRES_IGNORED,
static_cast<void (IEngineSound::*)(IRecipientFilter &, int, int, const char*, float, float,
int, int, const Vector *, const Vector *, CUtlVector<Vector> *, bool, float, int)>(&IEngineSound::EmitSound),
(crf, iEntIndex, iChannel, buffer, flVolume, SNDLVL_TO_ATTN(static_cast<soundlevel_t>(sndlevel)),
iFlags, iPitch, pOrigin, pDirection, pUtlVecOrigins, bUpdatePositions, soundtime, speakerentity)
);
}
}
}
}
示例6: OnTimer
ResultType TimerNatives::OnTimer(ITimer *pTimer, void *pData)
{
TimerInfo *pInfo = reinterpret_cast<TimerInfo *>(pData);
IPluginFunction *pFunc = pInfo->Hook;
cell_t res = static_cast<ResultType>(Pl_Continue);
pFunc->PushCell(pInfo->TimerHandle);
pFunc->PushCell(pInfo->UserData);
pFunc->Execute(&res);
return static_cast<ResultType>(res);
}
示例7: SM_DoSingleExecFwds
void SM_DoSingleExecFwds(IPluginContext *ctx)
{
IPluginFunction *pf;
if ((pf = ctx->GetFunctionByName("OnServerCfg")) != NULL)
{
pf->Execute(NULL);
}
if ((pf = ctx->GetFunctionByName("OnConfigsExecuted")) != NULL)
{
pf->Execute(NULL);
}
}
示例8: sort1d_amx_custom
int sort1d_amx_custom(const void *elem1, const void *elem2)
{
cell_t c1 = *(cell_t *)elem1;
cell_t c2 = *(cell_t *)elem2;
cell_t result = 0;
IPluginFunction *pf = g_SortInfo.pFunc;
pf->PushCell(c1);
pf->PushCell(c2);
pf->PushCell(g_SortInfo.array_addr);
pf->PushCell(g_SortInfo.hndl);
pf->Execute(&result);
return result;
}
示例9: OnQueryCvarValueFinished
void ConVarManager::OnQueryCvarValueFinished(QueryCvarCookie_t cookie, edict_t *pPlayer, EQueryCvarValueStatus result, const char *cvarName, const char *cvarValue)
#endif // SE_DOTA
{
IPluginFunction *pCallback = NULL;
cell_t value = 0;
List<ConVarQuery>::iterator iter;
for (iter = m_ConVarQueries.begin(); iter != m_ConVarQueries.end(); iter++)
{
ConVarQuery &query = (*iter);
if (query.cookie == cookie)
{
pCallback = query.pCallback;
value = query.value;
break;
}
}
if (pCallback)
{
cell_t ret;
pCallback->PushCell(cookie);
#if SOURCE_ENGINE == SE_DOTA
pCallback->PushCell(player.Get());
#else
pCallback->PushCell(IndexOfEdict(pPlayer));
#endif
pCallback->PushCell(result);
pCallback->PushString(cvarName);
if (result == eQueryCvarValueStatus_ValueIntact)
{
pCallback->PushString(cvarValue);
}
else
{
pCallback->PushString("\0");
}
pCallback->PushCell(value);
pCallback->Execute(&ret);
m_ConVarQueries.erase(iter);
}
}
示例10: Execute
static int Execute(const char *file)
{
char error[255];
AutoPtr<IPluginRuntime> rtb(sEnv->APIv2()->LoadBinaryFromFile(file, error, sizeof(error)));
if (!rtb) {
fprintf(stderr, "Could not load plugin %s: %s\n", file, error);
return 1;
}
PluginRuntime* rt = PluginRuntime::FromAPI(rtb);
rt->InstallBuiltinNatives();
BindNative(rt, "print", Print);
BindNative(rt, "printnum", PrintNum);
BindNative(rt, "printnums", PrintNums);
BindNative(rt, "printfloat", PrintFloat);
BindNative(rt, "writefloat", WriteFloat);
BindNative(rt, "donothing", DoNothing);
BindNative(rt, "execute", DoExecute);
BindNative(rt, "invoke", DoInvoke);
BindNative(rt, "dump_stack_trace", DumpStackTrace);
BindNative(rt, "report_error", ReportError);
IPluginFunction *fun = rt->GetFunctionByName("main");
if (!fun)
return 0;
IPluginContext *cx = rt->GetDefaultContext();
int result;
{
ExceptionHandler eh(cx);
if (!fun->Invoke(&result)) {
fprintf(stderr, "Error executing main: %s\n", eh.Message());
return 1;
}
}
return result;
}
示例11: OnGameFrameHit
// Frame hit
void OnGameFrameHit(bool simulating)
{
// Could lock?
if (m_locked)
{
return;
}
// Lock
m_locked = true;
// Item in vec?
if (!vecPawnReturn.empty())
{
// Get Last item
PawnFuncThreadReturn *pReturn = vecPawnReturn.back();
vecPawnReturn.pop_back();
// Call Forward
IPluginFunction *pFunc = pReturn->pFunc;
if (pFunc != NULL && pFunc->IsRunnable())
{
pFunc->PushCell(pReturn->result);
pFunc->PushCell(pReturn->error);
pFunc->Execute(NULL);
}
// Delete item
delete pReturn;
}
// Unlock
m_locked = false;
}
示例12: OnClientQueryFinished
void ConVarManager::OnClientQueryFinished(QueryCvarCookie_t cookie,
int client,
EQueryCvarValueStatus result,
const char *cvarName,
const char *cvarValue)
{
IPluginFunction *pCallback = NULL;
cell_t value = 0;
List<ConVarQuery>::iterator iter;
for (iter = m_ConVarQueries.begin(); iter != m_ConVarQueries.end(); iter++)
{
ConVarQuery &query = (*iter);
if (query.cookie == cookie)
{
pCallback = query.pCallback;
value = query.value;
break;
}
}
if (pCallback)
{
cell_t ret;
pCallback->PushCell(cookie);
pCallback->PushCell(client);
pCallback->PushCell(result);
pCallback->PushString(cvarName);
if (result == eQueryCvarValueStatus_ValueIntact)
{
pCallback->PushString(cvarValue);
}
else
{
pCallback->PushString("\0");
}
pCallback->PushCell(value);
pCallback->Execute(&ret);
m_ConVarQueries.erase(iter);
}
}
示例13: OnPlaybackTempEntity
void TempEntHooks::OnPlaybackTempEntity(IRecipientFilter &filter, float delay, const void *pSender, const SendTable *pST, int classID)
{
TEHookInfo *pInfo;
const char *name = g_TEManager.GetNameFromThisPtr(const_cast<void *>(pSender));
if (m_TEHooks->Retrieve(name, reinterpret_cast<void **>(&pInfo)))
{
SourceHook::List<IPluginFunction *>::iterator iter;
IPluginFunction *pFunc;
size_t size;
cell_t res = static_cast<ResultType>(Pl_Continue);
TempEntityInfo *oldinfo = g_CurrentTE;
g_CurrentTE = pInfo->te;
size = _FillInPlayers(g_TEPlayers, &filter);
for (iter=pInfo->lst.begin(); iter!=pInfo->lst.end(); iter++)
{
pFunc = (*iter);
pFunc->PushString(name);
pFunc->PushArray(g_TEPlayers, size);
pFunc->PushCell(size);
pFunc->PushFloat(delay);
pFunc->Execute(&res);
if (res != Pl_Continue)
{
g_CurrentTE = oldinfo;
RETURN_META(MRES_SUPERCEDE);
}
}
g_CurrentTE = oldinfo;
RETURN_META(MRES_IGNORED);
}
}
示例14: if
void SoundHooks::OnEmitSound2(IRecipientFilter &filter, int iEntIndex, int iChannel, const char *pSample,
float flVolume, float flAttenuation, int iFlags, int iPitch, const Vector *pOrigin,
const Vector *pDirection, CUtlVector<Vector> *pUtlVecOrigins, bool bUpdatePositions,
float soundtime, int speakerentity)
#endif
{
SoundHookIter iter;
IPluginFunction *pFunc;
cell_t res = static_cast<ResultType>(Pl_Continue);
cell_t sndlevel = static_cast<cell_t>(ATTN_TO_SNDLVL(flAttenuation));
char buffer[PLATFORM_MAX_PATH];
strcpy(buffer, pSample);
char soundEntry[PLATFORM_MAX_PATH] = "";
#if SOURCE_ENGINE >= SE_PORTAL2
Q_strncpy(soundEntry, pSoundEntry, sizeof(soundEntry));
#endif
#if SOURCE_ENGINE < SE_PORTAL2
int nSeed = 0;
#endif
for (iter=m_NormalFuncs.begin(); iter!=m_NormalFuncs.end(); iter++)
{
int players[SM_MAXPLAYERS], size;
size = _FillInPlayers(players, &filter);
pFunc = (*iter);
pFunc->PushArray(players, SM_ARRAYSIZE(players), SM_PARAM_COPYBACK);
pFunc->PushCellByRef(&size);
pFunc->PushStringEx(buffer, sizeof(buffer), SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK);
pFunc->PushCellByRef(&iEntIndex);
pFunc->PushCellByRef(&iChannel);
pFunc->PushFloatByRef(&flVolume);
pFunc->PushCellByRef(&sndlevel);
pFunc->PushCellByRef(&iPitch);
pFunc->PushCellByRef(&iFlags);
pFunc->PushStringEx(soundEntry, sizeof(soundEntry), SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK);
pFunc->PushCellByRef(&nSeed);
g_InSoundHook = true;
pFunc->Execute(&res);
g_InSoundHook = false;
switch (res)
{
case Pl_Handled:
case Pl_Stop:
{
#if SOURCE_ENGINE >= SE_PORTAL2
RETURN_META_VALUE(MRES_SUPERCEDE, -1);
#else
RETURN_META(MRES_SUPERCEDE);
#endif
}
case Pl_Changed:
{
/* Client validation */
for (int i = 0; i < size; i++)
{
int client = players[i];
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client);
if (!pPlayer)
{
pFunc->GetParentContext()->BlamePluginError(pFunc, "Client index %d is invalid", client);
} else if (!pPlayer->IsInGame()) {
pFunc->GetParentContext()->BlamePluginError(pFunc, "Client %d is not connected", client);
} else {
continue;
}
#if SOURCE_ENGINE >= SE_PORTAL2
RETURN_META_VALUE(MRES_IGNORED, -1 );
#else
return;
#endif
}
#if SOURCE_ENGINE >= SE_PORTAL2
if (strcmp(pSoundEntry, soundEntry) != 0 || strcmp(pSample, buffer) != 0)
{
if (strcmp(soundEntry, buffer) == 0)
nSoundEntryHash = -1;
else if (strcmp(soundEntry, "") != 0)
nSoundEntryHash = GenerateSoundEntryHash(soundEntry);
}
#endif
CellRecipientFilter crf;
crf.Initialize(players, size);
#if SOURCE_ENGINE >= SE_PORTAL2
RETURN_META_VALUE_NEWPARAMS(
MRES_IGNORED,
-1,
static_cast<int (IEngineSound::*)(IRecipientFilter &, int, int, const char *, unsigned int, const char *, float, float,
int, int, int, const Vector *, const Vector *, CUtlVector<Vector> *, bool, float, int)>(&IEngineSound::EmitSound),
(crf, iEntIndex, iChannel, soundEntry, nSoundEntryHash, buffer, flVolume, SNDLVL_TO_ATTN(static_cast<soundlevel_t>(sndlevel)),
nSeed, iFlags, iPitch, pOrigin, pDirection, pUtlVecOrigins, bUpdatePositions, soundtime, speakerentity)
);
#elif SOURCE_ENGINE == SE_CSS || SOURCE_ENGINE == SE_HL2DM || SOURCE_ENGINE == SE_DODS || SOURCE_ENGINE == SE_SDK2013 \
//.........这里部分代码省略.........
示例15: SQL_TConnect
static cell_t SQL_TConnect(IPluginContext *pContext, const cell_t *params)
{
IPluginFunction *pf = pContext->GetFunctionById(params[1]);
if (!pf)
{
return pContext->ThrowNativeError("Function id %x is invalid", params[1]);
}
char *conf;
pContext->LocalToString(params[2], &conf);
IDBDriver *driver = NULL;
const DatabaseInfo *pInfo = g_DBMan.FindDatabaseConf(conf);
char error[255];
if (pInfo != NULL)
{
if (pInfo->driver[0] == '\0')
{
driver = g_DBMan.GetDefaultDriver();
} else {
driver = g_DBMan.FindOrLoadDriver(pInfo->driver);
}
if (!driver)
{
UTIL_Format(error,
sizeof(error),
"Could not find driver \"%s\"",
pInfo->driver[0] == '\0' ? g_DBMan.GetDefaultDriverName() : pInfo->driver);
} else if (!driver->IsThreadSafe()) {
UTIL_Format(error,
sizeof(error),
"Driver \"%s\" is not thread safe!",
driver->GetIdentifier());
}
} else {
UTIL_Format(error, sizeof(error), "Could not find database conf \"%s\"", conf);
}
if (!pInfo || !driver)
{
pf->PushCell(BAD_HANDLE);
pf->PushCell(BAD_HANDLE);
pf->PushString(error);
pf->PushCell(0);
pf->Execute(NULL);
return 0;
}
/* HACK! Add us to the dependency list */
CExtension *pExt = g_Extensions.GetExtensionFromIdent(driver->GetIdentity());
if (pExt)
{
g_Extensions.BindChildPlugin(pExt, g_PluginSys.GetPluginByCtx(pContext->GetContext()));
}
/* Finally, add to the thread if we can */
TConnectOp *op = new TConnectOp(pf, driver, conf, params[3]);
CPlugin *pPlugin = g_PluginSys.GetPluginByCtx(pContext->GetContext());
if (pPlugin->GetProperty("DisallowDBThreads", NULL)
|| !g_DBMan.AddToThreadQueue(op, PrioQueue_High))
{
/* Do everything right now */
op->RunThreadPart();
op->RunThinkPart();
op->Destroy();
}
return 1;
}