2012-03-14 17:56:36 +01:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <gccore.h>
|
|
|
|
#include <sstream>
|
|
|
|
#include <vector>
|
|
|
|
#include <wiiuse/wpad.h>
|
|
|
|
|
|
|
|
#include "getios.h"
|
|
|
|
#include "menu.h"
|
|
|
|
#include "video.h"
|
|
|
|
#include "wad.h"
|
|
|
|
#include "../../svnrev/svnrev.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
std::vector<string> text1, text2, text3;
|
|
|
|
|
|
|
|
int startpos_x = 6;
|
|
|
|
int startpos_y = 12;
|
|
|
|
int menu_main_choice;
|
|
|
|
|
|
|
|
void show_menu_head()
|
|
|
|
{
|
|
|
|
Con_FgColor(6, 1);
|
|
|
|
printf("\x1b[%i;%iH", startpos_x, startpos_y);
|
2012-03-18 09:42:11 +01:00
|
|
|
printf("HBF installer v0.2.1");
|
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
Con_FgColor(7, 1);
|
|
|
|
printf("\t\t\t\t\t(C) 2011");
|
|
|
|
Con_FgColor(6, 1);
|
|
|
|
printf(" hamachi-mp");
|
2012-03-18 09:42:11 +01:00
|
|
|
|
|
|
|
Con_FgColor(7, 1);
|
2012-03-18 09:59:39 +01:00
|
|
|
printf("\n\t\t\t\t\t\t\t\t\t\t\t\t\t(C) 2012");
|
2012-03-18 09:42:11 +01:00
|
|
|
Con_FgColor(6, 1);
|
|
|
|
printf(" Nano");
|
2012-03-14 17:56:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void fill_menu_main()
|
|
|
|
{
|
|
|
|
text1.clear();
|
|
|
|
stringstream buffer;
|
2012-03-18 09:42:11 +01:00
|
|
|
buffer << "Install the HomebrewFilter rev" << SvnRev();
|
|
|
|
text1.push_back(buffer.str());
|
2012-03-14 17:56:36 +01:00
|
|
|
if(CheckAppFound(GetTitleID()))
|
2012-03-18 09:42:11 +01:00
|
|
|
text1.push_back("Uninstall the HomebrewFilter");
|
2012-03-14 17:56:36 +01:00
|
|
|
else
|
|
|
|
text1.push_back("");
|
|
|
|
text1.push_back("");
|
|
|
|
text1.push_back("Copyright");
|
|
|
|
text1.push_back("");
|
|
|
|
text1.push_back("Exit");
|
|
|
|
}
|
|
|
|
|
|
|
|
void fill_menu_install_uninstall()
|
|
|
|
{
|
2012-03-18 09:42:11 +01:00
|
|
|
text2.push_back("Continue");
|
|
|
|
text2.push_back("Go Back");
|
2012-03-14 17:56:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void fill_menu_copyright()
|
|
|
|
{
|
|
|
|
text3.push_back("Copyright (C) hamachi-mp");
|
2012-03-18 09:42:11 +01:00
|
|
|
text3.push_back("Copyright (C) Nano");
|
2012-03-14 17:56:36 +01:00
|
|
|
text3.push_back("");
|
|
|
|
text3.push_back("Thanks to:");
|
|
|
|
text3.push_back("\tTeam Twiizers");
|
|
|
|
text3.push_back("\tdevkitPRO");
|
|
|
|
text3.push_back("\tWaninkoko (WAD Manager)");
|
|
|
|
text3.push_back("\tWiiCrazy/I.R.on (Crap Installer)");
|
|
|
|
}
|
|
|
|
|
|
|
|
void menu()
|
|
|
|
{
|
|
|
|
mopen();
|
|
|
|
ISFS_Initialize();
|
|
|
|
listIOS();
|
|
|
|
|
|
|
|
fill_menu_main();
|
|
|
|
fill_menu_install_uninstall();
|
|
|
|
fill_menu_copyright();
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
menu_main_choice = text1.size() -1;
|
|
|
|
/*
|
|
|
|
int fgcolor = 3;
|
|
|
|
int fgbold = 1;
|
|
|
|
|
|
|
|
printf("\x1b[1;0H");
|
|
|
|
printf("fgcolor %i\n", fgcolor);
|
|
|
|
printf("fgbold %i\n", fgbold);
|
|
|
|
|
|
|
|
Con_FgColor(fgcolor, fgbold);
|
|
|
|
printf("test");
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
WPAD_ScanPads();
|
|
|
|
u32 pressed = WPAD_ButtonsDown(0);
|
|
|
|
|
|
|
|
if(pressed & WPAD_BUTTON_UP)
|
|
|
|
{
|
|
|
|
printf("test");
|
|
|
|
}
|
|
|
|
else if(pressed & WPAD_BUTTON_1)
|
|
|
|
{
|
|
|
|
fgcolor--;
|
|
|
|
printf("\x1b[1;0H");
|
|
|
|
Con_FgColor(7, 1);
|
|
|
|
printf("fgcolor %i\n\n", fgcolor);
|
|
|
|
Con_FgColor(fgcolor, fgbold);
|
|
|
|
printf("test");
|
|
|
|
}
|
|
|
|
else if(pressed & WPAD_BUTTON_2)
|
|
|
|
{
|
|
|
|
fgcolor++;
|
|
|
|
printf("\x1b[1;0H");
|
|
|
|
Con_FgColor(7, 1);
|
|
|
|
printf("fgcolor %i\n\n", fgcolor);
|
|
|
|
Con_FgColor(fgcolor, fgbold);
|
|
|
|
printf("test");
|
|
|
|
}
|
|
|
|
else if(pressed & WPAD_BUTTON_MINUS)
|
|
|
|
{
|
|
|
|
fgbold--;
|
|
|
|
printf("\x1b[2;0H");
|
|
|
|
Con_FgColor(7, 1);
|
|
|
|
printf("fgbold %i\n", fgbold);
|
|
|
|
Con_FgColor(fgcolor, fgbold);
|
|
|
|
printf("test");
|
|
|
|
}
|
|
|
|
else if(pressed & WPAD_BUTTON_PLUS)
|
|
|
|
{
|
|
|
|
fgbold++;
|
|
|
|
printf("\x1b[2;0H");
|
|
|
|
Con_FgColor(7, 1);
|
|
|
|
printf("fgbold %i\n", fgbold);
|
|
|
|
Con_FgColor(fgcolor, fgbold);
|
|
|
|
printf("test");
|
|
|
|
}
|
|
|
|
else if(pressed & WPAD_BUTTON_HOME)
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
*/
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
int currentMenu = 0;
|
|
|
|
while(currentMenu != MENU_EXIT)
|
|
|
|
{
|
|
|
|
switch (currentMenu)
|
|
|
|
{
|
|
|
|
case MENU_MAIN:
|
|
|
|
currentMenu = menu_main(menu_main_choice);
|
|
|
|
break;
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
case MENU_INSTALL:
|
|
|
|
currentMenu = menu_install_uninstall(1);
|
|
|
|
break;
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
case MENU_UNINSTALL:
|
|
|
|
currentMenu = menu_install_uninstall(0);
|
|
|
|
break;
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
case MENU_INSTALLING:
|
|
|
|
currentMenu = menu_install();
|
|
|
|
break;
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
case MENU_UNINSTALLING:
|
|
|
|
currentMenu = menu_uninstall();
|
|
|
|
break;
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
case MENU_COPYRIGHT:
|
|
|
|
currentMenu = menu_copyright();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
ISFS_Deinitialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
int menu_main(int scrollpos)
|
|
|
|
{
|
|
|
|
Con_Clear();
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
show_menu_head();
|
|
|
|
fill_menu_main();
|
|
|
|
if(text1[scrollpos] == "")
|
|
|
|
scrollpos = text1.size() -1;
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
Con_FgColor(3, 1);
|
|
|
|
printf("\x1b[%i;%iH", startpos_x +2, startpos_y);
|
|
|
|
printf("Main Menu");
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
Con_FgColor(7, 1);
|
|
|
|
for(int i=0; i < (signed)text1.size(); i++)
|
|
|
|
{
|
|
|
|
printf("\x1b[%i;%iH", startpos_x +4 +i, startpos_y +3);
|
|
|
|
printf("%s", text1[i].c_str());
|
|
|
|
}
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
bool scroll = true;
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
WPAD_ScanPads();
|
|
|
|
u32 pressed = WPAD_ButtonsDown(0);
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
if ( pressed & WPAD_BUTTON_DOWN && scrollpos < (signed)text1.size() -1)
|
|
|
|
{
|
|
|
|
scrollpos++;
|
|
|
|
while(text1[scrollpos] == "")
|
|
|
|
scrollpos++;
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
scroll = true;
|
|
|
|
}
|
|
|
|
else if ( pressed & WPAD_BUTTON_UP && scrollpos != 0)
|
|
|
|
{
|
|
|
|
scrollpos--;
|
|
|
|
while(text1[scrollpos] == "")
|
|
|
|
scrollpos--;
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
scroll = true;
|
|
|
|
}
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
if(scroll)
|
|
|
|
{
|
|
|
|
for(int i=0; i < (signed)text1.size(); i++)
|
|
|
|
{
|
|
|
|
printf("\x1b[%i;%iH", startpos_x +4 +i, startpos_y);
|
|
|
|
if(i == scrollpos)
|
|
|
|
printf(">>");
|
|
|
|
else
|
|
|
|
printf(" ");
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
}
|
|
|
|
scroll = false;
|
|
|
|
}
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
if( pressed & WPAD_BUTTON_A )
|
|
|
|
{
|
|
|
|
menu_main_choice = scrollpos;
|
|
|
|
switch(scrollpos)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return MENU_INSTALL;
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
case 1:
|
|
|
|
return MENU_UNINSTALL;
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
case 3:
|
|
|
|
return MENU_COPYRIGHT;
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
default:
|
|
|
|
return MENU_EXIT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int menu_install_uninstall(int install)
|
|
|
|
{
|
|
|
|
Con_Clear();
|
|
|
|
show_menu_head();
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
Con_FgColor(7, 1);
|
|
|
|
printf("\x1b[%i;%iH", startpos_x +2, startpos_y);
|
|
|
|
if(install)
|
2012-03-18 09:42:11 +01:00
|
|
|
printf("Install the HomebrewFilter now");
|
2012-03-14 17:56:36 +01:00
|
|
|
else
|
2012-03-18 09:42:11 +01:00
|
|
|
printf("Uninstall the HomebrewFilter now");
|
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
for(int i=0; i < (signed)text2.size(); i++)
|
|
|
|
{
|
|
|
|
printf("\x1b[%i;%iH", startpos_x +4 +i, startpos_y +3);
|
|
|
|
printf("%s", text2[i].c_str());
|
|
|
|
}
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
int scrollpos = 1;
|
|
|
|
bool scroll = true;
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
WPAD_ScanPads();
|
|
|
|
u32 pressed = WPAD_ButtonsDown(0);
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
if ( pressed & WPAD_BUTTON_DOWN && scrollpos < (signed)text2.size() -1)
|
|
|
|
{
|
|
|
|
scrollpos++;
|
|
|
|
scroll = true;
|
|
|
|
}
|
|
|
|
else if ( pressed & WPAD_BUTTON_UP && scrollpos != 0)
|
|
|
|
{
|
|
|
|
scrollpos--;
|
|
|
|
scroll = true;
|
|
|
|
}
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
if(scroll)
|
|
|
|
{
|
|
|
|
for(int i=0; i < (signed)text2.size(); i++)
|
|
|
|
{
|
|
|
|
printf("\x1b[%d;12H", startpos_x +4 +i);
|
|
|
|
if(i == scrollpos)
|
|
|
|
printf(">>");
|
|
|
|
else
|
|
|
|
printf(" ");
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
}
|
|
|
|
scroll = false;
|
|
|
|
}
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
if( pressed & WPAD_BUTTON_A )
|
|
|
|
{
|
|
|
|
switch(scrollpos)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
if(install)
|
|
|
|
return MENU_INSTALLING;
|
|
|
|
else
|
|
|
|
return MENU_UNINSTALLING;
|
|
|
|
break;
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
case 1:
|
|
|
|
return MENU_MAIN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int menu_install()
|
|
|
|
{
|
|
|
|
Con_Clear();
|
|
|
|
show_menu_head();
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
Con_FgColor(7, 1);
|
|
|
|
printf("\x1b[%i;%iH", startpos_x +2, startpos_y);
|
2012-03-18 09:42:11 +01:00
|
|
|
printf("Installing the HomebrewFilter");
|
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
printf("\x1b[%i;%iH", startpos_x +4, startpos_y);
|
|
|
|
if(Wad_InstallFromMemory(startpos_x, startpos_y) >= 0)
|
|
|
|
{
|
|
|
|
if(!getIOS(58))
|
|
|
|
{
|
|
|
|
s32 fd;
|
|
|
|
u32 high = (u32)(GetTitleID() >> 32);
|
|
|
|
u32 low = (u32)(GetTitleID() & 0xFFFFFFFF);
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
char filepath[ISFS_MAXPATH];
|
|
|
|
sprintf(filepath, "/title/%08x/%08x/content/title.tmd", high, low);
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
static fstats filestats ATTRIBUTE_ALIGN(32);
|
|
|
|
static u8 filearray[1024] ATTRIBUTE_ALIGN(32);
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
fd = ISFS_Open(filepath, ISFS_OPEN_READ);
|
|
|
|
if (fd <= 0)
|
|
|
|
ISFS_Close(fd);
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
ISFS_GetFileStats(fd, &filestats);
|
|
|
|
ISFS_Read(fd, filearray, filestats.file_length);
|
|
|
|
ISFS_Close(fd);
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
if(filestats.file_length >= 0)
|
|
|
|
{
|
|
|
|
fd = ISFS_Open(filepath, ISFS_OPEN_RW);
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
if(getIOS(61))
|
|
|
|
filearray[395] = 61;
|
|
|
|
else
|
|
|
|
filearray[395] = IOS_GetVersion();
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
ISFS_Write(fd, filearray, sizeof( filearray ));
|
|
|
|
ISFS_Close(fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
Con_FgColor(7, 1);
|
|
|
|
printf("\x1b[%i;%iH", startpos_x +8, startpos_y);
|
|
|
|
printf(">> Continue");
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
WPAD_ScanPads();
|
|
|
|
u32 pressed = WPAD_ButtonsDown(0);
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
if( pressed & WPAD_BUTTON_A )
|
|
|
|
return MENU_MAIN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int menu_uninstall()
|
|
|
|
{
|
|
|
|
Con_Clear();
|
|
|
|
show_menu_head();
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
Con_FgColor(7, 1);
|
|
|
|
printf("\x1b[%i;%iH", startpos_x +2, startpos_y);
|
2012-03-18 09:42:11 +01:00
|
|
|
printf("Uninstalling the HomebrewFilter");
|
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
Wad_UninstallFromMemory(startpos_x, startpos_y);
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
Con_FgColor(7, 1);
|
|
|
|
printf("\x1b[%i;%iH", startpos_x +8, startpos_y);
|
|
|
|
printf(">> Continue");
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
WPAD_ScanPads();
|
|
|
|
u32 pressed = WPAD_ButtonsDown(0);
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
if( pressed & WPAD_BUTTON_A )
|
|
|
|
return MENU_MAIN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int menu_copyright()
|
|
|
|
{
|
|
|
|
Con_Clear();
|
|
|
|
show_menu_head();
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
Con_FgColor(7, 1);
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
for(int i=0; i < (signed)text3.size(); i++)
|
|
|
|
{
|
|
|
|
printf("\x1b[%i;%iH", startpos_x +2 +i, startpos_y);
|
|
|
|
printf("%s", text3[i].c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\x1b[%i;%iH", startpos_x + text3.size() +3, startpos_y);
|
|
|
|
printf(">> Continue");
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
WPAD_ScanPads();
|
|
|
|
u32 pressed = WPAD_ButtonsDown(0);
|
2012-03-18 09:42:11 +01:00
|
|
|
|
2012-03-14 17:56:36 +01:00
|
|
|
if( pressed & WPAD_BUTTON_A )
|
|
|
|
return MENU_MAIN;
|
|
|
|
}
|
2012-03-18 09:42:11 +01:00
|
|
|
}
|