Ejemplo n.º 1
0
int main() {
    gfxInitDefault();
    consoleInit(GFX_TOP, NULL);
    
    Filesystem fs;
    std::string path = "pk/save/main";
    
    if( fs.isInitialized() )
        std::cout << "X: Export save file\nY: Inject save file\n\nSTART: Exit\n\n";
    
    else 
        std::cout << "Failed to initialize filesystem, press START to exit.";

    while(aptMainLoop()) {
        hidScanInput();
        u32 kDown = hidKeysDown();
        
        if( fs.isInitialized() ) {
            if(kDown & KEY_X) {
                if( fs.exportSaveFile(path) )
                    std::cout << "Success! Savefile exported in " << path << ".\n";
                else 
                    std:: cout << "Failed!";
                
                waitA();
                consoleClear();
                std::cout << "X: Export save file\nY: Inject save file\n\nSTART: Exit\n\n";
            }
            
            if(kDown & KEY_Y) {
                if( fs.exportSaveFile(path) )
                    std::cout << "Success! Savefile imported\n";
                else 
                    std:: cout << "Failed!";
                
                waitA();
                consoleClear();
                std::cout << "X: Export save file\nY: Inject save file\n\nSTART: Exit\n\n";
            }
        }
        
        if(kDown & KEY_START) break;
        gfxFlushBuffers();
	gfxSwapBuffers();
        gspWaitForVBlank();
    }
    
    gfxExit();
    return 0;
}
Ejemplo n.º 2
0
//---------------------------------------------------------------------------------
int main() {
//---------------------------------------------------------------------------------
	VIDEO_Init();
	
	rmode = VIDEO_GetPreferredMode(NULL);

	PAD_Init();
	
	xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
		
	VIDEO_Configure(rmode);
		
	VIDEO_SetNextFramebuffer(xfb);
	VIDEO_SetBlack(FALSE);
	VIDEO_Flush();
	VIDEO_WaitVSync();
	if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
	console_init(xfb,20,64,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*2);
	VIDEO_SetNextFramebuffer(xfb);
	
	int slot = CARD_SLOTA;
	u32 i;
	int tomenu = 0;
	u16 buttonsDown;
	u8 pressed = 0;
	int filesize;
	int bytesdone = 0;
	
	while(1){
		VIDEO_ClearFrameBuffer (rmode, xfb, COLOR_BLACK);
		listpos=0;
		tomenu=0;
		pressed = 0;
		printf("\x1b[2;0H");
		printf("Memory Card Loader 0.2 by Suloku\n");
		printf("********************************\n\n");
		printf("Press A or B button to select a slot.\n");
		while (1){
			PAD_ScanPads();
			buttonsDown=PAD_ButtonsDown(0);
			if (buttonsDown & PAD_BUTTON_A){ slot = CARD_SLOTA; pressed = 1;}
			if (buttonsDown & PAD_BUTTON_B){ slot = CARD_SLOTB; pressed = 1;}
			if (buttonsDown & PAD_BUTTON_START){ PSOreload();}
			VIDEO_WaitVSync();
			if (pressed) break;
		}
		printf("Mounting card in slot %s...", (slot==0?"A":"B"));
		
		int Slot_error = MountCard(slot);
		printf("code %d. ",Slot_error);

		int CardError;
		
		if (Slot_error >= 0) {
			printf("Sector size is %d bytes.\n",sectsize);
			printf("Reading memory card files...");

			card_dir CardDir;
			card_file CardFile;
			
			CardError = CARD_FindFirst(slot, &CardDir, true);

			cardcount = 0;
			while ( CARD_ERROR_NOFILE != CardError ) {
				if (strncmp ("DOLX", (char *)CardDir.gamecode, 4)  ==  0){
					memcpy (&CardList[cardcount], &CardDir, sizeof (card_dir));
					cardcount++;
				}
				CardError = CARD_FindNext(&CardDir);
			}
			printf("finished.\n\n");
			
			if (cardcount == 0){
				printf("No dol files in memory card in slot %s\n\n", (slot==0?"A":"B"));
				waitA();
			}else{
				while (1){
					pressed = 0;
					VIDEO_ClearFrameBuffer (rmode, xfb, COLOR_BLACK);
					printf("\x1b[2;0H");
					printf("Memory Card Loader 0.1 by Suloku\n");
					printf("********************************\n\n");
					printf("Dol files in memory card %s: %d\n\n", (slot==0?"A":"B"), cardcount);
					
					if (listpos!=0) printf ("/\\/\\\n");
					else printf("    \n");
					
					for (i=listpos; i<listpos+10; i++){
						printf ("    ");
						if (i==listpos) printf ("-->");
						printf("%s                    \n",CardList[i].filename);
						if (i>= cardcount )break;
					}
					printf("\x1b[18;0H");
					if (cardcount >=10 && listpos != cardcount-1) printf ("\\/\\/\n");
					else{
						printf("    \n");
					}
					printf("\n\t\tPress B button to go back to slot select.\n\n");

					while (1){
						PAD_ScanPads();
						buttonsDown=PAD_ButtonsDown(0);
						if (buttonsDown & PAD_BUTTON_UP){
							listpos--;
							if (listpos <0) listpos = 0;
							pressed = 1;
						}
						if (buttonsDown & PAD_BUTTON_DOWN){
							listpos++;
							if (listpos >= cardcount-1) listpos = cardcount-1;
							pressed = 1;
						}
						if (buttonsDown & PAD_BUTTON_LEFT){
							listpos-=10;
							if (listpos <0) listpos = 0;
							pressed = 1;
						}
						if (buttonsDown & PAD_BUTTON_RIGHT){
							listpos+=10;
							if (listpos >= cardcount-1) listpos = cardcount-1;
							pressed = 1;
						}
						if (buttonsDown & PAD_BUTTON_A){
							printf("Loading %s...\n", CardList[listpos].filename);
							/*** Initialise for this company & gamecode ***/
							//add null char
							company[2] = gamecode[4] = 0;
							memcpy (company, &CardList[listpos].company, 2);
							memcpy (gamecode, &CardList[listpos].gamecode, 4);							
							CARD_SetCompany(company);
							CARD_SetGamecode(gamecode);
							CardError = CARD_Open(slot ,(char*)&CardList[listpos].filename,&CardFile);
							if (CardError < 0)
							{
									CARD_Unmount (slot);
									printf("Error %d while opening file.\n", CardError);
									waitA();
									
							}else{
								/*** Copy the file contents to the buffer ***/
								filesize = CardFile.len;
								u8 *dolbuffer = (u8*) memalign(32, filesize);
								while (bytesdone < filesize)
								{
										CardError= CARD_Read(&CardFile, dolbuffer+bytesdone, sectsize, bytesdone);
										bytesdone += sectsize;
								}
								CARD_Close(&CardFile);
								CARD_Unmount(slot);
							//boot dol
								//This will load cli_buffer and cli_size
								getclifrombuffer(dolbuffer, filesize);
								if (cli_buffer!=NULL){
									// Build a command line to pass to the DOL
									int argc2 = 0;
									char *argv2[1024];
									//add a terminating null character for last argument if needed
									if (cli_buffer[cli_size-1] != '\0'){
										cli_buffer[cli_size] = '\0';
										cli_size += 1;
									}

									// CLI parse
									char bootpath[CARD_FILENAMELEN+10];
									sprintf(bootpath, "mc%d:/%s", slot, (char*)&CardList[listpos].filename);
									argv2[argc2] = bootpath;
									argc2++;
									// First argument is at the beginning of the file
									if(cli_buffer[0] != '\r' && cli_buffer[0] != '\n') {
										argv2[argc2] = cli_buffer;
										argc2++;
									}
									// Search for the others after each newline
									int i;
									for(i = 0; i < cli_size; i++) {
										if(cli_buffer[i] == '\r' || cli_buffer[i] == '\n') {
											cli_buffer[i] = '\0';
										}
										else if(cli_buffer[i - 1] == '\0') {
											argv2[argc2] = cli_buffer + i;
											argc2++;

											if(argc2 >= 1024)
												break;
										}
									}
									DOLtoARAM(dolbuffer, argc2, argc2 == 0 ? NULL : argv2);
								}else{
									DOLtoARAM(dolbuffer, 0, NULL);
								}

								//If we get here dol was invalid
								if(dolbuffer != NULL) free(dolbuffer);
								printf("Not a valid dol file.\n");
								waitA();
								tomenu = 1;
							}
							pressed = 1;
						}
						if (buttonsDown & PAD_BUTTON_B){ pressed = 1;tomenu=1;}
						if (buttonsDown & PAD_BUTTON_START){ PSOreload();}
						VIDEO_WaitVSync();
						if (pressed) break;
					}
					if (tomenu) break;
				}
			}
			CARD_Unmount(slot);
		}else{
			printf("\n\nCan't mount card in slot %s!\n", (slot==0?"A":"B"));
			waitA();
		}
	}
	return 0;
}