/* * Hanashizume Music ripper * 1999/12/26 by TF * usage: hanamus hanamus.dll */ #include #include #define TABLE_POS 0x00000960 #define OFFSET (0x00000bf0 - 0x17f0) #define MUSIC_NUM 40 int get4b(FILE *); int read_table(FILE *in, int *, int *); int main(int argc, char *argv[]) { FILE *in, *out; int i; unsigned char *buf; char fname[16]; int position[MUSIC_NUM], size[MUSIC_NUM]; in = fopen(argv[1], "r"); if (in == NULL) { fprintf(stderr, "No such a file %s.\n", argv[1]); exit(1); } /* read table */ fseek(in, TABLE_POS, SEEK_SET); for (i = 0; i < MUSIC_NUM; i++) { position[i] = get4b(in); size[i] = get4b(in); /* skip null bytes */ get4b(in); get4b(in); } /* read and output MIDI data */ for (i = 0; i < MUSIC_NUM; i++) { sprintf(fname, "hana%x.mid", i + 2); fprintf(stderr, "output %s...", fname); out = fopen(fname, "w"); fseek(in, position[i] + OFFSET, SEEK_SET); buf = (unsigned char *)calloc(size[i], sizeof(unsigned char)); fread(buf, 1, size[i], in); fwrite(buf, 1, size[i], out); fprintf(stderr, "done.\n"); free(buf); fclose(out); } fclose(in); return 0; } int get4b(FILE *in) { unsigned char b1, b2, b3, b4; b1 = fgetc(in); b2 = fgetc(in); b3 = fgetc(in); b4 = fgetc(in); return (b4 << 24) | (b3 << 16) | (b2 << 8) | b1; }