sourcemm/CSmmAPI.cpp
author Scott Ehlert <ds@alliedmods.net>
Mon Mar 26 19:44:04 2007 +0000 (2007-03-26)
changeset 298 0316a0d55281
parent 296 ba7337defd34
child 299 9bce3a94cde4
permissions -rw-r--r--
Added a check for relative jump in GetUserMessageInfo's vtable entry
Also, added more games to list...
     1 /* ======== SourceMM ========
     2  * Copyright (C) 2004-2007 Metamod:Source Development Team
     3  * No warranties of any kind
     4  *
     5  * License: zlib/libpng
     6  *
     7  * Author(s): David "BAILOPAN" Anderson
     8  * ============================
     9  */
    10 
    11 #include "convar_smm.h"
    12 #include "CSmmAPI.h"
    13 #include "sourcemm.h"
    14 #include "concommands.h"
    15 #include "CPlugin.h"
    16 #include "vsp_listener.h"
    17 
    18 /**
    19  * @brief Implementation of main API interface
    20  * @file CSmmAPI.cpp
    21  */
    22 
    23 using namespace SourceMM;
    24 
    25 CSmmAPI g_SmmAPI;
    26 
    27 CSmmAPI::CSmmAPI()
    28 {
    29 	m_ConPrintf = NULL;
    30 	m_CmdCache = false;
    31 	m_MsgCount = -1;
    32 	m_VSP = false;
    33 }
    34 
    35 CSmmAPI::~CSmmAPI()
    36 {
    37 	m_UserMessages.RemoveAll();
    38 }
    39 
    40 void CSmmAPI::LogMsg(ISmmPlugin *pl, const char *msg, ...)
    41 {
    42 	va_list ap;
    43 	static char buffer[2048];
    44 
    45 	va_start(ap, msg);
    46 	UTIL_FormatArgs(buffer, sizeof(buffer), msg, ap);
    47 	va_end(ap);
    48 
    49 	LogMessage("[%s] %s", pl->GetLogTag(), buffer);
    50 }
    51 
    52 CreateInterfaceFn CSmmAPI::engineFactory(bool syn)
    53 {
    54 	if (syn)
    55 		return EngineFactory;
    56 	return g_Engine.engineFactory;
    57 }
    58 
    59 CreateInterfaceFn CSmmAPI::physicsFactory(bool syn)
    60 {
    61 	if (syn)
    62 		return PhysicsFactory;
    63 	return g_Engine.physicsFactory;
    64 }
    65 
    66 CreateInterfaceFn CSmmAPI::fileSystemFactory(bool syn)
    67 {
    68 	if (syn)
    69 		return FileSystemFactory;
    70 	return g_Engine.fileSystemFactory;
    71 }
    72 
    73 CreateInterfaceFn CSmmAPI::serverFactory(bool syn)
    74 {
    75 	if (syn)
    76 		return CreateInterface;
    77 	return g_GameDll.factory;
    78 }
    79 
    80 CGlobalVars *CSmmAPI::pGlobals()
    81 {
    82 	return g_Engine.pGlobals;
    83 }
    84 
    85 void CSmmAPI::SetLastMetaReturn(META_RES res)
    86 {
    87 	m_Res = res;
    88 }
    89 
    90 META_RES CSmmAPI::GetLastMetaReturn()
    91 {
    92 	return m_Res;
    93 }
    94 
    95 IConCommandBaseAccessor *CSmmAPI::GetCvarBaseAccessor()
    96 {
    97 	return static_cast<IConCommandBaseAccessor *>(&g_SMConVarAccessor);
    98 }
    99 
   100 bool CSmmAPI::RegisterConCmdBase(ISmmPlugin *plugin, ConCommandBase *pCommand)
   101 {
   102 	if (pCommand->IsCommand())
   103 	{
   104 		g_PluginMngr.AddPluginCmd(plugin, pCommand);
   105 	} else {
   106 		g_PluginMngr.AddPluginCvar(plugin, pCommand);
   107 	}
   108 
   109 	return g_SMConVarAccessor.Register(pCommand);
   110 }
   111 
   112 void CSmmAPI::UnregisterConCmdBase(ISmmPlugin *plugin, ConCommandBase *pCommand)
   113 {
   114 	if (pCommand->IsCommand())
   115 	{
   116 		g_PluginMngr.RemovePluginCmd(plugin, pCommand);
   117 	} else {
   118 		g_PluginMngr.RemovePluginCvar(plugin, pCommand);
   119 	}
   120 
   121 	g_SMConVarAccessor.Unregister(pCommand);
   122 }
   123 
   124 void CSmmAPI::ConPrint(const char *fmt)
   125 {
   126 	(m_ConPrintf)("%s", fmt);
   127 }
   128 
   129 void CSmmAPI::ConPrintf(const char *fmt, ...)
   130 {
   131 	va_list ap;
   132 	static char buffer[4096];
   133 
   134 	va_start(ap, fmt);
   135 	UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
   136 	va_end(ap);
   137 
   138 	(m_ConPrintf)("%s", buffer);
   139 }
   140 
   141 void CSmmAPI::AddListener(ISmmPlugin *plugin, IMetamodListener *pListener)
   142 {
   143 	CPluginManager::CPlugin *pl = g_PluginMngr.FindByAPI(plugin);
   144 
   145 	pl->m_Events.push_back(pListener);
   146 }
   147 
   148 void *CSmmAPI::MetaFactory(const char *iface, int *_ret, PluginId *id)
   149 {
   150 	if (id)
   151 	{
   152 		*id = 0;
   153 	}
   154 
   155 	if (!iface)
   156 	{
   157 		return NULL;
   158 	}
   159 
   160 	//first check ours... we get first chance!
   161 	if (strcmp(iface, MMIFACE_SOURCEHOOK) == 0)
   162 	{
   163 		if (_ret)
   164 		{
   165 			*_ret = IFACE_OK;
   166 		}
   167 		return static_cast<void *>(static_cast<SourceHook::ISourceHook *>(&g_SourceHook));
   168 	} else if (strcmp(iface, MMIFACE_PLMANAGER) == 0) {
   169 		if (_ret)
   170 		{
   171 			*_ret = IFACE_OK;
   172 		}
   173 		return static_cast<void *>(static_cast<ISmmPluginManager *>(&g_PluginMngr));
   174 	}
   175 
   176 	CPluginManager::CPlugin *pl;
   177 	SourceHook::List<IMetamodListener *>::iterator event;
   178 	IMetamodListener *api;
   179 	int ret = 0;
   180 	void *val = NULL;
   181 
   182 	for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++)
   183 	{
   184 		pl = (*iter);
   185 		for (event=pl->m_Events.begin(); event!=pl->m_Events.end(); event++)
   186 		{
   187 			api = (*event);
   188 			ret = IFACE_FAILED;
   189 			if ( (val=api->OnMetamodQuery(iface, &ret)) != NULL )
   190 			{
   191 				if (_ret)
   192 					*_ret = ret;
   193 				if (id)
   194 					*id = pl->m_Id;
   195 				return val;
   196 			}
   197 		}
   198 	}
   199 
   200 	if (_ret)
   201 		*_ret = IFACE_FAILED;
   202 
   203 	return NULL;
   204 }
   205 
   206 //////////////////////////////////////////////////////////////////////////
   207 //THERE BE HAX HERE!!!! DON'T TELL ALFRED, BUT GABE WANTED IT THAT WAY. //
   208 // (note: you can find the offset by looking for the text               //
   209 //   "Echo text to console", you'll find the callback cmd pushed on the //
   210 //   stack.)                                                            //
   211 //////////////////////////////////////////////////////////////////////////
   212 
   213 #define SIGLEN			8
   214 #define ENGINE486_SIG	"\x55\x89\xE5\x53\x83\xEC\x14\xBB"
   215 #define ENGINE486_OFFS	40
   216 #define ENGINE686_SIG	"\x53\x83\xEC\x08\xBB\x01\x00\x00"
   217 #define ENGINE686_OFFS	50
   218 #define	ENGINEAMD_SIG	"\x53\x51\xBB\x01\x00\x00\x00\x51"
   219 #define	ENGINEAMD_OFFS	47
   220 #define ENGINEW32_SIG	"\xA1\x2A\x2A\x2A\x2A\x56\xBE\x01"
   221 #define ENGINEW32_OFFS	38
   222 #define IA32_CALL		0xE8
   223 
   224 bool vcmp(const void *_addr1, const void *_addr2, size_t len)
   225 {
   226 	unsigned char *addr1 = (unsigned char *)_addr1;
   227 	unsigned char *addr2 = (unsigned char *)_addr2;
   228 
   229 	for (size_t i=0; i<len; i++)
   230 	{
   231 		if (addr2[i] == '*')
   232 			continue;
   233 		if (addr1[i] != addr2[i])
   234 			return false;
   235 	}
   236 
   237 	return true;
   238 }
   239 
   240 //Thanks to fysh for the idea of extracting info from "echo" and for
   241 // having the original offsets at hand!
   242 bool CSmmAPI::CacheCmds()
   243 {
   244 	ICvar *pCvar = g_Engine.icvar;
   245 
   246 	ConCommandBase *pBase = pCvar->GetCommands();
   247 	unsigned char *ptr = NULL;
   248 	FnCommandCallback callback = NULL;
   249 	int offs = 0;
   250 
   251 	while (pBase)
   252 	{
   253 		if ( strcmp(pBase->GetName(), "echo") == 0 )
   254 		{
   255 			//callback = //*((FnCommandCallback *)((char *)pBase + offsetof(ConCommand, m_fnCommandCallback)));
   256 			callback = ((ConCommand *)pBase)->GetCallback();
   257 			ptr = (unsigned char *)callback;
   258 		#ifdef OS_LINUX
   259 			if (vcmp(ptr, ENGINE486_SIG, SIGLEN))
   260 			{
   261 				offs = ENGINE486_OFFS;
   262 			}
   263 			else if (vcmp(ptr, ENGINE686_SIG, SIGLEN))
   264 			{
   265 				offs = ENGINE686_OFFS;
   266 			}
   267 			else if (vcmp(ptr, ENGINEAMD_SIG, SIGLEN))
   268 			{
   269 				offs = ENGINEAMD_OFFS;
   270 			}
   271 		#elif defined OS_WIN32 // Only one Windows engine binary so far...
   272 			if (vcmp(ptr, ENGINEW32_SIG, SIGLEN))
   273 			{
   274 				offs = ENGINEW32_OFFS;
   275 			}
   276 		#endif
   277 
   278 			if (!offs || ptr[offs - 1] != IA32_CALL)
   279 			{
   280 				m_ConPrintf = (CONPRINTF_FUNC)Msg;
   281 				return false;
   282 			}
   283 			//get the relative offset
   284 			m_ConPrintf = *((CONPRINTF_FUNC *)(ptr + offs));
   285 			//add the base offset, to the ip (which is the address+offset + 4 bytes for next instruction)
   286 			m_ConPrintf = (CONPRINTF_FUNC)((unsigned long)m_ConPrintf + (unsigned long)(ptr + offs) + 4);
   287 
   288 			m_CmdCache = true;
   289 
   290 			return true;
   291 		}
   292 		pBase = const_cast<ConCommandBase *>(pBase->GetNext());
   293 	}
   294 
   295 	m_ConPrintf = (CONPRINTF_FUNC)Msg;
   296 
   297 	return false;
   298 }
   299 
   300 bool CSmmAPI::CmdCacheSuccessful()
   301 {
   302 	return m_CmdCache;
   303 }
   304 
   305 void CSmmAPI::GetApiVersions(int &major, int &minor, int &plvers, int &plmin)
   306 {
   307 	major = SM_VERS_API_MAJOR;
   308 	minor = SM_VERS_API_MINOR;
   309 	plvers = PLAPI_VERSION;
   310 	plmin = PLAPI_MIN_VERSION;
   311 }
   312 
   313 void CSmmAPI::GetShVersions(int &shvers, int &shimpl)
   314 {
   315 	shvers = SH_IFACE_VERSION;
   316 	shimpl = SH_IMPL_VERSION;
   317 }
   318 
   319 int CSmmAPI::FormatIface(char iface[], unsigned int maxlength)
   320 {
   321 	int length = (int)strlen(iface);
   322 	int i;
   323 	int num = 0;
   324 
   325 	for (i = length - 1; i >= 0; i--)
   326 	{
   327 		if (!isdigit(iface[i]))
   328 		{
   329 			if (i != length - 1)
   330 			{
   331 				num = 1;
   332 			}
   333 			break;
   334 		}
   335 	}
   336 
   337 	if ( (num && ((int)maxlength <= length)) || (!num && ((int)maxlength <= length + 3)) )
   338 	{
   339 		return -1;
   340 	}
   341 
   342 	if (i != length - 1)
   343 		num = atoi(&(iface[++i]));
   344 
   345 	num++;
   346 
   347 	snprintf(&(iface[i]), 4, "%03d", num);
   348 
   349 	return num;
   350 }
   351 
   352 void *CSmmAPI::InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max, int *ret)
   353 {
   354 	char _if[256];	/* assume no interface goes beyond this */
   355 	size_t len = strlen(iface);
   356 	int num = 0;
   357 	void *pf = NULL;
   358 
   359 	if (max > 999)
   360 		max = 999;
   361 
   362 	if (len + 4 > sizeof(_if))
   363 	{
   364 		if (ret)
   365 		{
   366 			*ret = IFACE_FAILED;
   367 		}
   368 		return NULL;
   369 	}
   370 
   371 	strcpy(_if, iface);
   372 
   373 	do
   374 	{
   375 		if ( (pf = (fn)(_if, ret)) != NULL )
   376 			break;
   377 		if (num > max)
   378 			break;
   379 	} while (( num = FormatIface(_if, len+1) ));
   380 
   381 	return pf;
   382 }
   383 
   384 void *CSmmAPI::VInterfaceMatch(CreateInterfaceFn fn, const char *iface, int min)
   385 {
   386 	char buffer[256];	/* assume no interface will go beyond this */
   387 	size_t len = strlen(iface);
   388 	int ret;			/* just in case something doesn't handle NULL properly */
   389 
   390 	if (len > sizeof(buffer) - 4)
   391 	{
   392 		return NULL;
   393 	}
   394 
   395 	strcpy(buffer, iface);
   396 
   397 	if (min != -1)
   398 	{
   399 		char *ptr = &buffer[len - 1];
   400 		int digits = 0;
   401 		while (isdigit(*ptr) && digits <=3)
   402 		{
   403 			*ptr = '\0';
   404 			digits++;
   405 			ptr--;
   406 		}
   407 		if (digits != 3)
   408 		{
   409 			/* for now, assume this is an error */
   410 			strcpy(buffer, iface);
   411 		} else {
   412 			char num[4];
   413 			min = (min == 0) ? 1 : min;
   414 			snprintf(num, sizeof(num), "%03d", min);
   415 			strcat(buffer, num);
   416 		}
   417 	}
   418 
   419 	return InterfaceSearch(fn, buffer, IFACE_MAXNUM, &ret);
   420 }
   421 
   422 const char *CSmmAPI::GetBaseDir()
   423 {
   424 	return g_ModPath.c_str();
   425 }
   426 
   427 void CSmmAPI::PathFormat(char *buffer, size_t len, const char *fmt, ...)
   428 {
   429 	va_list ap;
   430 	va_start(ap, fmt);
   431 	size_t mylen = UTIL_FormatArgs(buffer, len, fmt, ap);
   432 	va_end(ap);
   433 
   434 	for (size_t i = 0; i < mylen; i++)
   435 	{
   436 		if (buffer[i] == ALT_SEP_CHAR)
   437 		{
   438 			buffer[i] = PATH_SEP_CHAR;
   439 		}
   440 	}
   441 }
   442 
   443 void CSmmAPI::ClientConPrintf(edict_t *client, const char *fmt, ...)
   444 {
   445 	va_list ap;
   446 	static char buffer[4096];
   447 
   448 	va_start(ap, fmt);
   449 	UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
   450 	va_end(ap);
   451 
   452 	g_Engine.engine->ClientPrintf(client, buffer);
   453 }
   454 
   455 void CSmmAPI::LoadAsVSP()
   456 {
   457 	g_Engine.engine->ServerCommand("plugin_load \n");
   458 	g_Engine.engine->ServerExecute();
   459 
   460 	IServerPluginCallbacks *iface = NULL;
   461 	if (g_VspListener.IsLoaded())
   462 	{
   463 		iface = &g_VspListener;
   464 	}
   465 
   466 	PluginIter iter;
   467 	CPluginManager::CPlugin *pPlugin;
   468 	SourceHook::List<IMetamodListener *>::iterator event;
   469 	IMetamodListener *pML;
   470 	for (iter=g_PluginMngr._begin(); iter!=g_PluginMngr._end(); iter++)
   471 	{
   472 		pPlugin = (*iter);
   473 		if (pPlugin->m_Status < Pl_Paused)
   474 		{
   475 			continue;
   476 		}
   477 		/* Only valid for plugins >= 10 (v1:5, SourceMM 1.4) */
   478 		if (pPlugin->m_API->GetApiVersion() < 10)
   479 		{
   480 			continue;
   481 		}
   482 		for (event=pPlugin->m_Events.begin();
   483 			 event!=pPlugin->m_Events.end();
   484 			 event++)
   485 		{
   486 			pML = (*event);
   487 			pML->OnVSPListening(iface);
   488 		}
   489 	}
   490 }
   491 
   492 void CSmmAPI::EnableVSPListener()
   493 {
   494 	/* If GameInit already passed and we're not already enabled or loaded, go ahead and LoadAsVSP load */
   495 	if (bGameInit && !m_VSP && !g_VspListener.IsLoaded())
   496 	{
   497 		LoadAsVSP();
   498 	}
   499 	m_VSP = true;
   500 }
   501 
   502 int CSmmAPI::GetGameDLLVersion()
   503 {
   504 	return g_GameDllVersion;
   505 }
   506 
   507 //////////////////////////////////////////////////////////////////////
   508 // EVEN MORE HACKS HERE! YOU HAVE BEEN WARNED!                      //
   509 // Signatures necessary in finding the pointer to the CUtlDict that //
   510 //   stores user message information.                               //
   511 // IServerGameDLL::GetUserMessageInfo() normally crashes with bad   //
   512 //   message indices. This is our answer to it. Yuck! <:-(          //
   513 //////////////////////////////////////////////////////////////////////
   514 #ifdef OS_WIN32
   515 	/* General Windows sig */
   516 	#define MSGCLASS_SIGLEN		7
   517 	#define MSGCLASS_SIG		"\x8B\x0D\x2A\x2A\x2A\x2A\x56"
   518 	#define MSGCLASS_OFFS		2
   519 
   520 	/* Dystopia Wimdows hack */
   521 	#define MSGCLASS2_SIGLEN	16
   522 	#define MSGCLASS2_SIG		"\x56\x8B\x74\x24\x2A\x85\xF6\x7C\x2A\x3B\x35\x2A\x2A\x2A\x2A\x7D"
   523 	#define MSGCLASS2_OFFS		11
   524 #elif defined OS_LINUX
   525 	/* No frame pointer sig */
   526 	#define MSGCLASS_SIGLEN		14
   527 	#define MSGCLASS_SIG		"\x53\x83\xEC\x2A\x8B\x2A\x2A\x2A\xA1\x2A\x2A\x2A\x2A\x89"
   528 	#define MSGCLASS_OFFS		9
   529 
   530 	/* Frame pointer sig */
   531 	#define MSGCLASS2_SIGLEN	16
   532 	#define MSGCLASS2_SIG		"\x55\x89\xE5\x53\x83\xEC\x2A\x8B\x2A\x2A\xA1\x2A\x2A\x2A\x2A\x89"
   533 	#define MSGCLASS2_OFFS		11
   534 #endif
   535 
   536 /* This is the ugliest function in all of SourceMM */
   537 /* :TODO: Make this prettier */
   538 bool CSmmAPI::CacheUserMessages()
   539 {
   540 	SourceHook::MemFuncInfo info = {true, -1, 0, 0};
   541 	SourceHook::GetFuncInfo(&IServerGameDLL::GetUserMessageInfo, info);
   542 
   543 	/* Get address of original GetUserMessageInfo() */
   544 	char *vfunc = reinterpret_cast<char *>(g_GameDllPatch->GetOrigFunc(info.vtbloffs, info.vtblindex));
   545 
   546 	/* If we can't get original function, that means there's no hook */
   547 	if (vfunc == NULL)
   548 	{
   549 		/* Get virtual function address 'manually' then */
   550 		char *adjustedptr = reinterpret_cast<char *>(g_GameDll.pGameDLL) + info.thisptroffs + info.vtbloffs;
   551 		char **vtable = *reinterpret_cast<char ***>(adjustedptr);
   552 
   553 		vfunc = vtable[info.vtblindex];
   554 	}
   555 
   556 	/* Oh dear, we have a relative jump on our hands
   557 	 * PVK II on Windows made me do this, but I suppose it doesn't hurt to check this on Linux too...
   558 	 */
   559 	if (*vfunc == '\xE9')
   560 	{
   561 		/* Get address from displacement...
   562 		 *
   563 		 * Add 5 because it's relative to next instruction:
   564 		 * Opcode <1 byte> + 32-bit displacement <4 bytes> 
   565 		 */
   566 		vfunc = vfunc + *reinterpret_cast<unsigned int *>(vfunc + 1) + 5;
   567 	}
   568 
   569 	UserMsgDict *dict = NULL;
   570 
   571 	if (vcmp(vfunc, MSGCLASS_SIG, MSGCLASS_SIGLEN))
   572 	{
   573 		/* Get address of CUserMessages instance */
   574 		char **userMsgClass = *reinterpret_cast<char ***>(vfunc + MSGCLASS_OFFS);
   575 
   576 		/* Get address of CUserMessages::m_UserMessages */
   577 		dict = reinterpret_cast<UserMsgDict *>(*userMsgClass);
   578 	} else if (vcmp(vfunc, MSGCLASS2_SIG, MSGCLASS2_SIGLEN)) {
   579 	#ifdef OS_WIN32
   580 		/* If we get here, the code is possibly inlined like in Dystopia */
   581 
   582 		/* Get the address of the CUtlRBTree */
   583 		char *rbtree = *reinterpret_cast<char **>(vfunc + MSGCLASS2_OFFS);
   584 
   585 		/* CUtlDict should be 8 bytes before the CUtlRBTree (hacktacular!) */
   586 		dict = reinterpret_cast<UserMsgDict *>(rbtree - 8);
   587 	#elif defined OS_LINUX
   588 		/* Get address of CUserMessages instance */
   589 		char **userMsgClass = *reinterpret_cast<char ***>(vfunc + MSGCLASS2_OFFS);
   590 
   591 		/* Get address of CUserMessages::m_UserMessages */
   592 		dict = reinterpret_cast<UserMsgDict *>(*userMsgClass);
   593 	#endif
   594 	}
   595 
   596 	if (dict)
   597 	{
   598 		m_MsgCount = dict->Count();
   599 
   600 		/* Ensure that count is within bounds of an unsigned byte, because that's what engine supports */
   601 		if (m_MsgCount < 0 || m_MsgCount > 255)
   602 		{
   603 			m_MsgCount = -1;
   604 			return false;
   605 		}
   606 
   607 		UserMessage *msg;
   608 
   609 		/* Cache messages in our CUtlDict */
   610 		for (int i = 0; i < m_MsgCount; i++)
   611 		{
   612 			msg = dict->Element(i);
   613 			m_UserMessages.Insert(msg->name, msg);
   614 		}
   615 
   616 		return true;
   617 	}
   618 
   619 	return false;
   620 }
   621 
   622 bool CSmmAPI::MsgCacheSuccessful()
   623 {
   624 	return m_MsgCount > -1;
   625 }
   626 
   627 int CSmmAPI::GetUserMessageCount()
   628 {
   629 	return m_MsgCount;
   630 }
   631 
   632 int CSmmAPI::FindUserMessage(const char *name, int *size)
   633 {
   634 	int index = m_UserMessages.Find(name);
   635 
   636 	if (size && index > -1)
   637 	{
   638 		UserMessage *msg = m_UserMessages.Element(index);
   639 		*size = msg->size;
   640 	}
   641 
   642 	return index;
   643 }
   644 
   645 const char *CSmmAPI::GetUserMessage(int index, int *size)
   646 {
   647 	if (m_MsgCount <= 0 || index < 0 || index >= m_MsgCount)
   648 	{
   649 		return NULL;
   650 	}
   651 
   652 	UserMessage *msg = m_UserMessages.Element(index);
   653 
   654 	if (size)
   655 	{
   656 		*size = msg->size;
   657 	}
   658 
   659 	return msg->name;
   660 }