-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapcombine.c
More file actions
135 lines (115 loc) · 2.82 KB
/
mapcombine.c
File metadata and controls
135 lines (115 loc) · 2.82 KB
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
#include <stdio.h>
#include <string.h>
struct header {
int version;
int numremoves;
int numobjects;
int numzones;
float streamin;
float streamout;
float drawdistance;
};
struct header h1, h2, h3;
struct {
int model;
float x, y, z, rx, ry, rz;
} object;
struct {
int model;
float x, y, z, radius;
} removebuild;
struct {
float west, south, east, north;
int color;
} gangzone;
char newdata[sizeof(h3) + sizeof(object) * 2000 + sizeof(removebuild) * 2000 + sizeof(gangzone) * 2048];
char *datapos = newdata;
int main(int argc, char **argv)
{
FILE *master, *add;
int i;
if (argc < 3) {
puts("give master file and additional file as args");
return 1;
}
if (!(master = fopen(argv[1], "rb"))) {
puts("failed to open master file for reading");
return 1;
}
if (!(add = fopen(argv[2], "rb"))) {
fclose(master);
puts("failed to open additional file for reading");
return 1;
}
if (fread(&h1, sizeof(h1), 1, master) != 1 || fread(&h2, sizeof(h2), 1, add) != 1) {
goto fail;
}
if (h1.version != 0x0250414D || h2.version != 0x0250414D) {
puts("version unsupported");
goto fail;
}
h3 = h1;
h3.numremoves = h1.numremoves + h2.numremoves;
h3.numobjects = h1.numobjects + h2.numobjects;
h3.numzones = h1.numzones + h2.numzones;
memcpy(datapos, &h3, sizeof(h3));
datapos += sizeof(h3);
for (i = 0; i < h1.numremoves; i++) {
if (!fread(&removebuild, sizeof(removebuild), 1, master)) {
goto fail;
}
memcpy(datapos, &removebuild, sizeof(removebuild));
datapos += sizeof(removebuild);
}
for (i = 0; i < h2.numremoves; i++) {
if (!fread(&removebuild, sizeof(removebuild), 1, add)) {
goto fail;
}
memcpy(datapos, &removebuild, sizeof(removebuild));
datapos += sizeof(removebuild);
}
for (i = 0; i < h1.numobjects; i++) {
if (!fread(&object, sizeof(object), 1, master)) {
goto fail;
}
memcpy(datapos, &object, sizeof(object));
datapos += sizeof(object);
}
for (i = 0; i < h2.numobjects; i++) {
if (!fread(&object, sizeof(object), 1, add)) {
goto fail;
}
memcpy(datapos, &object, sizeof(object));
datapos += sizeof(object);
}
for (i = 0; i < h1.numzones; i++) {
if (!fread(&gangzone, sizeof(gangzone), 1, master)) {
goto fail;
}
memcpy(datapos, &gangzone, sizeof(gangzone));
datapos += sizeof(gangzone);
}
for (i = 0; i < h2.numzones; i++) {
if (!fread(&gangzone, sizeof(gangzone), 1, add)) {
goto fail;
}
memcpy(datapos, &gangzone, sizeof(gangzone));
datapos += sizeof(gangzone);
}
fclose(master);
fclose(add);
if (!(master = fopen(argv[1], "wb"))) {
puts("failed to open master file for writing");
return 1;
}
if (!fwrite(newdata, datapos - newdata, 1, master)) {
puts("failed to write master file?");
}
fclose(master);
return 0;
fail:
puts("failed, check both maps with mapinfo to see if they're valid");
fclose(master);
fclose(add);
return 1;
}