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


C# GenericReader.ReadSingle方法代码示例

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


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

示例1: ParseMovementUpdateBlock

        private bool ParseMovementUpdateBlock(GenericReader gr, StringBuilder sb, StreamWriter swe, StreamWriter data, ObjectTypes objectTypeId)
        {
            Coords4 coords;
            // need figure out flags2, check flags, because we can't read packet without it...
            // flags2:

            // 0x1 - not affect data
            // 0x2 - need check
            // 0x4
            // 0x8
            // 0x10 - need check
            // 0x20 - not affect data
            // 0x100
            // 0x800
            // 0x2000 - need check
            // 0x4000
            // 0x200000
            // 0x8000000 ?
            // 0x10000000
            // 0x20000000

            sb.AppendLine("=== movement_update_block_start ===");
            uint flags2 = 0;

            UpdateFlags flags = (UpdateFlags)gr.ReadByte();
            sb.AppendLine("flags " + flags.ToString("X"));

            if ((UpdateFlags.UPDATEFLAG_LIVING & flags) != 0) // 0x20
            {
                flags2 = gr.ReadUInt32();
                sb.AppendLine("flags2 " + flags2.ToString("X8"));

                uint time = gr.ReadUInt32();
                sb.AppendLine("time " + time);
            }

            if ((UpdateFlags.UPDATEFLAG_HASPOSITION & flags) != 0) // 0x40
            {
                if ((UpdateFlags.UPDATEFLAG_TRANSPORT & flags) != 0) // 0x02
                {
                    coords = gr.ReadCoords4();
                    sb.AppendLine("coords " + coords.GetCoordsAsString());
                }
                else // strange, we read the same data :)
                {
                    coords = gr.ReadCoords4();
                    sb.AppendLine("coords " + coords.GetCoordsAsString());
                }

                if (objectTypeId == ObjectTypes.TYPEID_UNIT || objectTypeId == ObjectTypes.TYPEID_GAMEOBJECT)
                {
                    data.WriteLine();
                    data.WriteLine(objectTypeId + ": " + coords.GetCoordsAsString());
                }

                if ((flags2 & 0x0200) != 0) // transport
                {
                    ulong t_guid = gr.ReadUInt64();
                    sb.Append("t_guid " + t_guid.ToString("X2") + ", ");

                    Coords4 transport = gr.ReadCoords4();
                    sb.AppendLine("t_coords " + transport.GetCoordsAsString());

                    uint unk1 = gr.ReadUInt32(); // unk, 2.0.6 == 0x11 or random
                    sb.AppendLine("unk1 " + unk1);
                }
            }

            if ((UpdateFlags.UPDATEFLAG_LIVING & flags) != 0) // 0x20
            {
                uint unk1 = gr.ReadUInt32();
                sb.AppendLine("unk1 " + unk1);

                if ((flags2 & 0x2000) != 0) // <---
                {
                    // looks like orientation/coords/speed
                    float unk2 = gr.ReadSingle();
                    sb.AppendLine("unk2 " + unk2);
                    float unk3 = gr.ReadSingle();
                    sb.AppendLine("unk3 " + unk3);
                    float unk4 = gr.ReadSingle();
                    sb.AppendLine("unk4 " + unk4);
                    float unk5 = gr.ReadSingle();
                    sb.AppendLine("unk5 " + unk5);
                }

                float ws = gr.ReadSingle();
                sb.AppendLine("Walk speed " + ws);
                float rs = gr.ReadSingle();
                sb.AppendLine("Run speed " + rs);
                float sbs = gr.ReadSingle();
                sb.AppendLine("Swimback speed " + sbs);
                float ss = gr.ReadSingle();
                sb.AppendLine("Swim speed " + ss);
                float wbs = gr.ReadSingle();
                sb.AppendLine("Walkback speed " + wbs);
                float fs = gr.ReadSingle();
                sb.AppendLine("Fly speed " + fs);
                float fbs = gr.ReadSingle();
                sb.AppendLine("Flyback speed " + fbs);
//.........这里部分代码省略.........
开发者ID:arkanoid1,项目名称:mywowtools,代码行数:101,代码来源:a9_parser.cs

示例2: ParseValuesUpdateBlock

        private bool ParseValuesUpdateBlock(GenericReader gr, StringBuilder sb, StreamWriter swe, StreamWriter data, ObjectTypes objectTypeId, UpdateTypes updatetype)
        {
            // may be we can reduce size of code there...

            sb.AppendLine("=== values_update_block_start ===");

            byte blocks_count = gr.ReadByte(); // count of update blocks (4 bytes for each update block)
            sb.AppendLine("Bit mask blocks count: " + blocks_count);

            uint[] updatemask = new uint[blocks_count]; // create array of update blocks
            for (int j = 0; j < blocks_count; j++)
                updatemask[j] = gr.ReadUInt32(); // populate array of update blocks with data

            Mask = (BitArr)updatemask; // convert array of update blocks to bitmask array

            int reallength = Mask.RealLength; // bitmask size (bits)

            // item/container values update block
            if (objectTypeId == ObjectTypes.TYPEID_ITEM || objectTypeId == ObjectTypes.TYPEID_CONTAINER)
            {
                if (reallength > 160) // 5*32, ??
                {
                    long pos = gr.BaseStream.Position;
                    swe.WriteLine("error position " + pos.ToString("X2"));

                    swe.WriteLine("error while parsing ITEM values update block, count " + reallength);
                    return false;
                }

                for (uint index = 0; index < reallength; index++)
                {
                    if (index > UpdateFields.ITEM_END)
                        break;

                    if (Mask[index])
                    {
                        switch (UpdateFields.item_updatefields[index].type)
                        {
                            case 1:
                                sb.AppendLine(UpdateFields.item_updatefields[index].name + " (" + index + "): " + gr.ReadSingle().ToString().Replace(",", "."));
                                break;
                            default:
                                sb.AppendLine(UpdateFields.item_updatefields[index].name + " (" + index + "): " + gr.ReadUInt32());
                                break;
                        }
                    }
                }
            }

            // unit values update block
            if (objectTypeId == ObjectTypes.TYPEID_UNIT)
            {
                if (reallength > 256) // 32*8 (for units bitmask = 8)
                {
                    long pos = gr.BaseStream.Position;
                    swe.WriteLine("error position " + pos.ToString("X2"));

                    swe.WriteLine("error while parsing UNIT values update block, count " + reallength);
                    return false;
                }

                for (uint index = 0; index < reallength; index++)
                {
                    if (index > UpdateFields.UNIT_END)
                        break;

                    if (Mask[index])
                    {
                        switch (UpdateFields.unit_updatefields[index].type)
                        {
                            case 1:
                                string val1 = gr.ReadSingle().ToString().Replace(",", ".");
                                if(updatetype == UpdateTypes.UPDATETYPE_CREATE_OBJECT || updatetype == UpdateTypes.UPDATETYPE_CREATE_OBJECT2)
                                    data.WriteLine(UpdateFields.unit_updatefields[index].name + " (" + index + "): " + val1);
                                sb.AppendLine(UpdateFields.unit_updatefields[index].name + " (" + index + "): " + val1);
                                break;
                            default:
                                uint val2 = gr.ReadUInt32();
                                if (updatetype == UpdateTypes.UPDATETYPE_CREATE_OBJECT || updatetype == UpdateTypes.UPDATETYPE_CREATE_OBJECT2)
                                    data.WriteLine(UpdateFields.unit_updatefields[index].name + " (" + index + "): " + val2);
                                sb.AppendLine(UpdateFields.unit_updatefields[index].name + " (" + index + "): " + val2);
                                break;
                        }
                    }
                }
            }

            // player values update block
            if (objectTypeId == ObjectTypes.TYPEID_PLAYER)
            {
                if (reallength > 1440) // 32*45 (for player bitmask = 45)
                {
                    long pos = gr.BaseStream.Position;
                    swe.WriteLine("error position " + pos.ToString("X2"));

                    swe.WriteLine("error while parsing PLAYER values update block, count " + reallength);
                    return false;
                }

                for (uint index = 0; index < reallength; index++)
//.........这里部分代码省略.........
开发者ID:arkanoid1,项目名称:mywowtools,代码行数:101,代码来源:a9_parser.cs


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