diff --git a/ArcFormats/ArcCommon.cs b/ArcFormats/ArcCommon.cs index cee8babd..c2e471ff 100644 --- a/ArcFormats/ArcCommon.cs +++ b/ArcFormats/ArcCommon.cs @@ -57,14 +57,26 @@ namespace GameRes.Formats public static AutoEntry Create (ArcView file, long offset, string base_name) { - return new AutoEntry (base_name, () => { - uint signature = file.View.ReadUInt32 (offset); - if (0 == signature) return null; - var res = FormatCatalog.Instance.LookupSignature (signature); - if (!res.Any() || res.Skip (1).Any()) // Count == 0 || Count > 1 - return null; - return res.First(); - }) { Offset = offset }; + return new AutoEntry (base_name, () => DetectFileType (file, offset)) { Offset = offset }; + } + + public static IResource DetectFileType (ArcView file, long offset) + { + uint signature = file.View.ReadUInt32 (offset); + if (0 == signature) return null; + // resolve some special cases first + if (s_OggFormat.Value.Signature == signature) + return s_OggFormat.Value; + if (AudioFormat.Wav.Signature == signature) + return AudioFormat.Wav; + if (0x4D42 == (signature & 0xFFFF)) // 'BM' + return ImageFormat.Bmp; + var res = FormatCatalog.Instance.LookupSignature (signature); + if (!res.Any()) + return null; + if (res.Skip (1).Any()) // type is ambiguous + return null; + return res.First(); } private string GetName (string name) @@ -81,6 +93,8 @@ namespace GameRes.Formats { return null == m_res.Value ? "" : m_res.Value.Type; } + + static readonly Lazy s_OggFormat = new Lazy (() => FormatCatalog.Instance.AudioFormats.FirstOrDefault (x => x.Tag == "OGG")); } public class PrefixStream : Stream diff --git a/ArcFormats/TopCat/ArcTCD3.cs b/ArcFormats/TopCat/ArcTCD3.cs index 78fea8fb..03ecaf5b 100644 --- a/ArcFormats/TopCat/ArcTCD3.cs +++ b/ArcFormats/TopCat/ArcTCD3.cs @@ -60,7 +60,7 @@ namespace GameRes.Formats.TopCat Offset = offset; } - private static IResource DetectFileType (ArcView file, long offset) + new private static IResource DetectFileType (ArcView file, long offset) { uint signature = file.View.ReadUInt32 (offset); return FormatCatalog.Instance.LookupSignature (signature).FirstOrDefault();