Alexandria.Engines.Sciagi.ResourceMap.DetectVersionSci2 C# (CSharp) Метод

DetectVersionSci2() статический приватный Метод

static private DetectVersionSci2 ( AssetLoader loader ) : bool
loader Glare.Assets.AssetLoader
Результат bool
        static bool DetectVersionSci2(AssetLoader loader)
        {
            BinaryReader reader = loader.Reader;
            long length = loader.Length;
            int firstOffset = -1, lastOffset = 3;

            // The resource map starts with the list of types and their offsets in the resource map.
            while (true) {
                // The resource map must contain resources.
                if (loader.Remaining < 7)
                    return false;

                ResourceType type = (ResourceType)reader.ReadByte();
                int offset = reader.ReadUInt16();

                if (firstOffset < 0)
                    firstOffset = offset;

                // Ensure that the offsets are increasing.
                if (offset < lastOffset)
                    return false;
                lastOffset = offset;

                // Naturally break if this is the end.
                if (type == ResourceType.End)
                    break;
            }

            reader.ReadInt32(); // Unknown value

            // Check that the first resource identifier is right after the type table and some unknown data.
            if (loader.Position != firstOffset)
                return false;

            // Check that the terminator type's offset is at the end.
            if (lastOffset != loader.Length)
                return false;

            // The type table is okay, so we assume this is the right type.
            return true;
        }