Code: Select all
#include <pspkernel.h>
#include <pspctrl.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <string.h>
PSP_MODULE_INFO("menreplace", 0, 1, 1);
#define printf pspDebugScreenPrintf
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common)
{
        sceKernelExitGame();
        return 0;
}
/* Callback thread */
int CallbackThread(SceSize args, void *argp)
{
        int cbid;
        cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
        sceKernelRegisterExitCallback(cbid);
        sceKernelSleepThreadCB();
        return 0;
}
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void)
{
        int thid = 0;
        thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
        if(thid >= 0)
        {
                sceKernelStartThread(thid, 0, 0);
        }
        return thid;
}
/* Build a path, append a directory slash if requested */
void build_path(char *output, const char *root, const char *path, int append)
{
        while(*root != 0)
        {
                *output++ = *root++;
        }
        if(*(root-1) != '/')
        {
                *output++ = '/';
        }
        while(*path != 0)
        {
                *output++ = *path++;
        }
        if(append)
                *output++ = '/';
        *output++ = 0;
}
/* Define a write buffer */
char write_buffer[128*1024];
void write_file(const char *read_loc, const char *write_loc, const char *name)
{
        int fdin;
        int fdout;
        char readpath[256];
        char writepath[256];
        build_path(readpath, read_loc, name, 0);
        build_path(writepath, write_loc, name, 0);
        printf("Writing %s\n", writepath);
        fdin = sceIoOpen(readpath, PSP_O_RDONLY, 0777);
        if(fdin >= 0)
        {
                int bytesRead = 1;
                fdout = sceIoOpen(writepath, PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777);
                if(fdout < 0)
                {
                        printf("Couldn't open %s\n", writepath);
                }
                bytesRead = sceIoRead(fdin, write_buffer, sizeof(write_buffer));
                while((bytesRead > 0) && (fdout >= 0))
                {
                        sceIoWrite(fdout, write_buffer, bytesRead);
                        bytesRead = sceIoRead(fdin, write_buffer, sizeof(write_buffer));
                }
                if(fdout >= 0)
                {
                        sceIoClose(fdout);
                }
                if(fdin >= 0)
                {
                        sceIoClose(fdin);
                }
        }
        else
        {
                printf("Couldn't open %s\n", readpath);
        }
}
void writethefileyo(void)
{
        int fd;
         fd = sceIoOpen("ms0:/topmenu_plugin.rco", PSP_O_RDONLY, 0777);
        if(fd >= 0)
        {
                char men_id[17];
                char path[256];
                sceIoRead(fd, men_id, 16);
                sceIoClose(fd);
                game_id[16] = 0;
                build_path(path, "flash0:/vsh/resource/", NULL, 0);
                printf("Found Top Menu, Writing... %s\n", men_id);
                write_file("ms0:/", path, "topmenu_plugin.rco");
        }
}
void show_menu(void)
{
 printf("psp top menu replacement tool - by callum bethune");
 printf("press [x] to continue/n");
}
int main(void)
{
        SceCtrlData pad_data;
        pspDebugScreenSetBackColor(0xFFFFFFFF);
        pspDebugScreenSetTextColor(0);
        pspDebugScreenInit();
        SetupCallbacks();
        sceCtrlSetSamplingCycle(0);
        sceCtrlSetSamplingMode(1);
        show_menu();
        for(;;)
        {
                sceCtrlReadBufferPositive(&pad_data, 1);
                if(pad_data.Buttons & PSP_CTRL_CROSS)
                {
                        writethefileyo();
                        pspDebugScreenClear();
                        printf("finished thank you for using!\n");
                        show_menu();
                }
                sceDisplayWaitVblankStart();
        }
        return 0;
}
can some one tell me if that works
i know it compiles but i dont wanna f up my psp
