Exemple #1
0
extern  cfloat  *CFMul( cfloat *op1, cfloat *op2 ) {
/**************************************************/

    cfloat      *result;
    cfloat      *temp;
    cfloat      *sum;
    int         op1left;
    int         op1exp;
    int         op2exp;
    int         op2ptr;
    int         sgn;

    sgn = op1->sign * op2->sign;
    result = CFAlloc( 1 );
    if( sgn != 0 ) {
        op1left = op1->exp;
        op1exp = op1left - op1->len + 1;
        op2exp = op2->exp - op2->len + 1;
        op2ptr = op2->len - 1;
        while( op2ptr >= 0 ) {
            temp = SDMul( op1, CFAccess( op2, op2ptr-- ),
                op1left, op1exp, op2exp++ );
            sum = CFAdd( result, temp );
            CFFree( temp );
            CFFree( result );
            result = sum;
        }
        result->sign = sgn;
    }
    return( result );
}
Exemple #2
0
bool getCoverFromServer(char* url, char* imgPath, int v, int max){

	struct block file;
	char* pch;

	sprintf(self.debugMsg, TX.getting, url);
	Paint_Progress_Generic(v, max,self.debugMsg);

	file = downloadfile(url);

	if(file.data != NULL && file.size >= 4000){
	    char* msg = CFMalloc(20*sizeof(char));
	    strncpy(msg, (char*)file.data,20);
	    pch = strtok(msg, " ");
	    if(strcmp(pch,"<!DOCTYPE")==0) //test for a bad file
	     {
		   CFFree(msg);
		   CFFree(file.data);
		   return false;
	     }  
	    CFFree(msg);
	    unlink(imgPath);
 		saveFile(imgPath, file);
		CFFree(file.data);
		sprintf(self.debugMsg, TX.done );
		Paint_Progress_Generic(v, max,self.debugMsg);
		return true;
	}
	
	return false;
}
Exemple #3
0
void LoadCurrentCover(int id, struct discHdr *gameList)
{
	#ifndef TEST_MODE
	void *imgData;// = (void *)no_cover_png;

	char filepath[128];
	char titleID[7];

	s32  ret;
	struct discHdr *header = &gameList[id];

	//sprintf(filepath, USBLOADER_PATH "/disks/%c%c%c%c%c%c.png", header->id[0],header->id[1],header->id[2],header->id[3],header->id[4],header->id[5]);
	sprintf(filepath, "%s/%c%c%c%c%c%c.png", dynPath.dir_disks, header->id[0],header->id[1],header->id[2],header->id[3],header->id[4],header->id[5]);

	ret = Fat_ReadFile(filepath, &imgData);
	
	sprintf(titleID, "%s", header->id);
	getGameSettings(titleID, &gameSetting);
	
	if (ret > 0)
	{
		BufferImageToSlot(&current_cover_texture,(const unsigned char*)imgData,10);

		CFFree(imgData);
	}
	else
	{
		//sprintf(filepath, USBLOADER_PATH "/disks/%c%c%c%c%c%c.png", header->id[0],header->id[1],header->id[2], header->id[3],header->id[4],header->id[5]);
		sprintf(filepath, "%s/%c%c%c%c%c%c.png", dynPath.dir_disks, header->id[0],header->id[1],header->id[2], header->id[3],header->id[4],header->id[5]);

		ret = Fat_ReadFile(filepath, &imgData);
		
		if (ret > 0)
		{
			BufferImageToSlot(&current_cover_texture,(const unsigned char*)imgData,10);
			CFFree(imgData);
		}
		else
		{
			BufferImageToSlot(&current_cover_texture,no_disc_png,10);
		}
	}
	
	#else
	BufferImageToSlot(&current_cover_texture,no_disc_png,10);
	#endif
}
Exemple #4
0
cfloat  *CFInverse( cfloat *op ) {
/********************************/

    cfloat      *one;
    cfloat      *result;

    one = CFCnvI32F( 1 );
    result = CFDiv( one, op );
    CFFree( one );
    return( result );
}
void CFThreadNotifyDestroy(CFThreadNotify* ntf)
{
    ERR_DEL_RD_EVT:
    CFFdeventsDel(ntf->evts, ntf->rdEvt);
ERR_DESTY_RD_EVT:
    CFFdeventFree(ntf->rdEvt);
ERR_CLOSE_PIPE:
    close(ntf->pipeFd[0]);
    close(ntf->pipeFd[1]);
ERR_FREE_NTF:
    CFFree(ntf);
}
Exemple #6
0
//boot HBC in either HAXX or JODI locations
//this function expects WII_Initialize() be called before it is called
s32 WII_BootHBC()
{
	u32 tmdsize;
	u64 tid = 0;
	u64 *list;
	u32 titlecount;
	s32 ret;
	u32 i;

	ret = ES_GetNumTitles(&titlecount);
	if(ret < 0)
		return WII_EINTERNAL;

	list = CFMemAlign(32, titlecount * sizeof(u64) + 32);

	ret = ES_GetTitles(list, titlecount);
	if(ret < 0) {
		CFFree(list);
		return WII_EINTERNAL;
	}
	
	for(i=0; i<titlecount; i++) {
		if (list[i]==TITLE_ID(0x00010001,0x4A4F4449) || list[i]==TITLE_ID(0x00010001,0x48415858) || list[i]==TITLE_ID(0x00010001,0xaf1bf516))
		{
			tid = list[i];
			break;
		}
	}
	CFFree(list);

	if(!tid)
		return WII_EINSTALL;

	if(ES_GetStoredTMDSize(tid, &tmdsize) < 0)
		return WII_EINSTALL;

	return WII_LaunchTitle(tid);
}
Exemple #7
0
bool downloadTitles(){
	//WindowPrompt(TX.error, "Error initializing network\nTitles.txt can't be downloaded.", &okButton, 0);
	char titlesPath[100];
	struct block file;
	
	//snprintf(titlesPath, sizeof(titlesPath), "%s/titles.txt", USBLOADER_PATH);
	snprintf(titlesPath, sizeof(titlesPath), "%s/titles.txt", dynPath.dir_usb_loader);
	
	//file = downloadfile("http://www.wiiboxart.com/titles.txt");
	file = downloadfile("http://wiitdb.com/titles.txt");
	if(file.data != NULL){
		
                char* pch;
                char* msg = CFMalloc(20*sizeof(char));
                strncpy(msg, (char*)file.data,20);
                pch = strtok(msg, " ");
                if(strcmp(pch,"<!DOCTYPE")==0) //test for a bad file
                {
                    CFFree(msg);
                    CFFree(file.data);
                    return false;
                }
                CFFree(msg);
                unlink(titlesPath);
                if(saveFile(titlesPath, file))
                {
                        CFFree(file.data);
                        return true;
                }
                else{
                    CFFree(file.data);
                    return false;
                }
        }
    return false;
}
CFThreadNotify* CFThreadNotifyNew(CFThreadNotifyCb cb, void* userData, CFFdevents* evts)
{
    CFThreadNotify* ntf;
    
    if (!(ntf = CFMalloc(sizeof(CFThreadNotify)))) {
        LCF_ERR_OUT(ERR_OUT, "out of memory\n");
    }
    
    ntf->evts = evts;
    ntf->userData = userData;
    ntf->cb = cb;
    
    if (pipe2(ntf->pipeFd, O_NONBLOCK|O_CLOEXEC)) {
        LCF_ERR_OUT(ERR_FREE_NTF, "pipe2() failed\n");
    }
    
    if (!(ntf->rdEvt = CFFdeventNew(ntf->pipeFd[0], "ThreadNotifyRdEvt",
            ThreadNotifyReadable, ntf, NULL, NULL, NULL, NULL))) {
        LCF_ERR_OUT(ERR_CLOSE_PIPE, "CFFdeventNew() failed\n");
    }
    
    if (CFFdeventsAdd(evts, ntf->rdEvt)) {
        LCF_ERR_OUT(ERR_DESTY_RD_EVT, "CFFdeventsAdd() failed\n");
    }
    
    return ntf;
    
ERR_DEL_RD_EVT:
    CFFdeventsDel(evts, ntf->rdEvt);
ERR_DESTY_RD_EVT:
    CFFdeventFree(ntf->rdEvt);
ERR_CLOSE_PIPE:
    close(ntf->pipeFd[0]);
    close(ntf->pipeFd[1]);
ERR_FREE_NTF:
    CFFree(ntf);
ERR_OUT:
    return NULL;
}
Exemple #9
0
bool Load_Dol(void **buffer, int* dollen, char * filepath)
{
	int ret;
	FILE* file;
	void* dol_buffer;

	char fullpath[200];
	char gameidbuffer6[7];
	memset(gameidbuffer6, 0, 7);
	memcpy(gameidbuffer6, (char*)0x80000000, 6);
	snprintf(fullpath, 200, "%s/%s.dol", filepath, gameidbuffer6);

    SDCard_Init();
    USBDevice_Init();

	file = fopen(fullpath, "rb");

	if(file == NULL)
	{
#ifdef DEBTXT_ALTDOL
		DebTxt(".dol is missing");
#endif
		fclose(file);
	    SDCard_deInit();
	    USBDevice_deInit();
		return false;
	}


	ClearAllocatedMemory();

	int filesize;
	fseek(file, 0, SEEK_END);
	filesize = ftell(file);
	fseek(file, 0, SEEK_SET);

#ifdef LOUDTEST
	dol_buffer = (void *) MEM2_START_ADDRESS; //safest
#else
	dol_buffer = CFMalloc(filesize);
#endif
	if (dol_buffer == NULL)
	{
#ifdef DEBTXT_ALTDOL
		char dbg[80];
		DebTxt("Out of memory");
		sprintf(dbg,"%s  %d", gameidbuffer6, filesize);
		DebTxt(dbg);
#endif
		fclose(file);
	    SDCard_deInit();
	    USBDevice_deInit();
		return false;
	}
	ret = fread( dol_buffer, 1, filesize, file);
	if(ret != filesize)
	{
#ifdef DEBTXT_ALTDOL
		DebTxt("Error reading dol header");
#endif
#ifndef LOUDTEST
		CFFree(dol_buffer);
#endif
		fclose(file);
	    SDCard_deInit();
	    USBDevice_deInit();
		return false;
	}
	fclose(file);
#ifdef DEBTXT_ALTDOL
	DebTxt("dol header in buffer");
#endif
	SDCard_deInit();
    USBDevice_deInit();
	*buffer = dol_buffer;
	*dollen = filesize;
	return true;
}
Exemple #10
0
/**
 * Downloads the contents of a URL to memory
 * This method is not threadsafe (because networking is not threadsafe on the Wii)
 */
struct block downloadfile(const char *url)
{
        //Check if the url starts with "http://", if not it is not considered a valid url
	if(strncmp(url, "http://", strlen("http://")) != 0)
	{
		sprintf(emptyblock.error,TX.URLnoBegin, url); //doen't start with http://
		return emptyblock;
	}
	
	//Locate the path part of the url by searching for '/' past "http://"
	char *path = strchr(url + strlen("http://"), '/');
	
	//At the very least the url has to end with '/', ending with just a domain is invalid
	if(path == NULL)
	{
		sprintf(emptyblock.error,TX.URLnoPath, url); //no path part in URL
		return emptyblock;
	}
	
	//Extract the domain part out of the url
	int domainlength = path - url - strlen("http://");
	
	if(domainlength == 0)
	{
		sprintf(emptyblock.error,TX.URLnoDomain, url); //couldn't find a domain in url
		return emptyblock;
	}
	
	char domain[domainlength + 1];
	strncpy(domain, url + strlen("http://"), domainlength);
	domain[domainlength] = '\0';
	
	//Parsing of the URL is done, start making an actual connection
	u32 ipaddress = getipbyname(domain); //slower but doesn't leak memory
	
	if(ipaddress == 0)
	{
		sprintf(emptyblock.error,TX.errorDomain, domain); //couldn't resolve domain
		return emptyblock;
	}


	s32 connection = server_connect(ipaddress, 80);
	
	if(connection < 0) {
		sprintf(emptyblock.error,TX.errEstablishConn); //couldn't establish connection
		return emptyblock;
	}
	
	//Form a nice request header to send to the webserver
	char* headerformat = "GET %s HTTP/1.0\r\nHost: %s\r\nUser-Agent: WiiEarthh 1.0\r\n\r\n";;
	char header[strlen(headerformat) + strlen(domain) + strlen(path)];
	sprintf(header, headerformat, path, domain);

	//Do the request and get the response
	send_message(connection, header);
	struct block response = read_message(connection);
	net_close(connection);

	//Search for the 4-character sequence \r\n\r\n in the response which signals the start of the http payload (file)
	unsigned char *filestart = NULL;
	u32 filesize = 0;
	int i;
	for(i = 3; i < response.size; i++)
	{
		if(response.data[i] == '\n' &&
			response.data[i-1] == '\r' &&
			response.data[i-2] == '\n' &&
			response.data[i-3] == '\r')
		{
			filestart = response.data + i + 1;
			filesize = response.size - i - 1;
			break;
		}
	}
	
	if(filestart == NULL)
	{
		sprintf(emptyblock.error,TX.HTTPnoFile);
		return emptyblock;
	}
	
	//Copy the file part of the response into a new memoryblock to return
	struct block file;
	file.data = CFMalloc(filesize);
	file.size = filesize;
	
	if(file.data == NULL)
	{
		sprintf(emptyblock.error,TX.noMemCopy ); //couldn't copy the file to the block
		CFFree(response.data);
		return emptyblock;
	}
	
	memcpy(file.data, filestart, filesize);

	//Dispose of the original response
	CFFree(response.data);
	
	return file;
}
Exemple #11
0
void FreeButton3Resources(struct Button3 *btn)
{
	if (btn->toFreeTexture) 		CFFree(btn->texture.data);
	if (btn->toFreeHoverTexture) 	CFFree(btn->hoverTexture.data);
	if (btn->toFreeTriStateTexture)	CFFree(btn->TriStateTexture.data);
}