Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
feat(gameengine): build random maps in memory instead of writing them out
Olcay Seygan2341fcf160c0
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 04a770ab7..0b0aca9c9 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1055,6 +1055,11 @@ found and fixed — EA's own, not port damage.**- The number that made the map is in its name, so the same number always makes the same map, onevery machine. Two people who type it get the same ground, and a map worth keeping can be foundagain.+- A generated map is never written to your disk. It is built when the match starts and lives in+ memory, and nothing is left behind afterwards - no map folder per roll, no preview files, no+ entry in the map cache. The name still says which map it is, so the replay of a generated match+ plays back on any machine: it rebuilds the same ground from the same name, and so does anybody+ who joins.---diff --git a/GeneralsMD/Code/GameEngine/Include/Common/RAMFile.h b/GeneralsMD/Code/GameEngine/Include/Common/RAMFile.hindex e344c384c..18eaf8aa2 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/RAMFile.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/RAMFile.h@@ -100,6 +100,7 @@ class RAMFile : public Filevirtual Bool open( File *file ); ///< Open file for fast RAM accessvirtual Bool openFromArchive(File *archiveFile, const AsciiString& filename, Int offset, Int size); ///< copy file data from the given file at the given offset for the given size.+ virtual Bool openFromMemory(const Char *data, Int size, const AsciiString& filename); ///< read a block somebody else is holding, for a file that was never on a diskvirtual Bool copyDataToFile(File *localFile); ///< write the contents of the RAM file to the given local file. This could be REALLY slow./**diff --git a/GeneralsMD/Code/GameEngine/Include/Common/RandomMapGenerator.h b/GeneralsMD/Code/GameEngine/Include/Common/RandomMapGenerator.hindex f10315252..6292a9cf8 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/RandomMapGenerator.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/RandomMapGenerator.h@@ -84,11 +84,29 @@ public:static void clampSettings( RandomMapSettings& settings );};-/** Generate the map and its preview and write both into the user map directory,- under a name that carries the generator version and the settings, so two- different maps never land on one file. Returns false when the file could not- be written; on success mapPathOut is what -map wants. */-extern Bool writeRandomMap( const RandomMapSettings& settings, AsciiString& mapPathOut );+/** Generate the map and its preview and keep both in memory under a path in the+ user map directory, named for the generator version and the settings. Nothing+ is written to disk: TheFileSystem serves that path out of the store below, so+ the map cache, the loader and the CRC all read it the way they read any other+ map. On success mapPathOut is what -map wants. */+extern Bool stageRandomMap( const RandomMapSettings& settings, AsciiString& mapPathOut );++/** Is this the path of a generated map or its preview? The settings are in the+ name, which is what lets a replay, a save or a joining machine rebuild the+ same bytes from the name alone. A name carrying another generator version is+ not one this build can rebuild, so it is not one of ours. */+extern Bool isGeneratedMapPath( const AsciiString& path );++/** The bytes of a generated map or preview, generated on the spot if this path+ has not been staged in this run - which is how a replay of a generated map+ plays back without the map having been kept anywhere. FALSE when the path is+ not a generated one. The bytes belong to the store and stay valid until it+ drops that map, so a caller that keeps them across a load is wrong. */+extern Bool generatedMapBytes( const AsciiString& path, const char **bytesOut, Int *sizeOut );++/** Every generated map the store is holding, so the map cache can carry an+ entry for each without a directory to scan. */+extern void generatedMapPaths( std::vector<AsciiString>& pathsOut );/** A ChunkInputStream over a block of memory, so a generated map can be handedto the same readers that parse maps off disk. */diff --git a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cppindex 6e7c9416c..b117d02c6 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp@@ -443,14 +443,13 @@ Int parseMapName(char *args[], int num)}// parseRandomMap =============================================================-/** -randommap <seed> [players] [cells|small|normal|large]: generate a skirmish map from the seed- and write it into the user map directory as+/** -randommap <seed> [players] [cells|small|normal|large]: generate a skirmish map from the seed,+ keep it in memory under the name"RMG_v<generator version>_<seed>_<players>p_<cells>c", then point -map at it. The version is inthe name because it is in the bytes: a build that generates a different map from the same seed- writes a different file rather than a confusing one.- Nothing downstream has to know- it was generated: the map cache walks that directory on startup, so it shows up in the skirmish- map list like any hand-made map, and -autoskirmish starts on it. The same seed gives the same+ names a different map rather than a confusing one. Nothing is written to disk and nothing+ downstream has to know: the file system serves that name out of the generator, so the map cache+ lists it like any hand-made map and -autoskirmish starts on it. The same seed gives the samemap on every machine, so both sides of a network game can be handed the same command line.The last argument is either a cell count outright or one of the three sizes, which are countsthat grow with the number of players rather than fixed ones. */@@ -493,7 +492,7 @@ Int parseRandomMap(char *args[], int num)}AsciiString path;- if (!writeRandomMap( settings, path ))+ if (!stageRandomMap( settings, path ))return eaten;TheWritableGlobalData->m_mapName = path;diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RandomMapGenerator.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RandomMapGenerator.cppindex ba55733fa..990a00fb4 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/RandomMapGenerator.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/RandomMapGenerator.cpp@@ -2994,60 +2994,189 @@ void RandomMapGenerator::generatePreview( const RandomMapSettings& settings,}//------------------------------------------------------------------------------// Writing a generated map where the map cache will find it+// Generated maps, kept in memory where the map cache will find them//------------------------------------------------------------------------------static Bool writeWholeFile( const AsciiString& path, const std::vector<char>& bytes )-{- FILE *fp = fopen( path.str(), "wb" );- if( fp == NULL )- {- DEBUG_LOG(("random map: could not write '%s'\n", path.str()));- return FALSE;- }+/** A generated map lives here and nowhere else. The seed, the player count and the size are in the+ path, so anything that names the map - a replay, a save, a lobby telling the other machines what+ is being played - names everything the generator needs to build the same bytes again. That is+ what lets the map stay out of the file system entirely: a machine that has never seen this seed+ rebuilds it from the name the moment something opens it.- fwrite( &bytes[0], 1, bytes.size(), fp );- fclose( fp );- return TRUE;-}+ Three maps are kept. Rerolling in the menu walks through them, and a map that falls off the end+ is not lost, only forgotten: the next open of that path builds it again. */+enum { RMG_MAPS_KEPT = 3 };-Bool writeRandomMap( const RandomMapSettings& settings, AsciiString& mapPathOut )+struct RMGStagedMap{- RandomMapSettings clamped = settings;- RandomMapGenerator::clampSettings( clamped );+ RandomMapSettings m_settings; ///< what it was built from, which is what a slot is looked up by+ AsciiString m_mapPath; ///< lowercase, the path the rest of the game names it by+ std::vector<char> m_mapBytes;+ std::vector<char> m_previewBytes;+ UnsignedInt m_stagedAt; ///< which staging this was, so the oldest can go first+};- std::vector<char> mapBytes;- std::vector<char> previewBytes;- RandomMapGenerator::generate( clamped, mapBytes );- RandomMapGenerator::generatePreview( clamped, previewBytes );+static RMGStagedMap theStagedMaps[ RMG_MAPS_KEPT ];+static UnsignedInt theStagingCount = 0;- // The map cache expects "<user maps>\<name>\<name>.map" - the directory- // carries the name - and getMapPreviewImage wants "<name>.tga" beside it.+/** Where a generated map's bytes would live, given its settings. The map cache expects+ "<user maps>\<name>\<name>.map" - the directory carries the name - and getMapPreviewImage wants+ "<name>.tga" beside it. */+static void generatedMapPathsFor( const RandomMapSettings& clamped, AsciiString& mapPath,+ AsciiString& previewPath )+{AsciiString name;name.format( "RMG_v%d_%d_%dp_%dc", RANDOM_MAP_GENERATOR_VERSION, clamped.m_seed,clamped.m_numPlayers, clamped.m_playableCells );- AsciiString mapsDir, dir, previewPath;- mapsDir.format( "%sMaps", TheGlobalData->getPath_UserData().str() );- dir.format( "%s\\%s", mapsDir.str(), name.str() );- mapPathOut.format( "%s\\%s.map", dir.str(), name.str() );+ AsciiString dir;+ dir.format( "%sMaps\\%s", TheGlobalData->getPath_UserData().str(), name.str() );+ mapPath.format( "%s\\%s.map", dir.str(), name.str() );previewPath.format( "%s\\%s.tga", dir.str(), name.str() );- TheFileSystem->createDirectory( mapsDir ); // createDirectory is one level at a time- TheFileSystem->createDirectory( dir );+ mapPath.toLower();+ previewPath.toLower();+}++/** Read the settings back out of a generated map's file name. FALSE for anything else, including a+ name written by another generator version - those bytes cannot be rebuilt here. */+static Bool settingsFromGeneratedPath( const AsciiString& path, RandomMapSettings& settingsOut )+{+ const char *leafStart = path.reverseFind( '\\' );+ AsciiString leaf = leafStart ? leafStart + 1 : path.str();++ // every path the game hands around has been through toLower somewhere, and a name is a name+ // whichever case it arrives in+ leaf.toLower();++ Int version = 0, seed = 0, players = 0, cells = 0;+ if( sscanf( leaf.str(), "rmg_v%d_%d_%dp_%dc", &version, &seed, &players, &cells ) != 4 )+ return FALSE;- if( !writeWholeFile( mapPathOut, mapBytes ) )+ if( version != RANDOM_MAP_GENERATOR_VERSION )return FALSE;- writeWholeFile( previewPath, previewBytes );+ settingsOut.m_seed = seed;+ settingsOut.m_numPlayers = players;+ settingsOut.m_playableCells = cells;++ // a name carrying settings the generator would clamp names bytes it never produced+ RandomMapSettings clamped = settingsOut;+ RandomMapGenerator::clampSettings( clamped );+ return clamped.m_seed == settingsOut.m_seed+ && clamped.m_numPlayers == settingsOut.m_numPlayers+ && clamped.m_playableCells == settingsOut.m_playableCells;+}++Bool isGeneratedMapPath( const AsciiString& path )+{+ RandomMapSettings settings;+ return settingsFromGeneratedPath( path, settings );+}++/** The slot holding this map, or NULL. Slots are looked up by what they were built from rather+ than by the path that asked for them: the same map is named several ways over a run - the switch+ that made it, the lobby, the loader, the preview - and two spellings of one map would otherwise+ each build their own copy. */+static RMGStagedMap *findStagedMap( const RandomMapSettings& settings )+{+ for( Int i = 0; i < RMG_MAPS_KEPT; i++ )+ {+ if( theStagedMaps[i].m_mapBytes.empty() )+ continue;++ if( theStagedMaps[i].m_settings.m_seed == settings.m_seed+ && theStagedMaps[i].m_settings.m_numPlayers == settings.m_numPlayers+ && theStagedMaps[i].m_settings.m_playableCells == settings.m_playableCells )+ return &theStagedMaps[i];+ }++ return NULL;+}++/// Build a map into the slot that has been unused longest.+static RMGStagedMap *stageMap( const RandomMapSettings& clamped )+{+ RMGStagedMap *slot = &theStagedMaps[0];+ for( Int i = 1; i < RMG_MAPS_KEPT; i++ )+ {+ if( theStagedMaps[i].m_stagedAt < slot->m_stagedAt )+ slot = &theStagedMaps[i];+ }- DEBUG_LOG(("random map: wrote '%s' - %d players, %d cells, %d bytes, fingerprint %X\n",- mapPathOut.str(), clamped.m_numPlayers, clamped.m_playableCells, mapBytes.size(),+ AsciiString previewPath;+ generatedMapPathsFor( clamped, slot->m_mapPath, previewPath );+ slot->m_settings = clamped;+ slot->m_mapBytes.clear();+ slot->m_previewBytes.clear();+ RandomMapGenerator::generate( clamped, slot->m_mapBytes );+ RandomMapGenerator::generatePreview( clamped, slot->m_previewBytes );+ slot->m_stagedAt = ++theStagingCount;++ DEBUG_LOG(("random map: built '%s' - %d players, %d cells, %d bytes, fingerprint %X\n",+ slot->m_mapPath.str(), clamped.m_numPlayers, clamped.m_playableCells, slot->m_mapBytes.size(),RandomMapGenerator::fingerprint( clamped )));+ return slot;+}++Bool stageRandomMap( const RandomMapSettings& settings, AsciiString& mapPathOut )+{+ RandomMapSettings clamped = settings;+ RandomMapGenerator::clampSettings( clamped );++ AsciiString mapPath, previewPath;+ generatedMapPathsFor( clamped, mapPath, previewPath );++ if( findStagedMap( clamped ) == NULL )+ stageMap( clamped );++ mapPathOut = mapPath;+ return TRUE;+}++Bool generatedMapBytes( const AsciiString& path, const char **bytesOut, Int *sizeOut )+{+ RandomMapSettings settings;+ if( !settingsFromGeneratedPath( path, settings ) )+ return FALSE;++ RandomMapSettings clamped = settings;+ RandomMapGenerator::clampSettings( clamped );++ RMGStagedMap *slot = findStagedMap( clamped );+ if( slot == NULL )+ {+ // nothing has this seed in hand - a replay, a save or a joined game naming a map this+ // machine has never built. The name says how to build it, so build it+ slot = stageMap( clamped );+ }++ AsciiString lower = path;+ lower.toLower();++ const std::vector<char>& bytes = lower.endsWith( ".tga" ) ? slot->m_previewBytes+ : slot->m_mapBytes;+ if( bytes.empty() )+ return FALSE;++ if( bytesOut )+ *bytesOut = &bytes[0];+ if( sizeOut )+ *sizeOut = (Int)bytes.size();+return TRUE;}+void generatedMapPaths( std::vector<AsciiString>& pathsOut )+{+ for( Int i = 0; i < RMG_MAPS_KEPT; i++ )+ {+ if( !theStagedMaps[i].m_mapBytes.empty() )+ pathsOut.push_back( theStagedMaps[i].m_mapPath );+ }+}+//-----------------------------------------------------------------------------// MemoryChunkInputStream//-----------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cppindex e84c816f0..4898a4cb4 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cpp@@ -54,6 +54,8 @@#include "Common/GameAudio.h"#include "Common/LocalFileSystem.h"#include "Common/PerfTimer.h"+#include "Common/RAMFile.h"+#include "Common/RandomMapGenerator.h"DECLARE_PERF_TIMER(FileSystem)@@ -180,11 +182,30 @@ void FileSystem::reset( void )// FileSystem::open//============================================================================-File* FileSystem::openFile( const Char *filename, Int access )+File* FileSystem::openFile( const Char *filename, Int access ){USE_PERF_TIMER(FileSystem)File *file = NULL;+ //+ // A generated map is not on any disk and never will be: its seed, player count and size are in+ // its name, so the bytes are built from the name on the first read and served out of memory+ // after that. It goes in front of both file systems because the map cache, the loader, the+ // CRC and the preview all reach a map through here and none of them has to know the difference.+ //+ const Char *generated = NULL;+ Int generatedSize = 0;+ if ( generatedMapBytes( AsciiString( filename ), &generated, &generatedSize ) )+ {+ RAMFile *ramFile = newInstance( RAMFile );+ if ( ramFile->openFromMemory( generated, generatedSize, AsciiString( filename ) ) )+ return ramFile;++ ramFile->close();+ ramFile->deleteInstance();+ return NULL;+ }+if ( TheLocalFileSystem != NULL ){file = TheLocalFileSystem->openFile( filename, access );@@ -206,6 +227,10 @@ Bool FileSystem::doesFileExist(const Char *filename) const{USE_PERF_TIMER(FileSystem)+ // a generated map exists wherever its name can be read, which is everywhere - see openFile+ if (isGeneratedMapPath( AsciiString( filename ) ))+ return TRUE;+unsigned key=TheNameKeyGenerator->nameToLowercaseKey(filename);std::map<unsigned,bool>::iterator i=m_fileExist.find(key);if (i!=m_fileExist.end())@@ -246,7 +271,16 @@ Bool FileSystem::getFileInfo(const AsciiString& filename, FileInfo *fileInfo) coreturn FALSE;}memset(fileInfo, 0, sizeof(fileInfo));-++ // a generated map has a size and no timestamp: the bytes follow from the name, so there is no+ // moment at which they were made and nothing that could make them go stale+ const Char *generated = NULL;+ Int generatedSize = 0;+ if (generatedMapBytes(filename, &generated, &generatedSize)) {+ fileInfo->sizeLow = generatedSize;+ return TRUE;+ }+if (TheLocalFileSystem->getFileInfo(filename, fileInfo)) {return TRUE;}diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/RAMFile.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/RAMFile.cppindex 0c44ce50c..66ea1d042 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/RAMFile.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/RAMFile.cpp@@ -236,8 +236,40 @@ Bool RAMFile::openFromArchive(File *archiveFile, const AsciiString& filename, Inreturn TRUE;}+//============================================================================+// RAMFile::openFromMemory+//============================================================================+/**+ * Take a copy of a block somebody else is holding and read from that, so a file that was never+ * on a disk - a map built from a seed, say - opens the way every other file opens.+ */+//============================================================================+Bool RAMFile::openFromMemory( const Char *data, Int size, const AsciiString& filename )+{+ if (data == NULL || size <= 0) {+ return FALSE;+ }++ if (File::open(filename.str(), File::READ | File::BINARY) == FALSE) {+ return FALSE;+ }++ if (m_data != NULL) {+ delete[] m_data;+ m_data = NULL;+ }++ m_data = MSGNEW("RAMFILE") Char [size]; // pool[]ify+ m_size = size;+ m_pos = 0;+ memcpy(m_data, data, size);+ m_nameStr = filename;++ return TRUE;+}+//=================================================================-// RAMFile::close+// RAMFile::close//=================================================================/*** Closes the current file if it is open.diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishMapSelectMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishMapSelectMenu.cppindex abfec6fca..5d45fb12a 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishMapSelectMenu.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishMapSelectMenu.cpp@@ -113,9 +113,9 @@ static void addRandomMapRows( GameWindow *listbox )}}-/** Generate a map, write it where the map cache looks, and hand back its path. The seed comes off- the clock: this is the client picking a map, not the simulation, so it may be as random as the- player expects a reroll to be. */+/** Generate a map, keep it where the map cache will find it, and hand back its path. The seed+ comes off the clock: this is the client picking a map, not the simulation, so it may be as+ random as the player expects a reroll to be. */static Bool generateRandomMapForSkirmish( RandomMapSize size, AsciiString& mapPathOut ){RandomMapSettings settings;@@ -123,7 +123,7 @@ static Bool generateRandomMapForSkirmish( RandomMapSize size, AsciiString& mapPasettings.m_numPlayers = RandomMapGenerator::MAX_PLAYERS;settings.m_playableCells = RandomMapGenerator::cellsFor( size, settings.m_numPlayers );- if( !writeRandomMap( settings, mapPathOut ) )+ if( !stageRandomMap( settings, mapPathOut ) )return FALSE;mapPathOut.toLower();@@ -642,8 +642,8 @@ WindowMsgHandledType SkirmishMapSelectMenuSystem( GameWindow *window, UnsignedInconst char *mapFname = (const char *)GadgetListBoxGetItemData( mapWindow, selected );DEBUG_ASSERTCRASH(mapFname, ("No map item data"));- // Choosing a random map row is the reroll: a fresh seed, a fresh map on- // disk at the size the row asks for, and the map cache reloaded so the rest+ // Choosing a random map row is the reroll: a fresh seed, a fresh map built in+ // memory at the size the row asks for, and the map cache reloaded so the rest// of this runs unchanged.RandomMapSize randomSize = randomMapSizeOfRow( mapFname );if( randomSize != RANDOM_MAP_SIZE_COUNT )diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MapUtil.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MapUtil.cppindex 6f68f0020..96a3e7bb5 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MapUtil.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MapUtil.cpp@@ -44,6 +44,7 @@#include "Common/WellKnownKeys.h"#include "Common/INI.h"#include "Common/QuotedPrintable.h"+#include "Common/RandomMapGenerator.h"#include "Common/SkirmishBattleHonors.h"#include "Common/ThingFactory.h"#include "Common/ThingTemplate.h"@@ -405,7 +406,10 @@ void MapCache::writeCacheINI( Bool userDir )MapMetaData md;while (it != end()){- if (it->first.startsWithNoCase(mapDir.str()))+ // a generated map is rebuilt from its name whenever it is asked for, so an entry for one is+ // a line about a file that is not there - and this file is the one place a random map could+ // still leave something behind on disk+ if (it->first.startsWithNoCase(mapDir.str()) && !isGeneratedMapPath(it->first)){md = it->second;fprintf(fp, "\nMapCache %s\n", AsciiStringToQuotedPrintable(it->first.str()).str());@@ -654,6 +658,24 @@ Bool MapCache::loadUserMaps()iter++;}+ //+ // The generated maps are in memory rather than in that directory, so the scan above cannot find+ // them. They are added here instead, off the list the generator is holding, which is what puts+ // a random map in the list with its players, its start positions and its preview without any of+ // it having been written anywhere.+ //+ std::vector<AsciiString> generated;+ generatedMapPaths(generated);+ for (std::vector<AsciiString>::const_iterator gen = generated.begin(); gen != generated.end(); ++gen)+ {+ FileInfo generatedInfo;+ if (!TheFileSystem->getFileInfo(*gen, &generatedInfo))+ continue;++ m_seen[*gen] = TRUE;+ parsedAMap |= addMap(mapDir, *gen, &generatedInfo, FALSE);+ }+// clean out unseen mapsif (clearUnseenMaps(mapDir))return TRUE;@@ -1109,9 +1131,28 @@ const MapMetaData *MapCache::findMap(AsciiString mapName){mapName.toLower();MapCache::iterator it = find(mapName);- if (it == end())+ if (it != end())+ return &(it->second);++ //+ // A generated map is in the cache only if something staged it this run, and a replay, a save or+ // a game somebody else is hosting names one that nothing here has built. The name carries the+ // settings, so the map is built now and cached like any other rather than reported missing -+ // which is what the map is asked for at, among other places, the point where the start+ // positions are dealt out, and that caller does not survive a no.+ //+ if (!isGeneratedMapPath(mapName))return NULL;- return &(it->second);++ FileInfo generatedInfo;+ if (!TheFileSystem->getFileInfo(mapName, &generatedInfo))+ return NULL;++ m_seen[mapName] = TRUE;+ addMap(getUserMapDir(), mapName, &generatedInfo, FALSE);++ it = find(mapName);+ return (it == end()) ? NULL : &(it->second);}// ------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex cf4759ef9..3e52511ff 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -7420,6 +7420,83 @@ TEST(the_generator_still_turns_a_seed_into_the_bytes_it_used_to)CHECK_EQ( _controlfp( 0, 0 ), entry );}+//-------------------------------------------------------------------------------------------------+/** A generated map is never written anywhere. It is staged in memory and TheFileSystem serves it,+ so the map cache, the loader, the CRC and the preview all reach it the way they reach a map on+ a disk - and the local file system, which is the only thing here that can touch a disk at all,+ has never heard of it. */+//-------------------------------------------------------------------------------------------------+TEST(a_generated_map_is_served_out_of_memory_and_written_nowhere)+{+ CHECK( bootOnce() );++ GlobalData *saved = TheWritableGlobalData;+ TheWritableGlobalData = NEW GlobalData;++ RandomMapSettings settings;+ settings.m_seed = 4242;+ settings.m_numPlayers = 2;+ settings.m_playableCells = 96;++ AsciiString path;+ CHECK( stageRandomMap( settings, path ) );+ CHECK( isGeneratedMapPath( path ) );++ // the settings are in the name, which is what lets any machine rebuild the same bytes+ CHECK( path.endsWithNoCase( "_4242_2p_96c.map" ) );++ // it exists, and it exists nowhere on a disk+ CHECK( TheFileSystem->doesFileExist( path.str() ) );+ CHECK( !TheLocalFileSystem->doesFileExist( path.str() ) );++ std::vector<char> expected;+ RandomMapGenerator::generate( settings, expected );++ FileInfo info;+ CHECK( TheFileSystem->getFileInfo( path, &info ) );+ CHECK_EQ( (Int)info.sizeLow, (Int)expected.size() );++ // and reading it back gives the generator's own bytes+ File *file = TheFileSystem->openFile( path.str(), File::READ | File::BINARY );+ CHECK( file != NULL );+ if( file )+ {+ std::vector<char> read( expected.size() );+ CHECK_EQ( file->read( &read[0], (Int)read.size() ), (Int)expected.size() );+ CHECK( memcmp( &read[0], &expected[0], expected.size() ) == 0 );+ file->close();+ }++ // a map the store has forgotten is rebuilt from its name: this is what plays a replay of a+ // generated map back on a machine that never staged it+ for( Int other = 0; other < 4; other++ )+ {+ RandomMapSettings evict;+ evict.m_seed = 5000 + other;+ evict.m_numPlayers = 2;+ evict.m_playableCells = 96;+ AsciiString evicted;+ CHECK( stageRandomMap( evict, evicted ) );+ }++ File *rebuilt = TheFileSystem->openFile( path.str(), File::READ | File::BINARY );+ CHECK( rebuilt != NULL );+ if( rebuilt )+ {+ std::vector<char> read( expected.size() );+ CHECK_EQ( rebuilt->read( &read[0], (Int)read.size() ), (Int)expected.size() );+ CHECK( memcmp( &read[0], &expected[0], expected.size() ) == 0 );+ rebuilt->close();+ }++ // nothing else is one of ours, and neither is a name from another generator version+ CHECK( !isGeneratedMapPath( AsciiString( "Maps\\Tournament Desert\\Tournament Desert.map" ) ) );+ CHECK( !isGeneratedMapPath( AsciiString( "Maps\\RMG_v1_7_2p_96c\\RMG_v1_7_2p_96c.map" ) ) );++ delete TheWritableGlobalData;+ TheWritableGlobalData = saved;+}+//-------------------------------------------------------------------------------------------------/** getMapPreviewImage looks for a 128x128 tga beside the map and shows nothing at all when it isnot there, which is what the map list did for every generated map. The bytes have to be a tga