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,47 +728,66 @@ 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 &&
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<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
}