Exemple #1
0
        public async Task Hash64_StreamAsync_ReturnsExpectedValuesAsync(FnvTestVector data)
        {
            using var stream = new MemoryStream(data.Buffer);
            ulong result = await Fnv1a.Hash64Async(stream);

            Assert.That(result, Is.EqualTo(data.ExpectedResult64));
        }
Exemple #2
0
        private void ReadField(SQEX.Luminous.Core.Object.BaseObject obj, Xmb2Element parentElement, uint hashedParentName, BaseObject objOffset)
        {
            if (objOffset != null)
            {
                obj = objOffset;
            }

            foreach (var element in parentElement.GetElements())
            {
                var name       = element.Name;
                var hashedName = Fnv1a.Fnv1a32(name, hashedParentName);
                var type       = obj.GetObjectType();
                if (type == null)
                {
                    continue;
                }

                var property = type.PropertyContainer.FindByName(name);
                if (property == null)
                {
                    continue;
                }

                this.ReadValue(obj, parentElement, element, property, hashedName, objOffset);
            }
        }
Exemple #3
0
        public void Hash64_Stream_ReturnsExpectedValues(FnvTestVector data)
        {
            using var stream = new MemoryStream(data.Buffer);
            ulong result = Fnv1a.Hash64(stream);

            Assert.That(result, Is.EqualTo(data.ExpectedResult64));
        }
Exemple #4
0
        public async Task Hash32_StreamAsync_ReturnsExpectedValuesAsync(FnvTestVector data)
        {
            using var stream = new MemoryStream(data.Buffer);
            uint result = await Fnv1a.Hash32Async(stream);

            Assert.AreEqual(data.ExpectedResult32, result);
        }
Exemple #5
0
        private static uint GetFnvHashValue(string word)
        {
            var  encodedWord = Encoding.ASCII.GetBytes(word);
            uint hashResult  = Fnv1a.Hash32(encodedWord);

            return(hashResult);
        }
Exemple #6
0
        public void Hash32_Stream_ReturnsExpectedValues(FnvTestVector data)
        {
            using var stream = new MemoryStream(data.Buffer);
            uint result = Fnv1a.Hash32(stream);

            Assert.AreEqual(data.ExpectedResult32, result);
        }
Exemple #7
0
        private void ReadValue(Luminous.Core.Object.BaseObject obj, Xmb2Element parentObject, Xmb2Element element, Property property, uint hashedName, BaseObject objOffset)
        {
            object value = null;

            switch (property.Type)
            {
            case Property.PrimitiveType.ClassField:
                this.ReadField(obj, element, Fnv1a.Fnv1a32(".", hashedName), obj.GetPropertyValue <BaseObject>(property));
                break;

            case Property.PrimitiveType.Int8:
            case Property.PrimitiveType.Int16:
            case Property.PrimitiveType.Int32:
            case Property.PrimitiveType.Int64:
            case Property.PrimitiveType.UInt8:
            case Property.PrimitiveType.UInt16:
            case Property.PrimitiveType.UInt32:
            case Property.PrimitiveType.UInt64:
            case Property.PrimitiveType.INVALID2:
            case Property.PrimitiveType.Bool:
            case Property.PrimitiveType.Float:
            case Property.PrimitiveType.Double:
            case Property.PrimitiveType.String:
            case Property.PrimitiveType.Fixid:
            case Property.PrimitiveType.Vector4:
            case Property.PrimitiveType.Color:
            case Property.PrimitiveType.Enum:
                value = this.ReadPrimitiveValue(element, property);
                break;

            case Property.PrimitiveType.Pointer:
                if (this.ResolvePointer(parentObject, element, out value))
                {
                    // TODO addPointerListReferedBySequenceIfMatchCondition
                }

                break;

            case Property.PrimitiveType.PointerArray:
            case Property.PrimitiveType.IntrusivePointerArray:
                // GOTCHA: We don't want to create a new List, because other objects can reference the list before it's instantiated
                value = obj.GetPropertyValue <IList>(property);
                this.ReadPointerArray(obj, element, value as IList);
                break;

            default:
                if (property.Type != Property.PrimitiveType.Array)
                {
                    throw new ArgumentException($"[EntityPackageXmlLoader]Unknown type {property.Type} for {property.Name}");
                }

                break;
            }

            if (value != null)
            {
                obj.SetPropertyValue(property, value);
            }
        }
Exemple #8
0
 public void Hash64_Stream_ReturnsExpectedValues(FnvTestVector data)
 {
     using (var stream = new MemoryStream(data.Buffer))
     {
         ulong result = Fnv1a.Hash64(stream);
         Assert.AreEqual(data.ExpectedResult64, result);
     }
 }
Exemple #9
0
        public async Task Hash64_StreamAsync_ReturnsExpectedValuesAsync(FnvTestVector data)
        {
            using (var stream = new MemoryStream(data.Buffer))
            {
                ulong result = await Fnv1a.Hash64Async(stream);

                Assert.AreEqual(data.ExpectedResult64, result);
            }
        }
Exemple #10
0
        public MetaPropertyAttribute(string name, BinPropertyType type, string otherClass, BinPropertyType primaryType, BinPropertyType secondaryType)
        {
            this.Name     = name;
            this.NameHash = Fnv1a.HashLower(name);

            this.OtherClass = otherClass;

            this.ValueType     = type;
            this.PrimaryType   = primaryType;
            this.SecondaryType = secondaryType;
        }
Exemple #11
0
        private static Dictionary <uint, string> ParseBinHashtable(string filePath)
        {
            Dictionary <uint, string> map = new Dictionary <uint, string>();

            foreach (string line in File.ReadAllLines(filePath))
            {
                string hashString = line.Split(" ")[1];
                uint   hash       = Fnv1a.HashLower(hashString);

                if (map.ContainsKey(hash) is false)
                {
                    map.Add(hash, hashString);
                }
            }

            return(map);
        }
Exemple #12
0
        public void WriteMetaClasses(Stream stream, ICollection <string> classNames, ICollection <string> propertyNames)
        {
            // Create dictionaries from collections
            Dictionary <uint, string> classNameMap    = new(classNames.Count);
            Dictionary <uint, string> propertyNameMap = new(propertyNames.Count);

            foreach (string className in classNames)
            {
                classNameMap.Add(Fnv1a.HashLower(className), className);
            }

            foreach (string propertyName in propertyNames)
            {
                propertyNameMap.Add(Fnv1a.HashLower(propertyName), propertyName);
            }

            WriteMetaClasses(stream, classNameMap, propertyNameMap);
        }
Exemple #13
0
        private void ReadDynamicBaseObjectChildElement(BaseObject parentObject, BaseObject baseObject, Xmb2Element childElement)
        {
            foreach (var element in childElement.GetElements())
            {
                var name       = element.Name;
                var hashedName = Fnv1a.Fnv1a32(name, 2166136261); // ???
                var type       = baseObject.GetObjectType();
                if (type == null)
                {
                    continue;
                }

                var property = type.PropertyContainer.FindByName(name);
                if (property == null)
                {
                    continue;
                }

                this.ReadValue(baseObject, childElement, element, property, hashedName, baseObject);
            }
        }
Exemple #14
0
 public void Hash64_NullBuffer_ThrowsArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() => Fnv1a.Hash64(null));
 }
Exemple #15
0
        public void Hash32_ReturnsExpectedValues(FnvTestVector data)
        {
            uint result = Fnv1a.Hash32(data.Buffer);

            Assert.AreEqual(data.ExpectedResult32, result);
        }
Exemple #16
0
 public uint ComputePicHash()
 {
     PictureHash = Fnv1a.Hash32(PictureData);
     return(PictureHash);
 }
Exemple #17
0
        /// <summary>
        /// Read the attribute element with a given name.
        /// </summary>
        /// <param name="name">The name of the attribute to get.</param>
        /// <returns>The parsed attribute.</returns>
        public Xmb2Variant GetAttributeByName(string name)
        {
            var nameHash = Fnv1a.Fnv1a32(name);

            return(this.GetAttributeByName(nameHash));
        }
Exemple #18
0
 public override int GetHashCode()
 {
     return((int)Fnv1a.Hash32(Utils.Latin1Encoding.GetBytes(ToString())));
 }
Exemple #19
0
        public void Hash64_ReturnsExpectedValues(FnvTestVector data)
        {
            ulong result = Fnv1a.Hash64(data.Buffer);

            Assert.AreEqual(data.ExpectedResult64, result);
        }
Exemple #20
0
 public static BinTreeObject Serialize <T>(MetaEnvironment environment, string path, T metaClass)
     where T : IMetaClass
 {
     return(Serialize(environment, Fnv1a.HashLower(path), metaClass));
 }
Exemple #21
0
        public void Hash64_ReturnsExpectedValues(FnvTestVector data)
        {
            ulong result = Fnv1a.Hash64(data.Buffer);

            Assert.That(result, Is.EqualTo(data.ExpectedResult64));
        }
Exemple #22
0
 public MetaPropertyAttribute(string name, BinPropertyType type)
 {
     this.Name      = name;
     this.NameHash  = Fnv1a.HashLower(name);
     this.ValueType = type;
 }
Exemple #23
0
 public MetaHash(string value)
 {
     this.Hash  = Fnv1a.HashLower(value);
     this.Value = value;
 }
Exemple #24
0
        public void Hash32_ReturnsExpectedValues(FnvTestVector data)
        {
            uint result = Fnv1a.Hash32(data.Buffer);

            Assert.That(result, Is.EqualTo(data.ExpectedResult32));
        }