コード例 #1
0
        public static void Create(RescueContractConfig config)
        {
            if (allowedPartsSettingsType != null)
            {
                return;
            }

            AssemblyBuilder assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(
                new AssemblyName("KSPRescueContractFixDynamic"), AssemblyBuilderAccess.Run);
            ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("KSPRescueContractFixDynamicModule");

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

            TypeBuilder partsSettingsBuilder = moduleBuilder.DefineType("KSPRescueContractFix.AllowedPartsSettings",
                                                                        TypeAttributes.Public | TypeAttributes.Class, typeof(AllowedPartsSettings));

            // Define a field for each contract type
            foreach (AvailablePart part in config.allowedCrewedParts.Select(PartLoader.getPartInfoByName).Where(p => p != null).OrderBy(p => p.title))
            {
                FieldBuilder groupField = partsSettingsBuilder.DefineField(Sanitize(part.name), typeof(bool), FieldAttributes.Public);

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

            allowedPartsSettingsType = partsSettingsBuilder.CreateType();
            GameParameters.ParameterTypes.Add(allowedPartsSettingsType);
        }
コード例 #2
0
 public void ModuleManagerPostLoad()
 {
     config = new RescueContractConfig();
     ConfigNode[] configNodes = GameDatabase.Instance.GetConfigNodes("RESCUE_CONTRACT_FIX_CONFIG");
     if (configNodes.Length > 0)
     {
         config.Load(configNodes[0]);
     }
 }