public static List <IEventEntry> Read(Stream stream) { var entries = new List <IEventEntry>(); int blockLength; while (stream.Position + 3 < stream.Length) { blockLength = stream.ReadInt16(); if (blockLength == Terminator) { break; } var startPosition = stream.Position - 2; var type = stream.ReadInt16(); if (_idType.TryGetValue(type, out var entryType)) { entries.Add(Mapping.ReadObject(stream, (IEventEntry)Activator.CreateInstance(entryType))); } else { Console.Error.WriteLine($"No Event implementation for {type:X02}"); } if (stream.Position != startPosition + blockLength) { stream.Position = stream.Position; } stream.Position = startPosition + blockLength; } return(entries); }
private static IEnumerable <IAreaDataCommand> ParseScript(byte[] bytecode) { for (int pc = 0; pc < bytecode.Length;) { var opcode = BitConverter.ToUInt16(bytecode, pc); var parameterCount = BitConverter.ToUInt16(bytecode, pc + 2); using var stream = new MemoryStream(bytecode, pc + 4, parameterCount * 4); var instance = Activator.CreateInstance(_idType[opcode]); yield return(Mapping.ReadObject(stream, instance) as IAreaDataCommand); pc += 4 + parameterCount * 4; } }
public static ISavePersona5 Read(Stream stream) { switch (GetGameIdentifier(stream.SetPosition(0))) { case Persona5Identifier: return(Mapper.ReadObject <Persona5Vanilla>(stream.SetPosition(0))); case Persona5RoyalIdentifier: return(Mapper.ReadObject <Persona5Royal>(stream.SetPosition(0))); default: throw new NotImplementedException("The version has been recognized but it is not supported."); } }
public static void AssertReadAndWrite <T>(IBinaryMapping mapper, T value, int expectedLength, Action <ValuePair <T> > assertion = null) { var expected = new Generic <T> { Value = value }; var actual = new Generic <T>(); var memory = new MemoryStream(); mapper.WriteObject(memory, expected); Assert.Equal(expectedLength, memory.Length); memory.Position = 0; mapper.ReadObject(memory, actual); Assert.Equal(expectedLength, memory.Position); if (assertion != null) { assertion(new ValuePair <T> { Expected = value, Actual = actual.Value }); } else { Assert.Equal(expected.Value, actual.Value); } }
public static Pmp Read(Stream stream) { Pmp pmp = new Pmp(); pmp.header = BinaryMapping.ReadObject <Header>(stream); // Read Object List. for (int i = 0; i < pmp.header.ObjectCount; i++) { pmp.objectInfo.Add(Mapping.ReadObject <ObjectInfo>(stream)); pmp.hasDifferentMatrix.Add(BitsUtil.Int.GetBit(pmp.objectInfo[i].ObjectFlags, 0)); } // Read PMO list. for (int p = 0; p < pmp.header.ObjectCount; p++) { ObjectInfo currentPmoInfo = pmp.objectInfo[p]; if (currentPmoInfo.PMO_Offset != 0) { stream.Seek(currentPmoInfo.PMO_Offset, SeekOrigin.Begin); pmp.PmoList.Add(Pmo.Read(stream)); } else { pmp.PmoList.Add(null); } } stream.Seek(pmp.header.TextureListOffset, SeekOrigin.Begin); for (int t = 0; t < pmp.header.TextureCount; t++) { pmp.TextureList.Add(BinaryMapping.ReadObject <PMPTextureInfo>(stream)); } // Read textures. for (int k = 0; k < pmp.TextureList.Count; k++) { stream.Seek(pmp.TextureList[k].Offset + 0x10, SeekOrigin.Begin); uint tm2size = stream.ReadUInt32() + 0x10; stream.Seek(pmp.TextureList[k].Offset, SeekOrigin.Begin); pmp.TextureDataList.Add(Tm2.Read(stream, true).First()); } return(pmp); }
public static T ReadObject <T>(this IBinaryMapping binaryMapping, Stream stream, int baseOffset = 0) where T : class => (T)binaryMapping.ReadObject(stream, Activator.CreateInstance <T>(), baseOffset);
public static void ReadHeader(Stream stream, Pmo pmo) { pmo.header = Mapping.ReadObject <Header>(stream); }