mirror of
https://github.com/kwsch/NHSE.git
synced 2026-08-20 01:26:19 -05:00
Decrypt savefile in-place (less allocation)
Each player and main.dat is ~11MB of allocation to read; old would read & decrypt into separate array = 22MB * (1 + playerCount). Cutting this in half reduces the amount of allocation and keeps stuff off gen2 LOH
This commit is contained in:
@@ -21,12 +21,11 @@ private static byte[] GetParam(uint[] data, in int index)
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decrypts the <see cref="encData"/> using the <see cref="headerData"/>.
|
||||
/// Decrypts the <see cref="encData"/> using the <see cref="headerData"/> in place.
|
||||
/// </summary>
|
||||
/// <param name="headerData">Header Data</param>
|
||||
/// <param name="encData">Encrypted SaveData</param>
|
||||
/// <returns>Decrypted SaveData</returns>
|
||||
public static byte[] Decrypt(byte[] headerData, byte[] encData)
|
||||
public static void Decrypt(byte[] headerData, byte[] encData)
|
||||
{
|
||||
// First 256 bytes go unused
|
||||
var importantData = new uint[0x80];
|
||||
@@ -41,10 +40,8 @@ public static byte[] Decrypt(byte[] headerData, byte[] encData)
|
||||
// Do the AES
|
||||
using var aesCtr = new Aes128CounterMode(counter);
|
||||
var transform = aesCtr.CreateDecryptor(key, counter);
|
||||
var decData = new byte[encData.Length];
|
||||
|
||||
transform.TransformBlock(encData, 0, encData.Length, decData, 0);
|
||||
return decData;
|
||||
transform.TransformBlock(encData, 0, encData.Length, encData, 0);
|
||||
}
|
||||
|
||||
private static CryptoFile GenerateHeaderFile(uint seed, byte[] versionData)
|
||||
|
||||
Reference in New Issue
Block a user