Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MDXRibbonEmitter"/> class.
        /// </summary>
        /// <param name="br">The reader to read the instance from.</param>
        /// <param name="version">The version to read the instance in the context of.</param>
        public MDXRibbonEmitter(BinaryReader br, WarcraftVersion version)
        {
            RibbonID         = br.ReadUInt32();
            BoneIndex        = br.ReadUInt32();
            RelativePosition = br.ReadVector3();

            Textures  = br.ReadMDXArray <ushort>();
            Materials = br.ReadMDXArray <ushort>();

            Colour      = br.ReadMDXTrack <RGB>(version);
            Alpha       = br.ReadMDXTrack <short>(version);
            HeightAbove = br.ReadMDXTrack <float>(version);
            HeightBelow = br.ReadMDXTrack <float>(version);

            EdgesPerSecond = br.ReadSingle();
            EdgeLifetime   = br.ReadSingle();
            Gravity        = br.ReadSingle();

            TextureTileX = br.ReadUInt16();
            TextureTileY = br.ReadUInt16();

            TextureSlot = br.ReadMDXTrack <ushort>(version);
            Visibility  = br.ReadMDXTrack <bool>(version);

            if (version < WarcraftVersion.Wrath)
            {
                return;
            }

            PriorityPlane = br.ReadInt16();
            Unknown       = br.ReadInt16();
        }
        /// <summary>
        /// Gets the number of fields expected to be in a reference by version. This is equal to LanguageCount + 1,
        /// that is, including the flag field.
        /// </summary>
        /// <param name="version"></param>
        /// <returns></returns>
        public static int GetFieldCount(WarcraftVersion version)
        {
            if (version >= WarcraftVersion.Cataclysm)
            {
                return(1);
            }

            switch (version)
            {
            case WarcraftVersion.Wrath:
            case WarcraftVersion.BurningCrusade:
            {
                return(17);
            }

            case WarcraftVersion.Classic:
            {
                return(9);
            }

            default:
            {
                throw new ArgumentOutOfRangeException(nameof(version));
            }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MDXCamera"/> class.
        /// </summary>
        /// <param name="br">The reader to read the instance from.</param>
        /// <param name="version">The version to read the instance in the context of.</param>
        public MDXCamera(BinaryReader br, WarcraftVersion version)
        {
            TypeLookupIndex = br.ReadUInt32();

            if (version < WarcraftVersion.Cataclysm)
            {
                FieldOfView = br.ReadSingle();
            }

            FarClip  = br.ReadSingle();
            NearClip = br.ReadSingle();

            Positions    = br.ReadMDXTrack <SplineKey <Vector3> >(version);
            PositionBase = br.ReadVector3();

            TargetPositions    = br.ReadMDXTrack <SplineKey <Vector3> >(version);
            TargetPositionBase = br.ReadVector3();

            Roll = br.ReadMDXTrack <SplineKey <float> >(version);

            if (version >= WarcraftVersion.Cataclysm)
            {
                AnimatedFOV = br.ReadMDXTrack <SplineKey <float> >(version);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Handles the add path button clicked event.
        /// </summary>
        /// <param name="sender">The sending object.</param>
        /// <param name="eventArgs">The event arguments.</param>
        private void OnAddPathButtonClicked(object sender, EventArgs eventArgs)
        {
            Uri defaultLocation = new Uri(Environment.GetFolderPath(Environment.SpecialFolder.Desktop));

            this.PathChooser.SetCurrentFolderUri(defaultLocation.ToString());

            switch ((ResponseType)this.NewGamePathDialog.Run())
            {
            case ResponseType.Ok:
            {
                string          alias           = this.AliasEntry.Text;
                WarcraftVersion selectedVersion = (WarcraftVersion)this.GameVersionCombo.Active;
                Uri             uriToStore      = new Uri(this.PathChooser.CurrentFolderUri);

                if (Directory.Exists(uriToStore.LocalPath))
                {
                    this.GamePathListStore.AppendValues(alias, uriToStore.LocalPath, (uint)selectedVersion, selectedVersion.ToString());
                    this.DidGameListChange = true;
                }

                this.NewGamePathDialog.Hide();
                break;
            }

            default:
            {
                this.NewGamePathDialog.Hide();
                break;
            }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Removes a path that's been stored.
        /// </summary>
        /// <param name="alias">The alias of the path.</param>
        /// <param name="version">The game version of the path.</param>
        /// <param name="pathToRemove">Path to remove.</param>
        public void RemoveStoredPath(string alias, WarcraftVersion version, string pathToRemove)
        {
            var storedPaths = this.GamePaths;

            if (storedPaths.Contains((alias, version, pathToRemove)))
            {
                ClearPaths();
                lock (_storageLock)
                {
                    storedPaths.Remove((alias, version, pathToRemove));

                    using (var fs = File.Open(GetPathStoragePath(), FileMode.Append, FileAccess.Write))
                    {
                        using (var bw = new BinaryWriter(fs))
                        {
                            foreach ((var remainingAlias, var remainingVersion, var remainingPath) in storedPaths)
                            {
                                bw.WriteNullTerminatedString(remainingAlias);
                                bw.Write((uint)remainingVersion);
                                bw.WriteNullTerminatedString(remainingPath);
                                bw.Flush();
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Deserializes an <see cref="MDXAnimationSequence"/> from a given data stream.
        /// </summary>
        /// <param name="br"></param>
        /// <param name="version"></param>
        public MDXAnimationSequence(BinaryReader br, WarcraftVersion version)
        {
            AnimationID = br.ReadUInt32();

            if (version <= WarcraftVersion.BurningCrusade)
            {
                StartTimestamp = br.ReadUInt32();
                EndTimestamp   = br.ReadUInt32();
            }
            else
            {
                Duration = br.ReadUInt32();
            }

            MovementSpeed = br.ReadSingle();
            Flags         = (MDXAnimationSequenceFlags)br.ReadUInt32();
            Probability   = br.ReadInt16();
            Padding       = br.ReadUInt16();
            ReplayRange   = br.ReadIntegerRange();

            BlendTime              = br.ReadUInt32();
            BoundingBox            = br.ReadBox();
            BoundingSphereRadius   = br.ReadSingle();
            NextVariation          = br.ReadInt16();
            NextAliasedAnimationID = br.ReadUInt16();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets the record field properties that are relevant for the given version, that is, those that exist in the
        /// given version. No order is guaranteed.
        /// </summary>
        /// <param name="version">The version which the property should be relevant for.</param>
        /// <param name="recordType">The type where the properties are.</param>
        /// <returns>An ordered set of properties.</returns>
        public static IEnumerable <PropertyInfo> GetVersionRelevantProperties(WarcraftVersion version, Type recordType)
        {
            foreach (var recordProperty in GetRecordProperties(recordType))
            {
                RecordFieldAttribute versionAttribute;
                if (IsPropertyFieldArray(recordProperty))
                {
                    versionAttribute = GetVersionRelevantPropertyFieldArrayAttribute(version, recordProperty);

                    if (versionAttribute == null)
                    {
                        // There was no property defined for the version.
                        continue;
                    }
                }
                else
                {
                    versionAttribute = GetPropertyFieldAttribute(recordProperty);
                }

                if (!IsPropertyRelevantForVersion(version, versionAttribute))
                {
                    continue;
                }

                yield return(recordProperty);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DBC"/> class.
        /// </summary>
        /// <param name="inVersion">In version.</param>
        /// <param name="data">ExtendedData.</param>
        public DBC(WarcraftVersion inVersion, byte[] data)
        {
            this.Version          = inVersion;
            this.DatabaseContents = data;

            using (BinaryReader databaseReader = new BinaryReader(new MemoryStream(this.DatabaseContents)))
            {
                this.Header = new DBCHeader(databaseReader.ReadBytes(DBCHeader.GetSize()));

                // Seek to and read the string block
                databaseReader.BaseStream.Seek(this.Header.RecordCount * this.Header.RecordSize, SeekOrigin.Current);
                this.StringBlockOffset = databaseReader.BaseStream.Position;
                while (databaseReader.BaseStream.Position != databaseReader.BaseStream.Length)
                {
                    this.Strings.Add(databaseReader.BaseStream.Position - this.StringBlockOffset, databaseReader.ReadNullTerminatedString());
                }
            }

            this.Records = new List <T>(this.Count);

            // Initialize the record list with null values
            for (int i = 0; i < this.Count; ++i)
            {
                this.Records.Add(null);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DBC{TRecord}"/> class.
        /// </summary>
        /// <param name="inVersion">In version.</param>
        /// <param name="data">ExtendedData.</param>
        public DBC(WarcraftVersion inVersion, byte[] data)
        {
            Version           = inVersion;
            _databaseContents = data;

            using (var databaseReader = new BinaryReader(new MemoryStream(_databaseContents)))
            {
                _header = new DBCHeader(databaseReader.ReadBytes(DBCHeader.GetSize()));

                // Seek to and read the string block
                databaseReader.BaseStream.Seek(_header.RecordCount * _header.RecordSize, SeekOrigin.Current);
                _stringBlockOffset = databaseReader.BaseStream.Position;
                while (databaseReader.BaseStream.Position != databaseReader.BaseStream.Length)
                {
                    Strings.Add(databaseReader.BaseStream.Position - _stringBlockOffset, databaseReader.ReadNullTerminatedString());
                }
            }

            _records = new List <TRecord?>(Count);

            // Initialize the record list with null values
            for (var i = 0; i < Count; ++i)
            {
                _records.Add(null);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Deserializes the values of a DBC record.
        /// </summary>
        /// <param name="reader">The <see cref="BinaryReader"/> containing the data of the record.</param>
        /// <param name="record">An instance of the record class.</param>
        /// <param name="version">The version of the record to deserialize.</param>
        /// <typeparam name="T">The type of record to deserialize.</typeparam>
        /// <exception cref="ArgumentException">Thrown if the record contains field properties without setters.</exception>
        public static void DeserializeRecord <T>(BinaryReader reader, T record, WarcraftVersion version)
        {
            var reflectionInfo = RecordInformationCache.Instance.GetRecordInformation(typeof(T), version);

            foreach (var databaseProperty in reflectionInfo.VersionRelevantProperties)
            {
                object propertyValue;
                if (reflectionInfo.IsPropertyFieldArray(databaseProperty))
                {
                    var elementType    = reflectionInfo.PropertyFieldArrayElementTypes[databaseProperty];
                    var arrayAttribute = reflectionInfo.PropertyFieldArrayAttributes[databaseProperty];

                    List <object> values = new List <object>();
                    for (int i = 0; i < arrayAttribute.Count; ++i)
                    {
                        values.Add(ReadPropertyValue(reader, reflectionInfo, databaseProperty, elementType, version));
                    }

                    propertyValue = GetAssignableCollectionObject(values, databaseProperty.PropertyType, elementType);
                }
                else
                {
                    propertyValue = ReadPropertyValue(reader, reflectionInfo, databaseProperty, databaseProperty.PropertyType, version);
                }

                databaseProperty.SetValue(record, propertyValue);
            }
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MDXAttachment"/> class.
 /// </summary>
 /// <param name="br">The reader to read the instance from.</param>
 /// <param name="version">The version to read the instance in the context of.</param>
 public MDXAttachment(BinaryReader br, WarcraftVersion version)
 {
     AttachmentIDLookupIndex = br.ReadUInt32();
     Bone            = br.ReadUInt16();
     Unknown         = br.ReadUInt16();
     Position        = br.ReadVector3();
     AnimateAttached = br.ReadMDXTrack <bool>(version);
 }
Ejemplo n.º 12
0
 public MDXAnimationEvent(BinaryReader br, WarcraftVersion version)
 {
     this.EventName        = new string(br.ReadChars(4));
     this.Data             = br.ReadUInt32();
     this.Bone             = br.ReadUInt32();
     this.RelativePosition = br.ReadVector3();
     this.RaiseEvent       = br.ReadMDXTrack <bool>(version, true);
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Reads an <see cref="MDXArray{T}"/> using a given <see cref="BinaryReader"/>, and fills it with its
        /// referenced values.
        /// </summary>
        /// <param name="br">The reader to use.</param>
        /// <param name="version">The contextually version for the stored objects.</param>
        public MDXArray(BinaryReader br, WarcraftVersion version)
        {
            this.Count          = br.ReadUInt32();
            this.ElementsOffset = br.ReadUInt32();

            Fill(br, version);

            this.IsFilled = true;
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Saves the selected preferences to disk from the UI elements.
        /// </summary>
        public void SavePreferences()
        {
            this.GamePathListStore.Foreach
            (
                (model, path, iter) =>
            {
                string alias            = (string)model.GetValue(iter, 0);
                string gamePath         = (string)model.GetValue(iter, 1);
                WarcraftVersion version = (WarcraftVersion)this.GamePathListStore.GetValue(iter, 2);
                GamePathStorage.Instance.StorePath(alias, version, gamePath);

                return(false);
            }
            );

            string selectedExportDirectory = new Uri(this.DefaultExportDirectoryFileChooserButton.Uri).LocalPath;

            if (!Directory.Exists(selectedExportDirectory))
            {
                try
                {
                    Directory.CreateDirectory(selectedExportDirectory);
                }
                catch (UnauthorizedAccessException uax)
                {
                    Console.WriteLine($"Failed to create the export directory: {uax}");
                    throw;
                }
            }

            this.Config.DefaultExportDirectory = selectedExportDirectory;

            this.Config.DefaultModelExportFormat   = (ModelFormat)this.DefaultModelExportFormatComboBox.Active;
            this.Config.DefaultImageExportFormat   = (ImageFormat)this.DefaultImageExportFormatComboBox.Active;
            this.Config.DefaultAudioExportFormat   = (AudioFormat)this.DefaultAudioExportFormatComboBox.Active;
            this.Config.KeepFileDirectoryStructure = this.KeepDirectoryStructureSwitch.Active;

            this.Config.AllowSendingStatistics = this.AllowStatsCheckButton.Active;
            this.Config.SendMachineID          = this.SendMachineIDCheckButton.Active;
            this.Config.SendInstallID          = this.SendInstallIDCheckButton.Active;
            this.Config.SendOperatingSystem    = this.SendOSCheckButton.Active;
            this.Config.SendAppVersion         = this.SendAppVersionCheckButton.Active;
            this.Config.SendRuntimeInformation = this.SendRuntimeInfoCheckButton.Active;

            this.Config.ViewportBackgroundColour = this.ViewportColourButton.Rgba;
            this.Config.WireframeColour          = this.WireframeColourButton.Rgba;
            this.Config.OccludeBoundingBoxes     = this.OccludeBoundingBoxesSwitch.Active;
            this.Config.CameraSpeed      = this.CameraSpeedAdjustment.Value;
            this.Config.RotationSpeed    = this.RotationSpeedAdjustment.Value;
            this.Config.CameraFOV        = this.CameraFOVAdjustment.Value;
            this.Config.SprintMultiplier = this.SprintMultiplierAdjustment.Value;

            this.Config.ShowUnknownFilesWhenFiltering = this.ShowUnknownFilesCheckButton.Active;
            this.Config.AutoplayAudioFiles            = this.AutoplayAudioCheckButton.Active;

            this.Config.Commit();
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Reads an <see cref="MDXTrack{T}"/> of type <typeparamref name="T"/> from the data stream.
 /// </summary>
 /// <param name="binaryReader">The reader.</param>
 /// <param name="version">The version.</param>
 /// <param name="valueless">
 /// If this value is true, it indicates that no values are associated with
 /// this track, and any value-related reading should be skipped.
 /// </param>
 /// <typeparam name="T">The type of the track.</typeparam>
 /// <returns>The value.</returns>
 public static MDXTrack <T> ReadMDXTrack <T>
 (
     this BinaryReader binaryReader,
     WarcraftVersion version,
     bool valueless = false
 )
 {
     return(new MDXTrack <T>(binaryReader, version, valueless));
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MDXSkin"/> class.
 /// </summary>
 /// <param name="br">A binary reader pointing at a valid starting point for the data.</param>
 /// <param name="version">The version to deserialize.</param>
 public MDXSkin(BinaryReader br, WarcraftVersion version)
 {
     VertexIndices    = br.ReadMDXArray <ushort>();
     Triangles        = br.ReadMDXArray <ushort>();
     VertexProperties = br.ReadMDXArray <MDXVertexProperty>();
     Sections         = br.ReadMDXArray <MDXSkinSection>(version);
     RenderBatches    = br.ReadMDXArray <MDXRenderBatch>();
     BoneCountMax     = br.ReadUInt32();
 }
Ejemplo n.º 17
0
        /// <summary>
        /// Gets the absolute serialized byte size of this class.
        /// </summary>
        /// <param name="version">The version that is contextually relevant.</param>
        /// <returns>The size of a serialized object.</returns>
        public static int GetSize(WarcraftVersion version)
        {
            if (version >= WarcraftVersion.BurningCrusade)
            {
                return(48);
            }

            return(32);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Reads a versioned value of type <paramref name="type"/> from the data stream. The generic type must be
        /// explicitly implemented in <see cref="TypeReaderMap"/>. Note that strings are read as C-style null-terminated
        /// strings, and not C#-style length-prefixed strings.
        /// </summary>
        /// <param name="br"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentException"></exception>
        public static dynamic Read(this BinaryReader br, Type type, WarcraftVersion version)
        {
            if (!VersionedTypeReaderMap.ContainsKey(type))
            {
                throw new ArgumentException("The given versioned type has no supported reading function associated " +
                                            "with it.", type.Name);
            }

            return(VersionedTypeReaderMap[type](br, version));
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Reads a versioned value of type <typeparamref name="T"/> from the data stream. The generic type must be
        /// explicitly implemented in <see cref="VersionedTypeReaderMap"/>.
        /// </summary>
        /// <param name="br"></param>
        /// <param name="version">The contextually relevant version for the object to be read.</param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static T Read <T>(this BinaryReader br, WarcraftVersion version)
        {
            if (!VersionedTypeReaderMap.ContainsKey(typeof(T)))
            {
                throw new ArgumentException("The given versioned generic type has no supported reading function associated " +
                                            "with it.", typeof(T).Name);
            }

            return(Read(br, typeof(T), version));
        }
Ejemplo n.º 20
0
        public FieldOrderer(WarcraftVersion version, IReadOnlyList <PropertyInfo> originalProperties)
        {
            this.Version            = version;
            this.OriginalProperties = originalProperties;

            // Get the properties that should move, and their movement information
            this.MovingProperties = DBCInspector.GetMovedProperties(this.Version, originalProperties);

            // Build the precedence chains for the moving properties
            this.PrecedenceChains = BuildPrecedenceChains();
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Gets the absolute size in bytes of the given record type.
        /// </summary>
        /// <param name="version">The version of the record.</param>
        /// <param name="recordType">The type to get the size of.</param>
        /// <returns>The absolute size in bytes of the record.</returns>
        public static int GetRecordSize(WarcraftVersion version, Type recordType)
        {
            var size = 0;

            foreach (var recordProperty in GetVersionRelevantProperties(version, recordType))
            {
                switch (recordProperty.PropertyType)
                {
                // Single-field types
                case Type foreignKeyType when foreignKeyType.IsGenericType && foreignKeyType.GetGenericTypeDefinition() == typeof(ForeignKey <>):
                case Type stringRefType when stringRefType == typeof(StringReference):
                case Type enumType when enumType.IsEnum:
                {
                    var underlyingType = DBCDeserializer.GetUnderlyingStoredPrimitiveType(recordProperty.PropertyType);

                    size += Marshal.SizeOf(underlyingType);
                    break;
                }

                // Multi-field types
                case Type genericListType when genericListType.IsGenericType && genericListType.GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IList <>)):
                case Type arrayType when arrayType.IsArray:
                {
                    var elementSize        = Marshal.SizeOf(DBCDeserializer.GetUnderlyingStoredPrimitiveType(recordProperty.PropertyType));
                    var arrayInfoAttribute = GetVersionRelevantPropertyFieldArrayAttribute(version, recordProperty);

                    size += (int)(elementSize * arrayInfoAttribute.Count);

                    break;
                }

                // Special version-variant length handling
                case Type locStringRefType when locStringRefType == typeof(LocalizedStringReference):
                {
                    size += LocalizedStringReference.GetFieldCount(version) * sizeof(uint);
                    break;
                }

                case Type registeredType when CustomFieldTypeStorageSizes.ContainsKey(registeredType):
                {
                    size += CustomFieldTypeStorageSizes[registeredType];
                    break;
                }

                default:
                {
                    size += Marshal.SizeOf(recordProperty.PropertyType);
                    break;
                }
                }
            }

            return(size);
        }
Ejemplo n.º 22
0
        public GameWorld(string InWorldPath, string InWorldName, WarcraftVersion InGameVersion, IPackage InPackage, byte[] InWorldData)
        {
            this.WorldPath = InWorldPath;
            this.WorldName = InWorldName;
            this.GameVersion = InGameVersion;
            this.Package = InPackage;

            // Load the world metadata
            this.WorldDataTable = new WorldTable(InWorldData);

            // Load all ADTs here? Bad for memory, perhaps better to leave it to the user to lazy load as needed
        }
Ejemplo n.º 23
0
        public GameWorld(string inWorldPath, string inWorldName, WarcraftVersion inGameVersion, IPackage inPackage, byte[] inWorldData)
        {
            this.WorldPath   = inWorldPath;
            this.WorldName   = inWorldName;
            this.GameVersion = inGameVersion;
            this.Package     = inPackage;

            // Load the world metadata
            this.WorldDataTable = new WorldTable(inWorldData);

            // Load all ADTs here? Bad for memory, perhaps better to leave it to the user to lazy load as needed
        }
Ejemplo n.º 24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MDXMaterial"/> class.
 /// </summary>
 /// <param name="br">The reader to read the instance from.</param>
 /// <param name="version">The version to read the instance in the context of.</param>
 public MDXMaterial(BinaryReader br, WarcraftVersion version)
 {
     Flags = (MDXRenderFlag)br.ReadUInt16();
     if (version >= WarcraftVersion.Cataclysm)
     {
         BlendMode = (BlendingMode)br.ReadUInt16();
     }
     else
     {
         BlendMode = RemapBlendingMode(br.ReadUInt16());
     }
 }
Ejemplo n.º 25
0
        /// <summary>
        /// Gets the reflection information for a given record type and version from the cache, creating it if it is not
        /// already present.
        /// </summary>
        /// <param name="recordType">The record type.</param>
        /// <param name="version">The version to get.</param>
        /// <returns>A <see cref="RecordFieldInformation"/> relevant for the given version.</returns>
        public RecordFieldInformation GetRecordInformation(Type recordType, WarcraftVersion version)
        {
            var infoKey = new RecordInformationIdentifier(recordType, version);

            if (!_informationCache.ContainsKey(infoKey))
            {
                var recordInfo = new RecordFieldInformation(recordType, version);
                _informationCache.Add(infoKey, recordInfo);
            }

            return(_informationCache[infoKey]);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Reads an <see cref="MDXArray{T}"/> of type <typeparamref name="T"/> from the data stream.
        /// This advances the position of the reader by 8 bytes.
        /// </summary>
        /// <param name="binaryReader">binaryReader.</param>
        /// <param name="version">The contextually relevant version of the stored objects.</param>
        /// <typeparam name="T">The type which the array encapsulates.</typeparam>
        /// <returns>A new array, filled with the values it references.</returns>
        public static MDXArray <T> ReadMDXArray <T>(this BinaryReader binaryReader, WarcraftVersion version)
        {
            // Quaternion hack, since it's packed into 16 bits in some versions
            var containsQuaternion = FindInnermostGenericType(typeof(T)) == typeof(Quaternion);

            if (!typeof(T).GetInterfaces().Contains(typeof(IVersionedClass)) && !containsQuaternion)
            {
                return(new MDXArray <T>(binaryReader));
            }

            return(new MDXArray <T>(binaryReader, version));
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Reads a property value from the given <see cref="BinaryReader"/>.
        /// </summary>
        /// <param name="reader">The reader, containing the data.</param>
        /// <param name="recordInfo">The reflected field information.</param>
        /// <param name="property">The property which will contain the data.</param>
        /// <param name="elementType">The element type of the field. This is primarily used for reading arrays.</param>
        /// <param name="version">The version of the record.</param>
        /// <returns>The value that should be assigned to the property.</returns>
        public static object ReadPropertyValue
        (
            BinaryReader reader,
            RecordFieldInformation recordInfo,
            PropertyInfo property,
            Type elementType,
            WarcraftVersion version
        )
        {
            object fieldValue;

            if (DBCInspector.IsPropertyForeignKey(property))
            {
                // Get the foreign key information
                var foreignKeyAttribute = recordInfo.PropertyForeignKeyAttributes[property];

                // Get the inner type
                var keyType  = GetUnderlyingStoredPrimitiveType(elementType);
                var keyValue = reader.Read(keyType);

                // Create the specific ForeignKey type
                var genericKeyFieldType  = typeof(ForeignKey <>);
                var specificKeyFieldType = genericKeyFieldType.MakeGenericType(keyType);

                fieldValue = Activator.CreateInstance
                             (
                    specificKeyFieldType,
                    foreignKeyAttribute.Database,
                    foreignKeyAttribute.Field,
                    keyValue
                             );
            }
            else if (elementType.IsEnum)
            {
                // Get the underlying type of the enum
                var enumType = elementType.GetEnumUnderlyingType();
                fieldValue = reader.Read(enumType);
            }
            else
            {
                if (elementType == typeof(LocalizedStringReference))
                {
                    fieldValue = reader.Read(elementType, version);
                }
                else
                {
                    fieldValue = reader.Read(elementType);
                }
            }

            return(fieldValue);
        }
Ejemplo n.º 28
0
        private static string GetDatabaseFilePath(WarcraftVersion version, DatabaseName databaseName)
        {
            var path = Path.Combine
                       (
                TestContext.CurrentContext.WorkDirectory,
                "Content",
                version.ToString(),
                "DBFilesClient",
                $"{databaseName}.dbc"
                       );

            return(path);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Reads an <see cref="MDXSkin"/> from the data stream.
        /// </summary>
        /// <param name="binaryReader">The reader to use.</param>
        /// <param name="version">The contextually relevant version to target.</param>
        /// <returns>A fully read skin.</returns>
        public static MDXSkin ReadMDXSkin(this BinaryReader binaryReader, WarcraftVersion version)
        {
            MDXSkin skin = new MDXSkin
            {
                VertexIndices    = binaryReader.ReadMDXArray <ushort>(),
                Triangles        = binaryReader.ReadMDXArray <ushort>(),
                VertexProperties = binaryReader.ReadMDXArray <MDXVertexProperty>(),
                Sections         = binaryReader.ReadMDXArray <MDXSkinSection>(version),
                RenderBatches    = binaryReader.ReadMDXArray <MDXRenderBatch>(),
                BoneCountMax     = binaryReader.ReadUInt32()
            };

            return(skin);
        }
Ejemplo n.º 30
0
        public MDXLight(BinaryReader br, WarcraftVersion version)
        {
            Type     = (MDXLightType)br.ReadUInt16();
            Bone     = br.ReadInt16();
            Position = br.ReadVector3();

            AmbientColour    = br.ReadMDXTrack <RGB>(version);
            AmbientIntensity = br.ReadMDXTrack <float>(version);
            DiffuseColour    = br.ReadMDXTrack <RGB>(version);
            DiffuseIntensity = br.ReadMDXTrack <float>(version);
            AttenuationStart = br.ReadMDXTrack <float>(version);
            AttenuationEnd   = br.ReadMDXTrack <float>(version);

            Visibility = br.ReadMDXTrack <bool>(version);
        }
Ejemplo n.º 31
0
        /// <summary>
        /// Fills the array with versioned objects using the given <see cref="BinaryReader"/>. The position of the
        /// reader will not be modified by this method.
        /// </summary>
        /// <param name="br"></param>
        /// <param name="version">The contextually relevant version of the stored objects.</param>
        public void Fill(BinaryReader br, WarcraftVersion version)
        {
            long initialPositionBeforeJumpToData = br.BaseStream.Position;

            br.BaseStream.Position = this.ElementsOffset;

            for (int i = 0; i < this.Count; ++i)
            {
                this.Values.Add(br.Read <T>(version));
            }

            br.BaseStream.Position = initialPositionBeforeJumpToData;

            this.IsFilled = true;
        }
Ejemplo n.º 32
0
 public FieldVersion(WarcraftVersion inVersion)
 {
     this.Version = inVersion;
 }
Ejemplo n.º 33
0
 /// <summary>
 /// Sets the version this record is valid for.
 /// </summary>
 public virtual void SetVersion(WarcraftVersion InVersion)
 {
     this.Version = InVersion;
 }