Merge pull request #396 from alliedmodders/findmapconst

Change FindMap to take a const char* for searching instead of char*.
This commit is contained in:
Kyle Sanderson 2015-09-10 12:14:43 -07:00
commit 6909f7f23c
4 changed files with 35 additions and 15 deletions

View File

@ -1207,8 +1207,15 @@ const char *CHalfLife2::GetEntityClassname(CBaseEntity *pEntity)
return *(const char **)(((unsigned char *)pEntity) + offset);
}
SMFindMapResult CHalfLife2::FindMap(char *pMapName, int nMapNameMax)
SMFindMapResult CHalfLife2::FindMap(char *pMapName, size_t nMapNameMax)
{
return this->FindMap(pMapName, pMapName, nMapNameMax);
}
SMFindMapResult CHalfLife2::FindMap(const char *pMapName, char *pFoundMap, size_t nMapNameMax)
{
ke::SafeStrcpy(pFoundMap, nMapNameMax, pMapName);
#if SOURCE_ENGINE >= SE_LEFT4DEAD
static char mapNameTmp[PLATFORM_MAX_PATH];
g_SourceMod.Format(mapNameTmp, sizeof(mapNameTmp), "maps%c%s.bsp", PLATFORM_SEP_CHAR, pMapName);
@ -1247,11 +1254,20 @@ SMFindMapResult CHalfLife2::FindMap(char *pMapName, int nMapNameMax)
}
else
{
ke::SafeStrcpy(pMapName, nMapNameMax, &results[0][helperCmdLen + 1]);
ke::SafeStrcpy(pFoundMap, nMapNameMax, &results[0][helperCmdLen + 1]);
return SMFindMapResult::FuzzyMatch;
}
#elif SOURCE_ENGINE == SE_TF2
return static_cast<SMFindMapResult>(engine->FindMap(pMapName, nMapNameMax));
static char szTemp[PLATFORM_MAX_PATH];
if (pFoundMap == NULL)
{
ke::SafeStrcpy(szTemp, SM_ARRAYSIZE(szTemp), pMapName);
pFoundMap = szTemp;
nMapNameMax = 0;
}
return static_cast<SMFindMapResult>(engine->FindMap(pFoundMap, static_cast<int>(nMapNameMax)));
#else
return engine->IsMapValid(pMapName) == 0 ? SMFindMapResult::NotFound : SMFindMapResult::Found;
#endif
@ -1262,10 +1278,7 @@ bool CHalfLife2::IsMapValid(const char *map)
if (!map || !map[0])
return false;
static char szTmp[PLATFORM_MAX_PATH];
ke::SafeStrcpy(szTmp, sizeof(szTmp), map);
return FindMap(szTmp, sizeof(szTmp)) != SMFindMapResult::NotFound;
return FindMap(map) != SMFindMapResult::NotFound;
}
// TODO: Add ep1 support for this. (No IServerTools available there)

View File

@ -185,7 +185,8 @@ public: //IGameHelpers
const char *GetEntityClassname(edict_t *pEdict);
const char *GetEntityClassname(CBaseEntity *pEntity);
bool IsMapValid(const char *map);
SMFindMapResult FindMap(char *pMapName, int nMapNameMax);
SMFindMapResult FindMap(char *pMapName, size_t nMapNameMax);
SMFindMapResult FindMap(const char *pMapName, char *pFoundMap = NULL, size_t nMapNameMax = 0);
#if SOURCE_ENGINE >= SE_ORANGEBOX
string_t AllocPooledString(const char *pszValue);
#endif

View File

@ -71,10 +71,15 @@ static cell_t FindMap(IPluginContext *pContext, const cell_t *params)
{
char *pMapname;
pContext->LocalToString(params[1], &pMapname);
cell_t size = params[2];
return static_cast<cell_t>(g_HL2.FindMap(pMapname, size));
if (params[0] == 2)
{
return static_cast<cell_t>(g_HL2.FindMap(pMapname, params[2]));
}
char *pDestMap;
pContext->LocalToString(params[2], &pDestMap);
return static_cast<cell_t>(g_HL2.FindMap(pMapname, pDestMap, params[3]));
}
static cell_t IsDedicatedServer(IPluginContext *pContext, const cell_t *params)

View File

@ -159,12 +159,13 @@ native bool:IsMapValid(const String:map[]);
* Returns whether a full or partial map name is found or can be resolved
*
* @param map Map name (usually same as map path relative to maps/ dir,
* excluding .bsp extension). If result is FindMap_FuzzyMatch
* or FindMap_NonCanonical, this will be updated to the full path.
* excluding .bsp extension).
* @param foundmap Resolved map name. If the return is FindMap_FuzzyMatch
* or FindMap_NonCanonical the buffer will be the full path.
* @param maxlen Maximum length to write to map var.
* @return Result of the find operation. Not all result types are supported on all games.
*/
native FindMapResult FindMap(char[] map, int maxlen);
native FindMapResult FindMap(const char[] map, char[] foundmap, int maxlen);
/**
* Returns whether the server is dedicated.