예제 #1
0
        public void ModifyMasterFlags(IModHeaderCommon header)
        {
            switch (_params.MasterFlag)
            {
            case BinaryWriteParameters.MasterFlagOption.NoCheck:
                break;

            case BinaryWriteParameters.MasterFlagOption.ChangeToMatchModKey:
                header.RawFlags = EnumExt.SetFlag(header.RawFlags, (int)ModHeaderCommonFlag.Master, _modKey.Type == ModType.Master);
                if (_modKey.Type != ModType.Plugin)
                {
                    header.RawFlags = EnumExt.SetFlag(header.RawFlags, (int)ModHeaderCommonFlag.Master, true);
                }
                break;

            case BinaryWriteParameters.MasterFlagOption.ExceptionOnMismatch:
                if ((_modKey.Type == ModType.Master) != EnumExt.HasFlag(header.RawFlags, (int)ModHeaderCommonFlag.Master))
                {
                    throw new ArgumentException($"Master flag did not match ModKey type. ({_modKey})");
                }
                if ((_modKey.Type == ModType.LightMaster) != EnumExt.HasFlag(header.RawFlags, (int)ModHeaderCommonFlag.LightMaster))
                {
                    throw new ArgumentException($"LightMaster flag did not match ModKey type. ({_modKey})");
                }
                break;

            default:
                break;
            }
        }
예제 #2
0
 private ModHeaderWriteLogic(
     BinaryWriteParameters?param,
     IModGetter mod,
     IModHeaderCommon modHeader)
 {
     _params     = param ?? BinaryWriteParameters.Default;
     _modKey     = mod.ModKey;
     _nextFormID = modHeader.MinimumCustomFormID;
 }
예제 #3
0
 private void AddProcessors(
     IModGetter mod,
     IModHeaderCommon modHeader)
 {
     ModifyMasterFlags(modHeader);
     AddMasterCollectionActions(mod);
     AddRecordCount();
     AddNextFormIDActions();
     AddFormIDUniqueness();
     AddLightMasterFormLimit(modHeader);
 }
예제 #4
0
 private void AddLightMasterFormLimit(IModHeaderCommon header)
 {
     if (!EnumExt.HasFlag(header.RawFlags, (int)ModHeaderCommonFlag.LightMaster))
     {
         return;
     }
     _recordIterationActions.Add(maj =>
     {
         if (maj.FormKey.ModKey == _modKey)
         {
             _uniqueRecordsFromMod++;
         }
     });
 }
예제 #5
0
        public static void WriteHeader(
            BinaryWriteParameters?param,
            MutagenWriter writer,
            IModGetter mod,
            IModHeaderCommon modHeader,
            ModKey modKey)
        {
            var modHeaderWriter = new ModHeaderWriteLogic(
                param: param,
                mod: mod,
                modHeader: modHeader);

            modHeaderWriter.AddProcessors(mod, modHeader);
            modHeaderWriter.RunProcessors(mod);
            modHeaderWriter.PostProcessAdjustments(writer, mod, modHeader);
            modHeader.WriteToBinary(writer);
        }
예제 #6
0
 private void PostProcessAdjustments(
     MutagenWriter writer,
     IModGetter mod,
     IModHeaderCommon modHeader)
 {
     writer.MetaData.MasterReferences = ConstructWriteMasters(mod);
     modHeader.MasterReferences.SetTo(writer.MetaData.MasterReferences !.Masters.Select(m => m.DeepCopy()));
     if (_params.RecordCount != BinaryWriteParameters.RecordCountOption.NoCheck)
     {
         modHeader.NumRecords = _numRecords;
     }
     if (_params.NextFormID != BinaryWriteParameters.NextFormIDOption.NoCheck)
     {
         modHeader.NextFormID = _nextFormID + 1;
     }
     if (EnumExt.HasFlag(modHeader.RawFlags, (int)ModHeaderCommonFlag.LightMaster) &&
         _uniqueRecordsFromMod > Constants.LightMasterLimit)
     {
         throw new ArgumentException($"Light Master Mod contained more originating records than allowed. {_uniqueRecordsFromMod} > {Constants.LightMasterLimit}");
     }
 }