MTRand *RandObjForPlugin(IPluginContext *ctx) { IPlugin *plugin = pluginsys->FindPluginByContext(ctx->GetContext()); MTRand *mtrand; if (!plugin->GetProperty("core.logic.mtrand", (void**)&mtrand)) { mtrand = new MTRand(); plugin->SetProperty("core.logic.mtrand", mtrand); } return mtrand; }
cell_t AddSettingsMenuItem(IPluginContext *pContext, const cell_t *params) { if (g_ClientPrefs.Database == NULL && !g_ClientPrefs.databaseLoading) { return pContext->ThrowNativeError("Clientprefs is disabled due to a failed database connection"); } char *display; pContext->LocalToString(params[3], &display); /* Register a callback */ ItemHandler *pItem = new ItemHandler; pItem->isAutoMenu = false; pItem->forward = forwards->CreateForwardEx(NULL, ET_Ignore, 5, NULL, Param_Cell, Param_Cell, Param_Cell, Param_String, Param_Cell); pItem->forward->AddFunction(pContext, static_cast<funcid_t>(params[1])); char info[20]; AutoMenuData *data = new AutoMenuData; data->datavalue = params[2]; data->handler = pItem; UTIL_Format(info, sizeof(info), "%x", data); ItemDrawInfo draw(display, 0); g_CookieManager.clientMenu->AppendItem(info, draw); /* Track this in case the plugin unloads */ IPlugin *pPlugin = plsys->FindPluginByContext(pContext->GetContext()); SourceHook::List<char *> *pList = NULL; if (!pPlugin->GetProperty("SettingsMenuItems", (void **)&pList, false) || !pList) { pList = new SourceHook::List<char *>; pPlugin->SetProperty("SettingsMenuItems", pList); } char *copyarray = new char[strlen(display)+1]; UTIL_Format(copyarray, strlen(display)+1, "%s", display); pList->push_back(copyarray); return 0; }
cell_t AddSettingsMenuItem(IPluginContext *pContext, const cell_t *params) { g_ClientPrefs.AttemptReconnection(); char *display; pContext->LocalToString(params[3], &display); /* Register a callback */ ItemHandler *pItem = new ItemHandler; pItem->isAutoMenu = false; pItem->forward = forwards->CreateForwardEx(NULL, ET_Ignore, 5, NULL, Param_Cell, Param_Cell, Param_Cell, Param_String, Param_Cell); pItem->forward->AddFunction(pContext, static_cast<funcid_t>(params[1])); char info[20]; AutoMenuData *data = new AutoMenuData; data->datavalue = params[2]; data->handler = pItem; g_pSM->Format(info, sizeof(info), "%x", data); ItemDrawInfo draw(display, 0); g_CookieManager.clientMenu->AppendItem(info, draw); /* Track this in case the plugin unloads */ IPlugin *pPlugin = plsys->FindPluginByContext(pContext->GetContext()); ke::Vector<char *> *pList = NULL; if (!pPlugin->GetProperty("SettingsMenuItems", (void **)&pList, false) || !pList) { pList = new ke::Vector<char *>; pPlugin->SetProperty("SettingsMenuItems", pList); } char *copyarray = new char[strlen(display)+1]; g_pSM->Format(copyarray, strlen(display)+1, "%s", display); pList->append(copyarray); return 0; }
void ConVarManager::AddConVarToPluginList(IPluginContext *pContext, const ConVar *pConVar) { ConVarList *pConVarList; ConVarList::iterator iter; bool inserted = false; const char *orig = pConVar->GetName(); IPlugin *plugin = scripts->FindPluginByContext(pContext->GetContext()); /* Check plugin for an existing convar list */ if (!plugin->GetProperty("ConVarList", (void **)&pConVarList)) { pConVarList = new ConVarList(); plugin->SetProperty("ConVarList", pConVarList); } else if (pConVarList->find(pConVar) != pConVarList->end()) { /* If convar is already in list, then don't add it */ return; } /* Insert convar into list which is sorted alphabetically */ for (iter = pConVarList->begin(); iter != pConVarList->end(); iter++) { if (strcmp(orig, (*iter)->GetName()) < 0) { pConVarList->insert(iter, pConVar); inserted = true; break; } } if (!inserted) { pConVarList->push_back(pConVar); } }
MsgListenerWrapper *UsrMessageNatives::CreateListener(IPluginContext *pCtx) { MsgWrapperList *pList; MsgListenerWrapper *pListener; IPlugin *pl = g_PluginSys.FindPluginByContext(pCtx->GetContext()); if (m_FreeListeners.empty()) { pListener = new MsgListenerWrapper; } else { pListener = m_FreeListeners.front(); m_FreeListeners.pop(); } if (!pl->GetProperty("MsgListeners", reinterpret_cast<void **>(&pList))) { pList = new List<MsgListenerWrapper *>; pl->SetProperty("MsgListeners", pList); } pList->push_back(pListener); return pListener; }
cell_t AddSettingsPrefabMenuItem(IPluginContext *pContext, const cell_t *params) { g_ClientPrefs.AttemptReconnection(); Handle_t hndl = static_cast<Handle_t>(params[1]); HandleError err; HandleSecurity sec; sec.pOwner = NULL; sec.pIdentity = myself->GetIdentity(); Cookie *pCookie; if ((err = handlesys->ReadHandle(hndl, g_CookieType, &sec, (void **)&pCookie)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Cookie handle %x (error %d)", hndl, err); } /* Register a callback */ ItemHandler *pItem = new ItemHandler; pItem->isAutoMenu = true; pItem->autoMenuType = (CookieMenu)params[2]; /* User passed a function id for a callback */ if (params[4] != -1) { pItem->forward = forwards->CreateForwardEx(NULL, ET_Ignore, 5, NULL, Param_Cell, Param_Cell, Param_Cell, Param_String, Param_Cell); pItem->forward->AddFunction(pContext, static_cast<funcid_t>(params[4])); } else { pItem->forward = NULL; } char *display; pContext->LocalToString(params[3], &display); ItemDrawInfo draw(display, 0); char info[20]; AutoMenuData *data = new AutoMenuData; data->datavalue = params[5]; data->pCookie = pCookie; data->type = (CookieMenu)params[2]; data->handler = pItem; g_pSM->Format(info, sizeof(info), "%x", data); g_CookieManager.clientMenu->AppendItem(info, draw); /* Track this in case the plugin unloads */ IPlugin *pPlugin = plsys->FindPluginByContext(pContext->GetContext()); ke::Vector<char *> *pList = NULL; if (!pPlugin->GetProperty("SettingsMenuItems", (void **)&pList, false) || !pList) { pList = new ke::Vector<char *>; pPlugin->SetProperty("SettingsMenuItems", pList); } char *copyarray = new char[strlen(display)+1]; g_pSM->Format(copyarray, strlen(display)+1, "%s", display); pList->append(copyarray); return 0; }
// HookSingleEntityOutput(int ent, const char[] output, EntityOutput function, bool once); cell_t HookSingleEntityOutput(IPluginContext *pContext, const cell_t *params) { if (!g_OutputManager.IsEnabled()) { return pContext->ThrowNativeError("Entity Outputs are disabled - See error logs for details"); } CBaseEntity *pEntity = gamehelpers->ReferenceToEntity(params[1]); if (!pEntity) { return pContext->ThrowNativeError("Invalid Entity index %i (%i)", gamehelpers->ReferenceToIndex(params[1]), params[1]); } const char *classname = gamehelpers->GetEntityClassname(pEntity); char *outputname; pContext->LocalToString(params[2], &outputname); OutputNameStruct *pOutputName = g_OutputManager.FindOutputPointer((const char *)classname, outputname, true); //Check for an existing identical hook SourceHook::List<omg_hooks *>::iterator _iter; omg_hooks *hook; IPluginFunction *pFunction; pFunction = pContext->GetFunctionById(params[3]); for (_iter=pOutputName->hooks.begin(); _iter!=pOutputName->hooks.end(); _iter++) { hook = (omg_hooks *)*_iter; if (hook->pf == pFunction && hook->entity_ref == gamehelpers->EntityToReference(pEntity)) { return 0; } } hook = g_OutputManager.NewHook(); hook->entity_ref = gamehelpers->EntityToReference(pEntity); hook->only_once= !!params[4]; hook->pf = pFunction; hook->m_parent = pOutputName; hook->in_use = false; hook->delete_me = false; pOutputName->hooks.push_back(hook); g_OutputManager.OnHookAdded(); IPlugin *pPlugin = plsys->FindPluginByContext(pContext->GetContext()); SourceHook::List<omg_hooks *> *pList = NULL; if (!pPlugin->GetProperty("OutputHookList", (void **)&pList, false) || !pList) { pList = new SourceHook::List<omg_hooks *>; pPlugin->SetProperty("OutputHookList", pList); } pList->push_back(hook); return 1; }
// HookEntityOutput(const char[] classname, const char[] output, EntityOutput function); cell_t HookEntityOutput(IPluginContext *pContext, const cell_t *params) { if (!g_OutputManager.IsEnabled()) { return pContext->ThrowNativeError("Entity Outputs are disabled - See error logs for details"); } //Find or create the base structures for this classname and the output char *classname; pContext->LocalToString(params[1], &classname); char *outputname; pContext->LocalToString(params[2], &outputname); OutputNameStruct *pOutputName = g_OutputManager.FindOutputPointer((const char *)classname, outputname, true); //Check for an existing identical hook SourceHook::List<omg_hooks *>::iterator _iter; omg_hooks *hook; IPluginFunction *pFunction; pFunction = pContext->GetFunctionById(params[3]); for (_iter=pOutputName->hooks.begin(); _iter!=pOutputName->hooks.end(); _iter++) { hook = (omg_hooks *)*_iter; if (hook->pf == pFunction && hook->entity_ref == -1) { //already hooked to this function... //throw an error or just let them get away with stupidity? // seems like poor coding if they dont know if something is hooked or not return 0; } } hook = g_OutputManager.NewHook(); hook->entity_ref = -1; hook->pf = pFunction; hook->m_parent = pOutputName; hook->in_use = false; hook->delete_me = false; pOutputName->hooks.push_back(hook); g_OutputManager.OnHookAdded(); IPlugin *pPlugin = plsys->FindPluginByContext(pContext->GetContext()); SourceHook::List<omg_hooks *> *pList = NULL; if (!pPlugin->GetProperty("OutputHookList", (void **)&pList, false) || !pList) { pList = new SourceHook::List<omg_hooks *>; pPlugin->SetProperty("OutputHookList", pList); } pList->push_back(hook); return 1; }
EventHookError EventManager::HookEvent(const char *name, IPluginFunction *pFunction, EventHookMode mode) { EventHook *pHook; /* If we aren't listening to this event... */ if (!gameevents->FindListener(this, name)) { /* Then add ourselves */ if (!gameevents->AddListener(this, name, true)) { /* If event doesn't exist... */ return EventHookErr_InvalidEvent; } } /* If a hook structure does not exist... */ if (!sm_trie_retrieve(m_EventHooks, name, (void **)&pHook)) { EventHookList *pHookList; IPlugin *plugin = g_PluginSys.GetPluginByCtx(pFunction->GetParentContext()->GetContext()); /* Check plugin for an existing EventHook list */ if (!plugin->GetProperty("EventHooks", (void **)&pHookList)) { pHookList = new EventHookList(); plugin->SetProperty("EventHooks", pHookList); } /* Create new GameEventHook structure */ pHook = new EventHook(); if (mode == EventHookMode_Pre) { /* Create forward for a pre hook */ pHook->pPreHook = g_Forwards.CreateForwardEx(NULL, ET_Hook, 3, GAMEEVENT_PARAMS); /* Add to forward list */ pHook->pPreHook->AddFunction(pFunction); } else { /* Create forward for a post hook */ pHook->pPostHook = g_Forwards.CreateForwardEx(NULL, ET_Ignore, 3, GAMEEVENT_PARAMS); /* Should we copy data from a pre hook to the post hook? */ pHook->postCopy = (mode == EventHookMode_Post); /* Add to forward list */ pHook->pPostHook->AddFunction(pFunction); } /* Increase reference count */ pHook->refCount++; /* Add hook structure to hook lists */ pHookList->push_back(pHook); sm_trie_insert(m_EventHooks, name, pHook); return EventHookErr_Okay; } /* Hook structure already exists at this point */ if (mode == EventHookMode_Pre) { /* Create pre hook forward if necessary */ if (!pHook->pPreHook) { pHook->pPreHook = g_Forwards.CreateForwardEx(NULL, ET_Event, 3, GAMEEVENT_PARAMS); } /* Add plugin function to forward list */ pHook->pPreHook->AddFunction(pFunction); } else { /* Create post hook forward if necessary */ if (!pHook->pPostHook) { pHook->pPostHook = g_Forwards.CreateForwardEx(NULL, ET_Ignore, 3, GAMEEVENT_PARAMS); } /* If postCopy is false, then we may want to set it to true */ if (!pHook->postCopy) { pHook->postCopy = (mode == EventHookMode_Post); } /* Add plugin function to forward list */ pHook->pPostHook->AddFunction(pFunction); } /* Increase reference count */ pHook->refCount++; return EventHookErr_Okay; }