2019-02-27 10:50:53 +00:00
|
|
|
/*
|
|
|
|
* 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_service.hpp"
|
2019-02-27 12:37:02 +00:00
|
|
|
#include "dmnt_cheat_manager.hpp"
|
2019-02-27 10:50:53 +00:00
|
|
|
|
2019-03-05 05:11:12 +00:00
|
|
|
/* ========================================================================================= */
|
|
|
|
/* ==================================== Meta Commands ==================================== */
|
|
|
|
/* ========================================================================================= */
|
|
|
|
|
2019-02-27 10:50:53 +00:00
|
|
|
void DmntCheatService::HasCheatProcess(Out<bool> out) {
|
2019-02-27 12:37:02 +00:00
|
|
|
out.SetValue(DmntCheatManager::GetHasActiveCheatProcess());
|
2019-02-27 10:50:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DmntCheatService::GetCheatProcessEvent(Out<CopiedHandle> out_event) {
|
2019-02-27 12:37:02 +00:00
|
|
|
out_event.SetValue(DmntCheatManager::GetCheatProcessEventHandle());
|
2019-02-27 10:50:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result DmntCheatService::GetCheatProcessMetadata(Out<CheatProcessMetadata> out_metadata) {
|
2019-02-27 12:37:02 +00:00
|
|
|
return DmntCheatManager::GetCheatProcessMetadata(out_metadata.GetPointer());
|
2019-02-27 10:50:53 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 14:55:37 +00:00
|
|
|
Result DmntCheatService::ForceOpenCheatProcess() {
|
|
|
|
Result rc = DmntCheatManager::ForceOpenCheatProcess();
|
|
|
|
|
|
|
|
if (R_FAILED(rc)) {
|
|
|
|
rc = ResultDmntCheatNotAttached;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2019-03-05 05:11:12 +00:00
|
|
|
/* ========================================================================================= */
|
|
|
|
/* =================================== Memory Commands =================================== */
|
|
|
|
/* ========================================================================================= */
|
2019-02-27 10:50:53 +00:00
|
|
|
|
|
|
|
Result DmntCheatService::GetCheatProcessMappingCount(Out<u64> out_count) {
|
2019-03-04 13:56:44 +00:00
|
|
|
return DmntCheatManager::GetCheatProcessMappingCount(out_count.GetPointer());
|
2019-02-27 10:50:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result DmntCheatService::GetCheatProcessMappings(OutBuffer<MemoryInfo> mappings, Out<u64> out_count, u64 offset) {
|
2019-03-04 13:56:44 +00:00
|
|
|
if (mappings.buffer == nullptr) {
|
|
|
|
return ResultDmntCheatNullBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DmntCheatManager::GetCheatProcessMappings(mappings.buffer, mappings.num_elements, out_count.GetPointer(), offset);
|
2019-02-27 10:50:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result DmntCheatService::ReadCheatProcessMemory(OutBuffer<u8> buffer, u64 address, u64 out_size) {
|
2019-03-04 13:56:44 +00:00
|
|
|
if (buffer.buffer == nullptr) {
|
|
|
|
return ResultDmntCheatNullBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
u64 sz = out_size;
|
|
|
|
if (buffer.num_elements < sz) {
|
|
|
|
sz = buffer.num_elements;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DmntCheatManager::ReadCheatProcessMemory(address, buffer.buffer, sz);
|
2019-02-27 10:50:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result DmntCheatService::WriteCheatProcessMemory(InBuffer<u8> buffer, u64 address, u64 in_size) {
|
2019-03-04 13:56:44 +00:00
|
|
|
if (buffer.buffer == nullptr) {
|
|
|
|
return ResultDmntCheatNullBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
u64 sz = in_size;
|
|
|
|
if (buffer.num_elements < sz) {
|
|
|
|
sz = buffer.num_elements;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DmntCheatManager::WriteCheatProcessMemory(address, buffer.buffer, sz);
|
|
|
|
}
|
|
|
|
|
|
|
|
Result DmntCheatService::QueryCheatProcessMemory(Out<MemoryInfo> mapping, u64 address) {
|
|
|
|
return DmntCheatManager::QueryCheatProcessMemory(mapping.GetPointer(), address);
|
2019-02-27 10:50:53 +00:00
|
|
|
}
|
|
|
|
|
2019-03-05 05:11:12 +00:00
|
|
|
/* ========================================================================================= */
|
|
|
|
/* =================================== Cheat Commands ==================================== */
|
|
|
|
/* ========================================================================================= */
|
2019-02-27 10:50:53 +00:00
|
|
|
|
|
|
|
Result DmntCheatService::GetCheatCount(Out<u64> out_count) {
|
2019-03-05 05:11:12 +00:00
|
|
|
return DmntCheatManager::GetCheatCount(out_count.GetPointer());
|
2019-02-27 10:50:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result DmntCheatService::GetCheats(OutBuffer<CheatEntry> cheats, Out<u64> out_count, u64 offset) {
|
2019-03-05 05:11:12 +00:00
|
|
|
if (cheats.buffer == nullptr) {
|
|
|
|
return ResultDmntCheatNullBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DmntCheatManager::GetCheats(cheats.buffer, cheats.num_elements, out_count.GetPointer(), offset);
|
2019-02-27 10:50:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result DmntCheatService::GetCheatById(OutBuffer<CheatEntry> cheat, u32 cheat_id) {
|
2019-03-05 05:11:12 +00:00
|
|
|
if (cheat.buffer == nullptr) {
|
|
|
|
return ResultDmntCheatNullBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cheat.num_elements < 1) {
|
|
|
|
return ResultDmntCheatInvalidBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DmntCheatManager::GetCheatById(cheat.buffer, cheat_id);
|
2019-02-27 10:50:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result DmntCheatService::ToggleCheat(u32 cheat_id) {
|
2019-03-05 05:11:12 +00:00
|
|
|
return DmntCheatManager::ToggleCheat(cheat_id);
|
2019-02-27 10:50:53 +00:00
|
|
|
}
|
|
|
|
|
2019-02-28 02:33:07 +00:00
|
|
|
Result DmntCheatService::AddCheat(InBuffer<CheatDefinition> cheat, Out<u32> out_cheat_id, bool enabled) {
|
2019-03-05 05:11:12 +00:00
|
|
|
if (cheat.buffer == nullptr) {
|
|
|
|
return ResultDmntCheatNullBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cheat.num_elements < 1) {
|
|
|
|
return ResultDmntCheatInvalidBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DmntCheatManager::AddCheat(out_cheat_id.GetPointer(), cheat.buffer, enabled);
|
2019-02-27 10:50:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result DmntCheatService::RemoveCheat(u32 cheat_id) {
|
2019-03-05 05:11:12 +00:00
|
|
|
return DmntCheatManager::RemoveCheat(cheat_id);
|
2019-02-27 10:50:53 +00:00
|
|
|
}
|
|
|
|
|
2019-03-05 05:11:12 +00:00
|
|
|
/* ========================================================================================= */
|
|
|
|
/* =================================== Address Commands ================================== */
|
|
|
|
/* ========================================================================================= */
|
2019-02-27 10:50:53 +00:00
|
|
|
|
|
|
|
Result DmntCheatService::GetFrozenAddressCount(Out<u64> out_count) {
|
|
|
|
/* TODO */
|
|
|
|
return 0xF601;
|
|
|
|
}
|
|
|
|
|
|
|
|
Result DmntCheatService::GetFrozenAddresses(OutBuffer<uintptr_t> addresses, Out<u64> out_count, u64 offset) {
|
|
|
|
/* TODO */
|
|
|
|
return 0xF601;
|
|
|
|
}
|
|
|
|
|
|
|
|
Result DmntCheatService::ToggleAddressFrozen(uintptr_t address) {
|
|
|
|
/* TODO */
|
|
|
|
return 0xF601;
|
|
|
|
}
|