From dd103fbdc40717c2873395d1cab4763773c04dfc Mon Sep 17 00:00:00 2001 From: morkt Date: Sat, 29 Dec 2018 22:26:45 +0400 Subject: [PATCH] (GRP): adjusted TPW decompression. --- ArcFormats/Ankh/ArcGRP.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ArcFormats/Ankh/ArcGRP.cs b/ArcFormats/Ankh/ArcGRP.cs index b3ac5b0c..b4bb0ed2 100644 --- a/ArcFormats/Ankh/ArcGRP.cs +++ b/ArcFormats/Ankh/ArcGRP.cs @@ -253,15 +253,16 @@ namespace GameRes.Formats.Ankh int count; if (ctl < 0x40) { - input.Read (output, dst, ctl); - dst += ctl; + count = Math.Min (ctl, output.Length - dst); + input.Read (output, dst, count); + dst += count; } else if (ctl <= 0x6F) { if (0x6F == ctl) count = input.ReadUInt16(); else - count = (ctl + 0xC3) & 0xFF; + count = ctl - 0x3D; byte v = input.ReadUInt8(); while (count --> 0) output[dst++] = v; @@ -271,7 +272,7 @@ namespace GameRes.Formats.Ankh if (ctl == 0x9F) count = input.ReadUInt16(); else - count = (ctl + 0x92) & 0xFF; + count = ctl - 0x6E; byte v1 = input.ReadUInt8(); byte v2 = input.ReadUInt8(); while (count --> 0) @@ -285,7 +286,7 @@ namespace GameRes.Formats.Ankh if (ctl == 0xBF) count = input.ReadUInt16(); else - count = ((ctl + 0x62) & 0xFF); + count = ctl - 0x9E; input.Read (output, dst, 3); if (count > 0) {