public bool IsEnabled(string name)
 {
     FieldInfo fi = GetType().GetField(SettingsBuilder.SanitizeName(name));
     if (fi != null)
     {
         return (bool)fi.GetValue(this);
     }
     return false;
 }
Exemple #2
0
 private void SetContractToDisabled(string contractType)
 {
     foreach (FieldInfo fi in contractFields)
     {
         if (fi.Name == SettingsBuilder.SanitizeName(contractType))
         {
             fi.SetValue(this, false);
         }
     }
 }
Exemple #3
0
        public override void OnLoad(ConfigNode node)
        {
            base.OnLoad(node);

            foreach (Type subclass in ContractConfigurator.GetAllTypes <Contract>().Where(t => t != null && !t.Name.StartsWith("ConfiguredContract")))
            {
                FieldInfo fi = GetType().GetField(SettingsBuilder.SanitizeName(subclass.Name));
                if (fi != null)
                {
                    bool val = (bool)fi.GetValue(this);
                    ContractDisabler.SetContractState(subclass, val);
                }
            }
        }
Exemple #4
0
        public static void EmitSettings()
        {
            // Do this before we start creating assemblies
            List <Type> contractTypes = ContractConfigurator.GetAllTypes <Contract>().Where(t => t != null && !t.Name.StartsWith("ConfiguredContract")).ToList();

            // Create the assembly
            AssemblyBuilder assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(
                new AssemblyName("ContractConfiguratorDynamic"), AssemblyBuilderAccess.ReflectionOnly);
            ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("ContractConfiguratorDynamicModule");

            // Attribute constructor
            ConstructorInfo paramUICons = typeof(GameParameters.CustomParameterUI).GetConstructor(new Type[] { typeof(string) });

            // Create the contract group settings page
            TypeBuilder groupParamBuilder = moduleBuilder.DefineType("ContractConfigurator.ContractGroupParameters",
                                                                     TypeAttributes.Public | TypeAttributes.Class, typeof(ContractGroupParametersTemplate));

            // Define a field for each Group
            foreach (ContractGroup contractGroup in ContractGroup.AllGroups.Where(g => g != null && g.parent == null).OrderBy(g => g.displayName))
            {
                FieldBuilder groupField = groupParamBuilder.DefineField(SettingsBuilder.SanitizeName(contractGroup.name), typeof(bool), FieldAttributes.Public);

                CustomAttributeBuilder attBuilder = new CustomAttributeBuilder(paramUICons, new object[] { contractGroup.displayName });
                groupField.SetCustomAttribute(attBuilder);
            }

            // Create the stock contracts settings page
            TypeBuilder stockParamBuilder = moduleBuilder.DefineType("ContractConfigurator.StockContractParametersTemplate",
                                                                     TypeAttributes.Public | TypeAttributes.Class, typeof(StockContractParametersTemplate));

            // Define a field for each contract type
            foreach (MissionControlUI.GroupContainer container in contractTypes.Select(t => new MissionControlUI.GroupContainer(t)).OrderBy(mcui => mcui.DisplayName()))
            {
                FieldBuilder groupField = stockParamBuilder.DefineField(SettingsBuilder.SanitizeName(container.stockContractType.Name), typeof(bool), FieldAttributes.Public);

                CustomAttributeBuilder attBuilder = new CustomAttributeBuilder(paramUICons, new object[] { container.DisplayName() });
                groupField.SetCustomAttribute(attBuilder);
            }

            // Finalize the types
            GroupParametersType = groupParamBuilder.CreateType();
            StockParametersType = stockParamBuilder.CreateType();

            // Add the types into the custom parameter list so they get picked up
            GameParameters.ParameterTypes.Add(GroupParametersType);
            GameParameters.ParameterTypes.Add(StockParametersType);
        }