dmnt-cheat: Skeleton cheat manager

This commit is contained in:
Michael Scire 2019-02-27 03:30:08 -08:00
parent 434f600f95
commit 66d5c9fe26
3 changed files with 110 additions and 0 deletions

View file

@ -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 <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();
}
}

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <switch.h>
#include <stratosphere.hpp>
#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();
};

View file

@ -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);