private void button1_Click(object sender, EventArgs e) { ItemField Field; int ItemIndex; if (listBoxItems.Items.Count > 0) { Field = (ItemField)listBoxItems.Items[listBoxItems.Items.Count - 1]; ItemIndex = Field.ItemCode + 1; } else { ItemIndex = listBoxCategory.SelectedIndex * 512; } MuDef.MUFile_ItemExcellentOption Item = new MuDef.MUFile_ItemExcellentOption(); Item.ItemCode = (ushort)ItemIndex; Item.Option0 = 0; Item.Option1 = 0; Item.Option2 = 0; Item.Option3 = 0; Item.Option4 = 0; Item.Option5 = 0; //swap items info object[] NewItems = new object[m_Items.Length + 1]; m_Items.CopyTo(NewItems, 0); NewItems[m_Items.Length] = Item; m_Items = NewItems; updateItemList(); listBoxItems.SelectedIndex = listBoxItems.Items.Count - 1; //jump to new item }
public override void SaveAsBmd(string OutputPath, object[] items) { try { FileStream OutputStream = File.Open(OutputPath, FileMode.Create, FileAccess.Write); int nSizeOfItem = Marshal.SizeOf(typeof(MuDef.MUFile_ItemExcellentOption)); MuDef.MUFile_ItemExcellentOption CurrentItem = new MuDef.MUFile_ItemExcellentOption(); object[] cur_group; byte[] FileBuffer = new byte[nSizeOfItem * items.Length]; for (int n = 0; n < items.Length; n++) { if (items[n] == null) { continue; } CurrentItem = ((MuDef.MUFile_ItemExcellentOption)(items[n])); byte[] buf = StructureToByteArray(items[n]); XorFilter(ref buf, Marshal.SizeOf(typeof(MuDef.MUFile_ItemExcellentOption))); buf.CopyTo(FileBuffer, n * nSizeOfItem); } OutputStream.Write(BitConverter.GetBytes(items.Length), 0, 4); OutputStream.Write(FileBuffer, 0, items.Length * nSizeOfItem); OutputStream.Flush(); OutputStream.Close(); } catch { MessageBox.Show("Failed to save file"); } }
public override void SaveAsXml(string OutputPath, object[] items) { try { FileStream OutputStream = File.Open(OutputPath, FileMode.Create, FileAccess.Write); int nSizeOfItem = Marshal.SizeOf(typeof(MuDef.MUFile_ItemExcellentOption)); MuDef.MUFile_ItemExcellentOption CurrentItem = new MuDef.MUFile_ItemExcellentOption(); object[] cur_group; byte[] FileBuffer = new byte[nSizeOfItem * items.Length]; byte[] buf = new byte[1000]; buf = ASCIIEncoding.ASCII.GetBytes("<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<itemexcellentoption>\r\n"); OutputStream.Write(buf, 0, buf.Length); for (int n = 0; n < items.Length; n++) { if (items[n] == null) { continue; } CurrentItem = ((MuDef.MUFile_ItemExcellentOption)(items[n])); string line = string.Format("\t<item type=\"{0}\" index=\"{1}\">\n\t\t<option index=\"0\" value=\"{2}\"/>\n\t\t<option index=\"1\" value=\"{3}\"/>\n\t\t<option index=\"2\" value=\"{4}\"/>\n\t\t<option index=\"3\" value=\"{5}\"/>\n\t\t<option index=\"4\" value=\"{6}\"/>\n\t\t<option index=\"5\" value=\"{7}\"/>\n\t</item>\r\n", CurrentItem.ItemCode / 512, CurrentItem.ItemCode % 512, CurrentItem.Option0, CurrentItem.Option1, CurrentItem.Option2, CurrentItem.Option3, CurrentItem.Option4, CurrentItem.Option5); buf = ASCIIEncoding.ASCII.GetBytes(line); OutputStream.Write(buf, 0, buf.Length); } buf = ASCIIEncoding.ASCII.GetBytes("</itemexcellentoption>"); OutputStream.Write(buf, 0, buf.Length); OutputStream.Flush(); OutputStream.Close(); Main.Log("File {0} saved", OutputPath); } catch { MessageBox.Show("Failed to save file"); } }