(PACKDAT): decrypt scripts.

This commit is contained in:
morkt 2018-01-29 03:36:30 +04:00
parent a4ba1ecdd5
commit b4e1e41c93

View File

@ -80,11 +80,12 @@ namespace GameRes.Formats.SystemEpsylon
public override Stream OpenEntry (ArcFile arc, Entry entry)
{
var pentry = entry as PackDatEntry;
if (null == pentry || entry.Size < 4 || 0 == (pentry.Flags & 0x10000))
if (null == pentry || entry.Size < 4
|| !(0 != (pentry.Flags & 0x10000) || entry.Name.HasExtension (".s")))
return arc.File.CreateStream (entry.Offset, entry.Size);
var input = arc.File.View.ReadBytes (entry.Offset, pentry.Size);
if (input.Length == pentry.Size)
if (0 != (pentry.Flags & 0x10000))
{
unsafe
{
@ -92,7 +93,7 @@ namespace GameRes.Formats.SystemEpsylon
{
uint* encoded = (uint*)buf_raw;
uint key = pentry.Size >> 2;
key = (key << (((int)key & 7) + 8)) ^ key;
key ^= key << (((int)key & 7) + 8);
for (uint i = entry.Size / 4; i != 0; --i )
{
*encoded ^= key;
@ -102,6 +103,11 @@ namespace GameRes.Formats.SystemEpsylon
}
}
}
if (entry.Name.HasExtension (".s"))
{
for (int i = 0; i < input.Length; ++i)
input[i] ^= 0xFF;
}
return new BinMemoryStream (input, entry.Name);
}
}