本文整理汇总了C#中System.IO.BinaryReader.ReadStruct方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryReader.ReadStruct方法的具体用法?C# BinaryReader.ReadStruct怎么用?C# BinaryReader.ReadStruct使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.BinaryReader
的用法示例。
在下文中一共展示了BinaryReader.ReadStruct方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Patch
public Patch(string patchFile)
{
using (FileStream fs = new FileStream(patchFile, FileMode.Open, FileAccess.Read))
using (BinaryReader br = new BinaryReader(fs))
{
m_PTCH = br.ReadStruct<PTCH>();
//Debug.Assert(m_PTCH.m_magic.FourCC() == "PTCH");
if (m_PTCH.m_magic.FourCC() != "PTCH")
throw new InvalidDataException("not PTCH");
m_MD5 = br.ReadStruct<MD5_>();
Debug.Assert(m_MD5.m_magic.FourCC() == "MD5_");
m_XFRM = br.ReadStruct<XFRM>();
Debug.Assert(m_XFRM.m_magic.FourCC() == "XFRM");
m_type = m_XFRM.m_type.FourCC();
switch (m_type)
{
case "BSD0":
m_unpackedSize = br.ReadInt32();
m_compressedDiffStream = new MemoryStream(br.ReadRemaining());
BSDIFFParse();
break;
case "COPY":
m_compressedDiffStream = new MemoryStream(br.ReadRemaining());
return;
default:
Debug.Assert(false, String.Format("Unknown patch type: {0}", m_type));
break;
}
}
}
示例2: STLReader
public STLReader(string fileName)
{
reader = BinaryReaderExtensions.FromFile(fileName);
MPQHeader mHdr = reader.ReadStruct<MPQHeader>();
StlHeader sHdr = reader.ReadStruct<StlHeader>();
//StlEntry sEntry = reader.ReadStruct<StlEntry>();
RecordsCount = sHdr.entriesSize / 0x50;
m_rows = new byte[RecordsCount][];
for (int i = 0; i < RecordsCount; ++i)
m_rows[i] = reader.ReadBytes(0x50);
//StringTable = new Dictionary<int, string>();
//if (reader.BaseStream.Position != reader.BaseStream.Length)
//{
// while (reader.BaseStream.Position != reader.BaseStream.Length)
// {
// if (reader.PeekChar() == 0)
// {
// reader.BaseStream.Position++;
// continue;
// }
// int offset = (int)reader.BaseStream.Position;
// StringTable[offset] = reader.ReadStringNull();
// }
//}
}
示例3: it_will_read_bool_true
public void it_will_read_bool_true()
{
using (var reader = new BinaryReader(new MemoryStream(new byte[] { 0xA0 })))
{
var value = reader.ReadStruct<bool>();
value.Should().BeTrue();
reader.BaseStream.ShouldBeEof();
}
}
示例4: it_will_read_color
public void it_will_read_color()
{
var expected = Color.FromArgb(0x33, 0x66, 0x99, 0xcc);
using (var reader = new BinaryReader(new MemoryStream(new[] { expected.A, expected.R, expected.G, expected.B })))
{
var color = reader.ReadStruct<Color>();
color.Should().BeOfType<Color>().And.Be(expected);
reader.BaseStream.ShouldBeEof();
}
}
示例5: it_will_read_enum_using_alternate_underlying_type
public void it_will_read_enum_using_alternate_underlying_type()
{
const LongEnum expected = LongEnum.B;
using (var reader = new BinaryReader(new MemoryStream(BitConverter.GetBytes((long)expected))))
{
var value = reader.ReadStruct<LongEnum>();
value.Should().BeOfType<LongEnum>().And.Be(expected);
reader.BaseStream.ShouldBeEof();
}
}
示例6: it_will_read_nullable_enum
public void it_will_read_nullable_enum()
{
const IntEnum expected = IntEnum.B;
using (var reader = new BinaryReader(new MemoryStream(BitConverter.GetBytes((int)expected))))
{
var value = reader.ReadStruct<IntEnum?>();
value.Should().Be(expected);
reader.BaseStream.ShouldBeEof();
}
}
示例7: ReadTilemaps
private IList<WEDTilemap> ReadTilemaps(BinaryReader reader, IEnumerable<WEDOverlay> overlays)
{
var tilemaps = new List<WEDTilemap>();
foreach (var overlay in overlays)
{
reader.BaseStream.Seek(overlay.TileOffset, SeekOrigin.Begin);
tilemaps.Add(reader.ReadStruct<WEDTilemap>());
}
return tilemaps;
}
示例8: GetTexture
/// <summary>
/// Returns an SM2 map texuture
/// </summary>
public BitmapSource GetTexture(Map map, int detail, UnitSync unitSync)
{
UnitSync.NativeMethods.RemoveAllArchives();
UnitSync.NativeMethods.AddAllArchives(map.ArchiveName);
ProgressChanged(this, new ProgressChangedEventArgs(0, "Extracting map"));
var mapName = map.Name + ".smf";
var smfFileData = unitSync.ReadVfsFile("maps\\" + mapName);
var reader = new BinaryReader(new MemoryStream(smfFileData));
var smfHeader = reader.ReadStruct<SMFHeader>();
smfHeader.SelfCheck();
var mapWidth = smfHeader.mapx;
var mapHeight = smfHeader.mapy;
reader.BaseStream.Position = smfHeader.tilesPtr;
var mapTileHeader = reader.ReadStruct<MapTileHeader>();
// get the tile files and the number of tiles they contain
var tileFiles = new Dictionary<byte[], int>();
for (var i = 0; i < mapTileHeader.numTileFiles; i++)
{
var numTiles = reader.ReadInt32();
var tileFileData = unitSync.ReadVfsFile("maps\\" + reader.ReadCString());
tileFiles.Add(tileFileData, numTiles);
}
// get the position of the tiles
var mapUnitInTiles = Tiles.TileMipLevel1Size/smfHeader.texelPerSquare;
var tilesX = smfHeader.mapx/mapUnitInTiles;
var tilesY = smfHeader.mapy/mapUnitInTiles;
var tileIndices = new int[tilesX*tilesY];
for (var i = 0; i < tileIndices.Length; i++)
{
tileIndices[i] = reader.ReadInt32();
}
Tiles.ProgressChanged += (s, e) => ProgressChanged(this, e);
UnitSync.NativeMethods.RemoveAllArchives();
// load the tiles
return Tiles.LoadTiles(tileFiles, tileIndices, tilesX, tilesY, detail);
}
示例9: GetTexture
/// <summary>
/// Returns n SM2 map texuture
/// </summary>
public Bitmap GetTexture(string mapArchive, string mapName, int detail, out int width, out int height)
{
if (!mapName.ToLower().EndsWith("smf")) throw new ArgumentException("Invalid map name");
if (!mapArchive.ToLower().EndsWith("sdz") && !mapArchive.ToLower().EndsWith("sd7")) throw new ArgumentException("Invalid map archive");
ProgressChanged(this, new ProgressChangedEventArgs(0, "Extracting map"));
var reader = new BinaryReader(new MemoryStream(ExtractFile(mapArchive, "maps\\" + mapName)));
var smfHeader = reader.ReadStruct<SMFHeader>();
smfHeader.SelfCheck();
width = smfHeader.mapx;
height = smfHeader.mapy;
reader.BaseStream.Position = smfHeader.tilesPtr;
var mapTileHeader = reader.ReadStruct<MapTileHeader>();
// get the tile files and the number of tiles they contain
var tileFiles = new Dictionary<byte[], int>();
for (var i = 0; i < mapTileHeader.numTileFiles; i++) {
var numTiles = reader.ReadInt32();
tileFiles.Add(ExtractFile(mapArchive, "maps\\" + reader.ReadCString()), numTiles);
}
// get the position of the tiles
var mapUnitInTiles = Tiles.TileMipLevel1Size/smfHeader.texelPerSquare;
var tilesX = smfHeader.mapx/mapUnitInTiles;
var tilesY = smfHeader.mapy/mapUnitInTiles;
var tileIndices = new int[tilesX*tilesY];
for (var i = 0; i < tileIndices.Length; i++) {
tileIndices[i] = reader.ReadInt32();
}
Tiles.ProgressChanged += (s, e) => ProgressChanged(this, e);
// load the tiles
return Tiles.LoadTiles(tileFiles, tileIndices, tilesX, tilesY, detail);
}
示例10: TestMethod1
public void TestMethod1()
{
using (var fs = new FileStream("l.bin", FileMode.OpenOrCreate))
{
var s = new S();
s.hello = 5;
s.world = "hgtr";
s.g = new ST() { blub = 155693 };
var bw = new BinaryWriter(fs);
bw.Write(s);
}
using (var fs = new FileStream("l.bin", FileMode.OpenOrCreate))
{
var bw = new BinaryReader(fs);
var s = bw.ReadStruct<S>();
}
}
示例11: Load
//грузим конфиг
public static void Load()
{
//MessageBox.Show(15.ToString());
if (cfgFInfo.Exists)
{
cfgFSize = cfgFInfo.Length;
_bValue = true;
//MessageBox.Show("file est");
if (cfgFSize != 0)
{
//MessageBox.Show(cfgFSize.ToString());
//грузим конфиг
using (BinaryReader binReader = new BinaryReader(new FileStream(FileName, FileMode.Open)))
{
GCDBExtensions.Init();
CfgDatas= binReader.ReadStruct<CfgDataStruct>();
ConString = CfgDatas.ConStr;
if (CfgDatas.CfgHdr != _ch)
{
MessageBox.Show("Ошибка при считывании header'а конфиг файла, создаю новый конфиг");
New();
}
}
}
else
{
MessageBox.Show(cfgFSize.ToString());
New();
}
}
else
{
MessageBox.Show("not ok file");
_bValue = false;
}
}
示例12: backgroundWorker1_DoWork
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
DirectoryInfo di = new DirectoryInfo(this.folder_patch);
FileInfo[] fi = di.GetFiles("*.pkt", SearchOption.AllDirectories);
int count = 0;
foreach (FileInfo f in fi)
{
if (worker.CancellationPending == true)
{
e.Cancel = true;
break;
}
worker.ReportProgress(count * 100 / fi.Length);
FileStream fs = new FileStream(f.FullName, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
int selectedIndex = 0;
if (comboBox1.InvokeRequired)
this.comboBox1.BeginInvoke(new Action(() => selectedIndex = comboBox1.SelectedIndex));
else
selectedIndex = comboBox1.SelectedIndex;
PktFileMainHeader MainHeader = new PktFileMainHeader();
MainHeader = br.ReadStruct<PktFileMainHeader>();
byte[] buffer = br.ReadBytes((int)MainHeader.OptionalHeaderLength);
if (MainHeader.Signature[0] == 'P'
&& MainHeader.Signature[1] == 'K'
&& MainHeader.Signature[2] == 'T'
&& MainHeader.MajorVersion == 3
&& MainHeader.MinorVersion == 1)
{
UInt32 counts = 0;
while (br.BaseStream.Position != br.BaseStream.Length)
{
try
{
if (worker.CancellationPending == true)
{
e.Cancel = true;
break;
}
string direct = Encoding.UTF8.GetString(br.ReadBytes(4));
var direction = (direct == "SMSG" ? Direction.ToServer : Direction.ToClient);
uint UnixTime = br.ReadUInt32();
uint tickCount = br.ReadUInt32();
int optionalHeaderLength1 = br.ReadInt32();
byte[] optionalData1 = new byte[optionalHeaderLength1];
int dataLength = br.ReadInt32();
byte[] data = new byte[dataLength];
optionalData1 = br.ReadBytes(optionalHeaderLength1);
data = br.ReadBytes(dataLength);
MemoryStream mss = new MemoryStream(data);
BinaryReader brr = new BinaryReader(mss);
uint opcodes = brr.ReadUInt32();
byte[] byteData = new byte[brr.BaseStream.Length - 4];
byteData = brr.ReadBytes((int)(brr.BaseStream.Length - 4));
if (selectedIndex == 0)
{
if (opcodes == (uint)WoWOpcodes.SMSG_NEW_WORLD)
SMSG_NEW_WORLD(new BinaryReader(new MemoryStream(byteData)), f.FullName, counts);
}
else if (selectedIndex == 1)
{
if (opcodes == (uint)WoWOpcodes.CMSG_CREATURE_QUERY)
CMSG_CREATURE_QUERY(new BinaryReader(new MemoryStream(byteData)), f.FullName, counts);
}
else if (selectedIndex == 2)
{
if (opcodes == (uint)WoWOpcodes.SMSG_INIT_WORLD_STATES)
SMSG_INIT_WORLD_STATES(new BinaryReader(new MemoryStream(byteData)), f.FullName, counts);
}
counts++;
}
catch { }
}
br.Close();
fs.Close();
count++;
}
}
}
示例13: ReadDescriptor
private WEDDescriptor ReadDescriptor(BinaryReader reader)
{
return reader.ReadStruct<WEDDescriptor>();
}
示例14: GetPathList
IEnumerable<string> GetPathList(BinaryReader reader, RiotArchiveHeader header)
{
var stream = reader.BaseStream;
stream.Seek(header.PathListOffset, SeekOrigin.Begin);
var pathListInfo = reader.ReadStruct<RiotPathListHeader>();
var stringOffsets = GetStringOffsets(reader, (int)pathListInfo.Length).ToArray();
foreach (var offset in stringOffsets)
{
stream.Seek(header.PathListOffset + offset.Offset, SeekOrigin.Begin);
yield return BinaryReaderTools.GetStaticLengthString(reader, (int)offset.Length);
}
}
示例15: LoadFromVBM
public bool LoadFromVBM(string filename, int vertexIndex, int normalIndex, int texCoord0Index)
{
//FILE * f = NULL;
FileStream f = new FileStream(filename, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(f);
//f = fopen(filename, "rb");
//if(f == NULL)
//return false;
//fseek(f, 0, SEEK_END);
//size_t filesize = ftell(f);
//fseek(f, 0, SEEK_SET);
long filesize = f.Length;
//f.Seek(0, SeekOrigin.End);
//f.Seek(0, SeekOrigin.Begin);
byte[] data = new byte[filesize];
UnmanagedArray<byte> raw_data;
f.Read(data, 0, (int)filesize);
//f.Close();
f.Seek(0, SeekOrigin.Begin);
//VBM_HEADER * header = (VBM_HEADER *)data;
VBM_HEADER header = br.ReadStruct<VBM_HEADER>();
//raw_data = data + header.size + header->num_attribs * sizeof(VBM_ATTRIB_HEADER) + header->num_frames * sizeof(VBM_FRAME_HEADER);
//{
// long offset = header.size + header.num_attribs * Marshal.SizeOf(typeof(VBM_ATTRIB_HEADER)) + header.num_frames * Marshal.SizeOf(typeof(VBM_FRAME_HEADER));
// raw_data = new UnmanagedArray<byte>((int)(data.Length - offset));
// for (int i = 0; i < raw_data.Length; i++)
// {
// raw_data[i] = data[offset+i];
// }
//}
//VBM_ATTRIB_HEADER * attrib_header = (VBM_ATTRIB_HEADER *)(data + header.size);
VBM_ATTRIB_HEADER attrib_header = br.ReadStruct<VBM_ATTRIB_HEADER>();
//VBM_FRAME_HEADER * frame_header = (VBM_FRAME_HEADER *)(data + header.size + header.num_attribs * sizeof(VBM_ATTRIB_HEADER));
{
long offset = header.size + header.num_attribs * Marshal.SizeOf(typeof(VBM_ATTRIB_HEADER));
f.Seek(offset, SeekOrigin.Begin);
}
VBM_FRAME_HEADER frame_header = br.ReadStruct<VBM_FRAME_HEADER>();
uint total_data_size = 0;
//memcpy(&m_header, header, header.size < Marshal.SizeOf(typeof(VBM_HEADER)) ? header.size : Marshal.SizeOf(typeof(VBM_HEADER)));
this.m_header = header;
//memcpy(m_attrib, attrib_header, header.num_attribs * Marshal.SizeOf(typeof(VBM_ATTRIB_HEADER)));
{
long offset = header.size;// +header.num_attribs * Marshal.SizeOf(typeof(VBM_ATTRIB_HEADER));
f.Seek(offset, SeekOrigin.Begin);
}
this.m_attrib = new VBM_ATTRIB_HEADER[header.num_attribs];
for (int i = 0; i < header.num_attribs; i++)
{
this.m_attrib[i] = br.ReadStruct<VBM_ATTRIB_HEADER>();
}
//memcpy(m_frame, frame_header, header.num_frames * Marshal.SizeOf(typeof(VBM_FRAME_HEADER)));
{
long offset = header.size + header.num_attribs * Marshal.SizeOf(typeof(VBM_ATTRIB_HEADER));// +header.num_frames * Marshal.SizeOf(typeof(VBM_FRAME_HEADER));
f.Seek(offset, SeekOrigin.Begin);
}
this.m_frame = new VBM_FRAME_HEADER[header.num_frames];
for (int i = 0; i < header.num_frames; i++)
{
this.m_frame[i] = br.ReadStruct<VBM_FRAME_HEADER>();
}
GL.GenVertexArrays(1, m_vao);
GL.BindVertexArray(m_vao[0]);
GL.GenBuffers(1, m_attribute_buffer);
GL.BindBuffer(BufferTarget.ArrayBuffer, m_attribute_buffer[0]);
//uint i;
for (uint i = 0; i < header.num_attribs; i++)
{
total_data_size += m_attrib[i].components * sizeof(float) * header.num_vertices;
}
{
long offset = header.size + header.num_attribs * Marshal.SizeOf(typeof(VBM_ATTRIB_HEADER)) + header.num_frames * Marshal.SizeOf(typeof(VBM_FRAME_HEADER));
raw_data = new UnmanagedArray<byte>((int)total_data_size);
for (int i = 0; i < raw_data.Length; i++)
{
raw_data[i] = data[offset + i];
}
}
//GL.BufferData(GL_ARRAY_BUFFER, total_data_size, raw_data, GL_STATIC_DRAW);
GL.BufferData(BufferTarget.ArrayBuffer, raw_data, BufferUsage.StaticDraw);
total_data_size = 0;
for (uint i = 0; i < header.num_attribs; i++)
{
uint attribIndex = i;
if (attribIndex == 0)
attribIndex = (uint)vertexIndex;
//.........这里部分代码省略.........