Skip to content

Commit

Permalink
Initial case of card and region checks
Browse files Browse the repository at this point in the history
Checks don't do anything yet aside from displaying warnings.
  • Loading branch information
ev1l0rd committed Apr 9, 2018
1 parent d13c9c2 commit da499b9
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 9 deletions.
36 changes: 27 additions & 9 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
#include <3ds.h>
#include "editprofile.h"
#include "main.h"
#include "title.h"

typedef enum {
/* Default sort but its commented to make it easy on _my_ mind. */
MAIN_SCREEN = 0,
SELECT_SAVE = 1,
FUSION_OR_NOT = 2,
THE_WIZARD_IS_BUSY = 3,
SUCCESS = 4
MAIN_SCREEN,
VERSION_TO_EDIT,
SELECT_SAVE,
FUSION_OR_NOT,
THE_WIZARD_IS_BUSY,
SUCCESS
}States;

int main() {
Expand All @@ -21,9 +23,11 @@ int main() {
consoleSelect(&topScreen);

States state = MAIN_SCREEN;
int profile_num;
int profile_num = 0;
int fusion_mode = 0;
int not_busy = 1;
int version_undetermined = 1;
u32 lowid;

printf("Metroid: SAMUS RETURNS amiibo unlocker v0.2-alpha\nThis unlocker is in ALPHA. Bugs and stuff are expected.\nPress A to continue.\n");

Expand All @@ -41,9 +45,24 @@ int main() {
if (kDown & KEY_A)
{
printSaveSelect();
state = SELECT_SAVE;
state = VERSION_TO_EDIT;
}
}

if (state == VERSION_TO_EDIT)
{
if (version_undetermined)
{
lowid = title_check();
if (lowid != 0) {
state = SELECT_SAVE;
} else {
printf("Could not determine version automatically.\n");
version_undetermined = 1;
}
}
}

if (state == SELECT_SAVE) // State 1 = Save select
{
if (kDown & KEY_Y) // Save 1 was chosen
Expand Down Expand Up @@ -89,7 +108,7 @@ int main() {
if(R_FAILED(res)) {
int cursorX = topScreen.cursorX;
int cursorY = topScreen.cursorY;
printf("\x1b[30;16H%4lx\n", res);
printf("\x1b[s\x1b[30;16H%4lx\n\x1b[u", res);
topScreen.cursorX = cursorX;
topScreen.cursorY = cursorY;
printf("Something went wrong, please see the error message below.\n");
Expand All @@ -107,7 +126,6 @@ int main() {
}

cfguExit();
fsExit();
gfxExit();
return 0;
}
Expand Down
73 changes: 73 additions & 0 deletions source/title.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include <3ds.h>
#include <stdio.h>
#include <stdlib.h>
#include "title.h"

/*
* title_check
* returns lowid if it can be automagically determined. otherwise returns 0
*/
u32 title_check()
{
u64 title_id; // This is for checking the title ID
u32 lowid = 0; // This is to be returned at the end.

u32 titles_read;
u32 title_count;

// Start by checking for the inserted card.
bool card_inserted;
FSUSER_CardSlotIsInserted(&card_inserted);
amInit();
if (card_inserted)
{
// Card found? Great, prioritize that.
AM_GetTitleList(&titles_read, MEDIATYPE_GAME_CARD, 1, &title_id);
int title_valid = valid_title(title_id, &lowid);
if (title_valid)
{
printf("Located a game card copy of SR, using that.\n");
// Title valid? No point in continuing, lets give the lowid back.
return lowid;
}
}

// No/Invalid card found.
u64* sd_titles;
int title_valid;
AM_GetTitleCount(MEDIATYPE_SD, &title_count);
sd_titles = malloc(title_count * sizeof(u64));
AM_GetTitleList(&titles_read, MEDIATYPE_SD, title_count, sd_titles);
for (unsigned int i = 0; i < title_count; ++i)
{
title_valid = valid_title(sd_titles[i], &lowid);
if (title_valid) {
printf("Located game copy with lowid: %ld\n", lowid);
break;
}
}

amExit();
return 0;
}

int valid_title(u64 title_id, u32 *lowid)
{
switch(title_id)
{
case 0x00040000001BB200:
*lowid = 0x001BB200;
return 1;

case 0x00040000001BFB00:
*lowid = 0x001BFB00;
return 1;

case 0x00040000001BFC00:
*lowid = 0x001BFC00;
return 1;

default:
return 0;
}
}
4 changes: 4 additions & 0 deletions source/title.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include <3ds.h>
#include <stdio.h>
u32 title_check();
int valid_title(u64 title_id, u32 *lowid);

0 comments on commit da499b9

Please sign in to comment.