diff --git a/README.md b/README.md index 2c8efa8..a3eae1b 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ Building A managed assembly can be built using any available compiling platform that supports C# 3.0 or higher. +Must define `VALVE_CALLBACK_PACK_SMALL` on Linux/Apple/FreeBSD, or `VALVE_CALLBACK_PACK_LARGE` on other platforms. + Define `VALVESOCKETS_SPAN` to enable support for Span. Please, follow [these steps](https://github.com/nxrighthere/ValveSockets-CSharp/issues/3#issuecomment-491916163) to enable fast access to native memory blocks and improve performance. Usage diff --git a/ValveSockets.cs b/ValveSockets.cs index 7d17cde..b0416ea 100644 --- a/ValveSockets.cs +++ b/ValveSockets.cs @@ -257,7 +257,7 @@ public enum Result { WGNetworkSendExceeded = 110 } - [StructLayout(LayoutKind.Sequential)] + [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct Address : IEquatable
{ [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] ip; @@ -289,7 +289,7 @@ public bool Equals(Address other) { } } - [StructLayout(LayoutKind.Sequential)] + [StructLayout(LayoutKind.Sequential, Pack = 8)] public struct Configuration { public ConfigurationValue value; public ConfigurationDataType dataType; @@ -310,7 +310,18 @@ public struct ConfigurationData { } } - [StructLayout(LayoutKind.Sequential)] + static class StructConst + { +#if VALVE_CALLBACK_PACK_SMALL + public const int PACK_SIZE = 4; +#elif VALVE_CALLBACK_PACK_LARGE + public const int PACK_SIZE = 8; +#else + #error "Not define VALVE_CALLBACK_PACK_SMALL(Linux/Apple/FreeBSD) or VALVE_CALLBACK_PACK_LARGE(Anything else.)" +#endif + } + + [StructLayout(LayoutKind.Sequential, Pack = StructConst.PACK_SIZE)] public struct StatusInfo { private const int callback = Library.socketsCallbacks + 1; public Connection connection; @@ -318,7 +329,7 @@ public struct StatusInfo { private ConnectionState oldState; } - [StructLayout(LayoutKind.Sequential)] + [StructLayout(LayoutKind.Sequential, Pack = StructConst.PACK_SIZE)] public struct ConnectionInfo { public NetworkingIdentity identity; public long userData; @@ -333,11 +344,12 @@ public struct ConnectionInfo { public string endDebug; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] public string connectionDescription; - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] + public int flags; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 63)] private uint[] reserved; } - [StructLayout(LayoutKind.Sequential)] + [StructLayout(LayoutKind.Sequential, Pack = StructConst.PACK_SIZE)] public struct ConnectionStatus { public ConnectionState state; public int ping; @@ -356,7 +368,7 @@ public struct ConnectionStatus { private uint[] reserved; } - [StructLayout(LayoutKind.Explicit, Size = 136)] + [StructLayout(LayoutKind.Explicit, Size = 136, Pack = 1)] public struct NetworkingIdentity { [FieldOffset(0)] public IdentityType type; @@ -376,7 +388,7 @@ public void SetSteamID(ulong steamID) { } } - [StructLayout(LayoutKind.Sequential)] + [StructLayout(LayoutKind.Sequential, Pack = 8)] public struct NetworkingMessage { public IntPtr data; public int length; @@ -390,6 +402,8 @@ public struct NetworkingMessage { public int channel; public int flags; public long userData; + public ushort idxLane; + public ushort pad1__; public void CopyTo(byte[] destination) { if (destination == null)