aboutsummaryrefslogtreecommitdiff
path: root/devtools/create_tony/create_tony.cpp
blob: f2d086c0834ebc22f0c87344b2bcbf312aec52c0 (plain)
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/* 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 2
 * 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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * This is a utility for storing all the hardcoded data of Tony Tough in a separate
 * data file, used by the game engine
 */

// Disable symbol overrides so that we can use system headers.
#define FORBIDDEN_SYMBOL_ALLOW_ALL

// HACK to allow building with the SDL backend on MinGW
// see bug #1800764 "TOOLS: MinGW tools building broken"
#ifdef main
#undef main
#endif // main

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "common/scummsys.h"
#include "common/events.h"

#include "create_tony.h"
#include "staticdata.h"

static void writeByte(FILE *fp, uint8 b) {
	fwrite(&b, 1, 1, fp);
}

static void writeUint16BE(FILE *fp, uint16 value) {
	writeByte(fp, (uint8)(value >> 8));
	writeByte(fp, (uint8)(value & 0xFF));
}

void writeSint16BE(FILE *fp, int16 value) {
	writeUint16BE(fp, (uint16)value);
}

static void writeUint32BE(FILE *fp, uint32 value) {
	writeByte(fp, (uint8)(value >> 24));
	writeByte(fp, (uint8)((value >> 16) & 0xFF));
	writeByte(fp, (uint8)((value >> 8) & 0xFF));
	writeByte(fp, (uint8)(value & 0xFF));
}

void writeSint32BE(FILE *fp, int32 value) {
	writeUint32BE(fp, (uint16)value);
}

int main(int argc, char *argv[]) {
	FILE *outFile;

	outFile = fopen("tony.dat", "wb");

	// Write header
	fwrite("TONY", 4, 1, outFile);

	writeByte(outFile, TONY_DAT_VER_MAJ);
	writeByte(outFile, TONY_DAT_VER_MIN);

	// game versions/variants
	writeUint16BE(outFile, NUM_VARIANTS);

	// Italian
	for (int i = 0; i < 256; i++) {
		writeSint16BE(outFile, _cTableDialogIta[i]);
		writeSint16BE(outFile, _lTableDialogIta[i]);
		writeSint16BE(outFile, _cTableMaccIta[i]);
		writeSint16BE(outFile, _lTableMaccIta[i]);
		writeSint16BE(outFile, _cTableCredIta[i]);
		writeSint16BE(outFile, _lTableCredIta[i]);
		writeSint16BE(outFile, _cTableObjIta[i]);
		writeSint16BE(outFile, _lTableObjIta[i]);
	}

	// Polish
	for (int i = 0; i < 256; i++) {
		writeSint16BE(outFile, _cTableDialogPol[i]);
		writeSint16BE(outFile, _lTableDialogPol[i]);
		writeSint16BE(outFile, _cTableMaccPol[i]);
		writeSint16BE(outFile, _lTableMaccPol[i]);
		writeSint16BE(outFile, _cTableCredPol[i]);
		writeSint16BE(outFile, _lTableCredPol[i]);
		writeSint16BE(outFile, _cTableObjPol[i]);
		writeSint16BE(outFile, _lTableObjPol[i]);
	}

	//Russian
	for (int i = 0; i < 256; i++) {
		writeSint16BE(outFile, _cTableDialogRus[i]);
		writeSint16BE(outFile, _lTableDialogRus[i]);
		writeSint16BE(outFile, _cTableMaccRus[i]);
		writeSint16BE(outFile, _lTableMaccRus[i]);
		writeSint16BE(outFile, _cTableCredRus[i]);
		writeSint16BE(outFile, _lTableCredRus[i]);
		writeSint16BE(outFile, _cTableObjRus[i]);
		writeSint16BE(outFile, _lTableObjRus[i]);
	}

	// Czech
	for (int i = 0; i < 256; i++) {
		writeSint16BE(outFile, _cTableDialogCze[i]);
		writeSint16BE(outFile, _lTableDialogCze[i]);
		writeSint16BE(outFile, _cTableMaccCze[i]);
		writeSint16BE(outFile, _lTableMaccCze[i]);
		writeSint16BE(outFile, _cTableCredCze[i]);
		writeSint16BE(outFile, _lTableCredCze[i]);
		writeSint16BE(outFile, _cTableObjCze[i]);
		writeSint16BE(outFile, _lTableObjCze[i]);
	}

	// French
	for (int i = 0; i < 256; i++) {
		writeSint16BE(outFile, _cTableDialogFra[i]);
		writeSint16BE(outFile, _lTableDialogFra[i]);
		writeSint16BE(outFile, _cTableMaccFra[i]);
		writeSint16BE(outFile, _lTableMaccFra[i]);
		writeSint16BE(outFile, _cTableCredFra[i]);
		writeSint16BE(outFile, _lTableCredFra[i]);
		writeSint16BE(outFile, _cTableObjFra[i]);
		writeSint16BE(outFile, _lTableObjFra[i]);
	}

	// Deutsch
	for (int i = 0; i < 256; i++) {
		writeSint16BE(outFile, _cTableDialogDeu[i]);
		writeSint16BE(outFile, _lTableDialogDeu[i]);
		writeSint16BE(outFile, _cTableMaccDeu[i]);
		writeSint16BE(outFile, _lTableMaccDeu[i]);
		writeSint16BE(outFile, _cTableCredDeu[i]);
		writeSint16BE(outFile, _lTableCredDeu[i]);
		writeSint16BE(outFile, _cTableObjDeu[i]);
		writeSint16BE(outFile, _lTableObjDeu[i]);
	}

	fclose(outFile);
	return 0;
}

void writeTextArray(FILE *outFile, const char *textArray[], int nbrText) {
	int len, len1, pad;
	uint8 padBuf[DATAALIGNMENT];

	for (int i = 0; i < DATAALIGNMENT; i++)
		padBuf[i] = 0;

	writeUint16BE(outFile, nbrText);
	len = DATAALIGNMENT - 2;
	for (int i = 0; i < nbrText; i++) {
		len1 = strlen(textArray[i]) + 1;
		pad = DATAALIGNMENT - (len1 + 2) % DATAALIGNMENT;
		len += 2 + len1 + pad;
	}
	writeUint16BE(outFile, len);

	fwrite(padBuf, DATAALIGNMENT - 2, 1, outFile); // padding
	for (int i = 0; i < nbrText; i++) {
		len = strlen(textArray[i]) + 1;
		pad = DATAALIGNMENT - (len + 2) % DATAALIGNMENT;

		writeUint16BE(outFile, len + pad + 2);
		fwrite(textArray[i], len, 1, outFile);
		fwrite(padBuf, pad, 1, outFile);
	}
}