mirror of
https://github.com/Facepunch/sbox-public.git
synced 2025-12-23 22:48:07 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
27 lines
704 B
C#
27 lines
704 B
C#
using System.IO;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace Sandbox;
|
|
|
|
public static partial class SandboxSystemExtensions
|
|
{
|
|
/// <summary>
|
|
/// Read a null terminated string from the stream, at given offset.
|
|
/// </summary>
|
|
/// <param name="stream">The stream to read from.</param>
|
|
/// <param name="offset">Offset where to start reading, from the beginning of the stream.</param>
|
|
public static string ReadNullTerminatedString( this Stream stream, long offset )
|
|
{
|
|
stream.Seek( offset, SeekOrigin.Begin );
|
|
|
|
int b;
|
|
List<byte> bytes = new List<byte>();
|
|
while ( (b = stream.ReadByte()) != 0x00 )
|
|
{
|
|
bytes.Add( (byte)b );
|
|
}
|
|
|
|
return Encoding.UTF8.GetString( bytes.ToArray() );
|
|
}
|
|
}
|