Skip to content

Commit

Permalink
models: check mda before md2 on load
Browse files Browse the repository at this point in the history
  • Loading branch information
0lvin committed Sep 15, 2024
1 parent 6ba618f commit 105b019
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
18 changes: 16 additions & 2 deletions src/client/refresh/files/models.c
Original file line number Diff line number Diff line change
Expand Up @@ -2894,6 +2894,17 @@ Mod_LoadModel_MDA_Text(const char *mod_name, char *curr_buff,
{
void *extradata, *base;
int base_size;
char *curr;

curr = base_model;
while (*curr)
{
if (*curr == '\\')
{
*curr = '/';
}
curr++;
}

base_size = read_file(base_model, (void **)&base);
if (base_size <= 0)
Expand Down Expand Up @@ -3250,12 +3261,13 @@ Mod_ReLoadSkins(struct image_s **skins, findimage_t find_image, loadimage_t load
else if (type == mod_alias)
{
dmdx_t *pheader;
int i;

pheader = (dmdx_t *)extradata;
if (pheader->ofs_imgbit && load_image)
{
byte* images = (byte *)pheader + pheader->ofs_imgbit;
int i;

for (i = 0; i < pheader->num_skins; i++)
{
skins[i] = load_image(
Expand All @@ -3269,7 +3281,9 @@ Mod_ReLoadSkins(struct image_s **skins, findimage_t find_image, loadimage_t load
}
else
{
for (i=0; i < pheader->num_skins; i++)
int i;

for (i = 0; i < pheader->num_skins; i++)
{
skins[i] = find_image((char *)pheader + pheader->ofs_skins + i*MAX_SKINNAME, it_skin);
}
Expand Down
12 changes: 6 additions & 6 deletions src/common/models.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,22 +287,22 @@ Mod_LoadFileWithoutExt(const char *namewe, void **buffer, const char* ext)
return filesize;
}

/* Check Quake 2 model */
Q_strlcpy(newname + tlen, ".md2", sizeof(newname));
/* Check Anachronox model definition */
Q_strlcpy(newname + tlen, ".mda", sizeof(newname));
filesize = FS_LoadFile(newname, buffer);
if (filesize > 0)
{
Com_DPrintf("%s: %s loaded as md2 (Quake 2/Anachronox)\n",
Com_DPrintf("%s: %s loaded as mda (Anachronox)\n",
__func__, namewe);
return filesize;
}

/* Check Anachronox model definition */
Q_strlcpy(newname + tlen, ".mda", sizeof(newname));
/* Check Quake 2 model */
Q_strlcpy(newname + tlen, ".md2", sizeof(newname));
filesize = FS_LoadFile(newname, buffer);
if (filesize > 0)
{
Com_DPrintf("%s: %s loaded as mda (Anachronox)\n",
Com_DPrintf("%s: %s loaded as md2 (Quake 2/Anachronox)\n",
__func__, namewe);
return filesize;
}
Expand Down
17 changes: 12 additions & 5 deletions src/game/g_spawn.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,15 @@ ED_CallSpawn(edict_t *ent)
}
}

i = DynamicSpawnSearch(ent->classname);
if (i >= 0)
if (dynamicentities && ndynamicentities)
{
DynamicSpawn(ent, &dynamicentities[i]);
i = DynamicSpawnSearch(ent->classname);
if (i >= 0)
{
DynamicSpawn(ent, &dynamicentities[i]);

return;
return;
}
}

gi.dprintf("%s doesn't have a spawn function\n", ent->classname);
Expand Down Expand Up @@ -1715,11 +1718,12 @@ DynamicIntParse(char *line, int *field)
static char *
DynamicFloatParse(char *line, float *field, int size)
{
char *next_section;
int i;

for (i = 0; i < size; i++)
{
char *next_section;

next_section = strchr(line, '|');
if (next_section)
{
Expand Down Expand Up @@ -1750,6 +1754,9 @@ DynamicSpawnInit(void)
buf = NULL;
len = 0;

dynamicentities = NULL;
ndynamicentities = 0;

/* load the file */
len = gi.FS_LoadFile("models/entity.dat", (void **)&raw);
if (len > 1)
Expand Down

0 comments on commit 105b019

Please sign in to comment.