perf: Various fixes

This commit is contained in:
ManicSteiner 2023-12-23 23:30:09 +08:00
parent 53d8fdd844
commit eb60e27378
3 changed files with 10 additions and 5 deletions

View File

@ -103,6 +103,9 @@ namespace GameRes.Formats.Ivory
bool IsValidInput (Stream input, uint width, uint height, int pixel_size) bool IsValidInput (Stream input, uint width, uint height, int pixel_size)
{ {
int total = (int)width * (int)height; 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; int dst = 0;
while (dst < total) while (dst < total)
{ {

View File

@ -38,6 +38,8 @@ namespace GameRes.Formats.Kid
entry.Size = size; entry.Size = size;
dir.Add(entry); dir.Add(entry);
} }
if (dir.Count == 0)
return null;
return new ArcFile(file, this, dir); return new ArcFile(file, this, dir);
} }

View File

@ -20,7 +20,7 @@ namespace GameRes.Formats.Kid
uint header = file.ReadUInt32(); uint header = file.ReadUInt32();
if (header == 9) 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) else if (header != 5)
{ {
@ -33,18 +33,18 @@ namespace GameRes.Formats.Kid
return null; return null;
} }
uint sign = file.ReadUInt16(); uint sign = file.ReadUInt16();
uint dy = 0; uint dy;
bool sliced = true; bool sliced = true;
if (sign == 0x17) if (sign == 0x17)
{ {
dy = 16; dy = 16;
} }
else if (sign == 0x16) else if (sign == 0x13)
{ {
dy = 16; dy = 16;
sliced = false; sliced = false;
} }
else if (sign == 0x13) else if (sign == 0x16)
{ {
dy = 32; dy = 32;
} }
@ -57,7 +57,7 @@ namespace GameRes.Formats.Kid
file.Seek(0x88, SeekOrigin.Begin); file.Seek(0x88, SeekOrigin.Begin);
uint width = file.ReadUInt16(); uint width = file.ReadUInt16();
uint height = 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; return null;
file.Seek(0x90, SeekOrigin.Begin); file.Seek(0x90, SeekOrigin.Begin);