Example #1
0
 public MeleeCMDEditor(DatFighterScript Script)
 {
     InitializeComponent();
     this.Script = Script;
     foreach (SubAction a in Script.SubActions)
     {
         richTextBox1.Text += MeleeCMD.DecompileSubAction(a) + "\n";
     }
 }
Example #2
0
        private void buttonCompile_Click(object sender, EventArgs e)
        {
            string[] actionsrc = richTextBox1.Text.Split('\n');
            ClearHighlights(richTextBox1);

            List <SubAction> actions = new List <SubAction>();
            int line = 0;

            foreach (string a in actionsrc)
            {
                if (a.Equals(""))
                {
                    continue;
                }
                CompileError err;
                SubAction    comp = null;
                try
                {
                    comp = MeleeCMD.CompileCommand(a, out err);
                }
                catch (Exception)
                {
                    err = CompileError.Syntax;
                };

                switch (err)
                {
                case CompileError.None:
                    actions.Add(comp);
                    break;

                case CompileError.Syntax:
                    HighlightLine(richTextBox1, line, Color.PaleVioletRed);
                    MessageBox.Show("Syntax error on line " + line);
                    return;

                case CompileError.ParameterCount:
                    HighlightLine(richTextBox1, line, Color.PaleVioletRed);
                    MessageBox.Show("Too many or too few parameters on line " + line);
                    return;

                case CompileError.UnknownCommand:
                    HighlightLine(richTextBox1, line, Color.PaleVioletRed);
                    MessageBox.Show("Unknown Command on line " + line);
                    return;
                }
                line++;
            }
            MessageBox.Show("Compiled Successfully");
            Script.SubActions = actions;
        }
Example #3
0
        public void SaveAs(object sender, EventArgs args)
        {
            using (var sfd = new SaveFileDialog())
            {
                sfd.Filter = "HAL DAT|*.dat|" +
                             "All Files (*.*)|*.*";

                sfd.DefaultExt = "dat";
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    if (DatFile.Roots.Length > 0)
                    {
                        if (DatFile.Roots[0].FighterData.Count > 0)
                        {
                            //MessageBox.Show("Cannot save this dat type yet");
                            // gonna have to inject this one for now
                            FileData d = new FileData(fileName);
                            d.endian = Endianness.Big;
                            FileOutput o = new FileOutput();

                            if (DatFile.Roots.Length > 1)
                            {
                                foreach (DatAnimation a in DatFile.Roots[1].Animations)
                                {
                                    DatFighterScript script = null;
                                    foreach (DatFighterScript s in DatFile.Roots[0].FighterData[0].Scripts)
                                    {
                                        if (s.Text.Equals(a.Text))
                                        {
                                            script = s;
                                            break;
                                        }
                                    }
                                    // Create Animation
                                    MeleeJointAnimationNode n = new MeleeJointAnimationNode(a);
                                    Compiler.Compile(n.GetAsDATFile(), "temp.dat");
                                    if (script != null)
                                    {
                                        script.AnimationOffset = o.Size();
                                    }
                                    o.WriteBytes(File.ReadAllBytes("temp.dat"));
                                    if (script != null)
                                    {
                                        script.AnimationSize = o.Size() - script.AnimationOffset;
                                    }
                                    o.Align(0x20, 0xFF);
                                }
                            }
                            if (File.Exists("temp.dat"))
                            {
                                File.Delete("temp.dat");
                            }
                            bool CanExpand = false;
                            foreach (DatFighterScript s in DatFile.Roots[0].FighterData[0].Scripts)
                            {
                                if (DatFile.Roots.Length > 1)
                                {
                                    d.WriteInt(s.Offset + 4, s.AnimationOffset);
                                    d.WriteInt(s.Offset + 8, s.AnimationSize);
                                }
                                List <byte> newSection = new List <byte>();
                                foreach (SubAction sub in s.SubActions)
                                {
                                    newSection.AddRange(sub.Data);
                                    if (MeleeCMD.GetActionName((byte)(sub.Data[0] >> 2)).Equals("Subroutine") ||
                                        MeleeCMD.GetActionName((byte)(sub.Data[0] >> 2)).Equals("Goto"))
                                    {
                                        newSection[newSection.Count - 1] -= 0x20;
                                    }
                                }
                                newSection.AddRange(new byte[] { 0, 0, 0, 0 });

                                if (newSection.Count > s.SubActionSize && !CanExpand)
                                {
                                    DialogResult dialogResult = MessageBox.Show("Expand the file?\n(Warning incomplete)", "Error: Not enough space", MessageBoxButtons.YesNo);
                                    if (dialogResult != DialogResult.Yes)
                                    {
                                        CanExpand = true;
                                    }
                                    else
                                    {
                                        MessageBox.Show("Failed saving the file");
                                        return;
                                    }
                                }
                                else if (newSection.Count > s.SubActionSize && CanExpand)
                                {
                                    d.WriteInt(s.Offset + 12, d.Size() - 0x20);
                                    d.WriteBytesAt(d.Size(), newSection.ToArray());
                                }
                                else
                                {
                                    d.WriteInt(s.Offset + 12, s.SubActionOffset - 0x20);
                                    d.WriteBytesAt(s.SubActionOffset, newSection.ToArray());
                                }
                                Console.WriteLine(s.SubActionOffset.ToString("x") + " " + s.SubActionSize.ToString("x") + " " + newSection.Count.ToString("x"));
                            }
                            if (DatFile.Roots.Length > 1)
                            {
                                o.Save(sfd.FileName.Replace(".dat", "AJ.dat"));
                            }
                            d.WriteInt(0, d.Size());
                            File.WriteAllBytes(sfd.FileName, d.GetSection(0, d.Eof()));
                            return;
                        }
                    }
                    Compiler.Compile(DatFile, sfd.FileName);
                }
            }
        }