本文整理汇总了C#中System.IO.BinaryReader.ReadNullTerminatedString方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryReader.ReadNullTerminatedString方法的具体用法?C# BinaryReader.ReadNullTerminatedString怎么用?C# BinaryReader.ReadNullTerminatedString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.BinaryReader
的用法示例。
在下文中一共展示了BinaryReader.ReadNullTerminatedString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Read
public void Read(Stream inputStream)
{
BinaryReader reader = new BinaryReader(inputStream, Encoding.UTF8, true);
int magicNumber = reader.ReadInt32();
int version = reader.ReadInt32(); // GZ 2, TPP 3
int endianess = reader.ReadInt32(); // LE, BE
int entryCount = reader.ReadInt32();
int valuesOffset = reader.ReadInt32();
int keysOffset = reader.ReadInt32();
inputStream.Position = valuesOffset;
Dictionary<int, LangEntry> offsetEntryDictionary = new Dictionary<int, LangEntry>();
for (int i = 0; i < entryCount; i++)
{
int valuePosition = (int)inputStream.Position - valuesOffset;
short valueConstant = reader.ReadInt16();
Debug.Assert(valueConstant == 1);
string value = reader.ReadNullTerminatedString();
offsetEntryDictionary.Add(valuePosition, new LangEntry
{
Value = value
});
}
inputStream.Position = keysOffset;
for (int i = 0; i < entryCount; i++)
{
uint key = reader.ReadUInt32();
int offset = reader.ReadInt32();
offsetEntryDictionary[offset].Key = key;
}
Entries = offsetEntryDictionary.Values.ToList();
}
示例2: ReadAll
public void ReadAll()
{
CustomPostprocessor.DoImports = false;
try
{
BinaryReader reader = new BinaryReader(new MemoryStream(data));
reader.SkipBytes(16);
reader.SkipBytes(12);
Archive arc = null;
while (reader.BaseStream.Position <= 90000)
{
short entryType = reader.ReadInt16();
short subType = reader.ReadInt16();
short entryCount = reader.ReadInt16();
short entryIndex = reader.ReadInt16();
string name = reader.ReadNullTerminatedString();
if (reader.PeekChar() == 0)
{
reader.SkipByte();
}
if (entryType == 2)
{
arc = new Archive(name, AssetDatabase.LoadAssetAtPath("Assets/SilentHill3/Archives/" + name + ".arc", typeof(UnityEngine.Object)));
arc.OpenArchive();
}
if (entryType == 3)
{
try
{
name = name.Replace("tmp", arc.NameAsPath());
string path = "Assets/SilentHill3/Resources/" + name;
path = Path.GetDirectoryName(path);
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
File.WriteAllBytes("Assets/SilentHill3/Resources/" + name, arc.AllFiles[entryCount].data);
}
catch (Exception)
{
Debug.LogError("Problem at " + name + " [" + entryIndex + "](" + arc.AllFiles.Count + ") sub " + subType.ToString("X"));
}
}
}
AssetDatabase.Refresh();
}
catch (Exception e)
{
Debug.LogException(e);
}
CustomPostprocessor.DoImports = true;
}
示例3: LoadBinaryData
public void LoadBinaryData(byte[] inData)
{
using (MemoryStream ms = new MemoryStream(inData))
{
using (BinaryReader br = new BinaryReader(ms))
{
this.Filenames.Add(br.ReadNullTerminatedString());
}
}
}
示例4: LoadBinaryData
public void LoadBinaryData(byte[] inData)
{
using (MemoryStream ms = new MemoryStream(inData))
{
using (BinaryReader br = new BinaryReader(ms))
{
this.SkyboxName = br.ReadNullTerminatedString();
}
}
}
示例5: Load
public static PTH Load(string path)
{
FileInfo fi = new FileInfo(path);
Logger.LogToFile(Logger.LogLevel.Info, "{0}", path);
PTH pth = new PTH();
using (var br = new BinaryReader(new FileStream(path, FileMode.Open)))
{
while (br.BaseStream.Position < br.BaseStream.Length)
{
pth.contents.Add(new PTHEntry { Name = br.ReadNullTerminatedString(), Size = (int)br.ReadUInt32(), Offset = (int)br.ReadUInt32() });
}
}
return pth;
}
示例6: Load
/// <summary>
/// Loads this SBM model
/// </summary>
/// <returns></returns>
public bool Load(out string err)
{
// Check the file exists
if (!File.Exists(filename))
{
err = "File not found";
return false;
}
// Load it
using (FileStream strm = File.OpenRead(filename))
{
// Create reader
BinaryReader rdr = new BinaryReader(strm);
// Read header
string magic = new string(rdr.ReadChars(4));
if (magic != "SBM\0")
{
err = "Specified file is not an SBM file";
return false;
}
int version = rdr.ReadInt32();
if (version != 1)
{
err = "Unsupported SBM version";
return false;
}
int num_materials = rdr.ReadInt32();
int num_meshes = rdr.ReadInt32();
// Read all materials
string[] materials = new string[num_materials];
for (int i = 0; i < num_materials; i++)
materials[i] = rdr.ReadNullTerminatedString();
// Read all meshes
meshes = new SBMMesh[num_meshes];
for (int i = 0; i < num_meshes; i++)
{
// Read mesh header
int num_vertices = rdr.ReadInt32();
int num_submeshes = rdr.ReadInt32();
// Create mesh builder
MeshBuilder builder = new MeshBuilder();
builder.UseNormals = true;
builder.UseTexCoords = true;
builder.UseTangents = true;
// Read all vertices
for (int j = 0; j < num_vertices; j++)
{
builder.AddPosition(new Vector3(rdr.ReadSingle(), rdr.ReadSingle(), rdr.ReadSingle()));
builder.AddNormal(new Vector3(rdr.ReadSingle(), rdr.ReadSingle(), rdr.ReadSingle()));
builder.AddTextureCoord(new Vector2(rdr.ReadSingle(), rdr.ReadSingle()));
builder.AddTangent(new Vector3(rdr.ReadSingle(), rdr.ReadSingle(), rdr.ReadSingle()));
}
// Loop each submesh
string[] meshmats = new string[num_submeshes];
for (int j = 0; j < num_submeshes; j++)
{
// Read submesh header
int num_indices = rdr.ReadInt32();
int material_index = rdr.ReadInt32();
meshmats[j] = materials[material_index];
// Read all indices
for (int k = 0; k < num_indices; k++)
builder.AddIndex(j, rdr.ReadUInt32());
}
// Add element to mesh array
SBMMesh sbmmesh = new SBMMesh();
sbmmesh.Mesh = builder.Build();
sbmmesh.Materials = meshmats;
meshes[i] = sbmmesh;
}
}
// Success
err = null;
return true;
}
示例7: LoadBinaryData
public void LoadBinaryData(byte[] inData)
{
using (MemoryStream ms = new MemoryStream(inData))
{
using (BinaryReader br = new BinaryReader(ms))
{
// Skip the first two bytes, since they're always zero
ms.Position += 2;
while (ms.Position < ms.Length)
{
this.GroupNames.Add(ms.Position, br.ReadNullTerminatedString());
}
}
}
}
示例8: LoadBinaryData
/// <summary>
/// Deserialzes the provided binary data of the object. This is the full data block which follows the data
/// signature and data block length.
/// </summary>
/// <param name="inData">The binary data containing the object.</param>
public void LoadBinaryData(byte[] inData)
{
using (MemoryStream ms = new MemoryStream(inData))
{
using (BinaryReader br = new BinaryReader(ms))
{
while (ms.Position < ms.Length)
{
this.DoodadNames.Add(new KeyValuePair<long, string>(ms.Position, br.ReadNullTerminatedString()));
}
}
}
// Remove null entries from the doodad list
this.DoodadNames.RemoveAll(s => s.Value.Equals("\0"));
}
示例9: ReadDirectoryEntries
private void ReadDirectoryEntries(BinaryReader br)
{
String extension, path, filename;
while ((extension = br.ReadNullTerminatedString()).Length > 0)
{
while ((path = br.ReadNullTerminatedString()).Length > 0)
{
// Single space = root directory
path = path == " " ? "" : path.Replace('\\', '/').Trim('/');
while ((filename = br.ReadNullTerminatedString()).Length > 0)
{
// get me some file information
var entry = ReadEntry(br, path + "/" + filename + "." + extension);
Entries.Add(entry.FullName, entry);
}
}
}
}
示例10: Load
/// <summary>
/// Loads the file from the specified stream.
/// </summary>
/// <param name="stream">The stream to read from.</param>
public override void Load(Stream stream)
{
BinaryReader reader = new BinaryReader(stream, Encoding.GetEncoding("EUC-KR"));
short modelFileCount = reader.ReadInt16();
for (int i = 0; i < modelFileCount; i++) {
string modelFile = reader.ReadNullTerminatedString();
ModelFiles.Add(modelFile);
}
short textureFileCount = reader.ReadInt16();
for (int i = 0; i < textureFileCount; i++) {
TextureFile texture = new TextureFile();
texture.FilePath = reader.ReadNullTerminatedString();
texture.UseSkinShader = reader.ReadInt16() != 0;
texture.AlphaEnabled = reader.ReadInt16() != 0;
texture.TwoSided = reader.ReadInt16() != 0;
texture.AlphaTestEnabled = reader.ReadInt16() != 0;
texture.AlphaReference = reader.ReadInt16();
texture.DepthTestEnabled = reader.ReadInt16() != 0;
texture.DepthWriteEnabled = reader.ReadInt16() != 0;
texture.BlendType = (BlendType)reader.ReadInt16();
texture.UseSpecularShader = reader.ReadInt16() != 0;
texture.Alpha = reader.ReadSingle();
texture.GlowType = (GlowType)reader.ReadInt16();
texture.GlowColour = reader.ReadColour3();
TextureFiles.Add(texture);
}
short effectFileCount = reader.ReadInt16();
for (int i = 0; i < effectFileCount; i++) {
string effectFile = reader.ReadNullTerminatedString();
EffectFiles.Add(effectFile);
}
short objectCount = reader.ReadInt16();
for (int i = 0; i < objectCount; i++) {
ModelListObject @object = new ModelListObject();
int cylinderRadius = reader.ReadInt32();
@object.BoundingCylinder = new BoundingCylinder(new Vector2(reader.ReadInt32(), reader.ReadInt32()), cylinderRadius);
int partCount = reader.ReadInt16();
if (partCount > 0) {
for (int j = 0; j < partCount; j++) {
ModelListPart part = new ModelListPart();
part.Model = reader.ReadInt16();
part.Texture = reader.ReadInt16();
byte propertyType = 0;
while ((propertyType = reader.ReadByte()) != 0) {
byte size = reader.ReadByte();
switch ((ModelListPropertyType)propertyType) {
case ModelListPropertyType.Position:
part.Position = reader.ReadVector3();
break;
case ModelListPropertyType.Rotation:
part.Rotation = reader.ReadQuaternion(true);
break;
case ModelListPropertyType.Scale:
part.Scale = reader.ReadVector3();
break;
case ModelListPropertyType.AxisRotation:
part.AxisRotation = reader.ReadQuaternion(true);
break;
case ModelListPropertyType.Parent:
part.Parent = reader.ReadInt16();
break;
case ModelListPropertyType.Collision:
part.Collision = (CollisionType)reader.ReadInt16();
break;
case ModelListPropertyType.ConstantAnimation:
part.AnimationFilePath = reader.ReadString(size);
break;
case ModelListPropertyType.VisibleRangeSet:
part.VisibleRangeSet = reader.ReadInt16();
break;
case ModelListPropertyType.UseLightmap:
part.UseLightmap = reader.ReadInt16() != 0;
break;
case ModelListPropertyType.BoneIndex:
part.BoneIndex = reader.ReadInt16();
break;
case ModelListPropertyType.DummyIndex:
part.DummyIndex = reader.ReadInt16();
break;
//.........这里部分代码省略.........
示例11: MW2PartystatePlayer
public MW2PartystatePlayer(BinaryReader binaryReader)
{
//Наркобарон!
playerID = binaryReader.ReadByte();
unknown2 = binaryReader.ReadBytes(3);
playerName = binaryReader.ReadNullTerminatedString(Encoding.UTF8); //Is the encoding right?
unknown4 = binaryReader.ReadUInt32();
steamID = binaryReader.ReadUInt64();
internalIP = new IPAddress(binaryReader.ReadBytes(4));
externalIP = new IPAddress(binaryReader.ReadBytes(4));
internalPort = binaryReader.ReadUInt16();
externalPort = binaryReader.ReadUInt16();
unknown10 = binaryReader.ReadBytes(24);
unknown11 = binaryReader.ReadUInt32();
unknown12 = binaryReader.ReadUInt32();
unknown13 = binaryReader.ReadUInt16();
unknown14 = binaryReader.ReadByte();
unknown15 = binaryReader.ReadByte();
unknown16 = binaryReader.ReadUInt32();
unknown17 = binaryReader.ReadUInt32();
unknown18 = binaryReader.ReadByte();
if (unknown18 != Convert.ToByte("0C", 16))
unknown19 = binaryReader.ReadByte();
Regex regex = new Regex("\\^[0-9]");
IsHost = false;
StrippedPlayerName = regex.Replace(playerName, "");
}
示例12: Parse
/// <summary>
/// Parses the read addon stream into the instance properties.
/// </summary>
/// <exception cref="ReaderException">Parsing errors.</exception>
private void Parse()
{
if (Buffer.Length == 0)
{
throw new ReaderException("Attempted to read from empty buffer.");
}
Buffer.Seek(0, SeekOrigin.Begin);
BinaryReader reader = new BinaryReader(Buffer);
// Ident
if (String.Join(String.Empty, reader.ReadChars(Addon.Ident.Length)) != Addon.Ident)
{
throw new ReaderException("Header mismatch.");
}
FormatVersion = reader.ReadChar();
if (FormatVersion > Addon.Version)
{
throw new ReaderException("Can't parse version " + Convert.ToString(FormatVersion) + " addons.");
}
SteamID = (ulong)reader.ReadInt64(); // SteamID (long)
Timestamp = new DateTime(1970, 1, 1, 0, 0, 0).ToLocalTime().
AddSeconds((double)reader.ReadInt64()); // Timestamp (long)
// Required content (not used at the moment, just read out)
if (FormatVersion > 1)
{
string content = reader.ReadNullTerminatedString();
while (content != String.Empty)
content = reader.ReadNullTerminatedString();
}
Name = reader.ReadNullTerminatedString();
Description = reader.ReadNullTerminatedString();
Author = reader.ReadNullTerminatedString();
Version = reader.ReadInt32(); // Addon version (unused)
// File index
int FileNumber = 1;
int Offset = 0;
while (reader.ReadInt32() != 0)
{
IndexEntry entry = new IndexEntry();
entry.Path = reader.ReadNullTerminatedString();
entry.Size = reader.ReadInt64(); // long long
entry.CRC = reader.ReadUInt32(); // unsigned long
entry.Offset = Offset;
entry.FileNumber = (uint)FileNumber;
Index.Add(entry);
Offset += (int)entry.Size;
FileNumber++;
}
Fileblock = (ulong)reader.BaseStream.Position;
// Try to parse the description
using (MemoryStream descStream = new MemoryStream(Encoding.ASCII.GetBytes(Description)))
{
DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(DescriptionJSON));
try
{
DescriptionJSON dJSON = (DescriptionJSON)jsonSerializer.ReadObject(descStream);
Description = dJSON.Description;
Type = dJSON.Type;
Tags = new List<string>(dJSON.Tags);
}
catch (SerializationException)
{
// The description is a plaintext in the file.
Type = String.Empty;
Tags = new List<string>();
}
}
}
示例13: Load
/// <summary>
/// Loads the file from the specified stream.
/// </summary>
/// <param name="stream">The stream to read from.</param>
public override void Load(Stream stream)
{
BinaryReader reader = new BinaryReader(stream, Encoding.GetEncoding("EUC-KR"));
string identifier = reader.ReadNullTerminatedString();
int version;
if (string.Compare(identifier, FILE_IDENTIFIER_7, false) == 0) {
version = 7;
} else if (string.Compare(identifier, FILE_IDENTIFIER_8, false) == 0) {
version = 8;
} else {
throw new FileIdentifierMismatchException(FilePath, string.Format("{0} / {1}", FILE_IDENTIFIER_7, FILE_IDENTIFIER_8), identifier);
}
format = (VertexFormat)reader.ReadInt32();
BoundingBox = new Bounds(reader.ReadVector3(), reader.ReadVector3());
short boneCount = reader.ReadInt16();
for (int i = 0; i < boneCount; i++) {
BoneTable.Add(reader.ReadInt16());
}
short vertexCount = reader.ReadInt16();
for (int i = 0; i < vertexCount; i++) {
ModelVertex vertex = new ModelVertex();
vertex.Position = reader.ReadVector3();
Vertices.Add(vertex);
}
if (NormalsEnabled) {
for (int i = 0; i < vertexCount; i++) {
ModelVertex vertex = Vertices[i];
vertex.Normal = reader.ReadVector3();
}
}
if (ColoursEnabled) {
for (int i = 0; i < vertexCount; i++) {
float a = reader.ReadSingle();
ModelVertex vertex = Vertices[i];
vertex.Colour = new Color(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), a);
}
}
if (BonesEnabled) {
for (int i = 0; i < vertexCount; i++) {
ModelVertex vertex = Vertices[i];
vertex.BoneWeights = reader.ReadVector4();
vertex.BoneIndices = reader.ReadShortVector4();
}
}
if (TangentsEnabled) {
for (int i = 0; i < vertexCount; i++) {
ModelVertex vertex = Vertices[i];
vertex.Tangent = reader.ReadVector3();
}
}
if (TextureCoordinates1Enabled) {
for (int i = 0; i < vertexCount; i++) {
ModelVertex vertex = Vertices[i];
vertex.TextureCoordinates[0] = reader.ReadVector2();
}
}
if (TextureCoordinates2Enabled) {
for (int i = 0; i < vertexCount; i++) {
ModelVertex vertex = Vertices[i];
vertex.TextureCoordinates[1] = reader.ReadVector2();
}
}
if (TextureCoordinates3Enabled) {
for (int i = 0; i < vertexCount; i++) {
ModelVertex vertex = Vertices[i];
vertex.TextureCoordinates[2] = reader.ReadVector2();
}
}
if (TextureCoordinates4Enabled) {
for (int i = 0; i < vertexCount; i++) {
ModelVertex vertex = Vertices[i];
vertex.TextureCoordinates[3] = reader.ReadVector2();
}
}
short indexCount = reader.ReadInt16();
for (int i = 0; i < indexCount; i++) {
Indices.Add(reader.ReadShortVector3());
//.........这里部分代码省略.........
示例14: USymSampleEvent
public USymSampleEvent(BinaryReader reader)
{
Address = reader.ReadSLeb128 ();
Size = reader.ReadULeb128 ();
Name = reader.ReadNullTerminatedString ();
}
示例15: MethodJitEvent
public MethodJitEvent (BinaryReader reader)
{
TimeDiff = reader.ReadULeb128 ();
Method = reader.ReadSLeb128 ();
CodeAddress = reader.ReadSLeb128 ();
CodeSize = reader.ReadULeb128 ();
Name = reader.ReadNullTerminatedString ();
}