Ejemplo n.º 1
0
        /// <summary>
        /// Loads the specified WMO group file from the archives and deserialize it.
        /// </summary>
        /// <param name="fileReference">The archive reference to the model group.</param>
        /// <returns>A WMO object, containing just the specified model group.</returns>
        public static WMO LoadWorldModelGroup(FileReference fileReference)
        {
            // Get the file name of the root object
            string modelRootPath = fileReference.FilePath.Remove(fileReference.FilePath.Length - 8, 4);

            // Extract it and load just this model group
            try
            {
                byte[] fileData = fileReference.PackageGroup.ExtractFile(modelRootPath);
                if (fileData != null)
                {
                    WMO    worldModel     = new WMO(fileData);
                    byte[] modelGroupData = fileReference.Extract();

                    if (modelGroupData != null)
                    {
                        worldModel.AddModelGroup(new ModelGroup(modelGroupData));
                    }

                    return(worldModel);
                }
            }
            catch (InvalidFileSectorTableException fex)
            {
                Log.Warn(
                    $"Failed to load the model group \"{fileReference.FilePath}\" due to an invalid sector table (\"{fex.Message}\").");

                return(null);
            }

            return(null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads the specified WMO group file from the archives and deserialize it.
        /// </summary>
        /// <param name="fileReference">The archive reference to the model group.</param>
        /// <returns>A WMO object, containing just the specified model group.</returns>
        public static WMO LoadWorldModelGroup(FileReference fileReference)
        {
            if (fileReference == null)
            {
                throw new ArgumentNullException(nameof(fileReference));
            }

            // Get the file name of the root object
            string modelRootPath = fileReference.FilePath.Remove(fileReference.FilePath.Length - 8, 4);

            WMO worldModel;

            // Extract it and load just this model group
            try
            {
                byte[] rootData = fileReference.Context.Assets.ExtractFile(modelRootPath);
                worldModel = new WMO(rootData);

                byte[] modelGroupData = fileReference.Extract();
                worldModel.AddModelGroup(new ModelGroup(modelGroupData));
            }
            catch (FileNotFoundException fex)
            {
                Log.Warn($"Failed to load the model group \"{fileReference.FilePath}\": {fex}");
                throw;
            }
            catch (InvalidFileSectorTableException fex)
            {
                Log.Warn($"Failed to load the model group \"{fileReference.FilePath}\" due to an invalid sector table (\"{fex}\")");
                throw;
            }

            return(worldModel);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// TODO: Refactor this and LoadWorldModelGroup
        /// Loads the specified WMO file from the archives and deserialize it.
        /// </summary>
        /// <param name="fileReference">The archive reference to the WMO root object.</param>
        /// <returns>A WMO object.</returns>
        public static WMO LoadWorldModel(FileReference fileReference)
        {
            try
            {
                byte[] fileData = fileReference.Extract();
                if (fileData != null)
                {
                    WMO worldModel = new WMO(fileData);

                    string modelPathWithoutExtension = Path.GetFileNameWithoutExtension(fileReference.FilePath);
                    for (int i = 0; i < worldModel.GroupCount; ++i)
                    {
                        // Extract the groups as well
                        string modelGroupPath = $"{modelPathWithoutExtension}_{i:D3}.wmo";

                        try
                        {
                            byte[] modelGroupData = fileReference.PackageGroup.ExtractFile(modelGroupPath);

                            if (modelGroupData != null)
                            {
                                worldModel.AddModelGroup(new ModelGroup(modelGroupData));
                            }
                        }
                        catch (InvalidFileSectorTableException fex)
                        {
                            Log.Warn(
                                $"Failed to load the model group \"{modelGroupPath}\" due to an invalid sector table (\"{fex.Message}\").");

                            return(null);
                        }
                    }

                    return(worldModel);
                }
            }
            catch (InvalidFileSectorTableException fex)
            {
                Log.Warn(
                    $"Failed to load the model \"{fileReference.FilePath}\" due to an invalid sector table (\"{fex.Message}\").");

                return(null);
            }

            return(null);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Loads the specified WMO file from the archives and deserialize it.
        /// </summary>
        /// <param name="fileReference">The archive reference to the WMO root object.</param>
        /// <returns>A WMO object.</returns>
        public static WMO LoadWorldModel(FileReference fileReference)
        {
            if (fileReference == null)
            {
                throw new ArgumentNullException(nameof(fileReference));
            }

            WMO worldModel;

            try
            {
                var fileData = fileReference.Extract();
                worldModel = new WMO(fileData);

                var modelPathWithoutExtension = $"{fileReference.FileDirectory.Replace('/', '\\')}\\" +
                                                $"{Path.GetFileNameWithoutExtension(fileReference.Filename)}";
                for (var i = 0; i < worldModel.GroupCount; ++i)
                {
                    // Extract the groups as well
                    var modelGroupPath = $"{modelPathWithoutExtension}_{i:D3}.wmo";

                    try
                    {
                        var modelGroupData = fileReference.Context.Assets.ExtractFile(modelGroupPath);
                        worldModel.AddModelGroup(new ModelGroup(modelGroupData));
                    }
                    catch (FileNotFoundException fex)
                    {
                        Log.Warn($"Failed to load model group \"{modelGroupPath}\": {fex}.");
                        throw;
                    }
                }
            }
            catch (InvalidFileSectorTableException fex)
            {
                Log.Warn
                (
                    $"Failed to load the model \"{fileReference.FilePath}\" due to an invalid sector table " +
                    $"(\"{fex.Message}\")."
                );
                throw;
            }

            return(worldModel);
        }