mirror of
https://git.code.sf.net/p/quake/newtree
synced 2024-11-10 06:42:26 +00:00
GL alias model meshes are now doubly protected from corruption and model
mismatch. First, the md4 checksum is stored in the mesh, and the md4 checksum of the mesh and the model checksum are also stored. If, on loading, either checksum fails, the model is re-meshed. include/mdfour.h: Add define for MDFOUR_DIGEST_BYTES source/.gdbinit setrom _windowed_mouse 0 so mods don't make debugging difficult source/model_alias.c: pass original model data and size to GL_MakeAliasModelDisplayLists source/sw_model_alias.c: GL_MakeAliasModelDisplayLists take (but ignore) new params source/gl_mesh.c: do md4 checksums on the model and mesh
This commit is contained in:
parent
7d8fb5901e
commit
26a2d6a3de
5 changed files with 56 additions and 10 deletions
|
@ -32,6 +32,8 @@
|
|||
|
||||
#include "uint32.h"
|
||||
|
||||
#define MDFOUR_DIGEST_BYTES 16
|
||||
|
||||
struct mdfour {
|
||||
uint32 A, B, C, D;
|
||||
uint32 totalN;
|
||||
|
|
|
@ -1 +1 @@
|
|||
set args -nocdaudio +set _windowed_mouse 0 +set gl_sky_clip 1 +set show_fps 1
|
||||
set args -nocdaudio +setrom _windowed_mouse 0 +set gl_sky_clip 1 +set show_fps 1
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include "console.h"
|
||||
#include "mdfour.h"
|
||||
#include "model.h"
|
||||
#include "quakefs.h"
|
||||
|
||||
|
@ -301,17 +302,22 @@ GL_MakeAliasModelDisplayLists
|
|||
================
|
||||
*/
|
||||
void
|
||||
GL_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr)
|
||||
GL_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m, int _s)
|
||||
{
|
||||
int i, j;
|
||||
int *cmds;
|
||||
trivertx_t *verts;
|
||||
char cache[MAX_QPATH], fullpath[MAX_OSPATH];
|
||||
QFile *f;
|
||||
unsigned char model_digest[MDFOUR_DIGEST_BYTES];
|
||||
unsigned char mesh_digest[MDFOUR_DIGEST_BYTES];
|
||||
qboolean remesh = true;
|
||||
|
||||
aliasmodel = m;
|
||||
paliashdr = hdr; // (aliashdr_t *)Mod_Extradata (m);
|
||||
|
||||
mdfour (model_digest, (unsigned char*)_m, _s);
|
||||
|
||||
//
|
||||
// look for a cached version
|
||||
//
|
||||
|
@ -322,12 +328,37 @@ GL_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr)
|
|||
|
||||
COM_FOpenFile (cache, &f);
|
||||
if (f) {
|
||||
Qread (f, &numcommands, 4);
|
||||
Qread (f, &numorder, 4);
|
||||
Qread (f, &commands, numcommands * sizeof (commands[0]));
|
||||
Qread (f, &vertexorder, numorder * sizeof (vertexorder[0]));
|
||||
unsigned char d1[MDFOUR_DIGEST_BYTES];
|
||||
unsigned char d2[MDFOUR_DIGEST_BYTES];
|
||||
struct mdfour md;
|
||||
int nc;
|
||||
int no;
|
||||
|
||||
memset (d1, 0, sizeof (d1));
|
||||
memset (d2, 0, sizeof (d2));
|
||||
Qread (f, &nc, 4);
|
||||
Qread (f, &no, 4);
|
||||
Qread (f, &commands, nc * sizeof (commands[0]));
|
||||
Qread (f, &vertexorder, no * sizeof (vertexorder[0]));
|
||||
Qread (f, d1, MDFOUR_DIGEST_BYTES);
|
||||
Qread (f, d2, MDFOUR_DIGEST_BYTES);
|
||||
Qclose (f);
|
||||
} else {
|
||||
|
||||
mdfour_begin (&md);
|
||||
mdfour_update (&md, (unsigned char*)&nc, 4);
|
||||
mdfour_update (&md, (unsigned char*)&no, 4);
|
||||
mdfour_update (&md, (unsigned char*)&commands, nc * sizeof (commands[0]));
|
||||
mdfour_update (&md, (unsigned char*)&vertexorder, no * sizeof (vertexorder[0]));
|
||||
mdfour_update (&md, d1, MDFOUR_DIGEST_BYTES);
|
||||
mdfour_result (&md, mesh_digest);
|
||||
|
||||
if (memcmp (d2, mesh_digest, MDFOUR_DIGEST_BYTES) == 0 && memcmp (d1, model_digest, MDFOUR_DIGEST_BYTES) == 0) {
|
||||
remesh = false;
|
||||
numcommands = nc;
|
||||
numorder = no;
|
||||
}
|
||||
}
|
||||
if (remesh) {
|
||||
//
|
||||
// build it from scratch
|
||||
//
|
||||
|
@ -346,10 +377,23 @@ GL_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr)
|
|||
}
|
||||
|
||||
if (f) {
|
||||
struct mdfour md;
|
||||
|
||||
mdfour_begin (&md);
|
||||
mdfour_update (&md, (unsigned char*)&numcommands, 4);
|
||||
mdfour_update (&md, (unsigned char*)&numorder, 4);
|
||||
mdfour_update (&md, (unsigned char*)&commands, numcommands * sizeof (commands[0]));
|
||||
mdfour_update (&md, (unsigned char*)&vertexorder,
|
||||
numorder * sizeof (vertexorder[0]));
|
||||
mdfour_update (&md, model_digest, MDFOUR_DIGEST_BYTES);
|
||||
mdfour_result (&md, mesh_digest);
|
||||
|
||||
Qwrite (f, &numcommands, 4);
|
||||
Qwrite (f, &numorder, 4);
|
||||
Qwrite (f, &commands, numcommands * sizeof (commands[0]));
|
||||
Qwrite (f, &vertexorder, numorder * sizeof (vertexorder[0]));
|
||||
Qwrite (f, model_digest, MDFOUR_DIGEST_BYTES);
|
||||
Qwrite (f, mesh_digest, MDFOUR_DIGEST_BYTES);
|
||||
Qclose (f);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ extern model_t *loadmodel;
|
|||
void *Mod_LoadAllSkins (int numskins, daliasskintype_t *pskintype,
|
||||
|
||||
int *pskinindex);
|
||||
void GL_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr);
|
||||
void GL_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *model, int size);
|
||||
|
||||
/*
|
||||
==============================================================================
|
||||
|
@ -254,7 +254,7 @@ Mod_LoadAliasModel (model_t *mod, void *buffer)
|
|||
//
|
||||
// build the draw lists
|
||||
//
|
||||
GL_MakeAliasModelDisplayLists (mod, pheader);
|
||||
GL_MakeAliasModelDisplayLists (mod, pheader, buffer, com_filesize);
|
||||
|
||||
//
|
||||
// move the complete, relocatable alias model to the cache
|
||||
|
|
|
@ -169,7 +169,7 @@ Mod_LoadAllSkins (int numskins, daliasskintype_t *pskintype, int *pskinindex)
|
|||
}
|
||||
|
||||
void
|
||||
GL_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr)
|
||||
GL_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m, int _s)
|
||||
{
|
||||
int i, j;
|
||||
stvert_t *pstverts;
|
||||
|
|
Loading…
Reference in a new issue