コード例 #1
0
        private void InvokeModLoaders(StateManager.StateTypes state)
        {
#if DEBUG
            System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
            timer.Start();
#endif
            if (alreadyAtStartMenuState)
            {
                Mod[] mods = GetAllMods();

                for (int i = 0; i < mods.Length; i++)
                {
                    List <SetupOptions> setupOptions = mods[i].FindModLoaders(state);

                    if (setupOptions == null)
                    {
                        Debug.Log("No mod loaders found for mod: " + mods[i].Title);
                        continue;
                    }

                    for (int j = 0; j < setupOptions.Count; j++)
                    {
                        SetupOptions options = setupOptions[j];
                        MethodInfo   mi      = options.mi;
                        if (mi == null)
                        {
                            continue;
                        }
                        InitParams initParams = new InitParams(options.mod, ModManager.Instance.GetModIndex(options.mod.Title), LoadedModCount);

                        try
                        {
                            mi.Invoke(null, new object[] { initParams });
                        }
                        catch (TargetInvocationException e)
                        {
                            Debug.LogError($"Exception has been thrown by entry point \"{mi.Name}\" of mod \"{mods[i].Title}\":\n{e.InnerException}");
                        }
                    }
                }
#if DEBUG
                timer.Stop();
                Debug.Log("InvokeModLoaders() finished...time: " + timer.ElapsedMilliseconds);
#endif
            }
        }
コード例 #2
0
ファイル: Mod.cs プロジェクト: jammerlich/daggerfall-unity
        private void FindModLoaders(StateManager.StateTypes state, Type type, List <SetupOptions> modLoaders)
        {
            foreach (MethodInfo mi in type.GetMethods())
            {
                if (!mi.IsPublic || !mi.IsStatic)
                {
                    continue;
                }
                else if (mi.ContainsGenericParameters)
                {
                    continue;
                }

                Invoke initAttribute = (Invoke)Attribute.GetCustomAttribute(mi, typeof(Invoke));
                if (initAttribute == null)
                {
                    continue;
                }
                else if (initAttribute.StartState != state)
                {
                    continue;
                }
                ParameterInfo[] pi = mi.GetParameters();
                if (pi.Length != 1)
                {
                    continue;
                }
                else if (pi[0].ParameterType != typeof(InitParams))
                {
                    continue;
                }
                SetupOptions options = new SetupOptions(initAttribute.Priority, this, mi);
#if DEBUG
                Debug.Log(string.Format("found new loader: {0} for mod: {1}", options.mi.Name, this.Title));
#endif
                modLoaders.Add(options);
            }
        }
コード例 #3
0
        public List <SetupOptions> FindModLoaders(StateManager.StateTypes state)
        {
            if (Assemblies == null || Assemblies.Count < 1)
            {
                return(null);
            }

            List <SetupOptions> modLoaders = new List <SetupOptions>(1);

            for (int i = 0; i < Assemblies.Count; i++)
            {
                try
                {
                    Type[] types = Assemblies[i].GetTypes();

                    foreach (Type t in types)
                    {
                        if (!t.IsClass)
                        {
                            continue;
                        }

                        foreach (MethodInfo mi in t.GetMethods())
                        {
                            if (!mi.IsPublic || !mi.IsStatic)
                            {
                                continue;
                            }
                            else if (mi.ContainsGenericParameters)
                            {
                                continue;
                            }

                            Invoke initAttribute = (Invoke)Attribute.GetCustomAttribute(mi, typeof(Invoke));
                            if (initAttribute == null)
                            {
                                continue;
                            }
                            else if (initAttribute.startState != state)
                            {
                                continue;
                            }
                            ParameterInfo[] pi = mi.GetParameters();
                            if (pi.Length != 1)
                            {
                                continue;
                            }
                            else if (pi[0].ParameterType != typeof(InitParams))
                            {
                                continue;
                            }
                            SetupOptions options = new SetupOptions(initAttribute.priority, this, mi);
#if DEBUG
                            Debug.Log(string.Format("found new loader: {0} for mod: {1}", options.mi.Name, this.Name));
#endif
                            modLoaders.Add(options);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.LogError(ex.Message);
                    continue;
                }
            }

            modLoaders.Sort();
            return(modLoaders);
        }