public Object ReadStructMember(ORNames Struct, ORNames Member, byte[] Data) { int Offset = GetStructMemberOffset(Struct, Member); int Size = GetStructMemberSize(Struct, Member); int Count = GetStructMemberCount(Struct, Member); Type type = GetStructMemberType(Struct, Member); if (Data == null) { throw new NullReferenceException("OffsetReader.ReadStructMember: Data was null. Struct: " + Struct + " Member: " + Member); } if (Data.Length < Offset + Size) { char[] hex = new char[16] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; string HexData = string.Empty; foreach (byte b in Data) { HexData += hex[b >> 4]; HexData += hex[b & 0x0F] + " "; } throw new IndexOutOfRangeException("OffsetReader.ReadStructMember: Data was too small to read all data.\nData.Length: " + Data.Length.ToString() + " Offset: " + Offset.ToString() + " Size: " + Size.ToString() + " Struct: " + Struct.ToString() + " Member: " + Member.ToString() + "\n Data: " + HexData); } if (type == StringType) { string ReturnValS = Encoding.UTF8.GetString(Data, Offset, Size); int NullPos = ReturnValS.IndexOf('\0'); if (NullPos >= 0) { ReturnValS = ReturnValS.Remove(NullPos); } return(ReturnValS); } if (Count <= 0) { return(ReadWriteMemory.RawDeserialize(Data, Offset, type)); } Array ReturnVal = Array.CreateInstance(type, Count); for (int i = 0; i < Count; i++) { ReturnVal.SetValue(ReadWriteMemory.RawDeserialize(Data, Offset + i * Size / Count, type), i); } return(ReturnVal); }
public Object ReadStructMember(ORNames Struct, ORNames Member, uint Address = 0) { if (Address <= 0) { Address = GetStructAddress(Struct); } Type type = GetStructMemberType(Struct, Member); if (type == StringType) { int Length = GetStructMemberSize(Struct, Member); byte[] buffer = new byte[Length]; mem.ReadMemory((uint)(GetStructMemberOffset(Struct, Member) + Address), buffer.Length, out buffer); string ReturnValS = Encoding.UTF8.GetString(buffer); int NullPos = ReturnValS.IndexOf('\0'); if (NullPos >= 0) { ReturnValS = ReturnValS.Remove(NullPos); } return(ReturnValS); } int Count = GetStructMemberCount(Struct, Member); if (Count <= 0) { return(mem.ReadMemory((uint)(GetStructMemberOffset(Struct, Member) + Address), GetStructMemberType(Struct, Member))); } int Size = GetStructMemberSize(Struct, Member); byte[] Data = new byte[Size]; mem.ReadMemory(Address, Data.Length, out Data); Array ReturnVal = Array.CreateInstance(type, Count); for (int i = 0; i < Count; i++) { ReturnVal.SetValue(ReadWriteMemory.RawDeserialize(Data, i * Size, type), i); } return(ReturnVal); }