Esempio n. 1
0
        public override bool Execute(List<string> args)
        {
            if (args.Count != 1)
                return false;

            var outDir = args[0];
            Directory.CreateDirectory(outDir);

            Console.WriteLine("Loading resource caches...");
            var resourceManager = new ResourceDataManager();
            try
            {
                resourceManager.LoadCachesFromDirectory(_info.CacheFile.DirectoryName);
            }
            catch
            {
                Console.WriteLine("Unable to load the resource .dat files.");
                Console.WriteLine("Make sure that they all exist and are valid.");
                return true;
            }

            var extractor = new BitmapDdsExtractor(resourceManager);
            var count = 0;
            using (var tagsStream = _info.OpenCacheRead())
            {
                foreach (var tag in _info.Cache.Tags.FindAllInGroup("bitm"))
                {
                    Console.Write("Extracting ");
                    TagPrinter.PrintTagShort(tag);

                    try
                    {
                        var tagContext = new TagSerializationContext(tagsStream, _info.Cache, _info.StringIDs, tag);
                        var bitmap = _info.Deserializer.Deserialize<TagDefinitions.Bitmap>(tagContext);
                        var ddsOutDir = outDir;
                        if (bitmap.Images.Count > 1)
                        {
                            ddsOutDir = Path.Combine(outDir, tag.Index.ToString("X8"));
                            Directory.CreateDirectory(ddsOutDir);
                        }
                        for (var i = 0; i < bitmap.Images.Count; i++)
                        {
                            var outPath = Path.Combine(ddsOutDir,
                                ((bitmap.Images.Count > 1) ? i.ToString() : tag.Index.ToString("X8")) + ".dds");
                            using (var outStream = File.Open(outPath, FileMode.Create, FileAccess.Write))
                            {
                                extractor.ExtractDds(_info.Deserializer, bitmap, i, outStream);
                            }
                        }
                        count++;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("ERROR: Failed to extract bitmap: " + ex.Message);
                    }
                }
            }
            Console.WriteLine("Extracted {0} bitmaps.", count);
            return true;
        }
Esempio n. 2
0
        public override object Execute(List <string> args)
        {
            if (args.Count != 1)
            {
                return(false);
            }

            var outDir = args[0];

            Directory.CreateDirectory(outDir);

            Console.WriteLine("Loading resource caches...");

            var count = 0;

            using (var tagsStream = CacheContext.OpenTagCacheRead())
            {
                var extractor = new BitmapDdsExtractor(CacheContext);

                foreach (var tag in CacheContext.TagCache.Index.FindAllInGroup("bitm"))
                {
                    Console.Write("Extracting ");
                    TagPrinter.PrintTagShort(tag);

                #if !DEBUG
                    try
                    {
                #endif
                    var bitmap    = CacheContext.Deserialize <Bitmap>(tagsStream, tag);
                    var ddsOutDir = outDir;

                    if (bitmap.Images.Count > 1)
                    {
                        ddsOutDir = Path.Combine(outDir, tag.Index.ToString("X8"));
                        Directory.CreateDirectory(ddsOutDir);
                    }

                    for (var i = 0; i < bitmap.Images.Count; i++)
                    {
                        var outPath = Path.Combine(ddsOutDir, ((bitmap.Images.Count > 1) ? i.ToString() : tag.Index.ToString("X8")) + ".dds");

                        using (var outStream = File.Open(outPath, FileMode.Create, FileAccess.Write))
                            extractor.ExtractDds(bitmap, i, outStream);
                    }
                    count++;
                #if !DEBUG
                }
                catch (Exception ex)
                {
                    Console.WriteLine("ERROR: Failed to extract bitmap: " + ex.Message);
                }
                #endif
                }
            }

            Console.WriteLine("Extracted {0} bitmaps.", count);

            return(true);
        }
        public override object Execute(List <string> args)
        {
            if (args.Count != 1)
            {
                return(false);
            }

            var directory = args[0];

            if (!Directory.Exists(directory))
            {
                Console.Write("Destination directory does not exist. Create it? [y/n] ");
                var answer = Console.ReadLine().ToLower();

                if (answer.Length == 0 || !(answer.StartsWith("y") || answer.StartsWith("n")))
                {
                    return(false);
                }

                if (answer.StartsWith("y"))
                {
                    Directory.CreateDirectory(directory);
                }
                else
                {
                    return(false);
                }
            }

            //var extractor = new BitmapExtractor(CacheContext);
            var extractor = new BitmapDdsExtractor(CacheContext);

            using (var tagsStream = CacheContext.OpenTagCacheRead())
            {
            #if !DEBUG
                try
                {
            #endif
                var bitmap    = CacheContext.Deserialize <Bitmap>(tagsStream, Tag);
                var ddsOutDir = directory;

                if (bitmap.Images.Count > 1)
                {
                    ddsOutDir = Path.Combine(directory, Tag.Index.ToString("X8"));
                    Directory.CreateDirectory(ddsOutDir);
                }

                for (var i = 0; i < bitmap.Images.Count; i++)
                {
                    var outPath = Path.Combine(ddsOutDir, ((bitmap.Images.Count > 1) ? i.ToString() : Tag.Index.ToString("X8")) + ".dds");

                    using (var outStream = File.Open(outPath, FileMode.Create, FileAccess.Write))
                    {
                        //extractor.ExtractBitmap(bitmap, i, outStream);
                        extractor.ExtractDds(bitmap, i, outStream);
                    }
                }
            #if !DEBUG
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR: Failed to extract bitmap: " + ex.Message);
            }
            #endif
            }

            Console.WriteLine("Done!");

            return(true);
        }
        public override object Execute(List <string> args)
        {
            if (args.Count != 1)
            {
                return(false);
            }

            var directory = args[0];

            if (!Directory.Exists(directory))
            {
                Console.Write("Destination directory does not exist. Create it? [y/n] ");
                var answer = Console.ReadLine().ToLower();

                if (answer.Length == 0 || !(answer.StartsWith("y") || answer.StartsWith("n")))
                {
                    return(false);
                }

                if (answer.StartsWith("y"))
                {
                    Directory.CreateDirectory(directory);
                }
                else
                {
                    return(false);
                }
            }

            using (var cacheStream = CacheContext.TagCacheFile.OpenRead())
            {
                foreach (var shader in Definition.Materials)
                {
                    var renderMethod = (RenderMethod)CacheContext.Deserialize(cacheStream, shader.RenderMethod);

                    foreach (var property in renderMethod.ShaderProperties)
                    {
                        var template = CacheContext.Deserialize <RenderMethodTemplate>(cacheStream, property.Template);

                        for (var i = 0; i < template.SamplerArguments.Count; i++)
                        {
                            var mapTemplate = template.SamplerArguments[i];

                            var extractor = new BitmapDdsExtractor(CacheContext);

                            var bitmap    = CacheContext.Deserialize <Bitmap>(cacheStream, property.ShaderMaps[i].Bitmap);
                            var ddsOutDir = directory;

                            if (bitmap.Images.Count > 1)
                            {
                                ddsOutDir = Path.Combine(directory, property.ShaderMaps[i].Bitmap.Index.ToString("X8"));
                                Directory.CreateDirectory(ddsOutDir);
                            }

                            for (var j = 0; j < bitmap.Images.Count; j++)
                            {
                                var outPath = Path.Combine(ddsOutDir, CacheContext.GetString(mapTemplate.Name) + "_" + property.ShaderMaps[i].Bitmap.Index.ToString("X4")) + ".dds";

                                using (var outStream = File.Open(outPath, FileMode.Create, FileAccess.Write))
                                    extractor.ExtractDds(bitmap, j, outStream);

                                Console.WriteLine($"Bitmap {i} ({CacheContext.GetString(mapTemplate.Name)}): {property.ShaderMaps[i].Bitmap.Group.Tag} 0x{property.ShaderMaps[i].Bitmap.Index:X4} extracted to '{outPath}'");
                            }
                        }
                    }
                }
            }

            return(true);
        }
Esempio n. 5
0
        public override bool Execute(List <string> args)
        {
            if (args.Count != 2)
            {
                return(false);
            }

            var tag = ArgumentParser.ParseTagIndex(Info, args[0]);

            if (tag == null)
            {
                return(false);
            }

            var directory = args[1];

            if (!Directory.Exists(directory))
            {
                Console.Write("Destination directory does not exist. Create it? [y/n] ");
                var answer = Console.ReadLine().ToLower();

                if (answer.Length == 0 || !(answer.StartsWith("y") || answer.StartsWith("n")))
                {
                    return(false);
                }

                if (answer.StartsWith("y"))
                {
                    Directory.CreateDirectory(directory);
                }
                else
                {
                    return(false);
                }
            }

            Console.Write("Loading resource caches...");
            var resourceManager = new ResourceDataManager();

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

            var extractor = new BitmapDdsExtractor(resourceManager);

            using (var tagsStream = Info.OpenCacheRead())
            {
                try
                {
                    var tagContext = new TagSerializationContext(tagsStream, Info.Cache, Info.StringIDs, tag);
                    var bitmap     = Info.Deserializer.Deserialize <TagDefinitions.Bitmap>(tagContext);
                    var ddsOutDir  = directory;
                    if (bitmap.Images.Count > 1)
                    {
                        ddsOutDir = Path.Combine(directory, tag.Index.ToString("X8"));
                        Directory.CreateDirectory(ddsOutDir);
                    }
                    for (var i = 0; i < bitmap.Images.Count; i++)
                    {
                        var outPath = Path.Combine(ddsOutDir,
                                                   ((bitmap.Images.Count > 1) ? i.ToString() : tag.Index.ToString("X8")) + ".dds");
                        using (var outStream = File.Open(outPath, FileMode.Create, FileAccess.Write))
                        {
                            extractor.ExtractDds(Info.Deserializer, bitmap, i, outStream);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("ERROR: Failed to extract bitmap: " + ex.Message);
                }
            }

            var tagName = Info.TagNames.ContainsKey(tag.Index) ?
                          Info.TagNames[tag.Index] :
                          $"0x{tag.Index:X4}";

            Console.WriteLine($"Extracted [Index: 0x{tag.Index:X4}, Offset: 0x{tag.HeaderOffset:X8}, Size: 0x{tag.TotalSize:X4}] {tagName}.{Info.StringIDs.GetString(tag.Group.Name)} to '{directory}'");

            return(true);
        }