mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-29 23:32:23 +00:00
dmnt-cheat: Skeleton cheat manager
This commit is contained in:
parent
434f600f95
commit
66d5c9fe26
3 changed files with 110 additions and 0 deletions
75
stratosphere/dmnt/source/dmnt_cheat_manager.cpp
Normal file
75
stratosphere/dmnt/source/dmnt_cheat_manager.cpp
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
31
stratosphere/dmnt/source/dmnt_cheat_manager.hpp
Normal file
31
stratosphere/dmnt/source/dmnt_cheat_manager.hpp
Normal 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();
|
||||||
|
};
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
#include "dmnt_service.hpp"
|
#include "dmnt_service.hpp"
|
||||||
#include "dmnt_cheat_service.hpp"
|
#include "dmnt_cheat_service.hpp"
|
||||||
|
#include "dmnt_cheat_manager.hpp"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
extern u32 __start__;
|
extern u32 __start__;
|
||||||
|
@ -125,6 +126,9 @@ int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
consoleDebugInit(debugDevice_SVC);
|
consoleDebugInit(debugDevice_SVC);
|
||||||
|
|
||||||
|
/* Start cheat manager. */
|
||||||
|
DmntCheatManager::InitializeCheatManager();
|
||||||
|
|
||||||
/* Nintendo uses four threads. Add a fifth for our cheat service. */
|
/* Nintendo uses four threads. Add a fifth for our cheat service. */
|
||||||
auto server_manager = new WaitableManager(5);
|
auto server_manager = new WaitableManager(5);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue