/// <summary> /// Reads the condition data from the underlying stream. /// </summary> /// <param name="reader">The reader.</param> public void Read(BinaryReader reader) { reader.BaseStream.Seek(-8, SeekOrigin.Current); int size = reader.ReadInt32() - 8; UseText = size != 4; reader.BaseStream.Seek(4, SeekOrigin.Current); if (reader.GetType() == typeof(AlignedBinaryReader)) { AlignedBinaryReader alignedReader = (AlignedBinaryReader)reader; alignedReader.Reset(); if (UseText) { alignedReader.DisableAlignment = true; } } if (UseText) { Text = reader.ReadString(size); } else { StringID = reader.ReadInt32(); } }
/// <summary> /// Reads the condition data from the underlying stream. /// </summary> /// <param name="reader">The reader.</param> public void Read(BinaryReader reader) { reader.BaseStream.Seek(-8, SeekOrigin.Current); int size = reader.ReadInt32() - 8; LevelDifferenceEnabled = size == 8; reader.BaseStream.Seek(4, SeekOrigin.Current); if (reader.GetType() == typeof(AlignedBinaryReader)) { AlignedBinaryReader alignedReader = (AlignedBinaryReader)reader; alignedReader.Reset(); } Distance = reader.ReadInt32(); IsAllied = reader.ReadBoolean(); if (!LevelDifferenceEnabled) { MinimumLevelDifference = reader.ReadInt16(); MaxmimumLevelDifference = reader.ReadInt16(); } else { LevelDifference = reader.ReadByte(); } CharacterCount = reader.ReadInt16(); }
/// <summary> /// Reads the condition data from the underlying stream. /// </summary> /// <param name="reader">The reader.</param> public void Read(BinaryReader reader) { if (reader.GetType() == typeof(AlignedBinaryReader)) { AlignedBinaryReader alignedReader = (AlignedBinaryReader)reader; alignedReader.DisableAlignment = true; } Trigger = reader.ReadShortString(); }
/// <summary> /// Loads the file from the specified stream. /// </summary> /// <param name="stream">The stream to read from.</param> public override void Load(Stream stream) { BinaryReader reader = new BinaryReader(stream, CodePagesEncodingProvider.Instance.GetEncoding("EUC-KR")); AlignedBinaryReader alignedReader = new AlignedBinaryReader(stream, CodePagesEncodingProvider.Instance.GetEncoding("EUC-KR")); int patternCount = reader.ReadInt32(); IdleInterval = reader.ReadInt32(); DamageRate = reader.ReadInt32(); Name = reader.ReadIntString(); for (int i = 0; i < patternCount; i++) { var pattern = new ArtificialIntelligencePattern(); pattern.Name = reader.ReadString(32).TrimEnd('\0'); int eventCount = reader.ReadInt32(); for (int j = 0; j < eventCount; j++) { var @event = new ArtificialIntelligenceEvent(); @event.Name = reader.ReadString(32).TrimEnd('\0'); int conditionCount = reader.ReadInt32(); for (int k = 0; k < conditionCount; k++) { long position = stream.Position; int size = reader.ReadInt32(); var type = (ArtificialIntelligenceCondition)(reader.ReadInt32() ^ CONDITION_MASK); if (!Enum.IsDefined(typeof(ArtificialIntelligenceCondition), type)) { throw new InvalidArtificialIntelligenceConditionException((int)type); } Type classType = type.GetAttributeValue <ArtificialIntelligenceTypeAttribute, Type>(x => x.Type); var condition = (IArtificialIntelligenceCondition)Activator.CreateInstance(classType); alignedReader.Reset(); condition.Read(alignedReader); alignedReader.Align(); @event.Conditions.Add(condition); if (stream.Position - position != size) { stream.Seek(position + size, SeekOrigin.Begin); } } int actionCount = reader.ReadInt32(); for (int k = 0; k < actionCount; k++) { long position = stream.Position; int size = reader.ReadInt32(); var type = (ArtificialIntelligenceAction)(reader.ReadInt32() ^ ACTION_MASK); if (!Enum.IsDefined(typeof(ArtificialIntelligenceAction), type)) { throw new InvalidArtificialIntelligenceActionException((int)type); } Type classType = type.GetAttributeValue <ArtificialIntelligenceTypeAttribute, Type>(x => x.Type); var action = (IArtificialIntelligenceAction)Activator.CreateInstance(classType); alignedReader.Reset(); action.Read(alignedReader); alignedReader.Align(); @event.Actions.Add(action); if (stream.Position - position != size) { stream.Seek(position + size, SeekOrigin.Begin); } } pattern.Events.Add(@event); } Patterns.Add(pattern); } }