mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-29 07:41:47 +00:00
maps: fix lump size calculation
This commit is contained in:
parent
f1d9bd6f47
commit
7e53c83c88
2 changed files with 34 additions and 28 deletions
|
@ -1060,8 +1060,12 @@ Mod_MaptypeName(maptype_t maptype)
|
||||||
}
|
}
|
||||||
|
|
||||||
static maptype_t
|
static maptype_t
|
||||||
Mod_LoadGetRules(const dheader_t *header, const rule_t **rules)
|
Mod_LoadGetRules(const dheader_t *header, const rule_t **rules, int *numlumps, int *numrules)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* numlumps is count lumps in format,
|
||||||
|
* numrules is what could checked and converted
|
||||||
|
*/
|
||||||
if (header->ident == IDBSPHEADER)
|
if (header->ident == IDBSPHEADER)
|
||||||
{
|
{
|
||||||
if (header->version == BSPDKMVERSION)
|
if (header->version == BSPDKMVERSION)
|
||||||
|
@ -1071,6 +1075,7 @@ Mod_LoadGetRules(const dheader_t *header, const rule_t **rules)
|
||||||
(header->lumps[LUMP_FACES].filelen % sizeof(drface_t) == 0))
|
(header->lumps[LUMP_FACES].filelen % sizeof(drface_t) == 0))
|
||||||
{
|
{
|
||||||
*rules = rbsplumps;
|
*rules = rbsplumps;
|
||||||
|
*numrules = *numlumps = HEADER_LUMPS;
|
||||||
return map_sin;
|
return map_sin;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1084,23 +1089,28 @@ Mod_LoadGetRules(const dheader_t *header, const rule_t **rules)
|
||||||
*rules = idbsplumps;
|
*rules = idbsplumps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*numrules = HEADER_LUMPS;
|
||||||
|
*numlumps = HEADER_DKLUMPS;
|
||||||
return map_daikatana;
|
return map_daikatana;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (header->version == BSPVERSION)
|
else if (header->version == BSPVERSION)
|
||||||
{
|
{
|
||||||
*rules = idbsplumps;
|
*rules = idbsplumps;
|
||||||
|
*numrules = *numlumps = HEADER_LUMPS;
|
||||||
return map_quake2rr;
|
return map_quake2rr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (header->ident == QBSPHEADER && header->version == BSPVERSION)
|
else if (header->ident == QBSPHEADER && header->version == BSPVERSION)
|
||||||
{
|
{
|
||||||
*rules = qbsplumps;
|
*rules = qbsplumps;
|
||||||
|
*numrules = *numlumps = HEADER_LUMPS;
|
||||||
return map_quake2rr;
|
return map_quake2rr;
|
||||||
}
|
}
|
||||||
else if (header->ident == RBSPHEADER && header->version == BSPSINVERSION)
|
else if (header->ident == RBSPHEADER && header->version == BSPSINVERSION)
|
||||||
{
|
{
|
||||||
*rules = rbsplumps;
|
*rules = rbsplumps;
|
||||||
|
*numrules = *numlumps = HEADER_LUMPS;
|
||||||
return map_sin;
|
return map_sin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1112,22 +1122,25 @@ byte *
|
||||||
Mod_Load2QBSP(const char *name, byte *inbuf, size_t filesize, size_t *out_len,
|
Mod_Load2QBSP(const char *name, byte *inbuf, size_t filesize, size_t *out_len,
|
||||||
maptype_t *maptype)
|
maptype_t *maptype)
|
||||||
{
|
{
|
||||||
|
/* max lump count * lumps + ident + version */
|
||||||
|
int headermem[64];
|
||||||
const rule_t *rules = NULL;
|
const rule_t *rules = NULL;
|
||||||
size_t result_size;
|
size_t result_size;
|
||||||
dheader_t header, *outheader;
|
dheader_t *header, *outheader;
|
||||||
int s, xofs, numlumps;
|
int s, xofs, numlumps, numrules;
|
||||||
qboolean error = false;
|
qboolean error = false;
|
||||||
byte *outbuf;
|
byte *outbuf;
|
||||||
maptype_t detected_maptype;
|
maptype_t detected_maptype;
|
||||||
|
|
||||||
for (s = 0; s < sizeof(dheader_t) / 4; s++)
|
for (s = 0; s < sizeof(headermem) / sizeof(int); s++)
|
||||||
{
|
{
|
||||||
((int *)&header)[s] = LittleLong(((int *)inbuf)[s]);
|
headermem[s] = LittleLong(((int *)inbuf)[s]);
|
||||||
}
|
}
|
||||||
|
header = (dheader_t *)&headermem;
|
||||||
|
|
||||||
result_size = sizeof(dheader_t);
|
result_size = sizeof(dheader_t);
|
||||||
|
|
||||||
detected_maptype = Mod_LoadGetRules(&header, &rules);
|
detected_maptype = Mod_LoadGetRules(header, &rules, &numlumps, &numrules);
|
||||||
if (detected_maptype != map_quake2rr)
|
if (detected_maptype != map_quake2rr)
|
||||||
{
|
{
|
||||||
/* Use detected maptype only if for sure know */
|
/* Use detected maptype only if for sure know */
|
||||||
|
@ -1136,19 +1149,19 @@ Mod_Load2QBSP(const char *name, byte *inbuf, size_t filesize, size_t *out_len,
|
||||||
|
|
||||||
if (rules)
|
if (rules)
|
||||||
{
|
{
|
||||||
for (s = 0; s < HEADER_LUMPS; s++)
|
for (s = 0; s < numrules; s++)
|
||||||
{
|
{
|
||||||
if (rules[s].size)
|
if (rules[s].size)
|
||||||
{
|
{
|
||||||
if (header.lumps[s].filelen % rules[s].size)
|
if (header->lumps[s].filelen % rules[s].size)
|
||||||
{
|
{
|
||||||
Com_Printf("%s: Map %s lump #%d: incorrect size %d / " YQ2_COM_PRIdS "\n",
|
Com_Printf("%s: Map %s lump #%d: incorrect size %d / " YQ2_COM_PRIdS "\n",
|
||||||
__func__, name, s, header.lumps[s].filelen, rules[s].size);
|
__func__, name, s, header->lumps[s].filelen, rules[s].size);
|
||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
result_size += (
|
result_size += (
|
||||||
xbsplumps[s].size * header.lumps[s].filelen / rules[s].size
|
xbsplumps[s].size * header->lumps[s].filelen / rules[s].size
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1156,11 +1169,11 @@ Mod_Load2QBSP(const char *name, byte *inbuf, size_t filesize, size_t *out_len,
|
||||||
|
|
||||||
Com_Printf("Map %s %c%c%c%c with version %d (%s)\n",
|
Com_Printf("Map %s %c%c%c%c with version %d (%s)\n",
|
||||||
name,
|
name,
|
||||||
(header.ident >> 0) & 0xFF,
|
(header->ident >> 0) & 0xFF,
|
||||||
(header.ident >> 8) & 0xFF,
|
(header->ident >> 8) & 0xFF,
|
||||||
(header.ident >> 16) & 0xFF,
|
(header->ident >> 16) & 0xFF,
|
||||||
(header.ident >> 24) & 0xFF,
|
(header->ident >> 24) & 0xFF,
|
||||||
header.version, Mod_MaptypeName(*maptype));
|
header->version, Mod_MaptypeName(*maptype));
|
||||||
|
|
||||||
if (error || !rules)
|
if (error || !rules)
|
||||||
{
|
{
|
||||||
|
@ -1170,18 +1183,10 @@ Mod_Load2QBSP(const char *name, byte *inbuf, size_t filesize, size_t *out_len,
|
||||||
|
|
||||||
/* find end of last lump */
|
/* find end of last lump */
|
||||||
xofs = 0;
|
xofs = 0;
|
||||||
|
|
||||||
numlumps = HEADER_LUMPS;
|
|
||||||
if ((header.version == BSPDKMVERSION) &&
|
|
||||||
(*maptype == map_daikatana))
|
|
||||||
{
|
|
||||||
numlumps = 21;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (s = 0; s < numlumps; s++)
|
for (s = 0; s < numlumps; s++)
|
||||||
{
|
{
|
||||||
xofs = Q_max(xofs,
|
xofs = Q_max(xofs,
|
||||||
(header.lumps[s].fileofs + header.lumps[s].filelen + 3) & ~3);
|
(header->lumps[s].fileofs + header->lumps[s].filelen + 3) & ~3);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xofs + sizeof(bspx_header_t) < filesize)
|
if (xofs + sizeof(bspx_header_t) < filesize)
|
||||||
|
@ -1209,13 +1214,13 @@ Mod_Load2QBSP(const char *name, byte *inbuf, size_t filesize, size_t *out_len,
|
||||||
int ofs = sizeof(dheader_t);
|
int ofs = sizeof(dheader_t);
|
||||||
|
|
||||||
/* mark offsets for all lumps */
|
/* mark offsets for all lumps */
|
||||||
for (s = 0; s < HEADER_LUMPS; s++)
|
for (s = 0; s < numrules; s++)
|
||||||
{
|
{
|
||||||
if (rules[s].size)
|
if (rules[s].size)
|
||||||
{
|
{
|
||||||
outheader->lumps[s].fileofs = ofs;
|
outheader->lumps[s].fileofs = ofs;
|
||||||
outheader->lumps[s].filelen = (
|
outheader->lumps[s].filelen = (
|
||||||
xbsplumps[s].size * header.lumps[s].filelen / rules[s].size
|
xbsplumps[s].size * header->lumps[s].filelen / rules[s].size
|
||||||
);
|
);
|
||||||
ofs += outheader->lumps[s].filelen;
|
ofs += outheader->lumps[s].filelen;
|
||||||
}
|
}
|
||||||
|
@ -1254,7 +1259,7 @@ Mod_Load2QBSP(const char *name, byte *inbuf, size_t filesize, size_t *out_len,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* convert lumps to QBSP for all lumps */
|
/* convert lumps to QBSP for all lumps */
|
||||||
for (s = 0; s < HEADER_LUMPS; s++)
|
for (s = 0; s < numrules; s++)
|
||||||
{
|
{
|
||||||
if (!rules[s].size)
|
if (!rules[s].size)
|
||||||
{
|
{
|
||||||
|
@ -1267,7 +1272,7 @@ Mod_Load2QBSP(const char *name, byte *inbuf, size_t filesize, size_t *out_len,
|
||||||
__func__, name, s);
|
__func__, name, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
rules[s].func(outbuf, outheader, inbuf, &header, rules[s].size, *maptype);
|
rules[s].func(outbuf, outheader, inbuf, header, rules[s].size, *maptype);
|
||||||
}
|
}
|
||||||
|
|
||||||
*out_len = result_size;
|
*out_len = result_size;
|
||||||
|
|
|
@ -681,6 +681,7 @@ typedef struct
|
||||||
#define LUMP_AREAS 17
|
#define LUMP_AREAS 17
|
||||||
#define LUMP_AREAPORTALS 18
|
#define LUMP_AREAPORTALS 18
|
||||||
#define HEADER_LUMPS 19
|
#define HEADER_LUMPS 19
|
||||||
|
#define HEADER_DKLUMPS 21
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue