diff --git a/src/ending/podium_ceremony_actors.c b/src/ending/podium_ceremony_actors.c index 28884b9972..5161bbad07 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("gBugfixRNGReset", true) == 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)); diff --git a/src/main.c b/src/main.c index 4031da6339..944f76cffa 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("gBugfixRNGReset", 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..2f8feeb436 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, "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(true)); } #ifdef __SWITCH__