Exemple #1
0
        public static List <Frame> InputWz(WZFile wz, string inpath)
        {
            WZObject      iwahz = wz.ResolvePath(inpath);
            WZSubProperty iwah  = iwahz as WZSubProperty;

            if (iwah == null)
            {
                throw new ArgumentException("The path provided did not lead to an animation; check input-wzfile, input-wzpath and input-wzver");
            }
            List <Frame> r = new List <Frame>();

            foreach (WZObject iwzo in iwah)
            {
                WZCanvasProperty iwc = iwzo.ResolveUOL() as WZCanvasProperty;
                if (iwc == null)
                {
                    continue;
                }
                int n;
                if (!int.TryParse(iwzo.Name, out n))
                {
                    continue;
                }
                r.Add(new Frame(n, new Bitmap(iwc.Value), ((WZPointProperty)iwc["origin"]).Value, iwc.HasChild("delay") ? Math.Max(iwc["delay"].ToInt(), 1) : 100));
                iwc.Dispose();
            }
            return(r.OrderBy(f => f.Number).ToList());
        }
Exemple #2
0
            public uint AddCanvas(WZCanvasProperty node)
            {
                uint ret = (uint)Canvases.Count;

                Canvases.Add(node);
                return(ret);
            }
Exemple #3
0
        private static void WriteBitmap(WZCanvasProperty node, BinaryWriter bw)
        {
            Bitmap b = node.Value;

            byte[] compressed = GetCompressedBitmap(b);
            node.Dispose();
            b = null;

            bw.Write((uint)compressed.Length);
            bw.Write(compressed);
        }
Exemple #4
0
        public static string GetImageBase64String(int itemId, int inventoryType, WZFile wzfile)
        {
            if (_itemImageDic.ContainsKey(itemId))
            {
                return(_itemImageDic[itemId]);
            }

            WZCanvasProperty wzcp = null;

            try
            {
                switch (inventoryType)
                {
                case 1:     // 装备
                    var cat = GetCharacterItemTypeName(itemId);
                    if (string.IsNullOrEmpty(cat))
                    {
                        return(string.Empty);
                    }

                    wzcp = wzfile.MainDirectory["Character"][cat][string.Concat(itemId.ToString().PadLeft(8, '0'), ".img")]["info"]["icon"] as WZCanvasProperty;
                    break;

                case 2:     // 消耗
                case 3:     // 消耗
                case 4:     // 材料
                    cat = "Consume";
                    if (inventoryType == 3 || inventoryType == 4)
                    {
                        cat = "Etc";
                    }

                    var o = wzfile.MainDirectory["Item"][cat][string.Concat(itemId.ToString().PadLeft(8, '0').Substring(0, 4), ".img")][itemId.ToString().PadLeft(8, '0')]["info"]["icon"];
                    if (o is WZUOLProperty)
                    {
                        var uol = o as WZUOLProperty;     // ../../02040002/info/icon
                        if (uol != null)
                        {
                            var path = uol.Value;
                            o = o.Parent;
                            while (path.StartsWith("../"))
                            {
                                o    = o.Parent;
                                path = path.Substring(3);
                            }

                            wzcp = o.ResolvePath(path) as WZCanvasProperty;
                        }
                    }
                    else
                    {
                        wzcp = o as WZCanvasProperty;
                    }
                    break;

                default:
                    break;
                }

                if (wzcp == null)
                {
                    return(string.Empty);
                }
            }
            catch
            {
                return(string.Empty);
            }

            using (Bitmap m = wzcp.Value)
            {
                if (m != null)
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        m.Save(ms, ImageFormat.Png);
                        byte[] byteImage = ms.ToArray();
                        var    str       = Convert.ToBase64String(byteImage);
                        _itemImageDic.Add(itemId, str);
                        return(str);
                    }
                }
            }

            return(string.Empty);
        }
Exemple #5
0
 public uint AddCanvas(WZCanvasProperty node) {
     uint ret = (uint) Canvases.Count;
     Canvases.Add(node);
     return ret;
 }
Exemple #6
0
        private static void WriteBitmap(WZCanvasProperty node, BinaryWriter bw) {
            Bitmap b = node.Value;

            byte[] compressed = GetCompressedBitmap(b);
            node.Dispose();
            b = null;

            bw.Write((uint) compressed.Length);
            bw.Write(compressed);
        }
Exemple #7
0
        private static void MainMain(string[] args)
        {
            #region getopt

            bool      printHelp   = false;
            string    aWzInPath   = null;
            bool      aWzNamesEnc = true;
            bool      aPngOutput  = false;
            WZVariant aWzVer      = (WZVariant)int.MinValue;
            string    aOutputPath = null;
            Color     aBgColor    = Color.Black;
            LoopType  aLoop       = LoopType.NoLoop;
            int       aPadding    = 10;
            // input, input-wzfile, input-wzpath, input-wzver, output, output-path, background-color, padding
            OptionSet set = new OptionSet();
            set.Add("iwzp=|input-wzpath=", "The path of the animation or image. Required", s => aWzInPath = s);
            set.Add("iwzv=|input-wzver=", "The WZ key to use when decoding the WZ. Required", s => aWzVer = (WZVariant)Enum.Parse(typeof(WZVariant), s));
            set.Add("iwzne|input-wz-names-not-encrypted", "Flag if WZ image names are not encrypted. ", s => aWzNamesEnc = false);
            set.Add("o=|of=|output-format=", "The method of output: (a)png or gif", s => {
                switch (s.ToLower())
                {
                case "png":
                    aPngOutput = true;
                    break;

                case "gif":
                    aPngOutput = false;
                    break;

                default:
                    throw new ArgumentException("output must be either png or gif");
                }
            });
            set.Add("op=|output-path=", "The path to write the output, (A)PNG or GIF, to", s => aOutputPath = s);
            set.Add("abg=|a-background-color=", "The background color of the animated output. Default is black. Ignored if there is no animation.", s => aBgColor        = Color.FromArgb(int.Parse(s)));
            set.Add("ap=|a-padding=", "The amount of padding in pixels to pad the animated output with. Default is 10. Ignored if there is no animation.", s => aPadding = int.Parse(s));
            set.Add("al=|a-looping=", "The method to loop multi-animations with. Default is NoLoop. Ignored if there is no animation.", s => aLoop = (LoopType)Enum.Parse(typeof(LoopType), s, true));
            set.Add("?|h|help", "Shows help", s => printHelp = true);
            set.Parse(args);

            #endregion

            #region check params

            printHelp |= aWzInPath == null || aWzVer == (WZVariant)int.MinValue || aOutputPath == null;
            if (printHelp)
            {
                PrintHelp(set);
                return;
            }

            #endregion

            string[]             wzpaths = aWzInPath.Split('*');
            List <List <Frame> > framess = new List <List <Frame> >();
            string newPath = null, cWzPath = null;
            WZFile wz = null;
            foreach (string[] split in wzpaths.Select(wzpath => wzpath.Split('?')))
            {
                string inPath;
                if (newPath != null && split.Length == 1)
                {
                    inPath = split[0];
                }
                else
                {
                    newPath = split[0];
                    inPath  = split[1];
                }
                if (cWzPath != newPath && wz != null)
                {
                    wz.Dispose();
                }

                #region wz parsing

                if (cWzPath != newPath)
                {
                    wz = new WZFile(newPath, aWzVer, aWzNamesEnc);
                }
                cWzPath = newPath;
                #endregion

                #region getting single image

                WZCanvasProperty wzcp = wz.ResolvePath(inPath).ResolveUOL() as WZCanvasProperty;
                if (wzcp != null)
                {
                    Bitmap b = wzcp.Value;
                    if (aPngOutput)
                    {
                        OutputMethods.OutputPNG(b, aOutputPath);
                    }
                    else
                    {
                        OutputMethods.OutputGIF(b, aOutputPath);
                    }
                    return;
                }

                #endregion

                try {
                    List <Frame> data = InputMethods.InputWz(wz, inPath);
                    if (data.Count > 0)
                    {
                        framess.Add(data);
                    }
                } catch (Exception e) {
                    Console.WriteLine("An error occured while retrieving frames. Check your arguments.");
                    Console.WriteLine(e);
                    throw;
                }
            }
            IEnumerable <Frame> final = OffsetAnimator.Process(new Rectangle(aPadding, aPadding, aPadding, aPadding), aBgColor, aLoop, framess.ToArray());
            framess.ForEach(f => f.ForEach(g => g.Image.Dispose()));
            if (aPngOutput)
#if APNG
            { OutputMethods.OutputAPNG(final, aOutputPath); }
            else
#else
            { Console.WriteLine("APNG output not supported in this version; outputting GIF."); }
#endif
            { OutputMethods.OutputAGIF(final, aOutputPath); }
        }
Exemple #8
0
        private static void WriteNode(WZObject node, DumpState ds, BinaryWriter bw, uint nextChildID)
        {
            ds.AddNode(node);
            bw.Write(ds.AddString(node.Name));
            bw.Write(nextChildID);
            bw.Write((ushort)node.ChildCount);
            ushort type;

            if (node is WZDirectory || node is WZImage || node is WZSubProperty || node is WZConvexProperty ||
                node is WZNullProperty)
            {
                type = 0; // no data; children only (8)
            }
            else if (node is WZInt32Property || node is WZUInt16Property || node is WZInt64Property)
            {
                type = 1; // int32 (4)
            }
            else if (node is WZSingleProperty || node is WZDoubleProperty)
            {
                type = 2; // Double (0)
            }
            else if (node is WZStringProperty)
            {
                type = 3; // String (4)
            }
            else if (node is WZPointProperty)
            {
                type = 4; // (0)
            }
            else if (node is WZCanvasProperty)
            {
                type = 5; // (4)
            }
            else if (node is WZAudioProperty)
            {
                type = 6; // (4)
            }
            else
            {
                throw new InvalidOperationException("Unhandled WZ node type [1]");
            }

            bw.Write(type);

            if (node is WZInt32Property)
            {
                bw.Write((long)((WZInt32Property)node).Value);
            }
            else if (node is WZUInt16Property)
            {
                bw.Write((long)((WZUInt16Property)node).Value);
            }
            else if (node is WZInt64Property)
            {
                bw.Write(((WZInt64Property)node).Value);
            }
            else if (node is WZSingleProperty)
            {
                bw.Write((double)((WZSingleProperty)node).Value);
            }
            else if (node is WZDoubleProperty)
            {
                bw.Write(((WZDoubleProperty)node).Value);
            }
            else if (node is WZStringProperty)
            {
                bw.Write(ds.AddString(((WZStringProperty)node).Value));
            }
            else if (node is WZPointProperty)
            {
                Point pNode = ((WZPointProperty)node).Value;
                bw.Write(pNode.X);
                bw.Write(pNode.Y);
            }
            else if (node is WZCanvasProperty)
            {
                WZCanvasProperty wzcp = (WZCanvasProperty)node;
                bw.Write(ds.AddCanvas(wzcp));
                if (dumpImg)
                {
                    bw.Write((ushort)wzcp.Value.Width);
                    bw.Write((ushort)wzcp.Value.Height);
                    wzcp.Dispose();
                }
                else
                {
                    bw.Write(0);
                }
            }
            else if (node is WZAudioProperty)
            {
                WZAudioProperty wzmp = (WZAudioProperty)node;
                bw.Write(ds.AddMP3(wzmp));
                if (dumpSnd)
                {
                    bw.Write((uint)wzmp.Value.Length);
                    wzmp.Dispose();
                }
                else
                {
                    bw.Write(0);
                }
            }
            switch (type)
            {
            case 0:
                bw.Write(0L);
                break;

            case 3:
                bw.Write(0);
                break;
            }
        }
        public ExtractDamageSkinNumbers(string fileName, string outputLocation)
        {
            int count = 0;
            //var dmgSkins = JsonConvert.DeserializeObject<List<DamageSkin>>(File.ReadAllText(jsonLocation));


            WZFile        xz = new WZFile(fileName, WZVariant.MSEA, false);
            WZSubProperty damageSkinNumberImg = (WZSubProperty)xz.MainDirectory["BasicEff.img"]["damageSkin"];

            foreach (var numberType in damageSkinNumberImg)
            {
                Bitmap dmgSkinNumberPng = null;
                //foreach (var numberImg in numberType)
                //{
                //    foreach (var number in numberImg)
                //    {
                //        if (!(number is WZCanvasProperty))
                //        {
                //            break;
                //        }

                //        WZCanvasProperty test = (WZCanvasProperty)number;
                //        string[] pathNames = number.Path.Split('/');
                //        int itemId = 0;

                //        if (numberType.HasChild("ItemID"))
                //        {
                //            itemId = numberType["ItemID"].ValueOrDefault<Int32>(Int32.Parse(pathNames[3]));
                //        }

                //        if (numberType["NoRed0"]["3"].HasChild("_inlink"))
                //        {
                //            break;
                //            //string path = numberType["NoCri1"]["5"]["_inlink"].ValueOrDie<string>();
                //            //dmgSkinNumberPng = xz.ResolvePath($"BasicEff.img/{path}").ValueOrDie<Bitmap>();

                //        }

                //        else
                //        {
                //            dmgSkinNumberPng = numberType["NoRed0"]["3"].ValueOrDie<Bitmap>();
                //        }

                //        //Directory.CreateDirectory($@"{outputLocation}\");
                //        if (numberType.HasChild("ItemID"))
                //        {
                //            dmgSkinNumberPng.Save($@"{outputLocation}\{numberType.Name}_{itemId}.png", ImageFormat.Png);
                //        }
                //        else
                //        {
                //            dmgSkinNumberPng.Save($@"{outputLocation}\{numberType.Name}.png", ImageFormat.Png);

                //        }
                //        Console.WriteLine($"Exported damage skin - {pathNames[3]}");
                //    }
                //}

                if (numberType.HasChild("ItemID"))
                {
                    Console.WriteLine("hi");
                    foreach (var numberImg in numberType)
                    {
                        foreach (var number in numberImg)
                        {
                            if (!(number is WZCanvasProperty))
                            {
                                break;
                            }

                            WZCanvasProperty test      = (WZCanvasProperty)number;
                            string[]         pathNames = number.Path.Split('/');
                            int itemId = numberType["ItemID"].ValueOrDefault <Int32>(Int32.Parse(pathNames[3]));


                            if (number.HasChild("_inlink"))
                            {
                                break;
                                string path = number["_inlink"].ValueOrDie <string>();
                                dmgSkinNumberPng = xz.ResolvePath($"BasicEff.img/{path}").ValueOrDie <Bitmap>();
                            }
                            else
                            {
                                dmgSkinNumberPng = test.Value;
                            }

                            Directory.CreateDirectory($@"{outputLocation}\{pathNames[3]}_{itemId.ToString()}\{pathNames[4]}");
                            dmgSkinNumberPng.Save($@"{outputLocation}\{pathNames[3]}_{itemId.ToString()}\{pathNames[4]}\{pathNames[5]}.png", ImageFormat.Png);
                            Console.WriteLine("Exported damage skin");
                        }
                    }
                }
                else
                {
                    foreach (var numberImg in numberType)
                    {
                        foreach (var number in numberImg)
                        {
                            if (!(number is WZCanvasProperty))
                            {
                                break;
                            }

                            WZCanvasProperty test      = (WZCanvasProperty)number;
                            string[]         pathNames = number.Path.Split('/');

                            if (number.HasChild("_inlink"))
                            {
                                string path = number["_inlink"].ValueOrDie <string>();
                                dmgSkinNumberPng = xz.ResolvePath($"BasicEff.img/{path}").ValueOrDie <Bitmap>();
                            }
                            else
                            {
                                dmgSkinNumberPng = test.Value;
                            }

                            Directory.CreateDirectory($@"{outputLocation}\{pathNames[3]}\{pathNames[4]}");
                            dmgSkinNumberPng.Save($@"{outputLocation}\{pathNames[3]}\{pathNames[4]}\{pathNames[5]}.png", ImageFormat.Png);
                            Console.WriteLine($"Exported damage skin - {pathNames[3]}");
                        }
                    }
                }
                count++;
            }
            Console.WriteLine($"Successfully dumped {count.ToString()} number of damage skins");
            Console.ReadKey();
        }
        public ExtractImg(string fileName, string location, string jsonLocation, string iconLocation)
        {
            int count    = 0;
            var dmgSkins = JsonConvert.DeserializeObject <List <DamageSkin> >(File.ReadAllText(jsonLocation));

            Directory.CreateDirectory(location);
            Directory.CreateDirectory(iconLocation);

            WZFile  xz          = new WZFile(fileName, WZVariant.MSEA, false);
            WZImage dmgSkinImg  = (WZImage)xz.MainDirectory["Consume"]["0243.img"];
            WZImage dmgSkinImg2 = (WZImage)xz.MainDirectory["Consume"]["0263.img"];

            foreach (var itemImg in dmgSkinImg)
            {
                foreach (var jsonDmg in dmgSkins)
                {
                    //Console.Write("debug");
                    string itemId = "0" + jsonDmg.itemId;

                    if (itemId.StartsWith("0243"))
                    {
                        if (itemImg.Name == itemId)
                        {
                            if (itemImg["info"].HasChild("sample"))
                            {
                                Bitmap           dmgSkinPng     = null;
                                Bitmap           dmgSkinIconPng = null;
                                WZCanvasProperty iconTest       = null;
                                WZCanvasProperty test           = (WZCanvasProperty)itemImg["info"]["sample"];

                                if (itemImg["info"].HasChild("icon"))
                                {
                                    if (itemImg["info"]["icon"].Type == WZObjectType.UOL)
                                    {
                                        iconTest = (WZCanvasProperty)itemImg["info"]["iconRaw"];
                                    }
                                    else
                                    {
                                        iconTest = (WZCanvasProperty)itemImg["info"]["icon"];
                                    }

                                    if (iconTest.HasChild("_outlink"))
                                    {
                                        string path = iconTest["_outlink"].ValueOrDie <string>();
                                        path           = path.Substring(path.IndexOf('/') + 1);
                                        dmgSkinIconPng = xz.ResolvePath(path).ValueOrDie <Bitmap>();
                                    }
                                    else if (iconTest.HasChild("_inlink"))
                                    {
                                        string   path     = iconTest["_inlink"].ValueOrDie <string>();
                                        string[] pathList = path.Split('/');
                                        dmgSkinIconPng = dmgSkinImg[pathList[0]][pathList[1]][pathList[2]].ValueOrDie <Bitmap>();
                                    }
                                    else
                                    {
                                        dmgSkinIconPng = iconTest.Value;
                                    }
                                }
                                // Damage Skin Section
                                if (test.HasChild("_outlink"))
                                {
                                    string path = test["_outlink"].ValueOrDie <string>();
                                    path       = path.Substring(path.IndexOf('/') + 1);
                                    dmgSkinPng = xz.ResolvePath(path).ValueOrDie <Bitmap>();
                                }
                                else if (test.HasChild("_inlink"))
                                {
                                    string   path     = test["_inlink"].ValueOrDie <string>();
                                    string[] pathList = path.Split('/');
                                    dmgSkinPng = dmgSkinImg[pathList[0]][pathList[1]][pathList[2]].ValueOrDie <Bitmap>();
                                }
                                else
                                {
                                    dmgSkinPng = test.Value;
                                }
                                dmgSkinPng.Save($@"{location}\{itemId}.png", ImageFormat.Png);
                                dmgSkinIconPng.Save($@"{iconLocation}\{itemId}.png", ImageFormat.Png);
                                Console.WriteLine($"Dumped {jsonDmg.itemId} - {jsonDmg.itemName}");
                                count++;
                            }
                        }
                    }
                }
            }

            foreach (var itemImg2 in dmgSkinImg2)
            {
                foreach (var jsonDmg in dmgSkins)
                {
                    //Console.Write("debug");
                    string itemId = "0" + jsonDmg.itemId;
                    if (itemId.StartsWith("0263"))
                    {
                        if (itemImg2.Name == itemId)
                        {
                            if (itemImg2["info"].HasChild("sample"))
                            {
                                Bitmap           dmgSkinPng     = null;
                                Bitmap           dmgSkinIconPng = null;
                                WZCanvasProperty iconTest       = null;
                                WZCanvasProperty test           = (WZCanvasProperty)itemImg2["info"]["sample"];

                                if (itemImg2["info"].HasChild("icon"))
                                {
                                    if (itemImg2["info"]["icon"].Type == WZObjectType.UOL)
                                    {
                                        iconTest = (WZCanvasProperty)itemImg2["info"]["iconRaw"];
                                    }
                                    else
                                    {
                                        iconTest = (WZCanvasProperty)itemImg2["info"]["icon"];
                                    }

                                    if (iconTest.HasChild("_outlink"))
                                    {
                                        string path = iconTest["_outlink"].ValueOrDie <string>();
                                        path           = path.Substring(path.IndexOf('/') + 1);
                                        dmgSkinIconPng = xz.ResolvePath(path).ValueOrDie <Bitmap>();
                                    }
                                    else if (iconTest.HasChild("_inlink"))
                                    {
                                        string   path     = iconTest["_inlink"].ValueOrDie <string>();
                                        string[] pathList = path.Split('/');
                                        dmgSkinIconPng = dmgSkinImg2[pathList[0]][pathList[1]][pathList[2]].ValueOrDie <Bitmap>();
                                    }
                                    else
                                    {
                                        dmgSkinIconPng = iconTest.Value;
                                    }
                                }
                                // damage skin
                                if (test.HasChild("_outlink"))
                                {
                                    string path = test["_outlink"].ValueOrDie <string>();
                                    path       = path.Substring(path.IndexOf('/') + 1);
                                    dmgSkinPng = xz.ResolvePath(path).ValueOrDie <Bitmap>();
                                }
                                else if (test.HasChild("_inlink"))
                                {
                                    string   path     = test["_inlink"].ValueOrDie <string>();
                                    string[] pathList = path.Split('/');
                                    if (path.Contains("2630086"))
                                    {
                                        dmgSkinPng = dmgSkinImg2[pathList[0]][pathList[1]][pathList[2]][pathList[3]].ValueOrDie <Bitmap>();
                                    }
                                    else
                                    {
                                        dmgSkinPng = dmgSkinImg2[pathList[0]][pathList[1]][pathList[2]].ValueOrDie <Bitmap>();
                                    }
                                }
                                else
                                {
                                    dmgSkinPng = test.Value;
                                }
                                dmgSkinIconPng = iconTest.Value;
                                dmgSkinPng.Save($@"{location}\{itemId}.png", ImageFormat.Png);
                                dmgSkinIconPng.Save($@"{iconLocation}\{itemId}.png", ImageFormat.Png);
                                Console.WriteLine($"Dumped {jsonDmg.itemId} - {jsonDmg.itemName}");
                                count++;
                            }
                        }
                    }
                }
            }

            Console.WriteLine($"Successfully dumped {count.ToString()} number of damage skins");
            Console.ReadKey();
        }