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


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

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


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

示例1: Form1

        public Form1()
        {
            InitializeComponent();

            using ( System.IO.FileStream S = new System.IO.FileInfo( "../TestAreaLight/BRDF0_64x64.table" ).OpenRead() )
                using ( System.IO.BinaryReader R = new System.IO.BinaryReader( S ) )
                    for ( int i=0; i < 64; i++ ) {
                        m_IntegralSpecularReflection[i,0] = R.ReadSingle();
                        m_IntegralSpecularReflection[i,1] = R.ReadSingle();
                    }
            outputPanelDiffuseFresnelReflectance.m_Table = m_IntegralSpecularReflection;
        }
开发者ID:Patapom,项目名称:GodComplex,代码行数:12,代码来源:Form1.cs

示例2: ReadMemorySingle

 public static Single ReadMemorySingle(IntPtr handle, IntPtr addr)
 {
     byte[] Buffer = new Byte[4];
     Single i = 0;
     Buffer = ReadProcessMemory(handle, (int)addr, 4);
     try
     {
         System.IO.MemoryStream ms = new System.IO.MemoryStream(Buffer);
         System.IO.BinaryReader br = new System.IO.BinaryReader(ms);
         i = br.ReadSingle();
     }
     finally
     {
     }
     return i;
 }
开发者ID:masahoshiro,项目名称:FinalFantasyXIV_ARR_Tools,代码行数:16,代码来源:MemoryProvidor.cs

示例3: ToArrays

    /// <summary>
    /// Imports a Galactic SPC file into a x and an y array. The file must not be a multi spectrum file (an exception is thrown in this case).
    /// </summary>
    /// <param name="xvalues">The x values of the spectrum.</param>
    /// <param name="yvalues">The y values of the spectrum.</param>
    /// <param name="filename">The filename where to import from.</param>
    /// <returns>Null if successful, otherwise an error description.</returns>
    public static string ToArrays(string filename, out double [] xvalues, out double [] yvalues)
    {
      System.IO.Stream stream=null;

      SPCHDR hdr = new SPCHDR();
      SUBHDR subhdr = new SUBHDR();

      try
      {
        stream = new System.IO.FileStream(filename,System.IO.FileMode.Open,System.IO.FileAccess.Read,System.IO.FileShare.Read);
        System.IO.BinaryReader binreader = new System.IO.BinaryReader(stream);


        hdr.ftflgs = binreader.ReadByte(); // ftflgs : not-evenly spaced data
        hdr.fversn = binreader.ReadByte(); // fversn : new version
        hdr.fexper = binreader.ReadByte(); // fexper : general experimental technique
        hdr.fexp   = binreader.ReadByte(); // fexp   : fractional scaling exponent (0x80 for floating point)

        hdr.fnpts  = binreader.ReadInt32(); // fnpts  : number of points

        hdr.ffirst = binreader.ReadDouble(); // ffirst : first x-value
        hdr.flast  = binreader.ReadDouble(); // flast : last x-value
        hdr.fnsub  = binreader.ReadInt32(); // fnsub : 1 (one) subfile only
      
        binreader.ReadByte(); //  Type of X axis units (see definitions below) 
        binreader.ReadByte(); //  Type of Y axis units (see definitions below) 
        binreader.ReadByte(); // Type of Z axis units (see definitions below)
        binreader.ReadByte(); // Posting disposition (see GRAMSDDE.H)

        binreader.Read(new byte[0x1E0],0,0x1E0); // rest of SPC header


        // ---------------------------------------------------------------------
        //   following the x-values array
        // ---------------------------------------------------------------------

        if(hdr.fversn!=0x4B)
        {
          if(hdr.fversn==0x4D)
            throw new System.FormatException(string.Format("This SPC file has the old format version of {0}, the only version supported here is the new version {1}",hdr.fversn,0x4B));
          else
            throw new System.FormatException(string.Format("This SPC file has a version of {0}, the only version recognized here is {1}",hdr.fversn,0x4B));
        }

        if(0!=(hdr.ftflgs & 0x80))
        {
          xvalues = new double[hdr.fnpts];
          for(int i=0;i<hdr.fnpts;i++)
            xvalues[i] = binreader.ReadSingle();
        }
        else if(0==hdr.ftflgs) // evenly spaced data
        {
          xvalues = new double[hdr.fnpts];
          for(int i=0;i<hdr.fnpts;i++)
            xvalues[i] = hdr.ffirst + i*(hdr.flast-hdr.ffirst)/(hdr.fnpts-1);
        }
        else
        {
          throw new System.FormatException("The SPC file must not be a multifile; only single file format is accepted!");
        }



        // ---------------------------------------------------------------------
        //   following the y SUBHEADER
        // ---------------------------------------------------------------------

        subhdr.subflgs = binreader.ReadByte(); // subflgs : always 0
        subhdr.subexp  = binreader.ReadByte(); // subexp : y-values scaling exponent (set to 0x80 means floating point representation)
        subhdr.subindx = binreader.ReadInt16(); // subindx :  Integer index number of trace subfile (0=first)

        subhdr.subtime = binreader.ReadSingle(); // subtime;   Floating time for trace (Z axis corrdinate) 
        subhdr.subnext = binreader.ReadSingle(); // subnext;   Floating time for next trace (May be same as beg) 
        subhdr.subnois = binreader.ReadSingle(); // subnois;   Floating peak pick noise level if high byte nonzero 

        subhdr.subnpts = binreader.ReadInt32(); // subnpts;  Integer number of subfile points for TXYXYS type 
        subhdr.subscan = binreader.ReadInt32(); // subscan; Integer number of co-added scans or 0 (for collect) 
        subhdr.subwlevel = binreader.ReadSingle();        // subwlevel;  Floating W axis value (if fwplanes non-zero) 
        subhdr.subresv   = binreader.ReadInt32(); // subresv[4];   Reserved area (must be set to zero) 


        // ---------------------------------------------------------------------
        //   following the y-values array
        // ---------------------------------------------------------------------
        yvalues = new double[hdr.fnpts];
        
        if(hdr.fexp==0x80) //floating point format
        {
          for(int i=0;i<hdr.fnpts;i++)
            yvalues[i] = binreader.ReadSingle();
        }
        else // fixed exponent format
        {
//.........这里部分代码省略.........
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:101,代码来源:ImportGalacticSpcFiles.cs

示例4: BuildPhaseQuantileBuffer

		private void	BuildPhaseQuantileBuffer( System.IO.FileInfo _PhaseQuantileFileName )
		{
			const int	QUANTILES_COUNT = 65536;

			Reg( m_SB_PhaseQuantile = new StructuredBuffer<float>( m_Device, 2*QUANTILES_COUNT, true ) );
			using ( System.IO.FileStream S = _PhaseQuantileFileName.OpenRead() )
				using ( System.IO.BinaryReader R = new System.IO.BinaryReader( S ) )
				{
					for ( int i=0; i < m_SB_PhaseQuantile.m.Length; i++ )
						m_SB_PhaseQuantile.m[i] = R.ReadSingle();
				}
			m_SB_PhaseQuantile.Write();
		}
开发者ID:Patapom,项目名称:GodComplex,代码行数:13,代码来源:Form1.cs

示例5: ScanNumber

    private static TclObject ScanNumber( byte[] src, int pos, int type )
    // Format character from "binary scan"
    {
      switch ( type )
      {

        case 'c':
          {
            return TclInteger.newInstance( (sbyte)src[pos] );
          }

        case 's':
          {
            short value = (short)( ( src[pos] & 0xff ) + ( ( src[pos + 1] & 0xff ) << 8 ) );
            return TclInteger.newInstance( (int)value );
          }

        case 'S':
          {
            short value = (short)( ( src[pos + 1] & 0xff ) + ( ( src[pos] & 0xff ) << 8 ) );
            return TclInteger.newInstance( (int)value );
          }

        case 'i':
          {
            int value = ( src[pos] & 0xff ) + ( ( src[pos + 1] & 0xff ) << 8 ) + ( ( src[pos + 2] & 0xff ) << 16 ) + ( ( src[pos + 3] & 0xff ) << 24 );
            return TclInteger.newInstance( value );
          }
        case 'I':
          {
            int value = ( src[pos + 3] & 0xff ) + ( ( src[pos + 2] & 0xff ) << 8 ) + ( ( src[pos + 1] & 0xff ) << 16 ) + ( ( src[pos] & 0xff ) << 24 );
            return TclInteger.newInstance( value );
          }
        case 'f':
          {
            System.IO.MemoryStream ms = new System.IO.MemoryStream( src, pos, 4, false );
            System.IO.BinaryReader reader = new System.IO.BinaryReader( ms );
            double fvalue = reader.ReadSingle();
            reader.Close();
            ms.Close();
            return TclDouble.newInstance( fvalue );
          }
        case 'd':
          {
            System.IO.MemoryStream ms = new System.IO.MemoryStream( src, pos, 8, false );
            System.IO.BinaryReader reader = new System.IO.BinaryReader( ms );
            double dvalue = reader.ReadDouble();
            reader.Close();
            ms.Close();
            return TclDouble.newInstance( dvalue );
          }
      }
      return null;
    }
开发者ID:Belxjander,项目名称:Asuna,代码行数:54,代码来源:BinaryCmd.cs

示例6: loadFromFileF32

        /// <summary>
        /// Loads a file consisting of 256x256 floats and imports it as an array into the map.
        /// </summary>
        /// <remarks>TODO: Move this to libTerrain itself</remarks>
        /// <param name="filename">The filename of the float array to import</param>
        public void loadFromFileF32(string filename)
        {
            System.IO.FileInfo file = new System.IO.FileInfo(filename);
            System.IO.FileStream s = file.Open(System.IO.FileMode.Open, System.IO.FileAccess.Read);
            System.IO.BinaryReader bs = new System.IO.BinaryReader(s);
            int x, y;
            for (x = 0; x < w; x++)
            {
                for (y = 0; y < h; y++)
                {
                    heightmap.map[x, y] = (double)bs.ReadSingle();
                }
            }

            bs.Close();
            s.Close();

            tainted++;
        }
开发者ID:BackupTheBerlios,项目名称:ulife-svn,代码行数:24,代码来源:TerrainEngine.cs

示例7: Load

        // Per spot:
        // uint32 magic
        // uint32 reserved;
        // uint32 flags;
        // float x;
        // float y;
        // float z;
        // uint32 no_paths
        //   for each path
        //     float x;
        //     float y;
        //     float z;
        public bool Load(string baseDir)
        {
            string fileName = FileName();
            string filenamebin = baseDir + fileName;

            System.IO.Stream stream = null;
            System.IO.BinaryReader file = null;
            int n_spots = 0;
            int n_steps = 0;
            try
            {
                stream = System.IO.File.OpenRead(filenamebin);
                if (stream != null)
                {
                    file = new System.IO.BinaryReader(stream);
                    if (file != null)
                    {
                        uint magic = file.ReadUInt32();
                        if (magic == FILE_MAGIC)
                        {

                            uint type;
                            while ((type = file.ReadUInt32()) != FILE_ENDMAGIC)
                            {
                                n_spots++;
                                uint reserved = file.ReadUInt32();
                                uint flags = file.ReadUInt32();
                                float x = file.ReadSingle();
                                float y = file.ReadSingle();
                                float z = file.ReadSingle();
                                uint n_paths = file.ReadUInt32();
                                if (x != 0 && y != 0)
                                {
                                    Spot s = new Spot(x, y, z);
                                    s.flags = flags;

                                    for (uint i = 0; i < n_paths; i++)
                                    {
                                        n_steps++;
                                        float sx = file.ReadSingle();
                                        float sy = file.ReadSingle();
                                        float sz = file.ReadSingle();
                                        s.AddPathTo(sx, sy, sz);
                                    }
                                    AddSpot(s);
                                }
                            }
                        }
                    }
                }
            }
            catch (System.IO.FileNotFoundException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (System.IO.DirectoryNotFoundException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            if (file != null)
            {
                file.Close();
            }
            if (stream != null)
            {
                stream.Close();
            }

            Log("Loaded " + fileName + " " + n_spots + " spots " + n_steps + " steps");

            modified = false;
            return false;
        }
开发者ID:iwaitu,项目名称:babbot,代码行数:90,代码来源:GraphChunk.cs

示例8: PipoImage2Texture

		public Texture2D	PipoImage2Texture( System.IO.FileInfo _FileName ) {
			using ( System.IO.FileStream S = _FileName.OpenRead() )
				using ( System.IO.BinaryReader R = new System.IO.BinaryReader( S ) ) {

					int	W, H;
					W = R.ReadInt32();
					H = R.ReadInt32();

					PixelsBuffer	Buff = new PixelsBuffer( (uint) (4 * W * H * 4) );
					using ( System.IO.BinaryWriter Wr = Buff.OpenStreamWrite() )
					{
						float4	C = new float4();
						for ( int Y=0; Y < H; Y++ ) {
							for ( int X=0; X < W; X++ ) {
								C.x = R.ReadSingle();
								C.y = R.ReadSingle();
								C.z = R.ReadSingle();
								C.w = R.ReadSingle();

								Wr.Write( C.x );
								Wr.Write( C.y );
								Wr.Write( C.z );
								Wr.Write( C.w );
							}
						}
					}

					return Image2Texture( (uint) W, (uint) H, PIXEL_FORMAT.RGBA32_FLOAT, Buff );
				}
		}
开发者ID:Patapom,项目名称:GodComplex,代码行数:30,代码来源:AreaLightForm.cs

示例9: LoadVoxelModel

        public VoxelModel LoadVoxelModel(System.IO.Stream stream, out Vector3 pivot, IProgressListener progress)
        {
            var reader = new System.IO.BinaryReader(stream);

            {
                var buf = new byte[4];
                if (stream.Read(buf, 0, 4) < 4)
                {
                    throw new System.IO.IOException("Magic not read");
                }
                if (buf[0] != 'K' ||
                   buf[1] != 'v' ||
                   buf[2] != 'x' ||
                   buf[3] != 'l')
                {
                    throw new System.IO.IOException("Invalid magic");
                }
            }

            int xsiz = reader.ReadInt32();
            int ysiz = reader.ReadInt32();
            int zsiz = reader.ReadInt32();
            float xpivot = reader.ReadSingle();
            float ypivot = reader.ReadSingle();
            float zpivot = reader.ReadSingle();
            int numblocks = reader.ReadInt32();
            var blocks = new Kv6Block[numblocks];

            progress?.Report("Reading voxels");

            for (int i = 0; i < blocks.Length; ++i)
            {
                blocks[i].color = reader.ReadUInt32();
                blocks[i].zpos = (int) reader.ReadUInt16();
                reader.ReadUInt16(); // skip visFaces & lighting
                if (((i & 8191) == 0))
                {
                    progress?.Report((double)i / blocks.Length * 0.5);
                }
            }

            var xyoffset = new int[xsiz * ysiz];

            // skip xoffset
            for (int i = 0; i < xsiz; ++i)
            {
                reader.ReadInt32();
            }
            for (int i = 0; i < xyoffset.Length; ++i)
            {
                xyoffset[i] = (int) reader.ReadUInt16();
            }

            progress?.Report("Placing voxels");

            int pos = 0;
            var model = new VoxelModel(xsiz, ysiz, zsiz);
            for (int x = 0; x < xsiz; ++x) {
                for (int y = 0; y < ysiz; ++y) {
                    int sb = xyoffset[x * ysiz + y];
                    for (int i = 0; i < sb; ++i) {
                        var b = blocks[pos];
                        model[x, y, b.zpos] = b.color;
                        pos += 1;
                    }
                }

                progress?.Report((double)pos / blocks.Length * 0.5 + 0.5);
            }

            pivot = new Vector3(xpivot, ypivot, zpivot);

            return model;
        }
开发者ID:yvt,项目名称:VxlToObj,代码行数:74,代码来源:Kv6VoxelModelLoader.cs

示例10: Pipi2Texture

		public Texture2D	Pipi2Texture( System.IO.FileInfo _FileName ) {
			using ( System.IO.FileStream S = _FileName.OpenRead() )
				using ( System.IO.BinaryReader R = new System.IO.BinaryReader( S ) ) {

					int				MipLevels = R.ReadInt32();
					PixelsBuffer[]	Mips = new PixelsBuffer[MipLevels];
					int				ImageWidth = 0, ImageHeight = 0;
					for ( int MipLevel=0; MipLevel < MipLevels; MipLevel++ ) {
						int	W, H;
						W = R.ReadInt32();
						H = R.ReadInt32();
						if ( MipLevel == 0 ) {
							ImageWidth = W;
							ImageHeight = H;
						}

						PixelsBuffer	Buff = new PixelsBuffer( (uint) (4 * W * H * 4) );
						Mips[MipLevel] = Buff;
						using ( System.IO.BinaryWriter Wr = Buff.OpenStreamWrite() )
						{
							float4	C = new float4();
							for ( int Y=0; Y < H; Y++ ) {
								for ( int X=0; X < W; X++ ) {
									C.x = R.ReadSingle();
									C.y = R.ReadSingle();
									C.z = R.ReadSingle();
									C.w = R.ReadSingle();

									Wr.Write( C.x );
									Wr.Write( C.y );
									Wr.Write( C.z );
									Wr.Write( C.w );
								}
							}
						}
					}

					return Image2Texture( (uint) ImageWidth, (uint) ImageHeight, PIXEL_FORMAT.RGBA32_FLOAT, Mips );
				}
		}
开发者ID:Patapom,项目名称:GodComplex,代码行数:40,代码来源:AreaLightForm.cs

示例11: Pipu2Texture

		public Texture3D	Pipu2Texture( System.IO.FileInfo _FileName ) {
			using ( System.IO.FileStream S = _FileName.OpenRead() )
				using ( System.IO.BinaryReader R = new System.IO.BinaryReader( S ) ) {

					int		SlicesCount = R.ReadInt32();
					int		W = R.ReadInt32();
					int		H = R.ReadInt32();

					PixelsBuffer	Slices = new PixelsBuffer( (uint) (4 * W * H * SlicesCount * 4) );
					using ( System.IO.BinaryWriter Wr = Slices.OpenStreamWrite() ) {
						for ( int SliceIndex=0; SliceIndex < SlicesCount; SliceIndex++ ) {
							float4	C = new float4();
							for ( int Y=0; Y < H; Y++ ) {
								for ( int X=0; X < W; X++ ) {
									C.x = R.ReadSingle();
									C.y = R.ReadSingle();
									C.z = R.ReadSingle();
									C.w = R.ReadSingle();

									Wr.Write( C.x );
									Wr.Write( C.y );
									Wr.Write( C.z );
									Wr.Write( C.w );
								}
							}
						}
					}

					return Image2Texture3D( (uint) W, (uint) H, (uint) SlicesCount, PIXEL_FORMAT.RGBA32_FLOAT, new PixelsBuffer[] { Slices } );
				}
		}
开发者ID:Patapom,项目名称:GodComplex,代码行数:31,代码来源:AreaLightForm.cs

示例12: ReverseBits


//.........这里部分代码省略.........

            float const vx = sqrtf( 1.0f - ndotv * ndotv );
            float const vy = 0.0f;
            float const vz = ndotv;

            float scale = 0.0f;
            float bias  = 0.0f;

            
            for ( unsigned i = 0; i < sampleNum; ++i )
            {
                float const e1 = (float) i / sampleNum;
                float const e2 = (float) ( (double) ReverseBits( i ) / (double) 0x100000000LL );

                float const phi         = 2.0f * MATH_PI * e1;
                float const cosPhi      = cosf( phi );
                float const sinPhi      = sinf( phi );
                float const cosTheta    = sqrtf( ( 1.0f - e2 ) / ( 1.0f + ( roughness * roughness - 1.0f ) * e2 ) );
                float const sinTheta    = sqrtf( 1.0f - cosTheta * cosTheta );

                float const hx  = sinTheta * cosf( phi );
                float const hy  = sinTheta * sinf( phi );
                float const hz  = cosTheta;

                float const vdh = vx * hx + vy * hy + vz * hz;
                float const lx  = 2.0f * vdh * hx - vx;
                float const ly  = 2.0f * vdh * hy - vy;
                float const lz  = 2.0f * vdh * hz - vz;

                float const ndotl = std::max( lz,   0.0f );
                float const ndoth = std::max( hz,   0.0f );
                float const vdoth = std::max( vdh,  0.0f );

                if ( ndotl > 0.0f )
                {
                    float const gsmith      = GSmith( roughness, ndotv, ndotl );
                    float const ndotlVisPDF = ndotl * gsmith * ( 4.0f * vdoth / ndoth );
                    float const fc          = powf( 1.0f - vdoth, 5.0f );

                    scale   += ndotlVisPDF * ( 1.0f - fc );
                    bias    += ndotlVisPDF * fc;
                }
            }
            scale /= sampleNum;
            bias  /= sampleNum;

            lutData[ x * 4 + y * LUT_WIDTH * 4 + 0 ] = scale;
            lutData[ x * 4 + y * LUT_WIDTH * 4 + 1 ] = bias;
            lutData[ x * 4 + y * LUT_WIDTH * 4 + 2 ] = 0.0f;
            lutData[ x * 4 + y * LUT_WIDTH * 4 + 3 ] = 0.0f;
        }
    }   

} */

#endif

		Texture2D	BuildBRDFTexture( System.IO.FileInfo _TableFileName, uint _TableSize ) {

			float2[,]	Table = new float2[_TableSize,_TableSize];

			float	MinA = 1, MaxA = 0;
			float	MinB = 1, MaxB = 0;
			using ( System.IO.FileStream S = _TableFileName.OpenRead() )
				using ( System.IO.BinaryReader R = new System.IO.BinaryReader( S ) )
					for ( int Y=0; Y < _TableSize; Y++ )
						for ( int X=0; X < _TableSize; X++ ) {
							float	A = R.ReadSingle();
							float	B = R.ReadSingle();
							Table[X,Y].x = A;
							Table[X,Y].y = B;
							MinA = Math.Min( MinA, A );
							MaxA = Math.Max( MaxA, A );
							MinB = Math.Min( MinB, B );
							MaxB = Math.Max( MaxB, B );
						}

			// MaxA = 1
			// MaxB = 0.00014996325546887346

// MaxA = 1.0;
// MaxB = 1.0;

			// Create the texture
//			PixelsBuffer	Content = new PixelsBuffer( _TableSize*_TableSize*4 );
			PixelsBuffer	Content = new PixelsBuffer( (uint) (_TableSize*_TableSize*2*4) );
			using ( System.IO.BinaryWriter W = Content.OpenStreamWrite() )
			for ( int Y=0; Y < _TableSize; Y++ )
				for ( int X=0; X < _TableSize; X++ ) {
// 					W.Write( (ushort) (65535.0 * Table[X,Y].x / MaxA) );
// 					W.Write( (ushort) (65535.0 * Table[X,Y].y / MaxB) );
					W.Write( Table[X,Y].x );
					W.Write( Table[X,Y].y );
				}


//			Texture2D	Result = new Texture2D( m_Device, _TableSize, _TableSize, 1, 1, PIXEL_FORMAT.RG16_UNORM, false, false, new PixelsBuffer[] { Content } );
			Texture2D	Result = new Texture2D( m_Device, _TableSize, _TableSize, 1, 1, PIXEL_FORMAT.RG32_FLOAT, false, false, new PixelsBuffer[] { Content } );
			return Result;
		}
开发者ID:Patapom,项目名称:GodComplex,代码行数:101,代码来源:AreaLightForm.cs

示例13: bEdit_Click

        private void bEdit_Click(object sender, EventArgs e)
        {
            if(dataGridView1.SelectedRows.Count!=1) return;
            int i=dataGridView1.SelectedRows[0].Index;
            switch(mode) {
            case Mode.Arrays: {
                    DataType[] types=new DataType[connection.ArrayLengths[i]];
                    string[] strings=new string[connection.ArrayLengths[i]];
                    connection.WriteDataType(DataTypeSend.GetArray);
                    connection.WriteInt(i);
                    for(int j=0;j<strings.Length;j++) types[j]=(DataType)connection.ReadInt();
                    byte[] buf=connection.ReadBytes(connection.ArrayLengths[i]*connection.ArrayDataSizes[i]);
                    MemoryStream ms=new MemoryStream(buf);
                    BinaryReader br=new BinaryReader(ms);
                    for(int j=0;j<strings.Length;j++) {
                        ms.Position=j*connection.ArrayDataSizes[i];
                        switch(types[j]) {
                        case DataType.Int:
                            strings[j]=br.ReadInt32().ToString();
                            break;
                        case DataType.Float:
                            strings[j]=br.ReadSingle().ToString();
                            break;
                        case DataType.String:
                            byte[] bytes=br.ReadBytes(connection.ArrayDataSizes[i]);
                            strings[j]=System.Text.Encoding.ASCII.GetString(bytes, 0, Array.IndexOf<byte>(bytes, 0));
                            break;
                        }
                    }
                    br.Close();
                    strings=EditorWindow.ShowEditor(null, types, strings);
                    if(strings!=null) {
                        connection.WriteDataType(DataTypeSend.SetArray);
                        connection.WriteInt(i);
                        ms=new MemoryStream(connection.ArrayLengths[i]*connection.ArrayDataSizes[i]);
                        BinaryWriter bw=new BinaryWriter(ms);
                        for(int j=0;j<strings.Length;j++) {
                            ms.Position=j*connection.ArrayDataSizes[i];
                            switch(types[j]) {
                            case DataType.Int:
                                bw.Write(int.Parse(strings[j]));
                                break;
                            case DataType.Float:
                                bw.Write(float.Parse(strings[j]));
                                break;
                            case DataType.String:
                                byte[] bytes=System.Text.Encoding.ASCII.GetBytes(strings[j]);
                                if(bytes.Length<connection.ArrayDataSizes[i]) bw.Write(bytes);
                                else bw.Write(bytes, 0, connection.ArrayDataSizes[i]-1);
                                bw.Write(0);
                                break;
                            }
                        }
                        connection.WriteBytes(ms.GetBuffer(), 0, connection.ArrayLengths[i]*connection.ArrayDataSizes[i]);
                        bw.Close();
                    }
                }
                break;
            case Mode.Critters: {
                    DataType[] types=new DataType[29];
                    string[] strings=new string[29];
                    string[] names=new string[29];
                    connection.WriteDataType(DataTypeSend.RetrieveCritter);
                    connection.WriteInt(i);
                    BinaryReader br=new BinaryReader(new System.IO.MemoryStream(connection.ReadBytes(29*4)));
                    for(int j=0;j<29;j++) {
                        types[j]=DataType.Int;
                        strings[j]=br.ReadInt32().ToString();
                        names[j]="0x"+(j*4).ToString("x");
                    }
                    br.Close();
                    names[1]="Tile";
                    names[10]="Elevation";
                    names[11]="Inventory count";
                    names[13]="Inventory pointer";
                    names[16]="Current AP";
                    names[17]="Crippled limbs";
                    names[22]="HP";
                    names[23]="Rads";
                    names[24]="Poison";
                    names[25]="Proto ID";
                    strings=EditorWindow.ShowEditor(names, types, strings);
                    if(strings!=null) {
                        MemoryStream ms=new MemoryStream(29*4);
                        BinaryWriter bw=new BinaryWriter(ms);
                        for(int j=0;j<29;j++) bw.Write(int.Parse(strings[j]));
                        connection.WriteDataType(DataTypeSend.SetCritter);
                        connection.WriteInt(i);
                        connection.WriteBytes(ms.GetBuffer(), 0, 29*4);
                        bw.Close();
                    }

                }
                break;
            }
        }
开发者ID:phobos2077,项目名称:sfall,代码行数:96,代码来源:DebugEditor.cs

示例14: 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

示例15: FromAIN

        public static Assembly FromAIN(string path)
        {
            Assembly asm = new Assembly();
            System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Open);
            System.IO.BinaryReader br = new System.IO.BinaryReader(fs);
            fs.Position = 8;
            uint size = br.ReadUInt32();
            uint compressedSize = br.ReadUInt32();
            byte[] buf;
            byte[] dst = new byte[size];
            buf = br.ReadBytes((int)compressedSize);
            fixed (byte* ptr = buf)
            {
                fixed (byte* ptr2 = dst)
                {
                    uncompress(ptr2, &size, ptr, compressedSize);
                }
            }
            fs.Close();

            System.IO.MemoryStream ms = new System.IO.MemoryStream(dst);
            br = new System.IO.BinaryReader(ms);
            while (ms.Position < ms.Length)
            {
                string trunk = Encoding.ASCII.GetString(br.ReadBytes(4));
                switch (trunk)
                {
                    case "VERS":
                        asm.Version = br.ReadInt32();
                        if (asm.Version != 6)
                        {
                            throw new NotSupportedException("本SDK仅支持版本为:6的反编译");
                        }
                        break;
                    case "KEYC":
                        asm.Keyc = br.ReadInt32();
                        break;
                    case "CODE":
                        asm.CodeBuffer = br.ReadBytes(br.ReadInt32());
                        break;
                    case "FUNC":
                        {
                            int count = br.ReadInt32();
                            for (int i = 0; i < count; i++)
                            {
                                Function func = new Function();
                                func.Address = br.ReadInt32();
                                func.Assembly = asm;
                                func.Name = ReadString(br);
                                func.U1 = br.ReadInt32();
                                func.ReturnType = (VarTypes)br.ReadInt32();
                                func.StructID = br.ReadInt32();
                                func.ArgCount = br.ReadInt32();
                                func.TotalLocalCount = br.ReadInt32();
                                func.U4 = br.ReadInt32();
                                for (int j = 0; j < func.TotalLocalCount; j++)
                                {
                                    Variable arg = new Variable();
                                    arg.Name = ReadString(br);
                                    arg.Assembly = asm;
                                    arg.VarType = (VarTypes)br.ReadInt32();
                                    arg.StructID = br.ReadInt32();
                                    arg.Dimension = br.ReadInt32();
                                    if (j < func.ArgCount)
                                        func.Arguments.Add(arg);
                                    func.LocalVariables.Add(arg);
                                }
                                asm.Functions.Add(func);
                            }
                        }
                        break;
                    case "GLOB":
                        {
                            int count = br.ReadInt32();
                            for (int i = 0; i < count; i++)
                            {
                                Variable var = new Variable();
                                var.Name = ReadString(br);
                                var.Assembly = asm;
                                var.VarType = (VarTypes)br.ReadInt32();
                                var.StructID = br.ReadInt32();
                                var.Dimension = br.ReadInt32();
                                var.U3 = br.ReadInt32();
                                asm.global.Add(var);
                            }
                        }
                        break;
                    case "GSET":
                        {
                            int count = br.ReadInt32();
                            for (int i = 0; i < count; i++)
                            {
                                Variable var = asm.global[br.ReadInt32()];
                                VarTypes type = (VarTypes)br.ReadInt32();
                                switch (type)
                                {
                                    case VarTypes.Float:
                                        var.FloatVal = br.ReadSingle();
                                        break;
                                    case VarTypes.String:
//.........这里部分代码省略.........
开发者ID:Ritsuko7,项目名称:chinesize,代码行数:101,代码来源:Assembly.cs


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