public static List <MAPINFO> ExtractMap(ScriptNode rawSprite)
            {
                var ret = new List <MAPINFO>();
                var map = rawSprite.GetNode("map");

                if (map != null)
                {
                    foreach (var mapNode in map)
                    {
                        var x = mapNode.GetInt32("x");
                        var y = mapNode.GetInt32("y");

                        var x2 = x; // Would otherwise be gotten from Vector2D, but are no-ops for Vector2D
                        var y2 = y;

                        ret.Add(new MAPINFO
                        {
                            Name     = mapNode.Name,
                            Position = new Point(
                                (x2 + x) / 2,
                                (y2 + y) / 2
                                ),
                        });
                    }
                }

                return(ret);
            }
Esempio n. 2
0
        public static ScriptNode FindAnimateableProp(ScriptNode prop)
        {
            if (prop.GetCanvas() != null)
            {
                return(prop);
            }

            string[] names = new[]
            {
                "move", "fly", "die", "stand", "iconRaw", "icon"
                , "effect/default"
                , "effect"
            };

            // Find any node that is usable for rendering
            foreach (var name in names)
            {
                var x = prop.GetNode(name);
                if (x == null)
                {
                    continue;
                }
                return(x);
            }

            if (prop.HasChild("0"))
            {
                return(prop);
            }

            return(null);
        }
Esempio n. 3
0
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (animationForm == null || animationForm.IsDisposed)
            {
                animationForm = null;
                Program.MainForm.tvData.AfterSelect -= treeView1_AfterSelect;
                return;
            }

            if (e.Node == null)
            {
                return;
            }
            if (!(e.Node is WZTreeNode))
            {
                return;
            }


            {
                var    wtn        = (WZTreeNode)e.Node;
                var    scriptNode = _mainScriptNode.GetNode(wtn.GetFullPath());
                string filename;
                var    frames = TryRenderNode(scriptNode, out filename);

                if (frames != null && frames.Count > 0)
                {
                    animationForm.FileName = filename;
                    animationForm.LoadFrames(frames);
                }
            }
        }
Esempio n. 4
0
        public void Start(ScriptNode mainScriptNode)
        {
            Console.WriteLine("Starting...");
            foreach (var mapNode in mainScriptNode.GetNode("Map/Map"))
            {
                Console.WriteLine(string.Format("{0}", mapNode.Name));
                if (!mapNode.Name.StartsWith("Map"))
                {
                    continue;
                }

                foreach (var actualMap in mapNode)
                {
                    Console.WriteLine(string.Format("- {0}", actualMap.Name));

                    var infoNode = actualMap["info"];
                    if (infoNode == null)
                    {
                        Console.WriteLine("Missing info node?");
                    }
                    else
                    {
                        object x;
                        if ((x = infoNode["link"]) != null)
                        {
                            Console.WriteLine("Link: " + x);
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        public void Start(ScriptNode mainScriptNode)
        {
            var weaponNode = mainScriptNode.GetNode("Skill/3300.img/skill/33001000/weapon");

            weaponNode.SetString("Boobs.");
            weaponNode.UpdateTreeNodes();

            return;

            Console.WriteLine("Starting...");
            foreach (var mapNode in mainScriptNode.GetNode("Map/Map"))
            {
                Console.WriteLine(string.Format("{0}", mapNode.Name));
                if (!mapNode.Name.StartsWith("Map"))
                {
                    continue;
                }

                foreach (var actualMap in mapNode)
                {
                    Console.WriteLine(string.Format("- {0}", actualMap.Name));

                    var infoNode = actualMap["info"];
                    if (infoNode == null)
                    {
                        Console.WriteLine("Missing info node?");
                    }
                    else
                    {
                        object x;
                        if ((x = infoNode["link"]) != null)
                        {
                            Console.WriteLine("Link: " + x);
                        }
                    }
                }
            }
        }
 public ScriptNode GetNode(ScriptNode mainNode)
 {
     return(mainNode.GetNode(NodePath));
 }
        private void LoadData()
        {
            if (_mainNode.GetNode("Base/zmap.img") == null)
            {
                MessageBox.Show("Unable to load Character Gen Form, please load Base, Character and String folders/wzs");
                return;
            }

            LoadBlock("zmap.img", delegate
            {
                var arr = new List <string>();
                foreach (var node in _mainNode.GetNode("Base/zmap.img"))
                {
                    arr.Add(node.Name);
                }

                arr.Reverse();

                zmap = arr.ToArray();
            });

            LoadBlock("smap.img", delegate
            {
                smap = new Dictionary <string, string>();
                foreach (var node in _mainNode.GetNode("Base/smap.img"))
                {
                    smap[node.Name] = node.GetString();
                }
            });

            LoadBlock("Skins", delegate
            {
                TreeNode skinNode = null;
                Invoke((MethodInvoker) delegate { skinNode = allPossibleItems.Nodes.Add("Skin"); });
                foreach (var sn in _mainNode.GetNode("Character/"))
                {
                    if (!sn.Name.EndsWith(".img"))
                    {
                        continue;
                    }
                    var nameWithoutImg    = sn.Name.Remove(sn.Name.Length - 4);
                    var nameWithoutZeroes = nameWithoutImg.TrimStart('0');
                    if (!nameWithoutZeroes.StartsWith("2"))
                    {
                        continue;
                    }
                    int id;
                    if (!int.TryParse(nameWithoutZeroes, out id))
                    {
                        continue;
                    }

                    Invoke((MethodInvoker) delegate
                    {
                        var node = skinNode.Nodes.Add("Skin color " + (id % 1000));
                        node.Tag = new ChosenItem
                        {
                            SelectedPath = node.FullPath,
                            NodePath     = sn.GetFullPath(),
                            ID           = (id % 1000),
                        };
                    });
                }
            });


            LoadBlock("Equip strings", delegate
            {
                var itemNode = _mainNode.GetNode("String/Item.img");
                ScriptNode scriptnodeToProcess;
                if (itemNode != null)
                {
                    scriptnodeToProcess = itemNode["Eqp"];
                }
                else
                {
                    // Load separate files
                    scriptnodeToProcess = _mainNode.GetNode("String/Eqp.img/Eqp");
                }

                if (scriptnodeToProcess != null)
                {
                    Invoke((MethodInvoker) delegate
                    {
                        LoadScriptNodeToTreeView(scriptnodeToProcess, allPossibleItems.Nodes);
                    });
                }
            });

            Invoke((MethodInvoker) delegate
            {
                filterNodes();
                UseWaitCursor = false;
            });
        }
Esempio n. 8
0
        private static List <FrameInfo> TryRenderNode(ScriptNode node, out string filename)
        {
            filename = "??";

resolveAgain:
            {
                // Try to resolve UOL
                while (node.Get() is WzUOL)
                {
                    var uol     = node.Get() as WzUOL;
                    var path    = uol.ActualPath();
                    var newNode = node.GetNode(path);
                    if (newNode == null)
                    {
                        return(null);
                    }
                    node = newNode;
                }
            }

            {
                // If its a single canvas, render that
                var canvas = node.GetCanvas();
                if (canvas != null)
                {
                    filename = GetFilenameForNode(node);
                    return(new List <FrameInfo>(RenderFrame(canvas)));
                }
            }

            {
                // If its a prop, figure out if we can render it
                var animateableProp = FindAnimateableProp(node);
                if (animateableProp == null)
                {
                    var info = node.GetNode("info");
                    if (info == null)
                    {
                        return(null);
                    }

                    // Maybe we can find a link node
                    var link = node.GetString("info/link");
                    if (link != null)
                    {
                        var path = "../" + link + ".img";
                        Console.WriteLine("Trying to get node @ {0}", path);
                        var tmp = node.GetNode(path);
                        if (tmp != null)
                        {
                            node = tmp;
                            goto resolveAgain;
                        }
                    }

                    // Figure out if the info node is any good
                    animateableProp = FindAnimateableProp(info);
                    if (animateableProp != null && animateableProp is ScriptNode)
                    {
                        node = animateableProp;
                        goto resolveAgain;
                    }
                }
                else
                {
                    node = animateableProp;
                }
            }

            {
                // Try to render elements
                var frames = new List <FrameInfo>();

                bool indexesAreImageOrUOL = true;
                bool foundAny             = false;
                for (var i = 0; ; i++)
                {
                    var p = node.Get(i.ToString());
                    if (p == null)
                    {
                        break;
                    }
                    foundAny = true;
                    if (!(p is WzCanvas || p is WzUOL))
                    {
                        if (i == 0)
                        {
                            continue;
                        }
                        indexesAreImageOrUOL = false;
                        break;
                    }

                    frames.AddRange(RenderFrame(p));
                }

                if (foundAny && indexesAreImageOrUOL)
                {
                    if (node.GetInt32("zigzag", 0) == 1)
                    {
                        // Apply a zigzag
                        if (frames.Count > 2)
                        {
                            // Zigzag
                            var tmp = new List <FrameInfo>(frames);
                            tmp.RemoveAt(0);
                            tmp.RemoveAt(tmp.Count - 1);
                            tmp.Reverse();
                            frames.AddRange(tmp);
                        }
                    }
                }

                filename = GetFilenameForNode(node);
                return(frames);
            }
        }
Esempio n. 9
0
        private string GetString(StringType type, int id, string field = "name")
        {
            int inv = id / 1000000;

            if (type == StringType.Item && inv == 1)
            {
                // Oh boy, this one is a bit harder.
                // Eqp.img/Eqp/categoryname/id ...
                // Lets just iterate over each category and try to find it

                foreach (var eqpCategory in MainScriptNode.GetNode("String/Eqp.img/Eqp"))
                {
                    var eqpNode = eqpCategory.GetNode(id.ToString());
                    if (eqpNode != null)
                    {
                        return(eqpNode.GetString(field));
                    }
                }

                return("??? Unknown equip " + id + " ???");
            }

            if (type == StringType.Map)
            {
                // Maps have about the same as equips. There's a category....
                foreach (var mapCategory in MainScriptNode.GetNode("String/Map.img"))
                {
                    var mapNode = mapCategory.GetNode(id.ToString());
                    if (mapNode != null)
                    {
                        return(mapNode.GetString(field));
                    }
                }
                return("??? Unknown map " + id + " ???");
            }


            string mainNode = ".";
            string idStr    = null;

            switch (type)
            {
            case StringType.Mob: mainNode = "Mob.img"; break;

            case StringType.Skill:
                mainNode = "Skill.img";
                idStr    = id.ToString("D7");
                break;

            case StringType.Npc: mainNode = "Npc.img"; break;

            case StringType.Item:
            {
                switch (inv)
                {
                case 2: mainNode = "Consume.img"; break;

                case 3: mainNode = "Ins.img"; break;

                case 4: mainNode = "Etc.img/Etc"; break;

                case 5: mainNode = "Cash.img"; break;
                }
                break;
            }
            }

            return(GetString(string.Format("String/{0}/{1}/{2}", mainNode, idStr ?? id.ToString(), field)));
        }
Esempio n. 10
0
        public void Start(ScriptNode mainScriptNode)
        {
            Program.MainForm.BeginTreeUpdate();
            var stringsNPC = new Dictionary <int, string>();
            var stringsMob = new Dictionary <int, string>();
            var stringsMap = new Dictionary <int, string>();


            Console.WriteLine("Loading names...");
            string name, streetName, mapName;

            foreach (var node in mainScriptNode.GetNode("String/Mob.img"))
            {
                var id = int.Parse(node.Name);
                GetString(node, "name", out name);
                stringsMob[id] = name;
            }
            foreach (var node in mainScriptNode.GetNode("String/Npc.img"))
            {
                var id = int.Parse(node.Name);
                GetString(node, "name", out name);
                stringsNPC[id] = name;
            }
            foreach (var section in mainScriptNode.GetNode("String/Map.img"))
            {
                foreach (var node in section)
                {
                    var id = int.Parse(node.Name);
                    GetString(node, "streetName", out streetName);
                    GetString(node, "mapName", out mapName);
                    name = "";
                    if (streetName != "")
                    {
                        name = streetName;
                    }
                    if (mapName != "")
                    {
                        name = (name != "" ? name + " - " : "") + mapName;
                    }
                    stringsMap[id] = name;
                }
            }

            Console.WriteLine("Mobs: {0}", stringsMob.Count);
            Console.WriteLine("Npcs: {0}", stringsNPC.Count);

            Console.WriteLine("Setting names...");
            foreach (var node in mainScriptNode.GetNode("Mob"))
            {
                var id = NameToID(node);
                if (stringsMob.TryGetValue(id, out name))
                {
                    var tn = node.TryGetTreeNode();
                    if (tn != null)
                    {
                        tn.SetAdditionalInfo("ign", name, true);
                    }
                }
                else
                {
                    Console.WriteLine("No name for Mob {0}", id);
                }
            }
            foreach (var node in mainScriptNode.GetNode("Npc"))
            {
                var id = NameToID(node);
                if (stringsNPC.TryGetValue(id, out name))
                {
                    var tn = node.TryGetTreeNode();
                    if (tn != null)
                    {
                        tn.SetAdditionalInfo("ign", name, true);
                    }
                }
                else
                {
                    Console.WriteLine("No name for NPC {0}", id);
                }
            }
            foreach (var mapCategory in mainScriptNode.GetNode("Map/Map"))
            {
                if (!mapCategory.Name.StartsWith("Map"))
                {
                    continue;
                }

                foreach (var node in mapCategory)
                {
                    var id = NameToID(node);
                    if (stringsMap.TryGetValue(id, out name))
                    {
                        var tn = node.TryGetTreeNode();
                        if (tn != null)
                        {
                            tn.SetAdditionalInfo("ign", name, true);
                        }
                    }
                    else
                    {
                        Console.WriteLine("No name for Map {0}", id);
                    }
                }
            }

            Console.WriteLine("Done.");
            Program.MainForm.EndTreeUpdate();
        }