public static FlowScriptBinary FromStream(Stream stream, BinaryFormatVersion version, bool leaveOpen = false) { using (var reader = new FlowScriptBinaryReader(stream, version, leaveOpen)) { return(reader.ReadBinary()); } }
private void FromFile_ResultNotNullAndFormatIsEqualToParameter(BinaryFormatVersion version, BinaryFormatVersion actualVersion) { var script = FlowScriptBinary.FromFile($"TestResources\\{actualVersion}.bf", version); Assert.IsNotNull(script, "Script object should not be null"); Assert.AreEqual(actualVersion, script.FormatVersion); }
private readonly List <byte[]> mSpeakerNames; // for storing the speaker names of dialogue messages public MessageScriptBinaryBuilder(BinaryFormatVersion version) { mFormatVersion = version; mAddressLocations = new List <int>(); mSpeakerNames = new List <byte[]>(); mPosition = BinaryHeader.SIZE; mDialogs = new List <Tuple <BinaryDialogKind, object> >(); }
public BinaryHeader ReadHeader() { var header = new BinaryHeader(); // Check if the stream isn't too small to be a proper file if (mReader.BaseStreamLength < BinaryHeader.SIZE) { throw new InvalidDataException("Stream is too small to be valid"); } header.FileType = mReader.ReadByte(); header.IsCompressed = mReader.ReadByte() != 0; header.UserId = mReader.ReadInt16(); header.FileSize = mReader.ReadInt32(); header.Magic = mReader.ReadBytes(4); header.Field0C = mReader.ReadInt32(); header.RelocationTable.Offset = mReader.ReadInt32(); header.RelocationTableSize = mReader.ReadInt32(); header.DialogCount = mReader.ReadInt32(); header.IsRelocated = mReader.ReadInt16() != 0; header.Field1E = mReader.ReadInt16(); // swap endianness if (header.Magic.SequenceEqual(BinaryHeader.MAGIC_V1) || header.Magic.SequenceEqual(BinaryHeader.MAGIC_V0)) { if (mVersion.HasFlag(BinaryFormatVersion.BigEndian)) { SwapHeader(ref header); mReader.Endianness = Endianness.LittleEndian; } mVersion = BinaryFormatVersion.Version1; } else if (header.Magic.SequenceEqual(BinaryHeader.MAGIC_V1_BE)) { if (!mVersion.HasFlag(BinaryFormatVersion.BigEndian)) { SwapHeader(ref header); mReader.Endianness = Endianness.BigEndian; } mVersion = BinaryFormatVersion.Version1BigEndian; } else { throw new InvalidDataException("Header magic value does not match"); } if (header.RelocationTable.Offset != 0) { mReader.EnqueuePositionAndSeekBegin(mPositionBase + header.RelocationTable.Offset); header.RelocationTable.Value = mReader.ReadBytes(header.RelocationTableSize); mReader.SeekBeginToDequedPosition(); } return(header); }
public FlowScriptBinaryBuilder(BinaryFormatVersion version) { if (!Enum.IsDefined(typeof(BinaryFormatVersion), version)) { throw new ArgumentOutOfRangeException(nameof(version), $"Value should be defined in the {nameof( BinaryFormatVersion )} enum."); } mFormatVersion = version; }
public static MessageScriptBinary FromStream(Stream stream, BinaryFormatVersion version, bool leaveOpen = false) { if (stream == null) { throw new ArgumentNullException(nameof(stream)); } if (!Enum.IsDefined(typeof(BinaryFormatVersion), version)) { throw new InvalidEnumArgumentException(nameof(version), ( int )version, typeof(BinaryFormatVersion)); } using (var reader = new MessageScriptBinaryReader(stream, version, leaveOpen)) { return(reader.ReadBinary()); } }
public FlowScriptBinaryBuilder(BinaryFormatVersion version, bool matching = true) { if (!Enum.IsDefined(typeof(BinaryFormatVersion), version)) { throw new ArgumentOutOfRangeException(nameof(version), $"Value should be defined in the {nameof( BinaryFormatVersion )} enum."); } mFormatVersion = version; mMatching = matching; if (mMatching) { // if matching then all sections are present regardless of being empty mProcedureLabelSection = new List <BinaryLabel>(); mJumpLabelSection = new List <BinaryLabel>(); mTextSection = new List <BinaryInstruction>(); mStringSection = new List <byte>(); } }
public static MessageScriptBinary FromFile(string path, BinaryFormatVersion version) { if (path == null) { throw new ArgumentNullException(nameof(path)); } if (string.IsNullOrEmpty(path)) { throw new ArgumentException("Value cannot be null or empty.", nameof(path)); } if (!Enum.IsDefined(typeof(BinaryFormatVersion), version)) { throw new InvalidEnumArgumentException(nameof(version), ( int )version, typeof(BinaryFormatVersion)); } using (var fileStream = File.OpenRead(path)) return(FromStream(fileStream, version)); }
public FlowScriptBinaryReader(Stream stream, BinaryFormatVersion version, bool leaveOpen = false) { mPositionBase = stream.Position; mReader = new EndianBinaryReader(stream, Encoding.GetEncoding(932), leaveOpen, version.HasFlag(BinaryFormatVersion.BigEndian) ? Endianness.BigEndian : Endianness.LittleEndian); mVersion = version; }
public static FlowScriptBinary FromFile(string path, BinaryFormatVersion version) { using (var fileStream = File.OpenRead(path)) return(FromStream(fileStream, version)); }
public MessageScriptBinaryWriter(Stream stream, BinaryFormatVersion version, bool leaveOpen = false) { mPositionBase = stream.Position; mWriter = new EndianBinaryWriter(stream, Encoding.ASCII, leaveOpen, version.HasFlag(BinaryFormatVersion.BigEndian) ? Endianness.BigEndian : Endianness.LittleEndian); }