private void OpenScriptResourceLittleEndian(uint id)
{
bool needByteSwap = false;
if (_isBigEndian)
{
// Cluster files are in big endian fomat.
// If the resource are not in memory anymore, and therefore will be read
// from disk, they will need to be byte swaped.
MemHandle memHandle = ResHandle(id);
if (memHandle != null)
needByteSwap = (memHandle.cond == MemMan.MEM_FREED);
}
ResOpen(id);
if (needByteSwap)
{
MemHandle handle = ResHandle(id);
if (handle == null)
return;
// uint32 totSize = handle.size;
Header head = new Header(handle.data);
head.comp_length = ScummHelper.SwapBytes(head.comp_length);
head.decomp_length = ScummHelper.SwapBytes(head.decomp_length);
head.version = ScummHelper.SwapBytes(head.version);
UIntAccess data = new UIntAccess(handle.data, Header.Size);
uint size = handle.size - Header.Size;
if ((size & 3) != 0)
throw new InvalidOperationException($"Odd size during script endian conversion. Resource ID ={id}, size = {size}");
size >>= 2;
for (uint cnt = 0; cnt < size; cnt++)
{
data[0] = ScummHelper.SwapBytes(data[0]);
data.Offset += 4;
}
}
}