示例#1
0
        }         //end struct

        public static byte[] LoadIndexData(string indexFile)
        {
            var numArray = File.ReadAllBytes(indexFile);
            var length   = ((int)numArray.Length - 4) / 28;

            if ((int)numArray.Length < 32 || ((int)numArray.Length - 4) % 28 != 0)
            {
                return(null);
            }

            if (BitConverter.ToUInt32(numArray, 0) != length)
            {
                return(null);
            }

            if (!Regex.IsMatch(Encoding.Default.GetString(numArray, 8, 20), "^([a-zA-Z0-9_\\-\\.']+)", RegexOptions.IgnoreCase))
            {
                if (!Regex.IsMatch(PakTools.Decode_Index_FirstRecord(numArray).FileName, "^([a-zA-Z0-9_\\-\\.']+)", RegexOptions.IgnoreCase))
                {
                    return(null);
                }

                numArray = PakTools.Decode(numArray, 4);
            }

            return(numArray);
        } //end LoadIndexData
示例#2
0
        }         //end Decode

        public static PakTools.IndexRecord Decode_Index_FirstRecord(byte[] src)
        {
            var numArray = new byte[36];

            Array.Copy(src, numArray, (int)numArray.Length);
            return(new PakTools.IndexRecord(PakTools.Decode(numArray, 4), 0));
        }         //end Decode_Index_FirstRecord
示例#3
0
        } //end CreateIndexRecords

        public static IndexRecord[] RebuildPak(string pakFileName, List <PakFile> files, bool isPackFileProtected, Action <int> progressUpdate = null)
        {
            var indexFile = pakFileName.Replace(".pak", ".idx");
            var pakIndex  = PakTools.CreateIndexRecords(PakTools.LoadIndexData(indexFile), true);

            var fileStream1 = File.OpenWrite(pakFileName);

            for (var x = 0; x < files.Count; x++)
            {
                var pakFile     = files[x];
                var updatedList = new List <PakTools.IndexRecord>();

                byte[] numArray = File.ReadAllBytes(pakFile.FileName);
                numArray = PakTools.Encode(numArray, 0);

                int offset = (int)fileStream1.Seek(0L, SeekOrigin.End);
                fileStream1.Write(numArray, 0, numArray.Length);

                string filename = pakFile.FileName.Substring(pakFile.FileName.LastIndexOf('\\') + 1);

                var  newRecord = new PakTools.IndexRecord(filename, numArray.Length, offset);
                bool inserted  = false;

                for (int i = 0; i < pakIndex.Length; ++i)
                {
                    PakTools.IndexRecord oldRecord = pakIndex[i];

                    if (oldRecord.FileName.Equals(filename))
                    {
                        updatedList.Add(newRecord);
                        inserted = true;
                    } // if our filename comes before the records filename alphabetically
                    else if (!inserted && string.CompareOrdinal(filename, oldRecord.FileName) < 0)
                    {
                        updatedList.Add(newRecord);
                        updatedList.Add(oldRecord);
                        inserted = true;
                    }
                    else
                    {
                        updatedList.Add(oldRecord);
                    }
                }

                Array.Resize <PakTools.IndexRecord>(ref pakIndex, updatedList.Count);
                pakIndex = updatedList.ToArray();

                if (progressUpdate != null)
                {
                    progressUpdate.Invoke(x + 1);
                }
            }

            fileStream1.Flush();
            fileStream1.Close();
            PakTools.RebuildIndex(indexFile, pakIndex, true);

            return(pakIndex);
        } //end RebuildPak
示例#4
0
        }         //end sub_403340

        private static byte[] sub_4033B0(byte[] a1, int a2)
        {
            var numArray = PakTools.sub_403450(a1);
            var num      = a2 * 6;
            var map5     = new byte[] { (byte)(numArray[0] ^ PakTools.Map5[num]), (byte)(numArray[1] ^ PakTools.Map5[num + 1]), (byte)(numArray[2] ^ PakTools.Map5[num + 2]), (byte)(numArray[3] ^ PakTools.Map5[num + 3]), (byte)(numArray[4] ^ PakTools.Map5[num + 4]), (byte)(numArray[5] ^ PakTools.Map5[num + 5]) };

            return(PakTools.sub_4035A0(PakTools.sub_403520(map5)));
        }         //end sub_4033B0
示例#5
0
        }         //end sub_4032E0

        private static byte[] sub_403340(int a1, byte[] a2)
        {
            var numArray = new byte[4];

            Array.Copy(a2, 4, numArray, 0, 4);
            var numArray1 = PakTools.sub_4033B0(numArray, a1);
            var numArray2 = new byte[] { a2[4], a2[5], a2[6], a2[7], (byte)(numArray1[0] ^ a2[0]), (byte)(numArray1[1] ^ a2[1]), (byte)(numArray1[2] ^ a2[2]), (byte)(numArray1[3] ^ a2[3]) };

            return(numArray2);
        }         //end sub_403340
示例#6
0
        }         //end Encode

        private static byte[] sub_403160(byte[] src)
        {
            var numArray = new byte[17][];

            numArray[0] = PakTools.sub_4032E0(src, PakTools.Map1);
            var num  = 0;
            var num1 = 0;

            while (num1 <= 15)
            {
                numArray[num + 1] = PakTools.sub_403340(num1, numArray[num]);
                num1++;
                num++;
            }

            var numArray1 = new byte[] { numArray[16][4], numArray[16][5], numArray[16][6], numArray[16][7], numArray[16][0], numArray[16][1], numArray[16][2], numArray[16][3] };

            return(PakTools.sub_4032E0(numArray1, PakTools.Map2));
        }         //end sub_403160
示例#7
0
        } //end CreateIndexRecords

        public static IndexRecord[] RebuildPak(string pakFileName, List <PakFile> files, bool isPackFileProtected)
        {
            var pakIndex = PakTools.CreateIndexRecords(PakTools.LoadIndexData(pakFileName.Replace(".pak", ".idx")), true);

            var fileStream = File.OpenWrite(pakFileName);

            foreach (var pakFile in files)
            {
                var bytes = Encoding.Default.GetBytes(pakFile.Content);
                bytes = PakTools.Encode(bytes, 0);

                var num = pakFile.Id - 1;
                pakIndex[num].Offset = (int)fileStream.Seek((long)0, SeekOrigin.End);
                fileStream.Write(bytes, 0, (int)bytes.Length);
            }

            fileStream.Close();

            return(pakIndex);
        } //end RebuildPak
示例#8
0
        } //end RebuildPak

        public static void RebuildIndex(string indexFile, IndexRecord[] indexRecords, bool isPackFileProtected)
        {
            var numArray = new byte[4 + indexRecords.Length * 28];

            Array.Copy(BitConverter.GetBytes(indexRecords.Length), 0, numArray, 0, 4);

            for (var i = 0; i < indexRecords.Length; i++)
            {
                var num = 4 + i * 28;
                Array.Copy(BitConverter.GetBytes(indexRecords[i].Offset), 0, numArray, num, 4);
                Encoding.Default.GetBytes(indexRecords[i].FileName, 0, indexRecords[i].FileName.Length, numArray, num + 4);
                Array.Copy(BitConverter.GetBytes(indexRecords[i].FileSize), 0, numArray, num + 24, 4);
            }

            if (isPackFileProtected)
            {
                Array.Copy(PakTools.Encode(numArray, 4), 0, numArray, 4, (int)numArray.Length - 4);
            }

            File.WriteAllBytes(indexFile, numArray);
        } //end RebuildIndex
示例#9
0
        }         //end constructor

        private static byte[] Coder(byte[] src, int index, bool isEncode)
        {
            var numArray = new byte[(int)src.Length - index];

            if ((int)numArray.Length >= 8)
            {
                var numArray1 = new byte[8];
                var length    = (int)numArray.Length / 8;
                var num       = 0;
                while (length > 0)
                {
                    Array.Copy(src, num + index, numArray1, 0, 8);
                    if (!isEncode)
                    {
                        Array.Copy(PakTools.sub_403220(numArray1), 0, numArray, num, 8);
                    }
                    else
                    {
                        Array.Copy(PakTools.sub_403160(numArray1), 0, numArray, num, 8);
                    }

                    num = num + 8;

                    length--;
                }
            }

            var length1 = (int)numArray.Length % 8;

            if (length1 > 0)
            {
                var num1 = (int)numArray.Length - length1;
                Array.Copy(src, num1 + index, numArray, num1, length1);
            }

            return(numArray);
        }         //end Coder
示例#10
0
        }         //end Decode_Index_FirstRecord

        public static byte[] Encode(byte[] src, int index)
        {
            return(PakTools.Coder(src, index, true));
        }         //end Encode
示例#11
0
        }         //end Coder

        public static byte[] Decode(byte[] src, int index)
        {
            return(PakTools.Coder(src, index, false));
        }         //end Decode