Mother2GbaTranslation/tools/ScriptTool/Extensions.cs

55 lines
1.5 KiB
C#
Raw Normal View History

2015-03-13 22:04:23 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ScriptTool
{
public static class Extensions
{
public static int ReadInt(this byte[] rom, int address)
{
int value = rom[address] |
(rom[address + 1] << 8) |
(rom[address + 2] << 16) |
(rom[address + 3] << 24);
return value;
}
public static int ReadSnesPointer(this byte[] rom, int address)
{
int offset = rom.ReadInt(address);
if (offset == 0) return 0;
return offset - 0xC00000;
}
public static int ReadGbaPointer(this byte[] rom, int address)
{
int offset = rom.ReadInt(address);
if (offset == 0) return 0;
return offset & 0x1FFFFFF;
}
2015-03-16 04:16:12 +00:00
public static void AddInt(this IList<byte> list, int value)
{
list.Add((byte)(value & 0xFF));
list.Add((byte)((value >> 8) & 0xFF));
list.Add((byte)((value >> 16) & 0xFF));
list.Add((byte)((value >> 24) & 0xFF));
}
2017-03-19 16:18:52 +00:00
public static int ReadShort(this byte[] rom, int address)
{
int value = rom[address] | (rom[address + 1] << 8);
return value;
}
2018-12-14 05:48:47 +00:00
public static int AlignTo(this int address, int alignBytes)
{
int mask = alignBytes - 1;
return ((address - 1) & ~mask) + alignBytes;
}
2015-03-13 22:04:23 +00:00
}
}