Skip to content

Add Y distance check to business Deku Scrub talk#2552

Open
djevangelia wants to merge 5 commits into
OoTRandomizer:Devfrom
djevangelia:dekyscruby
Open

Add Y distance check to business Deku Scrub talk#2552
djevangelia wants to merge 5 commits into
OoTRandomizer:Devfrom
djevangelia:dekyscruby

Conversation

@djevangelia

Copy link
Copy Markdown

ASM fix to add Y distance check to business Deku Scrub talking, which includes selling items. Fixes #2285.

Deku Scrubs have a Y distance check for giving the item, but not for selling it. In MQ Deku Tree player can buy the item from the water (is within XZ distance), but cannot receive it (is outside Y distance), potentially losing the check. This adds Y distance check of 100.0f to talking, which is the same as receiving item.

The float distance checking is 100% a product of disassembly of C code and I cannot explain how it works at all, but it does. I used matching decomp NTSC 1.0 as base, added check, took the disassembly and modified it to fit with jumps.

Testing

Works in Ares 1.47, Project64 3.0.1 and Mupen64plus 2.8. https://www.youtube.com/watch?v=qhhwmbkHhbo
Tested with adult as well.
I have not tested any scrubs beyond MQ Deku Tree and Lost Woods bridge. If the added check somehow would mess with a scrub I'll look into how that could be solved. A scene id check could be added to make this change only apply to the MQ Deku Tree scrub etc.

@flagrama

Copy link
Copy Markdown

If the code doesn't make sense in ASM but makes sense in C, I think you should create a C function for it instead. You're already successfully recompiling the C which isn't necessary for ASM only hacks, so you have already finished the hard part of getting a toolchain setup. Instead of creating a label EnDns_CheckYDist in a ASM file, create a C file or add to an appropriate existing one a function called EnDns_CheckYDist. You may need to make adjustments to the jumping code for calling convention needs to send the right arguments, or you may not, but you can get help in the dev channel on Discord if needed.

@djevangelia

djevangelia commented Apr 15, 2026

Copy link
Copy Markdown
Author

Instead of creating a label EnDns_CheckYDist in a ASM file, create a C file or add to an appropriate existing one a function called EnDns_CheckYDist.

Thanks, I think I will do this with more advanced hacks.

@fenhl fenhl 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 labels Apr 16, 2026
@GSKirox

GSKirox commented Apr 17, 2026

Copy link
Copy Markdown
Collaborator

I agree with flagrama that, if possible, readable C code is preferable to ASM magic no one can explain. We had issues last year with old ASM hacks that no one really understood anymore and that we had to fix anyway.
Not saying we'll have to fix yours, but if the og contributor cannot even explain the code, it's hard to even review correctly.

@djevangelia

Copy link
Copy Markdown
Author

Now a few days later I am more experienced with floats and updated the asm with comments.

This is how it looks with breakpoint at addi ra,ra,0x8c (increase ra to return at function end if absolute Y distance >= 100.0f): https://www.youtube.com/watch?v=0-0VfNodJhw

@GSKirox GSKirox left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Aside from this question, i understand the rest of the fix, and i did also test it and everything seems to work fine.

Comment thread ASM/src/endns_checkydist.asm Outdated
c.lt.s $f0,$f4 ; Y distance < 100.0f?
bc1tl @@EnDns_YReturn ; If yes, continue function
nop ; Else...
addi ra,ra,0x8c ; Go to 0x80a7550c (EnDns_Idle function return)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm assuming this forces an early return but i've never seen this syntax before.
This adds some value to the return register?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, increase the return address by 0x8c to return to the end of calling function

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sorry for the late answer, I was asking around because i remembered some warning about the ra register.
Turns out we did have issues before when trying to do this sort of thing on VC :
https://github.com/OoTRandomizer/OoT-Randomizer/pull/2345/changes
This kokiri actor hack previously added a value to the ra register and this caused inconsistent crashes on VC.
There was a big discussion about it on the discord and the conclusion was that we should never assume the state of the RA register and basically just avoid ever touching it other than with jr ra.
Feel free to bring this up more in the #dev-public-talk channel, mracsys and flagrama who poked around this issue last time should be able to have more elements.

@GSKirox GSKirox added the Status: Waiting for Author Changes or response requested label May 18, 2026
@fenhl fenhl requested a review from GSKirox May 18, 2026 21:03
@fenhl fenhl added Status: Waiting for Author Changes or response requested and removed Status: Waiting for Author Changes or response requested labels May 18, 2026
@djevangelia

Copy link
Copy Markdown
Author

Updated with no ra manipulation. Tested on Ares and Project64.

@fenhl fenhl removed the Status: Waiting for Author Changes or response requested label May 27, 2026
@GSKirox

GSKirox commented May 28, 2026

Copy link
Copy Markdown
Collaborator

I'm testing the latest update (on Dolphin) and i can't speak to a scrub at all after stunning them?
image
If i remove the fix no problem.

@GSKirox GSKirox added the Status: Waiting for Author Changes or response requested label May 28, 2026
@GSKirox GSKirox removed the Status: Waiting for Author Changes or response requested label May 28, 2026
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 Status: Needs Review Someone should be looking at it Type: Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Softlock possibility with the new feature of paying before obtaining a scrub item

4 participants