Skip to content

Commit

Permalink
Starfield PERS record
Browse files Browse the repository at this point in the history
  • Loading branch information
Noggog committed Aug 14, 2024
1 parent 5275305 commit c2b3021
Show file tree
Hide file tree
Showing 13 changed files with 4,641 additions and 7 deletions.
12 changes: 12 additions & 0 deletions Mutagen.Bethesda.Starfield/Mutagen.Bethesda.Starfield.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2381,6 +2381,9 @@
<Compile Include="Records\Major Records\PerkScriptFragments.cs">
<DependentUpon>Perk.xml</DependentUpon>
</Compile>
<Compile Include="Records\Major Records\PERS.cs">
<DependentUpon>PERS.xml</DependentUpon>
</Compile>
<Compile Include="Records\Major Records\PhotoModeFeature.cs">
<DependentUpon>PhotoModeFeature.xml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -6672,5 +6675,14 @@
<Compile Include="Records\Major Records\ATerminalMenuItemTarget_Generated.cs">
<DependentUpon>TerminalMenu.xml</DependentUpon>
</Compile>
<Compile Include="Records\Major Records\PERS_Generated.cs">
<DependentUpon>PERS.xml</DependentUpon>
</Compile>
<Compile Include="Records\Major Records\PERSItem_Generated.cs">
<DependentUpon>PERS.xml</DependentUpon>
</Compile>
<Compile Include="Records\Major Records\PERSItems_Generated.cs">
<DependentUpon>PERS.xml</DependentUpon>
</Compile>
</ItemGroup>
</Project>
104 changes: 104 additions & 0 deletions Mutagen.Bethesda.Starfield/Records/Major Records/PERS.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
using Mutagen.Bethesda.Plugins.Binary.Overlay;
using Mutagen.Bethesda.Plugins.Binary.Streams;
using Mutagen.Bethesda.Plugins.Binary.Translations;
using Mutagen.Bethesda.Plugins.Internals;
using Mutagen.Bethesda.Starfield.Internals;
using NexusMods.Paths.Trees.Traits;

namespace Mutagen.Bethesda.Starfield;

partial class PERSBinaryCreateTranslation
{
internal static readonly IReadOnlyRecordCollection Targets = RecordCollection.Factory(RecordTypes.XXXX, RecordTypes.DAT2);

public static partial ParseResult FillBinaryItemsParseCustom(
MutagenFrame frame,
IPERSInternal item,
PreviousParse lastParsed)
{
frame = frame.SpawnAll();
item.Items.Clear();
int? contentLen = null;
while (frame.TryGetSubrecord(Targets, out var subRec))
{
if (subRec.RecordType == RecordTypes.XXXX)
{
contentLen = subRec.AsInt32();
frame.Position += subRec.TotalLength;
}
else
{
if (contentLen == null)
{
contentLen = subRec.ContentLength;
}
frame.Position += subRec.HeaderLength;

var items = Mutagen.Bethesda.Plugins.Binary.Translations.ListBinaryTranslation<PERSItem>.Instance.Parse(
reader: frame.SpawnWithLength(contentLen.Value),
transl: PERSItem.TryCreateFromBinary);
item.Items.Add(new PERSItems()
{
Items = items
});
}
}

return (int)PERS_FieldIndex.Items;
}
}

partial class PERSBinaryWriteTranslation
{
public static partial void WriteBinaryItemsParseCustom(
MutagenWriter writer,
IPERSGetter item)
{
foreach (var x in item.Items)
{
using (HeaderExport.Subrecord(writer, RecordTypes.DAT2,
overflowRecord: RecordTypes.XXXX,
out var writerToUse))
{
x.WriteToBinary(writerToUse);
}
}
}
}

partial class PERSBinaryOverlay
{
public IReadOnlyList<IPERSItemsGetter> Items { get; private set; } = Array.Empty<IPERSItemsGetter>();

public partial ParseResult ItemsParseCustomParse(
OverlayStream stream,
int offset,
PreviousParse lastParsed)
{
var itemsList = new List<IPERSItemsGetter>();
int? contentLen = null;
while (stream.TryGetSubrecord(PERSBinaryCreateTranslation.Targets, out var subRec))
{
if (subRec.RecordType == RecordTypes.XXXX)
{
contentLen = subRec.AsInt32();
stream.Position += subRec.TotalLength;
}
else
{
if (contentLen == null)
{
contentLen = subRec.ContentLength;
}

stream.Position += subRec.HeaderLength;

itemsList.Add(PERSItemsBinaryOverlay.PERSItemsFactory(stream.ReadMemory(contentLen.Value), _package));
}
}

Items = itemsList;

return (int)PERS_FieldIndex.Items;
}
}
25 changes: 25 additions & 0 deletions Mutagen.Bethesda.Starfield/Records/Major Records/PERS.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="us-ascii"?>
<Loqui xmlns="http://tempuri.org/LoquiSource.xsd">
<Object name="PERS" recordType="PERS" objType="Record" baseClass="StarfieldMajorRecord">
<Fields>
<UInt32 name="DATA" recordType="DATA" unknown="true" />
<CustomLogic name="ItemsParse">
<RecordType>XXXX</RecordType>
<RecordType>DAT2</RecordType>
</CustomLogic>
<RefList name="Items" refName="PERSItems" unknown="true" binary="NoGeneration" />
</Fields>
</Object>
<Object name="PERSItems" objType="Subrecord">
<Fields>
<RefList name="Items" refName="PERSItem" unknown="true" />
</Fields>
</Object>
<Object name="PERSItem" objType="Subrecord">
<Fields>
<FormLink name="Record" refName="StarfieldMajorRecord" />
<UInt32 name="Unknown1" unknown="true" />
<UInt32 name="Unknown2" unknown="true" />
</Fields>
</Object>
</Loqui>
Loading

0 comments on commit c2b3021

Please sign in to comment.