示例#1
0
        private void LoadBuiltinMessages()
        {
            IEnumerable <Type> types = typeof(NetworkReaderExtensions).Module.GetTypes().Where(t => t.GetCustomAttribute <NetworkMessageAttribute>() != null);

            foreach (Type type in types)
            {
                TypeReference typeReference = module.ImportReference(type);
                writers.GetWriteFunc(typeReference, null);
                readers.GetReadFunc(typeReference, null);
                messages.Add(typeReference);
            }
        }
示例#2
0
        public bool ReadArguments(MethodDefinition method, ILProcessor worker, bool skipFirst)
        {
            // read each argument
            // example result

            /*
             * CallCmdDoSomething(reader.ReadPackedInt32(), reader.ReadNetworkIdentity());
             */

            // arg of calling  function, arg 0 is "this" so start counting at 1
            int argNum = 1;

            foreach (ParameterDefinition param in method.Parameters)
            {
                // NetworkConnection is not sent via the NetworkWriter so skip it here
                // skip first for NetworkConnection in TargetRpc
                if (argNum == 1 && skipFirst)
                {
                    argNum += 1;
                    continue;
                }
                // skip SenderConnection in ServerRpc
                if (IsNetworkConnection(param.ParameterType))
                {
                    argNum += 1;
                    continue;
                }

                SequencePoint   sequencePoint = method.DebugInformation.SequencePoints.ElementAtOrDefault(0);
                MethodReference readFunc      = readers.GetReadFunc(param.ParameterType, sequencePoint);

                if (readFunc == null)
                {
                    logger.Error($"{method.Name} has invalid parameter {param}.  Unsupported type {param.ParameterType},  use a supported Mirage type instead", method);
                    return(false);
                }

                worker.Append(worker.Create(OpCodes.Ldarg_1));
                worker.Append(worker.Create(OpCodes.Call, readFunc));

                // conversion.. is this needed?
                if (param.ParameterType.Is <float>())
                {
                    worker.Append(worker.Create(OpCodes.Conv_R4));
                }
                else if (param.ParameterType.Is <double>())
                {
                    worker.Append(worker.Create(OpCodes.Conv_R8));
                }
            }
            return(true);
        }
示例#3
0
        /// <summary>
        /// Generates serialization methods for synclists
        /// </summary>
        /// <param name="td">The synclist class</param>
        /// <param name="mirrorBaseType">the base SyncObject td inherits from</param>
        void GenerateReadersAndWriters(TypeReference tr)
        {
            if (tr is GenericInstanceType genericInstance)
            {
                foreach (TypeReference argument in genericInstance.GenericArguments)
                {
                    if (!argument.IsGenericParameter)
                    {
                        readers.GetReadFunc(argument, null);
                        writers.GetWriteFunc(argument, null);
                    }
                }
            }

            if (tr != null)
            {
                GenerateReadersAndWriters(tr.Resolve().BaseType);
            }
        }