static cell_t GetProfilerTime(IPluginContext *pContext, const cell_t *params) { Handle_t hndl = params[1]; HandleSecurity sec = HandleSecurity(pContext->GetIdentity(), g_pCoreIdent); HandleError err; Profiler *prof; if ((err = g_HandleSys.ReadHandle(hndl, g_ProfilerType, &sec, (void **)&prof)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error %d)", hndl, err); } if (!prof->stopped) { return pContext->ThrowNativeError("Profiler was never stopped"); } float fTime; #if defined PLATFORM_WINDOWS LONGLONG diff = prof->end.QuadPart - prof->start.QuadPart; double seconds = diff * prof->freq; fTime = (float)seconds; #endif return sp_ftoc(fTime); }
static cell_t SetTrieValue(IPluginContext *pContext, const cell_t *params) { Handle_t hndl; CellTrie *pTrie; HandleError err; HandleSecurity sec = HandleSecurity(pContext->GetIdentity(), g_pCoreIdent); hndl = params[1]; if ((err = g_HandleSys.ReadHandle(hndl, htCellTrie, &sec, (void **)&pTrie)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error %d)", hndl, err); } char *key; pContext->LocalToString(params[2], &key); SmartTrieNode *pNode; if ((pNode = pTrie->trie.retrieve(key)) == NULL) { SmartTrieNode node; UpdateNodeCells(pTrie, &node, ¶ms[3], 1); return pTrie->trie.insert(key, node) ? 1 : 0; } if (!params[4]) { return 0; } UpdateNodeCells(pTrie, pNode, ¶ms[3], 1); return 1; }
static cell_t CreateTrieSnapshot(IPluginContext *pContext, const cell_t *params) { HandleError err; HandleSecurity sec = HandleSecurity(pContext->GetIdentity(), g_pCoreIdent); Handle_t hndl = params[1]; CellTrie *pTrie; if ((err = handlesys->ReadHandle(hndl, htCellTrie, &sec, (void **)&pTrie)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error %d)", hndl, err); } TrieSnapshot *snapshot = new TrieSnapshot; snapshot->length = pTrie->map.elements(); snapshot->keys = ke::MakeUnique<int[]>(snapshot->length); size_t i = 0; for (StringHashMap<Entry>::iterator iter = pTrie->map.iter(); !iter.empty(); iter.next(), i++) snapshot->keys[i] = snapshot->strings.AddString(iter->key.chars(), iter->key.length()); assert(i == snapshot->length); if ((hndl = handlesys->CreateHandle(htSnapshot, snapshot, pContext->GetIdentity(), g_pCoreIdent, NULL)) == BAD_HANDLE) { delete snapshot; return BAD_HANDLE; } return hndl; }
static cell_t GetTrieValue(IPluginContext *pContext, const cell_t *params) { Handle_t hndl; CellTrie *pTrie; HandleError err; HandleSecurity sec = HandleSecurity(pContext->GetIdentity(), g_pCoreIdent); hndl = params[1]; if ((err = g_HandleSys.ReadHandle(hndl, htCellTrie, &sec, (void **)&pTrie)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error %d)", hndl, err); } char *key; cell_t *pValue; pContext->LocalToString(params[2], &key); pContext->LocalToPhysAddr(params[3], &pValue); SmartTrieNode *pNode; if ((pNode = pTrie->trie.retrieve(key)) == NULL) { return 0; } if (pNode->type == TrieNode_Cell) { *pValue = pNode->data; return 1; } return 0; }
static cell_t SetTrieString(IPluginContext *pContext, const cell_t *params) { CellTrie *pTrie; HandleError err; HandleSecurity sec = HandleSecurity(pContext->GetIdentity(), g_pCoreIdent); Handle_t hndl = params[1]; if ((err = handlesys->ReadHandle(hndl, htCellTrie, &sec, (void **)&pTrie)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error %d)", hndl, err); } char *key, *val; pContext->LocalToString(params[2], &key); pContext->LocalToString(params[3], &val); StringHashMap<Entry>::Insert i = pTrie->map.findForAdd(key); if (!i.found()) { if (!pTrie->map.add(i, key)) return 0; i->value.setString(val); return 1; } if (!params[4]) return 0; i->value.setString(val); return 1; }
static cell_t StopProfiling(IPluginContext *pContext, const cell_t *params) { Handle_t hndl = params[1]; HandleSecurity sec = HandleSecurity(pContext->GetIdentity(), g_pCoreIdent); HandleError err; Profiler *prof; if ((err = g_HandleSys.ReadHandle(hndl, g_ProfilerType, &sec, (void **)&prof)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error %d)", hndl, err); } if (!prof->started) { return pContext->ThrowNativeError("Profiler was never started"); } #if defined PLATFORM_WINDOWS QueryPerformanceCounter(&prof->end); #endif prof->started = false; prof->stopped = true; return 1; }
static cell_t RemoveFromTrie(IPluginContext *pContext, const cell_t *params) { Handle_t hndl; CellTrie *pTrie; HandleError err; HandleSecurity sec = HandleSecurity(pContext->GetIdentity(), g_pCoreIdent); hndl = params[1]; if ((err = g_HandleSys.ReadHandle(hndl, htCellTrie, &sec, (void **)&pTrie)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error %d)", hndl, err); } char *key; pContext->LocalToString(params[2], &key); SmartTrieNode *pNode; if ((pNode = pTrie->trie.retrieve(key)) == NULL) { return 0; } free(pNode->ptr); pNode->ptr = NULL; return pTrie->trie.remove(key) ? 1 : 0; }
static cell_t GetTrieString(IPluginContext *pContext, const cell_t *params) { Handle_t hndl; CellTrie *pTrie; HandleError err; HandleSecurity sec = HandleSecurity(pContext->GetIdentity(), g_pCoreIdent); hndl = params[1]; if ((err = handlesys->ReadHandle(hndl, htCellTrie, &sec, (void **)&pTrie)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error %d)", hndl, err); } if (params[4] < 0) { return pContext->ThrowNativeError("Invalid buffer size: %d", params[4]); } char *key; cell_t *pSize; pContext->LocalToString(params[2], &key); pContext->LocalToPhysAddr(params[5], &pSize); StringHashMap<Entry>::Result r = pTrie->map.find(key); if (!r.found() || !r->value.isString()) return 0; size_t written; pContext->StringToLocalUTF8(params[3], params[4], r->value.chars(), &written); *pSize = (cell_t)written; return 1; }
static cell_t GetTrieArray(IPluginContext *pContext, const cell_t *params) { Handle_t hndl; CellTrie *pTrie; HandleError err; HandleSecurity sec = HandleSecurity(pContext->GetIdentity(), g_pCoreIdent); hndl = params[1]; if ((err = g_HandleSys.ReadHandle(hndl, htCellTrie, &sec, (void **)&pTrie)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error %d)", hndl, err); } if (params[4] < 0) { return pContext->ThrowNativeError("Invalid array size: %d", params[4]); } char *key; cell_t *pValue, *pSize; pContext->LocalToString(params[2], &key); pContext->LocalToPhysAddr(params[3], &pValue); pContext->LocalToPhysAddr(params[5], &pSize); SmartTrieNode *pNode; if ((pNode = pTrie->trie.retrieve(key)) == NULL || pNode->type != TrieNode_CellArray) { return 0; } if (pNode->ptr == NULL) { *pSize = 0; return 1; } if (pNode->data > params[4]) { *pSize = params[4]; } else if (params[4] != 0) { *pSize = pNode->data; } else { return 1; } memcpy(pValue, pNode->ptr, sizeof(cell_t) * pSize[0]); return 1; }
static cell_t GetTrieArray(IPluginContext *pContext, const cell_t *params) { Handle_t hndl; CellTrie *pTrie; HandleError err; HandleSecurity sec = HandleSecurity(pContext->GetIdentity(), g_pCoreIdent); hndl = params[1]; if ((err = handlesys->ReadHandle(hndl, htCellTrie, &sec, (void **)&pTrie)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error %d)", hndl, err); } if (params[4] < 0) { return pContext->ThrowNativeError("Invalid array size: %d", params[4]); } char *key; cell_t *pValue, *pSize; pContext->LocalToString(params[2], &key); pContext->LocalToPhysAddr(params[3], &pValue); pContext->LocalToPhysAddr(params[5], &pSize); StringHashMap<Entry>::Result r = pTrie->map.find(key); if (!r.found() || !r->value.isArray()) return 0; if (!r->value.array()) { *pSize = 0; return 1; } if (!params[4]) return 1; size_t length = r->value.arrayLength(); cell_t *base = r->value.array(); if (length > size_t(params[4])) *pSize = params[4]; else *pSize = length; memcpy(pValue, base, sizeof(cell_t) * pSize[0]); return 1; }
static cell_t TrieSnapshotLength(IPluginContext *pContext, const cell_t *params) { HandleError err; HandleSecurity sec = HandleSecurity(pContext->GetIdentity(), g_pCoreIdent); Handle_t hndl = params[1]; TrieSnapshot *snapshot; if ((err = handlesys->ReadHandle(hndl, htSnapshot, &sec, (void **)&snapshot)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error %d)", hndl, err); } return snapshot->length; }
static cell_t GetTrieString(IPluginContext *pContext, const cell_t *params) { Handle_t hndl; CellTrie *pTrie; HandleError err; HandleSecurity sec = HandleSecurity(pContext->GetIdentity(), g_pCoreIdent); hndl = params[1]; if ((err = g_HandleSys.ReadHandle(hndl, htCellTrie, &sec, (void **)&pTrie)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error %d)", hndl, err); } if (params[4] < 0) { return pContext->ThrowNativeError("Invalid buffer size: %d", params[4]); } char *key; cell_t *pSize; pContext->LocalToString(params[2], &key); pContext->LocalToPhysAddr(params[5], &pSize); SmartTrieNode *pNode; if ((pNode = pTrie->trie.retrieve(key)) == NULL || pNode->type != TrieNode_String) { return 0; } if (pNode->ptr == NULL) { *pSize = 0; pContext->StringToLocal(params[3], params[4], ""); return 1; } size_t written; pContext->StringToLocalUTF8(params[3], params[4], (char *)pNode->ptr, &written); *pSize = (cell_t)written; return 1; }
static cell_t GetTrieSize(IPluginContext *pContext, const cell_t *params) { Handle_t hndl; CellTrie *pTrie; HandleError err; HandleSecurity sec = HandleSecurity(pContext->GetIdentity(), g_pCoreIdent); hndl = params[1]; if ((err = handlesys->ReadHandle(hndl, htCellTrie, &sec, (void **)&pTrie)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error %d)", hndl, err); } return pTrie->map.elements(); }
static cell_t ClearTrie(IPluginContext *pContext, const cell_t *params) { Handle_t hndl; CellTrie *pTrie; HandleError err; HandleSecurity sec = HandleSecurity(pContext->GetIdentity(), g_pCoreIdent); hndl = params[1]; if ((err = g_HandleSys.ReadHandle(hndl, htCellTrie, &sec, (void **)&pTrie)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error %d)", hndl, err); } pTrie->trie.run_destructor(TrieHelpers::DestroySmartTrieNode); pTrie->trie.clear(); return 1; }
static cell_t TrieSnapshotKeyBufferSize(IPluginContext *pContext, const cell_t *params) { HandleError err; HandleSecurity sec = HandleSecurity(pContext->GetIdentity(), g_pCoreIdent); Handle_t hndl = params[1]; TrieSnapshot *snapshot; if ((err = handlesys->ReadHandle(hndl, htSnapshot, &sec, (void **)&snapshot)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error %d)", hndl, err); } unsigned index = params[2]; if (index >= snapshot->length) return pContext->ThrowNativeError("Invalid index %d", index); return strlen(snapshot->strings.GetString(snapshot->keys[index])) + 1; }
static cell_t GetTrieValue(IPluginContext *pContext, const cell_t *params) { Handle_t hndl; CellTrie *pTrie; HandleError err; HandleSecurity sec = HandleSecurity(pContext->GetIdentity(), g_pCoreIdent); hndl = params[1]; if ((err = handlesys->ReadHandle(hndl, htCellTrie, &sec, (void **)&pTrie)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error %d)", hndl, err); } char *key; cell_t *pValue; pContext->LocalToString(params[2], &key); pContext->LocalToPhysAddr(params[3], &pValue); StringHashMap<Entry>::Result r = pTrie->map.find(key); if (!r.found()) return 0; if (r->value.isCell()) { *pValue = r->value.cell(); return 1; } // Maintain compatibility with an old bug. If an array was set with one // cell, it was stored internally as a single cell. We now store as an // actual array, but we make GetTrieValue() still work for this case. if (r->value.isArray() && r->value.arrayLength() == 1) { *pValue = r->value.array()[0]; return 1; } return 0; }
Handle_t CreateHudSyncObj(IdentityToken_t *pIdent) { Handle_t hndl; HandleError err; hud_syncobj_t *obj; HandleSecurity sec; obj = new hud_syncobj_t; memset(obj->player_channels, 0, sizeof(obj->player_channels)); sec = HandleSecurity(pIdent, g_pCoreIdent); if ((hndl = handlesys->CreateHandleEx(m_hHudSyncObj, obj, &sec, NULL, &err)) == BAD_HANDLE) { delete obj; } return hndl; }
static cell_t GetTrieSnapshotKey(IPluginContext *pContext, const cell_t *params) { HandleError err; HandleSecurity sec = HandleSecurity(pContext->GetIdentity(), g_pCoreIdent); Handle_t hndl = params[1]; TrieSnapshot *snapshot; if ((err = handlesys->ReadHandle(hndl, htSnapshot, &sec, (void **)&snapshot)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error %d)", hndl, err); } unsigned index = params[2]; if (index >= snapshot->length) return pContext->ThrowNativeError("Invalid index %d", index); size_t written; const char *str = snapshot->strings.GetString(snapshot->keys[index]); pContext->StringToLocalUTF8(params[3], params[4], str, &written); return written; }
static cell_t RemoveFromTrie(IPluginContext *pContext, const cell_t *params) { CellTrie *pTrie; HandleError err; HandleSecurity sec = HandleSecurity(pContext->GetIdentity(), g_pCoreIdent); Handle_t hndl = params[1]; if ((err = handlesys->ReadHandle(hndl, htCellTrie, &sec, (void **)&pTrie)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error %d)", hndl, err); } char *key; pContext->LocalToString(params[2], &key); StringHashMap<Entry>::Result r = pTrie->map.find(key); if (!r.found()) return 0; pTrie->map.remove(r); return 1; }