(GAL): recognize version 102.

This commit is contained in:
morkt
2018-06-19 14:11:03 +04:00
parent f215b8d5d3
commit 95f8aae480
2 changed files with 54 additions and 28 deletions

View File

@@ -66,12 +66,14 @@ namespace GameRes.Formats.LiveMaker
public override string Description { get { return "LiveMaker image format"; } } public override string Description { get { return "LiveMaker image format"; } }
public override uint Signature { get { return 0x656C6147; } } // 'Gale' public override uint Signature { get { return 0x656C6147; } } // 'Gale'
public static Dictionary<string, string> KnownKeys = new Dictionary<string, string>(); GalScheme DefaultScheme = new GalScheme { KnownKeys = new Dictionary<string, string>() };
public Dictionary<string, string> KnownKeys { get { return DefaultScheme.KnownKeys; } }
public override ResourceScheme Scheme public override ResourceScheme Scheme
{ {
get { return new GalScheme { KnownKeys = KnownKeys }; } get { return DefaultScheme; }
set { KnownKeys = ((GalScheme)value).KnownKeys; } set { DefaultScheme = (GalScheme)value; }
} }
public override ImageMetaData ReadMetaData (IBinaryStream stream) public override ImageMetaData ReadMetaData (IBinaryStream stream)
@@ -82,29 +84,51 @@ namespace GameRes.Formats.LiveMaker
int version = header[4] * 100 + header[5] * 10 + header[6] - 5328; int version = header[4] * 100 + header[5] * 10 + header[6] - 5328;
if (version < 100 || version > 107) if (version < 100 || version > 107)
return null; return null;
int header_size = LittleEndian.ToInt32 (header, 7); if (version > 102)
if (header_size < 0x28 || header_size > 0x100)
return null;
if (header_size > header.Length)
header = new byte[header_size];
if (header_size != stream.Read (header, 0, header_size))
return null;
if (version != LittleEndian.ToInt32 (header, 0))
return null;
return new GalMetaData
{ {
Width = LittleEndian.ToUInt32 (header, 4), int header_size = LittleEndian.ToInt32 (header, 7);
Height = LittleEndian.ToUInt32 (header, 8), if (header_size < 0x28 || header_size > 0x100)
BPP = LittleEndian.ToInt32 (header, 0xC), return null;
Version = version, if (header_size > header.Length)
FrameCount = LittleEndian.ToInt32 (header, 0x10), header = new byte[header_size];
Shuffled = header[0x15] != 0, if (header_size != stream.Read (header, 0, header_size))
Compression = header[0x16], return null;
Mask = LittleEndian.ToUInt32 (header, 0x18), if (version != LittleEndian.ToInt32 (header, 0))
BlockWidth = LittleEndian.ToInt32 (header, 0x1C), return null;
BlockHeight = LittleEndian.ToInt32 (header, 0x20), return new GalMetaData
DataOffset = header_size + 11, {
}; Width = LittleEndian.ToUInt32 (header, 4),
Height = LittleEndian.ToUInt32 (header, 8),
BPP = LittleEndian.ToInt32 (header, 0xC),
Version = version,
FrameCount = LittleEndian.ToInt32 (header, 0x10),
Shuffled = header[0x15] != 0,
Compression = header[0x16],
Mask = LittleEndian.ToUInt32 (header, 0x18),
BlockWidth = LittleEndian.ToInt32 (header, 0x1C),
BlockHeight = LittleEndian.ToInt32 (header, 0x20),
DataOffset = header_size + 11,
};
}
else
{
var old_header = stream.ReadHeader (0x10);
uint name_length = stream.ReadUInt32();
stream.Seek (name_length+17, SeekOrigin.Current);
uint width = stream.ReadUInt32();
uint height = stream.ReadUInt32();
int bpp = stream.ReadInt32();
return new GalMetaData
{
Width = width,
Height = height,
BPP = bpp,
Version = version,
FrameCount = 1,
Mask = old_header.ToUInt32 (0xC),
DataOffset = 0x10,
};
}
} }
uint? LastKey = null; uint? LastKey = null;
@@ -149,7 +173,7 @@ namespace GameRes.Formats.LiveMaker
public override object GetAccessWidget () public override object GetAccessWidget ()
{ {
return new GUI.WidgetGAL(); return new GUI.WidgetGAL (KnownKeys);
} }
internal uint QueryKey () internal uint QueryKey ()
@@ -271,6 +295,8 @@ namespace GameRes.Formats.LiveMaker
protected byte[] UnpackLayer (Frame frame, int length, bool is_alpha = false) protected byte[] UnpackLayer (Frame frame, int length, bool is_alpha = false)
{ {
if (m_info.Version < 103)
return m_input.ReadBytes (length);
var layer_start = m_input.Position; var layer_start = m_input.Position;
var layer_end = layer_start + length; var layer_end = layer_start + length;
var packed = new StreamRegion (m_input.AsStream, layer_start, length, true); var packed = new StreamRegion (m_input.AsStream, layer_start, length, true);

View File

@@ -15,12 +15,12 @@ namespace GameRes.Formats.GUI
/// </summary> /// </summary>
public partial class WidgetGAL : StackPanel public partial class WidgetGAL : StackPanel
{ {
public WidgetGAL() public WidgetGAL (IDictionary<string, string> known_keys)
{ {
InitializeComponent(); InitializeComponent();
var first_item = new KeyValuePair<string, string> (arcStrings.ArcIgnoreEncryption, ""); var first_item = new KeyValuePair<string, string> (arcStrings.ArcIgnoreEncryption, "");
var items = new KeyValuePair<string, string>[] { first_item }; var items = new KeyValuePair<string, string>[] { first_item };
this.Title.ItemsSource = items.Concat (GalFormat.KnownKeys.OrderBy (x => x.Key)); this.Title.ItemsSource = items.Concat (known_keys.OrderBy (x => x.Key));
} }
} }
} }