diff --git a/BizHawk.MultiClient/RomGame.cs b/BizHawk.MultiClient/RomGame.cs index 632a09664c..62d444bb77 100644 --- a/BizHawk.MultiClient/RomGame.cs +++ b/BizHawk.MultiClient/RomGame.cs @@ -45,6 +45,9 @@ namespace BizHawk.MultiClient if (file.Extension == ".SMD") RomData = DeInterleaveSMD(RomData); + if (file.Extension == ".Z64" || file.Extension == ".N64" || file.Extension == ".V64") + RomData = SwapN64(RomData); + GameInfo = Database.GetGameInfo(RomData, file.Name); CheckForPatchOptions(); @@ -81,6 +84,46 @@ namespace BizHawk.MultiClient return output; } + private static byte[] SwapN64(byte[] source) + { + // N64 roms are in one of the following formats: + // .Z64 = No swapping + // .N64 = Word Swapped + // .V64 = Bytse Swapped + + // File extension does not always match the format + + int size = source.Length; + byte[] output = new byte[size]; + + // V64 format + if (source[0] == 0x37) + { + for (int i = 0; i < size; i += 2) + { + output[i] = source[i + 1]; + output[i + 1] = source[i]; + } + } + // N64 format + else if (source[0] == 0x40) + { + for (int i = 0; i < size; i += 4) + { + output[i] = source[i + 3]; + output[i + 3] = source[i]; + output[i + 1] = source[i + 2]; + output[i + 2] = source[i + 1]; + } + } + // Z64 format (or some other unknown format) + else + { + return source; + } + return output; + } + private void CheckForPatchOptions() { try