NativeStructs.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace ENet
  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. [Flags]
  27. public enum PacketFlags
  28. {
  29. None = 0,
  30. Reliable = 1 << 0,
  31. Unsequenced = 1 << 1,
  32. NoAllocate = 1 << 2
  33. }
  34. [StructLayout(LayoutKind.Sequential)]
  35. public struct ENetAddress
  36. {
  37. public uint Host;
  38. public ushort Port;
  39. }
  40. [StructLayout(LayoutKind.Sequential)]
  41. public struct ENetCallbacks
  42. {
  43. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  44. public delegate IntPtr MallocCb(IntPtr size);
  45. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  46. public delegate void FreeCb(IntPtr memory);
  47. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  48. public delegate void NoMemoryCb();
  49. private readonly IntPtr malloc;
  50. private readonly IntPtr free;
  51. private readonly IntPtr no_memory;
  52. }
  53. [StructLayout(LayoutKind.Sequential)]
  54. public class ENetEvent
  55. {
  56. public EventType Type;
  57. public IntPtr Peer;
  58. public byte ChannelID;
  59. public uint Data;
  60. public IntPtr Packet;
  61. }
  62. [StructLayout(LayoutKind.Sequential)]
  63. public struct ENetHost
  64. {
  65. }
  66. [StructLayout(LayoutKind.Sequential)]
  67. public class ENetListNode
  68. {
  69. public ENetListNode Next;
  70. public ENetListNode Previous;
  71. }
  72. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  73. public delegate void ENetPacketFreeCallback(ref ENetPacket param0);
  74. [StructLayout(LayoutKind.Sequential)]
  75. public struct ENetPacket
  76. {
  77. public uint ReferenceCount;
  78. public uint Flags;
  79. public IntPtr Data;
  80. public uint DataLength;
  81. public ENetPacketFreeCallback FreeCallback;
  82. public IntPtr UserData;
  83. }
  84. [StructLayout(LayoutKind.Sequential)]
  85. public struct ENetPeer
  86. {
  87. public ENetListNode DispatchList;
  88. public readonly IntPtr Host;
  89. public readonly ushort OutgoingPeerID;
  90. public readonly ushort IncomingPeerID;
  91. public readonly uint ConnectID;
  92. public readonly byte OutgoingSessionID;
  93. public readonly byte IncomingSessionID;
  94. public ENetAddress Address;
  95. public IntPtr Data;
  96. public readonly PeerState State;
  97. }
  98. }