private void buttonExport_Click(object sender, EventArgs e) { byte[] temp = DataExtractor.PackPalico(this.Palico); try { using (SaveFileDialog sfd = new SaveFileDialog()) { sfd.Filter = "Palico File (*.catz)|*.catz|All files (*.*)|*.*"; sfd.FilterIndex = 1; sfd.RestoreDirectory = true; sfd.FileName = textBoxName.Text; if (sfd.ShowDialog() == DialogResult.OK) { savePalico(); File.WriteAllBytes(sfd.FileName, DataExtractor.PackPalico(this.Palico)); this.Palico = DataExtractor.GetPalcio(temp); MessageBox.Show(string.Format("Exported palico to {0}", sfd.FileName), "Success!"); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Save Unsucessful"); this.Palico = DataExtractor.GetPalcio(temp); } }
public PalicoEditDialog(Palico palico) { InitializeComponent(); this.Palico = palico; comboBoxForte.DataSource = GameConstants.PalicoForte; numericUpDownXP.Maximum = UInt32.MaxValue; numericUpDownLevel.Maximum = 255; numericUpDownTarget.Maximum = 255; numericUpDownEnthusiasm.Maximum = 255; textBoxLearnedActionRNG.MaxLength = 4; textBoxLearnedSkillRNG.MaxLength = 4; textBoxName.MaxLength = 16; textBoxNameGiver.MaxLength = 16; textBoxPreviousOwner.MaxLength = 16; textBoxCoatRGBA.MaxLength = 8; textBoxLeftEyeRGBA.MaxLength = 8; textBoxRightEyeRGBA.MaxLength = 8; textBoxVestRGBA.MaxLength = 8; textBoxGreetings.MaxLength = 30; loadPalico(); }
/// <summary> /// Get palico from byte[] /// </summary> /// <param name="buffer">buffer containing the palico data</param> /// <returns></returns> public static Palico GetPalcio(byte[] buffer) { Palico palico = new Palico(); BinaryReader binaryReader = new BinaryReader((Stream) new MemoryStream(buffer)); palico.Name = Encoding.UTF8.GetString(binaryReader.ReadBytes(Constants.SIZEOF_NAME), 0, Constants.SIZEOF_NAME); palico.XP = binaryReader.ReadUInt32(); palico.Level = binaryReader.ReadByte(); palico.Forte = binaryReader.ReadByte(); palico.Enthusiasm = binaryReader.ReadByte(); palico.Target = binaryReader.ReadByte(); palico.EquippedActions = binaryReader.ReadBytes(8); palico.EquippedSkills = binaryReader.ReadBytes(8); palico.LearnedActions = binaryReader.ReadBytes(16); palico.LearnedSkills = binaryReader.ReadBytes(12); palico.LearnedActionRNG = binaryReader.ReadUInt16(); palico.LearnedSkillRNG = binaryReader.ReadUInt16(); palico.Unknown1 = binaryReader.ReadBytes(8); palico.Greeting = Encoding.UTF8.GetString(binaryReader.ReadBytes(Constants.SIZEOF_PALICO_GREETINGS), 0, Constants.SIZEOF_PALICO_GREETINGS); palico.NameGiver = Encoding.UTF8.GetString(binaryReader.ReadBytes(Constants.SIZEOF_NAME), 0, Constants.SIZEOF_NAME); palico.PreviousMaster = Encoding.UTF8.GetString(binaryReader.ReadBytes(Constants.SIZEOF_NAME), 0, Constants.SIZEOF_NAME); palico.Unknown2 = binaryReader.ReadBytes(62); palico.CoatRGBAValue = binaryReader.ReadBytes(4); palico.LeftEyeRGBAValue = binaryReader.ReadBytes(4); palico.RightEyeRGBAValue = binaryReader.ReadBytes(4); palico.VestRGBAValue = binaryReader.ReadBytes(4); palico.Unknown3 = binaryReader.ReadBytes(21); return palico; }
/// <summary> /// Convert palico to it's byte[] /// </summary> /// <param name="palico">Palico to pack</param> /// <returns></returns> public static byte[] PackPalico(Palico palico) { byte[] buffer = new byte[Constants.SIZEOF_PALICO]; BinaryWriter binaryWriter = new BinaryWriter((Stream)new MemoryStream(buffer)); byte[] palicoNameBuff = new byte[Constants.SIZEOF_NAME]; Encoding.UTF8.GetBytes(palico.Name, 0, palico.Name.Length, palicoNameBuff, 0); binaryWriter.Write(palicoNameBuff); binaryWriter.Write(palico.XP); binaryWriter.Write(palico.Level); binaryWriter.Write(palico.Forte); binaryWriter.Write(palico.Enthusiasm); binaryWriter.Write(palico.Target); binaryWriter.Write(palico.EquippedActions); binaryWriter.Write(palico.EquippedSkills); binaryWriter.Write(palico.LearnedActions); binaryWriter.Write(palico.LearnedSkills); binaryWriter.Write(palico.LearnedActionRNG); binaryWriter.Write(palico.LearnedSkillRNG); binaryWriter.Write(palico.Unknown1); //Texts byte[] palicoGreetingsBuff = new byte[Constants.SIZEOF_PALICO_GREETINGS]; Encoding.UTF8.GetBytes(palico.Greeting, 0, palico.Greeting.Length, palicoGreetingsBuff, 0); binaryWriter.Write(palicoGreetingsBuff); byte[] palicoNamegiverBuff = new byte[Constants.SIZEOF_NAME]; Encoding.UTF8.GetBytes(palico.NameGiver, 0, palico.NameGiver.Length, palicoNamegiverBuff, 0); binaryWriter.Write(palicoNamegiverBuff); byte[] palicoPreviousOwner = new byte[Constants.SIZEOF_NAME]; Encoding.UTF8.GetBytes(palico.PreviousMaster, 0, palico.PreviousMaster.Length, palicoPreviousOwner, 0); binaryWriter.Write(palicoPreviousOwner); //RGBA binaryWriter.Write(palico.Unknown2); binaryWriter.Write(palico.CoatRGBAValue); binaryWriter.Write(palico.LeftEyeRGBAValue); binaryWriter.Write(palico.RightEyeRGBAValue); binaryWriter.Write(palico.VestRGBAValue); binaryWriter.Write(palico.Unknown3); return buffer; }
private void buttonImport_Click(object sender, EventArgs e) { byte[] temp = DataExtractor.PackPalico(this.Palico); try { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Palico File (*.catz)|*.catz|All files (*.*)|*.*"; ofd.FilterIndex = 1; if (ofd.ShowDialog() != DialogResult.OK) { ofd.Dispose(); return; } byte[] fileData = File.ReadAllBytes(ofd.FileName); if (fileData.Length != Constants.SIZEOF_PALICO) { MessageBox.Show("Invalid Palico", "Error"); return; } this.Palico = DataExtractor.GetPalcio(fileData); loadPalico(); ofd.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Loading Error"); this.Palico = DataExtractor.GetPalcio(temp); } }