]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_parse.c
Fix texture binding issues that were breaking r_shadow_bouncegrid.
[xonotic/darkplaces.git] / cl_parse.c
index 3ae26aa9657e1f9f92824ea7513494d0b65cf1be..5d8ff31fa2f1a6a66e7f4233ec50534647d6602e 100644 (file)
@@ -20,9 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 // cl_parse.c  -- parse a message received from the server
 
 #include "quakedef.h"
-#ifdef CONFIG_CD
 #include "cdaudio.h"
-#endif
 #include "cl_collision.h"
 #include "csprogs.h"
 #include "libcurl.h"
@@ -208,7 +206,7 @@ static void CL_ParseStartSoundPacket(int largesoundindex)
        vec3_t  pos;
        int     channel, ent;
        int     sound_num;
-       int     volume;
+       int     nvolume;
        int     field_mask;
        float   attenuation;
        float   speed;
@@ -219,15 +217,15 @@ static void CL_ParseStartSoundPacket(int largesoundindex)
                channel = MSG_ReadShort(&cl_message);
 
                if (channel & (1<<15))
-                       volume = MSG_ReadByte(&cl_message);
+                       nvolume = MSG_ReadByte(&cl_message);
                else
-                       volume = DEFAULT_SOUND_PACKET_VOLUME;
+                       nvolume = DEFAULT_SOUND_PACKET_VOLUME;
 
                if (channel & (1<<14))
                        attenuation = MSG_ReadByte(&cl_message) / 64.0;
                else
                        attenuation = DEFAULT_SOUND_PACKET_ATTENUATION;
-       
+
                speed = 1.0f;
 
                ent = (channel>>3)&1023;
@@ -240,9 +238,9 @@ static void CL_ParseStartSoundPacket(int largesoundindex)
                field_mask = MSG_ReadByte(&cl_message);
 
                if (field_mask & SND_VOLUME)
-                       volume = MSG_ReadByte(&cl_message);
+                       nvolume = MSG_ReadByte(&cl_message);
                else
-                       volume = DEFAULT_SOUND_PACKET_VOLUME;
+                       nvolume = DEFAULT_SOUND_PACKET_VOLUME;
 
                if (field_mask & SND_ATTENUATION)
                        attenuation = MSG_ReadByte(&cl_message) / 64.0;
@@ -276,7 +274,7 @@ static void CL_ParseStartSoundPacket(int largesoundindex)
 
        MSG_ReadVector(&cl_message, pos, cls.protocol);
 
-       if (sound_num >= MAX_SOUNDS)
+       if (sound_num < 0 || sound_num >= MAX_SOUNDS)
        {
                Con_Printf("CL_ParseStartSoundPacket: sound_num (%i) >= MAX_SOUNDS (%i)\n", sound_num, MAX_SOUNDS);
                return;
@@ -291,8 +289,8 @@ static void CL_ParseStartSoundPacket(int largesoundindex)
        if (ent >= cl.max_entities)
                CL_ExpandEntities(ent);
 
-       if( !CL_VM_Event_Sound(sound_num, volume / 255.0f, channel, attenuation, ent, pos, fflags, speed) )
-               S_StartSound_StartPosition_Flags (ent, channel, cl.sound_precache[sound_num], pos, volume/255.0f, attenuation, 0, fflags, speed);
+       if( !CL_VM_Event_Sound(sound_num, nvolume / 255.0f, channel, attenuation, ent, pos, fflags, speed) )
+               S_StartSound_StartPosition_Flags (ent, channel, cl.sound_precache[sound_num], pos, nvolume/255.0f, attenuation, 0, fflags, speed);
 }
 
 /*
@@ -366,7 +364,7 @@ void CL_KeepaliveMessage (qboolean readmessages)
                unsigned char           buf[4];
                countdownmsg = 5;
                // write out a nop
-               // LordHavoc: must use unreliable because reliable could kill the sigon message!
+               // LadyHavoc: must use unreliable because reliable could kill the sigon message!
                Con_Print("--> client to server keepalive\n");
                memset(&msg, 0, sizeof(msg));
                msg.data = buf;
@@ -380,10 +378,11 @@ void CL_KeepaliveMessage (qboolean readmessages)
 
 void CL_ParseEntityLump(char *entdata)
 {
+       qboolean loadedsky = false;
        const char *data;
        char key[128], value[MAX_INPUTLINE];
-       FOG_clear(); // LordHavoc: no fog until set
-       // LordHavoc: default to the map's sky (q3 shader parsing sets this)
+       FOG_clear(); // LadyHavoc: no fog until set
+       // LadyHavoc: default to the map's sky (q3 shader parsing sets this)
        R_SetSkyBox(cl.worldmodel->brush.skybox);
        data = entdata;
        if (!data)
@@ -408,11 +407,20 @@ void CL_ParseEntityLump(char *entdata)
                        return; // error
                strlcpy (value, com_token, sizeof (value));
                if (!strcmp("sky", key))
+               {
+                       loadedsky = true;
                        R_SetSkyBox(value);
+               }
                else if (!strcmp("skyname", key)) // non-standard, introduced by QuakeForge... sigh.
+               {
+                       loadedsky = true;
                        R_SetSkyBox(value);
+               }
                else if (!strcmp("qlsky", key)) // non-standard, introduced by QuakeLives (EEK)
+               {
+                       loadedsky = true;
                        R_SetSkyBox(value);
+               }
                else if (!strcmp("fog", key))
                {
                        FOG_clear(); // so missing values get good defaults
@@ -455,6 +463,9 @@ void CL_ParseEntityLump(char *entdata)
                        r_refdef.fog_height_texturename[63] = 0;
                }
        }
+
+       if (!loadedsky && cl.worldmodel->brush.isq2bsp)
+               R_SetSkyBox("unit1_");
 }
 
 static const vec3_t defaultmins = {-4096, -4096, -4096};
@@ -573,6 +584,12 @@ static void QW_CL_RequestNextDownload(void)
        // clear name of file that just finished
        cls.qw_downloadname[0] = 0;
 
+       // skip the download fragment if playing a demo
+       if (!cls.netcon)
+       {
+               return;
+       }
+
        switch (cls.qw_downloadtype)
        {
        case dl_single:
@@ -1026,7 +1043,7 @@ static void QW_CL_ParseNails(void)
        {
                for (j = 0;j < 6;j++)
                        bits[j] = MSG_ReadByte(&cl_message);
-               if (cl.qw_num_nails > 255)
+               if (cl.qw_num_nails >= 255)
                        continue;
                v = cl.qw_nails[cl.qw_num_nails++];
                v[0] = ( ( bits[0] + ((bits[1]&15)<<8) ) <<1) - 4096;
@@ -1220,7 +1237,7 @@ static void CL_BeginDownloads(qboolean aborteddownload)
                // finished loading sounds
        }
 
-       if(gamemode == GAME_NEXUIZ || gamemode == GAME_XONOTIC)
+       if(IS_NEXUIZ_DERIVED(gamemode))
                Cvar_SetValueQuick(&cl_serverextension_download, false);
                // in Nexuiz/Xonotic, the built in download protocol is kinda broken (misses lots
                // of dependencies) anyway, and can mess around with the game directory;
@@ -1377,7 +1394,7 @@ static void CL_StopDownload(int size, int crc)
                        {
                                Con_Printf("Inflated download: new size: %u (%g%%)\n", (unsigned)inflated_size, 100.0 - 100.0*(cls.qw_downloadmemorycursize / (float)inflated_size));
                                cls.qw_downloadmemory = out;
-                               cls.qw_downloadmemorycursize = inflated_size;
+                               cls.qw_downloadmemorycursize = (int)inflated_size;
                        }
                        else
                        {
@@ -1399,7 +1416,7 @@ static void CL_StopDownload(int size, int crc)
                        // save to disk only if we don't already have it
                        // (this is mainly for playing back demos)
                        existingcrc = FS_CRCFile(cls.qw_downloadname, &existingsize);
-                       if (existingsize || gamemode == GAME_NEXUIZ || gamemode == GAME_XONOTIC || !strcmp(cls.qw_downloadname, csqc_progname.string))
+                       if (existingsize || IS_NEXUIZ_DERIVED(gamemode) || !strcmp(cls.qw_downloadname, csqc_progname.string))
                                // let csprogs ALWAYS go to dlcache, to prevent "viral csprogs"; also, never put files outside dlcache for Nexuiz/Xonotic
                        {
                                if ((int)existingsize != size || existingcrc != crc)
@@ -1614,11 +1631,11 @@ static void CL_SignonReply (void)
        case 2:
                if (cls.netcon)
                {
-                       // LordHavoc: quake sent the player info here but due to downloads
+                       // LadyHavoc: quake sent the player info here but due to downloads
                        // it is sent earlier instead
                        // CL_SendPlayerInfo();
 
-                       // LordHavoc: changed to begin a loading stage and issue this when done
+                       // LadyHavoc: changed to begin a loading stage and issue this when done
                        MSG_WriteByte (&cls.netcon->message, clc_stringcmd);
                        MSG_WriteString (&cls.netcon->message, "spawn");
                }
@@ -2185,7 +2202,7 @@ static void CL_ParseClientdata (void)
                }
        }
 
-       // LordHavoc: hipnotic demos don't have this bit set but should
+       // LadyHavoc: hipnotic demos don't have this bit set but should
        if (bits & SU_ITEMS || cls.protocol == PROTOCOL_QUAKE || cls.protocol == PROTOCOL_QUAKEDP || cls.protocol == PROTOCOL_NEHAHRAMOVIE || cls.protocol == PROTOCOL_NEHAHRABJP || cls.protocol == PROTOCOL_NEHAHRABJP2 || cls.protocol == PROTOCOL_NEHAHRABJP3 || cls.protocol == PROTOCOL_DARKPLACES1 || cls.protocol == PROTOCOL_DARKPLACES2 || cls.protocol == PROTOCOL_DARKPLACES3 || cls.protocol == PROTOCOL_DARKPLACES4 || cls.protocol == PROTOCOL_DARKPLACES5)
                cl.stats[STAT_ITEMS] = MSG_ReadLong(&cl_message);
 
@@ -2219,7 +2236,7 @@ static void CL_ParseClientdata (void)
                cl.stats[STAT_NAILS] = MSG_ReadByte(&cl_message);
                cl.stats[STAT_ROCKETS] = MSG_ReadByte(&cl_message);
                cl.stats[STAT_CELLS] = MSG_ReadByte(&cl_message);
-               if (gamemode == GAME_HIPNOTIC || gamemode == GAME_ROGUE || gamemode == GAME_QUOTH || gamemode == GAME_NEXUIZ)
+               if (gamemode == GAME_HIPNOTIC || gamemode == GAME_ROGUE || gamemode == GAME_QUOTH || IS_OLDNEXUIZ_DERIVED(gamemode))
                        cl.stats[STAT_ACTIVEWEAPON] = (1<<MSG_ReadByte(&cl_message));
                else
                        cl.stats[STAT_ACTIVEWEAPON] = MSG_ReadByte(&cl_message);
@@ -2292,6 +2309,13 @@ static void CL_ParseStaticSound (int large)
                sound_num = (unsigned short) MSG_ReadShort(&cl_message);
        else
                sound_num = MSG_ReadByte(&cl_message);
+
+       if (sound_num < 0 || sound_num >= MAX_SOUNDS)
+       {
+               Con_Printf("CL_ParseStaticSound: sound_num(%i) >= MAX_SOUNDS (%i)\n", sound_num, MAX_SOUNDS);
+               return;
+       }
+
        vol = MSG_ReadByte(&cl_message);
        atten = MSG_ReadByte(&cl_message);
 
@@ -2631,7 +2655,7 @@ static void CL_ParseTempEntity(void)
                                        S_StartSound(-1, 0, cl.sfx_ric3, pos, 1, 1);
                        }
                        break;
-                       // LordHavoc: added for improved blood splatters
+                       // LadyHavoc: added for improved blood splatters
                case TE_BLOOD:
                        // blood puff
                        MSG_ReadVector(&cl_message, pos, cls.protocol);
@@ -2657,7 +2681,7 @@ static void CL_ParseTempEntity(void)
                        CL_FindNonSolidLocation(pos, pos, 4);
                        CL_ParticleEffect(EFFECT_TE_PLASMABURN, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
                        break;
-                       // LordHavoc: added for improved gore
+                       // LadyHavoc: added for improved gore
                case TE_BLOODSHOWER:
                        // vaporized body
                        MSG_ReadVector(&cl_message, pos, cls.protocol); // mins
@@ -2846,7 +2870,7 @@ static void CL_ParseTempEntity(void)
                        break;
        // PGM 01/21/97
 
-       // LordHavoc: for compatibility with the Nehahra movie...
+       // LadyHavoc: for compatibility with the Nehahra movie...
                case TE_LIGHTNING4NEH:
                        CL_ParseBeam(Mod_ForName(MSG_ReadString(&cl_message, cl_readstring, sizeof(cl_readstring)), true, false, NULL), false);
                        break;
@@ -2867,6 +2891,8 @@ static void CL_ParseTempEntity(void)
                        CL_FindNonSolidLocation(pos, pos, 10);
                        colorStart = MSG_ReadByte(&cl_message);
                        colorLength = MSG_ReadByte(&cl_message);
+                       if (colorLength == 0)
+                               colorLength = 1;
                        CL_ParticleExplosion2(pos, colorStart, colorLength);
                        tempcolor = palette_rgb[(rand()%colorLength) + colorStart];
                        color[0] = tempcolor[0] * (2.0f / 255.0f);
@@ -3373,7 +3399,7 @@ void CL_ParseServerMessage(void)
        qboolean        strip_pqc;
        char vabuf[1024];
 
-       // LordHavoc: moved demo message writing from before the packet parse to
+       // LadyHavoc: moved demo message writing from before the packet parse to
        // after the packet parse so that CL_Stop_f can be called by cl_autodemo
        // code in CL_ParseServerinfo
        //if (cls.demorecording)
@@ -3433,9 +3459,9 @@ void CL_ParseServerMessage(void)
                        cmdlogname[cmdindex] = qw_svc_strings[cmd];
                        if (!cmdlogname[cmdindex])
                        {
-                               // LordHavoc: fix for bizarre problem in MSVC that I do not understand (if I assign the string pointer directly it ends up storing a NULL pointer)
-                               temp = "<unknown>";
-                               cmdlogname[cmdindex] = temp;
+                               // LadyHavoc: fix for bizarre problem in MSVC that I do not understand (if I assign the string pointer directly it ends up storing a NULL pointer)
+                               const char *d = "<unknown>";
+                               cmdlogname[cmdindex] = d;
                        }
 
                        // other commands
@@ -3443,7 +3469,7 @@ void CL_ParseServerMessage(void)
                        {
                        default:
                                {
-                                       char description[32*64], temp[64];
+                                       char description[32*64], logtemp[64];
                                        int count;
                                        strlcpy(description, "packet dump: ", sizeof(description));
                                        i = cmdcount - 32;
@@ -3453,8 +3479,8 @@ void CL_ParseServerMessage(void)
                                        i &= 31;
                                        while(count > 0)
                                        {
-                                               dpsnprintf(temp, sizeof(temp), "%3i:%s ", cmdlog[i], cmdlogname[i]);
-                                               strlcat(description, temp, sizeof(description));
+                                               dpsnprintf(logtemp, sizeof(logtemp), "%3i:%s ", cmdlog[i], cmdlogname[i]);
+                                               strlcat(description, logtemp, sizeof(description));
                                                count--;
                                                i++;
                                                i &= 31;
@@ -3614,12 +3640,10 @@ void CL_ParseServerMessage(void)
 
                        case qw_svc_cdtrack:
                                cl.cdtrack = cl.looptrack = MSG_ReadByte(&cl_message);
-#ifdef CONFIG_CD
                                if ( (cls.demoplayback || cls.demorecording) && (cls.forcetrack != -1) )
                                        CDAudio_Play ((unsigned char)cls.forcetrack, true);
                                else
                                        CDAudio_Play ((unsigned char)cl.cdtrack, true);
-#endif
                                break;
 
                        case qw_svc_intermission:
@@ -3738,12 +3762,10 @@ void CL_ParseServerMessage(void)
 
                        case qw_svc_setpause:
                                cl.paused = MSG_ReadByte(&cl_message) != 0;
-#ifdef CONFIG_CD
                                if (cl.paused)
                                        CDAudio_Pause ();
                                else
                                        CDAudio_Resume ();
-#endif
                                S_PauseGameSounds (cl.paused);
                                break;
                        }
@@ -3780,7 +3802,7 @@ void CL_ParseServerMessage(void)
                        // if the high bit of the command byte is set, it is a fast update
                        if (cmd & 128)
                        {
-                               // LordHavoc: fix for bizarre problem in MSVC that I do not understand (if I assign the string pointer directly it ends up storing a NULL pointer)
+                               // LadyHavoc: fix for bizarre problem in MSVC that I do not understand (if I assign the string pointer directly it ends up storing a NULL pointer)
                                temp = "entity";
                                cmdlogname[cmdindex] = temp;
                                SHOWNET("fast update");
@@ -3798,9 +3820,9 @@ void CL_ParseServerMessage(void)
                        cmdlogname[cmdindex] = svc_strings[cmd];
                        if (!cmdlogname[cmdindex])
                        {
-                               // LordHavoc: fix for bizarre problem in MSVC that I do not understand (if I assign the string pointer directly it ends up storing a NULL pointer)
-                               temp = "<unknown>";
-                               cmdlogname[cmdindex] = temp;
+                               // LadyHavoc: fix for bizarre problem in MSVC that I do not understand (if I assign the string pointer directly it ends up storing a NULL pointer)
+                               const char *d = "<unknown>";
+                               cmdlogname[cmdindex] = d;
                        }
 
                        // other commands
@@ -3808,7 +3830,7 @@ void CL_ParseServerMessage(void)
                        {
                        default:
                                {
-                                       char description[32*64], temp[64];
+                                       char description[32*64], tempdesc[64];
                                        int count;
                                        strlcpy (description, "packet dump: ", sizeof(description));
                                        i = cmdcount - 32;
@@ -3818,8 +3840,8 @@ void CL_ParseServerMessage(void)
                                        i &= 31;
                                        while(count > 0)
                                        {
-                                               dpsnprintf (temp, sizeof (temp), "%3i:%s ", cmdlog[i], cmdlogname[i]);
-                                               strlcat (description, temp, sizeof (description));
+                                               dpsnprintf (tempdesc, sizeof (tempdesc), "%3i:%s ", cmdlog[i], cmdlogname[i]);
+                                               strlcat (description, tempdesc, sizeof (description));
                                                count--;
                                                i++;
                                                i &= 31;
@@ -3938,7 +3960,7 @@ void CL_ParseServerMessage(void)
                                        Host_Error("svc_setview >= MAX_EDICTS");
                                if (cl.viewentity >= cl.max_entities)
                                        CL_ExpandEntities(cl.viewentity);
-                               // LordHavoc: assume first setview recieved is the real player entity
+                               // LadyHavoc: assume first setview recieved is the real player entity
                                if (!cl.realplayerentity)
                                        cl.realplayerentity = cl.viewentity;
                                // update cl.playerentity to this one if it is a valid player
@@ -3970,8 +3992,9 @@ void CL_ParseServerMessage(void)
                                }
                                else
                                {
-                                       int i = (unsigned short)MSG_ReadShort(&cl_message);
-                                       char *s = MSG_ReadString(&cl_message, cl_readstring, sizeof(cl_readstring));
+                                       char *s;
+                                       i = (unsigned short)MSG_ReadShort(&cl_message);
+                                       s = MSG_ReadString(&cl_message, cl_readstring, sizeof(cl_readstring));
                                        if (i < 32768)
                                        {
                                                if (i >= 1 && i < MAX_MODELS)
@@ -4067,18 +4090,16 @@ void CL_ParseServerMessage(void)
 
                        case svc_setpause:
                                cl.paused = MSG_ReadByte(&cl_message) != 0;
-#ifdef CONFIG_CD
                                if (cl.paused)
                                        CDAudio_Pause ();
                                else
                                        CDAudio_Resume ();
-#endif
                                S_PauseGameSounds (cl.paused);
                                break;
 
                        case svc_signonnum:
                                i = MSG_ReadByte(&cl_message);
-                               // LordHavoc: it's rude to kick off the client if they missed the
+                               // LadyHavoc: it's rude to kick off the client if they missed the
                                // reconnect somehow, so allow signon 1 even if at signon 1
                                if (i <= cls.signon && i != 1)
                                        Host_Error ("Received signon %i when at %i", i, cls.signon);
@@ -4119,12 +4140,10 @@ void CL_ParseServerMessage(void)
                        case svc_cdtrack:
                                cl.cdtrack = MSG_ReadByte(&cl_message);
                                cl.looptrack = MSG_ReadByte(&cl_message);
-#ifdef CONFIG_CD
                                if ( (cls.demoplayback || cls.demorecording) && (cls.forcetrack != -1) )
                                        CDAudio_Play ((unsigned char)cls.forcetrack, true);
                                else
                                        CDAudio_Play ((unsigned char)cl.cdtrack, true);
-#endif
                                break;
 
                        case svc_intermission:
@@ -4233,7 +4252,7 @@ void CL_ParseServerMessage(void)
 
        parsingerror = false;
 
-       // LordHavoc: this was at the start of the function before cl_autodemo was
+       // LadyHavoc: this was at the start of the function before cl_autodemo was
        // implemented
        if (cls.demorecording)
        {