Merge pull request #8252 from Mailaender/legacy-map-dispose-stream
Fixed missing dispose on stream in LegacyMapImporter
This commit is contained in:
@@ -132,87 +132,90 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
|
|
||||||
public void ConvertIniMap(string iniFile)
|
public void ConvertIniMap(string iniFile)
|
||||||
{
|
{
|
||||||
var file = new IniFile(GlobalFileSystem.Open(iniFile));
|
using (var stream = GlobalFileSystem.Open(iniFile))
|
||||||
var basic = file.GetSection("Basic");
|
|
||||||
var mapSection = file.GetSection("Map");
|
|
||||||
var legacyMapFormat = (IniMapFormat)Exts.ParseIntegerInvariant(basic.GetValue("NewINIFormat", "0"));
|
|
||||||
var offsetX = Exts.ParseIntegerInvariant(mapSection.GetValue("X", "0"));
|
|
||||||
var offsetY = Exts.ParseIntegerInvariant(mapSection.GetValue("Y", "0"));
|
|
||||||
var width = Exts.ParseIntegerInvariant(mapSection.GetValue("Width", "0"));
|
|
||||||
var height = Exts.ParseIntegerInvariant(mapSection.GetValue("Height", "0"));
|
|
||||||
mapSize = (legacyMapFormat == IniMapFormat.RedAlert) ? 128 : 64;
|
|
||||||
var size = new Size(mapSize, mapSize);
|
|
||||||
|
|
||||||
var tileset = Truncate(mapSection.GetValue("Theater", "TEMPERAT"), 8);
|
|
||||||
map = Map.FromTileset(rules.TileSets[tileset]);
|
|
||||||
map.Title = basic.GetValue("Name", Path.GetFileNameWithoutExtension(iniFile));
|
|
||||||
map.Author = "Westwood Studios";
|
|
||||||
map.MapSize = new int2(mapSize, mapSize);
|
|
||||||
map.Bounds = Rectangle.FromLTRB(offsetX, offsetY, offsetX + width, offsetY + height);
|
|
||||||
|
|
||||||
map.MapResources = Exts.Lazy(() => new CellLayer<ResourceTile>(TileShape.Rectangle, size));
|
|
||||||
map.MapTiles = Exts.Lazy(() => new CellLayer<TerrainTile>(TileShape.Rectangle, size));
|
|
||||||
|
|
||||||
map.Videos = new MapVideos();
|
|
||||||
|
|
||||||
map.Options = new MapOptions();
|
|
||||||
|
|
||||||
if (legacyMapFormat == IniMapFormat.RedAlert)
|
|
||||||
{
|
{
|
||||||
UnpackRATileData(ReadPackedSection(file.GetSection("MapPack")));
|
var file = new IniFile(stream);
|
||||||
UnpackRAOverlayData(ReadPackedSection(file.GetSection("OverlayPack")));
|
var basic = file.GetSection("Basic");
|
||||||
ReadRATrees(file);
|
var mapSection = file.GetSection("Map");
|
||||||
}
|
var legacyMapFormat = (IniMapFormat)Exts.ParseIntegerInvariant(basic.GetValue("NewINIFormat", "0"));
|
||||||
else
|
var offsetX = Exts.ParseIntegerInvariant(mapSection.GetValue("X", "0"));
|
||||||
{
|
var offsetY = Exts.ParseIntegerInvariant(mapSection.GetValue("Y", "0"));
|
||||||
// CnC
|
var width = Exts.ParseIntegerInvariant(mapSection.GetValue("Width", "0"));
|
||||||
using (var s = GlobalFileSystem.Open(iniFile.Substring(0, iniFile.Length - 4) + ".bin"))
|
var height = Exts.ParseIntegerInvariant(mapSection.GetValue("Height", "0"));
|
||||||
UnpackCncTileData(s);
|
mapSize = (legacyMapFormat == IniMapFormat.RedAlert) ? 128 : 64;
|
||||||
ReadCncOverlay(file);
|
var size = new Size(mapSize, mapSize);
|
||||||
ReadCncTrees(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
LoadVideos(file, "BASIC");
|
var tileset = Truncate(mapSection.GetValue("Theater", "TEMPERAT"), 8);
|
||||||
LoadActors(file, "STRUCTURES");
|
map = Map.FromTileset(rules.TileSets[tileset]);
|
||||||
LoadActors(file, "UNITS");
|
map.Title = basic.GetValue("Name", Path.GetFileNameWithoutExtension(iniFile));
|
||||||
LoadActors(file, "INFANTRY");
|
map.Author = "Westwood Studios";
|
||||||
LoadSmudges(file, "SMUDGE");
|
map.MapSize = new int2(mapSize, mapSize);
|
||||||
|
map.Bounds = Rectangle.FromLTRB(offsetX, offsetY, offsetX + width, offsetY + height);
|
||||||
|
|
||||||
var wps = file.GetSection("Waypoints")
|
map.MapResources = Exts.Lazy(() => new CellLayer<ResourceTile>(TileShape.Rectangle, size));
|
||||||
.Where(kv => Exts.ParseIntegerInvariant(kv.Value) > 0)
|
map.MapTiles = Exts.Lazy(() => new CellLayer<TerrainTile>(TileShape.Rectangle, size));
|
||||||
.Select(kv => Pair.New(Exts.ParseIntegerInvariant(kv.Key),
|
|
||||||
LocationFromMapOffset(Exts.ParseIntegerInvariant(kv.Value), mapSize)));
|
|
||||||
|
|
||||||
// Add waypoint actors
|
map.Videos = new MapVideos();
|
||||||
foreach (var kv in wps)
|
|
||||||
{
|
map.Options = new MapOptions();
|
||||||
if (kv.First <= 7)
|
|
||||||
|
if (legacyMapFormat == IniMapFormat.RedAlert)
|
||||||
{
|
{
|
||||||
var ar = new ActorReference("mpspawn")
|
UnpackRATileData(ReadPackedSection(file.GetSection("MapPack")));
|
||||||
{
|
UnpackRAOverlayData(ReadPackedSection(file.GetSection("OverlayPack")));
|
||||||
new LocationInit((CPos)kv.Second),
|
ReadRATrees(file);
|
||||||
new OwnerInit("Neutral")
|
|
||||||
};
|
|
||||||
|
|
||||||
map.ActorDefinitions.Add(new MiniYamlNode("Actor" + actorCount++, ar.Save()));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var ar = new ActorReference("waypoint")
|
// CnC
|
||||||
{
|
using (var s = GlobalFileSystem.Open(iniFile.Substring(0, iniFile.Length - 4) + ".bin"))
|
||||||
new LocationInit((CPos)kv.Second),
|
UnpackCncTileData(s);
|
||||||
new OwnerInit("Neutral")
|
ReadCncOverlay(file);
|
||||||
};
|
ReadCncTrees(file);
|
||||||
|
|
||||||
map.ActorDefinitions.Add(new MiniYamlNode("waypoint" + kv.First, ar.Save()));
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Create default player definitions only if there are no players to import
|
LoadVideos(file, "BASIC");
|
||||||
mapPlayers = new MapPlayers(map.Rules, (players.Count == 0) ? map.SpawnPoints.Value.Length : 0);
|
LoadActors(file, "STRUCTURES");
|
||||||
foreach (var p in players)
|
LoadActors(file, "UNITS");
|
||||||
LoadPlayer(file, p, legacyMapFormat == IniMapFormat.RedAlert);
|
LoadActors(file, "INFANTRY");
|
||||||
map.PlayerDefinitions = mapPlayers.ToMiniYaml();
|
LoadSmudges(file, "SMUDGE");
|
||||||
|
|
||||||
|
var wps = file.GetSection("Waypoints")
|
||||||
|
.Where(kv => Exts.ParseIntegerInvariant(kv.Value) > 0)
|
||||||
|
.Select(kv => Pair.New(Exts.ParseIntegerInvariant(kv.Key),
|
||||||
|
LocationFromMapOffset(Exts.ParseIntegerInvariant(kv.Value), mapSize)));
|
||||||
|
|
||||||
|
// Add waypoint actors
|
||||||
|
foreach (var kv in wps)
|
||||||
|
{
|
||||||
|
if (kv.First <= 7)
|
||||||
|
{
|
||||||
|
var ar = new ActorReference("mpspawn")
|
||||||
|
{
|
||||||
|
new LocationInit((CPos)kv.Second),
|
||||||
|
new OwnerInit("Neutral")
|
||||||
|
};
|
||||||
|
|
||||||
|
map.ActorDefinitions.Add(new MiniYamlNode("Actor" + actorCount++, ar.Save()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var ar = new ActorReference("waypoint")
|
||||||
|
{
|
||||||
|
new LocationInit((CPos)kv.Second),
|
||||||
|
new OwnerInit("Neutral")
|
||||||
|
};
|
||||||
|
|
||||||
|
map.ActorDefinitions.Add(new MiniYamlNode("waypoint" + kv.First, ar.Save()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create default player definitions only if there are no players to import
|
||||||
|
mapPlayers = new MapPlayers(map.Rules, (players.Count == 0) ? map.SpawnPoints.Value.Length : 0);
|
||||||
|
foreach (var p in players)
|
||||||
|
LoadPlayer(file, p, legacyMapFormat == IniMapFormat.RedAlert);
|
||||||
|
map.PlayerDefinitions = mapPlayers.ToMiniYaml();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int2 LocationFromMapOffset(int offset, int mapSize)
|
static int2 LocationFromMapOffset(int offset, int mapSize)
|
||||||
|
|||||||
Reference in New Issue
Block a user