diff --git a/stratosphere/dmnt/source/dmnt_cheat_debug_events_manager.cpp b/stratosphere/dmnt/source/dmnt_cheat_debug_events_manager.cpp index 1a9d4c03a..638533025 100644 --- a/stratosphere/dmnt/source/dmnt_cheat_debug_events_manager.cpp +++ b/stratosphere/dmnt/source/dmnt_cheat_debug_events_manager.cpp @@ -13,7 +13,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + #include #include #include "dmnt_config.hpp" @@ -37,14 +37,14 @@ void DmntCheatDebugEventsManager::PerCoreThreadFunc(void *arg) { g_per_core_queues[current_core]->Receive(&x); debug_handle = static_cast(x); } - + /* Continue the process, if needed. */ if ((GetRuntimeFirmwareVersion() >= FirmwareVersion_300)) { svcContinueDebugEvent(debug_handle, 5, nullptr, 0); } else { svcLegacyContinueDebugEvent(debug_handle, 5, 0); } - + g_continued_signal.Signal(); } } @@ -55,7 +55,7 @@ void DmntCheatDebugEventsManager::ContinueCheatProcess(Handle cheat_dbg_hnd) { while (R_SUCCEEDED(svcGetDebugEvent((u8 *)&dbg_event, cheat_dbg_hnd))) { /* ... */ } - + size_t target_core = DmntCheatDebugEventsManager::NumCores - 1; /* Retrieve correct core for new thread event. */ if (dbg_event.type == DebugEventType::AttachThread) { @@ -65,14 +65,14 @@ void DmntCheatDebugEventsManager::ContinueCheatProcess(Handle cheat_dbg_hnd) { if (R_FAILED(rc)) { fatalSimple(rc); } - - + + target_core = out32; } - + /* Make appropriate thread continue. */ g_per_core_queues[target_core]->Send(static_cast(cheat_dbg_hnd)); - + /* Wait. */ g_continued_signal.Wait(); g_continued_signal.Reset(); @@ -83,17 +83,17 @@ void DmntCheatDebugEventsManager::Initialize() { for (size_t i = 0; i < DmntCheatDebugEventsManager::NumCores; i++) { /* Create queue. */ g_per_core_queues[i] = new HosMessageQueue(1); - + /* Create thread. */ if (R_FAILED(g_per_core_threads[i].Initialize(&DmntCheatDebugEventsManager::PerCoreThreadFunc, reinterpret_cast(i), 0x1000, 24, i))) { std::abort(); } - + /* Set core mask. */ if (R_FAILED(svcSetThreadCoreMask(g_per_core_threads[i].GetHandle(), i, (1u << i)))) { std::abort(); } - + /* Start thread. */ if (R_FAILED(g_per_core_threads[i].Start())) { std::abort(); diff --git a/stratosphere/dmnt/source/dmnt_cheat_debug_events_manager.hpp b/stratosphere/dmnt/source/dmnt_cheat_debug_events_manager.hpp index c35ee16af..c31ea37f7 100644 --- a/stratosphere/dmnt/source/dmnt_cheat_debug_events_manager.hpp +++ b/stratosphere/dmnt/source/dmnt_cheat_debug_events_manager.hpp @@ -13,7 +13,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + #pragma once #include #include @@ -126,6 +126,6 @@ class DmntCheatDebugEventsManager { static void PerCoreThreadFunc(void *arg); public: static void ContinueCheatProcess(Handle cheat_dbg_hnd); - + static void Initialize(); }; diff --git a/stratosphere/dmnt/source/dmnt_cheat_manager.hpp b/stratosphere/dmnt/source/dmnt_cheat_manager.hpp index d5b105904..3178d469a 100644 --- a/stratosphere/dmnt/source/dmnt_cheat_manager.hpp +++ b/stratosphere/dmnt/source/dmnt_cheat_manager.hpp @@ -13,7 +13,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + #pragma once #include #include @@ -30,14 +30,14 @@ class DmntCheatManager { static void DetectThread(void *arg); static void VmThread(void *arg); static void DebugEventsThread(void *arg); - + static void StartDebugEventsThread(); static void WaitDebugEventsThread(); - + static bool HasActiveCheatProcess(); static void CloseActiveCheatProcess(); static void ContinueCheatProcess(); - + static void ResetCheatEntry(size_t i); static void ResetAllCheatEntries(); static CheatEntry *GetFreeCheatEntry(); @@ -49,35 +49,35 @@ class DmntCheatManager { static bool ParseCheatToggles(const char *s, size_t len); static bool LoadCheatToggles(u64 title_id); static void SaveCheatToggles(u64 title_id); - + static void ResetFrozenAddresses(); public: static bool GetHasActiveCheatProcess(); static Handle GetCheatProcessEventHandle(); static Result GetCheatProcessMetadata(CheatProcessMetadata *out); static Result ForceOpenCheatProcess(); - + static Result ReadCheatProcessMemoryForVm(u64 proc_addr, void *out_data, size_t size); static Result WriteCheatProcessMemoryForVm(u64 proc_addr, const void *data, size_t size); - + static Result GetCheatProcessMappingCount(u64 *out_count); static Result GetCheatProcessMappings(MemoryInfo *mappings, size_t max_count, u64 *out_count, u64 offset); static Result ReadCheatProcessMemory(u64 proc_addr, void *out_data, size_t size); static Result WriteCheatProcessMemory(u64 proc_addr, const void *data, size_t size); static Result QueryCheatProcessMemory(MemoryInfo *mapping, u64 address); - + static Result GetCheatCount(u64 *out_count); static Result GetCheats(CheatEntry *cheats, size_t max_count, u64 *out_count, u64 offset); static Result GetCheatById(CheatEntry *out_cheat, u32 cheat_id); static Result ToggleCheat(u32 cheat_id); static Result AddCheat(u32 *out_id, CheatDefinition *def, bool enabled); static Result RemoveCheat(u32 cheat_id); - + static Result GetFrozenAddressCount(u64 *out_count); static Result GetFrozenAddresses(FrozenAddressEntry *frz_addrs, size_t max_count, u64 *out_count, u64 offset); static Result GetFrozenAddress(FrozenAddressEntry *frz_addr, u64 address); static Result EnableFrozenAddress(u64 *out_value, u64 address, u64 width); static Result DisableFrozenAddress(u64 address); - + static void InitializeCheatManager(); }; diff --git a/stratosphere/dmnt/source/dmnt_cheat_service.hpp b/stratosphere/dmnt/source/dmnt_cheat_service.hpp index a633c2d67..eedfb27f0 100644 --- a/stratosphere/dmnt/source/dmnt_cheat_service.hpp +++ b/stratosphere/dmnt/source/dmnt_cheat_service.hpp @@ -13,7 +13,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + #pragma once #include #include @@ -26,14 +26,14 @@ enum DmntCheatCmd { DmntCheat_Cmd_GetCheatProcessEvent = 65001, DmntCheat_Cmd_GetCheatProcessMetadata = 65002, DmntCheat_Cmd_ForceOpenCheatProcess = 65003, - + /* Interact with Memory */ DmntCheat_Cmd_GetCheatProcessMappingCount = 65100, DmntCheat_Cmd_GetCheatProcessMappings = 65101, DmntCheat_Cmd_ReadCheatProcessMemory = 65102, DmntCheat_Cmd_WriteCheatProcessMemory = 65103, DmntCheat_Cmd_QueryCheatProcessMemory = 65104, - + /* Interact with Cheats */ DmntCheat_Cmd_GetCheatCount = 65200, DmntCheat_Cmd_GetCheats = 65201, @@ -41,7 +41,7 @@ enum DmntCheatCmd { DmntCheat_Cmd_ToggleCheat = 65203, DmntCheat_Cmd_AddCheat = 65204, DmntCheat_Cmd_RemoveCheat = 65205, - + /* Interact with Frozen Addresses */ DmntCheat_Cmd_GetFrozenAddressCount = 65300, DmntCheat_Cmd_GetFrozenAddresses = 65301, @@ -56,20 +56,20 @@ class DmntCheatService final : public IServiceObject { void GetCheatProcessEvent(Out out_event); Result GetCheatProcessMetadata(Out out_metadata); Result ForceOpenCheatProcess(); - + Result GetCheatProcessMappingCount(Out out_count); Result GetCheatProcessMappings(OutBuffer mappings, Out out_count, u64 offset); Result ReadCheatProcessMemory(OutBuffer buffer, u64 address, u64 out_size); Result WriteCheatProcessMemory(InBuffer buffer, u64 address, u64 in_size); Result QueryCheatProcessMemory(Out mapping, u64 address); - + Result GetCheatCount(Out out_count); Result GetCheats(OutBuffer cheats, Out out_count, u64 offset); Result GetCheatById(OutBuffer cheat, u32 cheat_id); Result ToggleCheat(u32 cheat_id); Result AddCheat(InBuffer cheat, Out out_cheat_id, bool enabled); Result RemoveCheat(u32 cheat_id); - + Result GetFrozenAddressCount(Out out_count); Result GetFrozenAddresses(OutBuffer addresses, Out out_count, u64 offset); Result GetFrozenAddress(Out entry, u64 address); diff --git a/stratosphere/dmnt/source/dmnt_cheat_types.hpp b/stratosphere/dmnt/source/dmnt_cheat_types.hpp index 247f7bf2c..8c5305471 100644 --- a/stratosphere/dmnt/source/dmnt_cheat_types.hpp +++ b/stratosphere/dmnt/source/dmnt_cheat_types.hpp @@ -13,7 +13,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + #pragma once #include #include diff --git a/stratosphere/dmnt/source/dmnt_cheat_vm.hpp b/stratosphere/dmnt/source/dmnt_cheat_vm.hpp index 2241947b0..2ad1fcbbe 100644 --- a/stratosphere/dmnt/source/dmnt_cheat_vm.hpp +++ b/stratosphere/dmnt/source/dmnt_cheat_vm.hpp @@ -13,7 +13,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + #pragma once #include #include @@ -31,16 +31,16 @@ enum CheatVmOpcodeType : u32 { CheatVmOpcodeType_StoreStaticToAddress = 6, CheatVmOpcodeType_PerformArithmeticStatic = 7, CheatVmOpcodeType_BeginKeypressConditionalBlock = 8, - + /* These are not implemented by Gateway's VM. */ CheatVmOpcodeType_PerformArithmeticRegister = 9, CheatVmOpcodeType_StoreRegisterToAddress = 10, CheatVmOpcodeType_Reserved11 = 11, - + /* This is a meta entry, and not a real opcode. */ /* This is to facilitate multi-nybble instruction decoding. */ CheatVmOpcodeType_ExtendedWidth = 12, - + /* Extended width opcodes. */ CheatVmOpcodeType_BeginRegisterConditionalBlock = 0xC0, CheatVmOpcodeType_SaveRestoreRegister = 0xC1, @@ -49,7 +49,7 @@ enum CheatVmOpcodeType : u32 { /* This is a meta entry, and not a real opcode. */ /* This is to facilitate multi-nybble instruction decoding. */ CheatVmOpcodeType_DoubleExtendedWidth = 0xF0, - + /* Double-extended width opcodes. */ CheatVmOpcodeType_DebugLog = 0xFFF, }; @@ -74,13 +74,13 @@ enum RegisterArithmeticType : u32 { RegisterArithmeticType_Multiplication = 2, RegisterArithmeticType_LeftShift = 3, RegisterArithmeticType_RightShift = 4, - + /* These are not supported by Gateway's VM. */ RegisterArithmeticType_LogicalAnd = 5, RegisterArithmeticType_LogicalOr = 6, RegisterArithmeticType_LogicalNot = 7, RegisterArithmeticType_LogicalXor = 8, - + RegisterArithmeticType_None = 9, }; @@ -276,25 +276,25 @@ class DmntCheatVm { bool DecodeNextOpcode(CheatVmOpcode *out); void SkipConditionalBlock(); void ResetState(); - + /* For implementing the DebugLog opcode. */ void DebugLog(u32 log_id, u64 value); - + /* For debugging. These will be IFDEF'd out normally. */ void OpenDebugLogFile(); void CloseDebugLogFile(); void LogToDebugFile(const char *format, ...); void LogOpcode(const CheatVmOpcode *opcode); - + static u64 GetVmInt(VmInt value, u32 bit_width); static u64 GetCheatProcessAddress(const CheatProcessMetadata* metadata, MemoryAccessType mem_type, u64 rel_address); public: DmntCheatVm() { } - + size_t GetProgramSize() { return this->num_opcodes; } - + bool LoadProgram(const CheatEntry *cheats, size_t num_cheats); void Execute(const CheatProcessMetadata *metadata); #ifdef DMNT_CHEAT_VM_DEBUG_LOG diff --git a/stratosphere/dmnt/source/dmnt_config.cpp b/stratosphere/dmnt/source/dmnt_config.cpp index dc945c166..e61af7461 100644 --- a/stratosphere/dmnt/source/dmnt_config.cpp +++ b/stratosphere/dmnt/source/dmnt_config.cpp @@ -13,7 +13,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + #include #include #include @@ -33,7 +33,7 @@ static char g_config_ini_data[0x800]; static OverrideKey ParseOverrideKey(const char *value) { OverrideKey cfg; - + /* Parse on by default. */ if (value[0] == '!') { cfg.override_by_default = true; @@ -41,7 +41,7 @@ static OverrideKey ParseOverrideKey(const char *value) { } else { cfg.override_by_default = false; } - + /* Parse key combination. */ if (strcasecmp(value, "A") == 0) { cfg.key_combination = KEY_A; @@ -82,7 +82,7 @@ static OverrideKey ParseOverrideKey(const char *value) { } else { cfg.key_combination = 0; } - + return cfg; } @@ -101,7 +101,7 @@ static int DmntIniHandler(void *user, const char *section, const char *name, con static int DmntTitleSpecificIniHandler(void *user, const char *section, const char *name, const char *value) { /* We'll output an override key when relevant. */ OverrideKey *user_cfg = reinterpret_cast(user); - + if (strcasecmp(section, "override_config") == 0) { if (strcasecmp(name, "cheat_enable_key") == 0) { *user_cfg = ParseOverrideKey(value); @@ -117,20 +117,20 @@ void DmntConfigManager::RefreshConfiguration() { if (config == NULL) { return; } - + memset(g_config_ini_data, 0, sizeof(g_config_ini_data)); fread(g_config_ini_data, 1, sizeof(g_config_ini_data) - 1, config); fclose(config); - + ini_parse_string(g_config_ini_data, DmntIniHandler, NULL); } OverrideKey DmntConfigManager::GetTitleCheatEnableKey(u64 tid) { OverrideKey cfg = g_default_cheat_enable_key; char path[FS_MAX_PATH+1] = {0}; - snprintf(path, FS_MAX_PATH, "sdmc:/atmosphere/titles/%016lx/config.ini", tid); - - + snprintf(path, FS_MAX_PATH, "sdmc:/atmosphere/titles/%016lx/config.ini", tid); + + FILE *config = fopen(path, "r"); if (config != NULL) { ON_SCOPE_EXIT { fclose(config); }; @@ -138,7 +138,7 @@ OverrideKey DmntConfigManager::GetTitleCheatEnableKey(u64 tid) { /* Parse current title ini. */ ini_parse_file(config, DmntTitleSpecificIniHandler, &cfg); } - + return cfg; } @@ -151,7 +151,7 @@ static bool HasOverrideKey(OverrideKey *cfg) { bool DmntConfigManager::HasCheatEnableButton(u64 tid) { /* Unconditionally refresh loader.ini contents. */ RefreshConfiguration(); - + OverrideKey title_cfg = GetTitleCheatEnableKey(tid); return HasOverrideKey(&title_cfg); } diff --git a/stratosphere/dmnt/source/dmnt_config.hpp b/stratosphere/dmnt/source/dmnt_config.hpp index e31ae4153..c9a68b6f0 100644 --- a/stratosphere/dmnt/source/dmnt_config.hpp +++ b/stratosphere/dmnt/source/dmnt_config.hpp @@ -13,7 +13,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + #pragma once #include @@ -25,7 +25,7 @@ struct OverrideKey { class DmntConfigManager { public: static void RefreshConfiguration(); - + static OverrideKey GetTitleCheatEnableKey(u64 tid); static bool HasCheatEnableButton(u64 tid); }; diff --git a/stratosphere/dmnt/source/dmnt_hid.cpp b/stratosphere/dmnt/source/dmnt_hid.cpp index 959ffb79e..016052cd2 100644 --- a/stratosphere/dmnt/source/dmnt_hid.cpp +++ b/stratosphere/dmnt/source/dmnt_hid.cpp @@ -13,7 +13,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + #include #include #include @@ -24,13 +24,13 @@ static HosMutex g_hid_keys_down_lock; Result HidManagement::GetKeysDown(u64 *keys) { std::scoped_lock lk(g_hid_keys_down_lock); - + hidScanInput(); *keys = 0; for (int controller = 0; controller < 10; controller++) { *keys |= hidKeysHeld((HidControllerID) controller); } - + return ResultSuccess; } diff --git a/stratosphere/dmnt/source/dmnt_hid.hpp b/stratosphere/dmnt/source/dmnt_hid.hpp index 0c7fac031..e56b95143 100644 --- a/stratosphere/dmnt/source/dmnt_hid.hpp +++ b/stratosphere/dmnt/source/dmnt_hid.hpp @@ -13,7 +13,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + #pragma once #include diff --git a/stratosphere/dmnt/source/dmnt_service.hpp b/stratosphere/dmnt/source/dmnt_service.hpp index c03c8f188..378a37a2a 100644 --- a/stratosphere/dmnt/source/dmnt_service.hpp +++ b/stratosphere/dmnt/source/dmnt_service.hpp @@ -13,7 +13,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + #pragma once #include #include @@ -81,7 +81,7 @@ class DebugMonitorService final : public IServiceObject { Result GetProcessId(Out out_pid, Handle hnd); Result GetProcessHandle(Out out_hnd, u64 pid); Result WaitSynchronization(Handle hnd, u64 ns); - + Result TargetIO_FileOpen(OutBuffer out_hnd, InBuffer path, int open_mode, u32 create_mode); Result TargetIO_FileClose(InBuffer hnd); Result TargetIO_FileRead(InBuffer hnd, OutBuffer out_data, Out out_read, u64 offset); diff --git a/stratosphere/dmnt/source/pm_shim.c b/stratosphere/dmnt/source/pm_shim.c index cee99193c..7c83beca0 100644 --- a/stratosphere/dmnt/source/pm_shim.c +++ b/stratosphere/dmnt/source/pm_shim.c @@ -13,7 +13,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + #include #include "pm_shim.h" @@ -53,7 +53,7 @@ Result pmdmntAtmosphereGetProcessInfo(Handle* out, u64 *tid_out, FsStorageId *si if (R_SUCCEEDED(rc)) { if (out) { - *out = r.Handles[0]; + *out = r.Handles[0]; } else { svcCloseHandle(r.Handles[0]); }