コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void addRootFromTypeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var settings = new NewRootSettings();

            using (HSDTypeDialog t = new HSDTypeDialog())
            {
                if (t.ShowDialog() == DialogResult.OK)
                {
                    using (PropertyDialog d = new PropertyDialog("New Root", settings))
                    {
                        if (d.ShowDialog() == DialogResult.OK)
                        {
                            var root = new HSDRootNode();

                            root.Name = settings.Symbol;
                            root.Data = (HSDAccessor)Activator.CreateInstance(t.HSDAccessorType);

                            RawHSDFile.Roots.Add(root);

                            RefreshTree();
                        }
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="FileName"></param>
        /// <param name="animation"></param>
        /// <param name="skeleton"></param>
        private void ExportAnimJoint(string FileName, SBAnimation animation, SBSkeleton skeleton)
        {
            HSDRawFile  file = new HSDRawFile();
            HSDRootNode root = new HSDRootNode();

            if (HSDSettings.RootName == "" || HSDSettings.RootName == null)
            {
                HSDSettings.RootName = System.IO.Path.GetFileNameWithoutExtension(FileName);
            }

            if (HSDSettings.RootName == "" || HSDSettings.RootName == null)
            {
                HSDSettings.RootName = animation.Name;
            }

            root.Name = HSDSettings.RootName;

            if (root.Name == null)
            {
                System.Windows.Forms.MessageBox.Show($"Warning, the root name does not end with \"_figatree\"\n{root.Name}");
            }

            file.Roots.Add(root);

            var joint = new HSD_AnimJoint();

            EncodeAnimJoint(skeleton.Bones[0], joint, animation);
            root.Data = joint;

            file.Save(FileName);
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="root"></param>
        public static void AddRoot(string name, HSDAccessor accesor)
        {
            var root = new HSDRootNode()
            {
                Name = name,
                Data = accesor
            };

            Instance.RawHSDFile.Roots.Add(root);
            Instance.treeView1.Nodes.Add(new DataNode(name, accesor, root: root));
        }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void addRootFromFileToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            var f = Tools.FileIO.OpenFile("All Files |*.*");

            if (f != null)
            {
                var root = new HSDRootNode();

                root.Name = System.IO.Path.GetFileNameWithoutExtension(f);
                root.Data = new HSDAccessor();
                root.Data._s.SetData(System.IO.File.ReadAllBytes(f));

                RawHSDFile.Roots.Add(root);

                RefreshTree();
            }
        }
コード例 #5
0
        /// <summary>
        /// Injects a given symbol into a dat
        /// If symbol already exists it is overwritten
        /// </summary>
        /// <param name="f"></param>
        /// <param name="symbolName"></param>
        /// <param name="function"></param>
        public static void InjectSymbolIntoDat(HSDRawFile f, string symbolName, HSDAccessor function)
        {
            // generate root
            var root = new HSDRootNode();

            root.Name = symbolName;
            root.Data = function;

            // if this symbol already exists in file, replace it
            foreach (var ro in f.Roots)
            {
                if (ro.Name.Equals(root.Name))
                {
                    ro.Data = root.Data;
                }
            }

            // if symbol is not in file, then add it
            if (f.Roots.FindIndex(e => e.Name == root.Name) == -1)
            {
                f.Roots.Add(root);
            }
        }
コード例 #6
0
        public static void Deconstruct(string plFilePath, string ajFilePath, string outputFolder)
        {
            var plfile = new HSDRawFile(plFilePath);

            var path = Path.GetDirectoryName(plFilePath) + "\\" + outputFolder + "\\";

            Directory.CreateDirectory(path);

            var data = plfile.Roots[0].Data as SBM_FighterData;

            if (data == null)
            {
                return;
            }

            var ajfile = new HSDRawFile(ajFilePath);

            foreach (var prop in data.GetType().GetProperties())
            {
                var val = prop.GetValue(data) as HSDAccessor;

                if (val == null)
                {
                    continue;
                }
                if (prop.PropertyType == typeof(SBM_CommonFighterAttributes))
                {
                    var attr = prop.GetValue(data) as SBM_CommonFighterAttributes;
                    using (StreamWriter w = new StreamWriter(new FileStream(path + prop.Name + ".ini", FileMode.Create)))
                    {
                        foreach (var v in attr.GetType().GetProperties())
                        {
                            if (v.Name.Equals("TrimmedSize"))
                            {
                                continue;
                            }
                            w.WriteLine($"{v.Name}={v.GetValue(attr)}");
                        }
                    }
                }
                else
                if (prop.Name.Equals("SubActionTable"))
                {
                    ScriptFile f = new ScriptFile();

                    f.Actions = new ActionGroup[val._s.Length / 0x18];

                    var ActionDecompiler = new ActionDecompiler();
                    HashSet <string> ExportedAnimations = new HashSet <string>();

                    for (int i = 0; i < f.Actions.Length; i++)
                    {
                        SBM_FighterAction subaction = new HSDRaw.Melee.Pl.SBM_FighterAction();
                        subaction._s = val._s.GetEmbeddedStruct(0x18 * i, 0x18);

                        if (!ExportedAnimations.Contains(subaction.Name) && subaction.Name != null && subaction.Name != "")
                        {
                            ExportedAnimations.Add(subaction.Name);
                            if (ajFilePath != null && File.Exists(ajFilePath))
                            {
                                using (BinaryReaderExt r = new BinaryReaderExt(new FileStream(ajFilePath, FileMode.Open)))
                                {
                                    var animdata = r.GetSection((uint)subaction.AnimationOffset, subaction.AnimationSize);
                                    File.WriteAllBytes(path + "Animations\\" + subaction.Name + ".dat", animdata);
                                }
                            }
                        }

                        ActionGroup g = new ActionGroup();
                        g.animation_name = subaction.Name;
                        g.flags          = (int)subaction.Flags;
                        g.script         = ActionDecompiler.Decompile("Func_" + i.ToString("X3"), subaction.SubAction);
                        //g.script =
                        g.off        = subaction.AnimationOffset;
                        g.size       = subaction.AnimationSize;
                        f.Actions[i] = g;

                        Console.WriteLine(i + " " + subaction.Name + " " + subaction._s.GetReference <HSDAccessor>(0x0C)._s.References.Count);
                    }

                    XmlSerializer writer = new XmlSerializer(typeof(ScriptFile));
                    using (var w = new XmlTextWriter(new FileStream(path + prop.Name + ".txt", FileMode.Create), Encoding.UTF8))
                    {
                        w.Formatting = Formatting.Indented;
                        writer.Serialize(w, f);
                    }
                }
                else
                {
                    HSDRootNode root = new HSDRootNode();

                    root.Name = prop.Name;

                    root.Data = val;

                    HSDRawFile file = new HSDRawFile();
                    file.Roots.Add(root);

                    file.Save(path + prop.Name + ".dat");

                    Console.WriteLine(prop.Name + " " + val._s.GetSubStructs().Count);
                }
            }
        }
コード例 #7
0
        public static void Reconstruct(string filepath, string animPath, string directory, string rootName)
        {
            var path = Path.GetDirectoryName(directory);

            HSDRawFile file = new HSDRawFile();

            HSDRootNode root = new HSDRootNode();

            root.Name = rootName;
            var ftData = new SBM_FighterData();

            root.Data = ftData;
            file.Roots.Add(root);
            var prop = root.Data.GetType().GetProperties().ToList();

            foreach (var f in Directory.GetFiles(directory))
            {
                if (f.EndsWith(".dat"))
                {
                    HSDRawFile chunk = new HSDRawFile(f);
                    Console.WriteLine(f + " " + chunk.Roots.Count);
                    var property = prop.Find(e => e.Name == chunk.Roots[0].Name);

                    if (property != null)
                    {
                        var newt = Activator.CreateInstance(property.PropertyType);
                        {
                            var dset = newt as HSDAccessor;
                            if (dset != null)
                            {
                                dset._s = chunk.Roots[0].Data._s;
                            }
                        }
                        property.SetValue(root.Data, newt);
                    }
                }
                else if (f.EndsWith(".ini"))
                {
                    SBM_CommonFighterAttributes attr = new SBM_CommonFighterAttributes();
                    using (StreamReader r = new StreamReader(new FileStream(f, FileMode.Open)))
                    {
                        foreach (var v in attr.GetType().GetProperties())
                        {
                            if (v.Name.Equals("TrimmedSize"))
                            {
                                continue;
                            }
                            var line = r.ReadLine().Split('=');
                            if (line.Length < 2 || line[0] != v.Name)
                            {
                                throw new InvalidDataException("Invalid Attribute " + string.Join("=", line));
                            }
                            if (v.PropertyType == typeof(int))
                            {
                                v.SetValue(attr, int.Parse(line[1].Trim()));
                            }
                            if (v.PropertyType == typeof(float))
                            {
                                v.SetValue(attr, float.Parse(line[1].Trim()));
                            }
                        }
                    }
                    ftData.Attributes = attr;
                }
                else if (f.EndsWith(".txt"))
                {
                    XmlSerializer writer = new XmlSerializer(typeof(ScriptFile));
                    var           script = (ScriptFile)writer.Deserialize(new FileStream(f, FileMode.Open));

                    Dictionary <string, Tuple <int, int> > animationToOffset = new Dictionary <string, Tuple <int, int> >();

                    List <SBM_FighterAction> SubActions = new List <SBM_FighterAction>();
                    Dictionary <SBM_FighterAction, string> subActionToScript = new Dictionary <SBM_FighterAction, string>();

                    Dictionary <string, HSDStruct> stringToStruct = new Dictionary <string, HSDStruct>();

                    using (BinaryWriter w = new BinaryWriter(new FileStream(animPath, FileMode.Create)))
                    {
                        foreach (var s in script.Actions)
                        {
                            SBM_FighterAction subaction = new SBM_FighterAction();
                            subaction.Flags = (uint)s.flags;
                            if (s.animation_name != null)
                            {
                                if (!stringToStruct.ContainsKey(s.animation_name))
                                {
                                    var    namestruct = new HSDStruct();
                                    byte[] data       = new byte[s.animation_name.Length + 1];
                                    var    bytes      = UTF8Encoding.UTF8.GetBytes(s.animation_name);
                                    for (int i = 0; i < s.animation_name.Length; i++)
                                    {
                                        data[i] = bytes[i];
                                    }
                                    namestruct.SetData(data);
                                    stringToStruct.Add(s.animation_name, namestruct);
                                }
                                subaction._s.SetReferenceStruct(0, stringToStruct[s.animation_name]);
                                //subaction.Name = s.animation_name;
                                if (!animationToOffset.ContainsKey(s.animation_name))
                                {
                                    if (File.Exists(path + "\\Animations\\" + s.animation_name + ".dat"))
                                    {
                                        var data = File.ReadAllBytes(path + "\\Animations\\" + s.animation_name + ".dat");
                                        animationToOffset.Add(s.animation_name, new Tuple <int, int>((int)w.BaseStream.Position, data.Length));
                                        w.Write(data);
                                        if (w.BaseStream.Length % 0x20 != 0)
                                        {
                                            var padd = new byte[0x20 - (w.BaseStream.Position % 0x20)];
                                            for (int i = 0; i < padd.Length; i++)
                                            {
                                                padd[i] = 0xFF;
                                            }
                                            w.Write(padd);
                                        }
                                    }
                                    else
                                    {
                                        throw new FileNotFoundException("Could not find animation " + path + "\\Animations\\" + s.animation_name + ".dat");
                                    }
                                }
                                subaction.AnimationOffset = animationToOffset[s.animation_name].Item1;
                                subaction.AnimationSize   = animationToOffset[s.animation_name].Item2;
                            }

                            if (s.script != null)
                            {
                                ActionCompiler.Compile(s.script);
                                subActionToScript.Add(subaction, s.script);
                            }

                            SubActions.Add(subaction);
                        }
                    }

                    ftData.FighterActionTable = new SBM_FighterActionTable();

                    ActionCompiler.LinkStructs();

                    ftData.FighterActionTable.Commands = SubActions.ToArray();

                    Console.WriteLine("recompiled count " + ftData.FighterActionTable._s.GetSubStructs().Count);
                }
            }

            file.Save(filepath);
        }
コード例 #8
0
        public JOBJContextMenu() : base()
        {
            MenuItem Import = new MenuItem("Import Model From File");

            Import.Click += (sender, args) =>
            {
                if (MainForm.SelectedDataNode.Accessor is HSD_JOBJ root)
                {
                    MainForm.SelectedDataNode.Collapse();
                    ModelImporter.ReplaceModelFromFile(root);
                }
            };
            MenuItems.Add(Import);


            MenuItem GenerateMatAnimJoint = new MenuItem("Generate and Export MatAnimJoint Structure");

            GenerateMatAnimJoint.Click += (sender, args) =>
            {
                if (MainForm.SelectedDataNode.Accessor is HSD_JOBJ root)
                {
                    var file = Tools.FileIO.SaveFile(ApplicationSettings.HSDFileFilter, "matanim_joint.dat");
                    if (file != null)
                    {
                        HSDRawFile  f = new HSDRawFile();
                        HSDRootNode r = new HSDRootNode();
                        r.Name = "matanim_joint";
                        r.Data = GenerateMatAnimJointFromJOBJ(root);
                        f.Roots.Add(r);
                        f.Save(file);
                    }
                }
            };
            MenuItems.Add(GenerateMatAnimJoint);

            MenuItem addChild = new MenuItem("Add Child");

            MenuItems.Add(addChild);

            MenuItem createJOBJ = new MenuItem("From Scratch");

            createJOBJ.Click += (sender, args) =>
            {
                if (MainForm.SelectedDataNode.Accessor is HSD_JOBJ root)
                {
                    root.AddChild(new HSD_JOBJ()
                    {
                        SX    = 1,
                        SY    = 1,
                        SZ    = 1,
                        Flags = JOBJ_FLAG.CLASSICAL_SCALING | JOBJ_FLAG.ROOT_XLU
                    });
                    MainForm.SelectedDataNode.Refresh();
                }
            };
            addChild.MenuItems.Add(createJOBJ);


            MenuItem createJOBJFromFile = new MenuItem("From File");

            createJOBJFromFile.Click += (sender, args) =>
            {
                if (MainForm.SelectedDataNode.Accessor is HSD_JOBJ root)
                {
                    var f = Tools.FileIO.OpenFile(ApplicationSettings.HSDFileFilter);
                    if (f != null)
                    {
                        HSDRaw.HSDRawFile file = new HSDRaw.HSDRawFile(f);

                        var node = file.Roots[0].Data;
                        if (node is HSD_JOBJ newchild)
                        {
                            root.AddChild(newchild);
                        }
                    }
                    MainForm.SelectedDataNode.Refresh();
                }
            };
            addChild.MenuItems.Add(createJOBJFromFile);
        }
コード例 #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="FileName"></param>
        /// <param name="animation"></param>
        /// <param name="skeleton"></param>
        private void ExportFigaTree(string FileName, SBAnimation animation, SBSkeleton skeleton)
        {
            HSDRawFile  file = new HSDRawFile();
            HSDRootNode root = new HSDRootNode();

            if (HSDSettings.RootName == "" || HSDSettings.RootName == null)
            {
                HSDSettings.RootName = System.IO.Path.GetFileNameWithoutExtension(FileName);
            }

            if (HSDSettings.RootName == "" || HSDSettings.RootName == null)
            {
                HSDSettings.RootName = animation.Name;
            }

            root.Name = HSDSettings.RootName;

            if (root.Name == null || !root.Name.EndsWith("_figatree"))
            {
                System.Windows.Forms.MessageBox.Show($"Warning, the root name does not end with \"_figatree\"\n{root.Name}");
            }

            file.Roots.Add(root);

            var nodes = new List <FigaTreeNode>();

            int boneIndex = -1;

            foreach (var skelnode in skeleton.Bones)
            {
                FigaTreeNode animNode = new FigaTreeNode();
                nodes.Add(animNode);

                boneIndex++;
                // skip trans n and rotn tracks
                if (boneIndex == 0)
                {
                    continue;
                }

                var node = animation.TransformNodes.Find(e => e.Name == skelnode.Name);
                if (node == null)
                {
                    continue;
                }

                foreach (var track in node.Tracks)
                {
                    HSD_Track animTrack = new HSD_Track();
                    animTrack.FOBJ       = EncodeFOBJ(track);
                    animTrack.DataLength = (short)animTrack.FOBJ.Buffer.Length;
                    animNode.Tracks.Add(animTrack);
                }
            }

            HSD_FigaTree tree = new HSD_FigaTree();

            tree.FrameCount = animation.FrameCount;
            tree.Type       = 1;
            tree.Nodes      = nodes;

            root.Data = tree;
            file.Save(FileName);
        }