Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 34 additions & 30 deletions Mutagen.Bethesda.Fallout4/Records/Major Records/Perk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,16 +265,13 @@ public static APerkEffect ParseEffect<TStream>(TStream stream, SubrecordFrame pr
break;
case APerkEntryPointEffect.FunctionType.AddActivateChoice:
if (!payload.EPFT.HasValue) throw new MalformedDataException($"{nameof(PerkEntryPointAddActivateChoice)} did not have expected EPFT record");
if (!payload.EPF3.HasValue) throw new MalformedDataException($"{nameof(PerkEntryPointAddActivateChoice)} did not have expected EPF3 record");
if (payload.EPFT.Value.Content[0] != (byte)APerkEntryPointEffect.ParameterType.SpellWithStrings)
{
throw new MalformedDataException($"{nameof(PerkEntryPointAddActivateChoice)} did not have expected parameter type flag: {(APerkEntryPointEffect.ParameterType)payload.EPFT.Value.Content[0]}");
}
entryPointEffect = new PerkEntryPointAddActivateChoice()
{
Spell = FormLinkBinaryTranslation.Instance.FactoryNullable<ISpellGetter>(stream.MetaData, payload.EPFD?.Content),
ButtonLabel = payload.EPF2.HasValue ? StringBinaryTranslation.Instance.Parse(payload.EPF2.Value.Content, StringsSource.Normal, stream.MetaData, eager: true) : null,
Flags = (PerkEntryPointAddActivateChoice.Flag)BinaryPrimitives.ReadInt16LittleEndian(payload.EPF3.Value.Content),
};
break;
case APerkEntryPointEffect.FunctionType.SelectSpell:
Expand Down Expand Up @@ -447,7 +444,7 @@ public static partial void WriteBinaryEffectsCustom(MutagenWriter writer, IPerkG
writer,
effect.Conditions,
(w, i) => i.WriteToBinary(w));
if (effect is APerkEntryPointEffect ptEffect)
if (effect is APerkEntryPointEffect)
{
var paramType = effect switch
{
Expand All @@ -472,32 +469,7 @@ public static partial void WriteBinaryEffectsCustom(MutagenWriter writer, IPerkG
writer.Write((byte)paramType);
}
}

if (ptEffect.PerkEntryID is { } id)
{
using (HeaderExport.Subrecord(writer, RecordTypes.EPFB))
{
writer.Write(id);
}
}

if (effect is PerkEntryPointAddActivateChoice choice)
{
if (choice.ButtonLabel != null)
{
using (HeaderExport.Subrecord(writer, RecordTypes.EPF2))
{
StringBinaryTranslation.Instance.Write(writer, choice.ButtonLabel, StringBinaryType.NullTerminate, StringsSource.Normal);
}
}
using (HeaderExport.Subrecord(writer, RecordTypes.EPF3))
{
EnumBinaryTranslation<PerkEntryPointAddActivateChoice.Flag, MutagenFrame, MutagenWriter>.Instance.Write(
writer,
choice.Flags,
2);
}
}
WriteFunctionParameters(writer, effect);
switch (effect)
{
case PerkEntryPointModifyValue modVal:
Expand Down Expand Up @@ -564,9 +536,41 @@ public static partial void WriteBinaryEffectsCustom(MutagenWriter writer, IPerkG
throw new NotImplementedException();
}
}
else
{
WriteFunctionParameters(writer, effect);
}
using (HeaderExport.Subrecord(writer, RecordTypes.PRKF)) { }
}
}

private static void WriteFunctionParameters(MutagenWriter writer, IAPerkEffectGetter effect)
{
if (effect.PerkEntryID is { } id)
{
using (HeaderExport.Subrecord(writer, RecordTypes.EPFB))
{
writer.Write(id);
}
}
if (effect.ButtonLabel != null)
{
using (HeaderExport.Subrecord(writer, RecordTypes.EPF2))
{
StringBinaryTranslation.Instance.Write(writer, effect.ButtonLabel, StringBinaryType.NullTerminate, StringsSource.Normal);
}
}
if (effect.Flags is { } flags)
{
using (HeaderExport.Subrecord(writer, RecordTypes.EPF3))
{
EnumBinaryTranslation<APerkEffect.Flag, MutagenFrame, MutagenWriter>.Instance.Write(
writer,
flags,
2);
}
}
}
}

partial class PerkBinaryOverlay
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ partial class APerkEffectBinaryOverlay

public IReadOnlyList<IPerkConditionGetter> Conditions => throw new NotImplementedException();
public ITranslatedStringGetter? ButtonLabel => throw new NotImplementedException();
public IPerkScriptFlagGetter Flags => throw new NotImplementedException();
public IPerkScriptFlagGetter? Flags => throw new NotImplementedException();
}

partial class APerkEffectBinaryCreateTranslation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,15 @@ public ExtendedList<PerkCondition> Conditions
ITranslatedStringGetter? IAPerkEffectGetter.ButtonLabel => this.ButtonLabel;
#endregion
#region Flags
public PerkScriptFlag Flags { get; set; } = new PerkScriptFlag();
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
IPerkScriptFlagGetter IAPerkEffectGetter.Flags => Flags;
private PerkScriptFlag? _Flags;
public PerkScriptFlag? Flags
{
get => _Flags;
set => _Flags = value;
}
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
IPerkScriptFlagGetter? IAPerkEffectGetter.Flags => this.Flags;
#endregion

#region To String
Expand Down Expand Up @@ -624,7 +630,7 @@ public partial interface IAPerkEffect :
new Byte Priority { get; set; }
new ExtendedList<PerkCondition> Conditions { get; }
new TranslatedString? ButtonLabel { get; set; }
new PerkScriptFlag Flags { get; set; }
new PerkScriptFlag? Flags { get; set; }
}

/// <summary>
Expand All @@ -647,7 +653,7 @@ public partial interface IAPerkEffectGetter :
Byte Priority { get; }
IReadOnlyList<IPerkConditionGetter> Conditions { get; }
ITranslatedStringGetter? ButtonLabel { get; }
IPerkScriptFlagGetter Flags { get; }
IPerkScriptFlagGetter? Flags { get; }

}

Expand Down Expand Up @@ -925,7 +931,7 @@ public virtual void Clear(IAPerkEffect item)
item.Priority = default(Byte);
item.Conditions.Clear();
item.ButtonLabel = default;
item.Flags.Clear();
item.Flags = null;
}

#region Mutagen
Expand Down Expand Up @@ -983,7 +989,11 @@ public void FillEqualsMask(
(loqLhs, loqRhs) => loqLhs.GetEqualsMask(loqRhs, include),
include);
ret.ButtonLabel = object.Equals(item.ButtonLabel, rhs.ButtonLabel);
ret.Flags = MaskItemExt.Factory(item.Flags.GetEqualsMask(rhs.Flags, include), include);
ret.Flags = EqualsMaskHelper.EqualsHelper(
item.Flags,
rhs.Flags,
(loqLhs, loqRhs, incl) => loqLhs.GetEqualsMask(loqRhs, incl),
include);
}

public string Print(
Expand Down Expand Up @@ -1055,9 +1065,10 @@ protected static void ToStringFields(
{
sb.AppendItem(ButtonLabelItem, "ButtonLabel");
}
if (printMask?.Flags?.Overall ?? true)
if ((printMask?.Flags?.Overall ?? true)
&& item.Flags is {} FlagsItem)
{
item.Flags?.Print(sb, "Flags");
FlagsItem?.Print(sb, "Flags");
}
}

Expand Down Expand Up @@ -1105,7 +1116,10 @@ public virtual int GetHashCode(IAPerkEffectGetter item)
{
hash.Add(ButtonLabelitem);
}
hash.Add(item.Flags);
if (item.Flags is {} Flagsitem)
{
hash.Add(Flagsitem);
}
return hash.ToHashCode();
}

Expand Down Expand Up @@ -1183,11 +1197,15 @@ public virtual void DeepCopyIn(
errorMask?.PushIndex((int)APerkEffect_FieldIndex.Flags);
try
{
if ((copyMask?.GetShouldTranslate((int)APerkEffect_FieldIndex.Flags) ?? true))
if(rhs.Flags is {} rhsFlags)
{
item.Flags = rhsFlags.DeepCopy(
errorMask: errorMask,
copyMask?.GetSubCrystal((int)APerkEffect_FieldIndex.Flags));
}
else
{
item.Flags = rhs.Flags.DeepCopy(
copyMask: copyMask?.GetSubCrystal((int)APerkEffect_FieldIndex.Flags),
errorMask: errorMask);
item.Flags = default;
}
}
catch (Exception ex)
Expand Down
29 changes: 17 additions & 12 deletions Mutagen.Bethesda.Skyrim/Records/Major Records/Perk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -445,18 +445,7 @@ public static partial void WriteBinaryEffectsCustom(MutagenWriter writer, IPerkG
writer.Write((byte)paramType);
}
}

if (effect is PerkEntryPointAddActivateChoice choice)
{
if (choice.ButtonLabel != null)
{
using (HeaderExport.Subrecord(writer, RecordTypes.EPF2))
{
StringBinaryTranslation.Instance.Write(writer, choice.ButtonLabel, StringBinaryType.NullTerminate, StringsSource.Normal);
}
}
choice.Flags.WriteToBinary(writer);
}
WriteFunctionParameters(writer, effect);
switch (effect)
{
case PerkEntryPointModifyValue modVal:
Expand Down Expand Up @@ -523,9 +512,25 @@ public static partial void WriteBinaryEffectsCustom(MutagenWriter writer, IPerkG
throw new NotImplementedException();
}
}
else
{
WriteFunctionParameters(writer, effect);
}
using (HeaderExport.Subrecord(writer, RecordTypes.PRKF)) { }
}
}

private static void WriteFunctionParameters(MutagenWriter writer, IAPerkEffectGetter effect)
{
if (effect.ButtonLabel != null)
{
using (HeaderExport.Subrecord(writer, RecordTypes.EPF2))
{
StringBinaryTranslation.Instance.Write(writer, effect.ButtonLabel, StringBinaryType.NullTerminate, StringsSource.Normal);
}
}
effect.Flags?.WriteToBinary(writer);
}
}

partial class PerkBinaryOverlay
Expand Down
2 changes: 1 addition & 1 deletion Mutagen.Bethesda.Skyrim/Records/Major Records/Perk.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<RefList name="Conditions" refName="PerkCondition" binary="NoGeneration" />
<CustomLogic name="FunctionParameters" recordType="EPFT" binary="NoGeneration" />
<String name="ButtonLabel" translated="Normal" recordType="EPF2" nullable="True" binary="NoGeneration" />
<RefDirect name="Flags" refName="PerkScriptFlag" nullable="False" binary="NoGeneration" />
<RefDirect name="Flags" refName="PerkScriptFlag" nullable="True" binary="NoGeneration" />
</Fields>
</Object>
<Object name="PerkQuestEffect" objType="Subrecord" baseClass="APerkEffect">
Expand Down
64 changes: 34 additions & 30 deletions Mutagen.Bethesda.Starfield/Records/Major Records/PerkRank.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,16 +245,13 @@ public static IEnumerable<APerkEffect> ParseEffects(IMutagenReadStream stream)
break;
case APerkEntryPointEffect.FunctionType.AddActivateChoice:
if (!payload.EPFT.HasValue) throw new MalformedDataException($"{nameof(PerkEntryPointModifyActorValue)} did not have expected EPFT record");
if (!payload.EPF3.HasValue) throw new MalformedDataException($"{nameof(PerkEntryPointModifyActorValue)} did not have expected EPF3 record");
if (payload.EPFT.Value.Content[0] != (byte)APerkEntryPointEffect.ParameterType.SpellWithStrings)
{
throw new MalformedDataException($"{nameof(PerkEntryPointAddActivateChoice)} did not have expected parameter type flag: {(APerkEntryPointEffect.ParameterType)payload.EPFT.Value.Content[0]}");
}
entryPointEffect = new PerkEntryPointAddActivateChoice()
{
Spell = FormLinkBinaryTranslation.Instance.FactoryNullable<ISpellGetter>(stream.MetaData, payload.EPFD?.Content),
ButtonLabel = payload.EPF2.HasValue ? StringBinaryTranslation.Instance.Parse(payload.EPF2.Value.Content, StringsSource.Normal, stream.MetaData, eager: true) : null,
Flags = (PerkEntryPointAddActivateChoice.Flag)BinaryPrimitives.ReadInt16LittleEndian(payload.EPF3.Value.Content),
};
break;
case APerkEntryPointEffect.FunctionType.SelectSpell:
Expand Down Expand Up @@ -446,7 +443,7 @@ public static partial void WriteBinaryEffectsCustom(MutagenWriter writer, IPerkR
writer,
effect.Conditions,
(w, i) => i.WriteToBinary(w));
if (effect is APerkEntryPointEffect ptEffect)
if (effect is APerkEntryPointEffect)
{
var paramType = effect switch
{
Expand All @@ -473,32 +470,7 @@ public static partial void WriteBinaryEffectsCustom(MutagenWriter writer, IPerkR
writer.Write((byte)paramType);
}
}

if (ptEffect.PerkEntryID is { } id)
{
using (HeaderExport.Subrecord(writer, RecordTypes.EPFB))
{
writer.Write(id);
}
}

if (effect is PerkEntryPointAddActivateChoice choice)
{
if (choice.ButtonLabel != null)
{
using (HeaderExport.Subrecord(writer, RecordTypes.EPF2))
{
StringBinaryTranslation.Instance.Write(writer, choice.ButtonLabel, StringBinaryType.NullTerminate, StringsSource.Normal);
}
}
using (HeaderExport.Subrecord(writer, RecordTypes.EPF3))
{
EnumBinaryTranslation<PerkEntryPointAddActivateChoice.Flag, MutagenFrame, MutagenWriter>.Instance.Write(
writer,
choice.Flags,
2);
}
}
WriteFunctionParameters(writer, effect);
switch (effect)
{
case PerkEntryPointModifyValue modVal:
Expand Down Expand Up @@ -573,9 +545,41 @@ public static partial void WriteBinaryEffectsCustom(MutagenWriter writer, IPerkR
throw new NotImplementedException();
}
}
else
{
WriteFunctionParameters(writer, effect);
}
using (HeaderExport.Subrecord(writer, RecordTypes.PRKF)) { }
}
}

private static void WriteFunctionParameters(MutagenWriter writer, IAPerkEffectGetter effect)
{
if (effect.PerkEntryID is { } id)
{
using (HeaderExport.Subrecord(writer, RecordTypes.EPFB))
{
writer.Write(id);
}
}
if (effect.ButtonLabel != null)
{
using (HeaderExport.Subrecord(writer, RecordTypes.EPF2))
{
StringBinaryTranslation.Instance.Write(writer, effect.ButtonLabel, StringBinaryType.NullTerminate, StringsSource.Normal);
}
}
if (effect.Flags is { } flags)
{
using (HeaderExport.Subrecord(writer, RecordTypes.EPF3))
{
EnumBinaryTranslation<APerkEffect.Flag, MutagenFrame, MutagenWriter>.Instance.Write(
writer,
flags,
2);
}
}
}
}

partial class PerkRankBinaryOverlay
Expand Down
Loading
Loading