<commit_before>/*
*		Event Manager by qu<EMAIL>
*				Version: 1.1
*
*/

#include "q_events.h"

EventManager Events;

EventManager::EventManager()
{
	m_hook = false;
	//m_args = std::vector<EventArg>(16);
}

void EventManager::RegisterEvent(const int _msg_id, EventCallback _func)
{
	// Check for exist
	for (auto iter = m_regevents.cbegin(); iter != m_regevents.cend(); iter++)
		if (iter->msg_id == _msg_id && iter->func == _func)
			return;

	m_regevents.push_back(EventRegister(_msg_id, _func));
}

void EventManager::RegisterEvent(const char* msg_name, EventCallback func)
{
	RegisterEvent(ID(msg_name), func);
}

int EventManager::ID(const char* msg_name)
{
	return GET_USER_MSG_ID(PLID, msg_name, NULL);
}

// Get args
int EventManager::GetArgInt(int num)
{
	if (num < 0 || num >= m_args.size())
		return 0;

	return m_args[num].value.iValue;
}

float EventManager::GetArgFloat(int num)
{
	if (num < 0 || num >= m_args.size())
		return 0.0;

	return m_args[num].value.flValue;
}

const char* EventManager::GetArgString(int num)
{
	if (num < 0 || num >= m_args.size() || m_args[num].m_type != at_string)
		return nullptr;

	return m_args[num].str.c_str();
}

// Set Args
void EventManager::SetArg(int num, int set)
{
	if (num < 0 || num >= m_args.size())
		return;

	m_args[num].value.iValue = set;
}

void EventManager::SetArg(int num, float set)
{
	if (num < 0 || num >= m_args.size())
		return;

	m_args[num].value.flValue = set;
}

void EventManager::SetArg(int num, const char* set)
{
	if (num < 0 || num >= m_args.size() || m_args[num].m_type != at_string)
		return;

	m_args[num].str = set;
}

// Handlers
void EventManager::EM_MessageBegin(int msg_dest, int msg_type, const float *pOrigin, edict_t *ed)
{
	m_args.clear();
	m_hook = false;
	
	for (auto iter = m_regevents.cbegin(); iter != m_regevents.cend(); iter++)
	{
		if (msg_type == iter->msg_id)
		{
			m_hook = true;

			m_msg_dest = msg_dest;
			m_msg_type = msg_type;
			m_origin = pOrigin;
			m_ed = ed;

			RETURN_META(MRES_SUPERCEDE);
		}
	}

	RETURN_META(MRES_IGNORED);
}

void EventManager::EM_MessageEnd()
{
	if (m_hook)
	{
		m_hook = false;

		int cb_return = ER_IGNORED, _cbret;

		// Execute all registered events
		for (auto iter = m_regevents.cbegin(); iter != m_regevents.cend(); iter++)
		{
			if (m_msg_type == iter->msg_id)
			{<commit_msg>Fixed SUPERCEDE return in EventManager<commit_after>/*
*		Event Manager by quckly
*				Version: 1.0
*
*/

#include "q_events.h"

EventManager Events;

EventManager::EventManager()
{
	m_hook = false;
	//m_args = std::vector<EventArg>(16);
}

void EventManager::RegisterEvent(const int _msg_id, EventCallback _func)
{
	// Check for exist
	for (auto iter = m_regevents.cbegin(); iter != m_regevents.cend(); iter++)
		if (iter->msg_id == _msg_id && iter->func == _func)
			return;

	m_regevents.push_back(EventRegister(_msg_id, _func));
}

void EventManager::RegisterEvent(const char* msg_name, EventCallback func)
{
	RegisterEvent(ID(msg_name), func);
}

int EventManager::ID(const char* msg_name)
{
	return GET_USER_MSG_ID(PLID, msg_name, NULL);
}

// Get args
int EventManager::GetArgInt(int num)
{
	if (num < 0 || num >= m_args.size())
		return 0;

	return m_args[num].value.iValue;
}

float EventManager::GetArgFloat(int num)
{
	if (num < 0 || num >= m_args.size())
		return 0.0;

	return m_args[num].value.flValue;
}

const char* EventManager::GetArgString(int num)
{
	if (num < 0 || num >= m_args.size() || m_args[num].m_type != at_string)
		return nullptr;

	return m_args[num].str.c_str();
}

// Set Args
void EventManager::SetArg(int num, int set)
{
	if (num < 0 || num >= m_args.size())
		return;

	m_args[num].value.iValue = set;
}

void EventManager::SetArg(int num, float set)
{
	if (num < 0 || num >= m_args.size())
		return;

	m_args[num].value.flValue = set;
}

void EventManager::SetArg(int num, const char* set)
{
	if (num < 0 || num >= m_args.size() || m_args[num].m_type != at_string)
		return;

	m_args[num].str = set;
}

// Handlers
void EventManager::EM_MessageBegin(int msg_dest, int msg_type, const float *pOrigin, edict_t *ed)
{
	m_hook = false;
	
	for (auto iter = m_regevents.cbegin(); iter != m_regevents.cend(); iter++)
	{
		if (msg_type == iter->msg_id)
		{
			m_hook = true;
			m_args.clear();

			m_msg_dest = msg_dest;
			m_msg_type = msg_type;
			m_origin = pOrigin;
			m_ed = ed;

			RETURN_META(MRES_SUPERCEDE);
		}
	}

	RETURN_META(MRES_IGNORED);
}

void EventManager::EM_MessageEnd()
{
	if (m_hook)
	{
		m_hook = false;

		int cb_return = ER_IGNORED, _cbret;

		// Execute all registered events
		for (auto iter = m_regevents.cbegin(); iter != m_regevents.cend(); iter++)
		{
			if (m_msg_type == iter->msg_id)
			{
{'fraction_non_alphanumeric': 0.155622060709705, 'fraction_numerical': 0.0055579307396323215, 'mean_word_length': 4.1701657458563535, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1399179', 'n_tokens_mistral': 2002, 'n_tokens_neox': 1871, 'n_words': 406}