Пример #1
0
        private static SyncVarHook FindAutomatic(FieldDefinition syncVar, string hookFunctionName, TypeReference originalType)
        {
            SyncVarHook foundHook = null;

            CheckHook(syncVar, hookFunctionName, ref foundHook, FindMethod1Arg(syncVar, hookFunctionName, originalType));
            CheckHook(syncVar, hookFunctionName, ref foundHook, FindMethod2Arg(syncVar, hookFunctionName, originalType));
            CheckHook(syncVar, hookFunctionName, ref foundHook, FindEvent1Arg(syncVar, hookFunctionName, originalType));
            CheckHook(syncVar, hookFunctionName, ref foundHook, FindEvent2Arg(syncVar, hookFunctionName, originalType));

            return(foundHook);
        }
Пример #2
0
        private static void CheckHook(FieldDefinition syncVar, string hookFunctionName, ref SyncVarHook foundHook, SyncVarHook newfound)
        {
            // dont need to check anything if new one is null (not found)
            if (newfound == null)
            {
                return;
            }

            if (foundHook == null)
            {
                foundHook = newfound;
            }
            else
            {
                throw new HookMethodException($"Mutliple hooks found for '{syncVar.Name}', hook name '{hookFunctionName}'. Please set HookType or remove one of the overloads", syncVar);
            }
        }
Пример #3
0
        /// <summary>
        /// Finds any attribute values needed for this syncvar
        /// </summary>
        /// <param name="module"></param>
        public void ProcessAttributes(Writers writers, Readers readers)
        {
            SyncVarHook hook = HookMethodFinder.GetHookMethod(FieldDefinition, OriginalType);

            Hook    = hook;
            HasHook = hook != null;

            InitialOnly = GetInitialOnly(FieldDefinition);

            InvokeHookOnServer = GetFireOnServer(FieldDefinition);

            ValueSerializer = ValueSerializerFinder.GetSerializer(this, writers, readers);

            if (!HasHook && InvokeHookOnServer)
            {
                throw new HookMethodException("'invokeHookOnServer' is set to true but no hook was implemented. Please implement hook or set 'invokeHookOnServer' back to false or remove for default false.", FieldDefinition);
            }
        }