Merge pull request #396 from alliedmodders/findmapconst
Change FindMap to take a const char* for searching instead of char*.
This commit is contained in:
commit
6909f7f23c
@ -1207,8 +1207,15 @@ const char *CHalfLife2::GetEntityClassname(CBaseEntity *pEntity)
|
|||||||
return *(const char **)(((unsigned char *)pEntity) + offset);
|
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
|
#if SOURCE_ENGINE >= SE_LEFT4DEAD
|
||||||
static char mapNameTmp[PLATFORM_MAX_PATH];
|
static char mapNameTmp[PLATFORM_MAX_PATH];
|
||||||
g_SourceMod.Format(mapNameTmp, sizeof(mapNameTmp), "maps%c%s.bsp", PLATFORM_SEP_CHAR, pMapName);
|
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
|
else
|
||||||
{
|
{
|
||||||
ke::SafeStrcpy(pMapName, nMapNameMax, &results[0][helperCmdLen + 1]);
|
ke::SafeStrcpy(pFoundMap, nMapNameMax, &results[0][helperCmdLen + 1]);
|
||||||
return SMFindMapResult::FuzzyMatch;
|
return SMFindMapResult::FuzzyMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif SOURCE_ENGINE == SE_TF2
|
#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
|
#else
|
||||||
return engine->IsMapValid(pMapName) == 0 ? SMFindMapResult::NotFound : SMFindMapResult::Found;
|
return engine->IsMapValid(pMapName) == 0 ? SMFindMapResult::NotFound : SMFindMapResult::Found;
|
||||||
#endif
|
#endif
|
||||||
@ -1262,10 +1278,7 @@ bool CHalfLife2::IsMapValid(const char *map)
|
|||||||
if (!map || !map[0])
|
if (!map || !map[0])
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
static char szTmp[PLATFORM_MAX_PATH];
|
return FindMap(map) != SMFindMapResult::NotFound;
|
||||||
ke::SafeStrcpy(szTmp, sizeof(szTmp), map);
|
|
||||||
|
|
||||||
return FindMap(szTmp, sizeof(szTmp)) != SMFindMapResult::NotFound;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add ep1 support for this. (No IServerTools available there)
|
// TODO: Add ep1 support for this. (No IServerTools available there)
|
||||||
|
@ -185,7 +185,8 @@ public: //IGameHelpers
|
|||||||
const char *GetEntityClassname(edict_t *pEdict);
|
const char *GetEntityClassname(edict_t *pEdict);
|
||||||
const char *GetEntityClassname(CBaseEntity *pEntity);
|
const char *GetEntityClassname(CBaseEntity *pEntity);
|
||||||
bool IsMapValid(const char *map);
|
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
|
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||||
string_t AllocPooledString(const char *pszValue);
|
string_t AllocPooledString(const char *pszValue);
|
||||||
#endif
|
#endif
|
||||||
|
@ -71,10 +71,15 @@ static cell_t FindMap(IPluginContext *pContext, const cell_t *params)
|
|||||||
{
|
{
|
||||||
char *pMapname;
|
char *pMapname;
|
||||||
pContext->LocalToString(params[1], &pMapname);
|
pContext->LocalToString(params[1], &pMapname);
|
||||||
|
|
||||||
cell_t size = params[2];
|
if (params[0] == 2)
|
||||||
|
{
|
||||||
return static_cast<cell_t>(g_HL2.FindMap(pMapname, size));
|
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)
|
static cell_t IsDedicatedServer(IPluginContext *pContext, const cell_t *params)
|
||||||
|
@ -159,12 +159,13 @@ native bool:IsMapValid(const String:map[]);
|
|||||||
* Returns whether a full or partial map name is found or can be resolved
|
* 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,
|
* @param map Map name (usually same as map path relative to maps/ dir,
|
||||||
* excluding .bsp extension). If result is FindMap_FuzzyMatch
|
* excluding .bsp extension).
|
||||||
* or FindMap_NonCanonical, this will be updated to the full path.
|
* @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.
|
* @param maxlen Maximum length to write to map var.
|
||||||
* @return Result of the find operation. Not all result types are supported on all games.
|
* @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.
|
* Returns whether the server is dedicated.
|
||||||
|
Loading…
Reference in New Issue
Block a user