LSLib.LS.LSBReader.Read C# (CSharp) Method

Read() public method

public Read ( ) : Resource
return Resource
        public Resource Read()
        {
            using (this.reader = new BinaryReader(stream))
            {
                LSBHeader header;
                header.signature = reader.ReadUInt32();
                if (header.signature != LSBHeader.Signature)
                    throw new InvalidFormatException(String.Format("Illegal signature in header; expected {0}, got {1}", LSBHeader.Signature, header.signature));

                header.totalSize = reader.ReadUInt32();
                if (stream.Length != header.totalSize)
                    throw new InvalidFormatException(String.Format("Invalid LSB file size; expected {0}, got {1}", header.totalSize, stream.Length));

                header.bigEndian = reader.ReadUInt32();
                // The game only uses little-endian files on all platforms currently and big-endian support isn't worth the hassle
                if (header.bigEndian != 0)
                    throw new InvalidFormatException("Big-endian LSB files are not supported");

                header.unknown = reader.ReadUInt32();
                header.metadata.timestamp = reader.ReadUInt64();
                header.metadata.majorVersion = reader.ReadUInt32();
                header.metadata.minorVersion = reader.ReadUInt32();
                header.metadata.revision = reader.ReadUInt32();
                header.metadata.buildNumber = reader.ReadUInt32();

                ReadStaticStrings();

                Resource rsrc = new Resource();
                rsrc.Metadata = header.metadata;
                ReadRegions(rsrc);
                return rsrc;
            }
        }

Usage Example

Example #1
0
        public static Resource LoadResource(string inputPath, ResourceFormat format)
        {
            var file = new FileStream(inputPath, FileMode.Open, FileAccess.Read);

            switch (format)
            {
            case ResourceFormat.LSX:
            {
                using (var reader = new LSXReader(file))
                {
                    return(reader.Read());
                }
            }

            case ResourceFormat.LSB:
            {
                using (var reader = new LSBReader(file))
                {
                    return(reader.Read());
                }
            }

            case ResourceFormat.LSF:
            {
                using (var reader = new LSFReader(file))
                {
                    return(reader.Read());
                }
            }

            default:
                throw new ArgumentException("Invalid resource format");
            }
        }
All Usage Examples Of LSLib.LS.LSBReader::Read