Alexandria.Engines.UltimaUnderworld.GraphicArchiveFormat.LoadMatch C# (CSharp) Method

LoadMatch() public method

public LoadMatch ( AssetLoader loader ) : LoadMatchStrength
loader Glare.Assets.AssetLoader
return LoadMatchStrength
        public override LoadMatchStrength LoadMatch(AssetLoader loader)
        {
            BinaryReader reader = loader.Reader;
            long length = loader.Length;

            if (length < 5)
                return LoadMatchStrength.None;

            byte forceSizeCode = reader.ReadByte();
            int forceSize = 0;

            if (forceSizeCode == 2)
                forceSize = reader.ReadByte();
            else if (forceSizeCode != 1)
                return LoadMatchStrength.None;

            int count = reader.ReadUInt16();
            long first = loader.Position + (count + 1) * 4;
            if (length < first || count < 2)
                return LoadMatchStrength.None;

            long last = 0;

            for (int index = 0; index <= count; index++) {
                int offset = reader.ReadInt32();

                if (index == 0) {
                    if (offset != first)
                        return LoadMatchStrength.None;
                } else if (offset <= last)
                    return LoadMatchStrength.None;

                last = offset;
            }

            if (last != length)
                return LoadMatchStrength.None;

            // This is a pretty weak header match, so don't overdo it.
            return LoadMatchStrength.Medium;
        }