diff --git a/soh/soh/Enhancements/mods.cpp b/soh/soh/Enhancements/mods.cpp index 820ccc783..fb9a713ae 100644 --- a/soh/soh/Enhancements/mods.cpp +++ b/soh/soh/Enhancements/mods.cpp @@ -728,47 +728,66 @@ void RegisterMirrorModeHandler() { }); } -void RegisterPatchNoMSHandler() { - GameInteractor::Instance->RegisterGameHook([]() { - if (OTRGlobals::Instance->gRandomizer->GetRandoSettingValue(RSK_SHUFFLE_MASTER_SWORD) && - (gSaveContext.equips.buttonItems[0] != ITEM_SWORD_MASTER && - gSaveContext.equips.buttonItems[0] != ITEM_SWORD_BGS && - gSaveContext.equips.buttonItems[0] != ITEM_SWORD_BROKEN)) { - for (int i = 43; i <= 46; i++) { - std::string patchName = "adultNoMS." + std::to_string(1) + "." + std::to_string(i); - ResourceMgr_PatchGfxByName(gLinkAdultHylianShieldSwordAndSheathFarDL, patchName.c_str(), i, gsDPNoOp()); - } - for (int i = 62; i <= 150; i++) { - std::string patchName = "adultNoMS." + std::to_string(2) + "." + std::to_string(i); - ResourceMgr_PatchGfxByName(gLinkAdultMirrorShieldSwordAndSheathNearDL, patchName.c_str(), i, gsDPNoOp()); - } - for (int i = 61; i <= 118; i++) { - std::string patchName = "adultNoMS." + std::to_string(3) + "." + std::to_string(i); - ResourceMgr_PatchGfxByName(gLinkAdultMirrorShieldSwordAndSheathFarDL, patchName.c_str(), i, gsDPNoOp()); - } - ResourceMgr_PatchGfxByName(gLinkAdultHylianShieldSwordAndSheathNearDL, "adultNoMSHylianShield1", 75, gsSPEndDisplayList()); - ResourceMgr_PatchGfxByName(gLinkAdultHylianShieldSwordAndSheathFarDL, "adultNoMSHylianShield2", 71, gsSPEndDisplayList()); - ResourceMgr_PatchGfxByName(gLinkAdultMasterSwordAndSheathNearDL, "adultNoMasterSword1", 2, gsSPEndDisplayList()); - ResourceMgr_PatchGfxByName(gLinkAdultMasterSwordAndSheathFarDL, "adultNoMasterSword2", 2, gsSPEndDisplayList()); +void UpdateNoMSPatch() { + // Condition for patching + bool shouldPatch = (gSaveContext.equips.buttonItems[0] != ITEM_SWORD_MASTER && + gSaveContext.equips.buttonItems[0] != ITEM_SWORD_BGS && + gSaveContext.equips.buttonItems[0] != ITEM_SWORD_KNIFE && + (gSaveContext.equips.buttonItems[0] != ITEM_FISHING_POLE || + (!CHECK_OWNED_EQUIP(EQUIP_TYPE_SWORD, EQUIP_INV_SWORD_MASTER) && + !CHECK_OWNED_EQUIP(EQUIP_TYPE_SWORD, EQUIP_INV_SWORD_BIGGORON) && + !CHECK_OWNED_EQUIP(EQUIP_TYPE_SWORD, EQUIP_INV_SWORD_BROKENGIANTKNIFE)))); + + if (OTRGlobals::Instance->gRandomizer->GetRandoSettingValue(RSK_SHUFFLE_MASTER_SWORD) && shouldPatch) { + // Patching if conditions are met + for (int i = 43; i <= 46; i++) { + std::string patchName = "adultNoMS." + std::to_string(1) + "." + std::to_string(i); + ResourceMgr_PatchGfxByName(gLinkAdultHylianShieldSwordAndSheathFarDL, patchName.c_str(), i, gsDPNoOp()); } - else { - for (int i = 43; i <= 46; i++) { - std::string patchName = "adultNoMS." + std::to_string(1) + "." + std::to_string(i); - ResourceMgr_UnpatchGfxByName(gLinkAdultHylianShieldSwordAndSheathFarDL, patchName.c_str()); - } - for (int i = 62; i <= 150; i++) { - std::string patchName = "adultNoMS." + std::to_string(2) + "." + std::to_string(i); - ResourceMgr_UnpatchGfxByName(gLinkAdultMirrorShieldSwordAndSheathNearDL, patchName.c_str()); - } - for (int i = 61; i <= 118; i++) { - std::string patchName = "adultNoMS." + std::to_string(3) + "." + std::to_string(i); - ResourceMgr_UnpatchGfxByName(gLinkAdultMirrorShieldSwordAndSheathFarDL, patchName.c_str()); - } - ResourceMgr_UnpatchGfxByName(gLinkAdultHylianShieldSwordAndSheathNearDL, "adultNoMSHylianShield1"); - ResourceMgr_UnpatchGfxByName(gLinkAdultHylianShieldSwordAndSheathFarDL, "adultNoMSHylianShield2"); - ResourceMgr_UnpatchGfxByName(gLinkAdultMasterSwordAndSheathNearDL, "adultNoMasterSword1"); - ResourceMgr_UnpatchGfxByName(gLinkAdultMasterSwordAndSheathFarDL, "adultNoMasterSword2"); + for (int i = 62; i <= 150; i++) { + std::string patchName = "adultNoMS." + std::to_string(2) + "." + std::to_string(i); + ResourceMgr_PatchGfxByName(gLinkAdultMirrorShieldSwordAndSheathNearDL, patchName.c_str(), i, gsDPNoOp()); } + for (int i = 61; i <= 118; i++) { + std::string patchName = "adultNoMS." + std::to_string(3) + "." + std::to_string(i); + ResourceMgr_PatchGfxByName(gLinkAdultMirrorShieldSwordAndSheathFarDL, patchName.c_str(), i, gsDPNoOp()); + } + ResourceMgr_PatchGfxByName(gLinkAdultHylianShieldSwordAndSheathNearDL, "adultNoMSHylianShield1", 75, gsSPEndDisplayList()); + ResourceMgr_PatchGfxByName(gLinkAdultHylianShieldSwordAndSheathFarDL, "adultNoMSHylianShield2", 71, gsSPEndDisplayList()); + ResourceMgr_PatchGfxByName(gLinkAdultMasterSwordAndSheathNearDL, "adultNoMasterSword1", 2, gsSPEndDisplayList()); + ResourceMgr_PatchGfxByName(gLinkAdultMasterSwordAndSheathFarDL, "adultNoMasterSword2", 2, gsSPEndDisplayList()); + } else { + // Unpatching if conditions are not met + for (int i = 43; i <= 46; i++) { + std::string patchName = "adultNoMS." + std::to_string(1) + "." + std::to_string(i); + ResourceMgr_UnpatchGfxByName(gLinkAdultHylianShieldSwordAndSheathFarDL, patchName.c_str()); + } + for (int i = 62; i <= 150; i++) { + std::string patchName = "adultNoMS." + std::to_string(2) + "." + std::to_string(i); + ResourceMgr_UnpatchGfxByName(gLinkAdultMirrorShieldSwordAndSheathNearDL, patchName.c_str()); + } + for (int i = 61; i <= 118; i++) { + std::string patchName = "adultNoMS." + std::to_string(3) + "." + std::to_string(i); + ResourceMgr_UnpatchGfxByName(gLinkAdultMirrorShieldSwordAndSheathFarDL, patchName.c_str()); + } + ResourceMgr_UnpatchGfxByName(gLinkAdultHylianShieldSwordAndSheathNearDL, "adultNoMSHylianShield1"); + ResourceMgr_UnpatchGfxByName(gLinkAdultHylianShieldSwordAndSheathFarDL, "adultNoMSHylianShield2"); + ResourceMgr_UnpatchGfxByName(gLinkAdultMasterSwordAndSheathNearDL, "adultNoMasterSword1"); + ResourceMgr_UnpatchGfxByName(gLinkAdultMasterSwordAndSheathFarDL, "adultNoMasterSword2"); + } +} + + +void RegisterNoMSPatch() { + GameInteractor::Instance->RegisterGameHook([]() { + static uint16_t lastItemOnB = gSaveContext.equips.buttonItems[0]; + if (lastItemOnB != gSaveContext.equips.buttonItems[0]) { + UpdateNoMSPatch(); + lastItemOnB = gSaveContext.equips.buttonItems[0]; + } + }); + GameInteractor::Instance->RegisterGameHook([]() { + UpdateNoMSPatch(); }); } @@ -1490,7 +1509,7 @@ void InitMods() { RegisterToTMedallions(); RegisterRandomizerCompasses(); NameTag_RegisterHooks(); - RegisterPatchNoMSHandler(); + RegisterNoMSPatch(); RegisterFloorSwitchesHook(); RegisterPatchHandHandler(); RegisterHurtContainerModeHandler(); diff --git a/soh/soh/Enhancements/mods.h b/soh/soh/Enhancements/mods.h index b70cda286..4cdd3507c 100644 --- a/soh/soh/Enhancements/mods.h +++ b/soh/soh/Enhancements/mods.h @@ -17,6 +17,7 @@ void UpdateHyperEnemiesState(); void UpdateHyperBossesState(); void InitMods(); void UpdatePatchHand(); +void UpdateNoMSPatch(); #ifdef __cplusplus }