public InteractionList(IffChunk Chunk) : base(Chunk) { MemoryStream MemStream = new MemoryStream(Chunk.Data); BinaryReader Reader = new BinaryReader(MemStream); if ((Reader.BaseStream.Length - Reader.BaseStream.Position) == 0) { return; //Empty (strange, but it happens). } m_NumInteractions = Reader.ReadInt16(); if ((Reader.BaseStream.Length - Reader.BaseStream.Position) == 0 || (Reader.BaseStream.Length - Reader.BaseStream.Position) < 2) { return; //Too short (strange, but it happens). } m_Version = Reader.ReadInt16(); if (m_NumInteractions <= 0) { return; } if (m_Version == 9 || m_Version == 10) { m_CompressionCode = Reader.ReadByte(); if (m_CompressionCode != 1) { return; //Compressioncode should always be 1. } } switch (m_Version) { case 2: for (int i = 0; i < m_NumInteractions; i++) { TTABCore Interaction = new TTABCore(); Interaction.ActionFunction = Reader.ReadInt16(); Interaction.GuardFunction = Reader.ReadInt16(); Interaction.MotiveEntries = Reader.ReadInt16(); Reader.ReadInt16(); //0xA3A3 (skip) Reader.ReadInt32(); //4-byte float, no idea what it is used for. m_Interactions.Add(Interaction); } break; case 3: for (int i = 0; i < m_NumInteractions; i++) { TTABCore Interaction = new TTABCore(); Interaction.ActionFunction = Reader.ReadInt16(); Interaction.GuardFunction = Reader.ReadInt16(); Interaction.MotiveEntries = Reader.ReadInt16(); Interaction.Flags = Reader.ReadInt16(); Reader.ReadInt32(); //4-byte float, no idea what it is used for. m_Interactions.Add(Interaction); } break; case 5: for (int i = 0; i < m_NumInteractions; i++) { TTABCore Interaction = new TTABCore(); Interaction.ActionFunction = Reader.ReadInt16(); Interaction.GuardFunction = Reader.ReadInt16(); Interaction.MotiveEntries = Reader.ReadInt32(); Interaction.Flags = Reader.ReadInt32(); Interaction.StrTableIndex = Reader.ReadInt32(); Interaction.Autonomy = Reader.ReadInt32(); Interaction.JoinIndex = Reader.ReadInt32(); m_Interactions.Add(Interaction); } break; case 7: for (int i = 0; i < m_NumInteractions; i++) { TTABCore Interaction = new TTABCore(); Interaction.ActionFunction = Reader.ReadInt16(); Interaction.GuardFunction = Reader.ReadInt16(); Interaction.MotiveEntries = Reader.ReadInt32(); Interaction.Flags = Reader.ReadInt32(); Interaction.StrTableIndex = Reader.ReadInt32(); Interaction.AttenuationCode = Reader.ReadInt32(); Interaction.AttenuationValue = Reader.ReadInt32(); Interaction.Autonomy = Reader.ReadInt32(); Interaction.JoinIndex = Reader.ReadInt32(); m_Interactions.Add(Interaction); } break; case 8: for (int i = 0; i < m_NumInteractions; i++) { TTABCore Interaction = new TTABCore(); Interaction.ActionFunction = Reader.ReadInt16(); Interaction.GuardFunction = Reader.ReadInt16(); Interaction.MotiveEntries = Reader.ReadInt32(); Interaction.Flags = Reader.ReadInt32(); Interaction.StrTableIndex = Reader.ReadInt32(); Interaction.AttenuationCode = Reader.ReadInt32(); Interaction.AttenuationValue = Reader.ReadInt32(); Interaction.Autonomy = Reader.ReadInt32(); Interaction.JoinIndex = Reader.ReadInt32(); m_Interactions.Add(Interaction); } break; case 9: for (int i = 0; i < m_NumInteractions; i++) { TTABCore Interaction = new TTABCore(); BitArray BArray = new BitArray(Reader.ReadBytes(2)); Interaction.ActionFunction = (short)GetShortBits(BArray); BArray = new BitArray(Reader.ReadBytes(4)); Interaction.GuardFunction = (short)GetShortBits(BArray); BArray = new BitArray(Reader.ReadBytes(4)); Interaction.MotiveEntries = (int)GetLongBits(BArray); BArray = new BitArray(Reader.ReadBytes(4)); Interaction.Flags = (int)GetLongBits(BArray); BArray = new BitArray(Reader.ReadBytes(4)); Interaction.StrTableIndex = (int)GetLongBits(BArray); BArray = new BitArray(Reader.ReadBytes(4)); Interaction.AttenuationCode = (int)GetLongBits(BArray); BArray = new BitArray(Reader.ReadBytes(4)); Interaction.AttenuationValue = (int)GetLongBits(BArray); BArray = new BitArray(Reader.ReadBytes(4)); Interaction.Autonomy = (int)GetLongBits(BArray); BArray = new BitArray(Reader.ReadBytes(4)); Interaction.JoinIndex = (int)GetLongBits(BArray); m_Interactions.Add(Interaction); } break; } Reader.Close(); }
public InteractionList(IffChunk Chunk) : base(Chunk) { MemoryStream MemStream = new MemoryStream(Chunk.Data); BinaryReader Reader = new BinaryReader(MemStream); if ((Reader.BaseStream.Length - Reader.BaseStream.Position) == 0) return; //Empty (strange, but it happens). m_NumInteractions = Reader.ReadInt16(); if ((Reader.BaseStream.Length - Reader.BaseStream.Position) == 0 || (Reader.BaseStream.Length - Reader.BaseStream.Position) < 2) return; //Too short (strange, but it happens). m_Version = Reader.ReadInt16(); if (m_NumInteractions <= 0) return; if (m_Version == 9 || m_Version == 10) { m_CompressionCode = Reader.ReadByte(); if (m_CompressionCode != 1) return; //Compressioncode should always be 1. } switch (m_Version) { case 2: for (int i = 0; i < m_NumInteractions; i++) { TTABCore Interaction = new TTABCore(); Interaction.ActionFunction = Reader.ReadInt16(); Interaction.GuardFunction = Reader.ReadInt16(); Interaction.MotiveEntries = Reader.ReadInt16(); Reader.ReadInt16(); //0xA3A3 (skip) Reader.ReadInt32(); //4-byte float, no idea what it is used for. m_Interactions.Add(Interaction); } break; case 3: for (int i = 0; i < m_NumInteractions; i++) { TTABCore Interaction = new TTABCore(); Interaction.ActionFunction = Reader.ReadInt16(); Interaction.GuardFunction = Reader.ReadInt16(); Interaction.MotiveEntries = Reader.ReadInt16(); Interaction.Flags = Reader.ReadInt16(); Reader.ReadInt32(); //4-byte float, no idea what it is used for. m_Interactions.Add(Interaction); } break; case 5: for (int i = 0; i < m_NumInteractions; i++) { TTABCore Interaction = new TTABCore(); Interaction.ActionFunction = Reader.ReadInt16(); Interaction.GuardFunction = Reader.ReadInt16(); Interaction.MotiveEntries = Reader.ReadInt32(); Interaction.Flags = Reader.ReadInt32(); Interaction.StrTableIndex = Reader.ReadInt32(); Interaction.Autonomy = Reader.ReadInt32(); Interaction.JoinIndex = Reader.ReadInt32(); m_Interactions.Add(Interaction); } break; case 7: for (int i = 0; i < m_NumInteractions; i++) { TTABCore Interaction = new TTABCore(); Interaction.ActionFunction = Reader.ReadInt16(); Interaction.GuardFunction = Reader.ReadInt16(); Interaction.MotiveEntries = Reader.ReadInt32(); Interaction.Flags = Reader.ReadInt32(); Interaction.StrTableIndex = Reader.ReadInt32(); Interaction.AttenuationCode = Reader.ReadInt32(); Interaction.AttenuationValue = Reader.ReadInt32(); Interaction.Autonomy = Reader.ReadInt32(); Interaction.JoinIndex = Reader.ReadInt32(); m_Interactions.Add(Interaction); } break; case 8: for (int i = 0; i < m_NumInteractions; i++) { TTABCore Interaction = new TTABCore(); Interaction.ActionFunction = Reader.ReadInt16(); Interaction.GuardFunction = Reader.ReadInt16(); Interaction.MotiveEntries = Reader.ReadInt32(); Interaction.Flags = Reader.ReadInt32(); Interaction.StrTableIndex = Reader.ReadInt32(); Interaction.AttenuationCode = Reader.ReadInt32(); Interaction.AttenuationValue = Reader.ReadInt32(); Interaction.Autonomy = Reader.ReadInt32(); Interaction.JoinIndex = Reader.ReadInt32(); m_Interactions.Add(Interaction); } break; case 9: for (int i = 0; i < m_NumInteractions; i++) { TTABCore Interaction = new TTABCore(); BitArray BArray = new BitArray(Reader.ReadBytes(2)); Interaction.ActionFunction = (short)GetShortBits(BArray); BArray = new BitArray(Reader.ReadBytes(4)); Interaction.GuardFunction = (short)GetShortBits(BArray); BArray = new BitArray(Reader.ReadBytes(4)); Interaction.MotiveEntries = (int)GetLongBits(BArray); BArray = new BitArray(Reader.ReadBytes(4)); Interaction.Flags = (int)GetLongBits(BArray); BArray = new BitArray(Reader.ReadBytes(4)); Interaction.StrTableIndex = (int)GetLongBits(BArray); BArray = new BitArray(Reader.ReadBytes(4)); Interaction.AttenuationCode = (int)GetLongBits(BArray); BArray = new BitArray(Reader.ReadBytes(4)); Interaction.AttenuationValue = (int)GetLongBits(BArray); BArray = new BitArray(Reader.ReadBytes(4)); Interaction.Autonomy = (int)GetLongBits(BArray); BArray = new BitArray(Reader.ReadBytes(4)); Interaction.JoinIndex = (int)GetLongBits(BArray); m_Interactions.Add(Interaction); } break; } Reader.Close(); }