Beispiel #1
0
        public override void Handle(ByteReader data)
        {
            object target = Activator.CreateInstance(delegateType);

            for (int i = 0; i < fieldPaths.Length; i++)
            {
                string path       = fieldPaths[i];
                string noTypePath = MpReflection.RemoveType(path);
                Type   fieldType  = fieldTypes[i];
                object value;

                if (fieldType.IsCompilerGenerated())
                {
                    value = Activator.CreateInstance(fieldType);
                }
                else
                {
                    value = Sync.ReadSyncObject(data, fieldType);
                }

                if (value == null)
                {
                    if (cancelIfAnyNullBlacklist != null && !cancelIfAnyNullBlacklist.Contains(noTypePath))
                    {
                        return;
                    }

                    if (path.EndsWith("$this"))
                    {
                        return;
                    }

                    if (cancelIfNull != null && cancelIfNull.Contains(noTypePath))
                    {
                        return;
                    }
                }

                if (removeNullsFromLists != null && removeNullsFromLists.Contains(noTypePath) && value is IList list)
                {
                    list.RemoveNulls();
                }

                MpReflection.SetValue(target, path, value);
            }

            if (context.HasFlag(SyncContext.MapSelected) && cancelIfNoSelectedObjects && Find.Selector.selected.Count == 0)
            {
                return;
            }

            object[] parameters = Sync.ReadSyncObjects(data, argTypes);

            MpLog.Log("Invoked delegate method " + method + " " + delegateType);
            method.Invoke(target, parameters);
        }
Beispiel #2
0
        public override void Handle(ByteReader data)
        {
            object target = null;

            if (targetType != null)
            {
                target = Sync.ReadSyncObject(data, targetType);
                if (target == null)
                {
                    return;
                }
            }

            if (!instancePath.NullOrEmpty())
            {
                target = target.GetPropertyOrField(instancePath);
            }

            object[] args = null;
            if (argTypes != null)
            {
                args = Sync.ReadSyncObjects(data, argTypes);
                if (cancelIfAnyArgNull && args.Any(a => a == null))
                {
                    return;
                }
            }

            if (context.HasFlag(SyncContext.MapSelected) && cancelIfNoSelectedMapObjects && Find.Selector.selected.Count == 0)
            {
                return;
            }

            if (context.HasFlag(SyncContext.WorldSelected) && cancelIfNoSelectedWorldObjects && Find.WorldSelector.selected.Count == 0)
            {
                return;
            }

            beforeCall?.Invoke(target, args);

            MpLog.Log("Invoked " + method + " on " + target + " with " + args.Length + " params " + args.ToStringSafeEnumerable());
            method.Invoke(target, args);

            afterCall?.Invoke(target, args);
        }