diff --git a/stratosphere/dmnt/source/dmnt_cheat_manager.cpp b/stratosphere/dmnt/source/dmnt_cheat_manager.cpp
new file mode 100644
index 000000000..65c98d7cd
--- /dev/null
+++ b/stratosphere/dmnt/source/dmnt_cheat_manager.cpp
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2018 Atmosphère-NX
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include
+#include "dmnt_cheat_manager.hpp"
+
+static HosMutex g_cheat_lock;
+static HosThread g_detect_thread, g_vm_thread;
+
+Handle DmntCheatManager::PrepareDebugNextApplication() {
+ Result rc;
+ Handle event_h;
+ if (R_FAILED((rc = pmdmntEnableDebugForApplication(&event_h)))) {
+ fatalSimple(rc);
+ }
+
+ return event_h;
+}
+
+void DmntCheatManager::OnNewApplicationLaunch() {
+ std::scoped_lock lk(g_cheat_lock);
+
+ /* TODO: load information about the new process. */
+}
+
+void DmntCheatManager::DetectThread(void *arg) {
+ auto waiter = new WaitableManager(1);
+ waiter->AddWaitable(LoadReadOnlySystemEvent(PrepareDebugNextApplication(), [](u64 timeout) {
+ /* Process stuff for new application. */
+ DmntCheatManager::OnNewApplicationLaunch();
+
+ /* Setup detection for the next application, and close the duplicate handle. */
+ svcCloseHandle(PrepareDebugNextApplication());
+
+ return 0x0;
+ }, true));
+
+ waiter->Process();
+ delete waiter;
+}
+
+void DmntCheatManager::VmThread(void *arg) {
+ while (true) {
+ /* TODO */
+ svcSleepThread(0x5000000ul);
+ }
+}
+
+void DmntCheatManager::InitializeCheatManager() {
+ /* Spawn application detection thread, spawn cheat vm thread. */
+ if (R_FAILED(g_detect_thread.Initialize(&DmntCheatManager::DetectThread, nullptr, 0x4000, 28))) {
+ std::abort();
+ }
+ if (R_FAILED(g_vm_thread.Initialize(&DmntCheatManager::VmThread, nullptr, 0x4000, 28))) {
+ std::abort();
+ }
+
+ /* Start threads. */
+ if (R_FAILED(g_detect_thread.Start()) || R_FAILED(g_vm_thread.Start())) {
+ std::abort();
+ }
+}
diff --git a/stratosphere/dmnt/source/dmnt_cheat_manager.hpp b/stratosphere/dmnt/source/dmnt_cheat_manager.hpp
new file mode 100644
index 000000000..a0ad6d3c7
--- /dev/null
+++ b/stratosphere/dmnt/source/dmnt_cheat_manager.hpp
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2018 Atmosphère-NX
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
+#include
+#include
+
+#include "dmnt_cheat_types.hpp"
+
+class DmntCheatManager {
+ private:
+ static Handle PrepareDebugNextApplication();
+ static void OnNewApplicationLaunch();
+ static void DetectThread(void *arg);
+ static void VmThread(void *arg);
+ public:
+ static void InitializeCheatManager();
+};
diff --git a/stratosphere/dmnt/source/dmnt_main.cpp b/stratosphere/dmnt/source/dmnt_main.cpp
index bf56137b7..e4321328f 100644
--- a/stratosphere/dmnt/source/dmnt_main.cpp
+++ b/stratosphere/dmnt/source/dmnt_main.cpp
@@ -25,6 +25,7 @@
#include "dmnt_service.hpp"
#include "dmnt_cheat_service.hpp"
+#include "dmnt_cheat_manager.hpp"
extern "C" {
extern u32 __start__;
@@ -125,6 +126,9 @@ int main(int argc, char **argv)
{
consoleDebugInit(debugDevice_SVC);
+ /* Start cheat manager. */
+ DmntCheatManager::InitializeCheatManager();
+
/* Nintendo uses four threads. Add a fifth for our cheat service. */
auto server_manager = new WaitableManager(5);