Add new function: GetMapDisplayName.
This function will resolve the name of a map using FindMap, then (if applicable), will turn a workshop map name into a nicely formatted name. Currently only TF2 and CS:GO Map Workshops are supported. More can be added at a later date. This function returns false if a map was not found, but true in any other instance even if FindMap could not resolve the map name. This patch also updates the following core plugins to use this GetMapDisplayName: BaseTriggers BaseVotes MapChooser NextMap Nominations RandomCycle RockTheVote
This commit is contained in:
@@ -1273,6 +1273,38 @@ SMFindMapResult CHalfLife2::FindMap(const char *pMapName, char *pFoundMap, size_
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CHalfLife2::GetMapDisplayName(const char *pMapName, char *pDisplayname, size_t nMapNameMax)
|
||||
{
|
||||
SMFindMapResult result = FindMap(pMapName, pDisplayname, nMapNameMax);
|
||||
|
||||
if (result == SMFindMapResult::NotFound)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
char *lastSlashPos;
|
||||
// In CSGO, workshop maps show up as workshop/123456789/mapname
|
||||
if (strncmp(pDisplayname, "workshop/", 9) == 0 && (lastSlashPos = strrchr(pDisplayname, '/')) != NULL)
|
||||
{
|
||||
ke::SafeSprintf(pDisplayname, nMapNameMax, "%s", &lastSlashPos[1]);
|
||||
return true;
|
||||
}
|
||||
#elif SOURCE_ENGINE == SE_TF2
|
||||
char *ugcPos;
|
||||
// In TF2, workshop maps show up as workshop/mapname.ugc123456789
|
||||
if (strncmp(pDisplayname, "workshop/", 9) == 0 && (ugcPos = strstr(pDisplayname, ".ugc")) != NULL)
|
||||
{
|
||||
// Overwrite the . with a nul and SafeSprintf will handle the rest
|
||||
ugcPos[0] = '\0';
|
||||
ke::SafeSprintf(pDisplayname, nMapNameMax, "%s", &pDisplayname[9]);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CHalfLife2::IsMapValid(const char *map)
|
||||
{
|
||||
if (!map || !map[0])
|
||||
|
||||
@@ -187,6 +187,7 @@ public: //IGameHelpers
|
||||
bool IsMapValid(const char *map);
|
||||
SMFindMapResult FindMap(char *pMapName, size_t nMapNameMax);
|
||||
SMFindMapResult FindMap(const char *pMapName, char *pFoundMap = NULL, size_t nMapNameMax = 0);
|
||||
bool GetMapDisplayName(const char *pMapName, char *pDisplayname, size_t nMapNameMax);
|
||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||
string_t AllocPooledString(const char *pszValue);
|
||||
#endif
|
||||
|
||||
@@ -82,6 +82,14 @@ static cell_t FindMap(IPluginContext *pContext, const cell_t *params)
|
||||
return static_cast<cell_t>(g_HL2.FindMap(pMapname, pDestMap, params[3]));
|
||||
}
|
||||
|
||||
static cell_t GetMapDisplayName(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
char *pMapname, *pDisplayname;
|
||||
pContext->LocalToString(params[1], &pMapname);
|
||||
pContext->LocalToString(params[2], &pDisplayname);
|
||||
return static_cast<cell_t>(g_HL2.GetMapDisplayName(pMapname, pDisplayname, params[3]));
|
||||
}
|
||||
|
||||
static cell_t IsDedicatedServer(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
return engine->IsDedicatedServer();
|
||||
@@ -642,6 +650,7 @@ REGISTER_NATIVES(halflifeNatives)
|
||||
{"IsDedicatedServer", IsDedicatedServer},
|
||||
{"IsMapValid", IsMapValid},
|
||||
{"FindMap", FindMap},
|
||||
{"GetMapDisplayName", GetMapDisplayName},
|
||||
{"SetFakeClientConVar", SetFakeClientConVar},
|
||||
{"SetRandomSeed", SetRandomSeed},
|
||||
{"PrecacheModel", PrecacheModel},
|
||||
|
||||
Reference in New Issue
Block a user