From 1fa31410c263768ddfd31bb13a9ba036c438a2c4 Mon Sep 17 00:00:00 2001 From: inspectredc <78732756+inspectredc@users.noreply.github.com> Date: Fri, 7 Apr 2023 22:05:12 +0100 Subject: [PATCH] Switch age fix (#2676) * specific scenarios for switch age button, non rando * Working fix for vanilla swordless change age * Fix now works for randomiser * Fixed room load on change age transition * Removed potentially unnecessary function call Need to investigate this more, maybe wait for more room documentation. * Suggested Edits Moves setting cvar back into mods.cpp and makes clear the condition expected for the no sword flag --- soh/soh/Enhancements/mods.cpp | 16 +++++++++++----- soh/src/code/z_parameter.c | 32 +++++++++++++++++++++++++------- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/soh/soh/Enhancements/mods.cpp b/soh/soh/Enhancements/mods.cpp index cdbacdf06..3034be65e 100644 --- a/soh/soh/Enhancements/mods.cpp +++ b/soh/soh/Enhancements/mods.cpp @@ -163,23 +163,29 @@ void RegisterSwitchAge() { static bool warped = false; static Vec3f playerPos; static int16_t playerYaw; + static RoomContext* roomCtx; + static s32 roomNum; if (!gPlayState) return; - if (CVarGetInteger("gSwitchAge", 0) != 0) { - CVarSetInteger("gSwitchAge", 0); + if (CVarGetInteger("gSwitchAge", 0) && !warped) { playerPos = GET_PLAYER(gPlayState)->actor.world.pos; playerYaw = GET_PLAYER(gPlayState)->actor.shape.rot.y; - + roomCtx = &gPlayState->roomCtx; + roomNum = roomCtx->curRoom.num; ReloadSceneTogglingLinkAge(); - warped = true; } - if (warped && gPlayState->sceneLoadFlag != 0x0014 && gSaveContext.nextTransitionType == 255) { + if (warped && gPlayState->sceneLoadFlag != 0x0014 && + gSaveContext.nextTransitionType == 255) { GET_PLAYER(gPlayState)->actor.shape.rot.y = playerYaw; GET_PLAYER(gPlayState)->actor.world.pos = playerPos; + func_8009728C(gPlayState, roomCtx, roomNum); //load original room + //func_800973FC(gPlayState, &gPlayState->roomCtx); // commit to room load? + func_80097534(gPlayState, roomCtx); // load map for new room (unloading the previous room) warped = false; + CVarSetInteger("gSwitchAge", 0); } }); } diff --git a/soh/src/code/z_parameter.c b/soh/src/code/z_parameter.c index f1a0eb36a..e69fd0126 100644 --- a/soh/src/code/z_parameter.c +++ b/soh/src/code/z_parameter.c @@ -1411,17 +1411,18 @@ void Inventory_SwapAgeEquipment(void) { u16 temp; if (LINK_AGE_IN_YEARS == YEARS_CHILD) { - // When becoming adult, remove swordless flag since we'll get master sword - // Only in rando to keep swordless link bugs in vanilla - if (gSaveContext.n64ddFlag) { - gSaveContext.infTable[29] &= ~1; - } + for (i = 0; i < ARRAY_COUNT(gSaveContext.equips.buttonItems); i++) { if (i != 0) { gSaveContext.childEquips.buttonItems[i] = gSaveContext.equips.buttonItems[i]; } else { - gSaveContext.childEquips.buttonItems[i] = ITEM_SWORD_KOKIRI; + if (CVarGetInteger("gSwitchAge", 0) && + (gSaveContext.infTable[29] & 1)) { + gSaveContext.childEquips.buttonItems[i] = ITEM_NONE; + } else { + gSaveContext.childEquips.buttonItems[i] = ITEM_SWORD_KOKIRI; + } } if (i != 0) { @@ -1429,6 +1430,12 @@ void Inventory_SwapAgeEquipment(void) { } } + // When becoming adult, remove swordless flag since we'll get master sword + // Only in rando to keep swordless link bugs in vanilla + if (gSaveContext.n64ddFlag) { + gSaveContext.infTable[29] &= ~1; + } + gSaveContext.childEquips.equipment = gSaveContext.equips.equipment; if (gSaveContext.adultEquips.buttonItems[0] == ITEM_NONE) { @@ -1493,7 +1500,8 @@ void Inventory_SwapAgeEquipment(void) { gSaveContext.adultEquips.equipment = gSaveContext.equips.equipment; - if (gSaveContext.childEquips.buttonItems[0] != ITEM_NONE) { + if (gSaveContext.childEquips.buttonItems[0] != ITEM_NONE || + CVarGetInteger("gSwitchAge", 0)) { for (i = 0; i < ARRAY_COUNT(gSaveContext.equips.buttonItems); i++) { gSaveContext.equips.buttonItems[i] = gSaveContext.childEquips.buttonItems[i]; @@ -1533,6 +1541,16 @@ void Inventory_SwapAgeEquipment(void) { } gSaveContext.equips.equipment = 0x1111; } + + if (CVarGetInteger("gSwitchAge", 0) && + (gSaveContext.equips.buttonItems[0] == ITEM_NONE)) { + gSaveContext.infTable[29] |= 1; + if (gSaveContext.childEquips.equipment == 0) { + // force equip kokiri tunic and boots in scenario gSaveContext.childEquips.equipment is uninitialized + gSaveContext.equips.equipment &= 0xFFF0; + gSaveContext.equips.equipment |= 0x1100; + } + } } temp = gEquipMasks[EQUIP_SHIELD] & gSaveContext.equips.equipment;