Skip to content

Rewrite scarecrow hacks in C#2508

Closed
GSKirox wants to merge 3 commits into
OoTRandomizer:Devfrom
GSKirox:scarecrow_c_rewrite
Closed

Rewrite scarecrow hacks in C#2508
GSKirox wants to merge 3 commits into
OoTRandomizer:Devfrom
GSKirox:scarecrow_c_rewrite

Conversation

@GSKirox

@GSKirox GSKirox commented Jan 2, 2026

Copy link
Copy Markdown
Collaborator

Rewrites the scarecrow hacks in rando to C to get rid of a faulty asm block, see mracsys analysis here : #2492 (comment)

The current Scarecrow hack hooks in this place :
https://github.com/zeldaret/oot/blob/main/src/code/z_message.c#L3744
So we can directly hook instead to a C function with the same arguments, and armed with more decomp knowledge than back then. The goal is to keep the same fixes as the original 2 PR : #167 and #359

This new function has 3 parts :

  • Check if the first note is a rest (PR 167)
  • Put a minimum of 4 for each note length (PR 359)
  • Do the displaced Memcpy

@GSKirox GSKirox added Type: Bug Something isn't working Component: ASM/C Changes some internals of the ASM/C libraries Status: Needs Review Someone should be looking at it Status: Needs Testing Probably should be tested labels Jan 2, 2026
Comment thread ASM/c/scarecrow.c Outdated

// Fix the length of each note to a minimum.
OcarinaNote* scarecrow_song = (OcarinaNote*)src;
for (uint8_t i = 0; i < 8; i++) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There can be rests in between notes, so the song is not necessarily just 8 OcarinaNotes long. You should check the entire 20-note buffer, updating the length if pitch is non-zero. I know the original C hack only updated the first 8 OcarinaNotes, but we should make it correct while we're in here.

Lowest note is 0x02 (OCARINA_PITCH_D4) assuming no stick/Z-button modifiers. Trying to record a song with modifiers actually ignored the modifiers when playtesting, so it's safe to assume 0x02 as the lower bound for a player input.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If we wanted to try fixing the 9-note problem, we could also use this loop to count non-rest notes and zero everything out after the 8th one in the buffer. IMO that should be saved for another PR given the time pressure.

Comment thread ASM/c/scarecrow.c
}
}

// Displaced Memcpy

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why not use the existing MemCpy function? No actual problem with the code below, just curious.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Laziness honestly, since the function is just a couple of lines

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sounds good. For future reference, it's already defined in z64.h as z64_memcopy.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Wait how did i miss that lol, i thought this wasn't interfaced already.

@flagrama

flagrama commented Jan 2, 2026

Copy link
Copy Markdown

also could you run this code through the compiler with -Wall and fix any warnings it finds (if any) without commiting -Wall itself. Should keep reenabling -Wall easier

@GSKirox

GSKirox commented Jan 2, 2026

Copy link
Copy Markdown
Collaborator Author

No new warning for building scarecrow.o with -Wall 👍

TreZc0 added a commit that referenced this pull request Jan 2, 2026
…imes hints that were unintentionally excluded (#2509)
@TreZc0 TreZc0 closed this Jan 2, 2026
TreZc0 added a commit that referenced this pull request Jan 2, 2026
…imes hints that were unintentionally excluded (#2509)
@fenhl fenhl removed Status: Needs Review Someone should be looking at it Status: Needs Testing Probably should be tested labels Jan 2, 2026
@fenhl fenhl added this to the 9.0 milestone Jan 2, 2026
@fenhl fenhl mentioned this pull request Jan 2, 2026
GSKirox pushed a commit to GSKirox/OoT-Randomizer that referenced this pull request Jan 4, 2026
…dd some sometimes hints that were unintentionally excluded (OoTRandomizer#2509)
@GSKirox GSKirox deleted the scarecrow_c_rewrite branch January 5, 2026 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: ASM/C Changes some internals of the ASM/C libraries Type: Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants