Browse Source

cherry picking

also update readme saying why this fork's version of enet is eternally 2.4.0
Matt Coburn 5 years ago
parent
commit
fc2b4724c2
2 changed files with 15 additions and 0 deletions
  1. 2 0
      README.md
  2. 13 0
      Source/Managed/ENet.cs

+ 2 - 0
README.md

@@ -17,6 +17,8 @@ The original C library both this fork and upstreams' fork is based on is located
 A slightly longer description is that this is a improved and refactored version of ENET-CSharp. A fork of a fork, if you want to call it that. This fork started since the upstream fork was originally archived, disabling the ability to report issues and submit pull requests.
 The upstream developer also made some questionable choices (including blacklisting/blocking myself and numerous others). As a result, this fork was made and allows developers to ask questions and submit pull requests to improve the implementation.
 
+Please note that while upstream may have a *newer* version number compared to this fork, upstream Enet native commits will be cherry picked. So you'll get best of both worlds.
+
 ## Native Library Features
 
 - Lightweight and straightforward

+ 13 - 0
Source/Managed/ENet.cs

@@ -921,10 +921,20 @@ namespace ENet {
 		public const uint version = (2 << 16) | (4 << 8) | (0);
 
 		public static bool Initialize() {
+			if (Native.enet_linked_version() != version)
+				throw new InvalidOperationException("You're trying to use an incompatible version of Enet with this Managed Library.");
+
 			return Native.enet_initialize() == 0;
 		}
 
 		public static bool Initialize(Callbacks callbacks) {
+			if(callbacks == null) 
+				throw new ArgumentNullException("callbacks");
+			
+			if (Native.enet_linked_version() != version)
+				throw new InvalidOperationException("You're trying to use an incompatible version of Enet with this Managed Library.");
+
+			
 			ENetCallbacks nativeCallbacks = callbacks.NativeData;
 
 			return Native.enet_initialize_with_callbacks(version, ref nativeCallbacks) == 0;
@@ -979,6 +989,9 @@ namespace ENet {
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern void enet_deinitialize();
 
+		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
+		internal static extern uint enet_linked_version();
+		
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern uint enet_time_get();