Skip to content
Open
Show file tree
Hide file tree
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
39 changes: 22 additions & 17 deletions src/ending/podium_ceremony_actors.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,35 +137,39 @@ void clear_D_802874D8_actors() {
}

u16 random_u16_credits(void) {
u16 temp1, temp2;
if (CVarGetInteger("gBugfixRNGReset", true) == false) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite understand this change.

The idea is to remove the duplicate function and use the original one. But now the random seed won't have been reset because we're now using gRandomSeed instead of sRandomSeed.

I would recommend one of two options

  1. Just delete random_u16_credits, and modify the game to act how expected using just the one random function
  • This is simpler, makes more sense, etc.
  1. Not call the original random_u16() and just use random_u16_credits()
  • Otherwise it's more likely to get mixed up and confused.

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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not identical behaviour

}

f32 random_who_knows(f32 arg0) {
Expand Down Expand Up @@ -309,6 +313,7 @@ void unused_80280FA8(UNUSED CeremonyActor* actor) {
}

void balloons_and_fireworks_init(void) {
sRandomSeed16 = 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be placed in?

void init_segment_ending_sequences(void) {
#ifdef TARGET_N64
    bzero((void*) SEG_ENDING, SEG_ENDING_SIZE);
    osWritebackDCacheAll();
    dma_copy((u8*) SEG_ENDING, (u8*) SEG_ENDING_ROM_START, SEG_ENDING_ROM_SIZE);
    osInvalICache((void*) SEG_ENDING, SEG_ENDING_SIZE);
    osInvalDCache((void*) SEG_ENDING, SEG_ENDING_SIZE);
#endif
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see it's static. Yea this is fine.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it's not around a CVar?

D_802874D8.actorTimer = 0;
sPodiumActorList = (CeremonyActor*) get_next_available_memory_addr(sizeof(CeremonyActor) * 200);
bzero(sPodiumActorList, (sizeof(CeremonyActor) * 200));
Expand Down
8 changes: 6 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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:
Expand All @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/port/ui/PortMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix random seeding ? Maybe Prevent random seeding from being reset
Or perhaps
Randomize racer spawns and then have the explanation in the tooltip?

.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));
Copy link
Copy Markdown
Contributor

@MegaMech MegaMech Aug 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Racer spawns are not randomized at the start of Grand Prix. Enable this to fix random seeding.
or

Fix random seeding allowing randomized racer spawns at the start of a Grand Prix and randomized firework spawns during the podium ceremony.

(I think I like this one the best so far of everything I've come up with)

}

#ifdef __SWITCH__
Expand Down
Loading