Example #1
0
    public override void OnInspectorGUI()
    {
        GUILayout.TextArea("This asset contains your Action Library. The library contains one or more" +
                           " networks for use in your Unity3D project. To edit the library, press the 'Edit Library' button below.");
        EditorGUILayout.Separator();

        ActionAsset highlightedAsset = Selection.activeObject as ActionAsset;

        try
        {
            currentLibrary = ActionLibrary.LoadData(highlightedAsset.libraryData);
        }
        catch {}

        GUILayout.Label("This library contains " + currentLibrary.networks.Length + " networks.");
        EditorGUILayout.Separator();

        GUILayout.BeginHorizontal();
        {
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Edit Library", GUILayout.MaxWidth(100f)))
            {
                ActionMenu.EditLibraryAsset();
            }
            GUILayout.FlexibleSpace();
        }
        GUILayout.EndHorizontal();

        GUILayout.Space(10f);

        GUILayout.BeginHorizontal();
        {
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Generate Runtime Library from Asset"))
            {
                //ActionClassGenerator.CreateNetworkClass(Selection.activeObject as ActionAsset);
                ActionCompiler.GenerateRTLibrary(Selection.activeObject as ActionAsset);
            }
            GUILayout.FlexibleSpace();
        }
        GUILayout.EndHorizontal();

        GUILayout.Space(10f);

        GUILayout.BeginHorizontal();
        {
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Export Library"))
            {
                SerializeToXML(currentLibrary);
                //SerializeToBin(currentLibrary);
            }
            GUILayout.FlexibleSpace();
        }
        GUILayout.EndHorizontal();
    }
Example #2
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);
        }