/// <summary>
        /// Filters a set of localized strings and prepares them for display.
        /// </summary>
        /// <param name="unic">The string list.</param>
        /// <param name="stringIds">The string ID cache to use.</param>
        /// <param name="strings">The strings to display.</param>
        /// <param name="language">The language to display strings from.</param>
        /// <param name="filter">The filter to match strings and stringIDs against. Can be <c>null</c> to display everything.</param>
        /// <returns>The strings to print.</returns>
        public static List <DisplayString> PrepareForDisplay(MultilingualUnicodeStringList unic, StringIdCache stringIds, IEnumerable <LocalizedString> strings, GameLanguage language, string filter)
        {
            // Filter the input strings
            var display = new List <DisplayString>();

            foreach (var localizedString in strings)
            {
                var str = unic.GetString(localizedString, language);
                if (str == null)
                {
                    continue;
                }
                var stringId = stringIds.GetString(localizedString.StringID);
                if (filter != null && !str.Contains(filter) && !stringId.Contains(filter))
                {
                    continue;
                }
                display.Add(new DisplayString
                {
                    StringID = stringId,
                    String   = str
                });
            }
            display.Sort((a, b) => String.Compare(a.StringID, b.StringID, StringComparison.Ordinal));
            return(display);
        }
        public override bool Execute(List <string> args)
        {
            if (args.Count != 0)
            {
                return(false);
            }
            var variantNames = _model.Variants.Select(v => _stringIds.GetString(v.Name) ?? v.Name.ToString()).OrderBy(n => n).ToList();

            if (variantNames.Count == 0)
            {
                Console.WriteLine("Model has no variants");
                return(true);
            }
            foreach (var name in variantNames)
            {
                Console.WriteLine(name);
            }
            return(true);
        }
 /// <summary>
 /// Filters a set of localized strings and prepares them for display.
 /// </summary>
 /// <param name="unic">The string list.</param>
 /// <param name="stringIds">The string ID cache to use.</param>
 /// <param name="strings">The strings to display.</param>
 /// <param name="language">The language to display strings from.</param>
 /// <param name="filter">The filter to match strings and stringIDs against. Can be <c>null</c> to display everything.</param>
 /// <returns>The strings to print.</returns>
 public static List<DisplayString> PrepareForDisplay(MultilingualUnicodeStringList unic, StringIdCache stringIds, IEnumerable<LocalizedString> strings, GameLanguage language, string filter)
 {
     // Filter the input strings
     var display = new List<DisplayString>();
     foreach (var localizedString in strings)
     {
         var str = unic.GetString(localizedString, language);
         if (str == null)
             continue;
         var stringId = stringIds.GetString(localizedString.StringId);
         if (filter != null && !str.Contains(filter) && !stringId.Contains(filter))
             continue;
         display.Add(new DisplayString
         {
             StringId = stringId,
             String = str
         });
     }
     display.Sort((a, b) => String.Compare(a.StringId, b.StringId, StringComparison.Ordinal));
     return display;
 }
示例#4
0
        public override bool Execute(List <string> args)
        {
            if (args.Count != 3)
            {
                return(false);
            }
            var variantName = args[0];
            var fileType    = args[1];
            var fileName    = args[2];

            if (fileType != "obj")
            {
                return(false);
            }

            // Find the variant to extract
            if (_model.RenderModel == null)
            {
                Console.Error.WriteLine("The model does not have a render model associated with it.");
                return(true);
            }
            var variant = _model.Variants.FirstOrDefault(v => (_stringIds.GetString(v.Name) ?? v.Name.ToString()) == variantName);

            if (variant == null && _model.Variants.Count > 0)
            {
                Console.Error.WriteLine("Unable to find variant \"{0}\"", variantName);
                Console.Error.WriteLine("Use \"listvariants\" to list available variants.");
                return(true);
            }

            // Load resource caches
            Console.WriteLine("Loading resource caches...");
            var resourceManager = new ResourceDataManager();

            try
            {
                resourceManager.LoadCachesFromDirectory(_fileInfo.DirectoryName);
            }
            catch
            {
                Console.WriteLine("Unable to load the resource .dat files.");
                Console.WriteLine("Make sure that they all exist and are valid.");
                return(true);
            }

            // Deserialize the render model tag
            Console.WriteLine("Reading model data...");
            RenderModel renderModel;

            using (var cacheStream = _fileInfo.OpenRead())
            {
                var renderModelContext = new TagSerializationContext(cacheStream, _cache, _model.RenderModel);
                renderModel = TagDeserializer.Deserialize <RenderModel>(renderModelContext);
            }
            if (renderModel.Resource == null)
            {
                Console.Error.WriteLine("Render model does not have a resource associated with it");
                return(true);
            }

            // Deserialize the resource definition
            var resourceContext = new ResourceSerializationContext(renderModel.Resource);
            var definition      = TagDeserializer.Deserialize <RenderGeometryResourceDefinition>(resourceContext);

            using (var resourceStream = new MemoryStream())
            {
                // Extract the resource data
                resourceManager.Extract(renderModel.Resource, resourceStream);
                using (var objFile = new StreamWriter(File.Open(fileName, FileMode.Create, FileAccess.Write)))
                {
                    var objExtractor     = new ObjExtractor(objFile);
                    var vertexCompressor = new VertexCompressor(renderModel.Compression[0]);                     // Create a (de)compressor from the first compression block
                    if (variant != null)
                    {
                        // Extract each region in the variant
                        foreach (var region in variant.Regions)
                        {
                            // Get the corresonding region in the render model tag
                            if (region.RenderModelRegionIndex >= renderModel.Regions.Count)
                            {
                                continue;
                            }
                            var renderModelRegion = renderModel.Regions[region.RenderModelRegionIndex];

                            // Get the corresponding permutation in the render model tag
                            // (Just extract the first permutation for now)
                            if (region.Permutations.Count == 0)
                            {
                                continue;
                            }
                            var permutation = region.Permutations[0];
                            if (permutation.RenderModelPermutationIndex >= renderModelRegion.Permutations.Count)
                            {
                                continue;
                            }
                            var renderModelPermutation = renderModelRegion.Permutations[permutation.RenderModelPermutationIndex];

                            // Extract each mesh in the permutation
                            var meshIndex       = renderModelPermutation.MeshIndex;
                            var meshCount       = renderModelPermutation.MeshCount;
                            var regionName      = _stringIds.GetString(region.Name) ?? region.Name.ToString();
                            var permutationName = _stringIds.GetString(permutation.Name) ?? permutation.Name.ToString();
                            Console.WriteLine("Extracting {0} mesh(es) for {1}:{2}...", meshCount, regionName, permutationName);
                            for (var i = 0; i < meshCount; i++)
                            {
                                // Create a MeshReader for the mesh and pass it to the obj extractor
                                var meshReader = new MeshReader(renderModel.Meshes[meshIndex + i], definition);
                                objExtractor.ExtractMesh(meshReader, vertexCompressor, resourceStream);
                            }
                        }
                    }
                    else
                    {
                        // No variant - just extract every mesh
                        Console.WriteLine("Extracting {0} mesh(es)...", renderModel.Meshes.Count);
                        foreach (var mesh in renderModel.Meshes)
                        {
                            // Create a MeshReader for the mesh and pass it to the obj extractor
                            var meshReader = new MeshReader(mesh, definition);
                            objExtractor.ExtractMesh(meshReader, vertexCompressor, resourceStream);
                        }
                    }
                    objExtractor.Finish();
                }
            }
            Console.WriteLine("Done!");
            return(true);
        }