| 351 | } |
| 352 | |
| 353 | Handle_t ConVarManager::CreateConVar(IPluginContext *pContext, const char *name, const char *defaultVal, const char *description, int flags, bool hasMin, float min, bool hasMax, float max) |
| 354 | { |
| 355 | ConVar *pConVar = NULL; |
| 356 | ConVarInfo *pInfo = NULL; |
| 357 | Handle_t hndl = 0; |
| 358 | |
| 359 | IPlugin *plugin = scripts->FindPluginByContext(pContext); |
| 360 | |
| 361 | /* Find out if the convar exists already */ |
| 362 | pConVar = icvar->FindVar(name); |
| 363 | |
| 364 | /* If the convar already exists... */ |
| 365 | if (pConVar) |
| 366 | { |
| 367 | /* Add convar to plugin's list */ |
| 368 | AddConVarToPluginList(plugin, pConVar); |
| 369 | |
| 370 | /* First find out if we already have a handle to it */ |
| 371 | if (convar_cache_lookup(name, &pInfo)) |
| 372 | { |
| 373 | /* If the convar doesn't have an owning plugin, but SM created it, adopt it */ |
| 374 | if (pInfo->sourceMod && pInfo->pPlugin == nullptr) { |
| 375 | pInfo->pPlugin = plugin; |
| 376 | } |
| 377 | |
| 378 | return pInfo->handle; |
| 379 | } |
| 380 | else |
| 381 | { |
| 382 | /* Create and initialize ConVarInfo structure */ |
| 383 | pInfo = new ConVarInfo(); |
| 384 | pInfo->sourceMod = false; |
| 385 | pInfo->pChangeForward = NULL; |
| 386 | pInfo->pVar = pConVar; |
| 387 | |
| 388 | /* If we don't, then create a new handle from the convar */ |
| 389 | hndl = handlesys->CreateHandle(m_ConVarType, pInfo, NULL, g_pCoreIdent, NULL); |
| 390 | if (hndl == BAD_HANDLE) |
| 391 | { |
| 392 | delete pInfo; |
| 393 | return BAD_HANDLE; |
| 394 | } |
| 395 | |
| 396 | pInfo->handle = hndl; |
| 397 | |
| 398 | /* Insert struct into caches */ |
| 399 | m_ConVars.push_back(pInfo); |
| 400 | convar_cache.insert(name, pInfo); |
| 401 | TrackConCommandBase(pConVar, this); |
| 402 | |
| 403 | return hndl; |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | /* Prevent creating a convar that has the same name as a console command */ |
| 408 | if (FindCommand(name)) |
| 409 | { |
| 410 | return BAD_HANDLE; |
no test coverage detected