NativeStructs.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace UNet
  4. {
  5. public enum EventType
  6. {
  7. None = 0,
  8. Connect = 1,
  9. Disconnect = 2,
  10. Receive = 3
  11. }
  12. public enum PeerState
  13. {
  14. Uninitialized = -1,
  15. Disconnected = 0,
  16. Connecting = 1,
  17. AcknowledgingConnect = 2,
  18. ConnectionPending = 3,
  19. ConnectionSucceeded = 4,
  20. Connected = 5,
  21. DisconnectLater = 6,
  22. Disconnecting = 7,
  23. AcknowledgingDisconnect = 8,
  24. Zombie = 9
  25. }
  26. [StructLayout(LayoutKind.Sequential)]
  27. public struct ENetAddress
  28. {
  29. public uint Host;
  30. public ushort Port;
  31. }
  32. [StructLayout(LayoutKind.Sequential)]
  33. public struct ENetCallbacks
  34. {
  35. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  36. public delegate IntPtr MallocCb(IntPtr size);
  37. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  38. public delegate void FreeCb(IntPtr memory);
  39. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  40. public delegate void NoMemoryCb();
  41. private readonly IntPtr malloc;
  42. private readonly IntPtr free;
  43. private readonly IntPtr no_memory;
  44. }
  45. [StructLayout(LayoutKind.Sequential)]
  46. public class ENetEvent
  47. {
  48. public EventType Type;
  49. public IntPtr Peer;
  50. public byte ChannelID;
  51. public uint Data;
  52. public IntPtr Packet;
  53. }
  54. [StructLayout(LayoutKind.Sequential)]
  55. public struct ENetHost
  56. {
  57. }
  58. [StructLayout(LayoutKind.Sequential)]
  59. public class ENetListNode
  60. {
  61. public ENetListNode Next;
  62. public ENetListNode Previous;
  63. }
  64. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  65. public delegate void ENetPacketFreeCallback(ref ENetPacket param0);
  66. [StructLayout(LayoutKind.Sequential)]
  67. public struct ENetPacket
  68. {
  69. public uint ReferenceCount;
  70. public uint Flags;
  71. public IntPtr Data;
  72. public uint DataLength;
  73. public ENetPacketFreeCallback FreeCallback;
  74. public IntPtr UserData;
  75. }
  76. [StructLayout(LayoutKind.Sequential)]
  77. public struct ENetPeer
  78. {
  79. public ENetListNode DispatchList;
  80. public readonly IntPtr Host;
  81. public readonly ushort OutgoingPeerID;
  82. public readonly ushort IncomingPeerID;
  83. public readonly uint ConnectID;
  84. public readonly byte OutgoingSessionID;
  85. public readonly byte IncomingSessionID;
  86. public ENetAddress Address;
  87. public IntPtr Data;
  88. public readonly PeerState State;
  89. }
  90. }