Much Less OnGameUpdating

This commit is contained in:
Patrick12115 2024-10-28 18:12:09 -04:00
parent 9b8835117c
commit 619c579005
2 changed files with 60 additions and 40 deletions

View File

@ -728,12 +728,18 @@ void RegisterMirrorModeHandler() {
});
}
void RegisterPatchNoMSHandler() {
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnGameFrameUpdate>([]() {
if (OTRGlobals::Instance->gRandomizer->GetRandoSettingValue(RSK_SHUFFLE_MASTER_SWORD) &&
(gSaveContext.equips.buttonItems[0] != ITEM_SWORD_MASTER &&
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_BROKEN)) {
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());
@ -750,8 +756,8 @@ void RegisterPatchNoMSHandler() {
ResourceMgr_PatchGfxByName(gLinkAdultHylianShieldSwordAndSheathFarDL, "adultNoMSHylianShield2", 71, gsSPEndDisplayList());
ResourceMgr_PatchGfxByName(gLinkAdultMasterSwordAndSheathNearDL, "adultNoMasterSword1", 2, gsSPEndDisplayList());
ResourceMgr_PatchGfxByName(gLinkAdultMasterSwordAndSheathFarDL, "adultNoMasterSword2", 2, gsSPEndDisplayList());
}
else {
} 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());
@ -769,6 +775,19 @@ void RegisterPatchNoMSHandler() {
ResourceMgr_UnpatchGfxByName(gLinkAdultMasterSwordAndSheathNearDL, "adultNoMasterSword1");
ResourceMgr_UnpatchGfxByName(gLinkAdultMasterSwordAndSheathFarDL, "adultNoMasterSword2");
}
}
void RegisterNoMSPatch() {
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnPlayerUpdate>([]() {
static uint16_t lastItemOnB = gSaveContext.equips.buttonItems[0];
if (lastItemOnB != gSaveContext.equips.buttonItems[0]) {
UpdateNoMSPatch();
lastItemOnB = gSaveContext.equips.buttonItems[0];
}
});
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnSceneSpawnActors>([]() {
UpdateNoMSPatch();
});
}
@ -1490,7 +1509,7 @@ void InitMods() {
RegisterToTMedallions();
RegisterRandomizerCompasses();
NameTag_RegisterHooks();
RegisterPatchNoMSHandler();
RegisterNoMSPatch();
RegisterFloorSwitchesHook();
RegisterPatchHandHandler();
RegisterHurtContainerModeHandler();

View File

@ -17,6 +17,7 @@ void UpdateHyperEnemiesState();
void UpdateHyperBossesState();
void InitMods();
void UpdatePatchHand();
void UpdateNoMSPatch();
#ifdef __cplusplus
}