Skip to content

Commit

Permalink
Merge pull request #674 from notyourav/b
Browse files Browse the repository at this point in the history
fix fakematch in LinkHoldingItem_Action3
  • Loading branch information
hytopoulos committed Dec 29, 2023
2 parents b32553e + 7c1c612 commit d6b425f
Show file tree
Hide file tree
Showing 21 changed files with 101 additions and 104 deletions.
32 changes: 15 additions & 17 deletions include/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,23 +243,21 @@ typedef struct {
} PlayerMacroEntry;

typedef enum {
PLAYER_INPUT_1 = 0x1, // A
PLAYER_INPUT_2 = 0x2, // B
PLAYER_INPUT_8 = 0x8, // A sub_080782C0, sub_0807953C, PlayerUpdateSwimming, sub_08076518. ItemForSale_Action2
PLAYER_INPUT_10 = 0x10, // B sub_0807953C, ToggleDiving, sub_08076518, ItemForSale_Action2
PLAYER_INPUT_20 = 0x20, // R sub_0807953C
PLAYER_INPUT_40 = 0x40, // A CrenelBeanSprout_Action1
PLAYER_INPUT_80 =
INPUT_USE_ITEM1 = 0x1, // A
INPUT_USE_ITEM2 = 0x2, // B
INPUT_INTERACT = 0x8, // A sub_080782C0, sub_0807953C, PlayerUpdateSwimming, sub_08076518. ItemForSale_Action2
INPUT_CANCEL = 0x10, // B sub_0807953C, ToggleDiving, sub_08076518, ItemForSale_Action2
INPUT_CONTEXT = 0x20, // R sub_0807953C
INPUT_40 = 0x40, // A CrenelBeanSprout_Action1
INPUT_ACTION =
0x80, // R sub_08073584, IsPreventedFromUsingItem, sub_080782C0, CrenelBeanSprout_Action1, ItemForSale_Action2
PLAYER_INPUT_RIGHT = 0x100,
PLAYER_INPUT_LEFT = 0x200,
PLAYER_INPUT_UP = 0x400,
PLAYER_INPUT_DOWN = 0x800,
PLAYER_INPUT_ANY_DIRECTION = 0xf00,
PLAYER_INPUT_1000 = 0x1000, // L, where is it set? sub_080782C0
PLAYER_INPUT_8000 = 0x8000, // R, IsTryingToPickupObject, sub_08076518

// TODO What is the result of u32 result = (s32) - (keys & 0x200) >> 0x1f & 0x1000;?
INPUT_RIGHT = 0x100,
INPUT_LEFT = 0x200,
INPUT_UP = 0x400,
INPUT_DOWN = 0x800,
INPUT_ANY_DIRECTION = 0xf00,
INPUT_FUSE = 0x1000, // L, where is it set? sub_080782C0
INPUT_LIFT_THROW = 0x8000, // R, IsTryingToPickupObject, sub_08076518
} PlayerInputState;

typedef struct {
Expand Down Expand Up @@ -535,7 +533,7 @@ typedef struct {
/*0x09*/ u8 _hasAllFigurines;
/*0x0a*/ u8 charm;
/*0x0b*/ u8 picolyteType;
/*0x0c*/ u8 itemButtons[2];
/*0x0c*/ u8 equipped[2];
/*0x0e*/ u8 bottles[4];
/*0x12*/ u8 effect;
/*0x13*/ u8 hasAllFigurines;
Expand Down
6 changes: 3 additions & 3 deletions src/beanstalkSubtask.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ u32 UpdatePlayerCollision(void) {
return 0;
}
gUnk_0200AF00.rActionInteractTile = R_ACTION_READ;
if ((gPlayerState.playerInput.newInput & (PLAYER_INPUT_80 | PLAYER_INPUT_40)) == 0) {
if ((gPlayerState.playerInput.newInput & (INPUT_ACTION | INPUT_40)) == 0) {
return 0;
}
gPlayerState.mobility = 1;
Expand All @@ -327,7 +327,7 @@ u32 UpdatePlayerCollision(void) {
return 0;
}
gUnk_0200AF00.rActionInteractTile = R_ACTION_OPEN;
if ((gPlayerState.playerInput.newInput & (PLAYER_INPUT_80 | PLAYER_INPUT_8)) == 0) {
if ((gPlayerState.playerInput.newInput & (INPUT_ACTION | INPUT_INTERACT)) == 0) {
return 0;
}
gPlayerState.mobility = 1;
Expand All @@ -338,7 +338,7 @@ u32 UpdatePlayerCollision(void) {
return 0;
}
gUnk_0200AF00.rActionInteractTile = R_ACTION_OPEN;
if ((gPlayerState.playerInput.newInput & (PLAYER_INPUT_80 | PLAYER_INPUT_8)) == 0) {
if ((gPlayerState.playerInput.newInput & (INPUT_ACTION | INPUT_INTERACT)) == 0) {
return 0;
}
gPlayerState.mobility = 1;
Expand Down
26 changes: 13 additions & 13 deletions src/code_0805EC04.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,40 +138,40 @@ void UpdatePlayerInput(void) {
gPlayerState.playerInput.heldInput = state;
gPlayerState.playerInput.newInput = state & prevState;
// Calculate the direction from the currently held input.
gPlayerState.direction = gUnk_08109202[(state & PLAYER_INPUT_ANY_DIRECTION) >> 8];
gPlayerState.direction = gUnk_08109202[(state & INPUT_ANY_DIRECTION) >> 8];
}

u32 ConvInputToState(u32 keys) {
u32 result;
if (keys & L_BUTTON) {
result = 0x1000;
result = INPUT_FUSE;
} else {
result = 0;
}
if (keys & R_BUTTON) {
result |= PLAYER_INPUT_20;
result |= PLAYER_INPUT_8000;
result |= PLAYER_INPUT_80;
result |= INPUT_CONTEXT;
result |= INPUT_LIFT_THROW;
result |= INPUT_ACTION;
}
if (keys & A_BUTTON) {
result |= PLAYER_INPUT_8;
result |= PLAYER_INPUT_40 | PLAYER_INPUT_1;
result |= INPUT_INTERACT;
result |= INPUT_40 | INPUT_USE_ITEM1;
}
if (keys & B_BUTTON) {
result |= PLAYER_INPUT_10;
result |= PLAYER_INPUT_2;
result |= INPUT_CANCEL;
result |= INPUT_USE_ITEM2;
}
if (keys & DPAD_RIGHT) {
result |= PLAYER_INPUT_RIGHT;
result |= INPUT_RIGHT;
}
if (keys & DPAD_LEFT) {
result |= PLAYER_INPUT_LEFT;
result |= INPUT_LEFT;
}
if (keys & DPAD_UP) {
result |= PLAYER_INPUT_UP;
result |= INPUT_UP;
}
if (keys & DPAD_DOWN) {
result |= PLAYER_INPUT_DOWN;
result |= INPUT_DOWN;
}
return result;
}
Expand Down
8 changes: 4 additions & 4 deletions src/enemy/likeLike.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,12 @@ void sub_080281A0(LikeLikeEntity* this) {
bool32 LikeLike_StealItem(u32 item) {
bool32 ret = FALSE;
if (GetInventoryValue(item) == 1) {
if (ItemIsShield(gSave.stats.itemButtons[SLOT_A])) {
gSave.stats.itemButtons[SLOT_A] = ITEM_NONE;
if (ItemIsShield(gSave.stats.equipped[SLOT_A])) {
gSave.stats.equipped[SLOT_A] = ITEM_NONE;
}

if (ItemIsShield(gSave.stats.itemButtons[SLOT_B])) {
gSave.stats.itemButtons[SLOT_B] = ITEM_NONE;
if (ItemIsShield(gSave.stats.equipped[SLOT_B])) {
gSave.stats.equipped[SLOT_B] = ITEM_NONE;
}

SetInventoryValue(item, 0);
Expand Down
6 changes: 3 additions & 3 deletions src/item/itemPegasusBoots.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ void sub_08076964(ItemBehavior* this, u32 index) {
SetItemAnim(this, ANIM_DASH);
entity = CreatePlayerItemWithParent(this, PLAYER_ITEM_DASH_SWORD);
if (entity != NULL) {
if (ItemIsSword(gSave.stats.itemButtons[SLOT_A]) != 0) {
uVar3 = gSave.stats.itemButtons[SLOT_A];
if (ItemIsSword(gSave.stats.equipped[SLOT_A]) != 0) {
uVar3 = gSave.stats.equipped[SLOT_A];
} else {
uVar3 = gSave.stats.itemButtons[SLOT_B];
uVar3 = gSave.stats.equipped[SLOT_B];
}
entity->field_0x68.HALF.LO = uVar3;
return;
Expand Down
4 changes: 2 additions & 2 deletions src/item/itemTryPickupObject.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void sub_080762D8(ItemBehavior* this, u32 index) {
if (gPlayerEntity.iframes < 9 && gPlayerEntity.knockbackDuration == 0) {
if (this->field_0x18 != NULL) {
if (this->field_0x18->action == 2 && this->field_0x18->subAction == 5) {
if (!(gPlayerState.playerInput.heldInput & PLAYER_INPUT_80)) { // Pressing R
if (!(gPlayerState.playerInput.heldInput & INPUT_ACTION)) { // Pressing R
this->field_0x18->subAction = 6;
PlayerCancelHoldItem(this, index);
return;
Expand Down Expand Up @@ -263,7 +263,7 @@ void sub_08076518(ItemBehavior* this, u32 index) {
if (gPlayerEntity.knockbackDuration != 0) {
PlayerCancelHoldItem(this, index);
} else {
if ((gPlayerState.playerInput.newInput & (PLAYER_INPUT_8000 | PLAYER_INPUT_10 | PLAYER_INPUT_8)) != 0) {
if ((gPlayerState.playerInput.newInput & (INPUT_LIFT_THROW | INPUT_CANCEL | INPUT_INTERACT)) != 0) {
sub_0806F948(&gPlayerEntity);
gPlayerState.heldObject = 5;
this->field_0x18->subAction = 2;
Expand Down
20 changes: 10 additions & 10 deletions src/itemUtils.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ void ModArrows(s32 arrows) {
EquipSlot IsItemEquipped(u32 itemId) {
EquipSlot equipSlot;

if (itemId == gSave.stats.itemButtons[SLOT_A]) {
if (itemId == gSave.stats.equipped[SLOT_A]) {
equipSlot = EQUIP_SLOT_A;
} else if (itemId == gSave.stats.itemButtons[SLOT_B]) {
} else if (itemId == gSave.stats.equipped[SLOT_B]) {
equipSlot = EQUIP_SLOT_B;
} else {
equipSlot = EQUIP_SLOT_NONE;
Expand All @@ -273,17 +273,17 @@ void PutItemOnSlot(u32 itemId) {
}
if (itemId2 - 1 < 0x1f) {
equipSlot = EQUIP_SLOT_NONE;
if (gSave.stats.itemButtons[SLOT_A] == ITEM_NONE) {
if (gSave.stats.equipped[SLOT_A] == ITEM_NONE) {
equipSlot = EQUIP_SLOT_A;
} else if (gSave.stats.itemButtons[SLOT_B] == ITEM_NONE) {
} else if (gSave.stats.equipped[SLOT_B] == ITEM_NONE) {
equipSlot = EQUIP_SLOT_B;
}
if (equipSlot == EQUIP_SLOT_NONE) {
u32 temp = gItemMetaData[itemId2].menuSlot;
if (temp == gItemMetaData[gSave.stats.itemButtons[SLOT_A]].menuSlot) {
if (temp == gItemMetaData[gSave.stats.equipped[SLOT_A]].menuSlot) {
equipSlot = EQUIP_SLOT_A;
} else {
if (temp == gItemMetaData[gSave.stats.itemButtons[SLOT_B]].menuSlot) {
if (temp == gItemMetaData[gSave.stats.equipped[SLOT_B]].menuSlot) {
equipSlot = EQUIP_SLOT_B;
}
}
Expand All @@ -302,13 +302,13 @@ void ForceEquipItem(u32 itemId, u32 equipSlot) {

if ((itemId - 1 < 0x1f) && (equipSlot < EQUIP_SLOT_NONE)) {
otherItemSlot = equipSlot == EQUIP_SLOT_A;
replacedItem = gSave.stats.itemButtons[equipSlot];
otherItem = gSave.stats.itemButtons[otherItemSlot];
replacedItem = gSave.stats.equipped[equipSlot];
otherItem = gSave.stats.equipped[otherItemSlot];
if (gItemMetaData[otherItem].menuSlot == gItemMetaData[itemId].menuSlot) {
otherItem = replacedItem;
}
gSave.stats.itemButtons[equipSlot] = itemId;
gSave.stats.itemButtons[otherItemSlot] = otherItem;
gSave.stats.equipped[equipSlot] = itemId;
gSave.stats.equipped[otherItemSlot] = otherItem;
gUnk_0200AF00.unk_13 = 0x7f;
gUnk_0200AF00.unk_14 = 0x7f;
}
Expand Down
2 changes: 1 addition & 1 deletion src/manager/miscManager.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ void MiscManager_TypeB(MiscManager* this) {

bool32 sub_080593CC(MiscManager* this) {
if (!(gPlayerState.flags & PL_MINISH) && gPlayerState.swim_state != 0 && gPlayerEntity.animationState == 0 &&
(gPlayerState.playerInput.heldInput & PLAYER_INPUT_ANY_DIRECTION) == PLAYER_INPUT_UP) {
(gPlayerState.playerInput.heldInput & INPUT_ANY_DIRECTION) == INPUT_UP) {
return EntityWithinDistance(&gPlayerEntity, this->unk_38, this->unk_3a + 0xC, 6);
}
return FALSE;
Expand Down
4 changes: 2 additions & 2 deletions src/menu/pauseMenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,14 +529,14 @@ void PauseMenu_ItemMenu_Draw(void) {
gOamCmd._8 = 0x800;
DrawDirect(sub_080A5384_draw_constant0, 0x22);
}
i = GetMenuSlotForItem(gSave.stats.itemButtons[SLOT_A]);
i = GetMenuSlotForItem(gSave.stats.equipped[SLOT_A]);
if (i < MENU_SLOT_COUNT) {
entry = &gItemMenuTable[i];
gOamCmd.x = entry->x;
gOamCmd.y = entry->y;
DrawDirect(sub_080A5384_draw_constant0, 3);
}
i = GetMenuSlotForItem(gSave.stats.itemButtons[SLOT_B]);
i = GetMenuSlotForItem(gSave.stats.equipped[SLOT_B]);
if (i < MENU_SLOT_COUNT) {
entry = &gItemMenuTable[i];
gOamCmd.x = entry->x;
Expand Down
2 changes: 1 addition & 1 deletion src/npc/bigGoron.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ void sub_0806D5D4(void) {
InitBiggoronTimer();
equipSlot = IsItemEquipped(ITEM_SHIELD);
if (equipSlot != EQUIP_SLOT_NONE) {
gSave.stats.itemButtons[equipSlot] = ITEM_NONE;
gSave.stats.equipped[equipSlot] = ITEM_NONE;
}
SetInventoryValue(ITEM_SHIELD, 0);
}
Expand Down
4 changes: 2 additions & 2 deletions src/npc/bladeBrothers.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,10 @@ void BladeBrothers_StartPlayerDemonstration(Entity* this, ScriptExecutionContext
}

void sub_08068BB4(BladeBrothersEntity* this) {
u32 item = gSave.stats.itemButtons[SLOT_A];
u32 item = gSave.stats.equipped[SLOT_A];

this->itemSlotA = item;
item = gSave.stats.itemButtons[SLOT_B];
item = gSave.stats.equipped[SLOT_B];
this->itemSlotB = item;
}

Expand Down
4 changes: 2 additions & 2 deletions src/npc/npc4E.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ Item NPC4E_GetItemWithSwordUpgraded(Item itemId) {
}

void NPC4E_SaveEquippedItems(NPC4EEntity* this) {
this->unk_68 = gSave.stats.itemButtons[SLOT_A];
this->unk_69 = gSave.stats.itemButtons[SLOT_B];
this->unk_68 = gSave.stats.equipped[SLOT_A];
this->unk_69 = gSave.stats.equipped[SLOT_B];
}

void NPC4E_RestoreEquippedItems(NPC4EEntity* this) {
Expand Down
2 changes: 1 addition & 1 deletion src/object/crenelBeanSprout.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void CrenelBeanSprout_Action1(CrenelBeanSproutEntity* this) {
RestorePrevTileEntity(0xdc, super->collisionLayer);
sub_08096A78(this);
}
if ((gPlayerState.playerInput.newInput & (PLAYER_INPUT_80 | PLAYER_INPUT_40)) == 0) {
if ((gPlayerState.playerInput.newInput & (INPUT_ACTION | INPUT_40)) == 0) {
return;
}
if (gUnk_0200AF00.rActionPlayerState != R_ACTION_THROW) {
Expand Down
2 changes: 1 addition & 1 deletion src/object/houseDoorExterior.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void sub_0808692C(HouseDoorExteriorEntity* this) {
static u8 sub_08086954(HouseDoorExteriorEntity* this) {
if (sub_0800445C(super)) {
if (GetAnimationStateInRectRadius(super, 6, 20) >= 0 && gPlayerEntity.animationState == 0 &&
(u16)gPlayerState.playerInput.heldInput == PLAYER_INPUT_UP && gPlayerState.jump_status == 0) {
(u16)gPlayerState.playerInput.heldInput == INPUT_UP && gPlayerState.jump_status == 0) {
super->timer--;
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/object/itemForSale.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ void ItemForSale_Action2(ItemForSaleEntity* this) {
ptr = sub_080784E4();
if (((*(int*)(ptr + 8) == 0) || ((*(u8*)(ptr + 1) != 1 || (gUnk_0200AF00.rActionPlayerState = R_ACTION_SPEAK,
(gPlayerState.playerInput.newInput &
(PLAYER_INPUT_80 | PLAYER_INPUT_8)) == 0)))) &&
((gPlayerState.playerInput.newInput & (PLAYER_INPUT_80 | PLAYER_INPUT_10 | PLAYER_INPUT_8)) != 0)) {
(INPUT_ACTION | INPUT_INTERACT)) == 0)))) &&
((gPlayerState.playerInput.newInput & (INPUT_ACTION | INPUT_CANCEL | INPUT_INTERACT)) != 0)) {
sub_080819B4(this);
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/object/linkHoldingItem.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ void LinkHoldingItem_Action2(LinkHoldingItemEntity* this) {
}

void LinkHoldingItem_Action3(LinkHoldingItemEntity* this) {
u32 tmp;
if ((super->parent)->action == 8) {
u32 bottle_no;
if (super->parent->action == PLAYER_ITEMGET) {
return;
}
switch (super->timer) {
Expand All @@ -149,9 +149,9 @@ void LinkHoldingItem_Action3(LinkHoldingItemEntity* this) {
ModHealth(160);
break;
case 3:
tmp = GetBottleContaining(super->type);
if (tmp != 0) {
gSave.stats.itemButtons[tmp + 1] = ITEM_BOTTLE_EMPTY;
bottle_no = GetBottleContaining(super->type);
if (bottle_no != 0) {
gSave.stats.bottles[bottle_no - 1] = ITEM_BOTTLE_EMPTY;
} else {
SetInventoryValue(super->type, ITEM_GREEN_SWORD);
}
Expand Down
15 changes: 7 additions & 8 deletions src/player.c
Original file line number Diff line number Diff line change
Expand Up @@ -2750,7 +2750,7 @@ static void sub_08073504(Entity* this) {
static void sub_08073584(Entity* this) {
u32 state, dir, idx;

if ((gPlayerState.playerInput.newInput & PLAYER_INPUT_80) || this->iframes > 0 || gPlayerState.field_0x3c ||
if ((gPlayerState.playerInput.newInput & INPUT_ACTION) || this->iframes > 0 || gPlayerState.field_0x3c ||
(gPlayerState.flags & PL_PARACHUTE) == 0) {
gPlayerState.jump_status |= 0x40;
PlayerSetNormalAndCollide();
Expand Down Expand Up @@ -3447,10 +3447,10 @@ void SurfaceAction_14(Entity* this) {
void SurfaceAction_CloneTile(Entity* this) {
if (gPlayerState.chargeState.action == 4) {
u32 item, n, i;
if (ItemIsSword(gSave.stats.itemButtons[SLOT_A])) {
item = gSave.stats.itemButtons[SLOT_A];
if (ItemIsSword(gSave.stats.equipped[SLOT_A])) {
item = gSave.stats.equipped[SLOT_A];
} else {
item = gSave.stats.itemButtons[SLOT_B];
item = gSave.stats.equipped[SLOT_B];
}
switch (item) {
case 1:
Expand Down Expand Up @@ -3523,8 +3523,7 @@ void SurfaceAction_ShallowWater(Entity* this) {
this->spritePriority.b0 = 4;
gPlayerState.swim_state = 0;
}
if ((gPlayerState.playerInput.newInput & PLAYER_INPUT_ANY_DIRECTION) ||
gPlayerState.surfacePositionSameTimer == 1)
if ((gPlayerState.playerInput.newInput & INPUT_ANY_DIRECTION) || gPlayerState.surfacePositionSameTimer == 1)
SoundReq(SFX_WATER_WALK);
}
}
Expand Down Expand Up @@ -3567,7 +3566,7 @@ void SurfaceAction_Swamp(Entity* this) {
CreateObjectWithParent(this, OBJECT_70, 0, 0);
CreateFx(this, FX_GREEN_SPLASH, 0);
SoundReq(SFX_161);
} else if ((gPlayerState.playerInput.newInput & PLAYER_INPUT_ANY_DIRECTION) != 0) {
} else if ((gPlayerState.playerInput.newInput & INPUT_ANY_DIRECTION) != 0) {
SoundReq(SFX_161);
} else if ((gRoomTransition.frameCount & 0xf) == 0) {
SoundReq(SFX_161);
Expand Down Expand Up @@ -3723,7 +3722,7 @@ void SurfaceAction_Dust(Entity* this) {
if (!sub_080741C4()) {
gPlayerState.speed_modifier -= 128;
if (gPlayerState.surfacePositionSameTimer == 1 ||
(gPlayerState.playerInput.newInput & PLAYER_INPUT_ANY_DIRECTION) != 0) {
(gPlayerState.playerInput.newInput & INPUT_ANY_DIRECTION) != 0) {
if (gPlayerState.floor_type == SURFACE_DUST)
CreateObjectWithParent(this, DIRT_PARTICLE, 1, 0);
else
Expand Down
Loading

0 comments on commit d6b425f

Please sign in to comment.