コード例 #1
0
ファイル: xPS.c プロジェクト: conleon/neo-myth-plugins
void handle_ips(void)
{
#define BYTE3_TO_LONG(bp)   \
      (((long)(bp)[0] << 16) | ((long)(bp)[1] <<  8) | (long)(bp)[2])

#define BYTE2_TO_WORD(bp)   \
      (((bp)[0] << 8) | (bp)[1])

    const u8 end_of_ips[3] = "EOF";

    u8 puffer[5];
    long offset;
    u16 count;

    while (1)
    {
        IO_ReadSingle(puffer,1,3,patch_file);
        if (!memcmp(puffer,end_of_ips,3))
            break;
        offset = BYTE3_TO_LONG(puffer);
        IO_ReadSingle(puffer,2,1,patch_file);
        count = BYTE2_TO_WORD(puffer);
        if (count)
            make_changes(offset,count,UNCOMPRESSED);
        else
        {
            IO_ReadSingle(puffer,1,2,patch_file);
            make_changes(offset,BYTE2_TO_WORD(puffer),IPS_RLE);
        }
    }
}
コード例 #2
0
ファイル: xPS.c プロジェクト: conleon/neo-myth-plugins
void handle_aps(void)
{
    long offset,romsize;
    u8 count;
    u16 num;

    romsize = fsize(rom_file);
    while (IO_ReadSingle(&offset,4,1,patch_file))
    {
        if (romsize < offset)
            break;

        if (count = IO_GetcSingle(patch_file))
            make_changes(offset,(u16)count,UNCOMPRESSED);
        else
        {
            IO_ReadSingle(&num,1,2,patch_file);
            make_changes(offset,(u16)num,APS_RLE);
        }
    }
}
コード例 #3
0
ファイル: rom_functions.c プロジェクト: Quote58/Gtk-Hexer
int not_main(char *rom_name, char *offset, char *bytes, int apply_or_check) {

	FILE* file = fopen(rom_name, "rb");
	//printf("trying to open...\n");	

	if (file) {
		size_t size;

		//printf("file exists!\n");
		unsigned char *buf;

		get_data("rom.smc", &buf, file, &size);

		fclose(file);
		//printf("file closed!\n");

		//char input[30];
		char to_use[30];
		//printf("offset?\n");
		//scanf("%s", input);		//needed
		int num = strlen(bytes);	//needed
		
		int offset_to_apply, bytes_to_apply, new_offset;
		int c = 0;
		int check_tweak = 0;

		sscanf(offset, "%x", &offset_to_apply);
		//printf("bytes? (offset is: %d)\n", offset_to_apply);
		//scanf("%s", input);		//needed

		while (c < num) {
			//printf(">>>>>%d<<<<<<\n>>>>>%d<<<<<\n", c, num);
			strncpy(to_use, bytes+c, 2);
			sscanf(to_use, "%x", &bytes_to_apply);

			if ((make_changes(buf, offset_to_apply, bytes_to_apply, size, &check_tweak)==0)) {
				if (apply_or_check == 0) { //0 = apply
					/*switch(apply_changes(buf, rom_name, size)) {
						case 0: printf("success!\n"); break;
						case 1: printf("not success :(\n"); break;
					}*/
					apply_changes(buf, rom_name, size);
				}
			}	
			c += 2;
			offset_to_apply++;
		}
		
		free(buf);

		if (apply_or_check > 0)	//if this is checking stuff
			//printf("number of bytes in the tweak: %d\nnumber of bytes that were the same: %d\n", c/2, check_tweak);
			if (check_tweak == (c/2))
				return 1;
			else
				return 0;

		return 1;
	}

	else {
		fclose(file);
		printf("no such file???\n");
		return 0;
	}
}