public TTAB(IffChunk Chunk) : base(Chunk) { MemoryStream MemStream = new MemoryStream(Chunk.Data); BinaryReader Reader = new BinaryReader(MemStream); m_InteractionCount = Reader.ReadUInt16(); if (m_InteractionCount > 0) { m_Version = Reader.ReadUInt16(); try { long FieldValue = 0; if (m_Version == 9 || m_Version == 10) { m_CompressionCode = Reader.ReadByte(); m_FEncodingData.CompressionCode = m_CompressionCode; m_FEncodingData.FieldWidths = new byte[] { 5, 8, 13, 16, 6, 11, 21, 32 }; m_FEncodingData.EncodedDataLength = (uint)(Reader.BaseStream.Length - Reader.BaseStream.Position); m_FEncodingData.EncodedData = Reader.ReadBytes((int)m_FEncodingData.EncodedDataLength); } for (ushort i = 0; i < m_InteractionCount; i++) { if (m_Version == 9 || m_Version == 10) { Interaction Action = new Interaction(); m_FReader.DecodeField(ref m_FEncodingData, 0, ref FieldValue); Action.ActionFuncID = (short)FieldValue; m_FReader.DecodeField(ref m_FEncodingData, 0, ref FieldValue); Action.GuardFuncID = (short)FieldValue; m_FReader.DecodeField(ref m_FEncodingData, 1, ref FieldValue); Action.MotiveEntryCount = (uint)FieldValue; m_FReader.DecodeField(ref m_FEncodingData, 1, ref FieldValue); Action.Flags = (uint)FieldValue; m_FReader.DecodeField(ref m_FEncodingData, 1, ref FieldValue); Action.TTAID = (uint)FieldValue; m_FReader.DecodeField(ref m_FEncodingData, 1, ref FieldValue); Action.AttenuationCode = (uint)FieldValue; m_FReader.DecodeField(ref m_FEncodingData, 1, ref FieldValue); Action.AttenuationValue = (float)FieldValue; m_FReader.DecodeField(ref m_FEncodingData, 1, ref FieldValue); Action.AutonomyThreshold = (uint)FieldValue; m_FReader.DecodeField(ref m_FEncodingData, 1, ref FieldValue); Action.JoiningIndex = (int)FieldValue; for (uint j = 0; j < Action.MotiveEntryCount; j++) { Motive MotiveEntry = new Motive(); m_FReader.DecodeField(ref m_FEncodingData, 0, ref FieldValue); MotiveEntry.EffectRangeMinimum = (short)FieldValue; m_FReader.DecodeField(ref m_FEncodingData, 0, ref FieldValue); MotiveEntry.EffectRangeMaximum = (short)FieldValue; m_FReader.DecodeField(ref m_FEncodingData, 0, ref FieldValue); MotiveEntry.PersonalityModifier = (ushort)FieldValue; Action.Motives.Add(MotiveEntry); } m_Interactions.Add(Action); if(m_Version == 10) m_FReader.DecodeField(ref m_FEncodingData, 1, ref FieldValue); //Unknown... } else if (m_Version == 5 || m_Version == 7 || m_Version == 8 || m_Version == 11) { Interaction Action = new Interaction(); Action.ActionFuncID = Reader.ReadInt16(); Action.GuardFuncID = Reader.ReadInt16(); Action.MotiveEntryCount = Reader.ReadUInt32(); Action.Flags = Reader.ReadUInt32(); Action.TTAID = Reader.ReadUInt32(); if (m_Version >= 7) Action.AttenuationCode = Reader.ReadUInt32(); Action.AttenuationValue = Reader.ReadUInt32(); Action.AutonomyThreshold = Reader.ReadUInt32(); Action.JoiningIndex = Reader.ReadInt32(); for (uint j = 0; j < Action.MotiveEntryCount; j++) { Motive MotiveEntry = new Motive(); if (m_Version >= 7) MotiveEntry.EffectRangeMinimum = Reader.ReadInt16(); MotiveEntry.EffectRangeMaximum = Reader.ReadInt16(); if(m_Version >= 7) MotiveEntry.PersonalityModifier = Reader.ReadUInt16(); Action.Motives.Add(MotiveEntry); } m_Interactions.Add(Action); if (m_Version == 11) Reader.ReadBytes(4); //Unknown. } } } catch (Exception E) { Log.LogThis("Failed parsing a TTAB chunk!\r\n" + "Version: " + m_Version + "\r\n" + "InteractionCount: " + m_InteractionCount + "\r\n" + E.ToString(), eloglevel.error); } } Reader.Close(); }
public TTAB(IffChunk Chunk) : base(Chunk) { MemoryStream MemStream = new MemoryStream(Chunk.Data); BinaryReader Reader = new BinaryReader(MemStream); m_InteractionCount = Reader.ReadUInt16(); if (m_InteractionCount > 0) { m_Version = Reader.ReadUInt16(); try { long FieldValue = 0; if (m_Version == 9 || m_Version == 10) { m_CompressionCode = Reader.ReadByte(); m_FEncodingData.CompressionCode = m_CompressionCode; m_FEncodingData.FieldWidths = new byte[] { 5, 8, 13, 16, 6, 11, 21, 32 }; m_FEncodingData.EncodedDataLength = (uint)(Reader.BaseStream.Length - Reader.BaseStream.Position); m_FEncodingData.EncodedData = Reader.ReadBytes((int)m_FEncodingData.EncodedDataLength); } for (ushort i = 0; i < m_InteractionCount; i++) { if (m_Version == 9 || m_Version == 10) { Interaction Action = new Interaction(); m_FReader.DecodeField(ref m_FEncodingData, 0, ref FieldValue); Action.ActionFuncID = (short)FieldValue; m_FReader.DecodeField(ref m_FEncodingData, 0, ref FieldValue); Action.GuardFuncID = (short)FieldValue; m_FReader.DecodeField(ref m_FEncodingData, 1, ref FieldValue); Action.MotiveEntryCount = (uint)FieldValue; m_FReader.DecodeField(ref m_FEncodingData, 1, ref FieldValue); Action.Flags = (uint)FieldValue; m_FReader.DecodeField(ref m_FEncodingData, 1, ref FieldValue); Action.TTAID = (uint)FieldValue; m_FReader.DecodeField(ref m_FEncodingData, 1, ref FieldValue); Action.AttenuationCode = (uint)FieldValue; m_FReader.DecodeField(ref m_FEncodingData, 1, ref FieldValue); Action.AttenuationValue = (float)FieldValue; m_FReader.DecodeField(ref m_FEncodingData, 1, ref FieldValue); Action.AutonomyThreshold = (uint)FieldValue; m_FReader.DecodeField(ref m_FEncodingData, 1, ref FieldValue); Action.JoiningIndex = (int)FieldValue; for (uint j = 0; j < Action.MotiveEntryCount; j++) { Motive MotiveEntry = new Motive(); m_FReader.DecodeField(ref m_FEncodingData, 0, ref FieldValue); MotiveEntry.EffectRangeMinimum = (short)FieldValue; m_FReader.DecodeField(ref m_FEncodingData, 0, ref FieldValue); MotiveEntry.EffectRangeMaximum = (short)FieldValue; m_FReader.DecodeField(ref m_FEncodingData, 0, ref FieldValue); MotiveEntry.PersonalityModifier = (ushort)FieldValue; Action.Motives.Add(MotiveEntry); } m_Interactions.Add(Action); if (m_Version == 10) { m_FReader.DecodeField(ref m_FEncodingData, 1, ref FieldValue); //Unknown... } } else if (m_Version == 5 || m_Version == 7 || m_Version == 8 || m_Version == 11) { Interaction Action = new Interaction(); Action.ActionFuncID = Reader.ReadInt16(); Action.GuardFuncID = Reader.ReadInt16(); Action.MotiveEntryCount = Reader.ReadUInt32(); Action.Flags = Reader.ReadUInt32(); Action.TTAID = Reader.ReadUInt32(); if (m_Version >= 7) { Action.AttenuationCode = Reader.ReadUInt32(); } Action.AttenuationValue = Reader.ReadUInt32(); Action.AutonomyThreshold = Reader.ReadUInt32(); Action.JoiningIndex = Reader.ReadInt32(); for (uint j = 0; j < Action.MotiveEntryCount; j++) { Motive MotiveEntry = new Motive(); if (m_Version >= 7) { MotiveEntry.EffectRangeMinimum = Reader.ReadInt16(); } MotiveEntry.EffectRangeMaximum = Reader.ReadInt16(); if (m_Version >= 7) { MotiveEntry.PersonalityModifier = Reader.ReadUInt16(); } Action.Motives.Add(MotiveEntry); } m_Interactions.Add(Action); if (m_Version == 11) { Reader.ReadBytes(4); //Unknown. } } } } catch (Exception E) { Log.LogThis("Failed parsing a TTAB chunk!\r\n" + "Version: " + m_Version + "\r\n" + "InteractionCount: " + m_InteractionCount + "\r\n" + E.ToString(), eloglevel.error); } } Reader.Close(); }