Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BtlController_EmitChosenMonReturnValue reads from NULL #5979

Open
DizzyEggg opened this issue Jan 8, 2025 · 2 comments
Open

BtlController_EmitChosenMonReturnValue reads from NULL #5979

DizzyEggg opened this issue Jan 8, 2025 · 2 comments
Labels
bug Bug category: battle-mechanic Pertains to battle mechanics status: unconfirmed This bug has not been reproduced yet

Comments

@DizzyEggg
Copy link
Collaborator

Description

Vanilla issue.

BtlController_EmitChosenMonReturnValue is sometimes called with battlePartyOrder equal to NULL, which means we're reading garbage from bios(or it evaluates to zeroes, not sure)

Affected code:

void BtlController_EmitChosenMonReturnValue(u32 battler, u32 bufferId, u8 partyId, u8 *battlePartyOrder)
{
//
    for (i = 0; i < (int)ARRAY_COUNT(gBattlePartyCurrentOrder); i++)
        gBattleResources->transferBuffer[2 + i] = battlePartyOrder[i];
}

In battle_controller_player.c

static void WaitForMonSelection(u32 battler)
{
//

            BtlController_EmitChosenMonReturnValue(battler, BUFFER_B, PARTY_SIZE, NULL);
}

In battle_controller_player_partner.c

static void PlayerPartnerHandleChoosePokemon(u32 battler)
{
    BtlController_EmitChosenMonReturnValue(battler, BUFFER_B, chosenMonId, NULL);
}

I didn't look more into it, so I'm not sure if this causes anything visible in-game, but it still should be fixed.

Version

1.10.1 (Latest release)

Upcoming/master Version

No response

Discord contact info

No response

@DizzyEggg DizzyEggg added bug Bug category: battle-mechanic Pertains to battle mechanics status: unconfirmed This bug has not been reproduced yet labels Jan 8, 2025
@Pawkkie
Copy link
Collaborator

Pawkkie commented Jan 8, 2025

Wonder if there's any shot this might be the mystery cause of #5589 due to the use of BtlController_EmitChosenMonReturnValue by the switching engine in OpponentHandleChoosePokemon, "reading garbage data" is an acceptable cause for "some phantom switch prompt" 🤔

@DizzyEggg
Copy link
Collaborator Author

Wonder if there's any shot this might be the mystery cause of #5589 due to the use of BtlController_EmitChosenMonReturnValue by the switching engine in OpponentHandleChoosePokemon, "reading garbage data" is an acceptable cause for "some phantom switch prompt" 🤔

That was my intuition too. We'll need to test it, because for all it's worth it could be totally harmless. OR it could be behind all of the switching weirdness which pops up once in a while

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug category: battle-mechanic Pertains to battle mechanics status: unconfirmed This bug has not been reproduced yet
Projects
None yet
Development

No branches or pull requests

2 participants