mirror of
https://github.com/Barubary/dsdecmp.git
synced 2024-06-01 08:08:48 +02:00
C#: removed the BitConverter reference in the Huffman decompressor, and replaced the call with one to a local utility method (to be sure that the byte*->u32 conversion always uses the correct endianness.
This commit is contained in:
parent
8a5583c308
commit
468e2e645e
|
@ -123,7 +123,7 @@ namespace DSDecmp.Formats.Nitro
|
|||
if (nRead < 4)
|
||||
throw new StreamTooShortException();
|
||||
readBytes += nRead;
|
||||
data = BitConverter.ToUInt32(buffer, 0);
|
||||
data = IOUtils.ToNDSu32(buffer, 0);
|
||||
bitsLeft = 32;
|
||||
}
|
||||
// get the next bit
|
||||
|
|
27
CSharp/DSDecmp/Utils/IOUtils.cs
Normal file
27
CSharp/DSDecmp/Utils/IOUtils.cs
Normal file
|
@ -0,0 +1,27 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace DSDecmp
|
||||
{
|
||||
/// <summary>
|
||||
/// Class for I/O-related utility methods.
|
||||
/// </summary>
|
||||
public static class IOUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns a 4-byte unsigned integer as used on the NDS converted from four bytes
|
||||
/// at a specified position in a byte array.
|
||||
/// </summary>
|
||||
/// <param name="buffer">The source of the data.</param>
|
||||
/// <param name="offset">The location of the data in the source.</param>
|
||||
/// <returns>The indicated 4 bytes converted to uint</returns>
|
||||
public static uint ToNDSu32(byte[] buffer, int offset)
|
||||
{
|
||||
return (uint)(buffer[offset]
|
||||
| (buffer[offset + 1] << 8)
|
||||
| (buffer[offset + 2] << 16)
|
||||
| (buffer[offset + 3] << 24));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user