本文整理汇总了C#中System.IO.MemoryStream.ReadInt32方法的典型用法代码示例。如果您正苦于以下问题:C# MemoryStream.ReadInt32方法的具体用法?C# MemoryStream.ReadInt32怎么用?C# MemoryStream.ReadInt32使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.MemoryStream
的用法示例。
在下文中一共展示了MemoryStream.ReadInt32方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseAttributes
private static ICollection<Sc2ReplayAttribute> ParseAttributes(IMpqArchive replay)
{
var file = replay.ReadFile("replay.attributes.events");
using (var stream = new MemoryStream(file))
{
stream.Skip(5); // there is a 5-byte header; should we validate this?
var attributeCount = stream.ReadInt32();
var attributes = new List<Sc2ReplayAttribute>();
for (var i = 0; i < attributeCount; i++)
{
var attr = new Sc2ReplayAttribute
{
Header = stream.ReadInt32(),
Type = (Sc2ReplayAttributeType) stream.ReadInt32(),
PlayerIndex = stream.ReadByte(),
Value = stream.ReadBytes(4).Reverse().ToArray(),
};
attributes.Add(attr);
}
return attributes;
}
}
示例2: Read
public void Read(MemoryStream ms)
{
base.Read(ms, "MCNK");
flags = (uint) ms.ReadInt32();
indexX = (uint)ms.ReadInt32();
indexY = (uint)ms.ReadInt32();
numLayers = (uint)ms.ReadInt32();
numDoodads = (uint)ms.ReadInt32();
mcvtOff = (uint)ms.ReadInt32();
mcnrOff = (uint)ms.ReadInt32();
mclyOff = (uint)ms.ReadInt32();
mcrfOff = (uint)ms.ReadInt32();
mcalOff = (uint)ms.ReadInt32();
mcalSize = (uint)ms.ReadInt32();
mcshOff = (uint)ms.ReadInt32();
mcshSize = (uint)ms.ReadInt32();
areaId = (uint)ms.ReadInt32();
numWmos = (uint)ms.ReadInt32();
holes = (uint)ms.ReadInt32();
texmap0 = (ulong)ms.ReadInt64();
texmap1 = (ulong)ms.ReadInt64();
predTex = (uint)ms.ReadInt32();
noEffectDoodad = (uint)ms.ReadInt32();
msceOff = (uint)ms.ReadInt32();
numSoundEmitters = (uint)ms.ReadInt32();
mclqOff = (uint)ms.ReadInt32();
mclqSize = (uint)ms.ReadInt32();
float x = ms.ReadFloat();
float y = ms.ReadFloat();
float z = ms.ReadFloat();
position = new Vector3(x, y, z);
mccvOff = (uint)ms.ReadInt32();
ms.Read(pad, 0, pad.Length);
}
示例3: Read
public void Read(MemoryStream ms)
{
id = (uint)ms.ReadInt32();
position.X = ms.ReadFloat(); position.Y = ms.ReadFloat(); position.Z = ms.ReadFloat();
rotation.X = ms.ReadFloat(); rotation.Y = ms.ReadFloat(); rotation.Z = ms.ReadFloat(); rotation.W = ms.ReadFloat();
scale = ms.ReadFloat();
color = (uint) ms.ReadInt32();
file = "";
}
示例4: ParseData
protected override void ParseData(MemoryStream ms)
{
Width = Helper.ConvertEndian(ms.ReadInt32());
Height = Helper.ConvertEndian(ms.ReadInt32());
BitDepth = Convert.ToByte(ms.ReadByte());
ColorType = Convert.ToByte(ms.ReadByte());
CompressionMethod = Convert.ToByte(ms.ReadByte());
FilterMethod = Convert.ToByte(ms.ReadByte());
InterlaceMethod = Convert.ToByte(ms.ReadByte());
}
示例5: Read
public uint Read(MemoryStream ms)
{
base.Read(ms, "MPHD");
flags = (uint)ms.ReadInt32();
ms.Read(pad, 0, pad.Length);
return size;
}
示例6: ReadInt32
public void ReadInt32()
{
Int32 testValue = 2048;
using( var stream = new MemoryStream() )
{
var bytes = BitConverter.GetBytes( testValue );
stream.Write( bytes, 0, bytes.Length );
stream.Seek( 0, SeekOrigin.Begin );
var value = stream.ReadInt32();
Assert.AreEqual( value, testValue );
}
}
示例7: Read
public uint Read(MemoryStream ms)
{
base.Read(ms, "MOGP");
nameIndex = (uint)ms.ReadInt32();
descriptionIndex = (uint)ms.ReadInt32();
flags = (uint)ms.ReadInt32();
bboxMin.X = ms.ReadFloat(); bboxMin.Y = ms.ReadFloat(); bboxMin.Z = ms.ReadFloat();
bboxMax.X = ms.ReadFloat(); bboxMax.Y = ms.ReadFloat(); bboxMax.Z = ms.ReadFloat();
moprIndex = (ushort)ms.ReadShort();
numMoprItems = (ushort)ms.ReadShort();
numBatchesA = (ushort)ms.ReadShort();
numBatchesB = (ushort)ms.ReadShort();
numBatchesC = (ushort)ms.ReadShort();
ms.Read(fogIndices, 0, fogIndices.Length);
liquid = (uint)ms.ReadInt32();
wmoGroupId = (uint)ms.ReadInt32();
ms.Read(unknown, 0, unknown.Length);
return size;
}
示例8: Read
public uint Read(MemoryStream ms)
{
id = (uint)ms.ReadInt32();
uid = (uint)ms.ReadInt32();
pos.X = ms.ReadFloat(); pos.Y = ms.ReadFloat(); pos.Z = ms.ReadFloat();
rot.X = ms.ReadFloat(); rot.Y = ms.ReadFloat(); rot.Z = ms.ReadFloat();
scale = (ushort)ms.ReadShort();
flags = (ushort)ms.ReadShort();
return 0;
}
示例9: M2
public M2(mpq.Wrapper mpq_h, string name)
{
MemoryStream ms = new MemoryStream(mpq_h.GetFile(name));
// read in chunk by chunk
ms.Read(id, 0, id.Length);
ms.Read(version, 0, id.Length);
nameLength = (uint) ms.ReadInt32();
nameOff = (uint)ms.ReadInt32();
flags = (uint)ms.ReadInt32();
ms.Read(pad0, 0, pad0.Length);
numVertices = (uint) ms.ReadInt32();
verticesOff = (uint)ms.ReadInt32();
ms.Read(pad1, 0, pad1.Length);
numBoundingTriangles = (uint)ms.ReadInt32();
boundingTriangleOff = (uint)ms.ReadInt32();
numBoundingVertices = (uint)ms.ReadInt32();
boundingVerticesOff = (uint)ms.ReadInt32();
numBoundingNormals = (uint)ms.ReadInt32();
boundingNormalsOff = (uint)ms.ReadInt32();
isCollide = numBoundingTriangles > 0;
// ignore non collidable M2s
if (!isCollide)
return;
// get M2 model name
ms.Position = nameOff;
byte[] _b = new byte[nameLength];
ms.Read(_b, 0, (int) nameLength);
System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
_m2name = enc.GetString(_b);
if (numVertices > 0)
{
ms.Position = verticesOff;
for (int i = 0; i < numVertices; i++)
{
Vector3 v;
v.X = ms.ReadFloat(); v.Y = ms.ReadFloat(); v.Z = ms.ReadFloat();
_vertices.Add(v);
}
}
// get bounding triangles
if (numBoundingTriangles > 0)
{
ms.Position = boundingTriangleOff;
for (int i = 0; i < numBoundingTriangles; i++)
{
// in the file those are 16bit, so read short
_boundingIndices.Add(ms.ReadShort());
}
}
// get bounding vertices
if (numBoundingVertices > 0)
{
ms.Position = boundingVerticesOff;
for (int i = 0; i < numBoundingVertices; i++)
{
Vector3 v;
v.X = ms.ReadFloat(); v.Y = ms.ReadFloat(); v.Z = ms.ReadFloat();
_boundingVertices.Add(v);
}
}
// get bounding normals
if (numBoundingNormals > 0)
{
ms.Position = boundingNormalsOff;
for (int i = 0; i < numBoundingNormals; i++)
{
Vector3 v;
v.X = ms.ReadFloat(); v.Y = ms.ReadFloat(); v.Z = ms.ReadFloat();
_boundingNormals.Add(v);
}
}
bbox = BoundingBox.CreateFromPoints(_boundingVertices);
}
示例10: parseObjectReferences
void parseObjectReferences(MemoryStream ms)
{
// get all object reference MCNKs
for (int i = 0; i < 256; i++)
{
ObjectReference_s _or = new ObjectReference_s();
// there is always a MCNK chunk first
_or.mcnkChunk.Read(ms, "MCNK");
long data_off = ms.Position;
long chunk_end;
long mcnk_end = ms.Position + _or.mcnkChunk.size ;
while (ms.Position < mcnk_end)
{
string hdr = Util.hdr(ms) ;
switch (hdr)
{
case "MCRD":
{
// read doodad indices
_or.mcrdChunk.Read(ms, "MCRD");
chunk_end = ms.Position + _or.mcrdChunk.size;
while (ms.Position < chunk_end)
_or.doodadIndices.Add(ms.ReadInt32());
}
break;
case "MCRW":
{
// read WMO indices
_or.mcrwChunk.Read(ms, "MCRW");
chunk_end = ms.Position + _or.mcrwChunk.size;
while (ms.Position < chunk_end)
_or.wmoIndices.Add(ms.ReadInt32());
}
break;
default:
throw new Exception("Not exptected chunk: " + hdr);
}
}
_objectRefs.Add(_or);
}
long left = ms.Length - ms.Position;
if (left != 0)
throw new Exception("still data left");
}
示例11: RolloverLogFile
/// <summary>
/// Resumes a rollover log
/// </summary>
/// <param name="fileName">the name of the log file to load.</param>
public RolloverLogFile(string fileName)
{
FileName = fileName;
SourceFiles.Clear();
IsValid = false;
try
{
byte[] data = File.ReadAllBytes(fileName);
if (data.Length < Header.Length + 1 + 20) //Header + Version + SHA1
{
Log.Publish(MessageLevel.Warning, "Failed to load file.", "Expected file length is not long enough", fileName);
return;
}
for (int x = 0; x < Header.Length; x++)
{
if (data[x] != Header[x])
{
Log.Publish(MessageLevel.Warning, "Failed to load file.", "Incorrect File Header", fileName);
return;
}
}
byte[] hash = new byte[20];
Array.Copy(data, data.Length - 20, hash, 0, 20);
using (var sha = new SHA1Managed())
{
var checksum = sha.ComputeHash(data, 0, data.Length - 20);
if (!hash.SequenceEqual(checksum))
{
Log.Publish(MessageLevel.Warning, "Failed to load file.", "Hashsum failed.", fileName);
return;
}
}
var stream = new MemoryStream(data);
stream.Position = Header.Length;
int version = stream.ReadNextByte();
switch (version)
{
case 1:
int count = stream.ReadInt32();
while (count > 0)
{
count--;
SourceFiles.Add(stream.ReadGuid());
}
DestinationFile = stream.ReadGuid();
IsValid = true;
return;
default:
Log.Publish(MessageLevel.Warning, "Failed to load file.", "Version Not Recgonized.", fileName);
SourceFiles.Clear();
return;
}
}
catch (Exception ex)
{
Log.Publish(MessageLevel.Warning, "Failed to load file.", "Unexpected Error", fileName, ex);
SourceFiles.Clear();
return;
}
}
示例12: Decompress
public static byte[] Decompress(byte[] buffer, int offset, int count)
{
if (buffer == null)
throw new ArgumentNullException();
if (count < 0)
throw new FormatException();
if (offset + count > buffer.Length)
throw new IndexOutOfRangeException();
using (MemoryStream buffStream = new MemoryStream(buffer, offset, count))
{
InflaterInputStream zipStream;
uint magicStream = buffStream.ReadUInt32();
if (magicStream != magic)
{
throw new InvalidDataException("found an invalid zlib block");
}
uint buffMaxSegmentSize = buffStream.ReadUInt32();
if (buffMaxSegmentSize != maxSegmentSize)
{
throw new FormatException();
}
uint totComprSize = buffStream.ReadUInt32();
uint totUncomprSize = buffStream.ReadUInt32();
byte[] outputBuffer = new byte[totUncomprSize];
int numOfSegm = (int)Math.Ceiling((double)totUncomprSize / (double)maxSegmentSize);
int headSegm = 16;
int dataSegm = headSegm + (numOfSegm * 8);
int buffOff = 0;
for (int i = 0; i < numOfSegm; i++)
{
buffStream.Seek(headSegm, SeekOrigin.Begin);
int comprSegm = buffStream.ReadInt32();
int uncomprSegm = buffStream.ReadInt32();
headSegm = (int)buffStream.Position;
buffStream.Seek(dataSegm, SeekOrigin.Begin);
//Console.WriteLine("compr size: {0}, uncompr size: {1}, data offset: 0x{2:X8}", comprSegm, uncomprSegm, dataSegm);
zipStream = new InflaterInputStream(buffStream);
zipStream.Read(outputBuffer, buffOff, uncomprSegm);
zipStream.Flush();
buffOff += uncomprSegm;
dataSegm += comprSegm;
}
buffStream.Close();
return outputBuffer;
}
}
示例13: PCCObjectHelper
void PCCObjectHelper(MemoryStream tempStream, string filePath)
{
tempStream.Seek(0, SeekOrigin.Begin);
Names = new List<string>();
Imports = new List<ImportEntry>();
Exports = new List<ExportEntry>();
if (GameVersion != 3)
{
// Find ME1 and 2 header...Why so difficult ME1 and 2?
tempStream.Seek(12, SeekOrigin.Begin);
int tempNameSize = tempStream.ReadInt32();
tempStream.Seek(64 + tempNameSize, SeekOrigin.Begin);
int tempGenerator = tempStream.ReadInt32();
tempStream.Seek(36 + tempGenerator * 12, SeekOrigin.Current);
int tempPos = (int)tempStream.Position + (GameVersion == 2 ? 0 : 4);
tempStream.Seek(0, SeekOrigin.Begin);
header = tempStream.ReadBytes(tempPos);
tempStream.Seek(0, SeekOrigin.Begin);
}
else
header = tempStream.ReadBytes(headerSize);
if (magic != ZBlock.magic &&
magic.Swap() != ZBlock.magic)
throw new FormatException(filePath + " is not a pcc file");
if (GameVersion == 3 && lowVers != 684 && highVers != 194)
throw new FormatException("unsupported version");
if (compressed)
{
if (GameVersion == 3)
ReadCompressedME3(tempStream);
else
ReadCompressedME1And2(tempStream);
compressed = false;
}
else
listsStream = tempStream;
//Fill name list
listsStream.Seek(NameOffset, SeekOrigin.Begin);
for (int i = 0; i < NameCount; i++)
{
int strLength = listsStream.ReadInt32();
string name = null;
switch (GameVersion)
{
case 1:
name = ReadME1Name(strLength);
break;
case 2:
name = ReadME2Name(strLength);
break;
case 3:
name = ReadME3Name(strLength);
break;
}
Names.Add(name);
}
byte[] buffer = null;
// fill import list
listsStream.Seek(ImportOffset, SeekOrigin.Begin);
buffer = new byte[ImportEntry.byteSize];
for (int i = 0; i < ImportCount; i++)
Imports.Add(new ImportEntry(this, listsStream));
//fill export list
listsStream.Seek(ExportOffset, SeekOrigin.Begin);
for (int i = 0; i < ExportCount; i++)
{
uint expInfoOffset = (uint)listsStream.Position;
// Find export data size
int count = 0;
int expInfoSize = 0;
if (GameVersion == 3)
{
listsStream.Seek(44, SeekOrigin.Current);
count = listsStream.ReadInt32();
expInfoSize = 68 + (count * 4);
}
else
{
listsStream.Seek(40, SeekOrigin.Current);
count = listsStream.ReadInt32();
listsStream.Seek(4 + count * 12, SeekOrigin.Current);
count = listsStream.ReadInt32();
listsStream.Seek(4 + count * 4, SeekOrigin.Current);
listsStream.Seek(16, SeekOrigin.Current);
expInfoSize = (int)(listsStream.Position - expInfoOffset);
}
// Read export data
//.........这里部分代码省略.........
示例14: ParseData
private void ParseData( GetDataEventArgs args )
{
try
{
PacketTypes packet = args.MsgID;
using (var data = new MemoryStream(args.Msg.readBuffer, args.Index, args.Length))
{
TSPlayer player = TShock.Players[args.Msg.whoAmI];
var name = player.Name;
if (player.IsLoggedIn)
{
name = player.UserAccountName;
}
switch (packet)
{
case PacketTypes.Tile:
{
byte type = data.ReadInt8();
int x = data.ReadInt32();
int y = data.ReadInt32();
bool fail = true;
Action act;
if (type == 0 || type == 2 || type == 4)
act = Action.BREAK;
else if (type == 1 || type == 3)
act = Action.PLACE;
else
act = Action.ERROR;
byte tileType = 0;
if (act == Action.BREAK)
{
tileType = Main.tile[x, y].type;
fail = data.ReadBoolean();
}
else if (act == Action.PLACE)
{
tileType = data.ReadInt8();
fail = false;
}
if (act != Action.ERROR && !fail)
{
TileEvent evt = new TileEvent(x, y, name, player.IP, act, tileType,
LogTile.helper.GetTime());
queue.Enqueue(evt);
}
break;
}
case PacketTypes.TileKill:
{
int x = data.ReadInt32();
int y = data.ReadInt32();
TileEvent evt = new TileEvent(x, y, name, player.IP, Action.BREAK, 0x15,
LogTile.helper.GetTime());
queue.Enqueue(evt);
break;
}
//case PacketTypes.ChestOpen:
// {
// int chestID = data.ReadInt16();
// int x = data.ReadInt32();
// int y = data.ReadInt32();
// int curChest = 0;
// if (!chestMap.TryGetValue(player, out curChest)) // chest being opened
// {
// //Console.WriteLine( string.Format( "Open:{0}: cId:{1}:", player.Name, chestID ) );
// if ( chestID > 0 ) // sometimes, this gets called right after a close
// {
// chestMap.Add(player, chestID);
// itemMap.Add(player, Main.chest[chestID].item);
// } // if
// }
// else // chest is being closed
// {
// //Console.WriteLine( "Closing: " + player.Name );
// chestMap.Remove(player);
// itemMap.Remove(player);
// }
// break;
// }
//case PacketTypes.ChestItem:
// {
// int chestID = data.ReadInt16();
// byte itemSlot = data.ReadInt8();
// byte stack = data.ReadInt8();
// int curChest = 0;
// int type = itemMap[player][itemSlot].type;
// if (LogTile.enableDebugOutput) Console.WriteLine(type);
// Item[] curItems = Main.chest[chestID].item;
// if (LogTile.enableDebugOutput) Console.WriteLine(curItems[itemSlot].type);
// //Console.WriteLine( "Chest item: " + player.Name );
// itemMap.Remove(player);
// itemMap.Add(player, curItems);
// break;
// }
//case PacketTypes.ChestGetContents:
// {
//.........这里部分代码省略.........
示例15: ReadCompressedME3
void ReadCompressedME3(MemoryStream tempStream)
{
List<Block> blockList = null;
// seeks the blocks info position
tempStream.Seek(idxOffsets + 60, SeekOrigin.Begin);
int generator = tempStream.ReadInt32();
tempStream.Seek((generator * 12) + 20, SeekOrigin.Current);
int blockCount = tempStream.ReadInt32();
blockList = new List<Block>();
// creating the Block list
for (int i = 0; i < blockCount; i++)
{
Block temp = new Block();
temp.uncOffset = tempStream.ReadInt32();
temp.uncSize = tempStream.ReadInt32();
temp.cprOffset = tempStream.ReadInt32();
temp.cprSize = tempStream.ReadInt32();
blockList.Add(temp);
}
// correcting the header, in case there's need to be saved
Buffer.BlockCopy(BitConverter.GetBytes((int)0), 0, header, header.Length - 12, sizeof(int));
tempStream.Read(header, header.Length - 8, 8);
headerEnd = (int)tempStream.Position;
// copying the extraNamesList
int extraNamesLenght = blockList[0].cprOffset - headerEnd;
if (extraNamesLenght > 0)
{
extraNamesList = new byte[extraNamesLenght];
tempStream.Read(extraNamesList, 0, extraNamesLenght);
}
int dataStart = 0;
using (MemoryStream he = new MemoryStream(header))
{
he.Seek(0, SeekOrigin.Begin);
he.ReadInt32();
he.ReadInt32();
dataStart = he.ReadInt32();
}
//Decompress ALL blocks
listsStream = new MemoryStream();
for (int i = 0; i < blockCount; i++)
{
tempStream.Seek(blockList[i].cprOffset, SeekOrigin.Begin);
listsStream.Seek(blockList[i].uncOffset, SeekOrigin.Begin);
listsStream.WriteBytes(ZBlock.Decompress(tempStream, blockList[i].cprSize));
}
}