Fixed bug where trying to load Metamod:Source a second time as a SourceMM or Valve server plugin could cause a crash.

--HG--
extra : convert_revision : svn%3Ac2935e3e-5518-0410-8daf-afa5dab7d4e3/trunk%40237
This commit is contained in:
Scott Ehlert 2006-07-21 06:59:58 +00:00
parent c538c9634b
commit 7c1b752c52
3 changed files with 22 additions and 8 deletions

View File

@ -5,7 +5,9 @@
GameDLL. This issue occured in HL2 CTF, SourceForts, or any other mod that relied on GameDLL. This issue occured in HL2 CTF, SourceForts, or any other mod that relied on
files from another mod directory. files from another mod directory.
- Fixed bug where returning false in Load() after adding a Metamod event listener or - Fixed bug where returning false in Load() after adding a Metamod event listener or
hooking a function could cause a crash. hooking a function could cause a crash instead of rejecting the plugin.
- Fixed bug where trying to load Metamod:Source a second time as a SourceMM or Valve
server plugin could cause a crash.
2006/06/14 1.2.3: 2006/06/14 1.2.3:
- Added SourceHook API for manual recalls: RETURN_META_(VALUE_)MNEWPARAMS - Added SourceHook API for manual recalls: RETURN_META_(VALUE_)MNEWPARAMS

View File

@ -47,6 +47,7 @@
#define PATH_SEP_CHAR '/' #define PATH_SEP_CHAR '/'
#define ALT_SEP_CHAR '\\' #define ALT_SEP_CHAR '\\'
#define stricmp strcasecmp #define stricmp strcasecmp
#define strnicmp strncasecmp
#define SERVER_DLL "server_i486.so" #define SERVER_DLL "server_i486.so"
#endif #endif

View File

@ -172,6 +172,17 @@ bool DLLInit_Post(CreateInterfaceFn engineFactory, CreateInterfaceFn physicsFact
//This is where the magic happens //This is where the magic happens
SMM_API void *CreateInterface(const char *iface, int *ret) SMM_API void *CreateInterface(const char *iface, int *ret)
{ {
// Prevent loading of self as a SourceMM plugin or Valve server plugin :x
const char *vspIface = "ISERVERPLUGINCALLBACKS";
if (strcmp(iface, PLAPI_NAME) == 0 || strnicmp(iface, vspIface, strlen(vspIface)) == 0)
{
Warning("Do not try loading Metamod:Source as a SourceMM or Valve server plugin.\n");
if (ret)
*ret = IFACE_FAILED;
return NULL;
}
if (!gParsedGameInfo) if (!gParsedGameInfo)
{ {
gParsedGameInfo = true; gParsedGameInfo = true;
@ -180,7 +191,7 @@ SMM_API void *CreateInterface(const char *iface, int *ret)
getcwd(curpath, sizeof(curpath)-1); getcwd(curpath, sizeof(curpath)-1);
if (!GetFileOfAddress((void *)CreateInterface, dllpath, sizeof(dllpath)-1)) if (!GetFileOfAddress((void *)CreateInterface, dllpath, sizeof(dllpath)-1))
{ {
Error("GetFileOfAddress() failed! Metamod cannot load."); Error("GetFileOfAddress() failed! Metamod cannot load.\n");
return NULL; return NULL;
} }
SourceHook::String s_dllpath(dllpath); SourceHook::String s_dllpath(dllpath);
@ -213,7 +224,7 @@ SMM_API void *CreateInterface(const char *iface, int *ret)
// c:\gaben.dll // c:\gaben.dll
if (path_len > dll_len) if (path_len > dll_len)
{ {
Error("Could not detect GameDLL path! Metamod cannot load[1]."); Error("Could not detect GameDLL path! Metamod cannot load[1].\n");
return NULL; return NULL;
} }
@ -229,7 +240,7 @@ SMM_API void *CreateInterface(const char *iface, int *ret)
if ( ((cmp)(curpath, dllpath, path_len)) != 0 ) if ( ((cmp)(curpath, dllpath, path_len)) != 0 )
{ {
//:TODO: In this case, we should read /proc/self/maps and find srcds! //:TODO: In this case, we should read /proc/self/maps and find srcds!
Error("Could not detect GameDLL path! Metamod cannot load[2]."); Error("Could not detect GameDLL path! Metamod cannot load[2].\n");
return NULL; return NULL;
} }
//this will skip past the dir and its separator char //this will skip past the dir and its separator char
@ -241,7 +252,7 @@ SMM_API void *CreateInterface(const char *iface, int *ret)
{ {
if (i == 0) if (i == 0)
{ {
Error("Could not detect GameDLL path! Metamod cannot load[3]."); Error("Could not detect GameDLL path! Metamod cannot load[3].\n");
return NULL; return NULL;
} else { } else {
ptr[i] = '\0'; ptr[i] = '\0';
@ -269,7 +280,7 @@ SMM_API void *CreateInterface(const char *iface, int *ret)
FILE *fp = fopen(temp_path, "rt"); FILE *fp = fopen(temp_path, "rt");
if (!fp) if (!fp)
{ {
Error("Unable to open gameinfo.txt! Metamod cannot load."); Error("Unable to open gameinfo.txt! Metamod cannot load.\n");
return NULL; return NULL;
} }
char buffer[255]; char buffer[255];
@ -411,7 +422,7 @@ SMM_API void *CreateInterface(const char *iface, int *ret)
{ {
if (sizeTooBig) if (sizeTooBig)
{ {
Error("This mod version requires a SourceMM update (ServerGameDLL%03d)!", sizeTooBig); Error("This mod version requires a SourceMM update (ServerGameDLL%03d)!\n", sizeTooBig);
if (ret) if (ret)
*ret = IFACE_FAILED; *ret = IFACE_FAILED;
return NULL; return NULL;
@ -427,7 +438,7 @@ SMM_API void *CreateInterface(const char *iface, int *ret)
} else { } else {
//wtf do we do... //wtf do we do...
//:TODO: .. something a bit more intelligent? //:TODO: .. something a bit more intelligent?
Error("Engine requested unknown interface before GameDLL was known!"); Error("Engine requested unknown interface before GameDLL was known!\n");
return NULL; return NULL;
} }
} }