Пример #1
0
        public byte[] GetFileArray(string file)
        {
            if (!toc.ContainsKey(file))
            {
                return(null);
            }
            HGFile f = toc[file];

            stream.Position = f.offset;
            byte[] array = new byte[f.length];
            stream.Read(array, 0, array.Length);
            Encode(array, array.Length, f.key);
            return(array);
        }
Пример #2
0
        private void Init()
        {
            toc             = new Dictionary <string, HGFile>();
            stream.Position = 0L;
            byte[] array = new byte[1024];
            stream.Read(array, 0, 1024);
            int fileCount = 0;

            for (int i = 0; i < 256; i++)
            {
                fileCount += BitConverter.ToInt32(array, i * 4);
            }
            byte[] head0 = new byte[16 * fileCount];
            stream.Read(head0, 0, head0.Length);
            Encode(head0, 16 * fileCount, BitConverter.ToUInt32(array, 212));
            int tableBaseLength = BitConverter.ToInt32(head0, 4);
            int strTableLength  = tableBaseLength - (1024 + 16 * fileCount);

            byte[] strTableBuffer = new byte[strTableLength];
            stream.Read(strTableBuffer, 0, strTableBuffer.Length);
            Encode(strTableBuffer, strTableLength, BitConverter.ToUInt32(array, 92));
            int strOff = 0;

            for (int j = 0; j < fileCount; j++)
            {
                int  fileOff = 16 * j;
                int  nameOff = BitConverter.ToInt32(head0, fileOff);
                uint offset  = BitConverter.ToUInt32(head0, fileOff + 0x4);
                uint length  = BitConverter.ToUInt32(head0, fileOff + 0x8);
                uint key     = BitConverter.ToUInt32(head0, fileOff + 0xC);
                int  strEnd;
                for (strEnd = nameOff; strEnd < strTableBuffer.Length && strTableBuffer[strEnd] != 0; strEnd++)
                {
                }
                string @string = Encoding.ASCII.GetString(strTableBuffer, strOff, strEnd - strOff);
                HGFile value   = default;
                value.offset = offset;
                value.length = length;
                value.key    = key;
                toc.Add(@string, value);
                strOff = strEnd + 1;
            }
        }