Skip to content

Commit

Permalink
0.5.5
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffRuLz committed Jan 17, 2019
1 parent b5b2c8f commit 9f7a473
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 141 deletions.
1 change: 0 additions & 1 deletion Makefile
Expand Up @@ -20,7 +20,6 @@ BUILD := build
SOURCES := src
DATA := data
INCLUDES := include
#GAME_ICON := $(CURDIR)/icon.bmp

GAME_TITLE := TMFH
GAME_SUBTITLE1 := Title Manager for HiyaCFW
Expand Down
73 changes: 38 additions & 35 deletions src/installmenu.c
Expand Up @@ -5,7 +5,6 @@
#include "maketmd.h"
#include <dirent.h>


enum {
INSTALL_MENU_INSTALL,
INSTALL_MENU_DELETE,
Expand All @@ -19,7 +18,6 @@ static int subMenu();
static void install(Menu* m);
static void delete(Menu* m);


void installMenu()
{
Menu* m = (Menu*)malloc(sizeof(Menu));
Expand All @@ -30,8 +28,7 @@ void installMenu()
//No files found
if (getNumberOfMenuItems(m) <= 0)
{
consoleSelect(&bottomScreen);
consoleClear();
clearScreen(&bottomScreen);

iprintf("No files found.\n");
iprintf("Place .nds, .app, or .dsi files in %s\n", ROM_PATH);
Expand Down Expand Up @@ -153,8 +150,7 @@ void generateList(Menu* m)
{
if (m == NULL) return;

consoleSelect(&bottomScreen);
consoleClear();
clearScreen(&bottomScreen);

iprintf("Gathering files...\n");

Expand Down Expand Up @@ -227,9 +223,7 @@ void install(Menu* m)
}

//Start installation
consoleSelect(&bottomScreen);
consoleClear();

clearScreen(&bottomScreen);
iprintf("Installing %s\n", fpath); swiWaitForVBlank();

tDSiHeader* header = (tDSiHeader*)malloc(sizeof(tDSiHeader));
Expand All @@ -244,7 +238,7 @@ void install(Menu* m)
}
else
{
bool patchHeader = false;
bool fixHeader = false;

//Read header and banner
{
Expand All @@ -259,9 +253,9 @@ void install(Menu* m)
if ((strcmp(header->ndshdr.gameCode, "####") == 0 && header->tid_low == 0x23232323) ||
(!*header->ndshdr.gameCode && header->tid_low == 0))
{
iprintf("Patching header...");
fixHeader = true;

patchHeader = true;
iprintf("Fixing Game Code...");

//Set as standard app
header->tid_high = 0x00030004;
Expand All @@ -282,19 +276,21 @@ void install(Menu* m)
}
while (titleIsUsed(header->tid_low, header->tid_high) == true);

//Fix header checksum
header->ndshdr.headerCRC16 = swiCRC16(0xFFFF, header, 0x15E);
//Fix RSA signature
u8 buffer[20];
swiSHA1Calc(&buffer, header, 0xE00);
memcpy(&(header->rsa_signature[0x6C]), buffer, 20);
iprintf("Done\n");
}

//Fix ique header
if (header->ndshdr.reserved1[8] == 0x80)
{
fixHeader = true;

iprintf("iQue Hack...");
header->ndshdr.reserved1[8] = 0x00;
iprintf("Done\n");
}

//Must be DSi rom
//High title id must be one of three
//High title id must be one of four
{
if (header->tid_high != 0x00030004 &&
header->tid_high != 0x00030005 &&
Expand Down Expand Up @@ -341,8 +337,11 @@ void install(Menu* m)
if (getDsiFree() < fileSize)
{
iprintf("No\n");
if (choiceBox("Try installing anyway?") == NO)

if (choicePrint("Try installing anyway?") == NO)
{
goto error;
}
}
else
{
Expand All @@ -357,8 +356,11 @@ void install(Menu* m)
if (getMenuSlotsFree() <= 0)
{
iprintf("No\n");
if (choiceBox("Try installing anyway?") == NO)

if (choicePrint("Try installing anyway?") == NO)
{
goto error;
}
}
else
{
Expand All @@ -383,19 +385,12 @@ void install(Menu* m)
{
closedir(dir);

iprintf("Title %s is already used.\nInstall anyway?\n", titleID);
iprintf("Yes - A\nNo - B\n");
char msg[512];
sprintf(msg, "Title %s is already used.\nInstall anyway?", titleID);

while (1)
if (choicePrint(msg) == NO)
{
swiWaitForVBlank();
scanKeys();

if (keysDown() & KEY_A)
break;

if (keysDown() & KEY_B)
goto complete;
goto complete;
}
}
}
Expand Down Expand Up @@ -439,10 +434,18 @@ void install(Menu* m)
iprintf("Done\n");
}

//Write new patched header
if (patchHeader == true)
//Fix and write new header
if (fixHeader == true)
{
iprintf("Writing header...");

//Fix header checksum
header->ndshdr.headerCRC16 = swiCRC16(0xFFFF, header, 0x15E);

//Fix RSA signature
u8 buffer[20];
swiSHA1Calc(&buffer, header, 0xE00);
memcpy(&(header->rsa_signature[0x6C]), buffer, 20);

FILE* f = fopen(appPath, "r+");

Expand Down
81 changes: 44 additions & 37 deletions src/main.c
Expand Up @@ -2,7 +2,7 @@
#include "menu.h"
#include <time.h>

#define VERSION "0.5.2"
#define VERSION "0.5.5"

enum {
MAIN_MENU_INSTALL,
Expand All @@ -18,7 +18,7 @@ int main(int argc, char **argv)
{
srand(time(0));

//Setup top screen
//Setup screens
REG_DISPCNT = MODE_FB0;
VRAM_A_CR = VRAM_ENABLE;

Expand All @@ -28,51 +28,52 @@ int main(int argc, char **argv)
vramSetBankA(VRAM_A_MAIN_BG);
vramSetBankC(VRAM_C_SUB_BG);

consoleInit(&topScreen, 3, BgType_Text4bpp, BgSize_T_256x256, 31, 0, true, true);
consoleInit(&topScreen, 3, BgType_Text4bpp, BgSize_T_256x256, 31, 0, true, true);
consoleInit(&bottomScreen, 3, BgType_Text4bpp, BgSize_T_256x256, 31, 0, false, true);

consoleSelect(&bottomScreen);
consoleClear();
clearScreen(&bottomScreen);

VRAM_A[100] = 0xFFFF;

//Cannot use SD card
if (!fatInitDefault())
{
consoleSelect(&bottomScreen);
consoleClear();

//iprintf("fatInitDefault...Failed\n");
//iprintf("\nPress B to exit.\n");
clearScreen(&bottomScreen);

for (int i = 0; i < 32*24; i++)
iprintf("%c", i);
iprintf("fatInitDefault()...Failed\n");
iprintf("\nPress B to exit.\n");

keyWait(KEY_B | KEY_A | KEY_START);

return 0;
}
else
{
bool programEnd = false;

while (!programEnd)
//Main menu selection
bool programEnd = false;

while (!programEnd)
{
switch (mainMenu())
{
switch (mainMenu())
{
case MAIN_MENU_INSTALL:
installMenu();
break;

case MAIN_MENU_TITLES:
titleMenu();
break;

case MAIN_MENU_TEST:
testMenu();
break;

case MAIN_MENU_EXIT:
programEnd = true;
break;
}
case MAIN_MENU_INSTALL:
installMenu();
break;

case MAIN_MENU_TITLES:
titleMenu();
break;

/* case MAIN_MENU_RESTORE:
restoreMenu();
break;
*/
case MAIN_MENU_TEST:
testMenu();
break;

case MAIN_MENU_EXIT:
programEnd = true;
break;
}
}

Expand All @@ -81,18 +82,18 @@ int main(int argc, char **argv)

static int mainMenu()
{
consoleSelect(&topScreen);
consoleClear();
clearScreen(&topScreen);

iprintf("\tTitle Manager for HiyaCFW\n");
iprintf("\nversion %s\n", VERSION);
iprintf("\x1b[23;0HJeff - 2018");
iprintf("\x1b[23;0HJeff - 2018-2019");

Menu* m = (Menu*)malloc(sizeof(Menu));
clearMenu(m);

addMenuItem(m, "Install");
addMenuItem(m, "Titles");
// addMenuItem(m, "Restore");
addMenuItem(m, "Test");
addMenuItem(m, "Exit");

Expand All @@ -114,4 +115,10 @@ static int mainMenu()
free(m);

return cursor;
}

void clearScreen(PrintConsole* screen)
{
consoleSelect(screen);
consoleClear();
}
2 changes: 2 additions & 0 deletions src/main.h
Expand Up @@ -8,6 +8,8 @@
PrintConsole topScreen;
PrintConsole bottomScreen;

void clearScreen(PrintConsole* screen);

#define abs(X) ( (X) < 0 ? -(X): (X) )
#define sign(X) ( ((X) > 0) - ((X) < 0) )
#define repeat(X) for (int _I_ = 0; _I_ < (X); _I_++)
Expand Down

0 comments on commit 9f7a473

Please sign in to comment.