diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 04f3533d..b1f2c7f7 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -12,7 +12,8 @@ "defines": [ "DEBUG", "SWITCH", - "__SWITCH__" + "__SWITCH__", + "VERSION_STRING=\"3.1.0\"" ], "compilerPath": "${DEVKITPRO}/devkitA64/bin/aarch64-none-elf-g++", "cStandard": "c11", diff --git a/include/guis/gui.hpp b/include/guis/gui.hpp index 438ce9d6..e8e3cb97 100644 --- a/include/guis/gui.hpp +++ b/include/guis/gui.hpp @@ -80,7 +80,7 @@ class Gui { void drawTooltip(s16 x, s16 y, const char *text, color_t backgroundColor, color_t textColor, u8 alpha, bool flipped); static bool requestKeyboardInput(std::string headerText, std::string subHeaderText, std::string initialText, SwkbdType type, char *out_text, size_t maxLength); - static u128 requestPlayerSelection(); + static AccountUid requestPlayerSelection(); static void requestErrorMessage(Result result); protected: @@ -92,7 +92,7 @@ class Gui { FT_Library m_fontLibrary; FT_Face m_fontFaces[FONT_FACES_MAX]; FT_Face m_fontLastUsedFace; - size_t m_fontFacesTotal; + s32 m_fontFacesTotal; std::unordered_map> m_stringDimensions; diff --git a/include/guis/gui_main.hpp b/include/guis/gui_main.hpp index 930f3b14..ee3997e0 100644 --- a/include/guis/gui_main.hpp +++ b/include/guis/gui_main.hpp @@ -26,7 +26,7 @@ class GuiMain : public Gui { s8 extraOption; u64 titleId; - u128 userId; + AccountUid userId; } m_selected = { 0, -1, 0, 0 }; static inline bool m_editableOnly = false; diff --git a/include/helpers/account.hpp b/include/helpers/account.hpp index 5cb2ebb0..3f848d18 100644 --- a/include/helpers/account.hpp +++ b/include/helpers/account.hpp @@ -6,18 +6,33 @@ #include #include +namespace std { + template <> + struct hash { + std::size_t operator()(const AccountUid& acc_uid) const { + using std::hash; + return ((hash()(acc_uid.uid[0]) + ^ (hash()(acc_uid.uid[1]) << 1)) >> 1); + } + }; +} + +inline bool operator==(const AccountUid& acc_1, const AccountUid& acc_2) { + return (acc_1.uid[0] == acc_2.uid[0] && acc_1.uid[1] == acc_2.uid[1]); +} + class Account { public: static inline Account *g_currAccount = nullptr; - static inline std::unordered_map g_accounts; + static inline std::unordered_map g_accounts; - static inline u128 g_activeUser = 0; + static inline AccountUid g_activeUser = {0}; - Account(u128 userID); + Account(AccountUid userID); ~Account(); std::string getUserName(); - u128 getUserID(); + AccountUid getUserID(); u8* getProfileImage(); bool isInitialized(); @@ -26,9 +41,9 @@ class Account { AccountUserData m_userData; AccountProfileBase m_profileBase; - u128 m_userID; + AccountUid m_userID; std::vector m_profileImage; - size_t m_profileImageSize; + u32 m_profileImageSize; std::string m_userName; bool m_isInitialized; }; diff --git a/include/helpers/dmntcht.h b/include/helpers/dmntcht.h index b7ef24a6..186782ce 100644 --- a/include/helpers/dmntcht.h +++ b/include/helpers/dmntcht.h @@ -1,76 +1,92 @@ -#pragma once - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - u64 base; - u64 size; -} DmntMemoryRegionExtents; - -typedef struct { - u64 process_id; - u64 title_id; - DmntMemoryRegionExtents main_nso_extents; - DmntMemoryRegionExtents heap_extents; - DmntMemoryRegionExtents alias_extents; - DmntMemoryRegionExtents address_space_extents; - u8 main_nso_build_id[0x20]; -} DmntCheatProcessMetadata; - -typedef struct { - char readable_name[0x40]; - uint32_t num_opcodes; - uint32_t opcodes[0x100]; -} DmntCheatDefinition; - -typedef struct { - bool enabled; - uint32_t cheat_id; - DmntCheatDefinition definition; -} DmntCheatEntry; - -typedef struct { - u64 value; - u8 width; -} DmntFrozenAddressValue; - -typedef struct { - u64 address; - DmntFrozenAddressValue value; -} DmntFrozenAddressEntry; - -Result dmntchtInitialize(void); -void dmntchtExit(void); -Service* dmntchtGetServiceSession(void); - -Result dmntchtHasCheatProcess(bool *out); -Result dmntchtGetCheatProcessEvent(Event *event); -Result dmntchtGetCheatProcessMetadata(DmntCheatProcessMetadata *out_metadata); -Result dmntchtForceOpenCheatProcess(void); - -Result dmntchtGetCheatProcessMappingCount(u64 *out_count); -Result dmntchtGetCheatProcessMappings(MemoryInfo *buffer, u64 max_count, u64 offset, u64 *out_count); -Result dmntchtReadCheatProcessMemory(u64 address, void *buffer, size_t size); -Result dmntchtWriteCheatProcessMemory(u64 address, const void *buffer, size_t size); -Result dmntchtQueryCheatProcessMemory(MemoryInfo *mem_info, u64 address); - -Result dmntchtGetCheatCount(u64 *out_count); -Result dmntchtGetCheats(DmntCheatEntry *buffer, u64 max_count, u64 offset, u64 *out_count); -Result dmntchtGetCheatById(DmntCheatEntry *out_cheat, u32 cheat_id); -Result dmntchtToggleCheat(u32 cheat_id); -Result dmntchtAddCheat(DmntCheatDefinition *cheat, bool enabled, u32 *out_cheat_id); -Result dmntchtRemoveCheat(u32 cheat_id); - -Result dmntchtGetFrozenAddressCount(u64 *out_count); -Result dmntchtGetFrozenAddresses(DmntFrozenAddressEntry *buffer, u64 max_count, u64 offset, u64 *out_count); -Result dmntchtGetFrozenAddress(DmntFrozenAddressEntry *out, u64 address); -Result dmntchtEnableFrozenAddress(u64 address, u64 width, u64 *out_value); -Result dmntchtDisableFrozenAddress(u64 address); - -#ifdef __cplusplus -} -#endif \ No newline at end of file +/* + * 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 . + */ + +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + u64 base; + u64 size; +} DmntMemoryRegionExtents; + +typedef struct { + u64 process_id; + u64 title_id; + DmntMemoryRegionExtents main_nso_extents; + DmntMemoryRegionExtents heap_extents; + DmntMemoryRegionExtents alias_extents; + DmntMemoryRegionExtents address_space_extents; + u8 main_nso_build_id[0x20]; +} DmntCheatProcessMetadata; + +typedef struct { + char readable_name[0x40]; + uint32_t num_opcodes; + uint32_t opcodes[0x100]; +} DmntCheatDefinition; + +typedef struct { + bool enabled; + uint32_t cheat_id; + DmntCheatDefinition definition; +} DmntCheatEntry; + +typedef struct { + u64 value; + u8 width; +} DmntFrozenAddressValue; + +typedef struct { + u64 address; + DmntFrozenAddressValue value; +} DmntFrozenAddressEntry; + +Result dmntchtInitialize(void); +void dmntchtExit(void); +Service* dmntchtGetServiceSession(void); + +Result dmntchtHasCheatProcess(bool *out); +Result dmntchtGetCheatProcessEvent(Event *event); +Result dmntchtGetCheatProcessMetadata(DmntCheatProcessMetadata *out_metadata); +Result dmntchtForceOpenCheatProcess(void); + +Result dmntchtGetCheatProcessMappingCount(u64 *out_count); +Result dmntchtGetCheatProcessMappings(MemoryInfo *buffer, u64 max_count, u64 offset, u64 *out_count); +Result dmntchtReadCheatProcessMemory(u64 address, void *buffer, size_t size); +Result dmntchtWriteCheatProcessMemory(u64 address, const void *buffer, size_t size); +Result dmntchtQueryCheatProcessMemory(MemoryInfo *mem_info, u64 address); + +Result dmntchtGetCheatCount(u64 *out_count); +Result dmntchtGetCheats(DmntCheatEntry *buffer, u64 max_count, u64 offset, u64 *out_count); +Result dmntchtGetCheatById(DmntCheatEntry *out_cheat, u32 cheat_id); +Result dmntchtToggleCheat(u32 cheat_id); +Result dmntchtAddCheat(DmntCheatDefinition *cheat, bool enabled, u32 *out_cheat_id); +Result dmntchtRemoveCheat(u32 cheat_id); + +Result dmntchtGetFrozenAddressCount(u64 *out_count); +Result dmntchtGetFrozenAddresses(DmntFrozenAddressEntry *buffer, u64 max_count, u64 offset, u64 *out_count); +Result dmntchtGetFrozenAddress(DmntFrozenAddressEntry *out, u64 address); +Result dmntchtEnableFrozenAddress(u64 address, u64 width, u64 *out_value); +Result dmntchtDisableFrozenAddress(u64 address); + +#ifdef __cplusplus +} +#endif diff --git a/include/helpers/save.hpp b/include/helpers/save.hpp index d393f87f..24ee6ab9 100644 --- a/include/helpers/save.hpp +++ b/include/helpers/save.hpp @@ -18,14 +18,14 @@ Result _getSaveList(std::vector &saveInfoList); s32 deleteDirRecursively(const char *path, bool isSave); -void makeExInjDir(char ptr[0x100], u64 titleID, u128 userID, bool isInject); -Result mountSaveByTitleAccountIDs(const u64 titleID, const u128 userID, FsFileSystem& tmpfs); +void makeExInjDir(char ptr[0x100], u64 titleID, AccountUid userID, bool isInject); +Result mountSaveByTitleAccountIDs(const u64 titleID, const AccountUid userID, FsFileSystem& tmpfs); s32 isDirectory(const char *path); s32 cpFile(std::string srcPath, std::string dstPath); s32 copyAllSave(const char * path, bool isInject, const char exInjDir[0x100]); -s32 backupSave(u64 titleID, u128 userID, bool isBatch, std::string backupName); -s32 restoreSave(u64 titleID, u128 userID, const char* path); +s32 backupSave(u64 titleID, AccountUid userID, bool isBatch, std::string backupName); +s32 restoreSave(u64 titleID, AccountUid userID, const char* path); -s32 loadSaveFile(std::vector *buffer, size_t *length, u64 titleID, u128 userID, const char *path); -s32 storeSaveFile(u8 *buffer, size_t length, u64 titleID, u128 userID, const char *path); +s32 loadSaveFile(std::vector *buffer, size_t *length, u64 titleID, AccountUid userID, const char *path); +s32 storeSaveFile(u8 *buffer, size_t length, u64 titleID, AccountUid userID, const char *path); diff --git a/include/helpers/service_guard.h b/include/helpers/service_guard.h new file mode 100644 index 00000000..588a0c99 --- /dev/null +++ b/include/helpers/service_guard.h @@ -0,0 +1,64 @@ +#pragma once +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct ServiceGuard { + Mutex mutex; + u32 refCount; +} ServiceGuard; + +NX_INLINE bool serviceGuardBeginInit(ServiceGuard* g) +{ + mutexLock(&g->mutex); + return (g->refCount++) == 0; +} + +NX_INLINE Result serviceGuardEndInit(ServiceGuard* g, Result rc, void (*cleanupFunc)(void)) +{ + if (R_FAILED(rc)) { + cleanupFunc(); + --g->refCount; + } + mutexUnlock(&g->mutex); + return rc; +} + +NX_INLINE void serviceGuardExit(ServiceGuard* g, void (*cleanupFunc)(void)) +{ + mutexLock(&g->mutex); + if (g->refCount && (--g->refCount) == 0) + cleanupFunc(); + mutexUnlock(&g->mutex); +} + +#define NX_GENERATE_SERVICE_GUARD_PARAMS(name, _paramdecl, _parampass) \ +\ +static ServiceGuard g_##name##Guard; \ +NX_INLINE Result _##name##Initialize _paramdecl; \ +static void _##name##Cleanup(void); \ +\ +Result name##Initialize _paramdecl \ +{ \ + Result rc = 0; \ + if (serviceGuardBeginInit(&g_##name##Guard)) \ + rc = _##name##Initialize _parampass; \ + return serviceGuardEndInit(&g_##name##Guard, rc, _##name##Cleanup); \ +} \ +\ +void name##Exit(void) \ +{ \ + serviceGuardExit(&g_##name##Guard, _##name##Cleanup); \ +} + +#define NX_GENERATE_SERVICE_GUARD(name) NX_GENERATE_SERVICE_GUARD_PARAMS(name, (void), ()) + +#ifdef __cplusplus +} +#endif diff --git a/include/helpers/title.hpp b/include/helpers/title.hpp index ef999772..08264544 100644 --- a/include/helpers/title.hpp +++ b/include/helpers/title.hpp @@ -23,8 +23,8 @@ class Title { std::string getTitleAuthor(); std::string getTitleVersion(); u8* getTitleIcon(); - std::vector getUserIDs(); - void addUserID(u128 userID); + std::vector getUserIDs(); + void addUserID(AccountUid userID); u64 getTitleID(); private: @@ -33,6 +33,6 @@ class Title { std::string m_titleName; std::string m_titleAuthor; std::string m_titleVersion; - std::vector m_userIDs; + std::vector m_userIDs; u8 m_errorCode; }; diff --git a/libs/libnx b/libs/libnx index f17773c6..26876cec 160000 --- a/libs/libnx +++ b/libs/libnx @@ -1 +1 @@ -Subproject commit f17773c64f300909b30db49be3d2ec12ebf2674f +Subproject commit 26876cec38b87481265af68351c12348994731e9 diff --git a/source/guis/gui.cpp b/source/guis/gui.cpp index ce0b339f..2acc9599 100644 --- a/source/guis/gui.cpp +++ b/source/guis/gui.cpp @@ -96,7 +96,7 @@ bool Gui::fontInit() { if (R_FAILED(plGetSharedFont(0, fonts, FONT_FACES_MAX, &m_fontFacesTotal))) return false; - for (u32 i = 0; i < m_fontFacesTotal; i++) { + for (s32 i = 0; i < m_fontFacesTotal; i++) { ret = FT_New_Memory_Face(m_fontLibrary, (FT_Byte*)fonts[i].address, fonts[i].size, 0, &m_fontFaces[i]); m_fontFacesRet[i] = ret; @@ -107,7 +107,7 @@ bool Gui::fontInit() { } void Gui::fontExit() { - for (u32 i = 0; i < m_fontFacesTotal; i++) + for (s32 i = 0; i < m_fontFacesTotal; i++) if (m_fontFacesRet[i] == 0) FT_Done_Face(m_fontFaces[i]); if (m_fontLibret == 0) FT_Done_FreeType(m_fontLibrary); @@ -126,7 +126,7 @@ bool Gui::setFontType(u32 font) { default: return false; } - for (u32 i = 0; i < m_fontFacesTotal; i++) { + for (s32 i = 0; i < m_fontFacesTotal; i++) { ret = FT_Set_Char_Size(m_fontFaces[i], 0, scale * 64, 300, 300); if (ret) return false; @@ -144,7 +144,7 @@ inline bool Gui::fontLoadGlyph(glyph_t* glyph, u32 font, u32 codepoint) { if (m_fontFacesTotal == 0) return false; - for (u32 i = 0; i < m_fontFacesTotal; i++) { + for (s32 i = 0; i < m_fontFacesTotal; i++) { face = m_fontFaces[i]; m_fontLastUsedFace = face; glyphIndex = FT_Get_Char_Index(face, codepoint); @@ -620,10 +620,10 @@ bool Gui::requestKeyboardInput(std::string headerText, std::string subHeaderText return std::strcmp(out_text, "") != 0; } -u128 Gui::requestPlayerSelection() { +AccountUid Gui::requestPlayerSelection() { struct UserReturnData{ u64 result; - u128 UID; + AccountUid UID; } PACKED; struct UserReturnData outdata; diff --git a/source/guis/gui_about.cpp b/source/guis/gui_about.cpp index cd1e817a..7bb21a0c 100644 --- a/source/guis/gui_about.cpp +++ b/source/guis/gui_about.cpp @@ -23,7 +23,7 @@ GuiAbout::GuiAbout() : Gui() { if (!threadRunning) { threadRunning = true; - threadCreate(&networkThread, getVersionInfoAsync, nullptr, 0x2000, 0x2C, -2); + threadCreate(&networkThread, getVersionInfoAsync, nullptr, nullptr, 0x2000, 0x2C, -2); threadStart(&networkThread); } } diff --git a/source/guis/gui_cheats.cpp b/source/guis/gui_cheats.cpp index a13ff464..7d733f94 100644 --- a/source/guis/gui_cheats.cpp +++ b/source/guis/gui_cheats.cpp @@ -278,9 +278,9 @@ void GuiCheats::draw() { Gui::drawTextAligned(font14, 290, 130, COLOR_BLACK, pidStr.c_str(), ALIGNED_LEFT); Gui::drawTextAligned(font14, 290, 150, COLOR_BLACK, buildIDStr.c_str(), ALIGNED_LEFT); - if (Account::g_activeUser != 0) { + if ((Account::g_activeUser.uid[0] != 0) && (Account::g_activeUser.uid[1] != 0)) { ss.str(""); - ss << Account::g_accounts[Account::g_activeUser]->getUserName() << " [ " << std::hex << (u64)(Account::g_activeUser >> 64) << " " << (u64)(Account::g_activeUser & 0xFFFFFFFFFFFFFFFFULL) << " ]"; + ss << Account::g_accounts[Account::g_activeUser]->getUserName() << " [ " << std::hex << (Account::g_activeUser.uid[1]) << " " << (Account::g_activeUser.uid[0]) << " ]"; Gui::drawTextAligned(font20, 768, 205, currTheme.textColor, ss.str().c_str(), ALIGNED_CENTER); } @@ -1428,7 +1428,7 @@ static void _moveLonelyCheats(u8 *buildID, u64 titleID) { lonelyCheatPath << EDIZON_DIR "/cheats/" << buildIDStr.str() << ".txt"; if (access(lonelyCheatPath.str().c_str(), F_OK) == 0) { - realCheatPath << "/atmosphere/titles/" << std::uppercase << std::hex << std::setfill('0') << std::setw(sizeof(u64) * 2) << titleID; + realCheatPath << "/atmosphere/contents/" << std::uppercase << std::hex << std::setfill('0') << std::setw(sizeof(u64) * 2) << titleID; mkdir(realCheatPath.str().c_str(), 0777); realCheatPath << "/cheats/"; mkdir(realCheatPath.str().c_str(), 0777); @@ -1444,7 +1444,7 @@ static void _moveLonelyCheats(u8 *buildID, u64 titleID) { static bool _wrongCheatsPresent(u8 *buildID, u64 titleID) { std::stringstream ss; - ss << "/atmosphere/titles/" << std::uppercase << std::hex << std::setfill('0') << std::setw(sizeof(u64) * 2) << titleID << "/cheats/"; + ss << "/atmosphere/contents/" << std::uppercase << std::hex << std::setfill('0') << std::setw(sizeof(u64) * 2) << titleID << "/cheats/"; if (!std::filesystem::exists(ss.str())) return false; diff --git a/source/guis/gui_main.cpp b/source/guis/gui_main.cpp index 3cc2e462..5a79386b 100644 --- a/source/guis/gui_main.cpp +++ b/source/guis/gui_main.cpp @@ -243,10 +243,10 @@ void GuiMain::onInput(u32 kdown) { (new Snackbar("The save files of a running game cannot be accessed."))->show(); return; } - u128 userID = Gui::requestPlayerSelection(); - std::vector users = Title::g_titles[m_selected.titleId]->getUserIDs(); + AccountUid userID = Gui::requestPlayerSelection(); + std::vector users = Title::g_titles[m_selected.titleId]->getUserIDs(); - if(userID == 0x00) + if(userID.uid[0] == 0x00 && userID.uid[1] == 0x00) return; if (std::find(users.begin(), users.end(), userID) != users.end()) { @@ -292,7 +292,7 @@ void GuiMain::onInput(u32 kdown) { u16 failed_titles = 0; for (auto title : Title::g_titles) { - for (u128 userID : Title::g_titles[title.first]->getUserIDs()) { + for (AccountUid userID : Title::g_titles[title.first]->getUserIDs()) { if((res = backupSave(title.first, userID, true, backupName))) { batchFailed = true; failed_titles++; @@ -326,7 +326,7 @@ void GuiMain::onInput(u32 kdown) { if (!Gui::requestKeyboardInput("Backup name", "Please enter a name for the backup to be saved under.", initialText.str(), SwkbdType_QWERTY, backupName, 32)) return; - for (u128 userID : Title::g_titles[m_selected.titleId]->getUserIDs()) { + for (AccountUid userID : Title::g_titles[m_selected.titleId]->getUserIDs()) { if((res = backupSave(m_selected.titleId, userID, true, backupName))) { batchFailed = true; } @@ -400,12 +400,12 @@ void GuiMain::onTouch(touchPosition &touch) { return; } - u128 userID = Gui::requestPlayerSelection(); + AccountUid userID = Gui::requestPlayerSelection(); Title::g_currTitle = Title::g_titles[m_selected.titleId]; - std::vector users = Title::g_titles[m_selected.titleId]->getUserIDs(); + std::vector users = Title::g_titles[m_selected.titleId]->getUserIDs(); - if(userID == 0x00) + if(userID.uid[0] == 0x00 && userID.uid[1] == 0x00) return; if (std::find(users.begin(), users.end(), userID) != users.end()) { diff --git a/source/helpers/account.cpp b/source/helpers/account.cpp index 60c41406..8db41ab4 100644 --- a/source/helpers/account.cpp +++ b/source/helpers/account.cpp @@ -9,7 +9,7 @@ extern "C" { #include "nanojpeg.h" } -Account::Account(u128 userID) : m_userID(userID) { +Account::Account(AccountUid userID) : m_userID(userID) { if (R_FAILED(accountGetProfile(&m_profile, userID))) return; if (!serviceIsActive(&m_profile.s)) return; @@ -17,11 +17,11 @@ Account::Account(u128 userID) : m_userID(userID) { if (R_FAILED(accountProfileGet(&m_profile, &m_userData, &m_profileBase))) return; if (R_FAILED(accountProfileGetImageSize(&m_profile, &m_profileImageSize))) return; - m_userName = std::string(m_profileBase.username); + m_userName = std::string(m_profileBase.nickname); std::vector buffer(m_profileImageSize); u8 *decodedBuffer; - size_t imageSize = 0; + u32 imageSize = 0; if (R_FAILED(accountProfileLoadImage(&m_profile, &buffer[0], m_profileImageSize, &imageSize))) return; @@ -42,7 +42,7 @@ Account::Account(u128 userID) : m_userID(userID) { Account::~Account() { } -u128 Account::getUserID() { +AccountUid Account::getUserID() { return m_userID; } diff --git a/source/helpers/debugger.cpp b/source/helpers/debugger.cpp index 2d59eda8..b5b016d9 100644 --- a/source/helpers/debugger.cpp +++ b/source/helpers/debugger.cpp @@ -9,8 +9,8 @@ Debugger::Debugger() { m_pid = 0; m_tid = 0; - pmdmntGetApplicationPid(&m_pid); - pminfoGetTitleId(&m_tid, m_pid); + pmdmntGetApplicationProcessId(&m_pid); + pminfoGetProgramId(&m_tid, m_pid); } Debugger::~Debugger() { diff --git a/source/helpers/dmntcht.c b/source/helpers/dmntcht.c index 0b03ae58..716a23ab 100644 --- a/source/helpers/dmntcht.c +++ b/source/helpers/dmntcht.c @@ -1,632 +1,168 @@ -#include "helpers/dmntcht.h" - -static Service g_dmntchtService; -static u64 g_refCnt; - -static Result _dmntchtGetCount(u64 cmd_id, u64 *out_count); -static Result _dmntchtGetEntries(u64 cmd_id, void *buffer, u64 buffer_size, u64 offset, u64 *out_count); - -Result dmntchtInitialize(void) { - atomicIncrement64(&g_refCnt); - - if (serviceIsActive(&g_dmntchtService)) { - return 0; - } - - return smGetService(&g_dmntchtService, "dmnt:cht"); -} - -void dmntchtExit(void) { - if (atomicIncrement64(&g_refCnt) == 0) { - serviceClose(&g_dmntchtService); - } -} - -Service* dmntchtGetServiceSession(void) { - return &g_dmntchtService; -} - -Result dmntchtHasCheatProcess(bool *out) { - IpcCommand c; - ipcInitialize(&c); - - struct { - u64 magic; - u64 cmd_id; - } *raw; - - raw = serviceIpcPrepareHeader(&g_dmntchtService, &c, sizeof(*raw)); - - raw->magic = SFCI_MAGIC; - raw->cmd_id = 65000; - - Result rc = serviceIpcDispatch(&g_dmntchtService); - - if (R_SUCCEEDED(rc)) { - IpcParsedCommand r; - struct { - u64 magic; - u64 result; - bool out; - } *resp; - - serviceIpcParse(&g_dmntchtService, &r, sizeof(*resp)); - resp = r.Raw; - - rc = resp->result; - if (R_SUCCEEDED(rc)) { - if (out) *out = resp->out; - } - } - - return rc; -} - -Result dmntchtGetCheatProcessEvent(Event *event) { - IpcCommand c; - ipcInitialize(&c); - - struct { - u64 magic; - u64 cmd_id; - } *raw; - - raw = serviceIpcPrepareHeader(&g_dmntchtService, &c, sizeof(*raw)); - - raw->magic = SFCI_MAGIC; - raw->cmd_id = 65001; - - Result rc = serviceIpcDispatch(&g_dmntchtService); - - if (R_SUCCEEDED(rc)) { - IpcParsedCommand r; - struct { - u64 magic; - u64 result; - } *resp; - - serviceIpcParse(&g_dmntchtService, &r, sizeof(*resp)); - resp = r.Raw; - - rc = resp->result; - - if (R_SUCCEEDED(rc)) { - eventLoadRemote(event, r.Handles[0], true); - } - } - - return rc; -} - -Result dmntchtGetCheatProcessMetadata(DmntCheatProcessMetadata *out_metadata) { - IpcCommand c; - ipcInitialize(&c); - - struct { - u64 magic; - u64 cmd_id; - } *raw; - - raw = serviceIpcPrepareHeader(&g_dmntchtService, &c, sizeof(*raw)); - - raw->magic = SFCI_MAGIC; - raw->cmd_id = 65002; - - Result rc = serviceIpcDispatch(&g_dmntchtService); - - if (R_SUCCEEDED(rc)) { - IpcParsedCommand r; - struct { - u64 magic; - u64 result; - DmntCheatProcessMetadata metadata; - } *resp; - - serviceIpcParse(&g_dmntchtService, &r, sizeof(*resp)); - resp = r.Raw; - - rc = resp->result; - if (R_SUCCEEDED(rc)) { - if (out_metadata) *out_metadata = resp->metadata; - } - } - - return rc; -} - -Result dmntchtForceOpenCheatProcess(void) { - IpcCommand c; - ipcInitialize(&c); - - struct { - u64 magic; - u64 cmd_id; - } *raw; - - raw = serviceIpcPrepareHeader(&g_dmntchtService, &c, sizeof(*raw)); - - raw->magic = SFCI_MAGIC; - raw->cmd_id = 65003; - - Result rc = serviceIpcDispatch(&g_dmntchtService); - - if (R_SUCCEEDED(rc)) { - IpcParsedCommand r; - struct { - u64 magic; - u64 result; - } *resp; - - serviceIpcParse(&g_dmntchtService, &r, sizeof(*resp)); - resp = r.Raw; - - rc = resp->result; - } - - return rc; -} - -static Result _dmntchtGetCount(u64 cmd_id, u64 *out_count) { - IpcCommand c; - ipcInitialize(&c); - - struct { - u64 magic; - u64 cmd_id; - } *raw; - - raw = serviceIpcPrepareHeader(&g_dmntchtService, &c, sizeof(*raw)); - - raw->magic = SFCI_MAGIC; - raw->cmd_id = cmd_id; - - Result rc = serviceIpcDispatch(&g_dmntchtService); - - if (R_SUCCEEDED(rc)) { - IpcParsedCommand r; - struct { - u64 magic; - u64 result; - u64 count; - } *resp; - - serviceIpcParse(&g_dmntchtService, &r, sizeof(*resp)); - resp = r.Raw; - - rc = resp->result; - *out_count = resp->count; - } - - return rc; -} - -static Result _dmntchtGetEntries(u64 cmd_id, void *buffer, u64 buffer_size, u64 offset, u64 *out_count) { - IpcCommand c; - ipcInitialize(&c); - ipcAddRecvBuffer(&c, buffer, buffer_size, 0); - - struct { - u64 magic; - u64 cmd_id; - u64 offset; - } *raw; - - raw = serviceIpcPrepareHeader(&g_dmntchtService, &c, sizeof(*raw)); - - raw->magic = SFCI_MAGIC; - raw->cmd_id = cmd_id; - raw->offset = offset; - - Result rc = serviceIpcDispatch(&g_dmntchtService); - - if (R_SUCCEEDED(rc)) { - IpcParsedCommand r; - struct { - u64 magic; - u64 result; - u64 count; - } *resp; - - serviceIpcParse(&g_dmntchtService, &r, sizeof(*resp)); - resp = r.Raw; - - rc = resp->result; - if (R_SUCCEEDED(rc)) { - if (out_count) *out_count = resp->count; - } - } - - return rc; -} - -Result dmntchtGetCheatProcessMappingCount(u64 *out_count) { - return _dmntchtGetCount(65100, out_count); -} - -Result dmntchtGetCheatProcessMappings(MemoryInfo *buffer, u64 max_count, u64 offset, u64 *out_count) { - return _dmntchtGetEntries(65101, buffer, sizeof(*buffer) * max_count, offset, out_count); -} - -Result dmntchtReadCheatProcessMemory(u64 address, void *buffer, size_t size) { - IpcCommand c; - ipcInitialize(&c); - ipcAddRecvBuffer(&c, buffer, size, 0); - - struct { - u64 magic; - u64 cmd_id; - u64 address; - u64 size; - } *raw; - - raw = serviceIpcPrepareHeader(&g_dmntchtService, &c, sizeof(*raw)); - - raw->magic = SFCI_MAGIC; - raw->cmd_id = 65102; - raw->address = address; - raw->size = size; - - Result rc = serviceIpcDispatch(&g_dmntchtService); - - if (R_SUCCEEDED(rc)) { - IpcParsedCommand r; - struct { - u64 magic; - u64 result; - } *resp; - - serviceIpcParse(&g_dmntchtService, &r, sizeof(*resp)); - resp = r.Raw; - - rc = resp->result; - } - - return rc; -} - -Result dmntchtWriteCheatProcessMemory(u64 address, const void *buffer, size_t size) { - IpcCommand c; - ipcInitialize(&c); - ipcAddSendBuffer(&c, buffer, size, 0); - - struct { - u64 magic; - u64 cmd_id; - u64 address; - u64 size; - } *raw; - - raw = serviceIpcPrepareHeader(&g_dmntchtService, &c, sizeof(*raw)); - - raw->magic = SFCI_MAGIC; - raw->cmd_id = 65103; - raw->address = address; - raw->size = size; - - Result rc = serviceIpcDispatch(&g_dmntchtService); - - if (R_SUCCEEDED(rc)) { - IpcParsedCommand r; - struct { - u64 magic; - u64 result; - } *resp; - - serviceIpcParse(&g_dmntchtService, &r, sizeof(*resp)); - resp = r.Raw; - - rc = resp->result; - } - - return rc; -} - -Result dmntchtQueryCheatProcessMemory(MemoryInfo *mem_info, u64 address){ - IpcCommand c; - ipcInitialize(&c); - - struct { - u64 magic; - u64 cmd_id; - u64 address; - } *raw; - - raw = serviceIpcPrepareHeader(&g_dmntchtService, &c, sizeof(*raw)); - - raw->magic = SFCI_MAGIC; - raw->cmd_id = 65104; - raw->address = address; - - Result rc = serviceIpcDispatch(&g_dmntchtService); - - if (R_SUCCEEDED(rc)) { - IpcParsedCommand r; - struct { - u64 magic; - u64 result; - MemoryInfo mem_info; - } *resp; - - serviceIpcParse(&g_dmntchtService, &r, sizeof(*resp)); - resp = r.Raw; - - rc = resp->result; - if (R_SUCCEEDED(rc)) { - if (mem_info) *mem_info = resp->mem_info; - } - } - - return rc; -} - -Result dmntchtGetCheatCount(u64 *out_count) { - return _dmntchtGetCount(65200, out_count); -} - -Result dmntchtGetCheats(DmntCheatEntry *buffer, u64 max_count, u64 offset, u64 *out_count) { - return _dmntchtGetEntries(65201, buffer, sizeof(*buffer) * max_count, offset, out_count); -} - -Result dmntchtGetCheatById(DmntCheatEntry *buffer, u32 cheat_id) { - IpcCommand c; - ipcInitialize(&c); - ipcAddRecvBuffer(&c, buffer, sizeof(*buffer), 0); - - struct { - u64 magic; - u64 cmd_id; - u32 cheat_id; - } *raw; - - raw = serviceIpcPrepareHeader(&g_dmntchtService, &c, sizeof(*raw)); - - raw->magic = SFCI_MAGIC; - raw->cmd_id = 65202; - raw->cheat_id = cheat_id; - - Result rc = serviceIpcDispatch(&g_dmntchtService); - - if (R_SUCCEEDED(rc)) { - IpcParsedCommand r; - struct { - u64 magic; - u64 result; - } *resp; - - serviceIpcParse(&g_dmntchtService, &r, sizeof(*resp)); - resp = r.Raw; - - rc = resp->result; - } - - return rc; -} - -Result dmntchtToggleCheat(u32 cheat_id) { - IpcCommand c; - ipcInitialize(&c); - - struct { - u64 magic; - u64 cmd_id; - u32 cheat_id; - } *raw; - - raw = serviceIpcPrepareHeader(&g_dmntchtService, &c, sizeof(*raw)); - - raw->magic = SFCI_MAGIC; - raw->cmd_id = 65203; - raw->cheat_id = cheat_id; - - Result rc = serviceIpcDispatch(&g_dmntchtService); - - if (R_SUCCEEDED(rc)) { - IpcParsedCommand r; - struct { - u64 magic; - u64 result; - } *resp; - - serviceIpcParse(&g_dmntchtService, &r, sizeof(*resp)); - resp = r.Raw; - - rc = resp->result; - } - - return rc; -} - -Result dmntchtAddCheat(DmntCheatDefinition *buffer, bool enabled, u32 *out_cheat_id) { - IpcCommand c; - ipcInitialize(&c); - ipcAddSendBuffer(&c, buffer, sizeof(*buffer), 0); - - struct { - u64 magic; - u64 cmd_id; - u8 enabled; - } *raw; - - raw = serviceIpcPrepareHeader(&g_dmntchtService, &c, sizeof(*raw)); - - raw->magic = SFCI_MAGIC; - raw->cmd_id = 65204; - raw->enabled = enabled; - - Result rc = serviceIpcDispatch(&g_dmntchtService); - - if (R_SUCCEEDED(rc)) { - IpcParsedCommand r; - struct { - u64 magic; - u64 result; - u32 cheat_id; - } *resp; - - serviceIpcParse(&g_dmntchtService, &r, sizeof(*resp)); - resp = r.Raw; - - rc = resp->result; - if (R_SUCCEEDED(rc)) { - if (out_cheat_id) *out_cheat_id = resp->cheat_id; - } - } - - return rc; -} - -Result dmntchtRemoveCheat(u32 cheat_id) { - IpcCommand c; - ipcInitialize(&c); - - struct { - u64 magic; - u64 cmd_id; - u32 cheat_id; - } *raw; - - raw = serviceIpcPrepareHeader(&g_dmntchtService, &c, sizeof(*raw)); - - raw->magic = SFCI_MAGIC; - raw->cmd_id = 65205; - raw->cheat_id = cheat_id; - - Result rc = serviceIpcDispatch(&g_dmntchtService); - - if (R_SUCCEEDED(rc)) { - IpcParsedCommand r; - struct { - u64 magic; - u64 result; - } *resp; - - serviceIpcParse(&g_dmntchtService, &r, sizeof(*resp)); - resp = r.Raw; - - rc = resp->result; - } - - return rc; -} - - -Result dmntchtGetFrozenAddressCount(u64 *out_count) { - return _dmntchtGetCount(65300, out_count); -} - -Result dmntchtGetFrozenAddresses(DmntFrozenAddressEntry *buffer, u64 max_count, u64 offset, u64 *out_count) { - return _dmntchtGetEntries(65301, buffer, sizeof(*buffer) * max_count, offset, out_count); -} - -Result dmntchtGetFrozenAddress(DmntFrozenAddressEntry *out, u64 address) { - IpcCommand c; - ipcInitialize(&c); - - struct { - u64 magic; - u64 cmd_id; - u64 address; - } *raw; - - raw = serviceIpcPrepareHeader(&g_dmntchtService, &c, sizeof(*raw)); - - raw->magic = SFCI_MAGIC; - raw->cmd_id = 65302; - raw->address = address; - - Result rc = serviceIpcDispatch(&g_dmntchtService); - - if (R_SUCCEEDED(rc)) { - IpcParsedCommand r; - struct { - u64 magic; - u64 result; - DmntFrozenAddressEntry entry; - } *resp; - - serviceIpcParse(&g_dmntchtService, &r, sizeof(*resp)); - resp = r.Raw; - - rc = resp->result; - if (R_SUCCEEDED(rc)) { - if (out) *out = resp->entry; - } - } - - return rc; -} - -Result dmntchtEnableFrozenAddress(u64 address, u64 width, u64 *out_value) { - IpcCommand c; - ipcInitialize(&c); - - struct { - u64 magic; - u64 cmd_id; - u64 address; - u64 width; - } *raw; - - raw = serviceIpcPrepareHeader(&g_dmntchtService, &c, sizeof(*raw)); - - raw->magic = SFCI_MAGIC; - raw->cmd_id = 65303; - raw->address = address; - raw->width = width; - - Result rc = serviceIpcDispatch(&g_dmntchtService); - - if (R_SUCCEEDED(rc)) { - IpcParsedCommand r; - struct { - u64 magic; - u64 result; - u64 value; - } *resp; - - serviceIpcParse(&g_dmntchtService, &r, sizeof(*resp)); - resp = r.Raw; - - rc = resp->result; - if (R_SUCCEEDED(rc)) { - if (out_value) *out_value = resp->value; - } - } - - return rc; -} - -Result dmntchtDisableFrozenAddress(u64 address) { - IpcCommand c; - ipcInitialize(&c); - - struct { - u64 magic; - u64 cmd_id; - u64 address; - } *raw; - - raw = serviceIpcPrepareHeader(&g_dmntchtService, &c, sizeof(*raw)); - - raw->magic = SFCI_MAGIC; - raw->cmd_id = 65304; - raw->address = address; - - Result rc = serviceIpcDispatch(&g_dmntchtService); - - if (R_SUCCEEDED(rc)) { - IpcParsedCommand r; - struct { - u64 magic; - u64 result; - u64 value; - } *resp; - - serviceIpcParse(&g_dmntchtService, &r, sizeof(*resp)); - resp = r.Raw; - - rc = resp->result; - } - - return rc; -} \ No newline at end of file +/* + * 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 . + */ +#define NX_SERVICE_ASSUME_NON_DOMAIN + +#include "helpers/service_guard.h" +#include "helpers/dmntcht.h" + +static Service g_dmntchtSrv; + +NX_GENERATE_SERVICE_GUARD(dmntcht); + +Result _dmntchtInitialize(void) { + return smGetService(&g_dmntchtSrv, "dmnt:cht"); +} + +void _dmntchtCleanup(void) { + serviceClose(&g_dmntchtSrv); +} + +Service* dmntchtGetServiceSession(void) { + return &g_dmntchtSrv; +} + +Result dmntchtHasCheatProcess(bool *out) { + u8 tmp; + Result rc = serviceDispatchOut(&g_dmntchtSrv, 65000, tmp); + if (R_SUCCEEDED(rc) && out) *out = tmp & 1; + return rc; +} + +Result dmntchtGetCheatProcessEvent(Event *event) { + Handle evt_handle; + Result rc = serviceDispatch(&g_dmntchtSrv, 65001, + .out_handle_attrs = { SfOutHandleAttr_HipcCopy }, + .out_handles = &evt_handle, + ); + + if (R_SUCCEEDED(rc)) { + eventLoadRemote(event, evt_handle, true); + } + + return rc; +} + +Result dmntchtGetCheatProcessMetadata(DmntCheatProcessMetadata *out_metadata) { + return serviceDispatchOut(&g_dmntchtSrv, 65002, *out_metadata); +} + +Result dmntchtForceOpenCheatProcess(void) { + return serviceDispatch(&g_dmntchtSrv, 65003); +} + +static Result _dmntchtGetCount(u64 *out_count, u32 cmd_id) { + return serviceDispatchOut(&g_dmntchtSrv, cmd_id, *out_count); +} + +static Result _dmntchtGetEntries(void *buffer, u64 buffer_size, u64 offset, u64 *out_count, u32 cmd_id) { + return serviceDispatchInOut(&g_dmntchtSrv, cmd_id, offset, *out_count, + .buffer_attrs = { SfBufferAttr_Out | SfBufferAttr_HipcMapAlias }, + .buffers = { { buffer, buffer_size } }, + ); +} + +static Result _dmntchtCmdInU32NoOut(u32 in, u32 cmd_id) { + return serviceDispatchIn(&g_dmntchtSrv, cmd_id, in); +} + +Result dmntchtGetCheatProcessMappingCount(u64 *out_count) { + return _dmntchtGetCount(out_count, 65100); +} + +Result dmntchtGetCheatProcessMappings(MemoryInfo *buffer, u64 max_count, u64 offset, u64 *out_count) { + return _dmntchtGetEntries(buffer, sizeof(*buffer) * max_count, offset, out_count, 65101); +} + +Result dmntchtReadCheatProcessMemory(u64 address, void *buffer, size_t size) { + const struct { + u64 address; + u64 size; + } in = { address, size }; + return serviceDispatchIn(&g_dmntchtSrv, 65102, in, + .buffer_attrs = { SfBufferAttr_Out | SfBufferAttr_HipcMapAlias }, + .buffers = { { buffer, size } }, + ); +} + +Result dmntchtWriteCheatProcessMemory(u64 address, const void *buffer, size_t size) { + const struct { + u64 address; + u64 size; + } in = { address, size }; + return serviceDispatchIn(&g_dmntchtSrv, 65103, in, + .buffer_attrs = { SfBufferAttr_In | SfBufferAttr_HipcMapAlias }, + .buffers = { { buffer, size } }, + ); +} + +Result dmntchtQueryCheatProcessMemory(MemoryInfo *mem_info, u64 address){ + return serviceDispatchInOut(&g_dmntchtSrv, 65104, address, *mem_info); +} + +Result dmntchtGetCheatCount(u64 *out_count) { + return _dmntchtGetCount(out_count, 65200); +} + +Result dmntchtGetCheats(DmntCheatEntry *buffer, u64 max_count, u64 offset, u64 *out_count) { + return _dmntchtGetEntries(buffer, sizeof(*buffer) * max_count, offset, out_count, 65201); +} + +Result dmntchtGetCheatById(DmntCheatEntry *out, u32 cheat_id) { + return serviceDispatchIn(&g_dmntchtSrv, 65202, cheat_id, + .buffer_attrs = { SfBufferAttr_Out | SfBufferAttr_HipcMapAlias | SfBufferAttr_FixedSize }, + .buffers = { { out, sizeof(*out) } }, + ); +} + +Result dmntchtToggleCheat(u32 cheat_id) { + return _dmntchtCmdInU32NoOut(cheat_id, 65203); +} + +Result dmntchtAddCheat(DmntCheatDefinition *cheat_def, bool enabled, u32 *out_cheat_id) { + const u8 in = enabled != 0; + return serviceDispatchInOut(&g_dmntchtSrv, 65204, in, *out_cheat_id, + .buffer_attrs = { SfBufferAttr_In | SfBufferAttr_HipcMapAlias | SfBufferAttr_FixedSize }, + .buffers = { { cheat_def, sizeof(*cheat_def) } }, + ); +} + +Result dmntchtRemoveCheat(u32 cheat_id) { + return _dmntchtCmdInU32NoOut(cheat_id, 65205); +} + +Result dmntchtGetFrozenAddressCount(u64 *out_count) { + return _dmntchtGetCount(out_count, 65300); +} + +Result dmntchtGetFrozenAddresses(DmntFrozenAddressEntry *buffer, u64 max_count, u64 offset, u64 *out_count) { + return _dmntchtGetEntries(buffer, sizeof(*buffer) * max_count, offset, out_count, 65301); +} + +Result dmntchtGetFrozenAddress(DmntFrozenAddressEntry *out, u64 address) { + return serviceDispatchInOut(&g_dmntchtSrv, 65302, address, *out); +} + +Result dmntchtEnableFrozenAddress(u64 address, u64 width, u64 *out_value) { + const struct { + u64 address; + u64 width; + } in = { address, width }; + return serviceDispatchInOut(&g_dmntchtSrv, 65303, in, *out_value); +} + +Result dmntchtDisableFrozenAddress(u64 address) { + return serviceDispatchIn(&g_dmntchtSrv, 65304, address); +} diff --git a/source/helpers/save.cpp b/source/helpers/save.cpp index 385dd622..f4a2da59 100644 --- a/source/helpers/save.cpp +++ b/source/helpers/save.cpp @@ -71,7 +71,7 @@ bool doesFolderExist(const char *path) { return stat(path, &sb) == 0 && S_ISDIR(sb.st_mode); } -bool makeExInjDir(char ptr[0x100], u64 titleID, u128 userID, bool isInject, const char* injectFolder, bool fromBatch, std::string backupName) { +bool makeExInjDir(char ptr[0x100], u64 titleID, AccountUid userID, bool isInject, const char* injectFolder, bool fromBatch, std::string backupName) { std::stringstream ss; std::string folder_path(EDIZON_DIR); @@ -105,8 +105,8 @@ bool makeExInjDir(char ptr[0x100], u64 titleID, u128 userID, bool isInject, cons mkdir(ss.str().c_str(), 0700); - u64 userIDH = userID >> 64; - u64 userIDL = userID & 0xFFFFFFFFFFFFFFFFULL; + u64 userIDH = userID.uid[1]; + u64 userIDL = userID.uid[0]; ss << std::setfill('0') << std::uppercase << std::hex << userIDH << std::setfill('0') << std::uppercase << std::hex << userIDL << "/"; mkdir(ss.str().c_str(), 0700); @@ -121,8 +121,8 @@ bool makeExInjDir(char ptr[0x100], u64 titleID, u128 userID, bool isInject, cons metadata.clear(); - u64 userIDH = userID >> 64; - u64 userIDL = userID & 0xFFFFFFFFFFFFFFFFULL; + u64 userIDH = userID.uid[1]; + u64 userIDL = userID.uid[0]; metadata_user_id << std::setfill('0') << std::uppercase << std::hex << userIDH; metadata_user_id << std::setfill('0') << std::uppercase << std::hex << userIDL; metadata["user_id"] = metadata_user_id.str(); @@ -146,38 +146,38 @@ bool makeExInjDir(char ptr[0x100], u64 titleID, u128 userID, bool isInject, cons Result _getSaveList(std::vector & saveInfoList) { Result rc=0; - FsSaveDataIterator iterator; - size_t total_entries=0; + FsSaveDataInfoReader iterator; + s64 total_entries=0; FsSaveDataInfo info; - rc = fsOpenSaveDataIterator(&iterator, FsSaveDataSpaceId_NandUser);//See libnx fs.h. + rc = fsOpenSaveDataInfoReader(&iterator, FsSaveDataSpaceId_User);//See libnx fs.h. if (R_FAILED(rc)) { printf("fsOpenSaveDataIterator() failed: 0x%x\n", rc); return rc; } - rc = fsSaveDataIteratorRead(&iterator, &info, 1, &total_entries);//See libnx fs.h. + rc = fsSaveDataInfoReaderRead(&iterator, &info, 1, &total_entries);//See libnx fs.h. if (R_FAILED(rc)) return rc; if (total_entries == 0) return MAKERESULT(Module_Libnx, LibnxError_NotFound); for (; R_SUCCEEDED(rc) && total_entries > 0; - rc = fsSaveDataIteratorRead(&iterator, &info, 1, &total_entries)) { - if (info.saveDataType == FsSaveDataType_SaveData) { + rc = fsSaveDataInfoReaderRead(&iterator, &info, 1, &total_entries)) { + if (info.save_data_type == FsSaveDataType_Account) { saveInfoList.push_back(info); } } - fsSaveDataIteratorClose(&iterator); + fsSaveDataInfoReaderClose(&iterator); return 0; } -Result mountSaveByTitleAccountIDs(const u64 titleID, const u128 userID, FsFileSystem& tmpfs) { +Result mountSaveByTitleAccountIDs(const u64 titleID, const AccountUid userID, FsFileSystem& tmpfs) { Result rc = 0; - rc = fsMount_SaveData(&tmpfs, titleID, userID);//See also libnx fs.h. + rc = fsOpen_SaveData(&tmpfs, titleID, userID);//See also libnx fs.h. if (R_FAILED(rc)) { printf("fsMount_SaveData() failed: 0x%x\n", rc); fsdevUnmountDevice(SAVE_DEV); @@ -301,7 +301,7 @@ s32 copyAllSave(const char * path, bool isInject, const char exInjDir[0x100]) { } } -s32 backupSave(u64 titleID, u128 userID, bool fromBatch, std::string backupName) { +s32 backupSave(u64 titleID, AccountUid userID, bool fromBatch, std::string backupName) { FsFileSystem fs; s32 res = 0; @@ -333,7 +333,7 @@ s32 backupSave(u64 titleID, u128 userID, bool fromBatch, std::string backupName) return res; } -s32 restoreSave(u64 titleID, u128 userID, const char* path) { +s32 restoreSave(u64 titleID, AccountUid userID, const char* path) { FsFileSystem fs; s32 res = 0; @@ -362,7 +362,7 @@ s32 restoreSave(u64 titleID, u128 userID, const char* path) { return res; } -s32 loadSaveFile(std::vector *buffer, size_t *length, u64 titleID, u128 userID, const char *path) { +s32 loadSaveFile(std::vector *buffer, size_t *length, u64 titleID, AccountUid userID, const char *path) { FsFileSystem fs; size_t size; @@ -411,7 +411,7 @@ s32 loadSaveFile(std::vector *buffer, size_t *length, u64 titleID, u128 user return 0; } -s32 storeSaveFile(u8 *buffer, size_t length, u64 titleID, u128 userID, const char *path) { +s32 storeSaveFile(u8 *buffer, size_t length, u64 titleID, AccountUid userID, const char *path) { FsFileSystem fs; if (R_FAILED(mountSaveByTitleAccountIDs(titleID, userID, fs))) { diff --git a/source/helpers/title.cpp b/source/helpers/title.cpp index 31191bba..ffbc3332 100644 --- a/source/helpers/title.cpp +++ b/source/helpers/title.cpp @@ -18,7 +18,7 @@ Title::Title(FsSaveDataInfo& saveInfo) { } memset(buf.get(), 0, sizeof(NsApplicationControlData)); - rc = nsGetApplicationControlData(NsApplicationControlSource_Storage, saveInfo.titleID, buf.get(), sizeof(NsApplicationControlData), &outsize); + rc = nsGetApplicationControlData(NsApplicationControlSource_Storage, saveInfo.application_id, buf.get(), sizeof(NsApplicationControlData), &outsize); if (R_FAILED(rc)) { m_errorCode = 2; return; @@ -37,9 +37,9 @@ Title::Title(FsSaveDataInfo& saveInfo) { m_titleName = std::string(langentry->name); m_titleAuthor = std::string(langentry->author); - m_titleVersion = std::string(buf->nacp.version); + m_titleVersion = std::string(buf->nacp.display_version); - m_titleID = saveInfo.titleID; + m_titleID = saveInfo.application_id; njInit(); @@ -96,10 +96,10 @@ u64 Title::getTitleID() { return m_titleID; } -std::vector Title::getUserIDs() { +std::vector Title::getUserIDs() { return m_userIDs; } -void Title::addUserID(u128 userID) { +void Title::addUserID(AccountUid userID) { m_userIDs.push_back(userID); } diff --git a/source/helpers/util.c b/source/helpers/util.c index 7e532373..c5dee301 100644 --- a/source/helpers/util.c +++ b/source/helpers/util.c @@ -30,12 +30,13 @@ void amspmdmntExit(void) { bool isServiceRunning(const char *serviceName) { Handle handle; - bool running = R_FAILED(smRegisterService(&handle, serviceName, false, 1)); + SmServiceName service_name = smEncodeName(serviceName); + bool running = R_FAILED(smRegisterService(&handle, service_name, false, 1)); svcCloseHandle(handle); if (!running) - smUnregisterService(serviceName); + smUnregisterService(service_name); return running; } diff --git a/source/main.cpp b/source/main.cpp index cc44011e..e0c81bc0 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -45,35 +45,35 @@ void initTitles() { _getSaveList(saveInfoList); s32 userCount = 0; - size_t foundUserCount = 0; + s32 foundUserCount = 0; accountGetUserCount(&userCount); - u128 userIDs[userCount]; + AccountUid userIDs[userCount]; accountListAllUsers(userIDs, userCount, &foundUserCount); for (auto saveInfo : saveInfoList) { bool accountPresent = false; - for (u32 i = 0; i < foundUserCount; i++) - if (userIDs[i] == saveInfo.userID) + for (s32 i = 0; i < foundUserCount; i++) + if (userIDs[i] == saveInfo.uid) accountPresent = true; if (!accountPresent) continue; - if (Title::g_titles.find(saveInfo.titleID) == Title::g_titles.end()) - Title::g_titles.insert({(u64)saveInfo.titleID, new Title(saveInfo)}); + if (Title::g_titles.find(saveInfo.application_id) == Title::g_titles.end()) + Title::g_titles.insert({(u64)saveInfo.application_id, new Title(saveInfo)}); - Title::g_titles[saveInfo.titleID]->addUserID(saveInfo.userID); + Title::g_titles[saveInfo.application_id]->addUserID(saveInfo.uid); - if (Account::g_accounts.find(saveInfo.userID) == Account::g_accounts.end()) { - Account *account = new Account(saveInfo.userID); + if (Account::g_accounts.find(saveInfo.uid) == Account::g_accounts.end()) { + Account *account = new Account(saveInfo.uid); if (!account->isInitialized()) { delete account; continue; } - Account::g_accounts.insert(std::make_pair(static_cast(saveInfo.userID), account)); + Account::g_accounts.insert(std::make_pair(static_cast(saveInfo.uid), account)); } } } @@ -116,7 +116,7 @@ void serviceInitialize() { setsysInitialize(); socketInitializeDefault(); nsInitialize(); - accountInitialize(); + accountInitialize(AccountServiceType_Administrator); plInitialize(); psmInitialize(); pminfoInitialize(); @@ -130,17 +130,12 @@ void serviceInitialize() { curl_global_init(CURL_GLOBAL_ALL); u64 pid = 0; - u128 activeUser; - bool accountSelected; Title::g_activeTitle = 0; - pmdmntGetApplicationPid(&pid); - pminfoGetTitleId(&Title::g_activeTitle, pid); + pmdmntGetApplicationProcessId(&pid); + pminfoGetProgramId(&Title::g_activeTitle, pid); - accountGetLastOpenedUser(&activeUser, &accountSelected); - - if (accountSelected) - Account::g_activeUser = activeUser; + accountGetLastOpenedUser(&Account::g_activeUser); } void serviceExit() { @@ -183,7 +178,7 @@ int main(int argc, char** argv) { // Setup Heap for swkbd on applets Result rc = svcSetHeapSize(&haddr, 0x10000000); if (R_FAILED(rc)) - fatalSimple(0xDEAD); + fatalThrow(0xDEAD); fake_heap_end = (char*) haddr + 0x10000000; serviceInitialize();