Skip to content

Commit

Permalink
fix(Steam): meta file enrcyption
Browse files Browse the repository at this point in the history
  • Loading branch information
cengelha committed Jul 21, 2024
1 parent 829aab1 commit 85c015f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
14 changes: 7 additions & 7 deletions libNOM.io/PlatformSteam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,15 @@ 91. EMPTY ( 20) // META_FORMAT_4
}
if (container.IsSave)
{
// Extended metadata since Waypoint 4.00.
UpdateContainerWithWaypointMetaInformation(container, disk);
// Extended metadata since Waypoint 4.00.
UpdateContainerWithWaypointMetaInformation(container, disk);

// Extended metadata including a new META_FORMAT since Worlds 5.00.
UpdateContainerWithWorldsMetaInformation(container, disk, decompressed);

// GameVersion with BaseVersion only is not 100% accurate but good enough to calculate SaveVersion.
container.SaveVersion = Meta.SaveVersion.Calculate(container, Meta.GameVersion.Get(container.Extra.BaseVersion));
}
// GameVersion with BaseVersion only is not 100% accurate but good enough to calculate SaveVersion.
container.SaveVersion = Meta.SaveVersion.Calculate(container, Meta.GameVersion.Get(container.Extra.BaseVersion));
}
}

// Size is save to write always.
Expand Down Expand Up @@ -299,7 +299,7 @@ protected override Span<uint> DecryptMeta(Container container, Span<byte> meta)

uint i1 = (current >> 3) ^ (result[valueIndex] << 4);
uint i2 = (current * 4) ^ (result[valueIndex] >> 5);
uint i3 = (result[valueIndex] ^ key[keyIndex]);
uint i3 = (result[valueIndex] ^ key[keyIndex]); // [(0 & 3) ^ keyIndex] as in j3 to be precise (0 would be the last executed index) but (0 & 3) is always zero and therefore does not matter
uint i4 = (current ^ hash);
result[0] -= (i1 + i2) ^ (i3 + i4);

Expand Down Expand Up @@ -441,7 +441,7 @@ protected override ReadOnlySpan<byte> EncryptMeta(Container container, ReadOnlyS

uint i1 = (value[0] >> 3) ^ (current << 4);
uint i2 = (value[0] * 4) ^ (current >> 5);
uint i3 = (current ^ key[keyIndex ^ 1]);
uint i3 = (current ^ key[(lastIndex & 3) ^ keyIndex]);
uint i4 = (value[0] ^ hash);
value[lastIndex] += (i1 + i2) ^ (i3 + i4);
current = value[lastIndex];
Expand Down
2 changes: 1 addition & 1 deletion libNOM.io/libNOM.io.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

<!-- Package -->
<PropertyGroup Label="General">
<Version>0.10.0-beta.8</Version>
<Version>0.10.0-beta.9</Version>
<Authors>cengelha</Authors>
<Description>Provides reading and writing save files from the game No Man's Sky for all possible platforms as well as related actions.</Description>
<Copyright>Copyright (c) Christian Engelhardt 2021</Copyright>
Expand Down
22 changes: 22 additions & 0 deletions libNOM.test/Steam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,28 @@ private static void AssertCommonMeta(IContainer container, uint[] metaA, uint[]
Assert.IsTrue(metaA.Skip(20).SequenceEqual(metaB.Skip(20)));
}
}
else if (metaA.Length == META_LENGTH_TOTAL_WORLDS)
{
AssertAllAreEqual(META_FORMAT_4, metaA[1], metaB[1]);

if (container.IsAccount)
{
AssertAllNotZero(metaA.Skip(2).Take(4), metaB.Skip(2).Take(4));
AssertAllNotZero(metaA.Skip(6).Take(8), metaB.Skip(6).Take(8));
AssertAllZero(metaA.Skip(14), metaB.Skip(14));
}
else
{
AssertAllZero(metaA.Skip(2).Take(12), metaB.Skip(2).Take(12));
AssertAllNotZero(metaA.Skip(14).Take(2), metaB.Skip(14).Take(2));
AssertAllZero(metaA[16], metaB[16]);
Assert.IsTrue(metaA.Skip(20).Take(69).SequenceEqual(metaB.Skip(20).Take(69)));
AssertAllNotZero(metaA[89], metaB[89]);
AssertAllAreEqual(META_FORMAT_4, metaA[90], metaB[90]);
AssertAllZero(metaA.Skip(91), metaB.Skip(91));

}
}
else
throw new AssertFailedException();
}
Expand Down

0 comments on commit 85c015f

Please sign in to comment.