void ProcessTargetRpc(HashSet <string> names, MethodDefinition md, CustomAttribute ca)
        {
            if (!TargetRpcProcessor.ProcessMethodsValidateTargetRpc(md, ca))
            {
                return;
            }

            if (names.Contains(md.Name))
            {
                Weaver.Error("Duplicate Target Rpc name [" + netBehaviourSubclass.FullName + ":" + md.Name + "]");
                return;
            }
            names.Add(md.Name);
            targetRpcs.Add(md);

            MethodDefinition rpcCallFunc = TargetRpcProcessor.ProcessTargetRpcCall(netBehaviourSubclass, md, ca);

            MethodDefinition rpcFunc = TargetRpcProcessor.ProcessTargetRpcInvoke(netBehaviourSubclass, md, rpcCallFunc);

            if (rpcFunc != null)
            {
                targetRpcInvocationFuncs.Add(rpcFunc);
            }

            if (rpcCallFunc != null)
            {
                targetRpcCallFuncs.Add(rpcCallFunc);
            }
        }
Ejemplo n.º 2
0
        void ProcessTargetRpc(HashSet <string> names, MethodDefinition md, CustomAttribute targetRpcAttr)
        {
            if (md.IsAbstract)
            {
                Weaver.Error("Abstract TargetRpc are currently not supported, use virtual method instead", md);
                return;
            }

            if (!TargetRpcProcessor.ProcessMethodsValidateTargetRpc(md))
            {
                return;
            }

            if (names.Contains(md.Name))
            {
                Weaver.Error($"Duplicate Target Rpc name {md.Name}", md);
                return;
            }
            names.Add(md.Name);
            targetRpcs.Add(md);

            MethodDefinition rpcCallFunc = TargetRpcProcessor.ProcessTargetRpcCall(netBehaviourSubclass, md, targetRpcAttr);

            MethodDefinition rpcFunc = TargetRpcProcessor.ProcessTargetRpcInvoke(netBehaviourSubclass, md, rpcCallFunc);

            if (rpcFunc != null)
            {
                targetRpcInvocationFuncs.Add(rpcFunc);
            }
        }
Ejemplo n.º 3
0
        void ProcessMethods()
        {
            HashSet <string> names = new HashSet <string>();

            // find command and RPC functions
            foreach (MethodDefinition md in m_td.Methods)
            {
                Weaver.ResetRecursionCount();
                foreach (CustomAttribute ca in md.CustomAttributes)
                {
                    if (ca.AttributeType.FullName == Weaver.CommandType.FullName)
                    {
                        if (!CommandProcessor.ProcessMethodsValidateCommand(m_td, md, ca))
                        {
                            return;
                        }

                        if (names.Contains(md.Name))
                        {
                            Log.Error("Duplicate Command name [" + m_td.FullName + ":" + md.Name + "]");
                            Weaver.fail = true;
                            return;
                        }
                        names.Add(md.Name);
                        m_Cmds.Add(md);

                        MethodDefinition cmdFunc = CommandProcessor.ProcessCommandInvoke(m_td, md);
                        if (cmdFunc != null)
                        {
                            m_CmdInvocationFuncs.Add(cmdFunc);
                        }

                        MethodDefinition cmdCallFunc = CommandProcessor.ProcessCommandCall(m_td, md, ca);
                        if (cmdCallFunc != null)
                        {
                            m_CmdCallFuncs.Add(cmdCallFunc);
                            Weaver.lists.replaceMethods[md.FullName] = cmdCallFunc;
                        }
                        break;
                    }

                    if (ca.AttributeType.FullName == Weaver.TargetRpcType.FullName)
                    {
                        if (!TargetRpcProcessor.ProcessMethodsValidateTargetRpc(m_td, md, ca))
                        {
                            return;
                        }

                        if (names.Contains(md.Name))
                        {
                            Log.Error("Duplicate Target Rpc name [" + m_td.FullName + ":" + md.Name + "]");
                            Weaver.fail = true;
                            return;
                        }
                        names.Add(md.Name);
                        m_TargetRpcs.Add(md);

                        MethodDefinition rpcFunc = TargetRpcProcessor.ProcessTargetRpcInvoke(m_td, md);
                        if (rpcFunc != null)
                        {
                            m_TargetRpcInvocationFuncs.Add(rpcFunc);
                        }

                        MethodDefinition rpcCallFunc = TargetRpcProcessor.ProcessTargetRpcCall(m_td, md, ca);
                        if (rpcCallFunc != null)
                        {
                            m_TargetRpcCallFuncs.Add(rpcCallFunc);
                            Weaver.lists.replaceMethods[md.FullName] = rpcCallFunc;
                        }
                        break;
                    }

                    if (ca.AttributeType.FullName == Weaver.ClientRpcType.FullName)
                    {
                        if (!RpcProcessor.ProcessMethodsValidateRpc(m_td, md, ca))
                        {
                            return;
                        }

                        if (names.Contains(md.Name))
                        {
                            Log.Error("Duplicate ClientRpc name [" + m_td.FullName + ":" + md.Name + "]");
                            Weaver.fail = true;
                            return;
                        }
                        names.Add(md.Name);
                        m_Rpcs.Add(md);

                        MethodDefinition rpcFunc = RpcProcessor.ProcessRpcInvoke(m_td, md);
                        if (rpcFunc != null)
                        {
                            m_RpcInvocationFuncs.Add(rpcFunc);
                        }

                        MethodDefinition rpcCallFunc = RpcProcessor.ProcessRpcCall(m_td, md, ca);
                        if (rpcCallFunc != null)
                        {
                            m_RpcCallFuncs.Add(rpcCallFunc);
                            Weaver.lists.replaceMethods[md.FullName] = rpcCallFunc;
                        }
                        break;
                    }
                }
            }

            // cmds
            foreach (MethodDefinition md in m_CmdInvocationFuncs)
            {
                m_td.Methods.Add(md);
            }
            foreach (MethodDefinition md in m_CmdCallFuncs)
            {
                m_td.Methods.Add(md);
            }

            // rpcs
            foreach (MethodDefinition md in m_RpcInvocationFuncs)
            {
                m_td.Methods.Add(md);
            }
            foreach (MethodDefinition md in m_TargetRpcInvocationFuncs)
            {
                m_td.Methods.Add(md);
            }
            foreach (MethodDefinition md in m_RpcCallFuncs)
            {
                m_td.Methods.Add(md);
            }
            foreach (MethodDefinition md in m_TargetRpcCallFuncs)
            {
                m_td.Methods.Add(md);
            }
        }