示例#1
0
        public static PAK Load(string path)
        {
            FileInfo fi = new FileInfo(path);
            Logger.LogToFile(Logger.LogLevel.Info, "{0}", path);
            PAK pak = new PAK();

            pak.name = Path.GetFileNameWithoutExtension(path);
            pak.location = Path.GetDirectoryName(path) + "\\";

            char[] filename = new char[255];
            bool[] rollback = new bool[255];
            byte code = 0;
            int i = 0;
            string sBase = "";

            using (BinaryReader brDir = new BinaryReader(fi.OpenRead()))
            {
                i = 0;

                while (brDir.BaseStream.Position < brDir.BaseStream.Length)
                {
                    do
                    {
                        filename[i] = (char)brDir.ReadByte();
                        code = brDir.ReadByte();

                        if (code == 136) { sBase = new string(filename, 0, i); }
                        if (code == 192) { rollback[i] = true; }

                        i++;
                    }
                    while ((code & 8) != 8);

                    var entry = new PAKEntry();
                    entry.Name = new string(filename, 0, i);
                    entry.Offset = (int)brDir.ReadUInt32();
                    entry.Size = (int)brDir.ReadUInt32();
                    pak.contents.Add(entry);

                    switch (code)
                    {
                        case 72:
                            // do nothing
                            break;

                        case 136:
                            i = sBase.Length;
                            break;

                        case 200:
                            rollback[i - 1] = true;
                            break;

                        default:
                            i = Array.LastIndexOf(rollback, true);
                            if (i > -1) { rollback[i] = false; }
                            break;
                    }
                }
            }

            return pak;
        }
示例#2
0
文件: tdrPAK.cs 项目: q4a/ToxicRagers
        public static PAK Load(string path)
        {
            FileInfo fi = new FileInfo(path);
            Logger.LogToFile(Logger.LogLevel.Info, "{0}", path);
            PAK pak = new PAK()
            {
                name = Path.GetFileNameWithoutExtension(path),
                location = Path.GetDirectoryName(path) + "\\"
            };

            char[] filename = new char[255];
            bool[] rollback = new bool[255];
            byte code = 0;
            int i = 0;
            string sBase = "";

            using (BinaryReader brDir = new BinaryReader(fi.OpenRead()))
            {
                i = 0;

                while (brDir.BaseStream.Position < brDir.BaseStream.Length)
                {
                    do
                    {
                        filename[i] = (char)brDir.ReadByte();
                        code = brDir.ReadByte();

                        if (code == 136) { sBase = new string(filename, 0, i); }
                        if (code == 192) { rollback[i] = true; }

                        i++;
                    }
                    while ((code & 8) != 8);

                    PAKEntry entry = new PAKEntry()
                    {
                        Name = new string(filename, 0, i),
                        Offset = (int)brDir.ReadUInt32(),
                        Size = (int)brDir.ReadUInt32()
                    };
                    pak.contents.Add(entry);

                    switch (code)
                    {
                        case 72:
                            // do nothing
                            break;

                        case 136:
                            i = sBase.Length;
                            break;

                        case 200:
                            rollback[i - 1] = true;
                            break;

                        default:
                            i = Array.LastIndexOf(rollback, true);
                            if (i > -1) { rollback[i] = false; }
                            break;
                    }
                }
            }

            return pak;
        }