Skip to content

Commit

Permalink
Fix Broken Giant's Knife flag not resetting
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanLongstaff committed Dec 2, 2024
1 parent fe9bf7d commit 7ff7e98
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
42 changes: 42 additions & 0 deletions soh/soh/Enhancements/mods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,47 @@ void RegisterResetNaviTimer() {
});
}

void RegisterBrokenGiantsKnifeFix() {
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnItemReceive>([](GetItemEntry itemEntry) {
if (itemEntry.itemId != ITEM_SWORD_BGS) {
return;
}

int32_t bypassEquipmentChecks = 0;

if (CVarGetInteger(CVAR_ENHANCEMENT("FixBrokenGiantsKnife"), 0)) {
// Flag wasn't reset because Kokiri or Master Sword
// was missing, so we need to bypass those checks
bypassEquipmentChecks |= (1 << EQUIP_INV_SWORD_KOKIRI) | (1 << EQUIP_INV_SWORD_MASTER);
} else if (IS_RANDO) {
// In rando, when buying Giant's Knife, bypass check
// for the Kokiri Sword in case we don't have it
bypassEquipmentChecks |= (1 << EQUIP_INV_SWORD_KOKIRI);
} else {
// If neither of the above cases was true, flag should
// be handled exclusively by vanilla behaviour
return;
}

int32_t allSwordsInEquipment = bypassEquipmentChecks | ALL_EQUIP_VALUE(EQUIP_TYPE_SWORD);
int32_t allSwordFlags = (1 << EQUIP_INV_SWORD_KOKIRI) | (1 << EQUIP_INV_SWORD_MASTER) |
(1 << EQUIP_INV_SWORD_BIGGORON) | (1 << EQUIP_INV_SWORD_BROKENGIANTKNIFE);

if (allSwordsInEquipment != allSwordFlags) {
return;
}

gSaveContext.inventory.equipment ^= OWNED_EQUIP_FLAG_ALT(EQUIP_TYPE_SWORD, EQUIP_INV_SWORD_BROKENGIANTKNIFE);

if (gSaveContext.equips.buttonItems[0] == ITEM_SWORD_KNIFE) {
gSaveContext.equips.buttonItems[0] = ITEM_SWORD_BGS;
if (gPlayState != NULL) {
Interface_LoadItemIcon1(gPlayState, 0);
}
}
});
}

//this map is used for enemies that can be uniquely identified by their id
//and that are always counted
//enemies that can't be uniquely identified by their id
Expand Down Expand Up @@ -1429,6 +1470,7 @@ void InitMods() {
RegisterMenuPathFix();
RegisterMirrorModeHandler();
RegisterResetNaviTimer();
RegisterBrokenGiantsKnifeFix();
RegisterEnemyDefeatCounts();
RegisterBossDefeatTimestamps();
RegisterAltTrapTypes();
Expand Down
6 changes: 4 additions & 2 deletions soh/soh/SohMenuBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1521,10 +1521,12 @@ void DrawEnhancementsMenu() {
"This will lower them, making activating them easier");
UIWidgets::PaddedEnhancementCheckbox("Fix Zora hint dialogue", CVAR_ENHANCEMENT("FixZoraHintDialogue"), true, false);
UIWidgets::Tooltip("Fixes one Zora's dialogue giving a hint about bringing Ruto's Letter to King Zora to properly occur before moving King Zora rather than after");
if (UIWidgets::PaddedEnhancementCheckbox("Fix hand holding Hammer", "gEnhancements.FixHammerHand", true, false)) {
if (UIWidgets::PaddedEnhancementCheckbox("Fix hand holding Hammer", CVAR_ENHANCEMENT("FixHammerHand"), true, false)) {
UpdatePatchHand();
}
UIWidgets::Tooltip("Fixes Adult Link have a backwards left hand when holding the Megaton Hammer.");
UIWidgets::Tooltip("Fixes Adult Link having a backwards left hand when holding the Megaton Hammer.");
UIWidgets::PaddedEnhancementCheckbox("Fix Broken Giant's Knife bug", CVAR_ENHANCEMENT("FixBrokenGiantsKnife"), true, false);
UIWidgets::Tooltip("Fixes the Broken Giant's Knife flag not being reset when Medigoron fixes it");

ImGui::EndMenu();
}
Expand Down
6 changes: 1 addition & 5 deletions soh/src/code/z_parameter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1987,13 +1987,9 @@ u8 Item_Give(PlayState* play, u8 item) {
if (item == ITEM_SWORD_BGS) {
gSaveContext.swordHealth = 8;

// In rando, when buying Giant's Knife, also check
// without the Koriri Sword in case we don't have it
if (ALL_EQUIP_VALUE(EQUIP_TYPE_SWORD) ==
((1 << EQUIP_INV_SWORD_KOKIRI) | (1 << EQUIP_INV_SWORD_MASTER) | (1 << EQUIP_INV_SWORD_BIGGORON) |
(1 << EQUIP_INV_SWORD_BROKENGIANTKNIFE)) ||
(IS_RANDO && ALL_EQUIP_VALUE(EQUIP_TYPE_SWORD) ==
((1 << EQUIP_INV_SWORD_MASTER) | (1 << EQUIP_INV_SWORD_BIGGORON) | (1 << EQUIP_INV_SWORD_BROKENGIANTKNIFE)))) {
(1 << EQUIP_INV_SWORD_BROKENGIANTKNIFE))) {

gSaveContext.inventory.equipment ^= OWNED_EQUIP_FLAG_ALT(EQUIP_TYPE_SWORD, EQUIP_INV_SWORD_BROKENGIANTKNIFE);

Expand Down

0 comments on commit 7ff7e98

Please sign in to comment.