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

1.增加Character类
2.hook库修改,更新easyhook到2.7

tanghai 12 лет назад
Родитель
Сommit
44660ee794

+ 11 - 0
CSharp/Game/Component/Character.cs

@@ -0,0 +1,11 @@
+
+namespace Component
+{
+	/// <summary>
+	/// 角色对象
+	/// </summary>
+	public class Character: GameObject
+	{
+
+	}
+}

+ 1 - 0
CSharp/Game/Component/Component.csproj

@@ -41,6 +41,7 @@
   <ItemGroup>
     <Compile Include="Buff.cs" />
     <Compile Include="BuffManager.cs" />
+    <Compile Include="Character.cs" />
     <Compile Include="GameObject.cs" />
     <Compile Include="ConfigAttribute.cs" />
     <Compile Include="ConfigCategory.cs" />

BIN
CSharp/Lib/EasyHook.dll


BIN
CSharp/Lib/EasyHook32.dll


BIN
CSharp/Lib/EasyHook64.dll


BIN
CSharp/Lib/EasyHook64Svc.exe


BIN
CSharp/Lib/detours.lib


+ 47 - 47
CSharp/Platform/ENetTest/ENetClientServerTest.cs

@@ -1,17 +1,17 @@
 using System.Diagnostics;
-using System.Threading;
-using ENet;
+using System.Threading;
+using ENet;
 using Helper;
 using Log;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace ENetCSTest
-{
-	[TestClass]
-	public class ENetClientServerTest
-	{
-		private const int pingPangCount = 1000;
-		private static async void ClientEvent(EService service, string hostName, ushort port)
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace ENetCSTest
+{
+	[TestClass]
+	public class ENetClientServerTest
+	{
+		private const int pingPangCount = 1000;
+		private static async void ClientEvent(EService service, string hostName, ushort port)
 		{
 			var eSocket = new ESocket(service);
 			await eSocket.ConnectAsync(hostName, port);
@@ -27,12 +27,12 @@ namespace ENetCSTest
 			}
 			stopWatch.Stop();
 			Logger.Debug("time: {0}", stopWatch.ElapsedMilliseconds);
-			await eSocket.DisconnectAsync();
-			service.Stop();
-		}
-
-		private static async void ServerEvent(EService service, Barrier barrier)
-		{
+			await eSocket.DisconnectAsync();
+			service.Stop();
+		}
+
+		private static async void ServerEvent(EService service, Barrier barrier)
+		{
 			barrier.SignalAndWait();
 			var eSocket = new ESocket(service);
 			await eSocket.AcceptAsync();
@@ -47,34 +47,34 @@ namespace ENetCSTest
 
 				eSocket.WriteAsync("9876543210".ToByteArray());
 			}
-		}
-
-		[TestMethod]
-		public void ClientSendToServer()
-		{
-			const string hostName = "127.0.0.1";
-			const ushort port = 8888;
-			var clientHost = new EService();
-			var serverHost = new EService(hostName, port);
-
-			var serverThread = new Thread(() => serverHost.Start(10));
-			var clientThread = new Thread(() => clientHost.Start(10));
-
-			serverThread.Start();
-			clientThread.Start();
-
-			var barrier = new Barrier(2);
-
-			// 往server host线程增加事件,accept
-			serverHost.Events += () => ServerEvent(serverHost, barrier);
-
-			barrier.SignalAndWait();
-
-			// 往client host线程增加事件,client线程连接server
-			clientHost.Events += () => ClientEvent(clientHost, hostName, port);
-
-			serverThread.Join();
-			clientThread.Join();
-		}
-	}
+		}
+
+		[TestMethod]
+		public void ClientSendToServer()
+		{
+			const string hostName = "127.0.0.1";
+			const ushort port = 8888;
+			var clientHost = new EService();
+			var serverHost = new EService(hostName, port);
+
+			var serverThread = new Thread(() => serverHost.Start(10));
+			var clientThread = new Thread(() => clientHost.Start(10));
+
+			serverThread.Start();
+			clientThread.Start();
+
+			var barrier = new Barrier(2);
+
+			// 往server host线程增加事件,accept
+			serverHost.Events += () => ServerEvent(serverHost, barrier);
+
+			barrier.SignalAndWait();
+
+			// 往client host线程增加事件,client线程连接server
+			clientHost.Events += () => ClientEvent(clientHost, hostName, port);
+
+			serverThread.Join();
+			clientThread.Join();
+		}
+	}
 }

+ 1 - 6
CSharp/Platform/Hooks/Hooks.csproj

@@ -36,16 +36,11 @@
     <Reference Include="EasyHook">
       <HintPath>..\..\Lib\EasyHook.dll</HintPath>
     </Reference>
-    <Reference Include="NLog, Version=2.0.1.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
-      <SpecificVersion>False</SpecificVersion>
-      <HintPath>..\..\packages\NLog.2.0.1.2\lib\net45\NLog.dll</HintPath>
-    </Reference>
     <Reference Include="System" />
     <Reference Include="System.Core" />
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="RecvHook.cs" />
-    <Compile Include="SendHook.cs" />
+    <Compile Include="Native.cs" />
   </ItemGroup>
   <ItemGroup>
     <Folder Include="Properties\" />

+ 22 - 0
CSharp/Platform/Hooks/Native.cs

@@ -0,0 +1,22 @@
+using System;
+using System.Runtime.InteropServices;
+
+namespace Hooks
+{
+	[UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, 
+		SetLastError = true)]
+	public delegate int DRecv(IntPtr handle, IntPtr buf, int count, int flag);
+
+	[UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode,
+		SetLastError = true)]
+	public delegate int DSend(IntPtr handle, IntPtr buf, int count, int flag);
+
+	public static class Native
+	{
+		[DllImport("Ws2_32.dll", EntryPoint = "recv")]
+		public static extern int Recv(IntPtr handle, IntPtr buf, int count, int flag);
+
+		[DllImport("Ws2_32.dll", EntryPoint = "send")]
+		public static extern int Send(IntPtr handle, IntPtr buf, int count, int flag);
+	}
+}

+ 0 - 55
CSharp/Platform/Hooks/RecvHook.cs

@@ -1,55 +0,0 @@
-using System;
-using System.Runtime.InteropServices;
-using EasyHook;
-using Log;
-
-namespace Hooks
-{
-	[UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, 
-		SetLastError = true)]
-	public delegate int DRecv(IntPtr handle, IntPtr buf, int count, int flag);
-
-	public class RecvHook: IDisposable
-	{
-		[DllImport("Ws2_32.dll", EntryPoint = "recv")]
-		public static extern int Recv(IntPtr handle, IntPtr buf, int count, int flag);
-
-		private readonly LocalHook localHook;
-
-		public RecvHook(DRecv dRecv)
-		{
-			try
-			{
-				this.localHook = LocalHook.Create(
-					LocalHook.GetProcAddress("Ws2_32.dll", "recv"), new DRecv(dRecv), this);
-				this.localHook.ThreadACL.SetInclusiveACL(new[] { 0 });
-			}
-			catch (Exception)
-			{
-				Logger.Debug("Error creating recv Hook");
-				throw;
-			}
-		}
-
-		public void Dispose()
-		{
-			this.localHook.Dispose();
-		}
-
-		//static int RecvHooked(IntPtr socketHandle, IntPtr buf, int count, int socketFlags)
-		//{
-		//	int bytesCount = recv(socketHandle, buf, count, socketFlags);
-		//	if (bytesCount > 0)
-		//	{
-		//		var newBuffer = new byte[bytesCount];
-		//		Marshal.Copy(buf, newBuffer, 0, bytesCount);
-		//		string s = Encoding.ASCII.GetString(newBuffer);
-		//		TextWriter tw = new StreamWriter("recv.txt");
-		//		tw.Write(s);
-		//		tw.Close();
-		//		Logger.Debug(string.Format("Hooked:>{0}", s));
-		//	}
-		//	return bytesCount;
-		//}
-	}
-}

+ 0 - 39
CSharp/Platform/Hooks/SendHook.cs

@@ -1,39 +0,0 @@
-using System;
-using System.Runtime.InteropServices;
-using EasyHook;
-using Log;
-
-namespace Hooks
-{
-	[UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, 
-		SetLastError = true)]
-	public delegate int DSend(IntPtr handle, IntPtr buf, int count, int flag);
-
-	public class SendHook: IDisposable
-	{
-		[DllImport("Ws2_32.dll", EntryPoint = "send")]
-		public static extern int Send(IntPtr handle, IntPtr buf, int count, int flag);
-
-		private readonly LocalHook localHook;
-
-		public SendHook(DSend dSend)
-		{
-			try
-			{
-				this.localHook = LocalHook.Create(
-						LocalHook.GetProcAddress("Ws2_32.dll", "send"), new DSend(dSend), this);
-				this.localHook.ThreadACL.SetInclusiveACL(new[] { 0 });
-			}
-			catch (Exception)
-			{
-				Logger.Debug("Error creating send Hook");
-				throw;
-			}
-		}
-
-		public void Dispose()
-		{
-			this.localHook.Dispose();
-		}
-	}
-}