mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-05 19:51:45 +00:00
76 lines
2.3 KiB
C++
76 lines
2.3 KiB
C++
|
/*
|
||
|
* 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 <http://www.gnu.org/licenses/>.
|
||
|
*/
|
||
|
|
||
|
#include <switch.h>
|
||
|
#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<HosMutex> 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();
|
||
|
}
|
||
|
}
|