public override object[] GetStructures() { int RealLineCount = ReadInt(m_FileStream); int LineCount = cTotalStructCount; object[] Res = new object[LineCount]; int SizeOfItem = Marshal.SizeOf(typeof(MuDef.MUFile_ItemTRSData)); MuDef.MUFile_ItemTRSData CurrentItem; m_FileBuffer = new byte[SizeOfItem * LineCount]; m_FileStream.Read(m_FileBuffer, 0, m_FileBuffer.Length); MemoryStream ms = new MemoryStream(m_FileBuffer); byte[] item_buf = new byte[SizeOfItem]; try { while ((ms.Read(item_buf, 0, item_buf.Length) == SizeOfItem)) { XorFilter(ref item_buf, SizeOfItem); object Item; if (m_CurrentLine < RealLineCount) { Item = Marshal.PtrToStructure( Marshal.UnsafeAddrOfPinnedArrayElement(item_buf, 0), typeof(MuDef.MUFile_ItemTRSData)); } else { Item = new MuDef.MUFile_ItemTRSData(); } Res[m_CurrentLine++] = (object)Item; } } catch (ArgumentException) { } catch (IndexOutOfRangeException) { } catch// (Exception e) { MessageBox.Show("Failed to read file structures."); } CloseSourceFile(); return Res; }
public override void SaveAsBmd(string OutputPath, DataGridView dgv) { //try //{ int FilledRowCount = dgv.Rows.Count; FileStream OutputStream = File.Open(OutputPath, FileMode.Create, FileAccess.Write); List<MuDef.MUFile_ItemTRSData> TmpList = new List<MuDef.MUFile_ItemTRSData>(dgv.Rows.Count); MuDef.MUFile_ItemTRSData CurrentItem = new MuDef.MUFile_ItemTRSData(); for (int i = 0; i < FilledRowCount; i++) { if (dgv.Rows[i].Cells[0].Value != null && (int.Parse(dgv.Rows[i].Cells[0].Value.ToString()) > 0 || float.Parse(dgv.Rows[i].Cells[4].Value.ToString()) > 0.0f)) { CurrentItem.ItemCode = int.Parse(dgv.Rows[i].Cells[0].Value.ToString()); CurrentItem.TranslationX = float.Parse(dgv.Rows[i].Cells[1].Value.ToString()); CurrentItem.TranslationY = float.Parse(dgv.Rows[i].Cells[2].Value.ToString()); CurrentItem.TranslationZ = float.Parse(dgv.Rows[i].Cells[3].Value.ToString()); CurrentItem.Rotation = float.Parse(dgv.Rows[i].Cells[4].Value.ToString()); CurrentItem.ScaleX = float.Parse(dgv.Rows[i].Cells[5].Value.ToString()); CurrentItem.ScaleY = float.Parse(dgv.Rows[i].Cells[6].Value.ToString()); CurrentItem.ScaleZ = float.Parse(dgv.Rows[i].Cells[7].Value.ToString()); TmpList.Add(CurrentItem); } } int ItemSize = Marshal.SizeOf(typeof(MuDef.MUFile_ItemTRSData)); int TotalSize = TmpList.Count * ItemSize; byte[] FileBuffer = new byte[TotalSize]; for (int i = 0; i < TmpList.Count; i++) { byte[] buf = StructureToByteArray(TmpList[i]); XorFilter(ref buf, Marshal.SizeOf(typeof(MuDef.MUFile_ItemTRSData))); buf.CopyTo(FileBuffer, i * ItemSize); } OutputStream.Write(BitConverter.GetBytes(TmpList.Count), 0, sizeof(int)); OutputStream.Write(FileBuffer, 0, TotalSize); OutputStream.Write(BitConverter.GetBytes(GetCRC(FileBuffer, FileBuffer.Length)), 0, sizeof(uint)); OutputStream.Flush(); OutputStream.Close(); // } // catch (Exception e) // { MessageBox.Show("Failed to save file"); } }