core/smn_usermsgs.cpp
author David Anderson <dvander@alliedmods.net>
Thu Mar 15 20:44:23 2007 +0000 (2007-03-15)
changeset 619 6934bf39171e
parent 600 f6d811158ad3
child 626 ad539443ad7f
permissions -rw-r--r--
random touchups that might not be so great
faluco@505
     1
/**
dvander@600
     2
 * vim: set ts=4 :
dvander@600
     3
 * ===============================================================
dvander@600
     4
 * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
dvander@600
     5
 * ===============================================================
dvander@600
     6
 *
dvander@600
     7
 * This file is not open source and may not be copied without explicit
dvander@600
     8
 * written permission of AlliedModders LLC.  This file may not be redistributed 
dvander@600
     9
 * in whole or significant part.
dvander@600
    10
 * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
dvander@600
    11
 *
dvander@600
    12
 * Version: $Id$
dvander@600
    13
 */
faluco@505
    14
faluco@505
    15
#include "HandleSys.h"
faluco@552
    16
#include "PluginSys.h"
dvander@592
    17
#include "UserMessages.h"
dvander@590
    18
#include "smn_usermsgs.h"
faluco@505
    19
faluco@505
    20
HandleType_t g_WrBitBufType;
faluco@598
    21
HandleType_t g_RdBitBufType;
faluco@505
    22
Handle_t g_CurMsgHandle;
faluco@598
    23
Handle_t g_ReadBufHandle;
faluco@598
    24
bf_read g_ReadBitBuf;
faluco@598
    25
faluco@552
    26
int g_MsgPlayers[256];
faluco@505
    27
bool g_IsMsgInExec = false;
faluco@505
    28
faluco@593
    29
typedef List<MsgListenerWrapper *> MsgWrapperList;
faluco@593
    30
typedef List<MsgListenerWrapper *>::iterator MsgWrapperIter;
faluco@593
    31
faluco@505
    32
class UsrMessageNatives :
faluco@505
    33
	public SMGlobalClass,
faluco@552
    34
	public IHandleTypeDispatch,
faluco@552
    35
	public IPluginsListener
faluco@505
    36
{
faluco@552
    37
public: //SMGlobalClass, IHandleTypeDispatch, IPluginListener
faluco@552
    38
	void OnSourceModAllInitialized();
faluco@552
    39
	void OnSourceModShutdown();
faluco@552
    40
	void OnHandleDestroy(HandleType_t type, void *object);
faluco@552
    41
	void OnPluginUnloaded(IPlugin *plugin);
faluco@505
    42
public:
faluco@593
    43
	MsgListenerWrapper *CreateListener(IPluginContext *pCtx);
faluco@593
    44
	MsgWrapperIter FindListener(int msgid, IPluginContext *pCtx, IPluginFunction *pHook, bool intercept);
faluco@593
    45
	bool DeleteListener(IPluginContext *pCtx, MsgWrapperIter iter);
faluco@552
    46
private:
faluco@552
    47
	CStack<MsgListenerWrapper *> m_FreeListeners;
faluco@552
    48
};
faluco@552
    49
faluco@552
    50
void UsrMessageNatives::OnSourceModAllInitialized()
faluco@552
    51
{
faluco@598
    52
	HandleAccess sec;
faluco@598
    53
	sec.access[HandleAccess_Delete] |= HANDLE_RESTRICT_IDENTITY;
faluco@598
    54
faluco@552
    55
	g_WrBitBufType = g_HandleSys.CreateType("BitBufWriter", this, 0, NULL, NULL, g_pCoreIdent, NULL);
faluco@598
    56
	g_RdBitBufType = g_HandleSys.CreateType("BitBufReader", this, 0, NULL, &sec, g_pCoreIdent, NULL);
faluco@598
    57
faluco@598
    58
	g_ReadBufHandle = g_HandleSys.CreateHandle(g_RdBitBufType, &g_ReadBitBuf, NULL, g_pCoreIdent, NULL);
faluco@598
    59
faluco@552
    60
	g_PluginSys.AddPluginsListener(this);
faluco@552
    61
}
faluco@552
    62
faluco@552
    63
void UsrMessageNatives::OnSourceModShutdown()
faluco@552
    64
{
faluco@598
    65
	HandleSecurity sec;
faluco@598
    66
	sec.pIdentity = g_pCoreIdent;
faluco@598
    67
faluco@598
    68
	g_HandleSys.FreeHandle(g_ReadBufHandle, &sec);
faluco@598
    69
faluco@552
    70
	g_HandleSys.RemoveType(g_WrBitBufType, g_pCoreIdent);
faluco@598
    71
	g_HandleSys.RemoveType(g_RdBitBufType, g_pCoreIdent);
faluco@598
    72
faluco@552
    73
	g_PluginSys.RemovePluginsListener(this);
faluco@552
    74
	g_WrBitBufType = 0;
faluco@598
    75
	g_RdBitBufType = 0;
faluco@552
    76
}
faluco@553
    77
faluco@552
    78
void UsrMessageNatives::OnHandleDestroy(HandleType_t type, void *object)
faluco@552
    79
{
faluco@552
    80
}
faluco@552
    81
faluco@552
    82
void UsrMessageNatives::OnPluginUnloaded(IPlugin *plugin)
faluco@552
    83
{
faluco@593
    84
	MsgWrapperList *pList;
faluco@552
    85
faluco@593
    86
	if (plugin->GetProperty("MsgListeners", reinterpret_cast<void **>(&pList), true))
faluco@505
    87
	{
faluco@593
    88
		MsgWrapperIter iter;
faluco@593
    89
		MsgListenerWrapper *pListener;
faluco@552
    90
faluco@593
    91
		for (iter=pList->begin(); iter!=pList->end(); iter++)
faluco@552
    92
		{
faluco@593
    93
			pListener = (*iter);
faluco@593
    94
			if (g_UserMsgs.UnhookUserMessage(pListener->GetMessageId(), pListener, pListener->IsInterceptHook()))
faluco@552
    95
			{
faluco@593
    96
				m_FreeListeners.push(pListener);
faluco@552
    97
			}
faluco@552
    98
		}
faluco@552
    99
faluco@593
   100
		delete pList;
faluco@552
   101
	}
faluco@552
   102
}
faluco@552
   103
faluco@593
   104
MsgListenerWrapper *UsrMessageNatives::CreateListener(IPluginContext *pCtx)
faluco@552
   105
{
faluco@593
   106
	MsgWrapperList *pList;
faluco@593
   107
	MsgListenerWrapper *pListener;
faluco@593
   108
	IPlugin *pl = g_PluginSys.FindPluginByContext(pCtx->GetContext());
faluco@552
   109
faluco@552
   110
	if (m_FreeListeners.empty())
faluco@552
   111
	{
faluco@593
   112
		pListener = new MsgListenerWrapper;
faluco@552
   113
	} else {
faluco@593
   114
		pListener = m_FreeListeners.front();
faluco@552
   115
		m_FreeListeners.pop();
faluco@505
   116
	}
faluco@552
   117
faluco@593
   118
	if (!pl->GetProperty("MsgListeners", reinterpret_cast<void **>(&pList)))
faluco@505
   119
	{
faluco@593
   120
		pList = new List<MsgListenerWrapper *>;
faluco@593
   121
		pl->SetProperty("MsgListeners", pList);
faluco@552
   122
	}
faluco@552
   123
faluco@593
   124
	pList->push_back(pListener);
faluco@552
   125
faluco@593
   126
	return pListener;
faluco@552
   127
}
faluco@552
   128
faluco@593
   129
MsgWrapperIter UsrMessageNatives::FindListener(int msgid, IPluginContext *pCtx, IPluginFunction *pHook, bool intercept)
faluco@552
   130
{
faluco@593
   131
	MsgWrapperList *pList;
faluco@593
   132
	MsgWrapperIter iter;
faluco@593
   133
	MsgListenerWrapper *pListener;
faluco@552
   134
	IPlugin *pl = g_PluginSys.FindPluginByContext(pCtx->GetContext());
faluco@552
   135
faluco@593
   136
	if (!pl->GetProperty("MsgListeners", reinterpret_cast<void **>(&pList)))
faluco@552
   137
	{
faluco@552
   138
		return NULL;
faluco@505
   139
	}
faluco@552
   140
faluco@593
   141
	for (iter=pList->begin(); iter!=pList->end(); iter++)
faluco@505
   142
	{
faluco@593
   143
		pListener = (*iter);
faluco@593
   144
		if ((msgid == pListener->GetMessageId()) 
faluco@593
   145
			&& (intercept == pListener->IsInterceptHook()) 
faluco@593
   146
			&& (pHook == pListener->GetHookedFunction()))
faluco@552
   147
		{
faluco@593
   148
			return iter;
faluco@552
   149
		}
faluco@505
   150
	}
faluco@552
   151
faluco@593
   152
	return NULL;
faluco@552
   153
}
faluco@553
   154
faluco@593
   155
bool UsrMessageNatives::DeleteListener(IPluginContext *pCtx, MsgWrapperIter iter)
faluco@552
   156
{
faluco@593
   157
	MsgWrapperList *pList;
faluco@593
   158
	MsgListenerWrapper *pListener;
faluco@552
   159
	IPlugin *pl = g_PluginSys.FindPluginByContext(pCtx->GetContext());
faluco@552
   160
faluco@593
   161
	if (!pl->GetProperty("MsgListeners", reinterpret_cast<void **>(&pList)))
faluco@552
   162
	{
faluco@552
   163
		return false;
faluco@552
   164
	}
faluco@552
   165
faluco@593
   166
	pListener = (*iter);
faluco@593
   167
	pList->erase(iter);
faluco@593
   168
	m_FreeListeners.push(pListener);
faluco@552
   169
faluco@552
   170
	return true;
faluco@552
   171
}
faluco@552
   172
dvander@590
   173
/***************************************
dvander@590
   174
 *                                     *
dvander@590
   175
 * USER MESSAGE WRAPPER IMPLEMENTATION *
dvander@590
   176
 *                                     *
dvander@590
   177
 ***************************************/
dvander@590
   178
faluco@593
   179
void MsgListenerWrapper::Initialize(int msgid, IPluginFunction *hook, IPluginFunction *notify, bool intercept)
faluco@593
   180
{
faluco@593
   181
	if (intercept)
faluco@593
   182
	{
faluco@593
   183
		m_Intercept = hook;
faluco@593
   184
		m_Hook = NULL;
faluco@593
   185
	} else {
faluco@593
   186
		m_Hook = hook;
faluco@593
   187
		m_Intercept = NULL;
faluco@593
   188
	}
faluco@593
   189
faluco@593
   190
	if (notify)
faluco@593
   191
	{
faluco@593
   192
		m_Notify = notify;
faluco@593
   193
	} else {
faluco@593
   194
		m_Notify = NULL;
faluco@593
   195
	}
faluco@593
   196
faluco@593
   197
	m_MsgId = msgid;
faluco@593
   198
	m_IsInterceptHook = intercept;
faluco@593
   199
}
faluco@593
   200
faluco@593
   201
size_t MsgListenerWrapper::_FillInPlayers(int *pl_array, IRecipientFilter *pFilter)
dvander@590
   202
{
dvander@590
   203
	size_t size = static_cast<size_t>(pFilter->GetRecipientCount());
dvander@590
   204
dvander@590
   205
	for (size_t i=0; i<size; i++)
dvander@590
   206
	{
dvander@590
   207
		pl_array[i] = pFilter->GetRecipientIndex(i);
dvander@590
   208
	}
dvander@590
   209
dvander@590
   210
	return size;
dvander@590
   211
}
dvander@590
   212
dvander@590
   213
bool MsgListenerWrapper::IsInterceptHook() const
dvander@590
   214
{
dvander@590
   215
	return m_IsInterceptHook;
dvander@590
   216
}
dvander@590
   217
dvander@590
   218
int MsgListenerWrapper::GetMessageId() const
dvander@590
   219
{
dvander@590
   220
	return m_MsgId;
dvander@590
   221
}
dvander@590
   222
dvander@590
   223
IPluginFunction *MsgListenerWrapper::GetHookedFunction() const
dvander@590
   224
{
dvander@590
   225
	if (m_Hook)
dvander@590
   226
	{
dvander@590
   227
		return m_Hook;
dvander@590
   228
	} else {
dvander@590
   229
		return m_Intercept;
dvander@590
   230
	}
dvander@590
   231
}
dvander@590
   232
dvander@590
   233
IPluginFunction *MsgListenerWrapper::GetNotifyFunction() const
dvander@590
   234
{
dvander@590
   235
	return m_Notify;
dvander@590
   236
}
dvander@590
   237
dvander@590
   238
void MsgListenerWrapper::OnUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFilter)
dvander@590
   239
{
dvander@590
   240
	cell_t res;
faluco@593
   241
	size_t size = _FillInPlayers(g_MsgPlayers, pFilter);
dvander@590
   242
faluco@598
   243
	g_ReadBitBuf.StartReading(bf->GetBasePointer(), bf->GetNumBytesWritten());
faluco@598
   244
dvander@590
   245
	m_Hook->PushCell(msg_id);
faluco@598
   246
	m_Hook->PushCell(g_ReadBufHandle);
dvander@590
   247
	m_Hook->PushArray(g_MsgPlayers, size);
dvander@590
   248
	m_Hook->PushCell(size);
dvander@590
   249
	m_Hook->PushCell(pFilter->IsReliable());
dvander@590
   250
	m_Hook->PushCell(pFilter->IsInitMessage());
dvander@590
   251
	m_Hook->Execute(&res);
dvander@590
   252
}
dvander@590
   253
dvander@590
   254
ResultType MsgListenerWrapper::InterceptUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFilter)
dvander@590
   255
{
dvander@590
   256
	cell_t res = static_cast<cell_t>(Pl_Continue);
faluco@593
   257
	size_t size = _FillInPlayers(g_MsgPlayers, pFilter);
dvander@590
   258
faluco@598
   259
	g_ReadBitBuf.StartReading(bf->GetBasePointer(), bf->GetNumBytesWritten());
faluco@598
   260
dvander@590
   261
	m_Intercept->PushCell(msg_id);
faluco@598
   262
	m_Intercept->PushCell(g_ReadBufHandle);
dvander@590
   263
	m_Intercept->PushArray(g_MsgPlayers, size);
dvander@590
   264
	m_Intercept->PushCell(size);
dvander@590
   265
	m_Intercept->PushCell(pFilter->IsReliable());
dvander@590
   266
	m_Intercept->PushCell(pFilter->IsInitMessage());
dvander@590
   267
	m_Intercept->Execute(&res);
dvander@590
   268
dvander@590
   269
	return static_cast<ResultType>(res);
dvander@590
   270
}
dvander@590
   271
dvander@590
   272
void MsgListenerWrapper::OnUserMessageSent(int msg_id)
dvander@590
   273
{
dvander@590
   274
	if (!m_Notify)
dvander@590
   275
	{
dvander@590
   276
		return;
dvander@590
   277
	}
dvander@590
   278
faluco@593
   279
	cell_t res;
dvander@590
   280
	m_Notify->PushCell(msg_id);
dvander@590
   281
	m_Notify->Execute(&res);
dvander@590
   282
}
dvander@590
   283
dvander@590
   284
/***************************************
dvander@590
   285
 *                                     *
dvander@590
   286
 * USER MESSAGE NATIVE IMPLEMENTATIONS *
dvander@590
   287
 *                                     *
dvander@590
   288
 ***************************************/
faluco@552
   289
faluco@552
   290
static UsrMessageNatives s_UsrMessageNatives;
faluco@505
   291
faluco@505
   292
static cell_t smn_GetUserMessageId(IPluginContext *pCtx, const cell_t *params)
faluco@505
   293
{
faluco@505
   294
	char *msgname;
faluco@505
   295
	int err;
faluco@505
   296
	if ((err=pCtx->LocalToString(params[1], &msgname)) != SP_ERROR_NONE)
faluco@505
   297
	{
faluco@505
   298
		pCtx->ThrowNativeErrorEx(err, NULL);
faluco@505
   299
		return 0;
faluco@505
   300
	}
faluco@505
   301
faluco@552
   302
	return g_UserMsgs.GetMessageIndex(msgname);
faluco@505
   303
}
faluco@505
   304
faluco@553
   305
static cell_t smn_GetUserMessageName(IPluginContext *pCtx, const cell_t *params)
faluco@553
   306
{
faluco@553
   307
	char *msgname;
faluco@553
   308
faluco@553
   309
	pCtx->LocalToPhysAddr(params[2], (cell_t **)&msgname);
faluco@553
   310
faluco@553
   311
	if (!g_UserMsgs.GetMessageName(params[1], msgname, params[3]))
faluco@553
   312
	{
faluco@553
   313
		msgname = "";
faluco@553
   314
		return 0;
faluco@553
   315
	}
faluco@553
   316
faluco@553
   317
	return 1;
faluco@553
   318
}
faluco@553
   319
faluco@505
   320
static cell_t smn_StartMessage(IPluginContext *pCtx, const cell_t *params)
faluco@505
   321
{
faluco@505
   322
	char *msgname;
faluco@505
   323
	cell_t *cl_array;
faluco@505
   324
	int msgid, err;
faluco@505
   325
	bf_write *pBitBuf;
faluco@505
   326
faluco@505
   327
	if (g_IsMsgInExec)
faluco@505
   328
	{
faluco@505
   329
		return pCtx->ThrowNativeError("Unable to execute a new message, there is already one in progress");
faluco@505
   330
	}
faluco@505
   331
faluco@505
   332
	if ((err=pCtx->LocalToString(params[1], &msgname)) != SP_ERROR_NONE)
faluco@505
   333
	{
faluco@505
   334
		pCtx->ThrowNativeErrorEx(err, NULL);
faluco@505
   335
		return 0;
faluco@505
   336
	}
faluco@505
   337
faluco@552
   338
	if ((msgid=g_UserMsgs.GetMessageIndex(msgname)) == INVALID_MESSAGE_ID)
faluco@505
   339
	{
faluco@505
   340
		return pCtx->ThrowNativeError("Invalid message name: \"%s\"", msgname);
faluco@505
   341
	}
faluco@505
   342
faluco@505
   343
	pCtx->LocalToPhysAddr(params[2], &cl_array);
faluco@505
   344
faluco@552
   345
	pBitBuf = g_UserMsgs.StartMessage(msgid, cl_array, params[3], params[4]);
faluco@593
   346
	if (!pBitBuf)
faluco@593
   347
	{
faluco@593
   348
		return pCtx->ThrowNativeError("Unable to execute a new message while in hook");
faluco@593
   349
	}
faluco@505
   350
faluco@505
   351
	g_CurMsgHandle = g_HandleSys.CreateHandle(g_WrBitBufType, pBitBuf, pCtx->GetIdentity(), g_pCoreIdent, NULL);
faluco@505
   352
	g_IsMsgInExec = true;
faluco@505
   353
faluco@505
   354
	return g_CurMsgHandle;
faluco@505
   355
}
faluco@505
   356
faluco@505
   357
static cell_t smn_StartMessageEx(IPluginContext *pCtx, const cell_t *params)
faluco@505
   358
{
faluco@505
   359
	cell_t *cl_array;
faluco@505
   360
	bf_write *pBitBuf;
faluco@505
   361
	int msgid = params[1];
faluco@505
   362
faluco@505
   363
	if (g_IsMsgInExec)
faluco@505
   364
	{
faluco@505
   365
		return pCtx->ThrowNativeError("Unable to execute a new message, there is already one in progress");
faluco@505
   366
	}
faluco@505
   367
faluco@552
   368
	if (msgid < 0 || msgid >= 255)
faluco@505
   369
	{
faluco@505
   370
		return pCtx->ThrowNativeError("Invalid message id supplied (%d)", msgid);
faluco@505
   371
	}
faluco@505
   372
faluco@505
   373
	pCtx->LocalToPhysAddr(params[2], &cl_array);
faluco@505
   374
faluco@552
   375
	pBitBuf = g_UserMsgs.StartMessage(msgid, cl_array, params[3], params[4]);
faluco@593
   376
	if (!pBitBuf)
faluco@593
   377
	{
faluco@593
   378
		return pCtx->ThrowNativeError("Unable to execute a new message while in hook");
faluco@593
   379
	}
faluco@505
   380
faluco@505
   381
	g_CurMsgHandle = g_HandleSys.CreateHandle(g_WrBitBufType, pBitBuf, pCtx->GetIdentity(), g_pCoreIdent, NULL);
faluco@505
   382
	g_IsMsgInExec = true;
faluco@505
   383
faluco@505
   384
	return g_CurMsgHandle;
faluco@505
   385
}
faluco@505
   386
faluco@505
   387
static cell_t smn_EndMessage(IPluginContext *pCtx, const cell_t *params)
faluco@505
   388
{
faluco@505
   389
	HandleSecurity sec;
faluco@505
   390
faluco@505
   391
	if (!g_IsMsgInExec)
faluco@505
   392
	{
faluco@505
   393
		return pCtx->ThrowNativeError("Unable to end message, no message is in progress");
faluco@505
   394
	}
faluco@505
   395
faluco@552
   396
	g_UserMsgs.EndMessage();
faluco@505
   397
faluco@505
   398
	sec.pOwner = pCtx->GetIdentity();
faluco@505
   399
	sec.pIdentity = g_pCoreIdent;
faluco@505
   400
	g_HandleSys.FreeHandle(g_CurMsgHandle, &sec);
faluco@505
   401
faluco@505
   402
	g_IsMsgInExec = false;
faluco@552
   403
faluco@552
   404
	return 1;
faluco@552
   405
}
faluco@552
   406
faluco@552
   407
static cell_t smn_HookUserMessage(IPluginContext *pCtx, const cell_t *params)
faluco@552
   408
{
faluco@552
   409
	IPluginFunction *pHook, *pNotify;
faluco@593
   410
	MsgListenerWrapper *pListener;
faluco@552
   411
	bool intercept;
faluco@552
   412
	int msgid = params[1];
faluco@552
   413
faluco@552
   414
	if (msgid < 0 || msgid >= 255)
faluco@552
   415
	{
faluco@552
   416
		return pCtx->ThrowNativeError("Invalid message id supplied (%d)", msgid);
faluco@552
   417
	}
faluco@552
   418
faluco@552
   419
	pHook = pCtx->GetFunctionById(params[2]);
faluco@552
   420
	if (!pHook)
faluco@552
   421
	{
faluco@552
   422
		return pCtx->ThrowNativeError("Invalid function id (%X)", params[2]);
faluco@552
   423
	}
faluco@552
   424
	pNotify = pCtx->GetFunctionById(params[4]);
faluco@593
   425
	intercept = (params[3]) ? true : false;
faluco@552
   426
faluco@593
   427
	pListener = s_UsrMessageNatives.CreateListener(pCtx);
faluco@593
   428
	pListener->Initialize(msgid, pHook, pNotify, intercept);
faluco@553
   429
faluco@593
   430
	g_UserMsgs.HookUserMessage(msgid, pListener, intercept);
faluco@505
   431
faluco@505
   432
	return 1;
faluco@505
   433
}
faluco@505
   434
faluco@552
   435
static cell_t smn_UnHookUserMessage(IPluginContext *pCtx, const cell_t *params)
faluco@552
   436
{
faluco@552
   437
	IPluginFunction *pFunc;
faluco@593
   438
	MsgListenerWrapper *pListener;
faluco@593
   439
	MsgWrapperIter iter;
faluco@552
   440
	bool intercept;
faluco@552
   441
	int msgid = params[1];
faluco@552
   442
faluco@552
   443
	if (msgid < 0 || msgid >= 255)
faluco@552
   444
	{
faluco@552
   445
		return pCtx->ThrowNativeError("Invalid message id supplied (%d)", msgid);
faluco@552
   446
	}
faluco@552
   447
faluco@552
   448
	pFunc = pCtx->GetFunctionById(params[2]);
faluco@552
   449
	if (!pFunc)
faluco@552
   450
	{
faluco@552
   451
		return pCtx->ThrowNativeError("Invalid function id (%X)", params[2]);
faluco@552
   452
	}
faluco@593
   453
	intercept = (params[3]) ? true : false;
faluco@552
   454
faluco@593
   455
	iter = s_UsrMessageNatives.FindListener(msgid, pCtx, pFunc, intercept);
faluco@593
   456
	if (iter == NULL)
faluco@552
   457
	{
faluco@552
   458
		return pCtx->ThrowNativeError("Unable to unhook the current user message");
faluco@552
   459
	}
faluco@552
   460
faluco@593
   461
	pListener = (*iter);
faluco@593
   462
	if (!g_UserMsgs.UnhookUserMessage(msgid, pListener, intercept))
faluco@552
   463
	{
faluco@552
   464
		return pCtx->ThrowNativeError("Unable to unhook the current user message");
faluco@552
   465
	}
faluco@552
   466
faluco@593
   467
	s_UsrMessageNatives.DeleteListener(pCtx, iter);
faluco@552
   468
faluco@552
   469
	return 1;
faluco@552
   470
}
faluco@505
   471
faluco@505
   472
REGISTER_NATIVES(usrmsgnatives)
faluco@505
   473
{
faluco@505
   474
	{"GetUserMessageId",			smn_GetUserMessageId},
faluco@553
   475
	{"GetUserMessageName",			smn_GetUserMessageName},
faluco@505
   476
	{"StartMessage",				smn_StartMessage},
faluco@505
   477
	{"StartMessageEx",				smn_StartMessageEx},
faluco@505
   478
	{"EndMessage",					smn_EndMessage},
faluco@552
   479
	{"HookUserMessage",				smn_HookUserMessage},
faluco@552
   480
	{"UnHookUserMessage",			smn_UnHookUserMessage},
faluco@505
   481
	{NULL,							NULL}
faluco@505
   482
};