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; } }
private ModHeaderWriteLogic( BinaryWriteParameters?param, IModGetter mod, IModHeaderCommon modHeader) { _params = param ?? BinaryWriteParameters.Default; _modKey = mod.ModKey; _nextFormID = modHeader.MinimumCustomFormID; }
private void AddProcessors( IModGetter mod, IModHeaderCommon modHeader) { ModifyMasterFlags(modHeader); AddMasterCollectionActions(mod); AddRecordCount(); AddNextFormIDActions(); AddFormIDUniqueness(); AddLightMasterFormLimit(modHeader); }
private void AddLightMasterFormLimit(IModHeaderCommon header) { if (!EnumExt.HasFlag(header.RawFlags, (int)ModHeaderCommonFlag.LightMaster)) { return; } _recordIterationActions.Add(maj => { if (maj.FormKey.ModKey == _modKey) { _uniqueRecordsFromMod++; } }); }
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); }
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}"); } }