Code: Select all
#include <pspkernel.h>
#include <pspdisplay.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <psppower.h>
#include <pspsdk.h>
PSP_MODULE_INFO("5.50 HEX Installer",0,1,1);
#define printf pspDebugScreenPrintf
//Sources & Destinations
#define sourcemoon "ms0:/PSP/GAME/5.50 HEX/sprx/moon.prx"
#define destinationmoon "flash0:/kd/moon.prx"
#define sourcepops "ms0:/PSP/GAME/5.50 HEX/sprx/pops.prx"
#define destinationpops "flash0:/kd/pops.prx"
#define sourcevshctrl "ms0:/PSP/GAME/5.50 HEX/sprx/vshctrl.prx"
#define destinationvshctrl "flash0:/kd/vshctrl.prx"
#define sourcerecovery "ms0:/PSP/GAME/5.50 HEX/sprx/recovery.prx"
#define destinationrecovery "flash0:/vsh/module/recovery.prx"
#define sourcesatelite "ms0:/PSP/GAME/5.50 HEX/sprx/satelite.prx"
#define destinationsatelite "flash0:/vsh/module/satelite.prx"
#define source1327 "ms0:/PSP/GAME/5.50 HEX/sprx/13-27.bmp"
#define destination1327 "flash0:/vsh/resource/13-27.bmp"
//Copy Paste flasher by Slasher
///// Globals /////
char buffer[8192];
///// Functions /////
void restart()
{
printf("Error...\n");
printf("Exiting\n");
sceKernelDelayThread(10*1000*300);
sceKernelExitGame();
}
// Cut & Paste Function
void flash_file(char *src, char *dst)
{
int bytesread, totalwritten = 0;
SceUID infd = sceIoOpen(src, PSP_O_RDONLY, 0777);
if (infd < 0)
{
// !!!!!!!!!!!!!!!!!!
//printf("Error. Please download updater again.\n");
// !!!!!!!!!!!!!!!!!!
// Error
restart();
}
// Remove the destination file
sceIoRemove(dst);
SceUID outfd = sceIoOpen(dst, PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777);
if (outfd < 0)
{
// !!!!!!!!!!!!!!!!!!
//printf("Error. Please download updater again.\n");
// !!!!!!!!!!!!!!!!!!
// Error
}
while ((bytesread = sceIoRead(infd, buffer, 8192)) > 0)
{
totalwritten += sceIoWrite(outfd, buffer, bytesread);
}
sceIoClose(infd);
sceIoClose(outfd);
sceIoRemove(src);
}
void flash()
{
int uas1, as1, errorCheck = 0;
uas1 = sceIoUnassign("flash0:");
if(uas1 < 0)
{
// Error
errorCheck = 1;
}
else
{
// Success
}
as1 = sceIoAssign("flash0:", "lflash0:0,0", "flashfat0:", 0, IOASSIGN_RDWR, 0);
if(as1 < 0)
{
// Error
errorCheck = 1;
}
else
{
// Success
}
// Critical moment.
if (errorCheck)
{
// Error
restart();
}
else
{
// Success!
// Flash!
flash_file( sourcemoon, destinationmoon );
flash_file( sourcepops, destinationpops );
flash_file( sourcevshctrl, destinationvshctrl );
flash_file( sourcerecovery, destinationrecovery );
flash_file( sourcesatelite, destinationsatelite );
flash_file( source1327, destination1327 );
}
// Arrived here. We should have everything flashed...
}
int checkFile(const char *filename)
{
SceUID file = sceIoOpen(filename, PSP_O_RDONLY, 0);
if (file < 0)
{
sceIoClose(file);
return 0;
}
else
{
sceIoClose(file);
return 1;
}
}
void CheckFileInPlace()
{
int errorCheck = 0;
if (!checkFile(source1327))
{
errorCheck = 1;
}
if (errorCheck)
{
printf("Please download the updater again.\n"
"Some files are corrupted."
"Auto-exiting program in 5 seconds.\n");
sceKernelDelayThread(10*1000*500);
sceKernelExitGame();
}
}
void CheckFileInPlace()
{
int errorCheck = 0;
if (!checkFile(sourcemoon))
{
errorCheck = 1;
}
if (errorCheck)
{
printf("Please download the updater again.\n"
"Some files are corrupted."
"Auto-exiting program in 5 seconds.\n");
sceKernelDelayThread(10*1000*500);
sceKernelExitGame();
}
}
void CheckFileInPlace()
{
int errorCheck = 0;
if (!checkFile(sourcepops))
{
errorCheck = 1;
}
if (errorCheck)
{
printf("Please download the updater again.\n"
"Some files are corrupted."
"Auto-exiting program in 5 seconds.\n");
sceKernelDelayThread(10*1000*500);
sceKernelExitGame();
}
}
void CheckFileInPlace()
{
int errorCheck = 0;
if (!checkFile(sourcevshctrl))
{
errorCheck = 1;
}
if (errorCheck)
{
printf("Please download the updater again.\n"
"Some files are corrupted."
"Auto-exiting program in 5 seconds.\n");
sceKernelDelayThread(10*1000*500);
sceKernelExitGame();
}
}
void CheckFileInPlace()
{
int errorCheck = 0;
if (!checkFile(sourcerecovery))
{
errorCheck = 1;
}
if (errorCheck)
{
printf("Please download the updater again.\n"
"Some files are corrupted."
"Auto-exiting program in 5 seconds.\n");
sceKernelDelayThread(10*1000*500);
sceKernelExitGame();
}
}
void CheckFileInPlace()
{
int errorCheck = 0;
if (!checkFile(sourcesatelite))
{
errorCheck = 1;
}
if (errorCheck)
{
printf("Please download the updater again.\n"
"Some files are corrupted."
"Auto-exiting program in 5 seconds.\n");
sceKernelDelayThread(10*1000*500);
sceKernelExitGame();
}
}
void CheckPowerOnline()
{
if (!scePowerIsPowerOnline())
{
printf("The AC adaptor is not connected.\n"
"Connect the AC adaptor and restart the updater.\n"
"Auto-exiting program in 5 seconds.\n");
sceKernelDelayThread(10*1000*500);
sceKernelExitGame();
}
}
///// Main /////
int main(int argc, char* argv[])
{
pspDebugScreenInit();
CheckFileInPlace();
CheckPowerOnline();
printf("Updating...\n");
sceKernelDelayThread(10*1000*300);
flash();
printf("Success!\n");
sceKernelDelayThread(10*1000*300);
printf("Exiting in 5 seconds...\n");
sceKernelDelayThread(5*1000*1000);
sceKernelExitGame();
return 0;
}