mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-05-19 04:17:04 -04:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
37 lines
729 B
C#
37 lines
729 B
C#
using System.Net;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace Steamworks;
|
|
|
|
internal static partial class Utility
|
|
{
|
|
static internal T ToType<T>( this IntPtr ptr )
|
|
{
|
|
if ( ptr == IntPtr.Zero )
|
|
return default;
|
|
|
|
return (T)Marshal.PtrToStructure( ptr, typeof( T ) );
|
|
}
|
|
|
|
static internal object ToType( this IntPtr ptr, System.Type t )
|
|
{
|
|
if ( ptr == IntPtr.Zero )
|
|
return default;
|
|
|
|
return Marshal.PtrToStructure( ptr, t );
|
|
}
|
|
|
|
static internal uint Swap( uint x )
|
|
{
|
|
return ((x & 0x000000ff) << 24) +
|
|
((x & 0x0000ff00) << 8) +
|
|
((x & 0x00ff0000) >> 8) +
|
|
((x & 0xff000000) >> 24);
|
|
}
|
|
|
|
static internal IPAddress Int32ToIp( uint ipAddress )
|
|
{
|
|
return new IPAddress( Swap( ipAddress ) );
|
|
}
|
|
}
|