Example #1
0
bool CreateBaseCall(const char *name,
						  ValveCallType vcalltype,
						  const ValvePassInfo *retinfo,
						  const ValvePassInfo params[],
						  unsigned int numParams,
						  ValveCall **vaddr)
{
	int offset;
	ValveCall *call;
	if (g_pGameConf->GetOffset(name, &offset))
	{
		call = CreateValveVCall(offset, vcalltype, retinfo, params, numParams);
		if (call)
		{
			g_RegCalls.push_back(call);
		}
		*vaddr = call;
		return true;
	} else {
		void *addr = NULL;
		if (g_pGameConf->GetMemSig(name, &addr) && addr != NULL)
		{
			call = CreateValveCall(addr, vcalltype, retinfo, params, numParams);
			if (call)
			{
				g_RegCalls.push_back(call);
			}
			*vaddr = call;
			return true;
		}
	}
	return false;
}
Example #2
0
void EntityOutputManager::CleanUpHook(omg_hooks *hook)
{
	FreeHooks.push(hook);

	OnHookRemoved();

	IPlugin *pPlugin = plsys->FindPluginByContext(hook->pf->GetParentContext()->GetContext());
	SourceHook::List<omg_hooks *> *pList = NULL;

	if (!pPlugin->GetProperty("OutputHookList", (void **)&pList, false) || !pList)
	{
		return;
	}

	SourceHook::List<omg_hooks *>::iterator p_iter = pList->begin();

	omg_hooks *pluginHook;

	while (p_iter != pList->end())
	{
		pluginHook = (omg_hooks *)*p_iter;
		if (pluginHook == hook)
		{
			p_iter = pList->erase(p_iter);
		}
		else
		{
			p_iter++;
		}
	}
}
Example #3
0
	static bool DoTests()
	{
		int passed=0, failed=0;
		for (SourceHook::List<Test*>::iterator iter = ms_Tests.begin(); iter != ms_Tests.end(); ++iter)
		{
			if ((**iter)())
				++passed;
			else
				++failed;
		}
		cout << endl << "----" << endl << "Passed: " << passed << endl << "Failed: " << failed << endl;
		cout << "Total: " << passed + failed << endl;
		return failed == 0;
	}
Example #4
0
void CookieManager::OnPluginDestroyed(IPlugin *plugin)
{
    SourceHook::List<char *> *pList;

    if (plugin->GetProperty("SettingsMenuItems", (void **)&pList, true))
    {
        SourceHook::List<char *>::iterator p_iter = pList->begin();
        char *name;

        while (p_iter != pList->end())
        {
            name = (char *)*p_iter;

            p_iter = pList->erase(p_iter); //remove from this plugins list

            ItemDrawInfo draw;

            for (unsigned int i=0; i<clientMenu->GetItemCount(); i++)
            {
                const char *info = clientMenu->GetItemInfo(i, &draw);

                if (info == NULL)
                {
                    continue;
                }

                if (strcmp(draw.display, name) == 0)
                {
                    ItemDrawInfo draw;
                    const char *info = clientMenu->GetItemInfo(i, &draw);
                    AutoMenuData *data = (AutoMenuData *)strtol(info, NULL, 16);

                    if (data->handler->forward != NULL)
                    {
                        forwards->ReleaseForward(data->handler->forward);
                    }
                    delete data->handler;
                    delete data;

                    clientMenu->RemoveItem(i);
                    break;
                }
            }

            delete name;
        }
    }
}
Example #5
0
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;
}
Example #6
0
void EntityOutputManager::OnPluginDestroyed(IPlugin *plugin)
{
	SourceHook::List<omg_hooks *> *pList = NULL;

	if (plugin->GetProperty("OutputHookList", (void **)&pList, true))
	{
		SourceHook::List<omg_hooks *>::iterator p_iter = pList->begin();
		omg_hooks *hook;

		while (p_iter != pList->end())
		{
			hook = (omg_hooks *)*p_iter;
		
			p_iter = pList->erase(p_iter); //remove from this plugins list
			hook->m_parent->hooks.remove(hook); // remove from the y's list

			FreeHooks.push(hook); //save the omg_hook

			OnHookRemoved();
		}		
	}
}
Example #7
0
	Test(TestProto func, const char *name) : m_Func(func), m_Name(name)
	{
		ms_Tests.push_back(this);
	}
// 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;
}
Example #10
0
cell_t AddSettingsPrefabMenuItem(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");
	}

	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;
	UTIL_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());
	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;
}