当前位置: 首页>>代码示例>>C#>>正文


C# BinaryWriter.Seek方法代码示例

本文整理汇总了C#中System.IO.BinaryWriter.Seek方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryWriter.Seek方法的具体用法?C# BinaryWriter.Seek怎么用?C# BinaryWriter.Seek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.BinaryWriter的用法示例。


在下文中一共展示了BinaryWriter.Seek方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MessageShouldBeSameAfterSerializationAndDeserialization

        public void MessageShouldBeSameAfterSerializationAndDeserialization()
        {
            var writer = new BinaryWriter(new MemoryStream());
            IMessageFactory msgFactory = new MessageFactory(new Message[]
                {
                    new ISomeServiceComplexRequest()
                });

            var fixture = new Fixture();
            fixture.Customize<ISomeServiceComplexRequest>(ob =>
                ob.With(x => x.datas,
                    fixture.CreateMany<SubData>().ToList()));
            fixture.Customize<ComplexData>(ob => ob
                .With(x => x.SomeArrString, fixture.CreateMany<string>().ToList())
                .With(x => x.SomeArrRec, fixture.CreateMany<SubData>().ToList()));

            var msg = fixture.CreateAnonymous<ISomeServiceComplexRequest>();

            //serialize and deserialize msg1
            msg.Serialize(writer);
            writer.Seek(0, SeekOrigin.Begin);
            var reader = new BinaryReader(writer.BaseStream);
            Message retMsg = msgFactory.Deserialize(reader);

            retMsg.Should().BeOfType<ISomeServiceComplexRequest>();
            msg.ShouldBeEqualTo((ISomeServiceComplexRequest)retMsg);
        }
开发者ID:tlotter,项目名称:MassiveOnlineUniversalServerEngine,代码行数:27,代码来源:MessageSerializationTests.cs

示例2: Write

        public override void Write(BinaryWriter writer)
        {
            WriteH(writer, 0); //Sender shift
            WriteH(writer, 0); //Message shift
            WriteD(writer, Type.GetHashCode());

            WriteUid(writer, Player);

            byte isGm = 0;

            if (Player != null)
                isGm = (byte)(Communication.Global.AdminEngine.IsGM(Player) ? 1 : 0);

            WriteC(writer, 0); //Blue shit
            WriteC(writer, isGm); //GM

            if (Player != null)
            {
                writer.Seek(4, SeekOrigin.Begin);
                WriteH(writer, (short) writer.BaseStream.Length);
                writer.Seek(0, SeekOrigin.End);

                WriteS(writer, Player.PlayerData.Name);
            }

            writer.Seek(6, SeekOrigin.Begin);
            WriteH(writer, (short) writer.BaseStream.Length);
            writer.Seek(0, SeekOrigin.End);

            WriteS(writer, Message);

            WriteC(writer, 0);
        }
开发者ID:bobobear,项目名称:TeraEmulator,代码行数:33,代码来源:SpChatMessage.cs

示例3: Query

        public void Query(string strAddress, ushort unPort)
        {
            // Build the packet.
            byte[] byPacket = new byte[PT_ASKINFO_SIZE];
            BinaryWriter bw = new BinaryWriter(new MemoryStream(byPacket));

            bw.Seek(4, SeekOrigin.Begin);		// Skip the checksum.
            bw.Write((byte)0);					// ack
            bw.Write((byte)0);					// ackreturn
            bw.Write((byte)PT_ASKINFO);			// Packet type.
            bw.Write((byte)0);					// Reserved.
            bw.Write((byte)0);					// Version. This is actually unnecessary -- the client will reply anyway. -MattW_CFI
            bw.Write((byte)0);					// Reserved.
            bw.Write((byte)0);					// Reserved.
            bw.Write((byte)0);					// Reserved.
            // Time for ping calculation.
            bw.Write(unchecked((uint)(DateTime.Now.Ticks / 10000)));

            // Calculate the checksum.
            bw.Seek(0, SeekOrigin.Begin);
            bw.Write(SRB2Checksum(byPacket));

            // Send the packet.
            udpclient.Send(byPacket, byPacket.Length, strAddress, unPort);
        }
开发者ID:HipsterLion,项目名称:SRB2,代码行数:25,代码来源:ServerQuerier.cs

示例4: Write

        public override void Write(BinaryWriter writer)
        {
            if (TestNpcHex != null)
            {
                WriteB(writer, TestNpcHex);
                return;
            }

            WriteD(writer, 0); //???
            WriteH(writer, 0); //Shit shift

            WriteUid(writer, Npc);
            WriteUid(writer, Npc.Target);
            WriteF(writer, Npc.Position.X);
            WriteF(writer, Npc.Position.Y);
            WriteF(writer, Npc.Position.Z);
            WriteH(writer, Npc.Position.Heading);
            WriteD(writer, 12); //???
            WriteD(writer, Npc.SpawnTemplate.NpcId);
            WriteH(writer, Npc.SpawnTemplate.Type);
            WriteD(writer, 0); //ModelId

            WriteB(writer, "000000000500000001010100000000000000000000000000000000000000");

            WriteUid(writer, Npc.Target); //If 1 agressiv

            WriteB(writer, "000000000000000000");

            writer.Seek(8, SeekOrigin.Begin);
            WriteH(writer, (short) writer.BaseStream.Length); //Shit shift
            writer.Seek(0, SeekOrigin.End);

            WriteB(writer, "45C5C8B958C72000E4C2D8D5B4CC0000"); //Shit
        }
开发者ID:CadeLaRen,项目名称:TeraEmulator,代码行数:34,代码来源:SpNpcInfo.cs

示例5: Play

        // Conversion extracted from the sample voice_synthesis.cs (RSSDK\framework\CSharp\voice_synthesis.cs)
        // To understand a little bit more about the WAV file format, acess the following links: 
        //     - http://www-mmsp.ece.mcgill.ca/documents/AudioFormats/WAVE/WAVE.html
        //     - http://www.sonicspot.com/guide/wavefiles.html
        public static void Play(PXCMAudio.AudioData audioData, PXCMAudio.AudioInfo audioInfo) {
            using (var memoryStream = new MemoryStream()) {
                using (var bw = new BinaryWriter(memoryStream)) {
                    bw.Write(0x46464952);  // chunkIdRiff:'FFIR'
                    bw.Write(0);           // chunkDataSizeRiff
                    bw.Write(0x45564157);  // riffType:'EVAW'
                    bw.Write(0x20746d66);  // chunkIdFmt:' tmf'
                    bw.Write(0x12);        // chunkDataSizeFmt
                    bw.Write((short)1);         // compressionCode
                    bw.Write((short)audioInfo.nchannels);  // numberOfChannels
                    bw.Write(audioInfo.sampleRate);   // sampleRate
                    bw.Write(audioInfo.sampleRate * 2 * audioInfo.nchannels); // averageBytesPerSecond
                    bw.Write((short)(audioInfo.nchannels * 2));   // blockAlign
                    bw.Write((short)16);        // significantBitsPerSample
                    bw.Write((short)0);         // extraFormatSize
                    bw.Write(0x61746164);  // chunkIdData:'atad'
                    bw.Write(0);           // chunkIdSizeData

                    bw.Write(audioData.ToByteArray());
                    long pos = bw.Seek(0, SeekOrigin.Current);
                    bw.Seek(0x2a, SeekOrigin.Begin); // chunkDataSizeData
                    bw.Write((int)(pos - 46));
                    bw.Seek(0x04, SeekOrigin.Begin); // chunkDataSizeRiff
                    bw.Write((int)(pos - 8));
                    bw.Seek(0, SeekOrigin.Begin);

                    using (var soundPlayer = new SoundPlayer(memoryStream)) {
                        soundPlayer.PlaySync();
                    }
                }
            }
        }
开发者ID:mbahar94,项目名称:SharpSenses,代码行数:36,代码来源:RealSenseAudioPlayer.cs

示例6: Write

        public override void Write(BinaryWriter writer)
        {
            WriteH(writer, (short) FlyTeleports.Count);
            WriteH(writer, 8);

            for (int i = 0; i < FlyTeleports.Count; i++)
            {
                WriteH(writer, (short)writer.BaseStream.Length);

                short shift = (short) writer.BaseStream.Length;
                WriteH(writer, 0);

                WriteD(writer, FlyTeleports[i].Id);
                WriteD(writer, FlyTeleports[i].Cost);
                WriteD(writer, FlyTeleports[i].FromNameId);
                WriteD(writer, FlyTeleports[i].ToNameId);
                WriteD(writer, FlyTeleports[i].Level);

                if(FlyTeleports.Count >= i+1)
                {
                    writer.Seek(shift, SeekOrigin.Begin);
                    WriteH(writer, (short) writer.BaseStream.Length);
                    writer.Seek(0, SeekOrigin.End);
                }
            }
        }
开发者ID:ZettaZero,项目名称:TeraEmulator,代码行数:26,代码来源:SpFlightPoints.cs

示例7: Write

        public override void Write(BinaryWriter writer)
        {
            WriteH(writer, 0); //Name shift
            WriteH(writer, 0); //Details shift
            WriteH(writer, (short) Player.PlayerData.Details.Length); //Details length

            WriteD(writer, Player.PlayerData.SexRaceClass);
            WriteUid(writer, Player);

            WriteD(writer, 11); //???

            WriteD(writer, Player.PlayerId);
            WriteB(writer, "000000000100000000460000006E000000");
            WriteB(writer, Player.PlayerData.Data); //PlayerData
            WriteC(writer, 1); //Online?
            WriteC(writer, 0); //??
            WriteD(writer, Player.GetLevel()); //Level

            WriteB(writer, "00000000000001000000000000000000");
            WriteQ(writer, Player.Exp);
            WriteQ(writer, Player.GetExpShown());
            WriteQ(writer, Player.GetExpNeed());
            WriteB(writer, "0000000000000000461600000000000000000000");

            WriteD(writer, Player.Inventory.GetItemId(1) ?? 0); //Item (hands)
            WriteD(writer, Player.Inventory.GetItemId(3) ?? 0); //Item (body)
            WriteD(writer, Player.Inventory.GetItemId(4) ?? 0); //Item (gloves)
            WriteD(writer, Player.Inventory.GetItemId(5) ?? 0); //Item (shoes)
            WriteD(writer, 0); //Item (???)
            WriteD(writer, 0); //Item (???)

            WriteB(writer, "5E10C101000000000100000000000000000000000000000000000000000000000000000000");

            WriteD(writer, Player.Inventory.GetItem(1) != null ? Player.Inventory.GetItem(1).Color : 0);
            WriteD(writer, Player.Inventory.GetItem(3) != null ? Player.Inventory.GetItem(3).Color : 0);
            WriteD(writer, Player.Inventory.GetItem(4) != null ? Player.Inventory.GetItem(4).Color : 0);
            WriteD(writer, Player.Inventory.GetItem(5) != null ? Player.Inventory.GetItem(5).Color : 0);
            WriteD(writer, 0); //Item ???
            WriteD(writer, 0); //Item ???

            WriteB(writer, "0001000000000000000000000000");

            writer.Seek(4, SeekOrigin.Begin);
            WriteH(writer, (short) (writer.BaseStream.Length)); //Name shift
            writer.Seek(0, SeekOrigin.End);

            WriteS(writer, Player.PlayerData.Name);

            writer.Seek(6, SeekOrigin.Begin);
            WriteH(writer, (short) (writer.BaseStream.Length)); //Details shift
            writer.Seek(0, SeekOrigin.End);

            WriteB(writer, Player.PlayerData.Details);

            //1603
            //C300D5002000 7A270000 87170B0000800002          7D900000000000000100000000460000006E000000650C00070D0F0400010001000000000000000000010000000000000000000100000000000000010000000000000048030000000000000000000000000000461600000000000000000000162700009C3A00009D3A00009E3A0000                  AD3F1C0F00000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000                            41006C006500680061006E006400720000000C0B10021710090A151910001006100008100C0C10150C101010160C0E100F15

            //1725
            //DC00E4002000 FE2A0000 D2340B0000800000 0B000000 A7250000000000000100000000460000006E0000006503040102050400010001000000000000000000010000000000000000000100000000000000010000000000000048030000000000000000000000000000A30100000000000000000000162700009C3A00009D3A00009E3A0000 0000000000000000 16DBB70300000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 01000000000000000000000000 45006C00610000000601020700000000180F1A00010000000F0001000000000F1517101019100909
        }
开发者ID:CadeLaRen,项目名称:TeraEmulator,代码行数:60,代码来源:SpCharacterInit.cs

示例8: Write

        public override void Write(BinaryWriter writer)
        {
            WriteH(writer, (short) Tradelist.ItemsByTabs.Count);
            WriteB(writer, "2000B008B8030080000E"); //2000 mb shift?
            WriteD(writer, (int) DateTime.Now.Ticks);
            WriteH(writer, 0x3EC0); // ???
            WriteH(writer, 0);

            WriteB(writer, "7B14AE47E17A843F");

            foreach (KeyValuePair<int, List<int>> tab in Tradelist.ItemsByTabs)
            {
                WriteH(writer, (short) writer.BaseStream.Length);
                WriteH(writer, 0); //next tab shift

                WriteH(writer, (short) tab.Value.Count);
                WriteH(writer, (short) (writer.BaseStream.Length + 6)); //first item shift
                WriteD(writer, tab.Key); // name Id

                writer.Seek((int) writer.BaseStream.Length - 10, SeekOrigin.Begin);
                WriteH(writer, (short) (writer.BaseStream.Length + tab.Value.Count*8));
                writer.Seek(0, SeekOrigin.End);

                for (int i = 0; i < tab.Value.Count; i++)
                {
                    short nowItemShift = (short) writer.BaseStream.Length;
                    WriteH(writer, nowItemShift); //now item shift
                    WriteH(writer, (short) (i == tab.Value.Count - 1 ? 0 : nowItemShift + 8)); //next item shift
                    WriteD(writer, tab.Value[i]);
                }
            }
        }
开发者ID:ZettaZero,项目名称:TeraEmulator,代码行数:32,代码来源:SpTradeList.cs

示例9: Write

        //public SpPartyAbnormals(Player player) // WRONG
        //{
        //    Player = player;
        //}
        public override void Write(BinaryWriter writer)
        {
            WriteD(writer, 0);
            WriteH(writer, (short) Player.Effects.Count);
            WriteH(writer, 0); //first effect shift
            WriteD(writer, 11); //hello AGAIN, fucking 0x0b shit...how are you? -_-
            WriteD(writer, Player.PlayerId);

            writer.Seek(10, SeekOrigin.Begin);
            WriteH(writer, (short) writer.BaseStream.Length);
            writer.Seek(0, SeekOrigin.End);

            for (int i = 0; i < Player.Effects.Count; i++)
            {
                short shPos = (short) writer.BaseStream.Position;

                WriteH(writer, shPos);
                WriteH(writer, 0); //next abnormal
                WriteD(writer, 0);
                WriteD(writer, 0);
                WriteC(writer, 1); //possible IsBuff

                if (Player.Effects.Count > i + 1)
                {
                    writer.Seek(shPos + 2, SeekOrigin.Begin);
                    WriteH(writer, (short) writer.BaseStream.Length);
                    writer.Seek(0, SeekOrigin.End);
                }
            }
        }
开发者ID:ZettaZero,项目名称:TeraEmulator,代码行数:34,代码来源:SpPartyAbnormals.cs

示例10: Write

        public override void Write(BinaryWriter writer)
        {
            //B2C0 0000000000000000 0ECE020000800B00 734F633F 00000000 09000000 00000000000000000000000000000000401F000005000000
            //B2C0 0100380000000000 F042030000800B00 F734423E 00000000 09000000 00000000000000000000000000000000401F000005000000 38000000E02A0900E803000001000000

            lock (Creature.EffectsLock)
            {
                WriteH(writer, (short) Creature.Effects.Count);
                int effectShift = (int) writer.BaseStream.Position;
                WriteH(writer, 0); //first Abnormal shift
                WriteD(writer, 0); //unk
                WriteUid(writer, Creature);
                WriteF(writer, (Creature.LifeStats.Hp/(Creature.MaxHp/100F))/100F);
                WriteD(writer, 0);
                WriteD(writer, Creature.GetLevel()); //npc level
                WriteB(writer, "00000000000000000000000000000000401F000005000000".ToBytes()); // ololo o_O

                for (int i = 0; i < Creature.Effects.Count; i++)
                {
                    writer.Seek(effectShift, SeekOrigin.Begin);
                    WriteH(writer, (short) writer.BaseStream.Length);
                    writer.Seek(0, SeekOrigin.End);

                    WriteH(writer, (short) writer.BaseStream.Length);
                    effectShift = (int) writer.BaseStream.Position;
                    WriteH(writer, 0); //posible next Abnormal shift
                    WriteD(writer, Creature.Effects[i].Abnormality.Id);
                    WriteD(writer, Creature.Effects[i].TimeRemain);
                    WriteD(writer, 1);
                }
            }
        }
开发者ID:ZettaZero,项目名称:TeraEmulator,代码行数:32,代码来源:SpNpcHpWindow.cs

示例11: GenericInject

 public static void GenericInject(string Filename, int Offset, byte[] Data, int Length)
 {
     BinaryWriter BW = new BinaryWriter(File.OpenWrite(Filename));
     BW.Seek(Offset, SeekOrigin.Begin);
     BW.Write(new byte[Length], 0, Length);
     BW.Seek(Offset, SeekOrigin.Begin);
     BW.Write(Data);
     BW.Close();
 }
开发者ID:xdanieldzd,项目名称:sharpocarina,代码行数:9,代码来源:Helpers.cs

示例12: Write

        public override void Write(BinaryWriter writer)
        {
            WriteWord(writer, 0); // shift
            WriteUid(writer, Npc);

            writer.Seek(4, SeekOrigin.Begin);
            WriteWord(writer, (short) writer.BaseStream.Length);
            writer.Seek(0, SeekOrigin.End);

            WriteString(writer, Options);
        }
开发者ID:arkanoid1,项目名称:Temu,代码行数:11,代码来源:SpNpcTalk.cs

示例13: Write

        public override void Write(BinaryWriter writer)
        {
            WriteH(writer, 0); //name shift
            WriteD(writer, 11);
            WriteD(writer, Player.PlayerId);

            writer.Seek(4, SeekOrigin.Begin);
            WriteH(writer, (short) writer.BaseStream.Length);
            writer.Seek(0, SeekOrigin.End);

            WriteS(writer, Player.PlayerData.Name);
        }
开发者ID:ZettaZero,项目名称:TeraEmulator,代码行数:12,代码来源:SpPartyRemoveMember.cs

示例14: WriteToFile

 public static void WriteToFile(DataUnit dataPage, BinaryWriter writer)
 {
     long initPos = writer.Seek(100L + (dataPage.UnitID * 0x1000L));
     writer.Write((byte) dataPage.Type);
     writer.Write(dataPage.NextUnitID);
     writer.Write(dataPage.IsEmpty);
     writer.Write(dataPage.DataBlockLength);
     if (!dataPage.IsEmpty)
     {
         writer.Seek(initPos + 8L);
         writer.Write(dataPage.DataBlock, 0, dataPage.DataBlockLength);
     }
 }
开发者ID:mind0n,项目名称:hive,代码行数:13,代码来源:UnitFactory.cs

示例15: WriteCues

 private void WriteCues(BinaryWriter w)
 {
     // write the cue chunks to the end of the stream
     if (cues != null)
     {
         byte[] cueChunks = cues.GetRIFFChunks();
         int cueChunksSize = cueChunks.Length;
         w.Seek(0, SeekOrigin.End);
         w.Write(cues.GetRIFFChunks(), 0, cueChunksSize);
         w.Seek(4, SeekOrigin.Begin);
         w.Write((int)(w.BaseStream.Length - 8));
     }
 }
开发者ID:BGCX261,项目名称:ziggy-pro-editor-svn-to-git,代码行数:13,代码来源:CueWaveFileWriter.cs


注:本文中的System.IO.BinaryWriter.Seek方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。