Skip to content

Instantly share code, notes, and snippets.

@Midnoclose
Last active June 20, 2022 20:46
Show Gist options
  • Save Midnoclose/0c42a35d7f9108a07d9e3afef9bddb07 to your computer and use it in GitHub Desktop.
Save Midnoclose/0c42a35d7f9108a07d9e3afef9bddb07 to your computer and use it in GitHub Desktop.
Extract music from .vvv file
/*
*
* VVVVVV Music Extractor
* by Midnoclose
*
* BSD Zero Clause License
*
* Copyright (c) 2021 Midnoclose
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#define HEADERS 128
#define FILENAME 11
struct header
{
char name[48];
int start_UNUSED;
int size;
bool valid;
};
int main(int argc, char *argv[]) {
if (argc != 2) {
printf("Usage: %s <file.vvv>\n", argv[0]);
return 1;
}
struct header files[HEADERS];
FILE *music, *output;
char *buffer;
int i = 0;
int numfiles = 0;
if ((music = fopen(argv[1], "rb")) == NULL) {
puts("Unable to open file.");
return 1;
}
// list off the files
do {
fread(&files[i], sizeof(struct header), 1, music);
if (!files[i].valid) break;
printf("%s %dKB\n", files[i].name+FILENAME, files[i].size >> 10); // shift right 10 times to divide by 1024
} while (files[i++].valid);
numfiles = i - 1;
// seek to actual files
fseek(music, sizeof(struct header) << 7, SEEK_SET); // shift left 7 times to multiply by HEADERS (128)
for (i = 0; i <= numfiles; i++) {
if ((output = fopen(files[i].name+FILENAME, "wb")) == NULL) {
puts("Unable to open file.");
return 1;
}
buffer = malloc(files[i].size);
fread(buffer, files[i].size, 1, music);
fwrite(buffer, files[i].size, 1, output);
free(buffer);
fclose(output);
}
fclose(music);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment