From eb60e27378c79b662e8db359681ca97e7bfb56a9 Mon Sep 17 00:00:00 2001 From: ManicSteiner Date: Sat, 23 Dec 2023 23:30:09 +0800 Subject: [PATCH] perf: Various fixes --- ArcFormats/Ivory/ImageMOE.cs | 3 +++ ArcFormats/Kid/ArcDATRAW.cs | 2 ++ ArcFormats/Kid/ImageBIP.cs | 10 +++++----- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/ArcFormats/Ivory/ImageMOE.cs b/ArcFormats/Ivory/ImageMOE.cs index ac976e8f..5c73e231 100644 --- a/ArcFormats/Ivory/ImageMOE.cs +++ b/ArcFormats/Ivory/ImageMOE.cs @@ -103,6 +103,9 @@ namespace GameRes.Formats.Ivory bool IsValidInput (Stream input, uint width, uint height, int pixel_size) { int total = (int)width * (int)height; + // Other formats will be incorrectly recognized as this format, try to correct it. + if (total * pixel_size < input.Length / 10) + return false; int dst = 0; while (dst < total) { diff --git a/ArcFormats/Kid/ArcDATRAW.cs b/ArcFormats/Kid/ArcDATRAW.cs index 3ce1f311..9928ab5d 100644 --- a/ArcFormats/Kid/ArcDATRAW.cs +++ b/ArcFormats/Kid/ArcDATRAW.cs @@ -38,6 +38,8 @@ namespace GameRes.Formats.Kid entry.Size = size; dir.Add(entry); } + if (dir.Count == 0) + return null; return new ArcFile(file, this, dir); } diff --git a/ArcFormats/Kid/ImageBIP.cs b/ArcFormats/Kid/ImageBIP.cs index 6f641cf2..7e8eb9b3 100644 --- a/ArcFormats/Kid/ImageBIP.cs +++ b/ArcFormats/Kid/ImageBIP.cs @@ -20,7 +20,7 @@ namespace GameRes.Formats.Kid uint header = file.ReadUInt32(); if (header == 9) { - throw new NotSupportedException(string.Format("BIP Chara format not supported.")); + return null;//throw new NotSupportedException(string.Format("BIP Chara format not supported.")); } else if (header != 5) { @@ -33,18 +33,18 @@ namespace GameRes.Formats.Kid return null; } uint sign = file.ReadUInt16(); - uint dy = 0; + uint dy; bool sliced = true; if (sign == 0x17) { dy = 16; } - else if (sign == 0x16) + else if (sign == 0x13) { dy = 16; sliced = false; } - else if (sign == 0x13) + else if (sign == 0x16) { dy = 32; } @@ -57,7 +57,7 @@ namespace GameRes.Formats.Kid file.Seek(0x88, SeekOrigin.Begin); uint width = file.ReadUInt16(); uint height = file.ReadUInt16(); - if (width >= 1280 || height >= 1280) // suppose not so large + if (width >= 1280 || height >= 1280 || width == 0 || height == 0) // suppose not so large return null; file.Seek(0x90, SeekOrigin.Begin);