Any-Region-Changer-ModMii-E.../source/main.c

486 lines
12 KiB
C
Raw Normal View History

2022-04-21 02:12:38 +02:00
/*-------------------------------------------------------------
2022-04-21 03:38:39 +02:00
2022-04-21 02:12:38 +02:00
regionchange.c -- Region Changing application
2022-04-21 03:38:39 +02:00
2022-04-21 02:12:38 +02:00
Copyright (C) 2008 tona
2022-04-21 03:38:39 +02:00
2022-04-21 02:12:38 +02:00
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
2022-04-21 03:38:39 +02:00
2022-04-21 02:12:38 +02:00
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
2022-04-21 03:38:39 +02:00
2022-04-21 02:12:38 +02:00
1.The origin of this software must not be misrepresented; you
must not claim that you wrote the original software. If you use
this software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
2022-04-21 03:38:39 +02:00
2022-04-21 02:12:38 +02:00
2.Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
2022-04-21 03:38:39 +02:00
2022-04-21 02:12:38 +02:00
3.This notice may not be removed or altered from any source
distribution.
2022-04-21 03:38:39 +02:00
2022-04-21 02:12:38 +02:00
-------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <malloc.h>
#include <assert.h>
#include <string.h>
#include <ogcsys.h>
#include <gccore.h>
#include <ogc/system.h>
#include <wiiuse/wpad.h>
#include "wiibasics.h"
#include "runtimeiospatch.h"
#include "sysconf.h"
#include "id.h"
#include "detect_settings.h"
#include "gecko.h"
2022-04-21 03:38:39 +02:00
#define ITEMS 11
2022-04-21 02:12:38 +02:00
#define SADR_LENGTH 0x1007 + 1
#define WARNING_SIGN "\x1b[30;1m\x1b[43;1m/!\\\x1b[37;1m\x1b[40m"
2022-04-21 03:38:39 +02:00
#define maxdata 256
2022-04-21 02:12:38 +02:00
u32 selected = 8;
2022-04-21 02:12:38 +02:00
char page_contents[ITEMS][64];
int lang, area, game, video, region, country, countrystr, eula;
u8 sadr[SADR_LENGTH];
char languages[][ITEMS] = {"Japanese ", "English ", "German ", "French ", "Spanish ", "Italian ", "Dutch "};
char areas[][ITEMS] = {"Japan ", "USA ", "Europe ", "Australia", "Brazil ", "Taiwan ", "China ", "Korea ", "Hong Kong", "Asia ", "Latin Am.", "S. Africa"};
char regions[][ITEMS] = {"Japan ", "USA ", "Europe ", "Korea "};
char vmodes[][ITEMS] = {"NTSC ", "PAL ", "MPAL "};
char eulas[][ITEMS] = {"Unread ", "Read "};
2022-04-21 03:38:39 +02:00
void draw_credits()
{
2022-04-21 02:12:38 +02:00
ClearScreen();
PrintBanner();
2022-04-21 03:38:39 +02:00
Console_SetPosition(3, 0);
2022-04-21 02:12:38 +02:00
printf("\t\t\t\tCREDITS:\n\n\n");
printf("\tOriginal Program:\n");
printf("\t- Tona\n");
printf("\n\tOthers in Original Credits: \n");
printf("\t- Bushing, svpe, Marcan, Waninkoko, Crediar, \n");
printf("\t- ChipD, Sorak05, serlex, pcg, callmebob, and dieforit .\n");
printf("\n\tARC ModMii Edition: \n");
printf("\t- Scooby74029(FakeCoder) - Coding \n");
printf("\t- Xflak - testing, overall help \n");
2022-04-21 02:17:37 +02:00
printf("\t- TheShadowEevee - KR region support \n");
2022-04-21 02:12:38 +02:00
printf("\t- To Many Coders To Thank For The Great Code I Used ..... \n");
printf("\n");
2022-04-21 03:38:39 +02:00
Console_SetPosition(26, 0);
2022-04-21 02:12:38 +02:00
ClearLine();
Console_SetPosition(26, 20);
printf("Press Any Button To Return ..... ");
}
2022-05-05 13:58:36 +02:00
2022-04-21 03:38:39 +02:00
void Draw_Disclaimer()
{
2022-04-21 02:12:38 +02:00
ClearScreen();
PrintBanner();
printf("\n\t This software comes supplied with absolutely no warranty.\n");
printf("\t\t\t\tUse this software at your own risk.\n");
2022-04-21 03:38:39 +02:00
2022-04-21 02:12:38 +02:00
printf("\n\n\n\t\t\t\t" WARNING_SIGN " IMPORTANT BRICK INFORMATION " WARNING_SIGN "\n\n");
printf("\n\tSemi Bricks are caused by the Console Area setting not matching\n");
printf("\tyour System Menu region. A semi-brick in itself is not terribly\n");
printf("\tharmful, but it can easily deteriorate into a full brick--there\n");
printf("\tare multiple simple triggers to do so.\n");
printf("\n\n\n\tIn order to practice proper safety when using this application, \n");
printf("\tplease make sure that your Console Area and System Menu region \n");
printf("\tare congruent before rebooting your system. A warning will be\n");
printf("\tdisplayed if they are not in agreement.\n");
2022-04-21 03:38:39 +02:00
2022-04-21 02:12:38 +02:00
sleep(5);
printf("\n\n\n\n\t\t\t\t[A] Continue [Home] Exit\n");
wait_key(WPAD_BUTTON_A);
}
2022-05-05 13:58:36 +02:00
2022-04-21 03:38:39 +02:00
void handleError(const char *string, int errorval)
{
2022-04-21 02:12:38 +02:00
printf("Unexpected Error: %s Value: %d\n", string, errorval);
printf("Press any key to quit\n");
wait_anyKey();
exit(0);
}
2022-04-21 03:38:39 +02:00
void getSettings(void)
{
2022-04-21 02:12:38 +02:00
int ret;
lang = SYSCONF_GetLanguage();
area = SYSCONF_GetArea();
2022-04-21 03:38:39 +02:00
game = SYSCONF_GetRegion();
2022-04-21 02:12:38 +02:00
video = SYSCONF_GetVideo();
eula = SYSCONF_GetEULA();
2022-04-21 03:38:39 +02:00
if (lang < 0 || area < 0 || game < 0 || video < 0 || (eula != SYSCONF_ENOENT && eula < 0))
{
2022-04-21 02:12:38 +02:00
printf("Error getting settings! %d, %d, %d, %d, %d\n", lang, area, game, video, eula);
wait_anyKey();
exit(1);
}
2022-04-21 03:38:39 +02:00
if (SYSCONF_GetLength("IPL.SADR") != SADR_LENGTH)
handleError("IPL.SADR Length Incorrect", SYSCONF_GetLength("IPL.SADR"));
2022-04-21 02:12:38 +02:00
ret = SYSCONF_Get("IPL.SADR", sadr, SADR_LENGTH);
2022-04-21 03:38:39 +02:00
if (ret < 0)
handleError("SYSCONF_Get IPL.SADR", ret);
2022-04-21 02:12:38 +02:00
country = sadr[0];
gprintf("\n\ncountry[%i] \n\n", country);
}
2022-04-21 03:38:39 +02:00
void saveSettings(void)
{
2022-04-21 02:12:38 +02:00
Console_SetPosition(24, 0);
int ret = 0;
2022-04-21 03:38:39 +02:00
if (lang != SYSCONF_GetLanguage())
ret = SYSCONF_SetLanguage(lang);
if (ret)
handleError("SYSCONF_SetLanguage", ret);
if (area != SYSCONF_GetArea())
ret = SYSCONF_SetArea(area);
if (ret)
handleError("SYSCONF_SetArea", ret);
if (game != SYSCONF_GetRegion())
ret = SYSCONF_SetRegion(game);
if (ret)
handleError("SYSCONF_SetRegion", ret);
if (video != SYSCONF_GetVideo())
ret = SYSCONF_SetVideo(video);
if (ret)
handleError("SYSCONF_SetVideo", ret);
if (eula != SYSCONF_GetEULA())
ret = SYSCONF_SetEULA(eula);
if (ret)
handleError("SYSCONF_SetEULA", ret);
if (country != sadr[0])
{
2022-04-21 02:12:38 +02:00
memset(sadr, 0, SADR_LENGTH);
sadr[0] = country;
ret = SYSCONF_Set("IPL.SADR", sadr, SADR_LENGTH);
2022-04-21 03:38:39 +02:00
if (ret)
handleError("SYSCONF_Set IPL.SADR", ret);
2022-04-21 02:12:38 +02:00
}
2022-04-21 03:38:39 +02:00
// wait_anyKey();
2022-04-21 02:12:38 +02:00
printf("Saving...");
ret = SYSCONF_SaveChanges();
2022-04-21 03:38:39 +02:00
if (ret < 0)
handleError("SYSCONF_SaveChanges", ret);
else
printf("OK!\n");
2022-04-21 02:12:38 +02:00
printf("Press any key to continue .....");
wait_anyKey();
}
2022-04-21 03:38:39 +02:00
void updateSelected(int delta)
{
if (selected + delta >= ITEMS || selected + delta < 0)
return;
if (delta != 0)
{
2022-04-21 02:12:38 +02:00
// Remove the cursor from the last selected item
page_contents[selected][1] = ' ';
page_contents[selected][45] = ' ';
page_contents[selected][57] = ' ';
// Set new cursor location
selected += delta;
}
2022-04-21 03:38:39 +02:00
2022-04-21 02:12:38 +02:00
// Add the cursor to the now-selected item
page_contents[selected][1] = '>';
page_contents[selected][45] = '<';
page_contents[selected][57] = '>';
}
2022-04-21 03:38:39 +02:00
void updatePage(void)
{
2022-04-21 02:12:38 +02:00
sprintf(page_contents[0], " %-40s %10s \n", "Language Setting:", languages[lang]);
sprintf(page_contents[1], " %-40s %10s \n", "Console Area Setting:", areas[area]);
sprintf(page_contents[2], " %-40s %10s \n", "Game Region Setting:", regions[game]);
sprintf(page_contents[3], " %-40s %10s \n", "Console Video Mode:", vmodes[video]);
sprintf(page_contents[4], " %-40s %10d \n", "Shop Country Code:", country);
2022-04-21 03:38:39 +02:00
sprintf(page_contents[5], " %-40s %10s \n", "Services EULA:", (eula == SYSCONF_ENOENT) ? "Disabled" : eulas[eula]);
2022-04-21 02:12:38 +02:00
sprintf(page_contents[6], " %-40s %10s \n", "Revert Settings", "Revert ");
sprintf(page_contents[7], " %-40s %10s \n", "Save Settings", "Save ");
sprintf(page_contents[8], " %-40s %10s \n", "Auto Fix Settings ", "Fix ");
sprintf(page_contents[9], " %-40s %10s \n", "Exit to the Homebrew Channel", "Exit ");
updateSelected(0);
}
2022-04-21 03:38:39 +02:00
char AREAtoSysMenuRegion(int area)
{
2022-04-21 02:12:38 +02:00
// Data based on my own tests with AREA/Sysmenu
2022-04-21 03:38:39 +02:00
switch (area)
{
case 0:
case 5:
case 6:
return 'J';
case 1:
case 4:
case 8:
case 9:
case 10:
case 11:
return 'U';
case 2:
case 3:
return 'E';
case 7:
return 'K';
2022-04-21 03:38:39 +02:00
default:
return 0;
2022-04-21 02:12:38 +02:00
}
}
//---------------------------------------------------------------------------------
2022-04-21 03:38:39 +02:00
int main(int argc, char **argv)
{
//---------------------------------------------------------------------------------
2022-04-21 02:12:38 +02:00
int ret = 0, i;
u16 sysmenu_version;
char sysmenu_region;
bool needbreak = false;
u32 buttons;
int Current_Ios = 0;
2022-04-21 03:38:39 +02:00
2022-04-21 02:12:38 +02:00
ret = IOS_ReloadIOS(236);
2022-04-21 03:38:39 +02:00
if (ret != 0)
{
2022-04-21 02:12:38 +02:00
ret = IOS_ReloadIOS(249);
2022-04-21 03:38:39 +02:00
if (ret != 0)
{
2022-04-21 02:12:38 +02:00
IosPatch_FULL(true, true, false, false, 58);
}
}
basicInit();
2022-04-21 03:38:39 +02:00
2022-04-21 02:12:38 +02:00
miscInit();
2022-04-21 03:38:39 +02:00
if (InitGecko())
2022-04-21 02:12:38 +02:00
USBGeckoOutput();
Current_Ios = IOS_GetVersion();
gprintf("\n\ncurrent_ios [%i] \n\n", Current_Ios);
2022-04-21 03:38:39 +02:00
sysmenu_version = get_installed_title_version(TITLE_ID(1, 2));
2022-04-21 02:12:38 +02:00
sysmenu_region = get_sysmenu_region();
gprintf("\n\nsysmenu_version[%u] sysmenu_region[%c] \n\n", sysmenu_version, sysmenu_region);
gprintf("Init SYSCONF...");
ret = SYSCONF_Init();
2022-04-21 03:38:39 +02:00
if (ret < 0)
handleError("SYSCONF_Init", ret);
else
gprintf("OK!\n");
2022-04-21 02:12:38 +02:00
getSettings();
region = game;
Draw_Disclaimer();
updatePage();
2022-04-21 03:38:39 +02:00
while (1)
{
2022-04-21 02:12:38 +02:00
PrintBanner();
printf("\n------------------------------------------------------------------------");
printf("Edit Region Settings");
if (sysmenu_region != 0 && sysmenu_region != AREAtoSysMenuRegion(area))
printf(" " WARNING_SIGN " \x1b[41;1mWARNING: AREA/SysMenu MISMATCH!\x1b[40m " WARNING_SIGN);
printf("\n------------------------------------------------------------------------");
for (i = 0; i < 4; i++)
printf(page_contents[i]);
2022-04-21 03:38:39 +02:00
2022-04-21 02:12:38 +02:00
printf("\t Country Codes: \t1[JPN] 49[USA] 110[UK] 136[KOR]\n");
2022-04-21 03:38:39 +02:00
2022-04-21 02:12:38 +02:00
for (i = i; i < 8; i++)
printf(page_contents[i]);
printf("------------------------------------------------------------------------");
2022-04-21 02:50:59 +02:00
printf("Auto Fix - SysMenu Region: %c (v%u)\n", sysmenu_region, sysmenu_version);
2022-04-21 02:12:38 +02:00
printf("------------------------------------------------------------------------");
for (i = i; i < 9; i++)
printf(page_contents[i]);
printf("------------------------------------------------------------------------");
printf("Exiting Options\n");
printf("------------------------------------------------------------------------");
for (i = i; i < ITEMS; i++)
printf(page_contents[i]);
printf("------------------------------------------------------------------------");
Console_SetPosition(26, 0);
printf("Change Selection: [%s%s %s%s]\t\t\t\t\t\tSelect: [A]\tCredits: [1]", LEFT_ARROW, RIGHT_ARROW, UP_ARROW, DOWN_ARROW);
buttons = wait_anyKey();
gprintf("\n\nselected [%i] \n\n", selected);
if (buttons & WPAD_BUTTON_DOWN)
updateSelected(1);
2022-04-21 03:38:39 +02:00
2022-04-21 02:12:38 +02:00
if (buttons & WPAD_BUTTON_UP)
updateSelected(-1);
2022-04-21 03:38:39 +02:00
if (buttons & WPAD_BUTTON_LEFT)
{
switch (selected)
{
case 0:
if (--lang < 0)
lang = 6;
2022-04-21 02:12:38 +02:00
break;
2022-04-21 03:38:39 +02:00
case 1:
if (--area < 0)
area = 11;
2022-04-21 02:12:38 +02:00
break;
2022-04-21 03:38:39 +02:00
case 2:
if (--game < 0)
game = 3;
2022-04-21 02:12:38 +02:00
break;
2022-04-21 03:38:39 +02:00
case 3:
if (--video < 0)
video = 2;
2022-04-21 02:12:38 +02:00
break;
2022-04-21 03:38:39 +02:00
case 4:
if (country == 1)
country = 136;
else if (country == 49)
country = 1;
else if (country == 110)
country = 49;
else if (country == 136)
country = 110;
if (eula >= 0)
eula = 0;
2022-04-21 02:12:38 +02:00
break;
2022-04-21 03:38:39 +02:00
case 5:
if (eula >= 0)
eula = !eula;
2022-04-21 02:12:38 +02:00
break;
}
}
2022-04-21 03:38:39 +02:00
if (buttons & WPAD_BUTTON_RIGHT)
{
switch (selected)
{
case 0:
if (++lang == 7)
lang = 0;
2022-04-21 02:12:38 +02:00
break;
2022-04-21 03:38:39 +02:00
case 1:
if (++area == 12)
area = 0;
2022-04-21 02:12:38 +02:00
break;
2022-04-21 03:38:39 +02:00
case 2:
if (++game == 4)
game = 0;
2022-04-21 02:12:38 +02:00
break;
2022-04-21 03:38:39 +02:00
case 3:
if (++video == 3)
video = 0;
2022-04-21 02:12:38 +02:00
break;
2022-04-21 03:38:39 +02:00
case 4:
if (country == 1)
country = 49;
else if (country == 49)
country = 110;
else if (country == 110)
country = 136;
else if (country == 136)
country = 1;
if (eula >= 0)
eula = 0;
2022-04-21 02:12:38 +02:00
break;
2022-04-21 03:38:39 +02:00
case 5:
if (eula >= 0)
eula = !eula;
2022-04-21 02:12:38 +02:00
break;
}
}
2022-04-21 03:38:39 +02:00
if (buttons & WPAD_BUTTON_A)
{
switch (selected)
{
case 6:
getSettings();
2022-04-21 02:12:38 +02:00
break;
2022-04-21 03:38:39 +02:00
case 7:
saveSettings();
2022-04-21 02:12:38 +02:00
break;
2022-04-21 03:38:39 +02:00
case 8:
if (sysmenu_region == 85)
{ // usa
lang = 1;
area = 1;
game = 1;
video = 0;
country = 49;
}
else if (sysmenu_region == 74)
{ // jpn
lang = 0;
area = 0;
game = 0;
video = 0;
country = 1;
}
else if (sysmenu_region == 69)
{ // EUR/PAL
lang = 1;
area = 2;
game = 2;
video = 1;
country = 110;
}
2022-05-05 13:58:36 +02:00
else if (sysmenu_region == 75)
2022-04-21 03:38:39 +02:00
{ // KOR
lang = 1;
area = 7;
game = 3;
video = 0;
country = 136;
}
2022-05-05 13:58:36 +02:00
else
{
printf("\nUnknown System Menu region \"%u\".\n", sysmenu_region);
printf("Press any key to quit\n");
wait_anyKey();
exit(0);
}
2022-04-21 03:38:39 +02:00
saveSettings();
2022-04-21 02:12:38 +02:00
break;
2022-04-21 03:38:39 +02:00
case 9:
needbreak = true;
2022-04-21 02:12:38 +02:00
break;
2022-04-21 03:38:39 +02:00
case 10:
STM_RebootSystem();
2022-04-21 02:12:38 +02:00
break;
}
}
2022-04-21 03:38:39 +02:00
if (buttons & WPAD_BUTTON_B)
{
2022-04-21 02:12:38 +02:00
selected = 9;
}
2022-04-21 03:38:39 +02:00
if (buttons & WPAD_BUTTON_1)
{
2022-04-21 02:12:38 +02:00
draw_credits();
wait_anyKey();
}
updatePage();
2022-04-21 03:38:39 +02:00
if (needbreak)
2022-04-21 02:12:38 +02:00
break;
}
2022-04-21 03:38:39 +02:00
Console_SetPosition(26, 30);
2022-04-21 02:12:38 +02:00
Console_SetColors(BLACK, 0, GREEN, 0);
printf("Exiting");
miscDeInit();
2022-04-21 03:38:39 +02:00
2022-04-21 02:12:38 +02:00
exit(0);
}