This software and its source code (if available) are licensed under the Apache-2.0 license (unless otherwise specified) which DOES NOT APPLY to any third-party code (such as zlib for example) and borrowed Assembler code (ripped code from other software executable files).
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
#include <stdint.h>
#define MAGIC_RS20 0x00325352
#define MAGIC_FAOE 0x454F4146
void dumpdata(char *name, void *data, uint32_t size) {
FILE *f;
if (name) {
f = fopen(name, "wb");
if (f) {
if (data && size) {
fwrite(data, size, 1, f);
}
fclose(f);
}
}
}
void readdata(FILE *fl, void *data, uint32_t size) {
if (data && size) {
memset(data, 0, size);
if (fl) {
fread(data, size, 1, fl);
}
}
}
int main(int argc, char *argv[]) {
uint32_t i, o, sz;
uint8_t *p;
char *s;
FILE *fl;
printf(
"Motocross Madness 2 .RES extractor v1.0\n"
"(c) CTPAX-X Team 2024\n"
"http://www.CTPAX-X.org/\n\n"
);
if (argc != 2) {
printf("Usage: mm2unres <filename.res>\n\n");
return(1);
}
fl = fopen(argv[1], "rb");
if (!fl) {
printf("Error: can't open input file.\n\n");
return(2);
}
/* read magic */
readdata(fl, &i, 4);
/* get file size */
fseek(fl, 0, SEEK_END);
sz = ftell(fl);
if (
((i != MAGIC_FAOE) && (i != MAGIC_RS20)) ||
((sz < 8) && (i == MAGIC_RS20)) ||
((sz < 12) && (i == MAGIC_FAOE))
) {
fclose(fl);
printf("Error: invalid input file format.\n\n");
return(3);
}
/* file not decrypted */
if (i == MAGIC_FAOE) {
fclose(fl);
printf("Error: encrypted .RES file - decrypt with mm2crypt tool first.\n\n");
return(4);
}
fseek(fl, 0, SEEK_SET);
p = (uint8_t *) malloc(sz);
if (!p) {
fclose(fl);
printf("Error: not enough memory for input file.\n\n");
return(5);
}
readdata(fl, p, sz);
fclose(fl);
sz = 4 + 4;
for (i = 0; i < (*((uint32_t *) &p[4])); i++) {
s = (char *) &p[sz + 4];
sz += 4 + (*((uint32_t *) &p[sz]));
/* save offset */
o = *((uint32_t *) &p[sz]);
/* ASCIIZ for filename */
p[sz] = 0;
sz += 4;
/* dump file */
printf("%s", s);
dumpdata(s, &p[o], *((uint32_t *) &p[sz]));
sz += 4;
printf("\n");
}
free(p);
printf("\ndone\n\n");
return(0);
}