private string ReadMetadataString() { STUString data = MetadataReader.Read <STUString>(); Metadata.Position = data.Offset; byte[] chars = MetadataReader.ReadBytes((int)data.Size); return(Encoding.UTF8.GetString(chars)); }
internal object GetValue(object fieldOwner, Type type, BinaryReader reader, STUFieldAttribute element, FieldInfo fieldInfo, bool isArray = false, bool isInlineInstance = false) { if (type.IsArray) { long offset = reader.ReadInt64(); if (offset == 0) { return(Array.CreateInstance(type.GetElementType(), 0)); } long position = reader.BaseStream.Position; reader.BaseStream.Position = offset + Start; if (element.EmbeddedInstance) { throw new NotImplementedException(); } object value = GetValueArray(type.GetElementType(), reader, element, fieldInfo); reader.BaseStream.Position = position + 8; return(value); } switch (type.Name) { case "String": { long offset = reader.ReadInt64(); if (offset == 0) { return(string.Empty); } long position = reader.BaseStream.Position; reader.BaseStream.Position = offset + Start; STUString stringData = reader.Read <STUString>(); if (stringData.Size == 0) { return(string.Empty); } reader.BaseStream.Position = stringData.Offset + Start; string @string = new string(reader.ReadChars((int)stringData.Size)); reader.BaseStream.Position = position; return(@string); } case "Single": return(reader.ReadSingle()); case "Boolean": return(reader.ReadByte() != 0); case "Int16": return(reader.ReadInt16()); case "UInt16": return(reader.ReadUInt16()); case "Int32": return(reader.ReadInt32()); case "UInt32": return(reader.ReadUInt32()); case "Int64": return(reader.ReadInt64()); case "UInt64": return(reader.ReadUInt64()); case "Byte": return(reader.ReadByte()); case "SByte": return(reader.ReadSByte()); case "Char": return(reader.ReadChar()); default: if (type.GetInterfaces().Contains(typeof(ISTUCustomSerializable))) { if (fieldInfo.FieldType.IsArray) { return(((ISTUCustomSerializable)Activator.CreateInstance(type)).DeserializeArray(fieldOwner, this, fieldInfo, reader, null)); } return(((ISTUCustomSerializable)Activator.CreateInstance(type)).Deserialize(fieldOwner, this, fieldInfo, reader, null)); } if (type.IsEnum) { return(Enum.ToObject(type, GetValue(fieldOwner, type.GetEnumUnderlyingType(), reader, element, fieldInfo, isArray))); } if (type.IsClass || type.IsValueType) { if (!element.EmbeddedInstance) { return(InitializeObject(Activator.CreateInstance(type), type, reader, isArray, isInlineInstance && typeof(STUInstance).IsAssignableFrom(type))); } int index = reader.ReadInt32(); EmbedRequests.Add(new KeyValuePair <object, FieldInfo>(fieldOwner, fieldInfo), index); return(null); } return(null); } }