Skip to content

Commit

Permalink
Parse malformed Oblivion string lists better
Browse files Browse the repository at this point in the history
  • Loading branch information
Noggog committed Oct 13, 2024
1 parent dadc93a commit 89142da
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,10 @@ public static IReadOnlyList<T> FactoryByLazyParseWithTrigger<T>(
var subLen = finalPos - stream.Position;
var mem = stream.RemainingMemory.Slice(0, subLen);

if (trimNullSuffix && mem.Length > 0 && mem[^1] == 0)
if (trimNullSuffix
&& mem.Length > 1
&& mem[^1] == 0
&& mem[^2] == 0)
{
mem = mem.Slice(0, mem.Length - 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public ExtendedList<TItem> ParseTrimNullEnding(
BinarySubParseDelegate<TReader, TItem> transl)
{
var ret = new ExtendedList<TItem>();
while (reader.Remaining > 1 || reader.GetUInt8() != 0)
while (reader.Remaining > 1)
{
if (transl(reader, out var subItem))
{
Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions Mutagen.Bethesda.Testing/TestDataPathing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class TestDataPathing
public static ModPath SkyrimPerkFunctionParametersTypeNone = ModPath.FromPath("Files/Skyrim/SkyrimPerkFunctionParametersTypeNone.esp");
public static string OblivionRegion = "Files/Oblivion/Region/OblivionRegion.esp";
public static string OblivionStringLists = "Files/Oblivion/stringlists.esp";
public static string OblivionMalformedStringLists = "Files/Oblivion/malformedstringlists.esp";
public static string SkyrimBodtLength8With42 = "Files/Skyrim/BodyTemplate/BodtLength8With42.esp";
public static string SkyrimBodtLength12With42 = "Files/Skyrim/BodyTemplate/BodtLength12With42.esp";
public static string SkyrimBodtLength8With43 = "Files/Skyrim/BodyTemplate/BodtLength8With43.esp";
Expand Down
15 changes: 15 additions & 0 deletions Mutagen.Bethesda.UnitTests/Plugins/Records/Oblivion/StringLists.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ public class StringLists : ASpecificCaseTest<Creature, ICreatureGetter>
public override GameRelease Release => GameRelease.Oblivion;
public override bool TestPassthrough => false;

public override void TestItem(ICreatureGetter item)
{
item.Models.Should().Equal(
"NDAyleid.NIF",
"NDAyleidLegs.NIF",
"NDMinionHead.NIF");
}
}

public class MalformedStringLists : ASpecificCaseTest<Creature, ICreatureGetter>
{
public override ModPath Path => TestDataPathing.OblivionMalformedStringLists;
public override GameRelease Release => GameRelease.Oblivion;
public override bool TestPassthrough => false;

public override void TestItem(ICreatureGetter item)
{
item.Models.Should().Equal(
Expand Down

0 comments on commit 89142da

Please sign in to comment.