Exemplo n.º 1
0
u32 Load_Dol_from_disc(u32 doloffset)
{
	int ret;
	void *dol_header;
	u32 entrypoint;

	dol_header = memalign(32, sizeof(dolheader));
	if (dol_header == NULL)
	{
#ifdef DEBTXT_ALTDOL
		DebTxt("Out of memory");
#endif		
		return -1;
	}

	ret = WDVD_Read(dol_header, sizeof(dolheader), (doloffset<<2));

	entrypoint = load_dol_start(dol_header);

	if (entrypoint == 0)
	{
#ifdef DEBTXT_ALTDOL
		DebTxt("entrypoint = 0");
#endif
		free(dol_header);
		return -1;
	}

	void *offset;
	u32 pos;
	u32 len;

	while (load_dol_image_modified(&offset, &pos, &len))
	{
		if (len != 0)
		{
			ret = WDVD_Read(offset, len, (doloffset<<2) + pos);

            DCFlushRange(offset, len);

			gamepatches(offset, len );

            DCFlushRange(offset, len);

			Remove_001_Protection(offset, len);
		}
	}

	free(dol_header);

	return entrypoint;
}
Exemplo n.º 2
0
s32 Apploader_Run(entry_point *entry, u8 cheat, u8 videoSelected, u8 vipatch, u8 patchcountrystring, u8 error002fix, u8 alternatedol, u32 alternatedoloffset) {
    app_entry appldr_entry;
    app_init  appldr_init;
    app_main  appldr_main;
    app_final appldr_final;

    u32 appldr_len;
    s32 ret;
    gprintf("\nApploader_Run() started\n");

    //u32 geckoattached = usb_isgeckoalive(EXI_CHANNEL_1);
    //if (geckoattached)usb_flush(EXI_CHANNEL_1);
    geckoinit = InitGecko();

    /* Read apploader header */
    ret = WDVD_Read(buffer, 0x20, APPLDR_OFFSET);
    if (ret < 0)
        return ret;

    /* Calculate apploader length */
    appldr_len = buffer[5] + buffer[6];

    /* Read apploader code */
    ret = WDVD_Read(appldr, appldr_len, APPLDR_OFFSET + 0x20);
    if (ret < 0)
        return ret;

    /* Set apploader entry function */
    appldr_entry = (app_entry)buffer[4];

    /* Call apploader entry */
    appldr_entry(&appldr_init, &appldr_main, &appldr_final);

    /* Initialize apploader */
    appldr_init(__noprint);

    if (error002fix!=0)
    {
        /* ERROR 002 fix (thanks to WiiPower for sharing this)*/
        *(u32 *)0x80003188 = *(u32 *)0x80003140;
    }

    for (;;)
    {
        void *dst = NULL;
        int len = 0, offset = 0;

        /* Run apploader main function */
        ret = appldr_main(&dst, &len, &offset);
        if (!ret)
            break;

        /* Read data from DVD */
        WDVD_Read(dst, len, (u64)(offset << 2));

        gamepatches(dst, len, videoSelected, patchcountrystring, vipatch, cheat);
        DCFlushRange(dst, len);
    }

    *entry = appldr_final();

    /** Load alternate dol if set **/
    if (alternatedol == 1)
    {
        wip_reset_counter();
        void *dolbuffer = NULL;
        int dollen = 0;

        bool dolloaded = Load_Dol(&dolbuffer, &dollen, Settings.dolpath, videoSelected, patchcountrystring, vipatch, cheat);
        if (dolloaded)
        {
            *entry = (entry_point) load_dol_image(dolbuffer);
        }

        if(dolbuffer)
            free(dolbuffer);
    }
    else if (alternatedol == 2)
    {
        wip_reset_counter();
        FST_ENTRY *fst = (FST_ENTRY *)*(u32 *)0x80000038;

        *entry = (entry_point) Load_Dol_from_disc(fst[alternatedoloffset].fileoffset, videoSelected, patchcountrystring, vipatch, cheat);

        if (*entry == 0)
            SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
    }

    return 0;
}