diff --git a/OpenRA.FileFormats/Graphics/SpriteSource.cs b/OpenRA.FileFormats/Graphics/SpriteSource.cs index 9c7f25a672..5442c8167f 100644 --- a/OpenRA.FileFormats/Graphics/SpriteSource.cs +++ b/OpenRA.FileFormats/Graphics/SpriteSource.cs @@ -29,7 +29,7 @@ namespace OpenRA.FileFormats bool CacheWhenLoadingTileset { get; } } - public enum SpriteType { Unknown, ShpTD, ShpTS, ShpD2, TmpTD, TmpRA, R8 } + public enum SpriteType { Unknown, ShpTD, ShpTS, ShpD2, TmpTD, TmpRA, TmpTS, R8 } public static class SpriteSource { static bool IsTmpRA(Stream s) @@ -57,6 +57,29 @@ namespace OpenRA.FileFormats return a == 0 && b == 0x0D1AFFFF; } + static bool IsTmpTS(Stream s) + { + var start = s.Position; + s.Position += 8; + var sx = s.ReadUInt32(); + var sy = s.ReadUInt32(); + + // Find the first frame + var offset = s.ReadUInt32(); + + if (offset > s.Length - 52) + { + s.Position = start; + return false; + } + + s.Position = offset + 12; + var test = s.ReadUInt32(); + + s.Position = start; + return test == sx * sy / 2 + 52; + } + static bool IsShpTS(Stream s) { var start = s.Position; @@ -204,6 +227,9 @@ namespace OpenRA.FileFormats if (IsTmpTD(s)) return SpriteType.TmpTD; + if (IsTmpTS(s)) + return SpriteType.TmpTS; + if (IsShpD2(s)) return SpriteType.ShpD2; @@ -225,6 +251,8 @@ namespace OpenRA.FileFormats return new TmpRAReader(s); case SpriteType.TmpTD: return new TmpTDReader(s); + case SpriteType.TmpTS: + return new TmpTSReader(s); case SpriteType.ShpD2: return new ShpD2Reader(s); case SpriteType.Unknown: diff --git a/OpenRA.FileFormats/Graphics/TmpTSReader.cs b/OpenRA.FileFormats/Graphics/TmpTSReader.cs new file mode 100644 index 0000000000..581cdeaafd --- /dev/null +++ b/OpenRA.FileFormats/Graphics/TmpTSReader.cs @@ -0,0 +1,75 @@ +#region Copyright & License Information +/* + * Copyright 2007-2013 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see COPYING. + */ +#endregion + +using System; +using System.Collections.Generic; +using System.Drawing; +using System.IO; +using System.Linq; + +namespace OpenRA.FileFormats +{ + public class TmpTSTile : ISpriteFrame + { + public Size Size { get; private set; } + public Size FrameSize { get { return Size; } } + public float2 Offset { get { return float2.Zero; } } + public byte[] Data { get; set; } + + public TmpTSTile(Stream s, Size size) + { + Size = size; + + // Ignore tile header for now + s.Position += 52; + + Data = new byte[size.Width * size.Height]; + + // Unpack tile data + var width = 4; + for (var i = 0; i < size.Height; i++) + { + var start = i * size.Width + (size.Width - width) / 2; + for (var j = 0; j < width; j++) + Data[start + j] = s.ReadUInt8(); + + width += (i < size.Height / 2 - 1? 1 : -1) * 4; + } + + // Ignore Z-data for now + // Ignore extra data for now + } + } + + public class TmpTSReader : ISpriteSource + { + readonly List tiles = new List(); + public IEnumerable Frames { get { return tiles.Cast(); } } + public bool CacheWhenLoadingTileset { get { return false; } } + + public TmpTSReader(Stream s) + { + var templateWidth = s.ReadUInt32(); + var templateHeight = s.ReadUInt32(); + var tileWidth = s.ReadInt32(); + var tileHeight = s.ReadInt32(); + var size = new Size(tileWidth, tileHeight); + var offsets = new uint[templateWidth * templateHeight]; + for (var i = 0; i < offsets.Length; i++) + offsets[i] = s.ReadUInt32(); + + for (var i = 0; i < offsets.Length; i++) + { + s.Position = offsets[i]; + tiles.Add(new TmpTSTile(s, size)); + } + } + } +} diff --git a/OpenRA.FileFormats/OpenRA.FileFormats.csproj b/OpenRA.FileFormats/OpenRA.FileFormats.csproj index cc8a5edf80..ce1a3bbf70 100644 --- a/OpenRA.FileFormats/OpenRA.FileFormats.csproj +++ b/OpenRA.FileFormats/OpenRA.FileFormats.csproj @@ -156,6 +156,7 @@ +