Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SX Based ROMs - Timing Override Fix #13

Merged
merged 3 commits into from
Sep 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions ShadowRando/Views/MainView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1498,9 +1498,42 @@ private async Task<int> 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
Expand Down