From 0d54cb15dff21c763d73171451871ae1e2d34d3c Mon Sep 17 00:00:00 2001
From: Josh Bodner <30329717+jbodner09@users.noreply.github.com>
Date: Thu, 2 Mar 2023 13:57:55 -0800
Subject: [PATCH 1/2] Spot fix so autosave dropdown will save immediately
 (#2568)

---
 soh/soh/GameMenuBar.cpp | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/soh/soh/GameMenuBar.cpp b/soh/soh/GameMenuBar.cpp
index a385d486d..8bf132a7a 100644
--- a/soh/soh/GameMenuBar.cpp
+++ b/soh/soh/GameMenuBar.cpp
@@ -834,18 +834,9 @@ namespace GameMenuBar {
             UIWidgets::PaddedSeparator(false, true);
 
             // Autosave enum value of 1 is the default in presets and the old checkbox "on" state for backwards compatibility
-            const uint16_t selectedAutosaveId = CVarGetInteger("gAutosave", 0);
-            std::string autosaveLabels[] = { "Off", "New Location + Major Item", "New Location + Any Item", "New Location", "Major Item", "Any Item" };
             UIWidgets::PaddedText("Autosave", false, true);
-            if (ImGui::BeginCombo("##AutosaveComboBox", autosaveLabels[selectedAutosaveId].c_str())) {
-                for (int index = 0; index < sizeof(autosaveLabels) / sizeof(autosaveLabels[0]); index++) {
-                    if (ImGui::Selectable(autosaveLabels[index].c_str(), index == selectedAutosaveId)) {
-                        CVarSetInteger("gAutosave", index);
-                    }
-                }
-
-                ImGui::EndCombo();
-            }
+            const char* autosaveLabels[] = { "Off", "New Location + Major Item", "New Location + Any Item", "New Location", "Major Item", "Any Item" };
+            UIWidgets::EnhancementCombobox("gAutosave", autosaveLabels, (sizeof(autosaveLabels) / sizeof(autosaveLabels[0])), CVarGetInteger("gAutosave", 0));
             UIWidgets::Tooltip("Automatically save the game every time a new area is entered and/or item is obtained\n"
                 "Major items exclude rupees and health/magic/ammo refills (but include bombchus unless bombchu drops are enabled)");
 

From a5bf13554195039566f7418d87156386c368bfaf Mon Sep 17 00:00:00 2001
From: Adam Bird <Archez@users.noreply.github.com>
Date: Thu, 2 Mar 2023 17:12:46 -0500
Subject: [PATCH 2/2] fix change age cheat causing link to spawn in the wrong
 spot (#2573)

---
 soh/soh/Enhancements/mods.cpp | 76 +++++++++++++++++------------------
 1 file changed, 36 insertions(+), 40 deletions(-)

diff --git a/soh/soh/Enhancements/mods.cpp b/soh/soh/Enhancements/mods.cpp
index 66f2d169e..c7bf6350b 100644
--- a/soh/soh/Enhancements/mods.cpp
+++ b/soh/soh/Enhancements/mods.cpp
@@ -89,13 +89,13 @@ void RegisterInfiniteNayrusLove() {
 
 void RegisterMoonJumpOnL() {
     GameInteractor::Instance->RegisterGameHook<GameInteractor::OnGameFrameUpdate>([]() {
+        if (!gPlayState) return;
+        
         if (CVarGetInteger("gMoonJumpOnL", 0) != 0) {
-            if (gPlayState) {
-                Player* player = GET_PLAYER(gPlayState);
+            Player* player = GET_PLAYER(gPlayState);
 
-                if (CHECK_BTN_ANY(gPlayState->state.input[0].cur.button, BTN_L)) {
-                    player->actor.velocity.y = 6.34375f;
-                }
+            if (CHECK_BTN_ANY(gPlayState->state.input[0].cur.button, BTN_L)) {
+                player->actor.velocity.y = 6.34375f;
             }
         }
     });
@@ -104,23 +104,23 @@ void RegisterMoonJumpOnL() {
 
 void RegisterInfiniteISG() {
     GameInteractor::Instance->RegisterGameHook<GameInteractor::OnGameFrameUpdate>([]() {
+        if (!gPlayState) return;
+
         if (CVarGetInteger("gEzISG", 0) != 0) {
-            if (gPlayState) {
-                Player* player = GET_PLAYER(gPlayState);
-                player->swordState = 1;
-            }
+            Player* player = GET_PLAYER(gPlayState);
+            player->swordState = 1;
         }
     });
 }
 
 void RegisterUnrestrictedItems() {
     GameInteractor::Instance->RegisterGameHook<GameInteractor::OnGameFrameUpdate>([]() {
+        if (!gPlayState) return;
+
         if (CVarGetInteger("gNoRestrictItems", 0) != 0) {
-            if (gPlayState) {
-                u8 sunsBackup = gPlayState->interfaceCtx.restrictions.sunsSong;
-                memset(&gPlayState->interfaceCtx.restrictions, 0, sizeof(gPlayState->interfaceCtx.restrictions));
-                gPlayState->interfaceCtx.restrictions.sunsSong = sunsBackup;
-            }
+            u8 sunsBackup = gPlayState->interfaceCtx.restrictions.sunsSong;
+            memset(&gPlayState->interfaceCtx.restrictions, 0, sizeof(gPlayState->interfaceCtx.restrictions));
+            gPlayState->interfaceCtx.restrictions.sunsSong = sunsBackup;
         }
     });
 }
@@ -142,35 +142,31 @@ void RegisterFreezeTime() {
 
 /// Switches Link's age and respawns him at the last entrance he entered.
 void RegisterSwitchAge() {
-    bool warped = false;
-    Vec3f playerPos;
-    int16_t playerYaw;
-    
-    GameInteractor::Instance->RegisterGameHook<GameInteractor::OnGameFrameUpdate>([&warped, &playerPos, &playerYaw]() {
+    GameInteractor::Instance->RegisterGameHook<GameInteractor::OnGameFrameUpdate>([]() {
+        static bool warped = false;
+        static Vec3f playerPos;
+        static int16_t playerYaw;
+
+        if (!gPlayState) return;
+
         if (CVarGetInteger("gSwitchAge", 0) != 0) {
             CVarSetInteger("gSwitchAge", 0);
-            if (gPlayState) {
-                playerPos = GET_PLAYER(gPlayState)->actor.world.pos;
-                playerYaw = GET_PLAYER(gPlayState)->actor.shape.rot.y;
-                gPlayState->nextEntranceIndex = gSaveContext.entranceIndex;
-                gPlayState->sceneLoadFlag = 0x14;
-                gPlayState->fadeTransition = 11;
-                gSaveContext.nextTransitionType = 11;
-                warped = true;
-                if (gPlayState->linkAgeOnLoad == 1) {
-                    gPlayState->linkAgeOnLoad = 0;
-                } else {
-                    gPlayState->linkAgeOnLoad = 1;
-                }
-            }
+            playerPos = GET_PLAYER(gPlayState)->actor.world.pos;
+            playerYaw = GET_PLAYER(gPlayState)->actor.shape.rot.y;
+
+            gPlayState->nextEntranceIndex = gSaveContext.entranceIndex;
+            gPlayState->sceneLoadFlag = 0x14;
+            gPlayState->fadeTransition = 11;
+            gSaveContext.nextTransitionType = 11;
+            gPlayState->linkAgeOnLoad ^= 1;
+
+            warped = true;
         }
-        
-        if (gPlayState) {
-            if (warped && gPlayState->sceneLoadFlag != 0x0014 && gSaveContext.nextTransitionType == 255) {
-                GET_PLAYER(gPlayState)->actor.shape.rot.y = playerYaw;
-                GET_PLAYER(gPlayState)->actor.world.pos = playerPos;
-                warped = false;
-            }
+
+        if (warped && gPlayState->sceneLoadFlag != 0x0014 && gSaveContext.nextTransitionType == 255) {
+            GET_PLAYER(gPlayState)->actor.shape.rot.y = playerYaw;
+            GET_PLAYER(gPlayState)->actor.world.pos = playerPos;
+            warped = false;
         }
     });
 }