Exemplo n.º 1
0
int state_save(int slot)
{
	SceUID fd = -1;
	pspTime nowtime;
	char path[MAX_PATH];
	char error_mes[128];
	char buf[128];
#if (EMU_SYSTEM == NCDZ)
	UINT8 *inbuf, *outbuf;
	unsigned long insize, outsize;
#else
#ifndef ADHOC
	UINT8 *state_buffer_base;
#endif
	UINT32 size;
#endif

	sprintf(path, "%sstate/%s.sv%d", launchDir, game_name, slot);
	sceIoRemove(path);

	sprintf(buf, TEXT(STATE_SAVING), game_name, slot);
	init_progress(6, buf);

	sceRtcGetCurrentClockLocalTime(&nowtime);

	if ((fd = sceIoOpen(path, PSP_O_WRONLY|PSP_O_CREAT, 0777)) >= 0)
#if (EMU_SYSTEM == NCDZ)
	{
		if ((inbuf = memalign(MEM_ALIGN, STATE_BUFFER_SIZE)) == NULL)
		{
			strcpy(error_mes, TEXT(COULD_NOT_ALLOCATE_STATE_BUFFER));
			goto error;
		}
		memset(inbuf, 0, STATE_BUFFER_SIZE);
		state_buffer = inbuf;

		state_save_byte(current_version_str, 8);
		state_save_byte(&nowtime, 16);
		update_progress();

		save_thumbnail();
		update_progress();

		sceIoWrite(fd, inbuf, (UINT32)state_buffer - (UINT32)inbuf);
		update_progress();

		memset(inbuf, 0, STATE_BUFFER_SIZE);
		state_buffer = inbuf;

		state_save_memory();
		state_save_m68000();
		state_save_z80();
		state_save_input();
		state_save_timer();
		state_save_driver();
		state_save_video();
		state_save_ym2610();
		state_save_cdda();
		state_save_cdrom();
		update_progress();

		insize = (UINT32)state_buffer - (UINT32)inbuf;
		outsize = insize * 1.1 + 12;
		if ((outbuf = memalign(MEM_ALIGN, outsize)) == NULL)
		{
			strcpy(error_mes, TEXT(COULD_NOT_ALLOCATE_STATE_BUFFER));
			free(inbuf);
			goto error;
		}
		memset(outbuf, 0, outsize);

		if (compress(outbuf, &outsize, inbuf, insize) != Z_OK)
		{
			strcpy(error_mes, TEXT(COULD_NOT_COMPRESS_STATE_DATA));
			free(inbuf);
			free(outbuf);
			goto error;
		}
		free(inbuf);
		update_progress();

		sceIoWrite(fd, &outsize, 4);
		sceIoWrite(fd, outbuf, outsize);
		sceIoClose(fd);
		free(outbuf);
		update_progress();

		show_progress(buf);
		return 1;
	}
#else
	{
#ifdef ADHOC
		state_buffer = state_buffer_base;
#else
#if (EMU_SYSTEM == CPS1 || (EMU_SYSTEM == CPS2 && defined(PSP_SLIM)))
		state_buffer = state_buffer_base = memalign(MEM_ALIGN, STATE_BUFFER_SIZE);
#else
		state_buffer = state_buffer_base = cache_alloc_state_buffer(STATE_BUFFER_SIZE);
#endif
		if (!state_buffer)
		{
			strcpy(error_mes, TEXT(COULD_NOT_ALLOCATE_STATE_BUFFER));
			goto error;
		}
#endif
		memset(state_buffer, 0, STATE_BUFFER_SIZE);
		update_progress();

		state_save_byte(current_version_str, 8);
		state_save_byte(&nowtime, 16);
		update_progress();

		save_thumbnail();
		update_progress();

		state_save_memory();
		state_save_m68000();
		state_save_z80();
		state_save_input();
		state_save_timer();
		state_save_driver();
		state_save_video();
#if (EMU_SYSTEM == CPS1)
		state_save_coin();
		switch (machine_driver_type)
		{
		case MACHINE_qsound:
			state_save_qsound();
			state_save_eeprom();
			break;

		case MACHINE_pang3:
			state_save_eeprom();

		default:
			state_save_ym2151();
			break;
		}
#elif (EMU_SYSTEM == CPS2)
		state_save_coin();
		state_save_qsound();
		state_save_eeprom();
#elif (EMU_SYSTEM == MVS)
		state_save_ym2610();
		state_save_pd4990a();
#endif
		update_progress();

		size = (UINT32)state_buffer - (UINT32)state_buffer_base;
		sceIoWrite(fd, state_buffer_base, size);
		sceIoClose(fd);
		update_progress();

#ifndef ADHOC
#if (EMU_SYSTEM == CPS1 || (EMU_SYSTEM == CPS2 && defined(PSP_SLIM)))
		free(state_buffer_base);
#else
		cache_free_state_buffer(STATE_BUFFER_SIZE);
#endif
#endif
		update_progress();

		show_progress(buf);
		return 1;
	}
#endif
	else
	{
Exemplo n.º 2
0
void MOD_SelectModMenu(char *basedir){

	SceCtrlData pad, oldpad;
	sceCtrlPeekBufferPositive(0, &pad, 1);

	// Ch0wW: Enable the mod menu once the R trigger is hold on startup.
	if (!(pad.buttons & SCE_CTRL_RTRIGGER))
	{
		// Reading current used mod
		char cur_mod[64];
		modname = malloc(64);
		FILE* f;
		if ((f = fopen( va("%s/%s", basedir, MOD_FILE), "r")) != NULL) {
			char tmp[256];
			fseek(f, 0, SEEK_END);
			int len = ftell(f);
			fseek(f, 0, SEEK_SET);
			fread(tmp, 1, len, f);
			fclose(f);
			tmp[len] = 0;
			sprintf(modname, "%s", tmp);
		}
		else
			modname = NULL;
		return;
	}

	// Initializing empty ModList
	ModsList* mods = NULL;
	int i = 0;
	int max_idx = -1;
	
	// Scanning main folder in search of mods
	int dd = sceIoDopen(basedir);
	SceIoDirent entry;
	int res;
	while (sceIoDread(dd, &entry) > 0){
		if (SCE_S_ISDIR(entry.d_stat.st_mode)){
			if (CheckForMod( va("%s/%s", basedir, entry.d_name))){
				mods = addMod(entry.d_name, mods);
				max_idx++;
			}
		}
	}
	sceIoDclose(dd);
	
	// Reading current used mod
	char cur_mod[64];
	modname = malloc(64);
	FILE* f;
	if ((f = fopen(va("%s/%s", basedir, MOD_FILE), "r")) != NULL) {
		char tmp[256];
		fseek(f, 0, SEEK_END);
		int len = ftell(f);
		fseek(f, 0, SEEK_SET);
		fread(tmp, 1, len, f);
		fclose(f);
		tmp[len] = 0;
		sprintf(modname, "%s", tmp);
		sprintf(cur_mod, "Current in use mod: %s - Press START to launch vitaQuake core", tmp);
	}else strcpy(cur_mod,"Current in use mod: id1 - Press START to launch vitaQuake core");
	
	// Initializing graphics stuffs
	vita2d_set_clear_color(RGBA8(0x00, 0x00, 0x00, 0xFF));
	vita2d_pgf* debug_font = vita2d_load_default_pgf();
	uint32_t white = RGBA8(0xFF, 0xFF, 0xFF, 0xFF);
	uint32_t green = RGBA8(0x00, 0xFF, 0x00, 0xFF);
	uint32_t red = RGBA8(0xFF, 0x00, 0x00, 0xFF);
	
	// Main loop
	while (max_idx >= 0){
		vita2d_start_drawing();
		vita2d_clear_screen();
		vita2d_pgf_draw_text(debug_font, 2, 20, red, 1.0, cur_mod);
		
		// Drawing menu
		int y = 40;
		int d = 0;
		ModsList* ptr = mods;
		while (ptr != NULL && y < 540){
			uint32_t color = white;
			if (d++ == i) color = green;
			vita2d_pgf_draw_text(debug_font, 2, y, color, 1.0, ptr->name);
			ptr = ptr->next;
			y += 20;
		}
		
		// Controls checking
		sceCtrlPeekBufferPositive(0, &pad, 1);
		if ((pad.buttons & SCE_CTRL_CROSS) && (!(oldpad.buttons & SCE_CTRL_CROSS))){
			int z = 0;
			ModsList* tmp = mods;
			while (z < i){
				tmp = tmp->next;
				z++;
			}
			sprintf(cur_mod,"Current in use mod: %s - Press START to launch vitaQuake core", tmp->name);
			if (!strcmp(tmp->name, "id1"))
			{
				sceIoRemove( va("%s/%s", basedir, MOD_FILE) );
				modname = NULL;
			}
			else{
				f = fopen(va("%s/%s", basedir, MOD_FILE), "w");
				fwrite(tmp->name,1,strlen(tmp->name),f);
				fclose(f);
				strcpy(modname, tmp->name);	// Refresh the mod directory.
			}
		}else if ((pad.buttons & SCE_CTRL_UP) && (!(oldpad.buttons & SCE_CTRL_UP))){
			i--;
			if (i < 0) i = max_idx;
		}else if ((pad.buttons & SCE_CTRL_DOWN) && (!(oldpad.buttons & SCE_CTRL_DOWN))){
			i++;
			if (i > max_idx) i = 0;
		}else if (pad.buttons & SCE_CTRL_START) break;
		oldpad = pad;
		
		vita2d_end_drawing();
		vita2d_wait_rendering_done();
		vita2d_swap_buffers();
	}
	
	// Freeing stuffs
	ModsList* tmp = mods;
	ModsList* tmp2;
	while (tmp != NULL){
		tmp2 = tmp->next;
		free(tmp);
		tmp = tmp2;
	}

	return;
}
Exemplo n.º 3
0
Arquivo: ctf.c Projeto: ErikPshat/cxmb
int makeCxmbThemeFile( unsigned int cxmb_magic, const char * cxmb_theme_file )
{
	const char * folders_name[] = {
		"/data/cert",
		"/dic",
		"/font",
		"/kd",
		"/kd/resource",
		"/vsh/etc",
		"/vsh/module",
		"/vsh/resource"
	};
	int folders_count = 8;
	const char * support_exts[] = {
		".prx",
		".rco",
		".bmp",
		".pmf",
		".res",
		".pgf",
		".bwfon",
		".rsc",
		".dat",
		".img",
		".bin",
		".cet",
		".dic"
	};
	int exts_count = 13;
	int dfd, heap_id, fd, i, bytes, file_count = 0;
	unsigned int ptf_h[5];
	char path[128], file[128], preview[64];
	u8 * buf;
	// dectect if theme file in conf exist
	int ctf = sceIoOpen( cxmb_theme_file, PSP_O_RDONLY, 0644 );
	if ( ctf >= 0 )
	{
		log( "theme file exist!\n" );
		sceIoClose( ctf );
		return 0;
	}

	dfd = sceIoDopen( "ms0:/cxmb" );
	if ( dfd < 0 )
	{
		log( "no cxmb folder found!\n" );
		return 0;
	}
	sceIoDclose( dfd );

	sprintf( preview, "ms0:/cxmb%s", &cxmb_theme_file[14] );
	preview[strlen( preview ) - 3] = 'p';
	log( "preview: %s\n", preview );
	fd = sceIoOpen( preview, PSP_O_RDONLY, 0644 );
	if ( fd < 0 )
	{
		log( "no preview ptf file found!\n" );
		return 0;
	}
	sceIoLseek( fd, 0x100, PSP_SEEK_SET );
	sceIoRead( fd, ptf_h, 20 );

	// create CXMB_MKCTF_BUF_SIZE + 32kb heap
	heap_id = sceKernelCreateHeap( 2, CXMB_MKCTF_BUF_SIZE + 1024 * 32 , 1, "cxmb_tmp_heap");
	if ( heap_id < 0 )
	{
		log( "failed in create heap in making cxmb theme file!\n" );
		return -1;
	}

	CtfHeader * ch = ( CtfHeader * )sceKernelAllocHeapMemory( heap_id, sizeof( CtfHeader ) * 64 );
	memset( ch, 0, sizeof( CtfHeader ) * 64 );
	SceIoDirent * ent = ( SceIoDirent * )sceKernelAllocHeapMemory( heap_id, sizeof( SceIoDirent ) );
	memset( ent, 0, sizeof( SceIoDirent ) );

	sceIoMkdir( "ms0:/PSP/THEME", 0777 );
	ctf = sceIoOpen( cxmb_theme_file, PSP_O_RDWR | PSP_O_CREAT | PSP_O_TRUNC, 0777 );
	if ( ctf < 0 )
	{
		log( "failed in opening %s\n", cxmb_theme_file );
		sceKernelFreeHeapMemory( heap_id, ent );
		sceKernelFreeHeapMemory( heap_id, ch );
		sceKernelDeleteHeap( heap_id );
		return -1;
	}
	else
	{
		if ( ptf_h[2] == 0 )
			ptf_h[2] = sceIoLseek( fd, 0, PSP_SEEK_END );
		log( "ptf sections size %08x\n", ptf_h[2] );
		buf = sceKernelAllocHeapMemory( heap_id, ptf_h[2] );
		if ( buf )
		{
			sceIoLseek( fd, 0, PSP_SEEK_SET );
			sceIoRead( fd, buf, ptf_h[2] );
			sceIoWrite( ctf, buf, ptf_h[2] );
			sceIoClose( fd );
			sceKernelFreeHeapMemory( heap_id, buf );

			sceIoLseek( ctf, 0x10, PSP_SEEK_SET );
			sceIoWrite( ctf, &cxmb_magic, 4 );
			sceIoLseek( ctf, 0x1C, PSP_SEEK_SET );
			sceIoWrite( ctf, &ptf_h[2], 4 );

			memset( &ptf_h[2], 0, 12 );
			sceIoLseek( ctf, 0x100, PSP_SEEK_SET );
			sceIoWrite( ctf, ptf_h, 20 );
			sceIoLseek( ctf, 0, PSP_SEEK_END );

			for ( i = 0; i < folders_count; i ++ )
			{
				sprintf( path, "ms0:/cxmb%s", folders_name[i] );
				dfd = sceIoDopen( path );
				if ( dfd < 0 )
				{
					log( "folder %s not found!\n", path );
					continue;
				}
				log( "parsing %s\n", path );
				while ( sceIoDread( dfd, ent ) > 0 )
				{
					log( "found %s\n", ent->d_name );
					if ( ( ent->d_stat.st_attr & FIO_SO_IFDIR ) || ent->d_name[0] == '.' )
					{
						log( "ignore %s\n", ent->d_name );
						continue;
					}
					if ( endwithistrs( ent->d_name, support_exts, exts_count ) )
					{
						sprintf( file, "%s/%s", path, ent->d_name );
						sprintf( ch[file_count].name, "%s/%s", folders_name[i], ent->d_name );
						ch[file_count].start = sceIoLseek( ctf, 0, PSP_SEEK_CUR );
						ch[file_count].size = 0;
						if ( cmpistrs( ent->d_name, diff_files, diff_count ) )
						{
							char ori_file[128];
							sprintf( ori_file, "%s/%s", CXMB_SUPPORT_FOLDER, ent->d_name );
							ch[file_count].size = makeDiff( file, ori_file, heap_id, ctf );
						}
						else
						{
							log( "dealing with %s\n", ent->d_name );
							fd = sceIoOpen( file, PSP_O_RDONLY, 0644 );
							if ( fd < 0 )
							{
								log( "failed in opening %s\n", file );
								continue;
							}
							buf = ( u8 * )sceKernelAllocHeapMemory( heap_id, CXMB_MKCTF_BUF_SIZE );
							bytes = sceIoRead( fd, buf, CXMB_MKCTF_BUF_SIZE );
							while( bytes > 0 )
							{
								ch[file_count].size += sceIoWrite( ctf, buf, bytes );
								bytes = sceIoRead( fd, buf, CXMB_MKCTF_BUF_SIZE );
							}
							sceKernelFreeHeapMemory( heap_id, buf );
							sceIoClose( fd );
						}
						if ( ch[file_count].size > 0 && ch[file_count].size < CXMB_MAX_FILE_SIZE )
						{
							log( "start: %08x size: %08x\n", ch[file_count].start, ch[file_count].size );
							file_count ++;
						}
					}
					else
					{
						log( "ignore %s\n", ent->d_name );
					}
				}
				sceIoDclose( dfd );
			}
		}
		else
		{
			log( "failed in allocating %08x heap\n", ptf_h[2] );
		}
	}

	log( "file_count: %d\n", file_count );
	if ( file_count > 0 )
	{
		u8 sha1[20];
		sceKernelUtilsSha1Digest( ( u8 * )ch, sizeof( CtfHeader ) * file_count, sha1 );
		sceIoWrite( ctf, ch, sizeof( CtfHeader ) * file_count );
		sceIoLseek( ctf, 0x14, PSP_SEEK_SET );
		sceIoWrite( ctf, &sha1[0], 4 );
		sceIoWrite( ctf, &file_count, 4 );
		sceIoClose( ctf );
	}
	else
	{
		sceIoClose( ctf );
		sceIoRemove( cxmb_theme_file );
	}
	sceKernelFreeHeapMemory( heap_id, ent );
	sceKernelFreeHeapMemory( heap_id, ch );
	sceKernelDeleteHeap( heap_id );
	return 0;
}
Exemplo n.º 4
0
int main(int argc, char **argv) {
	initDisplay();

	SceUtilitySavedataParam2 param;
	initStandardSavedataParams(&param);

	// First, let's create some savedata.
	param.mode = (PspUtilitySavedataMode) SCE_UTILITY_SAVEDATA_TYPE_MAKEDATASECURE;
	param.saveNameList = saveNameList;

	param.dataBuf = savedata;
	param.dataBufSize = sizeof(savedata);
	param.dataSize = sizeof(savedata);

	checkpointExists(&param);
	runStandardSavedataLoop(&param);

	// A bit more, non-secure mode.
	param.mode = (PspUtilitySavedataMode) SCE_UTILITY_SAVEDATA_TYPE_WRITEDATA;
	param.saveNameList = saveNameList;
	strcpy(param.fileName, "OTHER.BIN");

	param.dataBuf = savedata;
	param.dataBufSize = sizeof(savedata);
	param.dataSize = sizeof(savedata);

	checkpointExists(&param);
	runStandardSavedataLoop(&param);

	// Now the actual sizes call.
	param.mode = (PspUtilitySavedataMode) SCE_UTILITY_SAVEDATA_TYPE_LIST;
	param.saveNameList = saveNameList;
	// Filename appears to be ignored.
	strcpy(param.fileName, "ASDASD.BIN");
	// Try: ABC, ABC2, "", <>, * (wildcards, work, <> not?)
	strcpy(param.saveName, "A?C");

	SceUtilitySavedataIdListInfo idList;
	SceUtilitySavedataIdListEntry idEntries[10];
	memset(idEntries, 0, sizeof(idEntries));
	idList.maxCount = 10;
	idList.resultCount = -1;
	idList.entries = idEntries;
	param.idList = &idList;

	param.dataBuf = savedata;
	param.dataBufSize = sizeof(savedata);
	param.dataSize = sizeof(savedata);

	checkpointExists(&param);
	runStandardSavedataLoop(&param);

	checkpoint("Result: %08x", param.base.result);

checkpoint("%s", idEntries[0].name);

	checkpointExists(&param);

	// TODO: Better way of cleaning up...
	checkpoint("sceIoRemove: %08x", sceIoRemove("ms0:/PSP/SAVEDATA/TEST99901ABC/DATA.BIN"));
	checkpoint("sceIoRemove: %08x", sceIoRemove("ms0:/PSP/SAVEDATA/TEST99901ABC/OTHER.BIN"));
	checkpoint("sceIoRemove: %08x", sceIoRemove("ms0:/PSP/SAVEDATA/TEST99901ABC/PARAM.SFO"));
	checkpoint("sceIoRmdir: %08x", sceIoRmdir("ms0:/PSP/SAVEDATA/TEST99901ABC"));
	checkpoint("sceIoRemove: %08x", sceIoRemove("ms0:/PSP/SAVEDATA/TEST99901/DATA.BIN"));
	checkpoint("sceIoRemove: %08x", sceIoRemove("ms0:/PSP/SAVEDATA/TEST99901/OTHER.BIN"));
	checkpoint("sceIoRemove: %08x", sceIoRemove("ms0:/PSP/SAVEDATA/TEST99901/PARAM.SFO"));
	checkpoint("sceIoRmdir: %08x", sceIoRmdir("ms0:/PSP/SAVEDATA/TEST99901"));
	checkpoint("sceIoRemove: %08x", sceIoRemove("ms0:/PSP/SAVEDATA/TEST99901F1/DATA.BIN"));
	checkpoint("sceIoRemove: %08x", sceIoRemove("ms0:/PSP/SAVEDATA/TEST99901F1/OTHER.BIN"));
	checkpoint("sceIoRemove: %08x", sceIoRemove("ms0:/PSP/SAVEDATA/TEST99901F1/PARAM.SFO"));
	checkpoint("sceIoRmdir: %08x", sceIoRmdir("ms0:/PSP/SAVEDATA/TEST99901F1"));

	return 0;
}
Exemplo n.º 5
0
void *orpGetValue(char *key, SceSize *key_size)
{
	void *value = NULL;

	REGHANDLE rh;
	struct RegParam reg = {
		.regtype = 1,
		.namelen = strlen(SYSTEM_REGISTRY),
		.unk2 = 1,
		.unk3 = 1,
	};
	strcpy(reg.name, SYSTEM_REGISTRY);

	int rc;
	if ((rc = sceRegOpenRegistry(&reg, 1, &rh)) < 0) {
		printf("Error opening registry.\n");
		return value;
	}

	REGHANDLE cat;
	if ((rc = sceRegOpenCategory(rh, "/CONFIG/PREMO", 1, &cat)) < 0) {
		printf("Error opening: /CONFIG/PREMO\n");
		goto _orpGetValue_exit1;
	}

	unsigned int key_type;
	if ((rc = sceRegGetKeyInfoByName(cat, key, &key_type, key_size)) < 0)
		printf("Key info failed: %s: %d\n", key, rc);
	else {
//		printf("%s: type: %d, size: %d\n", key, key_type, *key_size);
		value = malloc(*key_size);
		if ((rc = sceRegGetKeyValueByName(cat, key, value, *key_size)) < 0) {
			free(value);
			value = NULL;
			printf("Key look-up failed: %s\n", key);
			goto _orpGetValue_exit2;
		}
	}

_orpGetValue_exit2:
	sceRegCloseCategory(cat);

_orpGetValue_exit1:
	sceRegCloseRegistry(rh);
	return value;
}

int main()
{
	pspDebugScreenInit();
	SetupCallbacks();

	printf("Open Remote Play Exporter!\n\n");

	int rc;
	struct orpConfigRecord_t record;
	memset(&record, 0, sizeof(struct orpConfigRecord_t));
	record.ps3_port = ORP_PORT;
	strcpy((char *)record.ps3_hostname, "0.0.0.0");

	SceSize key_size;
	unsigned char *value;
	if ((value = orpGetValue("ps3_name", &key_size)) != NULL) {
		printf("%16s: %s\n", "Name", value);
		strncpy((char *)record.ps3_nickname,
			(const char *)value, ORP_NICKNAME_LEN);
		free(value);
	} else {
		printf("This PSP has not been registered for Remote Play!\n");
		printf("\nPress HOME to quit.\n");

		sceKernelSleepThread();
		return 0;
	}

	if ((rc =
		sceUtilityGetSystemParamString(PSP_SYSTEMPARAM_ID_STRING_NICKNAME,
		(char *)record.psp_owner, ORP_NICKNAME_LEN)) == 0) {
		printf("%16s: %s\n", "PSP Owner", record.psp_owner);
	}

	if ((value = orpGetValue("ps3_mac", &key_size)) != NULL) {
		printf("%16s: ", "PS3 MAC Address");
		int i;
		for (i = 0; i < key_size - 1; i++)
			printf("%02x:", value[i]);
		printf("%02x\n", value[key_size - 1]);
		memcpy(record.ps3_mac, value, ORP_MAC_LEN);
		free(value);
	}

	u8 mac[8];
	if ((rc = sceWlanGetEtherAddr(mac)) == 0) {
		printf("%16s: ", "PSP MAC Address");
		int i;
		memcpy(record.psp_mac, mac, ORP_MAC_LEN);
		for (i = 0; i < ORP_MAC_LEN - 1; i++)
			printf("%02x:", record.psp_mac[i]);
		printf("%02x\n", record.psp_mac[ORP_MAC_LEN - 1]);
	}

	PspOpenPSID psid;
	memset(&psid, 0, sizeof(psid));
	if ((rc = sceOpenPSIDGetOpenPSID(&psid) == 0)) {
		printf("%16s: ", "PSP ID");
		int i;
		for (i = 0; i < sizeof(psid.data) - 1; i++)
			printf("%02x", psid.data[i]);
		printf("%02x\n", psid.data[sizeof(psid.data) - 1]);
		memcpy(record.psp_id, psid.data, ORP_KEY_LEN);
	}

	if ((value = orpGetValue("ps3_key", &key_size)) != NULL) {
		printf("%16s: ", "Private Key");
		int i;
		for (i = 0; i < key_size; i++)
			printf("%02x", value[i]);
		printf("\n");
		memcpy(record.pkey, value, ORP_KEY_LEN);
		free(value);
	}

	char path[] = { "ms0:/export.orp" };
	sceIoRemove(path);
	SceUID fd = sceIoOpen(path,
		PSP_O_WRONLY | PSP_O_CREAT, 0777);
	if (fd < 0)
		printf("\nUnable to open: %s\n", path);
	else {
		struct orpConfigHeader_t header;
		memset(&header, 0, sizeof(struct orpConfigHeader_t));
		header.magic[0] = 'O'; header.magic[1] = 'R'; header.magic[2] = 'P';
		header.version = ORP_CONFIG_VER;
		header.flags = ORP_CONFIG_EXPORT;
		sceIoWrite(fd, &header, sizeof(struct orpConfigHeader_t));
		sceIoWrite(fd, &record, sizeof(struct orpConfigRecord_t));
		sceIoClose(fd);
		printf("\nConfiguration saved to: %s\n", path);
	}

	printf("\nPress HOME to quit.\n");

	sceKernelSleepThread();
	return 0;
}
Exemplo n.º 6
0
void configChange(const char *bootpath, const char *newname, const char *newval, int mode)
{
	char cnf_path[256];
	char new_path[256];
	int found = 0;
	struct ConfigFile cnf;
	int fd = -1;

	if((mode != CONFIG_MODE_ADD) && (mode != CONFIG_MODE_DEL))
	{
		return;
	}

	strcpy(cnf_path, bootpath);
	strcat(cnf_path, "psplink.ini");
	printf("Config Path %s\n", cnf_path);

	strcpy(new_path, bootpath);
	strcat(new_path, "psplink.ini.tmp");
	fd = sceIoOpen(new_path, PSP_O_WRONLY | PSP_O_TRUNC | PSP_O_CREAT, 0777);
	if(fd >= 0)
	{
		if(psplinkConfigOpen(cnf_path, &cnf))
		{
			const char *name;
			const char *val;

			while((val = psplinkConfigReadNext(&cnf, &name)))
			{
				if(strcmp(name, newname) == 0)
				{
					if(mode == CONFIG_MODE_ADD)
					{
						fdprintf(fd, "%s=\"%s\"\n", newname, newval);
						found = 1;
					}
				}
				else
				{
					fdprintf(fd, "%s=\"%s\"\n", name, val);
				}
			}

			if((mode == CONFIG_MODE_ADD) && (!found))
			{
				fdprintf(fd, "%s=\"%s\"\n", newname, newval);
			}

			sceIoClose(fd);
			fd = -1;
			psplinkConfigClose(&cnf);

			if(sceIoRemove(cnf_path) < 0)
			{
				printf("Error deleting original configuration\n");
			}
			else
			{
				if(sceIoRename(new_path, cnf_path) < 0)
				{
					printf("Error renaming configuration\n");
				}
			}
		}
		else
		{
			printf("Couldn't open temporary config file %s\n", new_path);
		}

		if(fd >= 0)
		{
			sceIoClose(fd);
			sceIoRemove(new_path);
		}
	}
}
Exemplo n.º 7
0
int neogeo_check_game(void)
{
    FILE *fp;
    char fname[16], path[MAX_PATH], linebuf[128];
    int i, fd, found = 0, NGH_number;

    neogeo_ngh = 0;
    hack_irq = 0;

    if (neogeo_boot_bios)
    {
        strcpy(game_name, games[99].name);
        game_index = 99;
    }
    else
    {
        strcpy(game_name, default_name);
        game_index = 0;

        sprintf(path, "%sIPL.TMP", launchDir);

        zip_open(game_dir);

        i = zlength("IPL.TXT");

        if ((fd = zopen("IPL.TXT")) == -1)
        {
            zip_close();
            return 0;
        }
        zread(fd, memory_region_cpu1, i);
        zclose(fd);
        zip_close();

        if ((fp = fopen(path, "w")) == NULL)
        {
            return 0;
        }
        fwrite(memory_region_cpu1, 1, i, fp);
        fclose(fp);

        if ((fp = fopen(path, "r")) == NULL)
        {
            sceIoRemove(path);
            return 0;
        }

        while (fgets(linebuf, 127, fp))
        {
            char *strfname = strtok(linebuf, ",\r\n");
            char *strbank  = strtok(NULL, ",\r\n");
            char *stroffs  = strtok(NULL, ",\r\n");
            char *ext;
            int bank, offs;

            if (strfname == NULL || strbank == NULL || stroffs == NULL)
                break;

            sscanf(strbank, "%d", &bank);
            sscanf(stroffs, "%x", &offs);
            ext = strrchr(strfname, '.');

            if (stricmp(ext, ".PRG") == 0 || stricmp(ext, ".ARG") == 0)
            {
                if (!bank && !offs)
                {
                    strcpy(fname, strfname);
                    found = 1;
                    break;
                }
            }
        }
        fclose(fp);

        sceIoRemove(path);

        if (!found) return 0;

        zip_open(game_dir);
        if ((fd = zopen(fname)) == -1)
        {
            zip_close();
            return 0;
        }

        zread(fd, memory_region_cpu1, 0x110);
        zclose(fd);
        zip_close();

        swab(memory_region_cpu1, memory_region_cpu1, 0x110);
        memcpy(neogeo_game_vectors, memory_region_cpu1, 0x100);

        NGH_number = m68000_read_memory_16(0x108);

        for (i = 0; games[i].ngh_number; i++)
        {
            if (games[i].ngh_number == NGH_number)
            {
                game_index = i + 1;
                neogeo_ngh = NGH_number;
                strcpy(game_name, games[i].name);

                if (NGH_NUMBER(0x0243))	// lastbld2
                    hack_irq = 1;

                break;
            }
        }
    }

    neogeo_reset_driver_type();

    return 1;
}
Exemplo n.º 8
0
/*
**
**  [func] - remove.
**  [desc] - if the s named file exists then deletes the s named file and
**           returns 0. else returns -1.
**  [entr] - const char *s; the filename string pointer.
**  [exit] - int; 0 if able to delete the s file. else -1.
**  [prec] - s is a valid string pointer.
**  [post] - the s file is deleted.
**
*/
int remove(const char *s)
{
	int ret = sceIoRemove(s);

	return (ret);
}