diff --git a/ShadowRando/Views/MainView.axaml.cs b/ShadowRando/Views/MainView.axaml.cs index 34bccf5..388d08a 100644 --- a/ShadowRando/Views/MainView.axaml.cs +++ b/ShadowRando/Views/MainView.axaml.cs @@ -1498,9 +1498,42 @@ private async Task RandomizationProcess() buf = BitConverter.GetBytes(0x38000000 | stageAssociationIDMap[stageids[0] + stagefirst]); Array.Reverse(buf); - buf.CopyTo(dolfile, storyModeStartAddress); - } + // Check the ROM we're patching does not overwrite the Story Mode first stage (Mods using SX Timing) + if (dolfile[storyModeStartAddress] == 0x38 && dolfile[storyModeStartAddress + 1] == 0x0 && + dolfile[storyModeStartAddress + 2] == 0x0 && dolfile[storyModeStartAddress + 3] == 0x64) + { + buf.CopyTo(dolfile, storyModeStartAddress); + } + else + { + // Reloaded 1.2 + if (dolfile[storyModeStartAddress] == 0x4B && dolfile[storyModeStartAddress + 1] == 0xD3 && + dolfile[storyModeStartAddress + 2] == 0x25 && dolfile[storyModeStartAddress + 3] == 0xCC) + { + // 4BD325CC (jmp to 800046FC / 0x16FC) + buf.CopyTo(dolfile, 0x16FC); + } + // Reloaded 1.2 Widescreen + else if (dolfile[storyModeStartAddress] == 0x4B && dolfile[storyModeStartAddress + 1] == 0xD3 && + dolfile[storyModeStartAddress + 2] == 0x26 && dolfile[storyModeStartAddress + 3] == 0x34) + { + // 4BD32634 (jmp to 80004764 / 0x1764) + buf.CopyTo(dolfile, 0x1764); + } + // SX 1.1 & SX 1.1 Widescreen + else if (dolfile[storyModeStartAddress] == 0x4B && dolfile[storyModeStartAddress + 1] == 0xD3 && + dolfile[storyModeStartAddress + 2] == 0x2A && dolfile[storyModeStartAddress + 3] == 0xB4) + { + // 4BD32AB4 (jmp to 80004BE4 / 0x1BE4) + buf.CopyTo(dolfile, 0x1BE4); + } + else { + buf.CopyTo(dolfile, storyModeStartAddress); + Dispatcher.UIThread.Post(() => Utils.ShowSimpleMessage("Unidentified ROM Error", $"The Story Mode Start instruction is unexpected.{Environment.NewLine}Undefined behavior may occur if using this ROM.", ButtonEnum.Ok, Icon.Error)); + } + } + } Dispatcher.UIThread.Post(() => UpdateProgressBar(15)); // patch the route menu to allow stg06xx+ to display next stages