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); } } }