public static void DeserializeBlock(GenericReader reader, Action <GenericReader> deserializer) { if (reader.PeekInt() == 0x0C0FFEE0 && reader.ReadInt() == 0x0C0FFEE0) { int length = reader.ReadInt(); byte[] data = Array.Empty <byte>(); if (length > 0) { data = new byte[length]; } for (int i = 0; i < data.Length; i++) { data[i] = reader.ReadByte(); } if (deserializer != null) { using (MemoryStream ms = new MemoryStream(data)) { BinaryFileReader r = new BinaryFileReader(new BinaryReader(ms)); try { deserializer(r); } finally { r.Close(); } } } } else { deserializer?.Invoke(reader); } }
public static Type ReadType(this GenericReader reader) { if (!reader.ReadBool()) { return(null); } // Peek preamble for upgrade support if (reader.PeekInt() == 0x0C0FFEE0 && reader.ReadInt() == 0x0C0FFEE0) { return(_Types.GetValue(reader.ReadInt())); } var full = reader.ReadBool(); var name = reader.ReadString(); if (String.IsNullOrWhiteSpace(name)) { return(null); } return(Type.GetType(name, false) ?? (full ? ScriptCompiler.FindTypeByFullName(name) : ScriptCompiler.FindTypeByName(name))); }