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


C# System.IO.BinaryReader.ReadUInt16方法代码示例

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


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

示例1: BytesToString

 public string BytesToString(byte[] buff)
 {
     string pack = null;
     System.IO.MemoryStream ms = new System.IO.MemoryStream(buff);
     System.IO.BinaryReader br = new System.IO.BinaryReader(ms);
     ushort datasize = br.ReadUInt16();
     ushort opcode = br.ReadUInt16();
     br.ReadUInt16();
     pack = String.Format("{0}->{1}", opcode.ToString("X2"), Decode.StringToPack(br.ReadBytes(datasize)));
     return pack;
 }
开发者ID:CarlosX,项目名称:DarkEmu,代码行数:11,代码来源:Framework.Networking.cs

示例2: ExtractSPR

        static void ExtractSPR(string filename)
        {
            using (System.IO.BinaryReader reader = new System.IO.BinaryReader(System.IO.File.OpenRead("TIBIA.SPR"))) {
                ushort count = reader.ReadUInt16();
                reader.BaseStream.Seek(6, System.IO.SeekOrigin.Current);

                for (int a = 1; a < count; a++) {
                    Bitmap bmp = new Bitmap(32, 32, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
                    bmp.Palette = colorPalette;
                    System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, 32, 32), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
                    byte[] byteArray = new byte[1024];

                    for (int b = 0; b < 1024; b++) {
                        byteArray[b] = 0xFF;
                    }

                    long size = reader.ReadUInt16();
                    size += reader.BaseStream.Position - 1;
                    int i = 0;

                    while (reader.BaseStream.Position <= size) {
                        if (reader.BaseStream.Position >= reader.BaseStream.Length) {
                            break;
                        }

                        ushort tPixels = reader.ReadUInt16();
                        i += tPixels;

                        if (reader.BaseStream.Position > size) {
                            break;
                        }

                        byte cPixels = reader.ReadByte();

                        for (int c = 0; c < cPixels; c++) {
                            byte color = reader.ReadByte();
                            byteArray[i] = color;
                            i++;
                        }
                    }

                    System.Runtime.InteropServices.Marshal.Copy(byteArray, 0, bmpData.Scan0, 1024);
                    bmp.UnlockBits(bmpData);
                    bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);

                    if (!System.IO.Directory.Exists(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(filename), "Sprites\\"))) {
                        System.IO.Directory.CreateDirectory(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(filename), "Sprites\\"));
                    }

                    bmp.Save(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(filename), "Sprites\\" + a.ToString() + ".bmp"));
                    bmp.Dispose();
                }
            }
        }
开发者ID:brewsterl,项目名称:OldTibiaExtractor,代码行数:54,代码来源:Program.cs

示例3: Cursors_v2

        public Cursors_v2(string path)
        {
            System.IO.BinaryReader stream = new System.IO.BinaryReader(new System.IO.FileStream(path + "system\\icons.ph", System.IO.FileMode.Open, System.IO.FileAccess.Read));

            if (stream.ReadUInt32() != 0x6e6f6369 || stream.ReadUInt16() != 1)
                throw new Exception("Invalid icon file");

            _numCursors = stream.ReadUInt16();
            cursors = new V2_Cursor[_numCursors];

            for (int i = 0; i < _numCursors; i++)
            {
                readCursor(i, stream);
            }
        }
开发者ID:scott-t,项目名称:GJDBrowser,代码行数:15,代码来源:Cursors_v2.cs

示例4: GetDllMachineType

 public static MachineType GetDllMachineType(this string dllPath)
 {
     // See http://www.microsoft.com/whdc/system/platform/firmware/PECOFF.mspx
     // Offset to PE header is always at 0x3C.
     // The PE header starts with "PE\0\0" =  0x50 0x45 0x00 0x00,
     // followed by a 2-byte machine type field (see the document above for the enum).
     //
     using (var fs = new System.IO.FileStream(dllPath, System.IO.FileMode.Open, System.IO.FileAccess.Read))
         using (var br = new System.IO.BinaryReader(fs)) {
             MachineType machineType = MachineType.IMAGE_FILE_MACHINE_UNKNOWN;
     //					bool isgood = false;
             try {
                 fs.Seek(0x3c, System.IO.SeekOrigin.Begin);
                 Int32 peOffset = br.ReadInt32();
                 fs.Seek(peOffset, System.IO.SeekOrigin.Begin);
                 UInt32 peHead = br.ReadUInt32();
                 if (peHead != 0x00004550)
                     // "PE\0\0", little-endian
                     throw new Exception("Can't find PE header");
                 machineType = (MachineType)br.ReadUInt16();
     //						isgood = true;
             }
             catch {
     //						isgood = false;
             }
             finally {
                 br.Close();
                 fs.Close();
             }
             return machineType;
         }
 }
开发者ID:tfwio,项目名称:modest-smf-vstnet,代码行数:32,代码来源:DllExtension.cs

示例5: CheckWin32Header

 /// <summary>Checks whether a specified file is a valid Win32 plugin.</summary>
 /// <param name="file">The file to check.</param>
 /// <returns>Whether the file is a valid Win32 plugin.</returns>
 private static bool CheckWin32Header(string file)
 {
     using (System.IO.FileStream stream = new System.IO.FileStream(file, System.IO.FileMode.Open, System.IO.FileAccess.Read)) {
         using (System.IO.BinaryReader reader = new System.IO.BinaryReader(stream)) {
             if (reader.ReadUInt16() != 0x5A4D) {
                 /* Not MZ signature */
                 return false;
             }
             stream.Position = 0x3C;
             stream.Position = reader.ReadInt32();
             if (reader.ReadUInt32() != 0x00004550) {
                 /* Not PE signature */
                 return false;
             }
             if (reader.ReadUInt16() != 0x014C) {
                 /* Not IMAGE_FILE_MACHINE_I386 */
                 return false;
             }
         }
     }
     return true;
 }
开发者ID:sladen,项目名称:openbve,代码行数:25,代码来源:PluginManager.cs

示例6: TerrainData

        public TerrainData(System.IO.Stream stream, Vector3 worldSize, int size)
        {
            Size = size;
            WorldSize = worldSize;

            Data = new ushort[size * size];
            using (var reader = new System.IO.BinaryReader(stream))
            {
                var i = 0;
                while (reader.BaseStream.Position < reader.BaseStream.Length)
                    Data[i++] = reader.ReadUInt16();
            }
        }
开发者ID:johang88,项目名称:triton,代码行数:13,代码来源:TerrainData.cs

示例7: ExtractPIC

        static void ExtractPIC(string filename)
        {
            using (System.IO.BinaryReader reader = new System.IO.BinaryReader(System.IO.File.OpenRead(filename))) {
                ushort width = (ushort)(reader.ReadUInt16() + 2);
                ushort height = (ushort)(reader.ReadUInt16() + 2);
                Bitmap bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
                bmp.Palette = colorPalette;
                System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, width, height), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
                byte[] byteArray = new byte[width * height];

                for (int x = 1; x < (height - 1); x++) {
                    for (int y = 1; y < (width - 1); y++) {
                        byteArray[(width * x) + y] = reader.ReadByte();
                    }
                }

                System.Runtime.InteropServices.Marshal.Copy(byteArray, 0, bmpData.Scan0, width * height);
                bmp.UnlockBits(bmpData);
                bmp.Save(filename.Substring(0, filename.IndexOf(".")) + ".bmp");
                bmp.Dispose();
            }
        }
开发者ID:brewsterl,项目名称:OldTibiaExtractor,代码行数:22,代码来源:Program.cs

示例8: GameInitialize

        protected override void GameInitialize()
        {
            app.IsFixedTimeStep = true;
            app.TargetElapsedTime = TimeSpan.FromMilliseconds(10);

            byte[] tmp = ResourceManager.ReadAllBytes("timeless_table.bin");
            var ms = new System.IO.MemoryStream(tmp);
            var br = new System.IO.BinaryReader(ms);
            SuperSecretTable = new ushort[tmp.Length / 2];
            for(int i=0;i<SuperSecretTable.Length;i++)
                SuperSecretTable[i] = br.ReadUInt16();

            SuperSecretBuffer = NewImage(320, 200);

            SetResolution(320, 200);
            StaticInitializers();
            Autoexec();
        }
开发者ID:zeromus,项目名称:carotengine,代码行数:18,代码来源:timeless.cs

示例9: GenerateString

            public string GenerateString(int len)
            {
                if (len > 4000) len = 4000;
                var buffer = new byte[len * 2];
                new System.Security.Cryptography.RNGCryptoServiceProvider().GetBytes(buffer);

                using (var stream = new System.IO.MemoryStream(buffer, 0, buffer.Length, false, false))
                using (var reader = new System.IO.BinaryReader(stream))
                {
                    var builder = new System.Text.StringBuilder(buffer.Length, buffer.Length);
                    while (len-- > 0)
                    {
                        var i = (reader.ReadUInt16() & 8) % PWD_CHARSET.Length;
                        builder.Append(PWD_CHARSET[i]);
                    }
                    return builder.ToString();
                }
            }
开发者ID:acinmavi,项目名称:english-practice-helper,代码行数:18,代码来源:DataAccessTestBase.cs

示例10: readGameData

        private void readGameData()
        {
            textBox2.Text = path;
            if (roq != null)
                roq.stop();
            roq = null;
            if (vdx != null)
                vdx.stop();
            vdx = null;
            switch (game)
            {
                case GameID.T7G:
                    lblGame.Text = "The 7th Guest";

                    System.IO.DirectoryInfo DI = new System.IO.DirectoryInfo(path);
                    System.IO.FileInfo[] files = DI.GetFiles("*.rl");
                    this.gjdChooser.Items.Clear();

                    foreach (System.IO.FileInfo rl in files)
                    {
                        this.gjdChooser.Items.Add(rl.Name);
                    }

                    break;
                case GameID.T11H:
                    lblGame.Text = "The 11th Hour";
                    //ROQ roq = new ROQ(new System.IO.BinaryReader(new System.IO.FileStream(path + "\\media\\final_hr.rol", System.IO.FileMode.Open)));

                    this.gjdChooser.Items.Clear();
                    System.IO.BinaryReader idx = new System.IO.BinaryReader(new System.IO.FileStream(path + "\\groovie\\gjd.gjd", System.IO.FileMode.Open));
                    string name = "";
                    while (idx.BaseStream.Position < idx.BaseStream.Length)
                    {
                        if (idx.PeekChar() == 0x0A)
                        {
                            idx.ReadChar();
                            if (name.Length > 0)
                                this.gjdChooser.Items.Add(name.Substring(0, name.IndexOf(" ")));

                            name = "";
                        }
                        else
                            name += "" + idx.ReadChar();
                    }
                    idx.Close();
                    V2_RL = new List<GJD.RLData>[this.gjdChooser.Items.Count];
                    for (int i = 0; i < V2_RL.Length; i++)
                        V2_RL[i] = new List<GJD.RLData>();

                    this.gjdChooser.Items.Add("Icons");

                    idx = new System.IO.BinaryReader(new System.IO.FileStream(path + "\\groovie\\dir.rl", System.IO.FileMode.Open));
                    uint ctr = 0;
                    while (idx.BaseStream.Position < idx.BaseStream.Length)
                    {
                        // Get RL content
                        GJD.RLData rl = new GJD.RLData();
                        idx.ReadUInt32();
                        rl.offset = idx.ReadUInt32();
                        rl.length = idx.ReadUInt32();
                        rl.number = ctr;
                        ctr++;
                        ushort target = idx.ReadUInt16();
                        byte[] filename;
                        filename = idx.ReadBytes(12);
                        rl.filename = System.Text.Encoding.ASCII.GetString(filename).Trim();
                        idx.ReadBytes(6);
                        V2_RL[target].Add(rl);
                    }

                    break;
                default:
                    lblGame.Text = "None";
                    break;
            }
        }
开发者ID:scott-t,项目名称:GJDBrowser,代码行数:76,代码来源:frmMain.cs

示例11: Populate

 public void Populate(int iOffset, bool useMemoryStream)
 {
     this.isNulledOutReflexive = false;
     System.IO.BinaryReader BR = new System.IO.BinaryReader(meta.MS);
     //set offsets
     BR.BaseStream.Position = iOffset + this.chunkOffset;
     this.offsetInMap = iOffset + this.chunkOffset;
     // If we need to read / save tag info directly to file...
     if (!useMemoryStream)
     {
         map.OpenMap(MapTypes.Internal);
         BR = map.BR;
         BR.BaseStream.Position = this.offsetInMap;
     }
     else
         this.offsetInMap += meta.offset;
     switch (ValueType)
     {
         case IFPIO.ObjectEnum.Short:
             {
                 this.Value = BR.ReadInt16();
                 break;
             }
         case IFPIO.ObjectEnum.Int:
             {
                 this.Value = BR.ReadInt32();
                 break;
             }
         case IFPIO.ObjectEnum.UShort:
             {
                 this.Value = BR.ReadUInt16();
                 break;
             }
         case IFPIO.ObjectEnum.UInt:
             {
                 this.Value = BR.ReadUInt32();
                 break;
             }
         case IFPIO.ObjectEnum.Float:
             {
                 this.Value = BR.ReadSingle();
                 break;
             }
         case IFPIO.ObjectEnum.Unknown:
             {
                 this.Value = BR.ReadSingle();
                 break;
             }
         case IFPIO.ObjectEnum.Byte:
             {
                 this.Value = BR.ReadByte();
                 break;
             }
     }
     // ...and then close the file once we are done!
     if (!useMemoryStream)
         map.CloseMap();
     if (this.ValueType != IFPIO.ObjectEnum.Unused)
         this.Controls[1].Text = this.Value.ToString();
 }
开发者ID:nolenfelten,项目名称:Blam_BSP,代码行数:60,代码来源:DataValues.cs

示例12: LoadProgram

        private void LoadProgram()
        {
            var fileStream = new System.IO.FileStream(programFileName, System.IO.FileMode.Open);
            var binaryReader = new System.IO.BinaryReader(fileStream);

            var magicWordBytes = binaryReader.ReadBytes(8);
            var magicWord = System.Text.Encoding.Default.GetString(magicWordBytes);

            if (magicWord != "ZHANGSHU")
            {
                System.Windows.Forms.MessageBox.Show("It is NOT a VM binary file!", "Error!", MessageBoxButtons.OK);
                return;
            }

            var offset = binaryReader.ReadUInt16();
            var length = binaryReader.ReadUInt16();

            var position = binaryReader.ReadUInt16();          //where the program starts in memory

            ushort i = 0;
            while (binaryReader.BaseStream.Position < binaryReader.BaseStream.Length)
            {
                memory[(UInt16)(position + i)] = binaryReader.ReadByte();
                ++i;
            }

            binaryReader.Close();
            fileStream.Close();

            programPosition = (UInt16)(position + offset - 14);
        }
开发者ID:Locked-Cat,项目名称:VM,代码行数:31,代码来源:VM_Machine.xaml.cs

示例13: Populate

        public void Populate(int iOffset, bool useMemoryStream)
        {
            this.isNulledOutReflexive = false;
            System.IO.BinaryReader BR = new System.IO.BinaryReader(meta.MS);
            //set offsets
            BR.BaseStream.Position = iOffset + this.chunkOffset;
            this.offsetInMap = iOffset + this.chunkOffset;
            // If we need to read / save tag info directly to file...
            if (!useMemoryStream)
            {
                map.OpenMap(MapTypes.Internal);
                BR = map.BR;
                BR.BaseStream.Position = this.offsetInMap;
            }
            else
                this.offsetInMap += meta.offset;

            //Decide how big the bitmask is
            switch (this.bitCount)
            {
                case 8:
                    {
                        this.value = BR.ReadByte();
                        break;
                    }
                case 16:
                    {
                        this.value = BR.ReadUInt16();
                        break;
                    }
                case 32:
                    {
                        this.value = BR.ReadUInt32();
                        break;
                    }
            }
            // ...and then close the file once we are done!
            if (!useMemoryStream)
                map.CloseMap();
            //convert this.value (an object) into a bool array, then update the checkboxes with that bool array
            BitsToBool();
            BoolsToControls();
        }
开发者ID:troymac1ure,项目名称:Entity,代码行数:43,代码来源:Bitmask.cs

示例14: openToolStripMenuItem_Click

        private void openToolStripMenuItem_Click(object sender, System.EventArgs e)
        {
            byte Magic1;
            byte Magic2;
            byte Magic3;

            DialogResult dr;
            dr = openFileDialog1.ShowDialog();
            if (dr == DialogResult.Cancel) return;
            lock (reallySimpleScreen1)
            {
                reallySimpleScreen1.Reset();
            }

            System.IO.BinaryReader br;
            System.IO.FileStream fs = new
               System.IO.FileStream(openFileDialog1.FileName, System.IO.FileMode.Open);
            br = new System.IO.BinaryReader(fs);
            Magic1 = br.ReadByte();
            Magic2 = br.ReadByte();
            Magic3 = br.ReadByte();
            if (Magic1 != 'B' && Magic2 != '3' && Magic3 != '2')
            {
                MessageBox.Show("This is not a valid B32 file!", "Error!",
               MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            StartAddr = br.ReadUInt16();
            ExecAddr = br.ReadUInt16();
            ushort Counter = 0;
            while ((br.PeekChar() != -1))
            {
                ReallySimpleMemory[(StartAddr + Counter)] = br.ReadByte();
                Counter++;
            }
            br.Close();
            fs.Close();
            InstructionPointer = ExecAddr;
            //ExecuteProgram(ExecAddr, Counter);
            programThread = new Thread(delegate () { ExecuteProgram(ExecAddr, Counter); });
            PauseEvent = new ManualResetEvent(true);
            programThread.Start();
        }
开发者ID:cohen990,项目名称:ReallySimpleVM,代码行数:43,代码来源:MainForm.cs

示例15: Populate

        public void Populate(int iOffset, int iIndexedReflexiveOffset)
        {
            this.isNulledOutReflexive = false;
            System.IO.BinaryReader BR = new System.IO.BinaryReader(meta.MS);

            int mapMetaOffset = meta.offset;

            if (this._EntIndex.reflexiveTagType + this._EntIndex.reflexiveTagName != string.Empty)
            {
                int tagNum = map.Functions.ForMeta.FindByNameAndTagType(this._EntIndex.reflexiveTagType, this._EntIndex.reflexiveTagName);
                if (tagNum != -1)
                {
                    Meta meta2 = new Meta(map);
                    map.OpenMap(MapTypes.Internal);
                    meta2.ReadMetaFromMap(tagNum, true);
                    map.CloseMap();
                    mapMetaOffset = meta2.offset;
                    this._EntIndex.reflexiveLayer = "root";
                }
            }

            if (this._EntIndex.reflexiveLayer.ToLower() == "root")
                this._IndexedReflexiveOffset = mapMetaOffset + this._EntIndex.ReflexiveOffset;
            else if (this._EntIndex.reflexiveLayer.ToLower() == "oneup")
                this._IndexedReflexiveOffset = iIndexedReflexiveOffset + this._EntIndex.ReflexiveOffset;

            /*
            bool openedMap = false;
            if (map.isOpen == false)
            {
                map.OpenMap(MapTypes.Internal);
                openedMap = true;
            }
            map.BA.Position = iOffset + this.chunkOffset;
            */
            BR.BaseStream.Position = iOffset + this.chunkOffset;
            this.offsetInMap = meta.offset + iOffset + this.chunkOffset;

            switch (_ValueType)
            {
                case IFPIO.ObjectEnum.Short:
                    {
                        this.Value = (int)BR.ReadInt16();
                        break;
                    }
                case IFPIO.ObjectEnum.Int:
                    {
                        this.Value = BR.ReadInt32();
                        break;
                    }
                case IFPIO.ObjectEnum.UShort:
                    {
                        this.Value = (int)BR.ReadUInt16();
                        break;
                    }
                case IFPIO.ObjectEnum.UInt:
                    {
                        this.Value = (int)BR.ReadUInt32();
                        break;
                    }
                case IFPIO.ObjectEnum.Byte:
                    {
                        this.Value = (int)BR.ReadByte();
                        break;
                    }
            }
            UpdateSelectionList(false);
            /*
            if (openedMap == true)
                map.CloseMap();
            */
        }
开发者ID:troymac1ure,项目名称:Entity,代码行数:72,代码来源:Indices.cs


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