2019-09-16 10:22:08 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2019 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"
|
|
|
|
#include "impl/dmnt_cheat_api.hpp"
|
|
|
|
|
|
|
|
namespace sts::dmnt::cheat {
|
|
|
|
|
|
|
|
/* ========================================================================================= */
|
|
|
|
/* ==================================== Meta Commands ==================================== */
|
|
|
|
/* ========================================================================================= */
|
|
|
|
|
2019-10-18 06:18:27 +02:00
|
|
|
void CheatService::HasCheatProcess(sf::Out<bool> out) {
|
2019-09-16 10:22:08 +02:00
|
|
|
out.SetValue(dmnt::cheat::impl::GetHasActiveCheatProcess());
|
|
|
|
}
|
|
|
|
|
2019-10-18 06:18:27 +02:00
|
|
|
void CheatService::GetCheatProcessEvent(sf::OutCopyHandle out_event) {
|
2019-09-16 10:22:08 +02:00
|
|
|
out_event.SetValue(dmnt::cheat::impl::GetCheatProcessEventHandle());
|
|
|
|
}
|
|
|
|
|
2019-10-18 06:18:27 +02:00
|
|
|
Result CheatService::GetCheatProcessMetadata(sf::Out<CheatProcessMetadata> out_metadata) {
|
2019-09-16 10:22:08 +02:00
|
|
|
return dmnt::cheat::impl::GetCheatProcessMetadata(out_metadata.GetPointer());
|
|
|
|
}
|
|
|
|
|
|
|
|
Result CheatService::ForceOpenCheatProcess() {
|
|
|
|
if (R_FAILED(dmnt::cheat::impl::ForceOpenCheatProcess())) {
|
|
|
|
return ResultDmntCheatNotAttached;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ResultSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ========================================================================================= */
|
|
|
|
/* =================================== Memory Commands =================================== */
|
|
|
|
/* ========================================================================================= */
|
|
|
|
|
2019-10-18 06:18:27 +02:00
|
|
|
Result CheatService::GetCheatProcessMappingCount(sf::Out<u64> out_count) {
|
2019-09-16 10:22:08 +02:00
|
|
|
return dmnt::cheat::impl::GetCheatProcessMappingCount(out_count.GetPointer());
|
|
|
|
}
|
|
|
|
|
2019-10-18 06:18:27 +02:00
|
|
|
Result CheatService::GetCheatProcessMappings(const sf::OutArray<MemoryInfo> &mappings, sf::Out<u64> out_count, u64 offset) {
|
|
|
|
if (mappings.GetPointer() == nullptr) {
|
2019-09-16 10:22:08 +02:00
|
|
|
return ResultDmntCheatNullBuffer;
|
|
|
|
}
|
|
|
|
|
2019-10-18 06:18:27 +02:00
|
|
|
return dmnt::cheat::impl::GetCheatProcessMappings(mappings.GetPointer(), mappings.GetSize(), out_count.GetPointer(), offset);
|
2019-09-16 10:22:08 +02:00
|
|
|
}
|
|
|
|
|
2019-10-18 06:18:27 +02:00
|
|
|
Result CheatService::ReadCheatProcessMemory(const sf::OutBuffer &buffer, u64 address, u64 out_size) {
|
|
|
|
if (buffer.GetPointer() == nullptr) {
|
2019-09-16 10:22:08 +02:00
|
|
|
return ResultDmntCheatNullBuffer;
|
|
|
|
}
|
|
|
|
|
2019-10-18 06:18:27 +02:00
|
|
|
return dmnt::cheat::impl::ReadCheatProcessMemory(address, buffer.GetPointer(), std::min(out_size, buffer.GetSize()));
|
2019-09-16 10:22:08 +02:00
|
|
|
}
|
|
|
|
|
2019-10-18 06:18:27 +02:00
|
|
|
Result CheatService::WriteCheatProcessMemory(const sf::InBuffer &buffer, u64 address, u64 in_size) {
|
|
|
|
if (buffer.GetPointer() == nullptr) {
|
2019-09-16 10:22:08 +02:00
|
|
|
return ResultDmntCheatNullBuffer;
|
|
|
|
}
|
|
|
|
|
2019-10-18 06:18:27 +02:00
|
|
|
return dmnt::cheat::impl::WriteCheatProcessMemory(address, buffer.GetPointer(), std::min(in_size, buffer.GetSize()));
|
2019-09-16 10:22:08 +02:00
|
|
|
}
|
|
|
|
|
2019-10-18 06:18:27 +02:00
|
|
|
Result CheatService::QueryCheatProcessMemory(sf::Out<MemoryInfo> mapping, u64 address) {
|
2019-09-16 10:22:08 +02:00
|
|
|
return dmnt::cheat::impl::QueryCheatProcessMemory(mapping.GetPointer(), address);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ========================================================================================= */
|
|
|
|
/* =================================== Cheat Commands ==================================== */
|
|
|
|
/* ========================================================================================= */
|
|
|
|
|
2019-10-18 06:18:27 +02:00
|
|
|
Result CheatService::GetCheatCount(sf::Out<u64> out_count) {
|
2019-09-16 10:22:08 +02:00
|
|
|
return dmnt::cheat::impl::GetCheatCount(out_count.GetPointer());
|
|
|
|
}
|
|
|
|
|
2019-10-18 06:18:27 +02:00
|
|
|
Result CheatService::GetCheats(const sf::OutArray<CheatEntry> &cheats, sf::Out<u64> out_count, u64 offset) {
|
|
|
|
if (cheats.GetPointer() == nullptr) {
|
2019-09-16 10:22:08 +02:00
|
|
|
return ResultDmntCheatNullBuffer;
|
|
|
|
}
|
|
|
|
|
2019-10-18 06:18:27 +02:00
|
|
|
return dmnt::cheat::impl::GetCheats(cheats.GetPointer(), cheats.GetSize(), out_count.GetPointer(), offset);
|
2019-09-16 10:22:08 +02:00
|
|
|
}
|
|
|
|
|
2019-10-18 06:18:27 +02:00
|
|
|
Result CheatService::GetCheatById(sf::Out<CheatEntry> cheat, u32 cheat_id) {
|
|
|
|
return dmnt::cheat::impl::GetCheatById(cheat.GetPointer(), cheat_id);
|
2019-09-16 10:22:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Result CheatService::ToggleCheat(u32 cheat_id) {
|
|
|
|
return dmnt::cheat::impl::ToggleCheat(cheat_id);
|
|
|
|
}
|
|
|
|
|
2019-10-18 06:18:27 +02:00
|
|
|
Result CheatService::AddCheat(const CheatDefinition &cheat, sf::Out<u32> out_cheat_id, bool enabled) {
|
|
|
|
return dmnt::cheat::impl::AddCheat(out_cheat_id.GetPointer(), cheat, enabled);
|
2019-09-16 10:22:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Result CheatService::RemoveCheat(u32 cheat_id) {
|
|
|
|
return dmnt::cheat::impl::RemoveCheat(cheat_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ========================================================================================= */
|
|
|
|
/* =================================== Address Commands ================================== */
|
|
|
|
/* ========================================================================================= */
|
|
|
|
|
2019-10-18 06:18:27 +02:00
|
|
|
Result CheatService::GetFrozenAddressCount(sf::Out<u64> out_count) {
|
2019-09-16 10:22:08 +02:00
|
|
|
return dmnt::cheat::impl::GetFrozenAddressCount(out_count.GetPointer());
|
|
|
|
}
|
|
|
|
|
2019-10-18 06:18:27 +02:00
|
|
|
Result CheatService::GetFrozenAddresses(const sf::OutArray<FrozenAddressEntry> &addresses, sf::Out<u64> out_count, u64 offset) {
|
|
|
|
if (addresses.GetPointer() == nullptr) {
|
2019-09-16 10:22:08 +02:00
|
|
|
return ResultDmntCheatNullBuffer;
|
|
|
|
}
|
|
|
|
|
2019-10-18 06:18:27 +02:00
|
|
|
return dmnt::cheat::impl::GetFrozenAddresses(addresses.GetPointer(), addresses.GetSize(), out_count.GetPointer(), offset);
|
2019-09-16 10:22:08 +02:00
|
|
|
}
|
|
|
|
|
2019-10-18 06:18:27 +02:00
|
|
|
Result CheatService::GetFrozenAddress(sf::Out<FrozenAddressEntry> entry, u64 address) {
|
2019-09-16 10:22:08 +02:00
|
|
|
return dmnt::cheat::impl::GetFrozenAddress(entry.GetPointer(), address);
|
|
|
|
}
|
|
|
|
|
2019-10-18 06:18:27 +02:00
|
|
|
Result CheatService::EnableFrozenAddress(sf::Out<u64> out_value, u64 address, u64 width) {
|
2019-09-16 10:22:08 +02:00
|
|
|
switch (width) {
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 4:
|
|
|
|
case 8:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return ResultDmntCheatInvalidFreezeWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dmnt::cheat::impl::EnableFrozenAddress(out_value.GetPointer(), address, width);
|
|
|
|
}
|
|
|
|
|
|
|
|
Result CheatService::DisableFrozenAddress(u64 address) {
|
|
|
|
return dmnt::cheat::impl::DisableFrozenAddress(address);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|