@@ -124,6 +124,42 @@ void ADungeonGeneratorBase::SerializeDungeon(FArchive& Archive)
124124{
125125FDungeonSaveProxyArchive ProxyArchive (Archive);
126126
127+ static const int32 VersionMask = 0xFFFF0000 ; // High word for magic header, this still allows for 65536 versions
128+ static const int32 MagicHeader = 0x7E250000 ; // Magic header to dertemine if it's a valid version number
129+
130+ int32 SavedVersion = FProceduralDungeonCustomVersion::LatestVersion;
131+ if (ProxyArchive.IsSaving ())
132+ {
133+ int32 ValidatedVersion = (SavedVersion & ~VersionMask) | MagicHeader; // Place magic header in the version number
134+ ProxyArchive << ValidatedVersion;
135+ }
136+ else if (ProxyArchive.IsLoading ())
137+ {
138+ SavedVersion = FProceduralDungeonCustomVersion::InitialVersion; // Fallback version if no version found
139+ const int64 StartPos = ProxyArchive.Tell ();
140+ int32 PotentialVersion = 0 ;
141+
142+ // Try reading an int, but guard against short streams
143+ if (ProxyArchive.TotalSize () - StartPos >= sizeof (int32))
144+ {
145+ ProxyArchive << PotentialVersion;
146+
147+ if ((PotentialVersion & VersionMask) == MagicHeader) // Check if valid version (high word matches magic header)
148+ {
149+ SavedVersion = PotentialVersion & ~VersionMask; // Extract version number
150+ }
151+ else
152+ {
153+ // Not a version, rewind
154+ ProxyArchive.Seek (StartPos);
155+ }
156+ }
157+ }
158+
159+ FCustomVersionContainer Versions;
160+ Versions.SetVersion (FProceduralDungeonCustomVersion::GUID, SavedVersion, TEXT (" ProcDungeonVer" ));
161+ ProxyArchive.SetCustomVersions (Versions);
162+
127163TUniquePtr<FArchiveFormatterType> Formatter = CreateArchiveFormatterFromArchive (ProxyArchive,
128164#if WITH_EDITORONLY_DATA
129165bUseJsonSave
0 commit comments