1.1 --- a/core/logic/smn_functions.cpp Tue Oct 29 20:08:18 2013 -0400
1.2 +++ b/core/logic/smn_functions.cpp Tue Oct 29 22:10:40 2013 -0400
1.3 @@ -33,6 +33,8 @@
1.4 #include <IPluginSys.h>
1.5 #include <IHandleSys.h>
1.6 #include <IForwardSys.h>
1.7 +#include <ISourceMod.h>
1.8 +#include <am-utility.h>
1.9
1.10 HandleType_t g_GlobalFwdType = 0;
1.11 HandleType_t g_PrivateFwdType = 0;
1.12 @@ -589,6 +591,63 @@
1.13 return 1;
1.14 }
1.15
1.16 +struct SMFrameActionData
1.17 +{
1.18 + SMFrameActionData(Handle_t handle, Handle_t ownerhandle, cell_t data) : handle(handle), ownerhandle(ownerhandle), data(data)
1.19 + {
1.20 + };
1.21 + Handle_t handle;
1.22 + Handle_t ownerhandle;
1.23 + cell_t data;
1.24 +};
1.25 +
1.26 +static void PawnFrameAction(void *pData)
1.27 +{
1.28 + ke::AutoPtr<SMFrameActionData> frame(reinterpret_cast<SMFrameActionData *>(pData));
1.29 + IPlugin *pPlugin = pluginsys->PluginFromHandle(frame->ownerhandle, NULL);
1.30 + if (!pPlugin)
1.31 + {
1.32 + return;
1.33 + }
1.34 +
1.35 + IChangeableForward *pForward;
1.36 + HandleSecurity sec(pPlugin->GetIdentity(), g_pCoreIdent);
1.37 + if (handlesys->ReadHandle(frame->handle, g_PrivateFwdType, &sec, (void **)&pForward) != HandleError_None)
1.38 + {
1.39 + return;
1.40 + }
1.41 +
1.42 + pForward->PushCell(frame->data);
1.43 + pForward->Execute(NULL);
1.44 +
1.45 + handlesys->FreeHandle(frame->handle, &sec);
1.46 +}
1.47 +
1.48 +static cell_t sm_AddFrameAction(IPluginContext *pContext, const cell_t *params)
1.49 +{
1.50 + IPlugin *pPlugin = pluginsys->FindPluginByContext(pContext->GetContext());
1.51 + IPluginFunction *pFunction = pPlugin->GetBaseContext()->GetFunctionById(params[1]);
1.52 + if (!pFunction)
1.53 + {
1.54 + return pContext->ThrowNativeError("Invalid function id (%X)", params[1]);
1.55 + }
1.56 +
1.57 + IChangeableForward *pForward = forwardsys->CreateForwardEx(NULL, ET_Ignore, 1, NULL, Param_Cell);
1.58 + IdentityToken_t *pIdentity = pContext->GetIdentity();
1.59 + Handle_t Handle = handlesys->CreateHandle(g_PrivateFwdType, pForward, pIdentity, g_pCoreIdent, NULL);
1.60 + if (Handle == BAD_HANDLE)
1.61 + {
1.62 + delete pForward;
1.63 + return 0;
1.64 + }
1.65 +
1.66 + pForward->AddFunction(pFunction);
1.67 +
1.68 + SMFrameActionData *pData = new SMFrameActionData(Handle, pPlugin->GetMyHandle(), params[2]);
1.69 + g_pSM->AddFrameAction(PawnFrameAction, pData);
1.70 + return 1;
1.71 +}
1.72 +
1.73 REGISTER_NATIVES(functionNatives)
1.74 {
1.75 {"GetFunctionByName", sm_GetFunctionByName},
1.76 @@ -610,5 +669,6 @@
1.77 {"Call_PushStringEx", sm_CallPushStringEx},
1.78 {"Call_Finish", sm_CallFinish},
1.79 {"Call_Cancel", sm_CallCancel},
1.80 + {"RequestFrame", sm_AddFrameAction},
1.81 {NULL, NULL},
1.82 };