1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
// Disable symbol overrides so that we can use system headers.
#define FORBIDDEN_SYMBOL_ALLOW_ALL
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "util.h"
#include "create_cryomni3d_dat.h"
struct Parts {
size_t (*writeHeader)(FILE *f, uint32 offset, uint32 size);
size_t (*writeData)(FILE *f);
uint32 offset;
uint32 size;
};
#define DEFINE_GAME_PLATFORM_LANG_FUNCS(game, platform, lang) \
size_t write ## game ## _ ## platform ## _ ## lang ## _Header(FILE *f, \
uint32 offset, uint32 size); \
size_t write ## game ## _ ## platform ## _ ## lang ## _Data(FILE *f);
#define GAME_PLATFORM_LANG_PART(game, platform, lang) { write ## game ## _ ## platform ## _ ## lang ## _Header, \
write ## game ## _ ## platform ## _ ## lang ## _Data, 0, 0 }
DEFINE_GAME_PLATFORM_LANG_FUNCS(Versailles, ALL, FR)
DEFINE_GAME_PLATFORM_LANG_FUNCS(Versailles, ALL, BR)
DEFINE_GAME_PLATFORM_LANG_FUNCS(Versailles, ALL, DE)
DEFINE_GAME_PLATFORM_LANG_FUNCS(Versailles, ALL, EN)
DEFINE_GAME_PLATFORM_LANG_FUNCS(Versailles, ALL, ES)
DEFINE_GAME_PLATFORM_LANG_FUNCS(Versailles, ALL, IT)
DEFINE_GAME_PLATFORM_LANG_FUNCS(Versailles, ALL, JA)
DEFINE_GAME_PLATFORM_LANG_FUNCS(Versailles, ALL, KO)
DEFINE_GAME_PLATFORM_LANG_FUNCS(Versailles, ALL, ZT)
static Parts gamesParts[] = {
GAME_PLATFORM_LANG_PART(Versailles, ALL, FR),
GAME_PLATFORM_LANG_PART(Versailles, ALL, BR),
GAME_PLATFORM_LANG_PART(Versailles, ALL, DE),
GAME_PLATFORM_LANG_PART(Versailles, ALL, EN),
GAME_PLATFORM_LANG_PART(Versailles, ALL, ES),
GAME_PLATFORM_LANG_PART(Versailles, ALL, IT),
GAME_PLATFORM_LANG_PART(Versailles, ALL, JA),
GAME_PLATFORM_LANG_PART(Versailles, ALL, KO),
GAME_PLATFORM_LANG_PART(Versailles, ALL, ZT),
};
#define CRYOMNI3D_DAT_VER 1 // 32-bit integer
size_t writeFileHeader(FILE *f, uint16 games) {
size_t headerSize = 0;
fwrite("CY3DDATA", 8, 1, f);
headerSize += 8;
headerSize += writeUint16LE(f, CRYOMNI3D_DAT_VER);
headerSize += writeUint16LE(f, games);
// Dummy value to pad to 16 bytes
headerSize += writeUint32LE(f, 0);
assert((headerSize & PADDING_MASK) == 0);
return headerSize;
}
size_t writeGameHeader(FILE *f, uint32 gameId, uint16 version, uint16 lang, uint32 platforms,
uint32 offset, uint32 size) {
size_t headerSize = 0;
headerSize += writeUint32BE(f, gameId); // BE to keep the tag readable
headerSize += writeUint16LE(f, version);
headerSize += writeUint16BE(f, lang); // BE to keep the tag readable
headerSize += writeUint32LE(f, platforms);
headerSize += writeUint32LE(f, offset);
headerSize += writeUint32LE(f, size);
return headerSize;
}
static int emitData(char *outputFilename) {
FILE *f = fopen(outputFilename, "w+b");
if (!f) {
printf("ERROR: Unable to create output file %s\n", outputFilename);
return 1;
}
printf("Generating %s...\n", outputFilename);
writeFileHeader(f);
for (unsigned int i = 0; i < ARRAYSIZE(gamesParts); i++) {
gamesParts[i].writeHeader(f, 0xdeadfeed, 0xdeadfeed);
}
// Pad the games list
writePadding(f);
for (unsigned int i = 0; i < ARRAYSIZE(gamesParts); i++) {
gamesParts[i].offset = ftell(f);
gamesParts[i].size = gamesParts[i].writeData(f);
}
fseek(f, 0, SEEK_SET);
writeFileHeader(f, ARRAYSIZE(gamesParts));
for (unsigned int i = 0; i < ARRAYSIZE(gamesParts); i++) {
gamesParts[i].writeHeader(f, gamesParts[i].offset, gamesParts[i].size);
}
fclose(f);
printf("Done!\n");
return 0;
}
int main(int argc, char **argv) {
if (argc > 1) {
return emitData(argv[1]);
} else {
printf("Usage: %s <output.dat>\n", argv[0]);
}
return 0;
}
|