From 74ead67aec0d6c9e40e30bad43ab04e7b5af7996 Mon Sep 17 00:00:00 2001 From: Thomas Rohloff Date: Fri, 18 Jul 2025 20:13:25 +0200 Subject: [PATCH 1/5] Make deterministic spawn bugfix toggleable Signed-off-by: Thomas Rohloff --- src/main.c | 8 ++++++-- src/port/ui/PortMenu.cpp | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 4031da6339..421bf914fb 100644 --- a/src/main.c +++ b/src/main.c @@ -550,6 +550,10 @@ void init_segment_racing(void) { dma_copy((u8*) SEG_RACING, (u8*) SEG_RACING_ROM_START, SEG_RACING_ROM_SIZE); osInvalICache((void*) SEG_RACING, SEG_RACING_SIZE); osInvalDCache((void*) SEG_RACING, SEG_RACING_SIZE); +#else + if (CVarGetInteger("gBugfixDeterministicSpawn", true) == false) { + gRandomSeed16 = 0; + } #endif } @@ -1222,7 +1226,7 @@ void update_gamestate(void) { * @bug Reloading this segment makes random_u16() deterministic for player spawn order. * In laymens terms, random_u16() outputs the same value every time. */ - // init_segment_racing(); + init_segment_racing(); setup_race(); break; case ENDING: @@ -1232,7 +1236,7 @@ void update_gamestate(void) { break; case CREDITS_SEQUENCE: gCurrentlyLoadedCourseId = COURSE_NULL; - // init_segment_racing(); + init_segment_racing(); init_segment_ending_sequences(); load_credits(); break; diff --git a/src/port/ui/PortMenu.cpp b/src/port/ui/PortMenu.cpp index ba180d5b97..1678946c05 100644 --- a/src/port/ui/PortMenu.cpp +++ b/src/port/ui/PortMenu.cpp @@ -410,6 +410,12 @@ void PortMenu::AddEnhancements() { }) .Options(UIWidgets::CheckboxOptions({ { .tooltip = "Edit the universe!" } })); #endif + + path = { "Enhancements", "Bugfixes", SECTION_COLUMN_1 }; + AddSidebarEntry("Enhancements", "Bugfixes", 3); + AddWidget(path, "Deterministic Spawn", WIDGET_CVAR_CHECKBOX) + .CVar("gBugfixDeterministicSpawn") + .Options(CheckboxOptions().Tooltip("This fixes players always spawning at the same position when starting a new cup").DefaultValue(true)); } #ifdef __SWITCH__ From 676225767258c8e8a43e49279ce3248f6703e0ed Mon Sep 17 00:00:00 2001 From: Thomas Rohloff Date: Fri, 18 Jul 2025 21:06:39 +0200 Subject: [PATCH 2/5] Make option false by default Signed-off-by: Thomas Rohloff --- src/main.c | 2 +- src/port/ui/PortMenu.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 421bf914fb..fd543a8cf0 100644 --- a/src/main.c +++ b/src/main.c @@ -551,7 +551,7 @@ void init_segment_racing(void) { osInvalICache((void*) SEG_RACING, SEG_RACING_SIZE); osInvalDCache((void*) SEG_RACING, SEG_RACING_SIZE); #else - if (CVarGetInteger("gBugfixDeterministicSpawn", true) == false) { + if (CVarGetInteger("gBugfixDeterministicSpawn", false) == false) { gRandomSeed16 = 0; } #endif diff --git a/src/port/ui/PortMenu.cpp b/src/port/ui/PortMenu.cpp index 1678946c05..ca4dfa256a 100644 --- a/src/port/ui/PortMenu.cpp +++ b/src/port/ui/PortMenu.cpp @@ -415,7 +415,7 @@ void PortMenu::AddEnhancements() { AddSidebarEntry("Enhancements", "Bugfixes", 3); AddWidget(path, "Deterministic Spawn", WIDGET_CVAR_CHECKBOX) .CVar("gBugfixDeterministicSpawn") - .Options(CheckboxOptions().Tooltip("This fixes players always spawning at the same position when starting a new cup").DefaultValue(true)); + .Options(CheckboxOptions().Tooltip("This fixes players always spawning at the same position when starting a new cup").DefaultValue(false)); } #ifdef __SWITCH__ From 9d05ebc43cf0d35d9494620766626f50fb4ca8e7 Mon Sep 17 00:00:00 2001 From: Thomas Rohloff Date: Sat, 19 Jul 2025 10:46:56 +0200 Subject: [PATCH 3/5] Reset podium PRNG and make it replaceable with cstd rand(), too Signed-off-by: Thomas Rohloff --- src/ending/podium_ceremony_actors.c | 39 ++++++++++++++++------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/src/ending/podium_ceremony_actors.c b/src/ending/podium_ceremony_actors.c index 28884b9972..1966d593d5 100644 --- a/src/ending/podium_ceremony_actors.c +++ b/src/ending/podium_ceremony_actors.c @@ -137,35 +137,39 @@ void clear_D_802874D8_actors() { } u16 random_u16_credits(void) { - u16 temp1, temp2; + if (CVarGetInteger("gBugfixDeterministicSpawn", false) == false) { + u16 temp1, temp2; - if (sRandomSeed16 == 22026) { - sRandomSeed16 = 0; - } + if (sRandomSeed16 == 22026) { + sRandomSeed16 = 0; + } - temp1 = (sRandomSeed16 & 0x00FF) << 8; - temp1 = temp1 ^ sRandomSeed16; + temp1 = (sRandomSeed16 & 0x00FF) << 8; + temp1 = temp1 ^ sRandomSeed16; - sRandomSeed16 = ((temp1 & 0x00FF) << 8) + ((temp1 & 0xFF00) >> 8); + sRandomSeed16 = ((temp1 & 0x00FF) << 8) + ((temp1 & 0xFF00) >> 8); - temp1 = ((temp1 & 0x00FF) << 1) ^ sRandomSeed16; - temp2 = (temp1 >> 1) ^ 0xFF80; + temp1 = ((temp1 & 0x00FF) << 1) ^ sRandomSeed16; + temp2 = (temp1 >> 1) ^ 0xFF80; - if ((temp1 & 1) == 0) { - if (temp2 == 43605) { - sRandomSeed16 = 0; + if ((temp1 & 1) == 0) { + if (temp2 == 43605) { + sRandomSeed16 = 0; + } else { + sRandomSeed16 = temp2 ^ 0x1FF4; + } } else { - sRandomSeed16 = temp2 ^ 0x1FF4; + sRandomSeed16 = temp2 ^ 0x8180; } - } else { - sRandomSeed16 = temp2 ^ 0x8180; + + return sRandomSeed16; } - return sRandomSeed16; + return random_u16(); } f32 random_float_between_0_and_1(void) { - return random_u16_credits() / 65536.0f; + return random_u16_credits() / (f32) UINT16_MAX; } f32 random_who_knows(f32 arg0) { @@ -309,6 +313,7 @@ void unused_80280FA8(UNUSED CeremonyActor* actor) { } void balloons_and_fireworks_init(void) { + sRandomSeed16 = 0; D_802874D8.actorTimer = 0; sPodiumActorList = (CeremonyActor*) get_next_available_memory_addr(sizeof(CeremonyActor) * 200); bzero(sPodiumActorList, (sizeof(CeremonyActor) * 200)); From 616767572789e85918ca70958b33baf5a0f3dd75 Mon Sep 17 00:00:00 2001 From: Thomas Rohloff Date: Thu, 31 Jul 2025 10:04:35 +0200 Subject: [PATCH 4/5] Rename option Signed-off-by: Thomas Rohloff --- src/ending/podium_ceremony_actors.c | 2 +- src/main.c | 2 +- src/port/ui/PortMenu.cpp | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ending/podium_ceremony_actors.c b/src/ending/podium_ceremony_actors.c index 1966d593d5..e2b4d25229 100644 --- a/src/ending/podium_ceremony_actors.c +++ b/src/ending/podium_ceremony_actors.c @@ -137,7 +137,7 @@ void clear_D_802874D8_actors() { } u16 random_u16_credits(void) { - if (CVarGetInteger("gBugfixDeterministicSpawn", false) == false) { + if (CVarGetInteger("gBugfixRNGReset", false) == false) { u16 temp1, temp2; if (sRandomSeed16 == 22026) { diff --git a/src/main.c b/src/main.c index fd543a8cf0..c709e14836 100644 --- a/src/main.c +++ b/src/main.c @@ -551,7 +551,7 @@ void init_segment_racing(void) { osInvalICache((void*) SEG_RACING, SEG_RACING_SIZE); osInvalDCache((void*) SEG_RACING, SEG_RACING_SIZE); #else - if (CVarGetInteger("gBugfixDeterministicSpawn", false) == false) { + if (CVarGetInteger("gBugfixRNGReset", false) == false) { gRandomSeed16 = 0; } #endif diff --git a/src/port/ui/PortMenu.cpp b/src/port/ui/PortMenu.cpp index ca4dfa256a..d592d6e440 100644 --- a/src/port/ui/PortMenu.cpp +++ b/src/port/ui/PortMenu.cpp @@ -413,9 +413,9 @@ void PortMenu::AddEnhancements() { path = { "Enhancements", "Bugfixes", SECTION_COLUMN_1 }; AddSidebarEntry("Enhancements", "Bugfixes", 3); - AddWidget(path, "Deterministic Spawn", WIDGET_CVAR_CHECKBOX) - .CVar("gBugfixDeterministicSpawn") - .Options(CheckboxOptions().Tooltip("This fixes players always spawning at the same position when starting a new cup").DefaultValue(false)); + AddWidget(path, "Don't reset random seed", WIDGET_CVAR_CHECKBOX) + .CVar("gBugfixRNGReset") + .Options(CheckboxOptions().Tooltip("The section handling of MK8 zeroes the random seed before races. Enable this to never zero the seed.").DefaultValue(false)); } #ifdef __SWITCH__ From 2e6a5c422e2139843207f83e748c55e9cc5259f1 Mon Sep 17 00:00:00 2001 From: Thomas Rohloff Date: Thu, 31 Jul 2025 10:07:52 +0200 Subject: [PATCH 5/5] Revert "Make option false by default" This reverts commit 676225767258c8e8a43e49279ce3248f6703e0ed as talked up on Discord. --- src/ending/podium_ceremony_actors.c | 2 +- src/main.c | 2 +- src/port/ui/PortMenu.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ending/podium_ceremony_actors.c b/src/ending/podium_ceremony_actors.c index e2b4d25229..5161bbad07 100644 --- a/src/ending/podium_ceremony_actors.c +++ b/src/ending/podium_ceremony_actors.c @@ -137,7 +137,7 @@ void clear_D_802874D8_actors() { } u16 random_u16_credits(void) { - if (CVarGetInteger("gBugfixRNGReset", false) == false) { + if (CVarGetInteger("gBugfixRNGReset", true) == false) { u16 temp1, temp2; if (sRandomSeed16 == 22026) { diff --git a/src/main.c b/src/main.c index c709e14836..944f76cffa 100644 --- a/src/main.c +++ b/src/main.c @@ -551,7 +551,7 @@ void init_segment_racing(void) { osInvalICache((void*) SEG_RACING, SEG_RACING_SIZE); osInvalDCache((void*) SEG_RACING, SEG_RACING_SIZE); #else - if (CVarGetInteger("gBugfixRNGReset", false) == false) { + if (CVarGetInteger("gBugfixRNGReset", true) == false) { gRandomSeed16 = 0; } #endif diff --git a/src/port/ui/PortMenu.cpp b/src/port/ui/PortMenu.cpp index d592d6e440..2f8feeb436 100644 --- a/src/port/ui/PortMenu.cpp +++ b/src/port/ui/PortMenu.cpp @@ -415,7 +415,7 @@ void PortMenu::AddEnhancements() { AddSidebarEntry("Enhancements", "Bugfixes", 3); AddWidget(path, "Don't reset random seed", WIDGET_CVAR_CHECKBOX) .CVar("gBugfixRNGReset") - .Options(CheckboxOptions().Tooltip("The section handling of MK8 zeroes the random seed before races. Enable this to never zero the seed.").DefaultValue(false)); + .Options(CheckboxOptions().Tooltip("The section handling of MK8 zeroes the random seed before races. Enable this to never zero the seed.").DefaultValue(true)); } #ifdef __SWITCH__