137 lines
3.6 KiB
Plaintext
137 lines
3.6 KiB
Plaintext
|
|
The following had to be removed from UE v4.0c to compile with IL2CPU...
|
|
|
|
|
|
/// <summary>
|
|
/// Reads an array of items of the specified type from the current stream.
|
|
/// </summary>
|
|
/// <typeparam name="T">The data type of the items to read.</typeparam>
|
|
/// <param name="count">The number of items to read.</param>
|
|
/// <returns></returns>
|
|
public T[] ReadObjectArray<T>(int count)
|
|
{
|
|
List<T> objects = new List<T>();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
objects.Add((T)ReadObject(typeof(T)));
|
|
}
|
|
return objects.ToArray();
|
|
}
|
|
public T[] ReadStructArray<T> (int count) where T: struct
|
|
{
|
|
System.Collections.Generic.List<T> ts = new System.Collections.Generic.List<T> ();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
T obj = ReadStruct<T> ();
|
|
ts.Add (obj);
|
|
}
|
|
return ts.ToArray ();
|
|
}
|
|
|
|
// TODO: ReadStruct needs to be fixed. It has a lot of problems.
|
|
|
|
public T ReadStruct<T> () where T : struct
|
|
{
|
|
Type objectType = typeof(T);
|
|
object value = objectType.Assembly.CreateInstance (objectType.FullName);
|
|
|
|
System.Reflection.FieldInfo[] fis = (objectType.GetFields (System.Reflection.BindingFlags.Default | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance));
|
|
foreach (System.Reflection.FieldInfo fi in fis)
|
|
{
|
|
Type fieldType = fi.FieldType;
|
|
object fieldValue = ReadObject (fieldType);
|
|
|
|
fi.SetValue (value, fieldValue);
|
|
}
|
|
|
|
return (T)value;
|
|
}
|
|
public T ReadObject<T> () where T : class
|
|
{
|
|
Type objectType = typeof(T);
|
|
T value = (T)objectType.Assembly.CreateInstance (objectType.FullName);
|
|
|
|
System.Reflection.FieldInfo[] fis = (objectType.GetFields (System.Reflection.BindingFlags.Default | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance));
|
|
foreach (System.Reflection.FieldInfo fi in fis)
|
|
{
|
|
Type fieldType = fi.FieldType;
|
|
object fieldValue = ReadObject(fieldType);
|
|
|
|
fi.SetValue (value, fieldValue);
|
|
}
|
|
|
|
return value;
|
|
}
|
|
public object ReadObject(Type objectType)
|
|
{
|
|
if (objectType == typeof(Byte))
|
|
{
|
|
return ReadByte();
|
|
}
|
|
else if (objectType == typeof(SByte))
|
|
{
|
|
return ReadSByte();
|
|
}
|
|
else if (objectType == typeof(String))
|
|
{
|
|
return ReadLengthPrefixedString();
|
|
}
|
|
else if (objectType == typeof(Char))
|
|
{
|
|
return ReadChar();
|
|
}
|
|
else if (objectType == typeof(Char[]))
|
|
{
|
|
|
|
}
|
|
else if (objectType == typeof(Single))
|
|
{
|
|
return ReadSingle();
|
|
}
|
|
else if (objectType == typeof(Double))
|
|
{
|
|
return ReadDouble();
|
|
}
|
|
else if (objectType == typeof(Int16))
|
|
{
|
|
return ReadInt16();
|
|
}
|
|
else if (objectType == typeof(Int32))
|
|
{
|
|
return ReadInt32();
|
|
}
|
|
else if (objectType == typeof(Int64))
|
|
{
|
|
return ReadInt64();
|
|
}
|
|
else if (objectType == typeof(UInt16))
|
|
{
|
|
return ReadUInt16();
|
|
}
|
|
else if (objectType == typeof(UInt32))
|
|
{
|
|
return ReadUInt32();
|
|
}
|
|
else if (objectType == typeof(UInt64))
|
|
{
|
|
return ReadInt64();
|
|
}
|
|
else if (objectType == typeof(DateTime))
|
|
{
|
|
return ReadDateTime();
|
|
}
|
|
|
|
object value = objectType.Assembly.CreateInstance (objectType.FullName);
|
|
|
|
System.Reflection.FieldInfo[] fis = (objectType.GetFields (System.Reflection.BindingFlags.Default | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance));
|
|
foreach (System.Reflection.FieldInfo fi in fis)
|
|
{
|
|
Type fieldType = fi.FieldType;
|
|
object fieldValue = ReadObject (fieldType);
|
|
|
|
fi.SetValue (value, fieldValue);
|
|
}
|
|
|
|
return value;
|
|
}
|