Exemplo n.º 1
0
        public SCBlockMetadata(SCBlockAccessor accessor)
        {
            var aType = accessor.GetType();

            BlockList = aType.GetAllPropertiesOfType <SaveBlock>(accessor);
            ValueList = aType.GetAllConstantsOfType <uint>();
            Accessor  = accessor;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new instance of <see cref="SCBlockMetadata"/> by loading properties and constants declared via reflection.
        /// </summary>
        public SCBlockMetadata(SCBlockAccessor accessor, IEnumerable <string> extraKeyNames)
        {
            var aType = accessor.GetType();

            BlockList = aType.GetAllPropertiesOfType <SaveBlock>(accessor);
            ValueList = aType.GetAllConstantsOfType <uint>();
            AddExtraKeyNames(ValueList, extraKeyNames);
            Accessor = accessor;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a new instance of <see cref="SCBlockMetadata"/> by loading properties and constants declared via reflection.
        /// </summary>
        public SCBlockMetadata(SCBlockAccessor accessor, IEnumerable <string> extraKeyNames, params string[] exclusions)
        {
            var aType = accessor.GetType();

            BlockList = aType.GetAllPropertiesOfType <IDataIndirect>(accessor);
            ValueList = aType.GetAllConstantsOfType <uint>();
            AddExtraKeyNames(ValueList, extraKeyNames);
            if (exclusions.Length > 0)
            {
                ValueList = ValueList.Where(z => !exclusions.Any(z.Value.Contains)).ToDictionary(z => z.Key, z => z.Value);
            }
            Accessor = accessor;
        }
Exemplo n.º 4
0
        public SCBlockCompare(SCBlockAccessor s1, SCBlockAccessor s2)
        {
            var b1 = s1.BlockInfo;
            var b2 = s2.BlockInfo;

            KeyNames = GetKeyNames(s1, b1, b2);
            SCBlockMetadata.AddExtraKeyNames(KeyNames);

            var hs1 = new HashSet <uint>(b1.Select(z => z.Key));
            var hs2 = new HashSet <uint>(b2.Select(z => z.Key));

            LoadAddRemove(s1, s2, hs1, hs2);
            hs1.IntersectWith(hs2);
            LoadChanged(s1, s2, hs1);
        }
Exemplo n.º 5
0
        private void LoadChanged(SCBlockAccessor s1, SCBlockAccessor s2, IEnumerable <uint> shared)
        {
            foreach (var k in shared)
            {
                var x1   = s1.GetBlock(k);
                var x2   = s2.GetBlock(k);
                var name = GetKeyName(x1.Key);
                if (x1.Type != x2.Type)
                {
                    TypesChanged.Add($"{name} - {x1.Type} => {x2.Type}");
                    continue;
                }
                if (x1.Data.Length != x2.Data.Length)
                {
                    ValueChanged.Add($"{name} - Length: {x1.Data.Length} => {x2.Data.Length}");
                    continue;
                }

                if (x1.Data.Length == 0)
                {
                    continue;
                }

                if (x1.Type == SCTypeCode.Object || x1.Type == SCTypeCode.Array)
                {
                    if (!x1.Data.SequenceEqual(x2.Data))
                    {
                        ValueChanged.Add($"{name} - Bytes Changed");
                    }
                    continue;
                }

                var val1 = x1.GetValue();
                var val2 = x2.GetValue();
                if (Equals(val1, val2))
                {
                    continue;
                }
                if (val1 is ulong u1 && val2 is ulong u2)
                {
                    ValueChanged.Add($"{name} - {u1:X8} => {u2:x8}");
                }
Exemplo n.º 6
0
        private void LoadAddRemove(SCBlockAccessor s1, SCBlockAccessor s2, ICollection <uint> hs1, IEnumerable <uint> hs2)
        {
            var unique = new HashSet <uint>(hs1);

            unique.SymmetricExceptWith(hs2);
            foreach (var k in unique)
            {
                var name = GetKeyName(k);
                if (hs1.Contains(k))
                {
                    var b = s1.GetBlock(k);
                    RemovedKeys.Add($"{name} - {b.Type}");
                }
                else
                {
                    var b = s2.GetBlock(k);
                    AddedKeys.Add($"{name} - {b.Type}");
                }
            }
        }
Exemplo n.º 7
0
        public SCBlockCompare(SCBlockAccessor s1, SCBlockAccessor s2)
        {
            var b1    = s1.BlockInfo;
            var b2    = s2.BlockInfo;
            var names = GetKeyNames(s1, b1, b2);

            string GetKeyName(uint key) => names.TryGetValue(key, out var val) ? val : $"{key:X8}";

            var hs1 = new HashSet <uint>(b1.Select(z => z.Key));
            var hs2 = new HashSet <uint>(b2.Select(z => z.Key));

            var unique = new HashSet <uint>(hs1);

            unique.SymmetricExceptWith(hs2);
            foreach (var k in unique)
            {
                var name = GetKeyName(k);
                if (hs1.Contains(k))
                {
                    var b = s1.GetBlock(k);
                    RemovedKeys.Add($"{name} - {b.Type}");
                }
                else
                {
                    var b = s2.GetBlock(k);
                    AddedKeys.Add($"{name} - {b.Type}");
                }
            }

            hs1.IntersectWith(hs2);
            foreach (var k in hs1)
            {
                var x1   = s1.GetBlock(k);
                var x2   = s2.GetBlock(k);
                var name = GetKeyName(x1.Key);
                if (x1.Type != x2.Type)
                {
                    TypesChanged.Add($"{name} - {x1.Type} => {x2.Type}");
                    continue;
                }
                if (x1.Data.Length != x2.Data.Length)
                {
                    ValueChanged.Add($"{name} - Length: {x1.Data.Length} => {x2.Data.Length}");
                    continue;
                }

                if (x1.Data.Length == 0)
                {
                    continue;
                }

                if (x1.Type == SCTypeCode.Object || x1.Type == SCTypeCode.Array)
                {
                    if (!x1.Data.SequenceEqual(x2.Data))
                    {
                        ValueChanged.Add($"{name} - Bytes Changed");
                    }
                    continue;
                }

                var val1 = x1.GetValue();
                var val2 = x2.GetValue();
                if (Equals(val1, val2))
                {
                    continue;
                }
                if (val1 is ulong u1 && val2 is ulong u2)
                {
                    ValueChanged.Add($"{name} - {u1:X8} => {u2:x8}");
                }