2011-04-07 15:51:09 +02:00
|
|
|
|
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));
|
|
|
|
|
}
|
2011-05-15 13:40:14 +02:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Converts a u32 value into a sequence of bytes that would make ToNDSu32 return
|
|
|
|
|
/// the given input value.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static byte[] FromNDSu32(uint value)
|
|
|
|
|
{
|
|
|
|
|
return new byte[] {
|
|
|
|
|
(byte)(value & 0xFF),
|
|
|
|
|
(byte)((value >> 8) & 0xFF),
|
|
|
|
|
(byte)((value >> 16) & 0xFF),
|
|
|
|
|
(byte)((value >> 24) & 0xFF)
|
|
|
|
|
};
|
|
|
|
|
}
|
2011-04-07 15:51:09 +02:00
|
|
|
|
}
|
|
|
|
|
}
|