Пример #1
0
        private void EnableModule(ModuleAndAttribute module)
        {
            Logger.LogInfo($"Enabling module: {module.Attribute.Name}");

            ModuleAttribute customAttr = module.Attribute;
            Type            type       = module.Module;

            constuctorArgumentArray[0] = customAttr.Name;
            constuctorArgumentArray[1] = customAttr.Description;
            constuctorArgumentArray[2] = customAttr.DefaultEnabled;
            try
            {
                var         ctor         = type.GetConstructor(constructorParameters);
                R2DSEModule loadedModule = (R2DSEModule)ctor.Invoke(constuctorArgumentArray);
                loadedModule.ReloadHooks();
                Modules.Add(customAttr.Name, loadedModule);
            }
            catch (Exception e)
            {
                Logger.LogError($"Couldn't load module: {constuctorArgumentArray[0]}");
                Logger.LogError(e);
            }
        }
Пример #2
0
        private PluginEntry()
        {
            #region Not Release Message
#if DEBUG
            Logger.LogWarning($"This is a debug build!");
#elif BLEEDING
            Logger.LogWarning($"This is a Bleeding-Edge build!");
#endif
            #endregion

            Instance         = this;
            Log              = Logger;
            Configuration    = new ConfigFile(Paths.ConfigPath + "\\R2DSE.cfg", true);
            Modules          = new Dictionary <string, R2DSEModule>();
            ConvarsToAdd     = new Queue <BaseConVar>();
            ConCommandsToAdd = new Queue <MethodInfo>();
            ModulesToLoad    = new Queue <ModuleAndAttribute> [2];
            ModulesToLoad[0] = new Queue <ModuleAndAttribute>();
            ModulesToLoad[1] = new Queue <ModuleAndAttribute>();

            var disableWhenGraphicDetected = Configuration.Bind("_R2DSE", "Disable When Graphics Detected", true, "Disable the plugin when game graphics are detected.");

            if (!Application.isBatchMode && disableWhenGraphicDetected.Value)
            {
                Logger.LogWarning("Detected graphics. Plugin disabled. If you want to use R2DSE in this mode please change the plugin config.");
                return;
            }

            var pluginInfos = BepInEx.Bootstrap.Chainloader.PluginInfos;
            var types       = Assembly.GetExecutingAssembly().GetTypes();
            foreach (Type type in types)
            {
                ModuleAttribute customAttr   = (ModuleAttribute)type.GetCustomAttributes(typeof(ModuleAttribute), false).FirstOrDefault();
                var             dependencies = type.GetCustomAttributes <PluginDependency>();
                if (customAttr != null && dependencies.All(dep => pluginInfos.ContainsKey(dep.GUID)))
                {
                    foreach (FieldInfo field in type.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
                    {
                        if (field.FieldType.IsSubclassOf(typeof(BaseConVar)))
                        {
                            ConvarsToAdd.Enqueue((BaseConVar)(field.GetValue(null)));
                        }
                    }
                    foreach (MethodInfo method in type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
                    {
                        var CCattr = method.GetCustomAttribute <RoR2.ConCommandAttribute>();
                        if (CCattr != null)
                        {
                            ConCommandsToAdd.Enqueue(method);
                        }
                    }
                    if (customAttr.target == ModuleAttribute.StartupTarget.Awake)
                    {
                        ModulesToLoad[0].Enqueue(new ModuleAndAttribute()
                        {
                            Module = type, Attribute = customAttr
                        });
                    }
                    else
                    {
                        ModulesToLoad[1].Enqueue(new ModuleAndAttribute()
                        {
                            Module = type, Attribute = customAttr
                        });
                    }
                }
            }
        }