Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Core/GameEngine/Source/GameClient/MapUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#include "GameLogic/FPUControl.h"
#include "GameNetwork/GameInfo.h"
#include "GameNetwork/NetworkDefs.h"
#include "Lib/PathUtil.h"


//-------------------------------------------------------------------------------
Expand Down Expand Up @@ -1078,9 +1079,41 @@ Bool isOfficialMap( AsciiString mapName )
}


static AsciiString normalizePathSeparators( const AsciiString &path )
{
const char nativeSeparator = getNativePathSeparator();
const char *src = path.str();

for (; *src != 0; ++src)
{
if (isPathSeparator(*src) && *src != nativeSeparator)
{
break;
}
}

if (*src == 0)
{
return path;
}

AsciiString normalized;
for (src = path.str(); *src != 0; ++src)
{
normalized.concat(isPathSeparator(*src) ? nativeSeparator : *src);
}

return normalized;
}

const MapMetaData *MapCache::findMap(AsciiString mapName)
{
mapName.toLower();

// TheSuperHackers @bugfix bobtista 28/08/2026 Match whichever separator the cache keys were
// built with, so a name stored with the other separator still resolves
mapName = normalizePathSeparators(mapName);

MapCache::iterator it = find(mapName);
if (it == end())
return nullptr;
Expand Down
36 changes: 34 additions & 2 deletions Core/Libraries/Include/Lib/PathUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,38 @@
#include "BaseType.h"
#include <string.h>

inline char getNativePathSeparator()
{
#ifdef _WIN32
return '\\';
#else
return '/';
#endif
}

inline Bool isPathSeparator(char c)
{
return c == '/' || c == '\\';
}

inline const char* getLastPathSeparator(const char* path)
{
return maxPtr(strrchr(path, '/'), strrchr(path, '\\'));
}

inline const wchar_t* getLastPathSeparator(const wchar_t* path)
{
return maxPtr(wcsrchr(path, L'/'), wcsrchr(path, L'\\'));
}

// Returns the whole path when it contains no separator
inline const char* getFileName(const char* path)
{
const char* lastSeparator = getLastPathSeparator(path);

return lastSeparator ? lastSeparator + 1 : path;
}

inline const char* getExtension(const char* path)
{
const char* lastDot = strrchr(path, '.');
Expand All @@ -32,7 +64,7 @@ inline const char* getExtension(const char* path)
return nullptr;
}

const char* lastSeparator = maxPtr(strrchr(path, '/'), strrchr(path, '\\'));
const char* lastSeparator = getLastPathSeparator(path);

// Check if the dot is contained in the filename
if (lastSeparator && lastDot < lastSeparator)
Expand All @@ -52,7 +84,7 @@ inline const wchar_t* getExtension(const wchar_t* path)
return nullptr;
}

const wchar_t* lastSeparator = maxPtr(wcsrchr(path, L'/'), wcsrchr(path, L'\\'));
const wchar_t* lastSeparator = getLastPathSeparator(path);

// Check if the dot is contained in the filename
if (lastSeparator && lastDot < lastSeparator)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -780,15 +780,18 @@ void LanGameOptionsMenuInit( WindowLayout *layout, void *userData )
slot->setColor( pref.getPreferredColor() );
slot->setPlayerTemplate( pref.getPreferredFaction() );
slot->setNATBehavior(FirewallHelperClass::FIREWALL_TYPE_SIMPLE);
game->setMap( pref.getPreferredMap() );
AsciiString lowerMap = pref.getPreferredMap();
lowerMap.toLower();
std::map<AsciiString, MapMetaData>::iterator it = TheMapCache->find(lowerMap);
if (it != TheMapCache->end())
AsciiString mapName = pref.getPreferredMap();
const MapMetaData *mapData = TheMapCache->findMap(mapName);
if (mapData != nullptr)
{
mapName = mapData->m_fileName;
}
game->setMap(mapName);
if (mapData != nullptr)
{
TheLAN->GetMyGame()->getSlot(0)->setMapAvailability(true);
TheLAN->GetMyGame()->setMapCRC( it->second.m_CRC );
TheLAN->GetMyGame()->setMapSize( it->second.m_filesize );
TheLAN->GetMyGame()->setMapCRC( mapData->m_CRC );
TheLAN->GetMyGame()->setMapSize( mapData->m_filesize );

TheLAN->GetMyGame()->adjustSlotsForMap(); // BGC- adjust the slots for the selected map.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -856,17 +856,20 @@ void LanGameOptionsMenuInit( WindowLayout *layout, void *userData )
slot->setColor( pref.getPreferredColor() );
slot->setPlayerTemplate( pref.getPreferredFaction() );
slot->setNATBehavior(FirewallHelperClass::FIREWALL_TYPE_SIMPLE);
game->setMap( pref.getPreferredMap() );
AsciiString mapName = pref.getPreferredMap();
const MapMetaData *mapData = TheMapCache->findMap(mapName);
if (mapData != nullptr)
{
mapName = mapData->m_fileName;
}
game->setMap(mapName);
game->setStartingCash( pref.getStartingCash() );
game->setSuperweaponRestriction( pref.getSuperweaponRestricted() ? 1 : 0 );
AsciiString lowerMap = pref.getPreferredMap();
lowerMap.toLower();
std::map<AsciiString, MapMetaData>::iterator it = TheMapCache->find(lowerMap);
if (it != TheMapCache->end())
if (mapData != nullptr)
{
TheLAN->GetMyGame()->getSlot(0)->setMapAvailability(true);
TheLAN->GetMyGame()->setMapCRC( it->second.m_CRC );
TheLAN->GetMyGame()->setMapSize( it->second.m_filesize );
TheLAN->GetMyGame()->setMapCRC( mapData->m_CRC );
TheLAN->GetMyGame()->setMapSize( mapData->m_filesize );

TheLAN->GetMyGame()->adjustSlotsForMap(); // BGC- adjust the slots for the selected map.
}
Expand Down
Loading