NativeMethods.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.Text;
  4. using Network;
  5. namespace UNet
  6. {
  7. public static class NativeMethods
  8. {
  9. private const string LIB = "ENet.dll";
  10. public const int ENET_PEER_PACKET_THROTTLE_SCALE = 32;
  11. public const int ENET_PEER_PACKET_THROTTLE_ACCELERATION = 2;
  12. public const int ENET_PEER_PACKET_THROTTLE_DECELERATION = 2;
  13. public const int ENET_PEER_PACKET_THROTTLE_INTERVAL = 5000;
  14. public const int ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT = 1;
  15. public const int ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT = 255;
  16. public const int ENET_PROTOCOL_MAXIMUM_PEER_ID = 0xfff;
  17. public const uint ENET_VERSION = (1 << 16) | (3 << 8) | (10);
  18. public const uint ENET_HOST_ANY = 0;
  19. public const uint ENET_HOST_BROADCAST = 0xffffffff;
  20. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_address_set_host")
  21. ]
  22. internal static extern int EnetAddressSetHost(ref ENetAddress address, string hostName);
  23. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_address_get_host")
  24. ]
  25. internal static extern int EnetAddressGetHost(
  26. ref ENetAddress address, StringBuilder hostName, uint nameLength);
  27. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  28. EntryPoint = "enet_address_get_host_ip")]
  29. internal static extern int EnetAddressGetHostIp(
  30. ref ENetAddress address, StringBuilder hostIp, uint ipLength);
  31. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_deinitialize")]
  32. internal static extern void EnetDeinitialize();
  33. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_initialize")]
  34. internal static extern int EnetInitialize();
  35. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  36. EntryPoint = "enet_initialize_with_callbacks")]
  37. internal static extern int EnetInitializeWithCallbacks(uint version, ref ENetCallbacks inits);
  38. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_enable_crc")]
  39. internal static extern void EnetEnableCrc(IntPtr host);
  40. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_host_create")]
  41. internal static extern IntPtr EnetHostCreate(
  42. ref ENetAddress address, uint peerLimit, uint channelLimit, uint incomingBandwidth,
  43. uint outgoingBandwidth);
  44. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_host_create")]
  45. internal static extern IntPtr EnetHostCreate(
  46. IntPtr address, uint peerLimit, uint channelLimit, uint incomingBandwidth,
  47. uint outgoingBandwidth);
  48. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_host_destroy")]
  49. internal static extern void EnetHostDestroy(IntPtr host);
  50. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_host_connect")]
  51. internal static extern IntPtr EnetHostConnect(
  52. IntPtr host, ref ENetAddress address, uint channelCount, uint data);
  53. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_host_broadcast")]
  54. internal static extern void EnetHostBroadcast(IntPtr host, byte channelID, IntPtr packet);
  55. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_host_compress")]
  56. internal static extern void EnetHostCompress(IntPtr host, IntPtr compressor);
  57. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  58. EntryPoint = "enet_host_compress_with_range_coder")]
  59. internal static extern int EnetHostCompressWithRangeCoder(IntPtr host);
  60. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  61. EntryPoint = "enet_host_channel_limit")]
  62. internal static extern void EnetHostChannelLimit(IntPtr host, uint channelLimit);
  63. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  64. EntryPoint = "enet_host_bandwidth_limit")]
  65. internal static extern void EnetHostBandwidthLimit(
  66. IntPtr host, uint incomingBandwidth, uint outgoingBandwidth);
  67. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_host_flush")]
  68. internal static extern void EnetHostFlush(IntPtr host);
  69. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_host_check_events"
  70. )]
  71. internal static extern int EnetHostCheckEvents(IntPtr host, ENetEvent ev);
  72. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_host_service")]
  73. internal static extern int EnetHostService(IntPtr host, ENetEvent ev, uint timeout);
  74. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_time_get")]
  75. internal static extern uint EnetTimeGet();
  76. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_time_set")]
  77. internal static extern void EnetTimeSet(uint newTimeBase);
  78. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_packet_create")]
  79. internal static extern IntPtr EnetPacketCreate(byte[] data, uint dataLength, PacketFlags flags);
  80. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_packet_destroy")]
  81. internal static extern void EnetPacketDestroy(IntPtr packet);
  82. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_packet_resize")]
  83. internal static extern int EnetPacketResize(IntPtr packet, uint dataLength);
  84. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  85. EntryPoint = "enet_peer_throttle_configure")]
  86. internal static extern void EnetPeerThrottleConfigure(
  87. IntPtr peer, uint interval, uint acceleration, uint deceleration);
  88. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_peer_send")]
  89. internal static extern int EnetPeerSend(IntPtr peer, byte channelID, IntPtr packet);
  90. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_peer_receive")]
  91. internal static extern IntPtr EnetPeerReceive(IntPtr peer, out byte channelID);
  92. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_peer_reset")]
  93. internal static extern void EnetPeerReset(IntPtr peer);
  94. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_peer_ping")]
  95. internal static extern void EnetPeerPing(IntPtr peer);
  96. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  97. EntryPoint = "enet_peer_disconnect_now")]
  98. internal static extern void EnetPeerDisconnectNow(IntPtr peer, uint data);
  99. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_peer_disconnect")]
  100. internal static extern void EnetPeerDisconnect(IntPtr peer, uint data);
  101. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  102. EntryPoint = "enet_peer_disconnect_later")]
  103. internal static extern void EnetPeerDisconnectLater(IntPtr peer, uint data);
  104. }
  105. }