NativeMethods.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.Text;
  4. namespace Base
  5. {
  6. public static class NativeMethods
  7. {
  8. private const string LIB = "ENet";
  9. public const int ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT = 255;
  10. public const int ENET_PROTOCOL_MAXIMUM_PEER_ID = 0xfff;
  11. [DllImport(LIB, EntryPoint = "enet_address_set_host", CallingConvention = CallingConvention.Cdecl)]
  12. internal static extern int ENetAddressSetHost(ref ENetAddress address, string hostName);
  13. [DllImport(LIB, EntryPoint = "enet_address_get_host", CallingConvention = CallingConvention.Cdecl)]
  14. internal static extern int ENetAddressGetHost(ref ENetAddress address, StringBuilder hostName, uint nameLength);
  15. [DllImport(LIB, EntryPoint = "enet_address_get_host_ip", CallingConvention = CallingConvention.Cdecl)]
  16. internal static extern int ENetAddressGetHostIp(ref ENetAddress address, StringBuilder hostIp, uint ipLength);
  17. [DllImport(LIB, EntryPoint = "enet_deinitialize", CallingConvention = CallingConvention.Cdecl)]
  18. internal static extern void ENetDeinitialize();
  19. [DllImport(LIB, EntryPoint = "enet_initialize", CallingConvention = CallingConvention.Cdecl)]
  20. internal static extern int ENetInitialize();
  21. [DllImport(LIB, EntryPoint = "enet_host_create", CallingConvention = CallingConvention.Cdecl)]
  22. internal static extern IntPtr ENetHostCreate(
  23. ref ENetAddress address, uint peerLimit, uint channelLimit, uint incomingBandwidth, uint outgoingBandwidth);
  24. [DllImport(LIB, EntryPoint = "enet_host_create", CallingConvention = CallingConvention.Cdecl)]
  25. internal static extern IntPtr ENetHostCreate(IntPtr address, uint peerLimit, uint channelLimit, uint incomingBandwidth, uint outgoingBandwidth);
  26. [DllImport(LIB, EntryPoint = "enet_host_destroy", CallingConvention = CallingConvention.Cdecl)]
  27. internal static extern void ENetHostDestroy(IntPtr host);
  28. [DllImport(LIB, EntryPoint = "enet_host_connect", CallingConvention = CallingConvention.Cdecl)]
  29. internal static extern IntPtr ENetHostConnect(IntPtr host, ref ENetAddress address, uint channelCount, uint data);
  30. [DllImport(LIB, EntryPoint = "enet_host_broadcast", CallingConvention = CallingConvention.Cdecl)]
  31. internal static extern void ENetHostBroadcast(IntPtr host, byte channelID, IntPtr packet);
  32. [DllImport(LIB, EntryPoint = "enet_host_compress", CallingConvention = CallingConvention.Cdecl)]
  33. internal static extern void ENetHostCompress(IntPtr host, IntPtr compressor);
  34. [DllImport(LIB, EntryPoint = "enet_host_compress_with_range_coder", CallingConvention = CallingConvention.Cdecl)]
  35. internal static extern int ENetHostCompressWithRangeCoder(IntPtr host);
  36. [DllImport(LIB, EntryPoint = "enet_host_channel_limit", CallingConvention = CallingConvention.Cdecl)]
  37. internal static extern void ENetHostChannelLimit(IntPtr host, uint channelLimit);
  38. [DllImport(LIB, EntryPoint = "enet_host_bandwidth_limit", CallingConvention = CallingConvention.Cdecl)]
  39. internal static extern void ENetHostBandwidthLimit(IntPtr host, uint incomingBandwidth, uint outgoingBandwidth);
  40. [DllImport(LIB, EntryPoint = "enet_host_flush", CallingConvention = CallingConvention.Cdecl)]
  41. internal static extern void ENetHostFlush(IntPtr host);
  42. [DllImport(LIB, EntryPoint = "enet_host_check_events", CallingConvention = CallingConvention.Cdecl)]
  43. internal static extern int ENetHostCheckEvents(IntPtr host, ENetEvent ev);
  44. [DllImport(LIB, EntryPoint = "enet_host_service", CallingConvention = CallingConvention.Cdecl)]
  45. internal static extern int ENetHostService(IntPtr host, ENetEvent ev, uint timeout);
  46. [DllImport(LIB, EntryPoint = "enet_time_get", CallingConvention = CallingConvention.Cdecl)]
  47. internal static extern uint ENetTimeGet();
  48. [DllImport(LIB, EntryPoint = "enet_time_set", CallingConvention = CallingConvention.Cdecl)]
  49. internal static extern void ENetTimeSet(uint newTimeBase);
  50. [DllImport(LIB, EntryPoint = "enet_packet_create", CallingConvention = CallingConvention.Cdecl)]
  51. internal static extern IntPtr ENetPacketCreate(byte[] data, uint dataLength, PacketFlags flags);
  52. [DllImport(LIB, EntryPoint = "enet_packet_destroy", CallingConvention = CallingConvention.Cdecl)]
  53. internal static extern void ENetPacketDestroy(IntPtr packet);
  54. [DllImport(LIB, EntryPoint = "enet_packet_resize", CallingConvention = CallingConvention.Cdecl)]
  55. internal static extern int ENetPacketResize(IntPtr packet, uint dataLength);
  56. [DllImport(LIB, EntryPoint = "enet_peer_throttle_configure", CallingConvention = CallingConvention.Cdecl)]
  57. internal static extern void ENetPeerThrottleConfigure(IntPtr peer, uint interval, uint acceleration, uint deceleration);
  58. [DllImport(LIB, EntryPoint = "enet_peer_send")]
  59. internal static extern int ENetPeerSend(IntPtr peer, byte channelID, IntPtr packet);
  60. [DllImport(LIB, EntryPoint = "enet_peer_receive")]
  61. internal static extern IntPtr ENetPeerReceive(IntPtr peer, out byte channelID);
  62. [DllImport(LIB, EntryPoint = "enet_peer_reset")]
  63. internal static extern void ENetPeerReset(IntPtr peer);
  64. [DllImport(LIB, EntryPoint = "enet_peer_ping")]
  65. internal static extern void ENetPeerPing(IntPtr peer);
  66. [DllImport(LIB, EntryPoint = "enet_peer_disconnect_now")]
  67. internal static extern void ENetPeerDisconnectNow(IntPtr peer, uint data);
  68. [DllImport(LIB, EntryPoint = "enet_peer_disconnect")]
  69. internal static extern void ENetPeerDisconnect(IntPtr peer, uint data);
  70. [DllImport(LIB, EntryPoint = "enet_peer_disconnect_later")]
  71. internal static extern void ENetPeerDisconnectLater(IntPtr peer, uint data);
  72. }
  73. }