Ejemplo n.º 1
0
 internal static LbxInfo Load(string filename)
 {
     using (var stream = new MemoryStream(File.ReadAllBytes(filename)))
     {
         return(LbxInfo.Read(stream));
     }
 }
Ejemplo n.º 2
0
        public void Execute()
        {
            System.Console.WriteLine($"Reading {this.args[0]} archive...");
            LbxInfo info = LbxInfo.Load(this.args[0]);

            System.Console.WriteLine($"Archive contains {info.FileCount} files:");
            foreach (var item in info.ContentInfo)
            {
                System.Console.WriteLine($"\t[+{item.Offset}, {item.Data.Length}] Name:{item.Name}, Description:{item.Description}");
            }

            System.Console.WriteLine($"LBX file end offset is set to: {info.EndOffset}");
        }
Ejemplo n.º 3
0
        private static List <uint> ReadOffsets(LbxInfo result, BinaryReader reader)
        {
            var offsets = new List <uint>();

            for (int i = 0; i < result.FileCount; i++)
            {
                offsets.Add(reader.ReadUInt32());
            }

            result.EndOffset = reader.ReadUInt32();
            offsets.Add(result.EndOffset);
            return(offsets);
        }
Ejemplo n.º 4
0
        public void Execute()
        {
            var info = LbxInfo.Load(this.commandArgs[0]);

            for (int i = 0; i < info.FileCount; i++)
            {
                var ci = info.ContentInfo[i];

                var dir = this.GetDirName(ci);
                this.EnsureDirExistance(dir);
                string path = CreatePath(dir, i, ci);

                ci.WriteData(path);
            }
        }
Ejemplo n.º 5
0
        internal static LbxInfo Read(MemoryStream stream)
        {
            var result = new LbxInfo();

            using (var reader = new BinaryReader(stream, Encoding.Default, true))
            {
                result.FileCount   = reader.ReadUInt16();
                result.MagicString = reader.ReadBytes(4);
                result.UnusedValue = reader.ReadUInt16();
                List <uint> offsets = ReadOffsets(result, reader);

                var       firstFileOffset      = offsets[0];
                const int fileNamesStartOffset = 512;
                for (int i = 0; i < result.FileCount; i++)
                {
                    var    contentLength = (int)(offsets[i + 1] - offsets[i]);
                    var    recordStartOffset = fileNamesStartOffset + (i * 32);
                    var    recordEndOffset = fileNamesStartOffset + ((i + 1) * 32);
                    string fName, fDesc;

                    stream.Seek(recordStartOffset, SeekOrigin.Begin);
                    if (recordEndOffset < firstFileOffset)
                    {
                        fName = reader.ReadNullTerminatedFixedString(9);
                        fDesc = reader.ReadNullTerminatedFixedString(23);
                    }
                    else
                    {
                        fName = $"Unnamed_{i}";
                        fDesc = $"Description_{i}";
                    }

                    stream.Seek(offsets[i], SeekOrigin.Begin);
                    var bytes = new byte[contentLength];
                    stream.Read(bytes, 0, contentLength);

                    result.ContentInfo.Add(new ArchiveContent(offsets[i], fName, fDesc, bytes));
                }
            }

            return(result);
        }