From 742f67908c191a71b204519a353fb5e42a9dea56 Mon Sep 17 00:00:00 2001
From: Gus Caplan <me@gus.host>
Date: Thu, 14 Jul 2022 18:42:56 -0700
Subject: [PATCH] implement resume message

---
 src/core/hle/service/am/am.cpp |  4 ++++
 src/core/hle/service/am/am.h   |  1 +
 src/yuzu/main.cpp              | 17 +++++++++++++++++
 src/yuzu/main.h                |  1 +
 4 files changed, 23 insertions(+)

diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp
index 9c62ebc60d..9116dd77c9 100644
--- a/src/core/hle/service/am/am.cpp
+++ b/src/core/hle/service/am/am.cpp
@@ -636,6 +636,10 @@ void AppletMessageQueue::RequestExit() {
     PushMessage(AppletMessage::Exit);
 }
 
+void AppletMessageQueue::RequestResume() {
+    PushMessage(AppletMessage::Resume);
+}
+
 void AppletMessageQueue::FocusStateChanged() {
     PushMessage(AppletMessage::FocusStateChanged);
 }
diff --git a/src/core/hle/service/am/am.h b/src/core/hle/service/am/am.h
index 988ead2151..53144427b4 100644
--- a/src/core/hle/service/am/am.h
+++ b/src/core/hle/service/am/am.h
@@ -90,6 +90,7 @@ public:
     AppletMessage PopMessage();
     std::size_t GetMessageCount() const;
     void RequestExit();
+    void RequestResume();
     void FocusStateChanged();
     void OperationModeChanged();
 
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index ed802d3290..e60d840548 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -1131,6 +1131,7 @@ void GMainWindow::OnAppFocusStateChanged(Qt::ApplicationState state) {
             OnPauseGame();
         } else if (!emu_thread->IsRunning() && auto_paused && state == Qt::ApplicationActive) {
             auto_paused = false;
+            RequestGameResume();
             OnStartGame();
         }
     }
@@ -2570,6 +2571,7 @@ void GMainWindow::OnPauseContinueGame() {
         if (emu_thread->IsRunning()) {
             OnPauseGame();
         } else {
+            RequestGameResume();
             OnStartGame();
         }
     }
@@ -3749,6 +3751,21 @@ void GMainWindow::RequestGameExit() {
     }
 }
 
+void GMainWindow::RequestGameResume() {
+    auto& sm{system->ServiceManager()};
+    auto applet_oe = sm.GetService<Service::AM::AppletOE>("appletOE");
+    auto applet_ae = sm.GetService<Service::AM::AppletAE>("appletAE");
+
+    if (applet_oe != nullptr) {
+        applet_oe->GetMessageQueue()->RequestResume();
+        return;
+    }
+
+    if (applet_ae != nullptr) {
+        applet_ae->GetMessageQueue()->RequestResume();
+    }
+}
+
 void GMainWindow::filterBarSetChecked(bool state) {
     ui->action_Show_Filter_Bar->setChecked(state);
     emit(OnToggleFilterBar());
diff --git a/src/yuzu/main.h b/src/yuzu/main.h
index 8cf224c9c2..09e37f1528 100644
--- a/src/yuzu/main.h
+++ b/src/yuzu/main.h
@@ -244,6 +244,7 @@ private:
     bool ConfirmChangeGame();
     bool ConfirmForceLockedExit();
     void RequestGameExit();
+    void RequestGameResume();
     void closeEvent(QCloseEvent* event) override;
 
 private slots: