NativeStructs.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 malloc_cb(IntPtr size);
  45. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  46. public delegate void free_cb(IntPtr memory);
  47. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  48. public delegate void no_memory_cb();
  49. private IntPtr malloc, free, no_memory;
  50. }
  51. [StructLayout(LayoutKind.Sequential)]
  52. public struct ENetCompressor
  53. {
  54. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  55. public delegate void compress_cb(
  56. IntPtr context, IntPtr inBuffers, IntPtr inBufferCount, IntPtr inLimit, IntPtr outData, IntPtr outLimit);
  57. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  58. public delegate void decompress_cb(IntPtr context, IntPtr inData, IntPtr inLimit, IntPtr outData, IntPtr outLimit);
  59. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  60. public delegate void destroy_cb(IntPtr context);
  61. public IntPtr context;
  62. public IntPtr compress, decompress, destroy;
  63. }
  64. [StructLayout(LayoutKind.Sequential)]
  65. public class ENetEvent
  66. {
  67. public EventType type;
  68. public IntPtr peer;
  69. public byte channelID;
  70. public uint data;
  71. public IntPtr packet;
  72. }
  73. [StructLayout(LayoutKind.Sequential)]
  74. public struct ENetHost
  75. {
  76. }
  77. [StructLayout(LayoutKind.Sequential)]
  78. public class ENetListNode
  79. {
  80. public ENetListNode next;
  81. public ENetListNode previous;
  82. }
  83. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  84. public delegate void ENetPacketFreeCallback(ref ENetPacket param0);
  85. [StructLayout(LayoutKind.Sequential)]
  86. public struct ENetPacket
  87. {
  88. public uint referenceCount;
  89. public uint flags;
  90. public IntPtr data;
  91. public uint dataLength;
  92. public ENetPacketFreeCallback freeCallback;
  93. }
  94. [StructLayout(LayoutKind.Sequential)]
  95. public struct ENetPeer
  96. {
  97. public ENetListNode dispatchList;
  98. public readonly IntPtr host;
  99. public readonly ushort outgoingPeerID;
  100. public readonly ushort incomingPeerID;
  101. public readonly uint connectID;
  102. public readonly byte outgoingSessionID;
  103. public readonly byte incomingSessionID;
  104. public ENetAddress address;
  105. public IntPtr data;
  106. public readonly PeerState state;
  107. }
  108. }