Use OpenRA CRC32
This commit is contained in:
committed by
Gustas Kažukauskas
parent
78873b8e00
commit
d0ca1af555
@@ -11,7 +11,7 @@
|
||||
|
||||
using System;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.FileFormats
|
||||
namespace OpenRA.FileFormats
|
||||
{
|
||||
/// <summary>
|
||||
/// Static class that uses a lookup table to calculates CRC32
|
||||
@@ -118,5 +118,16 @@ namespace OpenRA.Mods.Cnc.FileFormats
|
||||
{
|
||||
return Calculate(data, 0xFFFFFFFF);
|
||||
}
|
||||
|
||||
// Chaining method: accepts the current CRC state
|
||||
public static uint Update(uint crc, ReadOnlySpan<byte> data)
|
||||
{
|
||||
for (var i = 0; i < data.Length; i++)
|
||||
crc = (crc >> 8) ^ LookUp[(crc & 0xFF) ^ data[i]];
|
||||
return crc;
|
||||
}
|
||||
|
||||
// Standard PNG start: 0xFFFFFFFF, Finalize: XOR 0xFFFFFFFF
|
||||
public static uint Finish(uint crc) => crc ^ 0xFFFFFFFF;
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,6 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using ICSharpCode.SharpZipLib.Checksum;
|
||||
using ICSharpCode.SharpZipLib.Zip.Compression;
|
||||
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
|
||||
using OpenRA.Graphics;
|
||||
@@ -333,10 +332,12 @@ namespace OpenRA.FileFormats
|
||||
var data = input.ReadAllBytes();
|
||||
output.Write(data);
|
||||
|
||||
var crc32 = new Crc32();
|
||||
crc32.Update(typeBytes);
|
||||
crc32.Update(data);
|
||||
output.Write(IPAddress.NetworkToHostOrder((int)crc32.Value));
|
||||
var crc = 0xFFFFFFFF;
|
||||
crc = CRC32.Update(crc, typeBytes);
|
||||
crc = CRC32.Update(crc, data);
|
||||
var finalCrc = CRC32.Finish(crc);
|
||||
|
||||
output.Write(IPAddress.NetworkToHostOrder((int)finalCrc));
|
||||
}
|
||||
|
||||
public byte[] Save(Compression compression = Compression.BEST_COMPRESSION)
|
||||
|
||||
@@ -14,7 +14,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using OpenRA.Mods.Cnc.FileFormats;
|
||||
using OpenRA.FileFormats;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.FileSystem
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user