예제 #1
0
        /// <summary>
        ///     Writes a Subtitle Packet to a Stream.
        /// </summary>
        /// <param name="Writer">The writer of the output Stream</param>
        /// <param name="PacketText">The packet to be written</param>
        /// <param name="Game">The game being tampered</param>
        public static void ToStream(EndianBinaryWriter Writer, SubtitlePacket Packet, MGSGame Game)
        {
            using (MemoryStream Content = new MemoryStream())
            {
                EndianBinaryWriter CWriter = new EndianBinaryWriter(Content, Writer.Endian);

                foreach (SubtitlePacketText Text in Packet.Texts)
                {
                    SubtitlePacketText.ToStream(CWriter, Text, Game);
                }

                int Length = (int)Content.Length + 0x14 + 1;
                if ((Length & 0xf) != 0)
                {
                    Length = (Length & ~0xf) + 0x10;
                }

                Writer.Write(Packet.StreamId);
                Writer.Write(Length);

                Writer.Write(Packet.BaseStartTime);
                Writer.Write(0u);
                Writer.Write((uint)Content.Length);

                Writer.Write(Content.ToArray());
                Writer.Write((byte)0);

                while ((Writer.BaseStream.Position & 0xf) != 0)
                {
                    Writer.Write((byte)0);
                }
            }
        }
예제 #2
0
        /// <summary>
        ///     Writes a Packet to a Stream.
        /// </summary>
        /// <param name="Writer">The writer of the output Stream</param>
        /// <param name="PacketText">The packet to be written</param>
        /// <param name="Game">The game being tampered</param>
        public static void ToStream(EndianBinaryWriter Writer, StreamPacket Packet, MGSGame Game)
        {
            switch (Packet.Type)
            {
            case PacketType.Subtitle: SubtitlePacket.ToStream(Writer, (SubtitlePacket)Packet, Game); break;

            case PacketType.EndOfStream: EndOfStreamPacket.ToStream(Writer, (EndOfStreamPacket)Packet); break;

            case PacketType.Raw: RawPacket.ToStream(Writer, (RawPacket)Packet); break;
            }
        }
예제 #3
0
        /// <summary>
        ///     Reads a Packet from a Stream.
        /// </summary>
        /// <param name="Reader">The reader of the Stream where the data is located</param>
        /// <param name="Game">The game being tampered</param>
        /// <returns>The packet as a object</returns>
        public static StreamPacket FromStream(EndianBinaryReader Reader, MGSGame Game)
        {
            uint StreamId = Reader.ReadUInt32() & 0xff;

            Reader.Seek(-4, SeekOrigin.Current);

            switch (StreamId)
            {
            case 4: return(SubtitlePacket.FromStream(Reader, Game));

            case 0xf0: return(EndOfStreamPacket.FromStream(Reader));

            default: return(RawPacket.FromStream(Reader));
            }
        }
예제 #4
0
        /// <summary>
        ///     Reads a Subtitle Packet from a Stream.
        /// </summary>
        /// <param name="Reader">The reader of the Stream where the data is located</param>
        /// <param name="Game">The game being tampered</param>
        /// <returns>The packet as a object</returns>
        public new static SubtitlePacket FromStream(EndianBinaryReader Reader, MGSGame Game)
        {
            SubtitlePacket Packet       = new SubtitlePacket();
            long           BasePosition = Reader.BaseStream.Position;

            Packet.StreamId = Reader.ReadUInt32();
            uint PacketLength = Reader.ReadUInt32();
            long EndPosition  = BasePosition + PacketLength;

            Packet.BaseStartTime = Reader.ReadUInt32();
            uint Dummy      = Reader.ReadUInt32();
            uint DataLength = Reader.ReadUInt32();

            while (Reader.BaseStream.Position + 0x10 < EndPosition)
            {
                Packet.Texts.Add(SubtitlePacketText.FromStream(Reader, Game));
            }

            Reader.Seek(EndPosition, SeekOrigin.Begin);

            return(Packet);
        }