Просмотр исходного кода

添加第三方库enet的C#包装

tanghai 13 лет назад
Родитель
Сommit
427cff9749

+ 7 - 4
CSharp/App/Editor/Editor.csproj

@@ -10,8 +10,9 @@
     <AppDesignerFolder>Properties</AppDesignerFolder>
     <RootNamespace>Editor</RootNamespace>
     <AssemblyName>Editor</AssemblyName>
-    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
-    <TargetFrameworkProfile>Client</TargetFrameworkProfile>
+    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+    <TargetFrameworkProfile>
+    </TargetFrameworkProfile>
     <FileAlignment>512</FileAlignment>
     <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
     <WarningLevel>4</WarningLevel>
@@ -21,7 +22,7 @@
     <RestorePackages>true</RestorePackages>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
-    <PlatformTarget>x86</PlatformTarget>
+    <PlatformTarget>AnyCPU</PlatformTarget>
     <DebugSymbols>true</DebugSymbols>
     <DebugType>full</DebugType>
     <Optimize>false</Optimize>
@@ -29,6 +30,7 @@
     <DefineConstants>DEBUG;TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
+    <Prefer32Bit>false</Prefer32Bit>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
     <PlatformTarget>x86</PlatformTarget>
@@ -38,6 +40,7 @@
     <DefineConstants>TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
+    <Prefer32Bit>false</Prefer32Bit>
   </PropertyGroup>
   <ItemGroup>
     <Reference Include="Microsoft.Expression.Interactions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
@@ -109,7 +112,7 @@
     <None Include="NLog.config">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </None>
-    <None Include="packages.config" />
+    <None Include="Packages.config" />
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <PropertyGroup>

+ 1 - 1
CSharp/App/Editor/Shell.xaml

@@ -1,5 +1,5 @@
 <Window x:Class="Editor.Shell" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
-        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:cal="http://www.codeplex.com/CompositeWPF"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
         xmlns:prism="http://www.codeplex.com/prism" Title="Editor" Height="800" Width="1280"
         WindowStartupLocation="CenterScreen">
 	<Grid>

+ 4 - 4
CSharp/App/Editor/app.config

@@ -1,11 +1,11 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0"?>
 <configuration>
 	<runtime>
 		<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
 			<dependentAssembly>
-				<assemblyIdentity name="Microsoft.Practices.Prism" publicKeyToken="31bf3856ad364e35" culture="neutral" />
-				<bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0" />
+				<assemblyIdentity name="Microsoft.Practices.Prism" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
+				<bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0"/>
 			</dependentAssembly>
 		</assemblyBinding>
 	</runtime>
-</configuration>
+<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>

+ 4 - 13
CSharp/App/Modules/BehaviorTree/BehaviorTree.csproj

@@ -10,12 +10,13 @@
     <AppDesignerFolder>Properties</AppDesignerFolder>
     <RootNamespace>BehaviorTree</RootNamespace>
     <AssemblyName>BehaviorTree</AssemblyName>
-    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
     <FileAlignment>512</FileAlignment>
     <Utf8Output>true</Utf8Output>
     <ExpressionBlendVersion>4.0.20621.0</ExpressionBlendVersion>
     <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\..\CSharp\</SolutionDir>
     <RestorePackages>true</RestorePackages>
+    <TargetFrameworkProfile />
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <DebugSymbols>true</DebugSymbols>
@@ -25,6 +26,7 @@
     <DefineConstants>DEBUG;TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
+    <Prefer32Bit>false</Prefer32Bit>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     <DebugType>pdbonly</DebugType>
@@ -33,23 +35,15 @@
     <DefineConstants>TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
+    <Prefer32Bit>false</Prefer32Bit>
   </PropertyGroup>
   <ItemGroup>
-    <Reference Include="Microsoft.Expression.Interactions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
-      <HintPath>..\..\..\packages\Prism.4.1.0.0\lib\NET40\Microsoft.Expression.Interactions.dll</HintPath>
-    </Reference>
     <Reference Include="Microsoft.Practices.Prism">
       <HintPath>..\..\..\packages\Prism.4.1.0.0\lib\NET40\Microsoft.Practices.Prism.dll</HintPath>
     </Reference>
-    <Reference Include="Microsoft.Practices.Prism.Interactivity">
-      <HintPath>..\..\..\packages\Prism.4.1.0.0\lib\NET40\Microsoft.Practices.Prism.Interactivity.dll</HintPath>
-    </Reference>
     <Reference Include="Microsoft.Practices.Prism.MefExtensions">
       <HintPath>..\..\..\packages\Prism.MEFExtensions.4.1.0.0\lib\NET40\Microsoft.Practices.Prism.MefExtensions.dll</HintPath>
     </Reference>
-    <Reference Include="Microsoft.Practices.ServiceLocation">
-      <HintPath>..\..\..\packages\CommonServiceLocator.1.0\lib\NET35\Microsoft.Practices.ServiceLocation.dll</HintPath>
-    </Reference>
     <Reference Include="NLog">
       <HintPath>..\..\..\packages\NLog.2.0.0.2000\lib\net40\NLog.dll</HintPath>
     </Reference>
@@ -58,9 +52,6 @@
     <Reference Include="System" />
     <Reference Include="System.ComponentModel.Composition" />
     <Reference Include="System.Core" />
-    <Reference Include="System.Windows.Interactivity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
-      <HintPath>..\..\..\packages\Prism.4.1.0.0\lib\NET40\System.Windows.Interactivity.dll</HintPath>
-    </Reference>
     <Reference Include="System.Xaml" />
     <Reference Include="System.Xml" />
     <Reference Include="WindowsBase" />

+ 18 - 3
CSharp/CSharp.sln

@@ -1,6 +1,6 @@
 
-Microsoft Visual Studio Solution File, Format Version 11.00
-# Visual Studio 2010
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 2012
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Modules", "Modules", "{C4C64188-4FAE-4CC3-A9E6-D9D4AF7429B6}"
 EndProject
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{EAEF8202-B3F6-4F9B-9EFD-41C374433612}"
@@ -20,6 +20,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BehaviorTree", "App\Modules
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Editor", "App\Editor\Editor.csproj", "{C46F3337-0F48-4A72-84AD-8FDD1F159BB0}"
 EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ThirdParty", "ThirdParty", "{9173C593-D63F-49F6-AFA7-028425D13E4B}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Enet", "ThirdParty\Enet\Enet.csproj", "{D0B4CFAC-A368-4742-9863-68776CFA9938}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -60,6 +64,16 @@ Global
 		{C46F3337-0F48-4A72-84AD-8FDD1F159BB0}.Release|Mixed Platforms.Build.0 = Release|x86
 		{C46F3337-0F48-4A72-84AD-8FDD1F159BB0}.Release|x86.ActiveCfg = Release|x86
 		{C46F3337-0F48-4A72-84AD-8FDD1F159BB0}.Release|x86.Build.0 = Release|x86
+		{D0B4CFAC-A368-4742-9863-68776CFA9938}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{D0B4CFAC-A368-4742-9863-68776CFA9938}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{D0B4CFAC-A368-4742-9863-68776CFA9938}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+		{D0B4CFAC-A368-4742-9863-68776CFA9938}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+		{D0B4CFAC-A368-4742-9863-68776CFA9938}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{D0B4CFAC-A368-4742-9863-68776CFA9938}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{D0B4CFAC-A368-4742-9863-68776CFA9938}.Release|Any CPU.Build.0 = Release|Any CPU
+		{D0B4CFAC-A368-4742-9863-68776CFA9938}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+		{D0B4CFAC-A368-4742-9863-68776CFA9938}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+		{D0B4CFAC-A368-4742-9863-68776CFA9938}.Release|x86.ActiveCfg = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
@@ -67,7 +81,8 @@ Global
 	GlobalSection(NestedProjects) = preSolution
 		{C4C64188-4FAE-4CC3-A9E6-D9D4AF7429B6} = {6E9D97F0-4243-452E-B832-1A855B8118EB}
 		{C46F3337-0F48-4A72-84AD-8FDD1F159BB0} = {6E9D97F0-4243-452E-B832-1A855B8118EB}
-		{6CD185D1-08E0-4729-A999-2D5B57BA8193} = {C4C64188-4FAE-4CC3-A9E6-D9D4AF7429B6}
 		{48A2E149-0DAC-41B4-BB54-DFBCCD6D42B3} = {ADBF5F67-B480-4A93-9D50-C81856FC61A9}
+		{6CD185D1-08E0-4729-A999-2D5B57BA8193} = {C4C64188-4FAE-4CC3-A9E6-D9D4AF7429B6}
+		{D0B4CFAC-A368-4742-9863-68776CFA9938} = {9173C593-D63F-49F6-AFA7-028425D13E4B}
 	EndGlobalSection
 EndGlobal

+ 5 - 2
CSharp/Platform/Infrastructure/Infrastructure.csproj

@@ -10,10 +10,11 @@
     <AppDesignerFolder>Properties</AppDesignerFolder>
     <RootNamespace>Infrastructure</RootNamespace>
     <AssemblyName>Infrastructure</AssemblyName>
-    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
     <FileAlignment>512</FileAlignment>
     <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\CSharp\</SolutionDir>
     <RestorePackages>true</RestorePackages>
+    <TargetFrameworkProfile />
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <DebugSymbols>true</DebugSymbols>
@@ -23,6 +24,7 @@
     <DefineConstants>DEBUG;TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
+    <Prefer32Bit>false</Prefer32Bit>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     <DebugType>pdbonly</DebugType>
@@ -31,6 +33,7 @@
     <DefineConstants>TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
+    <Prefer32Bit>false</Prefer32Bit>
   </PropertyGroup>
   <ItemGroup>
     <Reference Include="Microsoft.Practices.Prism, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
@@ -51,7 +54,7 @@
     <Folder Include="Properties\" />
   </ItemGroup>
   <ItemGroup>
-    <None Include="packages.config" />
+    <None Include="Packages.config" />
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <PropertyGroup>

+ 146 - 0
CSharp/ThirdParty/Enet/Address.cs

@@ -0,0 +1,146 @@
+#region License
+
+/*
+ENet for C#
+Copyright (c) 2011 James F. Bellinger <jfb@zer7.com>
+
+Permission to use, copy, modify, and/or distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*/
+
+#endregion
+
+using System;
+using System.Net;
+using System.Text;
+
+namespace ENet
+{
+	public unsafe struct Address : IEquatable<Address>
+	{
+		public const uint IPv4HostAny = Native.ENET_HOST_ANY;
+		public const uint IPv4HostBroadcast = Native.ENET_HOST_BROADCAST;
+
+		private Native.ENetAddress address;
+
+		public override bool Equals(object obj)
+		{
+			return obj is Address && this.Equals((Address) obj);
+		}
+
+		public bool Equals(Address address)
+		{
+			return this.Port == address.Port && Native.memcmp(this.GetHostBytes(), address.GetHostBytes());
+		}
+
+		public override int GetHashCode()
+		{
+			return Type.GetHashCode() ^ this.Port.GetHashCode() ^ this.IPv4Host.GetHashCode();
+		}
+
+		public byte[] GetHostBytes()
+		{
+			return BitConverter.GetBytes(IPAddress.NetworkToHostOrder((int) this.IPv4Host));
+		}
+
+		public string GetHostName()
+		{
+			var name = new byte[256];
+			fixed (byte* hostName = name)
+			{
+				if (Native.enet_address_get_host(ref this.address, hostName, (IntPtr) name.Length) < 0)
+				{
+					return null;
+				}
+			}
+			return BytesToString(name);
+		}
+
+		public string GetHostIP()
+		{
+			var ip = new byte[256];
+			fixed (byte* hostIP = ip)
+			{
+				if (Native.enet_address_get_host_ip(ref this.address, hostIP, (IntPtr) ip.Length) < 0)
+				{
+					return null;
+				}
+			}
+			return BytesToString(ip);
+		}
+
+		public bool SetHost(string hostName)
+		{
+			if (hostName == null)
+			{
+				throw new ArgumentNullException("hostName");
+			}
+			return Native.enet_address_set_host(ref this.address, Encoding.ASCII.GetBytes(hostName)) == 0;
+		}
+
+		private static string BytesToString(byte[] bytes)
+		{
+			try
+			{
+				return Encoding.ASCII.GetString(bytes, 0, Native.strlen(bytes));
+			}
+			catch
+			{
+				return null;
+			}
+		}
+
+		public Native.ENetAddress NativeData
+		{
+			get
+			{
+				return this.address;
+			}
+			set
+			{
+				this.address = value;
+			}
+		}
+
+		public uint IPv4Host
+		{
+			get
+			{
+				return this.address.host;
+			}
+			set
+			{
+				this.address.host = value;
+			}
+		}
+
+		public ushort Port
+		{
+			get
+			{
+				return this.address.port;
+			}
+			set
+			{
+				this.address.port = value;
+			}
+		}
+
+		public static AddressType Type
+		{
+			get
+			{
+				return AddressType.IPv4;
+			}
+		}
+	}
+}

+ 28 - 0
CSharp/ThirdParty/Enet/AddressType.cs

@@ -0,0 +1,28 @@
+#region License
+
+/*
+ENet for C#
+Copyright (c) 2011 James F. Bellinger <jfb@zer7.com>
+
+Permission to use, copy, modify, and/or distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*/
+
+#endregion
+
+namespace ENet
+{
+	public enum AddressType
+	{
+		IPv4 = 0
+	}
+}

+ 39 - 0
CSharp/ThirdParty/Enet/ENetException.cs

@@ -0,0 +1,39 @@
+#region License
+
+/*
+ENet for C#
+Copyright (c) 2011 James F. Bellinger <jfb@zer7.com>
+
+Permission to use, copy, modify, and/or distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*/
+
+#endregion
+
+using System;
+
+namespace ENet
+{
+	public class ENetException : Exception
+	{
+		public ENetException(int code, string message) : base(message)
+		{
+			this.Code = code;
+		}
+
+		public int Code
+		{
+			get;
+			private set;
+		}
+	}
+}

+ 66 - 0
CSharp/ThirdParty/Enet/Enet.csproj

@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{D0B4CFAC-A368-4742-9863-68776CFA9938}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>Enet</RootNamespace>
+    <AssemblyName>Enet</AssemblyName>
+    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Address.cs" />
+    <Compile Include="AddressType.cs" />
+    <Compile Include="ENetException.cs" />
+    <Compile Include="Event.cs" />
+    <Compile Include="EventType.cs" />
+    <Compile Include="Host.cs" />
+    <Compile Include="Library.cs" />
+    <Compile Include="Native.cs" />
+    <Compile Include="Native.Structs.cs" />
+    <Compile Include="Packet.cs" />
+    <Compile Include="PacketFlags.cs" />
+    <Compile Include="Peer.cs" />
+    <Compile Include="PeerState.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>

+ 85 - 0
CSharp/ThirdParty/Enet/Event.cs

@@ -0,0 +1,85 @@
+#region License
+
+/*
+ENet for C#
+Copyright (c) 2011 James F. Bellinger <jfb@zer7.com>
+
+Permission to use, copy, modify, and/or distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*/
+
+#endregion
+
+namespace ENet
+{
+	public unsafe struct Event
+	{
+		internal Native.ENetEvent e;
+
+		public Event(Native.ENetEvent e)
+		{
+			this.e = e;
+		}
+
+		public byte ChannelID
+		{
+			get
+			{
+				return this.e.channelID;
+			}
+		}
+
+		public uint Data
+		{
+			get
+			{
+				return this.e.data;
+			}
+		}
+
+		public Native.ENetEvent NativeData
+		{
+			get
+			{
+				return this.e;
+			}
+			set
+			{
+				this.e = value;
+			}
+		}
+
+		public Packet Packet
+		{
+			get
+			{
+				return new Packet(this.e.packet);
+			}
+		}
+
+		public Peer Peer
+		{
+			get
+			{
+				return new Peer(this.e.peer);
+			}
+		}
+
+		public EventType Type
+		{
+			get
+			{
+				return this.e.type;
+			}
+		}
+	}
+}

+ 31 - 0
CSharp/ThirdParty/Enet/EventType.cs

@@ -0,0 +1,31 @@
+#region License
+
+/*
+ENet for C#
+Copyright (c) 2011 James F. Bellinger <jfb@zer7.com>
+
+Permission to use, copy, modify, and/or distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*/
+
+#endregion
+
+namespace ENet
+{
+	public enum EventType
+	{
+		None = 0,
+		Connect = 1,
+		Disconnect = 2,
+		Receive = 3
+	}
+}

+ 228 - 0
CSharp/ThirdParty/Enet/Host.cs

@@ -0,0 +1,228 @@
+#region License
+
+/*
+ENet for C#
+Copyright (c) 2011 James F. Bellinger <jfb@zer7.com>
+
+Permission to use, copy, modify, and/or distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*/
+
+#endregion
+
+using System;
+
+namespace ENet
+{
+	public sealed unsafe class Host : IDisposable
+	{
+		private Native.ENetHost* host;
+
+		~Host()
+		{
+			this.Dispose(false);
+		}
+
+		private static void CheckChannelLimit(int channelLimit)
+		{
+			if (channelLimit < 0 || channelLimit > Native.ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT)
+			{
+				throw new ArgumentOutOfRangeException("channelLimit");
+			}
+		}
+
+		private void CheckCreated()
+		{
+			if (this.host == null)
+			{
+				throw new InvalidOperationException("Not created.");
+			}
+		}
+
+		public void Create(ushort port, int peerLimit)
+		{
+			var address = new Address {Port = port};
+			Create(address, peerLimit);
+		}
+
+		public void Create(Address? address, int peerLimit)
+		{
+			this.Create(address, peerLimit, 0);
+		}
+
+		public void Create(Address? address, int peerLimit, int channelLimit)
+		{
+			this.Create(address, peerLimit, channelLimit, 0, 0);
+		}
+
+		public void Create(Address? address, int peerLimit, int channelLimit, uint incomingBandwidth, uint outgoingBandwidth)
+		{
+			if (this.host != null)
+			{
+				throw new InvalidOperationException("Already created.");
+			}
+			if (peerLimit < 0 || peerLimit > Native.ENET_PROTOCOL_MAXIMUM_PEER_ID)
+			{
+				throw new ArgumentOutOfRangeException("peerLimit");
+			}
+			CheckChannelLimit(channelLimit);
+
+			if (address != null)
+			{
+				Native.ENetAddress nativeAddress = address.Value.NativeData;
+				this.host = Native.enet_host_create(ref nativeAddress, (IntPtr) peerLimit, 
+					(IntPtr) channelLimit, incomingBandwidth, outgoingBandwidth);
+			}
+			else
+			{
+				this.host = Native.enet_host_create(
+					null, (IntPtr) peerLimit, (IntPtr) channelLimit, 
+					incomingBandwidth, outgoingBandwidth);
+			}
+			if (this.host == null)
+			{
+				throw new ENetException(0, "Host creation call failed.");
+			}
+		}
+
+		public void Dispose()
+		{
+			this.Dispose(true);
+		}
+
+		private void Dispose(bool disposing)
+		{
+			if (this.host == null)
+			{
+				return;
+			}
+			Native.enet_host_destroy(this.host);
+			this.host = null;
+		}
+
+		public void Broadcast(byte channelID, ref Packet packet)
+		{
+			this.CheckCreated();
+			packet.CheckCreated();
+			Native.enet_host_broadcast(this.host, channelID, packet.NativeData);
+			packet.NativeData = null; // Broadcast automatically clears this.
+		}
+
+		public void CompressWithRangeEncoder()
+		{
+			this.CheckCreated();
+			Native.enet_host_compress_with_range_encoder(this.host);
+		}
+
+		public void DoNotCompress()
+		{
+			this.CheckCreated();
+			Native.enet_host_compress(this.host, null);
+		}
+
+		public int CheckEvents(out Event e)
+		{
+			this.CheckCreated();
+			Native.ENetEvent nativeEvent;
+			int ret = Native.enet_host_check_events(this.host, out nativeEvent);
+			if (ret <= 0)
+			{
+				e = new Event();
+				return ret;
+			}
+			e = new Event(nativeEvent);
+			return ret;
+		}
+
+		public Peer Connect(Address address, int channelLimit, uint data)
+		{
+			this.CheckCreated();
+			CheckChannelLimit(channelLimit);
+
+			Native.ENetAddress nativeAddress = address.NativeData;
+			var peer = new Peer(Native.enet_host_connect(this.host, ref nativeAddress, (IntPtr) channelLimit, data));
+			if (peer.NativeData == null)
+			{
+				throw new ENetException(0, "Host connect call failed.");
+			}
+			return peer;
+		}
+
+		public void Flush()
+		{
+			this.CheckCreated();
+			Native.enet_host_flush(this.host);
+		}
+
+		public int Service(int timeout)
+		{
+			if (timeout < 0)
+			{
+				throw new ArgumentOutOfRangeException("timeout");
+			}
+			this.CheckCreated();
+			return Native.enet_host_service(this.host, null, (uint) timeout);
+		}
+
+		public int Service(int timeout, out Event e)
+		{
+			if (timeout < 0)
+			{
+				throw new ArgumentOutOfRangeException("timeout");
+			}
+			this.CheckCreated();
+			Native.ENetEvent nativeEvent;
+
+			int ret = Native.enet_host_service(this.host, out nativeEvent, (uint) timeout);
+			if (ret <= 0)
+			{
+				e = new Event();
+				return ret;
+			}
+			e = new Event(nativeEvent);
+			return ret;
+		}
+
+		public void SetBandwidthLimit(uint incomingBandwidth, uint outgoingBandwidth)
+		{
+			this.CheckCreated();
+			Native.enet_host_bandwidth_limit(this.host, incomingBandwidth, outgoingBandwidth);
+		}
+
+		public void SetChannelLimit(int channelLimit)
+		{
+			CheckChannelLimit(channelLimit);
+			this.CheckCreated();
+			Native.enet_host_channel_limit(this.host, (IntPtr) channelLimit);
+		}
+
+		public bool IsSet
+		{
+			get
+			{
+				return this.host != null;
+			}
+		}
+
+		public Native.ENetHost* NativeData
+		{
+			get
+			{
+				return this.host;
+			}
+			set
+			{
+				this.host = value;
+			}
+		}
+	}
+}

+ 53 - 0
CSharp/ThirdParty/Enet/Library.cs

@@ -0,0 +1,53 @@
+#region License
+
+/*
+ENet for C#
+Copyright (c) 2011 James F. Bellinger <jfb@zer7.com>
+
+Permission to use, copy, modify, and/or distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*/
+
+#endregion
+
+namespace ENet
+{
+	public static class Library
+	{
+		public static void Initialize()
+		{
+			var inits = new Native.ENetCallbacks();
+			int ret = Native.enet_initialize_with_callbacks(Native.ENET_VERSION, ref inits);
+			if (ret < 0)
+			{
+				throw new ENetException(ret, "Initialization failed.");
+			}
+		}
+
+		public static void Deinitialize()
+		{
+			Native.enet_deinitialize();
+		}
+
+		public static uint Time
+		{
+			get
+			{
+				return Native.enet_time_get();
+			}
+			set
+			{
+				Native.enet_time_set(value);
+			}
+		}
+	}
+}

+ 118 - 0
CSharp/ThirdParty/Enet/Native.Structs.cs

@@ -0,0 +1,118 @@
+#region License
+
+/*
+ENet for C#
+Copyright (c) 2011 James F. Bellinger <jfb@zer7.com>
+
+Permission to use, copy, modify, and/or distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*/
+
+#endregion
+
+using System;
+using System.Runtime.InteropServices;
+
+namespace ENet
+{
+	public static unsafe partial class Native
+	{
+		[StructLayout(LayoutKind.Sequential)]
+		public struct ENetAddress
+		{
+			public uint host;
+			public ushort port;
+		}
+
+		[StructLayout(LayoutKind.Sequential)]
+		public struct ENetCallbacks
+		{
+			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+			public delegate IntPtr malloc_cb(IntPtr size);
+
+			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+			public delegate void free_cb(IntPtr memory);
+
+			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+			public delegate void no_memory_cb();
+
+			public IntPtr malloc, free, no_memory;
+		}
+
+		[StructLayout(LayoutKind.Sequential)]
+		public struct ENetCompressor
+		{
+			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+			public delegate void compress_cb(
+					IntPtr context, IntPtr inBuffers, IntPtr inBufferCount, IntPtr inLimit, IntPtr outData, IntPtr outLimit);
+
+			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+			public delegate void decompress_cb(IntPtr context, IntPtr inData, IntPtr inLimit, IntPtr outData, IntPtr outLimit);
+
+			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+			public delegate void destroy_cb(IntPtr context);
+
+			public IntPtr context;
+			public IntPtr compress, decompress, destroy;
+		}
+
+		[StructLayout(LayoutKind.Sequential)]
+		public struct ENetEvent
+		{
+			public readonly EventType type;
+			public readonly ENetPeer* peer;
+			public readonly byte channelID;
+			public readonly uint data;
+			public readonly ENetPacket* packet;
+		}
+
+		[StructLayout(LayoutKind.Sequential)]
+		public struct ENetHost
+		{
+		}
+
+		[StructLayout(LayoutKind.Sequential)]
+		public struct ENetListNode
+		{
+			public readonly ENetListNode* next;
+			public readonly ENetListNode* previous;
+		}
+
+		[StructLayout(LayoutKind.Sequential)]
+		public struct ENetPacket
+		{
+			[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+			public delegate void freeCallback_cb(IntPtr packet);
+
+			public IntPtr referenceCount;
+			public readonly PacketFlags flags;
+			public readonly void* data;
+			public IntPtr dataLength;
+			public IntPtr freeCallback;
+		}
+
+		[StructLayout(LayoutKind.Sequential)]
+		public struct ENetPeer
+		{
+			public ENetListNode dispatchList;
+			public readonly ENetHost* host;
+			public readonly ushort outgoingPeerID;
+			public readonly ushort incomingPeerID;
+			public readonly uint connectID;
+			public readonly byte outgoingSessionID;
+			public readonly byte incomingSessionID;
+			public ENetAddress address;
+			public IntPtr data;
+			public readonly PeerState state;
+		}
+	}
+}

+ 215 - 0
CSharp/ThirdParty/Enet/Native.cs

@@ -0,0 +1,215 @@
+#region License
+
+/*
+ENet for C#
+Copyright (c) 2011 James F. Bellinger <jfb@zer7.com>
+
+Permission to use, copy, modify, and/or distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*/
+
+#endregion
+
+using System;
+using System.Runtime.InteropServices;
+
+namespace ENet
+{
+	public static unsafe partial class Native
+	{
+		private const string LIB = "ENet.dll";
+
+		public const int ENET_PEER_PACKET_THROTTLE_SCALE = 32;
+		public const int ENET_PEER_PACKET_THROTTLE_ACCELERATION = 2;
+		public const int ENET_PEER_PACKET_THROTTLE_DECELERATION = 2;
+		public const int ENET_PEER_PACKET_THROTTLE_INTERVAL = 5000;
+		public const int ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT = 0x01;
+		public const int ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT = 0xff;
+		public const int ENET_PROTOCOL_MAXIMUM_PEER_ID = 0xfff;
+		public const uint ENET_VERSION = (1 << 16) | (3 << 8) | (1);
+		public const uint ENET_HOST_ANY = 0;
+		public const uint ENET_HOST_BROADCAST = 0xffffffff;
+
+		#region Address Functions
+
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
+		public static extern int enet_address_set_host(ref ENetAddress address, byte* hostName);
+
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
+		public static extern int enet_address_set_host(ref ENetAddress address, byte[] hostName);
+
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
+		public static extern int enet_address_get_host(ref ENetAddress address, byte* hostName, IntPtr nameLength);
+
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
+		public static extern int enet_address_get_host(ref ENetAddress address, byte[] hostName, IntPtr nameLength);
+
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
+		public static extern int enet_address_get_host_ip(ref ENetAddress address, byte* hostIP, IntPtr ipLength);
+
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
+		public static extern int enet_address_get_host_ip(ref ENetAddress address, byte[] hostIP, IntPtr ipLength);
+
+		#endregion
+
+		#region Global Functions
+
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
+		public static extern void enet_deinitialize();
+
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
+		public static extern int enet_initialize();
+
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
+		public static extern int enet_initialize_with_callbacks(uint version, ref ENetCallbacks inits);
+
+		#endregion
+
+		#region Host Functions
+
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
+		public static extern int enet_host_compress_with_range_encoder(ENetHost* host);
+
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
+		public static extern ENetHost* enet_host_create(
+				ENetAddress* address, IntPtr peerLimit, IntPtr channelLimit, uint incomingBandwidth, uint outgoingBandwidth);
+
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
+		public static extern ENetHost* enet_host_create(
+				ref ENetAddress address, IntPtr peerLimit, IntPtr channelLimit, uint incomingBandwidth, uint outgoingBandwidth);
+
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
+		public static extern void enet_host_destroy(ENetHost* host);
+
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
+		public static extern ENetPeer* enet_host_connect(
+				ENetHost* host, ref ENetAddress address, IntPtr channelCount, uint data);
+
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
+		public static extern void enet_host_broadcast(ENetHost* host, byte channelID, ENetPacket* packet);
+
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
+		public static extern void enet_host_compress(ENetHost* host, ENetCompressor* compressor);
+
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
+		public static extern void enet_host_channel_limit(ENetHost* host, IntPtr channelLimit);
+
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
+		public static extern void enet_host_bandwidth_limit(ENetHost* host, uint incomingBandwidth, uint outgoingBandwidth);
+
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
+		public static extern void enet_host_flush(ENetHost* host);
+
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
+		public static extern int enet_host_check_events(ENetHost* host, out ENetEvent @event);
+
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
+		public static extern int enet_host_service(ENetHost* host, ENetEvent* @event, uint timeout);
+
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
+		public static extern int enet_host_service(ENetHost* host, out ENetEvent @event, uint timeout);
+
+		#endregion
+
+		#region Miscellaneous Functions
+
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
+		public static extern uint enet_time_get();
+
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
+		public static extern void enet_time_set(uint newTimeBase);
+
+		#endregion
+
+		#region Packet Functions
+
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
+		public static extern ENetPacket* enet_packet_create(void* data, IntPtr dataLength, PacketFlags flags);
+
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
+		public static extern void enet_packet_destroy(ENetPacket* packet);
+
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
+		public static extern int enet_packet_resize(ENetPacket* packet, IntPtr dataLength);
+
+		#endregion
+
+		#region Peer Functions
+
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
+		public static extern void enet_peer_throttle_configure(
+				ENetPeer* peer, uint interval, uint acceleration, uint deceleration);
+
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
+		public static extern int enet_peer_send(ENetPeer* peer, byte channelID, ENetPacket* packet);
+
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
+		public static extern ENetPacket* enet_peer_receive(ENetPeer* peer, out byte channelID);
+
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
+		public static extern void enet_peer_reset(ENetPeer* peer);
+
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
+		public static extern void enet_peer_ping(ENetPeer* peer);
+
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
+		public static extern void enet_peer_disconnect_now(ENetPeer* peer, uint data);
+
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
+		public static extern void enet_peer_disconnect(ENetPeer* peer, uint data);
+
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
+		public static extern void enet_peer_disconnect_later(ENetPeer* peer, uint data);
+
+		#endregion
+
+		#region C# Utility
+
+		public static bool memcmp(byte[] s1, byte[] s2)
+		{
+			if (s1 == null || s2 == null)
+			{
+				throw new ArgumentNullException();
+			}
+			if (s1.Length != s2.Length)
+			{
+				return false;
+			}
+
+			for (int i = 0; i < s1.Length; i++)
+			{
+				if (s1[i] != s2[i])
+				{
+					return false;
+				}
+			}
+			return true;
+		}
+
+		public static int strlen(byte[] s)
+		{
+			if (s == null)
+			{
+				throw new ArgumentNullException();
+			}
+
+			int i;
+			for (i = 0; i < s.Length && s[i] != 0; i++)
+			{
+				;
+			}
+			return i;
+		}
+
+		#endregion
+	}
+}

+ 191 - 0
CSharp/ThirdParty/Enet/Packet.cs

@@ -0,0 +1,191 @@
+#region License
+
+/*
+ENet for C#
+Copyright (c) 2011 James F. Bellinger <jfb@zer7.com>
+
+Permission to use, copy, modify, and/or distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*/
+
+#endregion
+
+using System;
+using System.Runtime.InteropServices;
+
+namespace ENet
+{
+	public unsafe struct Packet : IDisposable
+	{
+		private Native.ENetPacket* packet;
+
+		public Packet(Native.ENetPacket* packet)
+		{
+			this.packet = packet;
+		}
+
+		internal void CheckCreated()
+		{
+			if (this.packet == null)
+			{
+				throw new InvalidOperationException("No native packet.");
+			}
+		}
+
+		public void Create(byte[] data)
+		{
+			if (data == null)
+			{
+				throw new ArgumentNullException("data");
+			}
+			Create(data, 0, data.Length);
+		}
+
+		public void Create(byte[] data, int offset, int length, PacketFlags flags = PacketFlags.None)
+		{
+			if (data == null)
+			{
+				throw new ArgumentNullException("data");
+			}
+			if (offset < 0 || length < 0 || length > data.Length - offset)
+			{
+				throw new ArgumentOutOfRangeException();
+			}
+			fixed (byte* bytes = data)
+			{
+				Create(bytes + offset, length, flags);
+			}
+		}
+
+		public void Create(void* data, int length, PacketFlags flags)
+		{
+			if (this.packet != null)
+			{
+				throw new InvalidOperationException("Already created.");
+			}
+
+			this.packet = Native.enet_packet_create(data, (IntPtr) length, flags);
+			if (this.packet == null)
+			{
+				throw new ENetException(0, "Packet creation call failed.");
+			}
+		}
+
+		public void CopyTo(byte[] array)
+		{
+			if (array == null)
+			{
+				throw new ArgumentNullException("array");
+			}
+			this.CopyTo(array, 0, array.Length);
+		}
+
+		public void CopyTo(byte[] array, int offset, int length)
+		{
+			if (array == null)
+			{
+				throw new ArgumentNullException("array");
+			}
+			if (offset < 0 || length < 0 || length > array.Length - offset)
+			{
+				throw new ArgumentOutOfRangeException();
+			}
+
+			this.CheckCreated();
+			if (length > this.Length - offset)
+			{
+				throw new ArgumentOutOfRangeException();
+			}
+			if (length > 0)
+			{
+				Marshal.Copy((IntPtr) ((byte*) this.Data + offset), array, offset, length);
+			}
+		}
+
+		public byte[] GetBytes()
+		{
+			this.CheckCreated();
+			var array = new byte[this.Length];
+			this.CopyTo(array);
+			return array;
+		}
+
+		public void Dispose()
+		{
+			if (this.packet == null)
+			{
+				return;
+			}
+			if (this.packet->referenceCount == IntPtr.Zero)
+			{
+				Native.enet_packet_destroy(this.packet);
+			}
+			this.packet = null;
+		}
+
+		public void Resize(int length)
+		{
+			if (length < 0)
+			{
+				throw new ArgumentOutOfRangeException("length");
+			}
+			this.CheckCreated();
+			int ret = Native.enet_packet_resize(this.packet, (IntPtr) length);
+			if (ret < 0)
+			{
+				throw new ENetException(ret, "Packet resize call failed.");
+			}
+		}
+
+		public void* Data
+		{
+			get
+			{
+				this.CheckCreated();
+				return this.packet->data;
+			}
+		}
+
+		public int Length
+		{
+			get
+			{
+				this.CheckCreated();
+				if (this.packet->dataLength.ToPointer() > (void*) int.MaxValue)
+				{
+					throw new ENetException(0, "Packet too long!");
+				}
+				return (int) this.packet->dataLength;
+			}
+		}
+
+		public Native.ENetPacket* NativeData
+		{
+			get
+			{
+				return this.packet;
+			}
+			set
+			{
+				this.packet = value;
+			}
+		}
+
+		public bool IsSet
+		{
+			get
+			{
+				return this.packet != null;
+			}
+		}
+	}
+}

+ 34 - 0
CSharp/ThirdParty/Enet/PacketFlags.cs

@@ -0,0 +1,34 @@
+#region License
+
+/*
+ENet for C#
+Copyright (c) 2011 James F. Bellinger <jfb@zer7.com>
+
+Permission to use, copy, modify, and/or distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*/
+
+#endregion
+
+using System;
+
+namespace ENet
+{
+	[Flags]
+	public enum PacketFlags
+	{
+		None = 0,
+		Reliable = 1 << 0,
+		Unsequenced = 1 << 1,
+		NoAllocate = 1 << 2
+	}
+}

+ 163 - 0
CSharp/ThirdParty/Enet/Peer.cs

@@ -0,0 +1,163 @@
+#region License
+
+/*
+ENet for C#
+Copyright (c) 2011 James F. Bellinger <jfb@zer7.com>
+
+Permission to use, copy, modify, and/or distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*/
+
+#endregion
+
+using System;
+
+namespace ENet
+{
+	public unsafe struct Peer
+	{
+		private Native.ENetPeer* peer;
+
+		public Peer(Native.ENetPeer* peer)
+		{
+			this.peer = peer;
+		}
+
+		private void CheckCreated()
+		{
+			if (this.peer == null)
+			{
+				throw new InvalidOperationException("No native peer.");
+			}
+		}
+
+		public void ConfigureThrottle(uint interval, uint acceleration, uint deceleration)
+		{
+			this.CheckCreated();
+			Native.enet_peer_throttle_configure(this.peer, interval, acceleration, deceleration);
+		}
+
+		public void Disconnect(uint data)
+		{
+			this.CheckCreated();
+			Native.enet_peer_disconnect(this.peer, data);
+		}
+
+		public void DisconnectLater(uint data)
+		{
+			this.CheckCreated();
+			Native.enet_peer_disconnect_later(this.peer, data);
+		}
+
+		public void DisconnectNow(uint data)
+		{
+			this.CheckCreated();
+			Native.enet_peer_disconnect_now(this.peer, data);
+		}
+
+		public void Ping()
+		{
+			this.CheckCreated();
+			Native.enet_peer_ping(this.peer);
+		}
+
+		public void Reset()
+		{
+			this.CheckCreated();
+			Native.enet_peer_reset(this.peer);
+		}
+
+		public bool Receive(out byte channelID, out Packet packet)
+		{
+			this.CheckCreated();
+			Native.ENetPacket* nativePacket = Native.enet_peer_receive(this.peer, out channelID);
+			if (nativePacket == null)
+			{
+				packet = new Packet();
+				return false;
+			}
+			packet = new Packet(nativePacket);
+			return true;
+		}
+
+		public void Send(byte channelID, byte[] data)
+		{
+			if (data == null)
+			{
+				throw new ArgumentNullException("data");
+			}
+			this.Send(channelID, data, 0, data.Length);
+		}
+
+		public void Send(byte channelID, byte[] data, int offset, int length)
+		{
+			if (data == null)
+			{
+				throw new ArgumentNullException("data");
+			}
+			using (var packet = new Packet())
+			{
+				packet.Create(data, offset, length);
+				this.Send(channelID, packet);
+			}
+		}
+
+		public void Send(byte channelID, Packet packet)
+		{
+			this.CheckCreated();
+			packet.CheckCreated();
+			Native.enet_peer_send(this.peer, channelID, packet.NativeData);
+		}
+
+		public bool IsSet
+		{
+			get
+			{
+				return this.peer != null;
+			}
+		}
+
+		public Native.ENetPeer* NativeData
+		{
+			get
+			{
+				return this.peer;
+			}
+			set
+			{
+				this.peer = value;
+			}
+		}
+
+		public PeerState State
+		{
+			get
+			{
+				return this.IsSet? this.peer->state : PeerState.Uninitialized;
+			}
+		}
+
+		public IntPtr UserData
+		{
+			get
+			{
+				this.CheckCreated();
+				return this.peer->data;
+			}
+			set
+			{
+				this.CheckCreated();
+				this.peer->data = value;
+			}
+		}
+	}
+}

+ 17 - 0
CSharp/ThirdParty/Enet/PeerState.cs

@@ -0,0 +1,17 @@
+namespace ENet
+{
+	public enum PeerState
+	{
+		Uninitialized = -1,
+		Disconnected = 0,
+		Connecting = 1,
+		AcknowledgingConnect = 2,
+		ConnectionPending = 3,
+		ConnectionSucceeded = 4,
+		Connected = 5,
+		DisconnectLater = 6,
+		Disconnecting = 7,
+		AcknowledgingDisconnect = 8,
+		Zombie = 9
+	}
+}