Merge pull request #354 from powerlord/findmap-plugins

GetMapDisplayName and associated core plugin changes.
This commit is contained in:
Nicholas Hastings
2015-09-17 11:17:40 -04:00
13 changed files with 195 additions and 50 deletions
+32
View File
@@ -1276,6 +1276,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])
+1
View File
@@ -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
+9
View File
@@ -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},