Save map generation args in replays/saves instead of full map.

This commit is contained in:
Paul Chote
2025-12-28 10:30:54 +00:00
committed by Gustas Kažukauskas
parent 0d479e7c18
commit fdb4ce4e0f
10 changed files with 56 additions and 71 deletions

View File

@@ -93,7 +93,7 @@ namespace OpenRA.Network
public Dictionary<string, Session.Slot> Slots { get; private set; }
public Dictionary<string, SlotClient> SlotClients { get; private set; }
public Dictionary<int, MiniYaml> TraitData = [];
public string MapData;
public MapGenerationArgs MapGenerationArgs;
// Set on game start
int[] clientsBySlotIndex = [];
@@ -142,7 +142,9 @@ namespace OpenRA.Network
SlotClients.Add(slotClient.Slot, slotClient);
}
MapData = rs.ReadLengthPrefixedString(Encoding.UTF8, Connection.MaxOrderLength);
var mapGenerationArgs = rs.ReadLengthPrefixedString(Encoding.UTF8, Connection.MaxOrderLength);
if (!string.IsNullOrEmpty(mapGenerationArgs))
MapGenerationArgs = FieldLoader.Load<MapGenerationArgs>(new MiniYaml("", MiniYaml.FromString(mapGenerationArgs, $"{filepath}:mapGenerationArgs")));
if (rs.Position != traitDataOffset || rs.ReadInt32() != TraitDataMarker)
throw new InvalidDataException("Invalid orasav file");
@@ -159,7 +161,7 @@ namespace OpenRA.Network
public void StartGame(Session lobbyInfo, MapPreview map)
{
if (map.Class == MapClassification.Generated)
MapData = map.ToBase64String();
MapGenerationArgs = map.GenerationArgs;
// Game orders are mapped from a client index to the slot that they occupy
// Orders from spectators are ignored, which is not a problem in practice
@@ -312,7 +314,7 @@ namespace OpenRA.Network
.ToList();
file.WriteLengthPrefixedString(Encoding.UTF8, slotClientNodes.WriteToString());
file.WriteLengthPrefixedString(Encoding.UTF8, MapData);
file.WriteLengthPrefixedString(Encoding.UTF8, MapGenerationArgs?.Serialize() ?? string.Empty);
var traitDataOffset = file.Length;
file.Write(TraitDataMarker);