Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 44 additions & 29 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
const char * EXPORT_DIR = "save/";
const char * INJECT_DIR = "inject/";
const char * SAVE_DEV = "save";
const char * DELETE = "Delete";
const char * INJECT = "Inject";

Result getSaveList(std::vector<FsSaveDataInfo> & saveInfoList) {
Result rc=0;
Expand All @@ -29,7 +31,7 @@ Result getSaveList(std::vector<FsSaveDataInfo> & saveInfoList) {
if (total_entries==0)
return MAKERESULT(Module_Libnx, LibnxError_NotFound);

for(; R_SUCCEEDED(rc) && total_entries > 0;
for(; R_SUCCEEDED(rc) && total_entries > 0;
rc = fsSaveDataIteratorRead(&iterator, &info, 1, &total_entries)) {
if (info.SaveDataType == FsSaveDataType_SaveData) {
saveInfoList.push_back(info);
Expand All @@ -47,7 +49,7 @@ Result mountSaveBySaveDataInfo(const FsSaveDataInfo & info, const char * dev) {

u64 titleID = info.titleID;
u128 userID = info.userID;

FsFileSystem tmpfs;

printf("\n\nUsing titleID=0x%016lx userID: 0x%lx 0x%lx\n", titleID, (u64)(userID>>64), (u64)userID);
Expand Down Expand Up @@ -75,27 +77,29 @@ int isDirectory(const char *path) {
return S_ISDIR(statbuf.st_mode);
}

int cpFile(const char * filenameI, const char * filenameO) {
int cpFile(const char * filenameI, const char * filenameO, bool isDelete) {
remove( filenameO );

std::ifstream src(filenameI, std::ios::binary);
std::ofstream dst(filenameO, std::ios::binary);

dst << src.rdbuf();

if(!isDelete) {
std::ifstream src(filenameI, std::ios::binary);
std::ofstream dst(filenameO, std::ios::binary);
dst << src.rdbuf();
}
return 0;
}


int copyAllSave(const char * dev, const char * path, bool isInject,
const char * exportDir) {
int copyAllSave(const char * dev, const char * path, const char * action, const char * exportDir) {
DIR* dir;
struct dirent* ent;
char dirPath[0x100];
if(isInject) {
bool isDelete = false;
if(action == DELETE){
isDelete=true;
}
if(action == INJECT) {
strcpy(dirPath, INJECT_DIR);
strcat(dirPath, path);
} else {
} else {
strcpy(dirPath, dev);
strcat(dirPath, path);
}
Expand All @@ -119,7 +123,7 @@ int copyAllSave(const char * dev, const char * path, bool isInject,

char filenameI[0x100];
char filenameO[0x100];
if(isInject) {
if(action!=NULL) {
strcpy(filenameI, INJECT_DIR);
strcat(filenameI, filename);

Expand All @@ -139,13 +143,13 @@ int copyAllSave(const char * dev, const char * path, bool isInject,

if(isDirectory(filenameI)) {
mkdir(filenameO, 0700);
int res = copyAllSave(dev, filename, isInject, exportDir);
int res = copyAllSave(dev, filename, action, exportDir);
if(res != 0)
return res;
} else {
printf("Copying %s... ", filenameI);
cpFile(filenameI, filenameO);
if(isInject) {
printf("Processing %s... ", filenameI);
cpFile(filenameI, filenameO, isDelete);
if(action!=NULL) {
if (R_SUCCEEDED(fsdevCommitDevice(SAVE_DEV))) { // Thx yellows8
printf("committed.\n");
} else {
Expand All @@ -164,11 +168,11 @@ int copyAllSave(const char * dev, const char * path, bool isInject,
}

int dumpAll() {
return copyAllSave("save:/", ".", false, NULL);
return copyAllSave("save:/", ".", NULL, NULL);
}

int dumpAllTo(char * dir) {
return copyAllSave("save:/", ".", false, dir);
return copyAllSave("save:/", ".", NULL, dir);
}

void dumpToTitleUserDir(FsSaveDataInfo info) {
Expand All @@ -182,7 +186,11 @@ void dumpToTitleUserDir(FsSaveDataInfo info) {
}

int inject() {
return copyAllSave("save:/", ".", true, NULL);
return copyAllSave("save:/", ".", INJECT, NULL);
}

int del() {
return copyAllSave("save:/", ".", DELETE, NULL);
}

Result getTitleName(u64 titleID, char * name) {
Expand Down Expand Up @@ -258,7 +266,6 @@ Result getUserNameById(u128 userID, char * username) {
if (R_FAILED(rc)) {
printf("accountGetProfile() failed: 0x%x\n", rc);
}


if (R_SUCCEEDED(rc)) {
rc = accountProfileGet(&profile, &userdata, &profilebase);//userdata is otional, see libnx acc.h.
Expand Down Expand Up @@ -286,8 +293,7 @@ int selectSaveFromList(int & selection, int change,
if (selection < 0) {
selection = abs(selection) % saveInfoList.size();
selection = saveInfoList.size() - selection;
} else if (selection > 0
&& static_cast<unsigned int>(selection) >= saveInfoList.size()) {
} else if (selection > 0 && static_cast<unsigned int>(selection) >= saveInfoList.size()) {
selection %= saveInfoList.size();
}

Expand All @@ -313,7 +319,7 @@ int selectSaveFromList(int & selection, int change,
bool userConfirm(const char * msg) {
printf("\n%s\nPress A to confirm, any other button to cancel\n", msg);

u64 kDownPrevious = hidKeysDown(CONTROLLER_P1_AUTO);
u64 kDownPrevious = hidKeysDown(CONTROLLER_P1_AUTO);
while(appletMainLoop())
{
hidScanInput();
Expand Down Expand Up @@ -344,13 +350,13 @@ int main(int argc, char **argv)
std::vector<FsSaveDataInfo> saveInfoList;

mkdir(EXPORT_DIR, 0700);
mkdir(INJECT_DIR, 0700);
mkdir(INJECT_DIR, 0700);

if (R_FAILED(getSaveList(saveInfoList))) {
printf("Failed to get save list 0x%x\n", rc);
}

printf("Y'allAreNUTs v0.1.1\n"
printf("Y'allAreNUTs v0.2 by 3096 and geek85\n"
"Press UP and DOWN to select a save\n"
"Press LEFT and RIGHT to skip 5 saves\n"
"Press A to dump save to 'save/'\n"
Expand Down Expand Up @@ -393,7 +399,7 @@ int main(int argc, char **argv)
printName = !printName;
selectSaveFromList(selection, 0, saveInfoList, info, printName);
}

if (kDown & KEY_A) {
mountSaveBySaveDataInfo(info, SAVE_DEV);
dumpAll();
Expand All @@ -420,12 +426,21 @@ int main(int argc, char **argv)
}
}

if (kDown & KEY_ZL) {
if (userConfirm("Erase saves? Sure?")) {
mountSaveBySaveDataInfo(info, SAVE_DEV);
if( del() == 0 ) {
printf("Delete over.\n\n");
}
fsdevUnmountDevice(SAVE_DEV);
}
}

if (kDown & KEY_X) {
if (userConfirm("Inject data from 'inject/'?")) {
mountSaveBySaveDataInfo(info, SAVE_DEV);
if( inject() == 0 ) {
printf("Inject over.\n\n");

}
fsdevUnmountDevice(SAVE_DEV);
}
Expand Down