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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
|
/*
Copyright (C) 1997-2001 Id Software, Inc.
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.
*/
//
// cl_precache.c
//
#include "client.h"
/*
================
CL_ParsePlayerSkin
Breaks up playerskin into name (optional), model and skin components.
If model or skin are found to be invalid, replaces them with sane defaults.
================
*/
void CL_ParsePlayerSkin(char *name, char *model, char *skin, const char *s)
{
size_t len;
char *t;
// configstring parsing guarantees that playerskins can never
// overflow, but still check the length to be entirely fool-proof
len = strlen(s);
if (len >= MAX_QPATH) {
Com_Error(ERR_DROP, "%s: oversize playerskin", __func__);
}
// isolate the player's name
t = strchr(s, '\\');
if (t) {
len = t - s;
strcpy(model, t + 1);
} else {
len = 0;
strcpy(model, s);
}
// copy the player's name
if (name) {
memcpy(name, s, len);
name[len] = 0;
}
// isolate the model name
t = strchr(model, '/');
if (!t)
t = strchr(model, '\\');
if (!t)
goto default_model;
*t = 0;
// isolate the skin name
strcpy(skin, t + 1);
// fix empty model to male
if (t == model)
strcpy(model, "male");
// apply restrictions on skins
if (cl_noskins->integer == 2 || !COM_IsPath(skin))
goto default_skin;
if (cl_noskins->integer || !COM_IsPath(model))
goto default_model;
return;
default_skin:
if (!Q_stricmp(model, "female")) {
strcpy(model, "female");
strcpy(skin, "athena");
} else {
default_model:
strcpy(model, "male");
strcpy(skin, "grunt");
}
}
/*
================
CL_LoadClientinfo
================
*/
void CL_LoadClientinfo(clientinfo_t *ci, const char *s)
{
int i;
char model_name[MAX_QPATH];
char skin_name[MAX_QPATH];
char model_filename[MAX_QPATH];
char skin_filename[MAX_QPATH];
char weapon_filename[MAX_QPATH];
char icon_filename[MAX_QPATH];
CL_ParsePlayerSkin(ci->name, model_name, skin_name, s);
// model file
Q_concat(model_filename, sizeof(model_filename),
"players/", model_name, "/tris.md2", NULL);
ci->model = R_RegisterModel(model_filename);
if (!ci->model && Q_stricmp(model_name, "male")) {
strcpy(model_name, "male");
strcpy(model_filename, "players/male/tris.md2");
ci->model = R_RegisterModel(model_filename);
}
// skin file
Q_concat(skin_filename, sizeof(skin_filename),
"players/", model_name, "/", skin_name, ".pcx", NULL);
ci->skin = R_RegisterSkin(skin_filename);
// if we don't have the skin and the model was female,
// see if athena skin exists
if (!ci->skin && !Q_stricmp(model_name, "female")) {
strcpy(skin_name, "athena");
strcpy(skin_filename, "players/female/athena.pcx");
ci->skin = R_RegisterSkin(skin_filename);
}
// if we don't have the skin and the model wasn't male,
// see if the male has it (this is for CTF's skins)
if (!ci->skin && Q_stricmp(model_name, "male")) {
// change model to male
strcpy(model_name, "male");
strcpy(model_filename, "players/male/tris.md2");
ci->model = R_RegisterModel(model_filename);
// see if the skin exists for the male model
Q_concat(skin_filename, sizeof(skin_filename),
"players/male/", skin_name, ".pcx", NULL);
ci->skin = R_RegisterSkin(skin_filename);
}
// if we still don't have a skin, it means that the male model
// didn't have it, so default to grunt
if (!ci->skin) {
// see if the skin exists for the male model
strcpy(skin_name, "grunt");
strcpy(skin_filename, "players/male/grunt.pcx");
ci->skin = R_RegisterSkin(skin_filename);
}
// weapon file
for (i = 0; i < cl.numWeaponModels; i++) {
Q_concat(weapon_filename, sizeof(weapon_filename),
"players/", model_name, "/", cl.weaponModels[i], NULL);
ci->weaponmodel[i] = R_RegisterModel(weapon_filename);
if (!ci->weaponmodel[i] && !Q_stricmp(model_name, "cyborg")) {
// try male
Q_concat(weapon_filename, sizeof(weapon_filename),
"players/male/", cl.weaponModels[i], NULL);
ci->weaponmodel[i] = R_RegisterModel(weapon_filename);
}
}
// icon file
Q_concat(icon_filename, sizeof(icon_filename),
"/players/", model_name, "/", skin_name, "_i.pcx", NULL);
ci->icon = R_RegisterPic2(icon_filename);
strcpy(ci->model_name, model_name);
strcpy(ci->skin_name, skin_name);
// base info should be at least partially valid
if (ci == &cl.baseclientinfo)
return;
// must have loaded all data types to be valid
if (!ci->skin || !ci->icon || !ci->model || !ci->weaponmodel[0]) {
ci->skin = 0;
ci->icon = 0;
ci->model = 0;
ci->weaponmodel[0] = 0;
ci->model_name[0] = 0;
ci->skin_name[0] = 0;
}
}
/*
=================
CL_RegisterSounds
=================
*/
void CL_RegisterSounds(void)
{
int i;
char *s;
S_BeginRegistration();
CL_RegisterTEntSounds();
for (i = 1; i < MAX_SOUNDS; i++) {
s = cl.configstrings[CS_SOUNDS + i];
if (!s[0])
break;
cl.sound_precache[i] = S_RegisterSound(s);
}
S_EndRegistration();
}
/*
=================
CL_RegisterBspModels
Registers main BSP file and inline models
=================
*/
void CL_RegisterBspModels(void)
{
qerror_t ret;
char *name;
int i;
ret = BSP_Load(cl.configstrings[CS_MODELS + 1], &cl.bsp);
if (cl.bsp == NULL) {
Com_Error(ERR_DROP, "Couldn't load %s: %s",
cl.configstrings[CS_MODELS + 1], Q_ErrorString(ret));
}
#if USE_MAPCHECKSUM
if (cl.bsp->checksum != atoi(cl.configstrings[CS_MAPCHECKSUM])) {
if (cls.demo.playback) {
Com_WPrintf("Local map version differs from demo: %i != %s\n",
cl.bsp->checksum, cl.configstrings[CS_MAPCHECKSUM]);
} else {
Com_Error(ERR_DROP, "Local map version differs from server: %i != %s",
cl.bsp->checksum, cl.configstrings[CS_MAPCHECKSUM]);
}
}
#endif
for (i = 1; i < MAX_MODELS; i++) {
name = cl.configstrings[CS_MODELS + i];
if (!name[0]) {
break;
}
if (name[0] == '*')
cl.model_clip[i] = BSP_InlineModel(cl.bsp, name);
else
cl.model_clip[i] = NULL;
}
}
/*
=================
CL_RegisterVWepModels
Builds a list of visual weapon models
=================
*/
void CL_RegisterVWepModels(void)
{
int i;
char *name;
cl.numWeaponModels = 1;
strcpy(cl.weaponModels[0], "weapon.md2");
// only default model when vwep is off
if (!cl_vwep->integer) {
return;
}
for (i = 2; i < MAX_MODELS; i++) {
name = cl.configstrings[CS_MODELS + i];
if (!name[0]) {
break;
}
if (name[0] != '#') {
continue;
}
// special player weapon model
strcpy(cl.weaponModels[cl.numWeaponModels++], name + 1);
if (cl.numWeaponModels == MAX_CLIENTWEAPONMODELS) {
break;
}
}
}
/*
=================
CL_SetSky
=================
*/
void CL_SetSky(void)
{
float rotate;
vec3_t axis;
rotate = atof(cl.configstrings[CS_SKYROTATE]);
if (sscanf(cl.configstrings[CS_SKYAXIS], "%f %f %f",
&axis[0], &axis[1], &axis[2]) != 3) {
Com_DPrintf("Couldn't parse CS_SKYAXIS\n");
VectorClear(axis);
}
R_SetSky(cl.configstrings[CS_SKY], rotate, axis);
}
/*
=================
CL_PrepRefresh
Call before entering a new level, or after changing dlls
=================
*/
void CL_PrepRefresh(void)
{
int i;
char *name;
if (!cls.ref_initialized)
return;
if (!cl.mapname[0])
return; // no map loaded
// register models, pics, and skins
R_BeginRegistration(cl.mapname);
CL_LoadState(LOAD_MODELS);
CL_RegisterTEntModels();
for (i = 2; i < MAX_MODELS; i++) {
name = cl.configstrings[CS_MODELS + i];
if (!name[0]) {
break;
}
if (name[0] == '#') {
continue;
}
cl.model_draw[i] = R_RegisterModel(name);
}
CL_LoadState(LOAD_IMAGES);
for (i = 1; i < MAX_IMAGES; i++) {
name = cl.configstrings[CS_IMAGES + i];
if (!name[0]) {
break;
}
cl.image_precache[i] = R_RegisterPic2(name);
}
CL_LoadState(LOAD_CLIENTS);
for (i = 0; i < MAX_CLIENTS; i++) {
name = cl.configstrings[CS_PLAYERSKINS + i];
if (!name[0]) {
continue;
}
CL_LoadClientinfo(&cl.clientinfo[i], name);
}
CL_LoadClientinfo(&cl.baseclientinfo, "unnamed\\male/grunt");
// set sky textures and speed
CL_SetSky();
// the renderer can now free unneeded stuff
R_EndRegistration();
// clear any lines of console text
Con_ClearNotify_f();
SCR_UpdateScreen();
}
/*
=================
CL_UpdateConfigstring
A configstring update has been parsed.
=================
*/
void CL_UpdateConfigstring(int index)
{
const char *s = cl.configstrings[index];
if (index == CS_MAXCLIENTS) {
cl.maxclients = atoi(s);
return;
}
if (index == CS_AIRACCEL) {
if (cl.pmp.qwmode)
cl.pmp.airaccelerate = qtrue;
else
cl.pmp.airaccelerate = atoi(s) ? qtrue : qfalse;
return;
}
if (index == CS_MODELS + 1) {
size_t len = strlen(s);
if (len <= 9) {
Com_Error(ERR_DROP, "%s: bad world model: %s", __func__, s);
}
memcpy(cl.mapname, s + 5, len - 9); // skip "maps/"
cl.mapname[len - 9] = 0; // cut off ".bsp"
return;
}
#if USE_LIGHTSTYLES
if (index >= CS_LIGHTS && index < CS_LIGHTS + MAX_LIGHTSTYLES) {
CL_SetLightStyle(index - CS_LIGHTS, s);
return;
}
#endif
if (cls.state < ca_precached) {
return;
}
if (index >= CS_MODELS + 2 && index < CS_MODELS + MAX_MODELS) {
int i = index - CS_MODELS;
cl.model_draw[i] = R_RegisterModel(s);
if (*s == '*')
cl.model_clip[i] = BSP_InlineModel(cl.bsp, s);
else
cl.model_clip[i] = NULL;
return;
}
if (index >= CS_SOUNDS && index < CS_SOUNDS + MAX_SOUNDS) {
cl.sound_precache[index - CS_SOUNDS] = S_RegisterSound(s);
return;
}
if (index >= CS_IMAGES && index < CS_IMAGES + MAX_IMAGES) {
cl.image_precache[index - CS_IMAGES] = R_RegisterPic2(s);
return;
}
if (index >= CS_PLAYERSKINS && index < CS_PLAYERSKINS + MAX_CLIENTS) {
CL_LoadClientinfo(&cl.clientinfo[index - CS_PLAYERSKINS], s);
return;
}
}
|