Skip to content

Commit

Permalink
Initial work on splitting up for save detection
Browse files Browse the repository at this point in the history
  • Loading branch information
noirscape committed Apr 11, 2018
1 parent 028782d commit 34ac5bb
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 17 deletions.
12 changes: 1 addition & 11 deletions source/editprofile.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,14 @@

Result edit_profile(int profile_num, bool fusion_mode, u32 lowid, InstallType install_type)
{
FS_MediaType media_type = (install_type == SD_CARD) ? MEDIATYPE_SD : MEDIATYPE_GAME_CARD;
// Open save archive
const u32 path[3] = { media_type, lowid, 0x00040000 };

FS_Archive save_archive;
FS_ArchiveID archive_id = (install_type == SD_CARD) ? ARCHIVE_USER_SAVEDATA : ARCHIVE_GAMECARD_SAVEDATA;

Result res;
res = FSUSER_OpenArchive(&save_archive, archive_id, (FS_Path){PATH_BINARY, 12, path});
if(R_FAILED(res)) return res;

char profile_path[0x107] = {0};
sprintf(profile_path, "/profile%i/pkprfl.bmssv", profile_num);
printf("%s\n", profile_path);

// Open file
Handle file_handle;

Result res;
res = FSUSER_OpenFile(&file_handle, save_archive, fsMakePath(PATH_ASCII, profile_path), FS_OPEN_WRITE | FS_OPEN_READ, 0);
if(R_FAILED(res))
{
Expand Down
42 changes: 36 additions & 6 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "title.h"
#include "const.h"
#include "struct.h"
#include "save.h"
#include "main.h"

int main()
{
Expand All @@ -22,6 +24,9 @@ int main()
bool save_unseen = true;
bool fusion_unseen = true;
bool region_autochecked = false;
FS_Archive save_archive;
Result res;
SavesList saves_list;
InstallType install_type;
u32 lowid;

Expand Down Expand Up @@ -96,22 +101,42 @@ int main()
case SELECT_SAVE: // Save file selection
if (save_unseen)
{
printf("\n---------------------\nSelect a save file to modify.\nY for save 1, B for save 2, X for save 3.\nPress START to exit.\n");
res = open_archive(lowid, install_type, &save_archive);
if(R_FAILED(res))
{
fail_print(&res);
state = SUCCESS;
}

saves_list = save_check(&save_archive);
if (saves_list.profile0)
{
printf("Press Y to select save 1.\n");
}
if (saves_list.profile1)
{
printf("Press B to select save 2.\n");
}
if (saves_list.profile2)
{
printf("Press X to select save 3.\n");
}
// printf("\n---------------------\nSelect a save file to modify.\nY for save 1, B for save 2, X for save 3.\nPress START to exit.\n");
save_unseen = false;
}
if (kDown & KEY_Y) // Save 1 was chosen
if (kDown & KEY_Y && saves_list.profile0) // Save 1 was chosen
{
profile_num = 0;
printf("You selected the 1st save file.\n");
state = FUSION_OR_NOT;
}
if (kDown & KEY_B) // Save 2 was chosen
if (kDown & KEY_B && saves_list.profile1) // Save 2 was chosen
{
profile_num = 1;
printf("You selected the 2nd save file.\n");
state = FUSION_OR_NOT;
}
if (kDown & KEY_X) // Save 3 was chosen
if (kDown & KEY_X && saves_list.profile2) // Save 3 was chosen
{
profile_num = 2;
printf("You selected the 3rd save file.\n");
Expand Down Expand Up @@ -143,8 +168,7 @@ int main()
Result res = edit_profile(profile_num, fusion_mode, lowid, install_type);
if(R_FAILED(res))
{
printf("\x1b[s\x1b[30;16H%4lx\n\x1b[u", res);
printf("Something went wrong, please see the error message below.\n");
fail_print(&res);
}
else
{
Expand All @@ -166,4 +190,10 @@ int main()
cfguExit();
gfxExit();
return 0;
}

void fail_print(Result* res)
{
printf("\x1b[s\x1b[30;16H%4lx\n\x1b[u", *res);
printf("Something went wrong, please see the error message below.\n");
}
10 changes: 10 additions & 0 deletions source/main.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <stdio.h>
#include <3ds.h>
#include "editprofile.h"
#include "title.h"
#include "const.h"
#include "struct.h"
#include "save.h"

int main();
void fail_print(Result* res);
74 changes: 74 additions & 0 deletions source/save.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include <3ds.h>
#include <stdlib.h>
#include <stdio.h>
#include "struct.h"
#include "save.h"

Result open_archive(u32 lowid, InstallType install_type, FS_Archive* save_archive)
{
FS_MediaType media_type = (install_type == SD_CARD) ? MEDIATYPE_SD : MEDIATYPE_GAME_CARD;
const u32 path[3] = { media_type, lowid, 0x00040000 };

FS_ArchiveID archive_id = (install_type == SD_CARD) ? ARCHIVE_USER_SAVEDATA : ARCHIVE_GAMECARD_SAVEDATA;

Result res;
res = FSUSER_OpenArchive(save_archive, archive_id, (FS_Path){PATH_BINARY, 12, path});
if(R_FAILED(res)) return res;

return 0;
}

SavesList save_check(FS_Archive* save_archive)
{
Result res;
SavesList saves_list = {false, false, false};

for (int i = 0; i < 3; ++i)
{
bool exist = file_check(i, save_archive);
if (exist)
{
saves_list.total_saves++;
}
switch(i)
{
case 0:
saves_list.profile0 = exist;
break;

case 1:
saves_list.profile1 = exist;
break;

case 2:
saves_list.profile2 = exist;
break;
}
}

return saves_list;
}

bool file_check(int i, FS_Archive* save_archive)
{
char profile_path[0x107] = {0};
sprintf(profile_path, "/profile%i/pkprfl.bmssv", i);
printf("%s\n", profile_path);

// Open file
Handle file_handle;

Result res;
res = FSUSER_OpenFile(&file_handle, *save_archive, fsMakePath(PATH_ASCII, profile_path), FS_OPEN_WRITE | FS_OPEN_READ, 0);
if(R_FAILED(res))
{
return false;
}
FSFILE_Close(file_handle);
return true;
}

Result open_file()
{

}
13 changes: 13 additions & 0 deletions source/save.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef _SAVEH_
#define _SAVEH_

#include <3ds.h>
#include <stdlib.h>
#include <stdio.h>
#include "struct.h"

Result open_archive(u32 lowid, InstallType install_type, FS_Archive* save_archive);
SavesList save_check(FS_Archive* save_archive);
bool file_check(int i, FS_Archive* save_archive);

#endif
8 changes: 8 additions & 0 deletions source/struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@ typedef struct {
int total_regions;
} Regions;

typedef struct {
bool profile0;
bool profile1;
bool profile2;
int total_saves;
} SavesList;

typedef enum {
MAIN_SCREEN,
VERSION_TO_EDIT,
SELECT_SAVE,
READ_SAVE,
FUSION_OR_NOT,
THE_WIZARD_IS_BUSY,
SUCCESS
Expand Down

0 comments on commit 34ac5bb

Please sign in to comment.