Explorar el Código

修复ILRT模式运行错误,还有些小问题,不太影响,下周修复

tanghai hace 7 años
padre
commit
ce551d4426

+ 1 - 1
Client-Server.sln

@@ -1,7 +1,7 @@
 
 Microsoft Visual Studio Solution File, Format Version 12.00
 # Visual Studio 15
-VisualStudioVersion = 15.0.27130.2036
+VisualStudioVersion = 15.0.27130.2027
 MinimumVisualStudioVersion = 10.0.40219.1
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity.Plugins", "Unity\Unity.Plugins.csproj", "{D1FDB199-0FB7-099D-3771-C6A942E4E326}"
 EndProject

+ 2 - 1
Unity/Assets/Editor/Proto2CsEditor/Proto2CSEditor.cs

@@ -16,6 +16,7 @@ namespace MyEditor
 	[Flags]
 	public enum HeadFlag
 	{
+		None = 0,
 		Bson = 1,
 		Proto = 2,
 	}
@@ -41,7 +42,7 @@ namespace MyEditor
 			GenerateOpcode("OuterOpcode", serverMessagePath);
 
 			msgOpcode.Clear();
-			Proto2CS("ETHotfix", "HotfixMessage.proto", hotfixMessagePath, "HotfixOpcode", 10000, HeadFlag.Proto);
+			Proto2CS("ETHotfix", "HotfixMessage.proto", hotfixMessagePath, "HotfixOpcode", 10000, HeadFlag.None);
 			GenerateOpcode("HotfixOpcode", hotfixMessagePath);
 
 			msgOpcode.Clear();

+ 5 - 2
Unity/Assets/Scripts/Helper/ILHelper.cs

@@ -2,6 +2,7 @@
 using System.Collections.Generic;
 using System.Reflection;
 using ILRuntime.CLR.Method;
+using ILRuntime.CLR.TypeSystem;
 using ILRuntime.Runtime.Enviorment;
 using ILRuntime.Runtime.Generated;
 using ILRuntime.Runtime.Intepreter;
@@ -20,8 +21,10 @@ namespace ETModel
 			appDomain.DelegateManager.RegisterMethodDelegate<AChannel, System.Net.Sockets.SocketError>();
 			appDomain.DelegateManager.RegisterMethodDelegate<byte[], int, int>();
 			appDomain.DelegateManager.RegisterMethodDelegate<IResponse>();
-			appDomain.DelegateManager.RegisterMethodDelegate<Session, PacketInfo>();
-			appDomain.DelegateManager.RegisterMethodDelegate<Session, uint, object>();
+			appDomain.DelegateManager.RegisterMethodDelegate<Session, object>();
+			appDomain.DelegateManager.RegisterMethodDelegate<Session, Packet>();
+			appDomain.DelegateManager.RegisterMethodDelegate<Session>();
+			appDomain.DelegateManager.RegisterMethodDelegate<ILTypeInstance>();
 
 			CLRBindings.Initialize(appDomain);
 

+ 7 - 9
Unity/Assets/Scripts/Module/Message/IMessage.cs

@@ -3,15 +3,6 @@
 // 不要在这个文件加[ProtoInclude]跟[BsonKnowType]标签,加到InnerMessage.cs或者OuterMessage.cs里面去
 namespace ETModel
 {
-	public struct PacketInfo
-	{
-		public ushort Opcode;
-		public uint RpcId;
-		public byte[] Bytes;
-		public ushort Index;
-		public ushort Length;
-	}
-
 	[ProtoContract]
 	public partial class MessageObject
 	{
@@ -32,4 +23,11 @@ namespace ETModel
 		string Message { get; set; }
 		int RpcId { get; set; }
 	}
+
+	public class ResponseMessage: IResponse
+	{
+		public int Error { get; set; }
+		public string Message { get; set; }
+		public int RpcId { get; set; }
+	}
 }

+ 26 - 30
Unity/Assets/Scripts/Module/Message/Session.cs

@@ -65,7 +65,7 @@ namespace ETModel
 
 			foreach (Action<IResponse> action in this.requestCallback.Values.ToArray())
 			{
-				action.Invoke(null);
+				action.Invoke(new ResponseMessage { Error = ErrorCode.ERR_SocketDisconnected });
 			}
 
 			this.channel.Dispose();
@@ -142,31 +142,31 @@ namespace ETModel
 				this.Network.MessageDispatcher.Dispatch(this, packet);
 				return;
 			}
-			
-			// flag第一位为1表示这是rpc返回消息
-			if ((flag & 0x01) > 0)
-			{
-				OpcodeTypeComponent opcodeTypeComponent = this.Network.Entity.GetComponent<OpcodeTypeComponent>();
-				Type responseType = opcodeTypeComponent.GetType(opcode);
-				object message = this.Network.MessagePacker.DeserializeFrom(responseType, packet.Bytes, Packet.Index, packet.Length - Packet.Index);
-
-				IResponse response = message as IResponse;
-				if (response == null)
-				{
-					throw new Exception($"flag is response, but message is not! {opcode}");
-				}
-				Action<IResponse> action;
-				if (!this.requestCallback.TryGetValue(response.RpcId, out action))
-				{
-					return;
-				}
-				this.requestCallback.Remove(response.RpcId);
 
-				action(response);
+			// flag第一位为1表示这是rpc返回消息,否则交由MessageDispatcher分发
+			if ((flag & 0x01) == 0)
+			{
+				this.Network.MessageDispatcher.Dispatch(this, packet);
 				return;
 			}
 			
-			this.Network.MessageDispatcher.Dispatch(this, packet);
+			OpcodeTypeComponent opcodeTypeComponent = this.Network.Entity.GetComponent<OpcodeTypeComponent>();
+			Type responseType = opcodeTypeComponent.GetType(opcode);
+			object message = this.Network.MessagePacker.DeserializeFrom(responseType, packet.Bytes, Packet.Index, packet.Length - Packet.Index);
+
+			IResponse response = message as IResponse;
+			if (response == null)
+			{
+				throw new Exception($"flag is response, but message is not! {opcode}");
+			}
+			Action<IResponse> action;
+			if (!this.requestCallback.TryGetValue(response.RpcId, out action))
+			{
+				return;
+			}
+			this.requestCallback.Remove(response.RpcId);
+
+			action(response);
 		}
 
 		public Task<IResponse> Call(IRequest request)
@@ -178,10 +178,6 @@ namespace ETModel
 			{
 				try
 				{
-					if (response.RpcId != rpcId)
-					{
-						return;
-					}
 					if (response.Error > ErrorCode.ERR_Exception)
 					{
 						throw new RpcException(response.Error, response.Message);
@@ -209,10 +205,6 @@ namespace ETModel
 			{
 				try
 				{
-					if (response.RpcId != rpcId)
-					{
-						return;
-					}
 					if (response.Error > ErrorCode.ERR_Exception)
 					{
 						throw new RpcException(response.Error, response.Message);
@@ -259,6 +251,10 @@ namespace ETModel
 
 		public void Send(byte flag, ushort opcode, byte[] bytes)
 		{
+			if (this.IsDisposed)
+			{
+				throw new Exception("session已经被Dispose了");
+			}
 			this.byteses[0][0] = flag;
 			this.byteses[1] = BitConverter.GetBytes(opcode);
 			this.byteses[2] = bytes;

+ 2 - 2
Unity/Assets/ThirdParty/ILRuntime/Generated/CLRBindings.cs

@@ -56,7 +56,7 @@ namespace ILRuntime.Runtime.Generated
             System_Activator_Binding.Register(app);
             ETModel_GameObjectHelper_Binding.Register(app);
             UnityEngine_TextAsset_Binding.Register(app);
-            UnityEngine_Resources_Binding.Register(app);
+            //UnityEngine_Resources_Binding.Register(app);
             System_Collections_Generic_HashSet_1_ILTypeInstance_Binding.Register(app);
             System_Linq_Enumerable_Binding.Register(app);
             System_Collections_Generic_HashSet_1_ILTypeInstance_Binding_Enumerator_Binding.Register(app);
@@ -73,8 +73,8 @@ namespace ILRuntime.Runtime.Generated
             System_Collections_Generic_Dictionary_2_Type_Queue_1_ILTypeInstance_Binding.Register(app);
             ETModel_Packet_Binding.Register(app);
             ETModel_ProtobufHelper_Binding.Register(app);
-            System_Collections_Generic_Dictionary_2_Int32_Action_1_ILTypeInstance_Binding.Register(app);
             ETModel_MessageInfo_Binding.Register(app);
+            System_Collections_Generic_Dictionary_2_Int32_Action_1_ILTypeInstance_Binding.Register(app);
             System_Threading_Tasks_TaskCompletionSource_1_ILTypeInstance_Binding.Register(app);
             System_Threading_CancellationToken_Binding.Register(app);
             ETModel_SessionCallbackComponent_Binding.Register(app);

+ 18 - 0
Unity/Assets/ThirdParty/ILRuntime/Generated/System_Collections_Generic_Dictionary_2_Int32_Action_1_ILTypeI_t.cs

@@ -31,6 +31,9 @@ namespace ILRuntime.Runtime.Generated
             args = new Type[]{typeof(System.Int32), typeof(System.Action<ILRuntime.Runtime.Intepreter.ILTypeInstance>)};
             method = type.GetMethod("set_Item", flag, null, args, null);
             app.RegisterCLRMethodRedirection(method, set_Item_2);
+            args = new Type[]{};
+            method = type.GetMethod("get_Values", flag, null, args, null);
+            app.RegisterCLRMethodRedirection(method, get_Values_3);
 
             args = new Type[]{};
             method = type.GetConstructor(flag, null, args, null);
@@ -154,6 +157,21 @@ namespace ILRuntime.Runtime.Generated
             return __ret;
         }
 
+        static StackObject* get_Values_3(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
+        {
+            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
+            StackObject* ptr_of_this_method;
+            StackObject* __ret = ILIntepreter.Minus(__esp, 1);
+            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
+            System.Collections.Generic.Dictionary<System.Int32, System.Action<ILRuntime.Runtime.Intepreter.ILTypeInstance>> instance_of_this_method;
+            instance_of_this_method = (System.Collections.Generic.Dictionary<System.Int32, System.Action<ILRuntime.Runtime.Intepreter.ILTypeInstance>>)typeof(System.Collections.Generic.Dictionary<System.Int32, System.Action<ILRuntime.Runtime.Intepreter.ILTypeInstance>>).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
+            __intp.Free(ptr_of_this_method);
+
+            var result_of_this_method = instance_of_this_method.Values;
+
+            return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method);
+        }
+
 
         static StackObject* Ctor_0(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
         {

+ 31 - 3
Unity/Assets/ThirdParty/ILRuntime/Generated/System_Linq_Enumerable_Binding.cs

@@ -50,7 +50,7 @@ namespace ILRuntime.Runtime.Generated
                     }
                 }
             }
-            args = new Type[]{typeof(System.String)};
+            args = new Type[]{typeof(System.Action<ILRuntime.Runtime.Intepreter.ILTypeInstance>)};
             if (genericMethods.TryGetValue("ToArray", out lst))
             {
                 foreach(var m in lst)
@@ -64,6 +64,20 @@ namespace ILRuntime.Runtime.Generated
                     }
                 }
             }
+            args = new Type[]{typeof(System.String)};
+            if (genericMethods.TryGetValue("ToArray", out lst))
+            {
+                foreach(var m in lst)
+                {
+                    if(m.GetParameters().Length == 1)
+                    {
+                        method = m.MakeGenericMethod(args);
+                        app.RegisterCLRMethodRedirection(method, ToArray_2);
+
+                        break;
+                    }
+                }
+            }
             args = new Type[]{typeof(ILRuntime.Runtime.Intepreter.ILTypeInstance)};
             if (genericMethods.TryGetValue("First", out lst))
             {
@@ -72,7 +86,7 @@ namespace ILRuntime.Runtime.Generated
                     if(m.GetParameters().Length == 1)
                     {
                         method = m.MakeGenericMethod(args);
-                        app.RegisterCLRMethodRedirection(method, First_2);
+                        app.RegisterCLRMethodRedirection(method, First_3);
 
                         break;
                     }
@@ -98,6 +112,20 @@ namespace ILRuntime.Runtime.Generated
         }
 
         static StackObject* ToArray_1(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
+        {
+            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
+            StackObject* ptr_of_this_method;
+            StackObject* __ret = ILIntepreter.Minus(__esp, 1);
+            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
+            System.Collections.Generic.IEnumerable<System.Action<ILRuntime.Runtime.Intepreter.ILTypeInstance>> source = (System.Collections.Generic.IEnumerable<System.Action<ILRuntime.Runtime.Intepreter.ILTypeInstance>>)typeof(System.Collections.Generic.IEnumerable<System.Action<ILRuntime.Runtime.Intepreter.ILTypeInstance>>).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
+            __intp.Free(ptr_of_this_method);
+
+            var result_of_this_method = System.Linq.Enumerable.ToArray<System.Action<ILRuntime.Runtime.Intepreter.ILTypeInstance>>(source);
+
+            return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method);
+        }
+
+        static StackObject* ToArray_2(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
         {
             ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
             StackObject* ptr_of_this_method;
@@ -111,7 +139,7 @@ namespace ILRuntime.Runtime.Generated
             return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method);
         }
 
-        static StackObject* First_2(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
+        static StackObject* First_3(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
         {
             ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
             StackObject* ptr_of_this_method;

+ 0 - 7
Unity/Hotfix/Module/Message/HotfixMessage.cs

@@ -127,10 +127,3 @@ namespace ETHotfix
 	}
 
 }
-namespace ETHotfix
-{
-	[ProtoInclude(HotfixOpcode.C2M_TestActorRequest, typeof(C2M_TestActorRequest))]
-	[ProtoInclude(HotfixOpcode.M2C_TestActorResponse, typeof(M2C_TestActorResponse))]
-	public partial class MessageObject {}
-
-}

+ 8 - 0
Unity/Hotfix/Module/Message/IMessage.cs

@@ -2,6 +2,7 @@
 
 namespace ETHotfix
 {
+	[ProtoContract]
 	public partial class MessageObject
 	{
 	}
@@ -21,4 +22,11 @@ namespace ETHotfix
 		string Message { get; set; }
 		int RpcId { get; set; }
 	}
+
+	public class ResponseMessage : IResponse
+	{
+		public int Error { get; set; }
+		public string Message { get; set; }
+		public int RpcId { get; set; }
+	}
 }