]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - pr_edict.c
Someone has been programming QC too long. (At least it was QC related!)
[xonotic/darkplaces.git] / pr_edict.c
index 4b17da13476b603cc72106705503cc9f9b1c27ef..3b1a6b9d24e5d7e0db22badf1e52446881dfcc3c 100644 (file)
@@ -171,7 +171,7 @@ void FindEdictFieldOffsets(void)
        SV_PlayerPhysicsQC = ED_FindFunction ("SV_PlayerPhysics");
        // LordHavoc: support for endframe
        EndFrameQC = ED_FindFunction ("EndFrame");
-};
+}
 
 /*
 =================
@@ -350,39 +350,6 @@ dfunction_t *ED_FindFunction (char *name)
 }
 
 
-/*
-eval_t *GetEdictFieldValue(edict_t *ed, char *field)
-{
-       ddef_t                  *def = NULL;
-       int                             i;
-       static int              rep = 0;
-
-       for (i=0 ; i<GEFV_CACHESIZE ; i++)
-       {
-               if (!strcmp(field, gefvCache[i].field))
-               {
-                       def = gefvCache[i].pcache;
-                       goto Done;
-               }
-       }
-
-       def = ED_FindField (field);
-
-       if (strlen(field) < MAX_FIELD_LEN)
-       {
-               gefvCache[rep].pcache = def;
-               strcpy (gefvCache[rep].field, field);
-               rep ^= 1;
-       }
-
-Done:
-       if (!def)
-               return NULL;
-
-       return (eval_t *)((char *)&ed->v + def->ofs*4);
-}
-*/
-
 /*
 ============
 PR_ValueString
@@ -452,10 +419,12 @@ Easier to parse than PR_ValueString
 */
 char *PR_UglyValueString (etype_t type, eval_t *val)
 {
-       static char     line[256];
-       ddef_t          *def;
-       dfunction_t     *f;
-       
+       static char line[4096];
+       int i;
+       char *s;
+       ddef_t *def;
+       dfunction_t *f;
+
        type &= ~DEF_SAVEGLOBAL;
 
        switch (type)
@@ -472,7 +441,28 @@ char *PR_UglyValueString (etype_t type, eval_t *val)
                break;
        case ev_field:
                def = ED_FieldAtOfs ( val->_int );
-               sprintf (line, "%s", pr_strings + def->s_name);
+               // LordHavoc: parse the string a bit to turn special characters
+               // (like newline, specifically) into escape codes,
+               // this fixes saving games from various mods
+               //sprintf (line, "%s", pr_strings + def->s_name);
+               s = pr_strings + def->s_name;
+               for (i = 0;i < 4095 && *s;)
+               {
+                       if (*s == '\n')
+                       {
+                               line[i++] = '\\';
+                               line[i++] = 'n';
+                       }
+                       else if (*s == '\r')
+                       {
+                               line[i++] = '\\';
+                               line[i++] = 'r';
+                       }
+                       else
+                               line[i] = *s;
+                       s++;
+               }
+               line[i++] = 0;
                break;
        case ev_void:
                sprintf (line, "void");
@@ -487,7 +477,7 @@ char *PR_UglyValueString (etype_t type, eval_t *val)
                sprintf (line, "bad type %i", type);
                break;
        }
-       
+
        return line;
 }
 
@@ -645,7 +635,7 @@ void ED_Write (QFile *f, edict_t *ed)
                Qprintf (f, "}\n");
                return;
        }
-       
+
        for (i=1 ; i<progs->numfielddefs ; i++)
        {
                d = &pr_fielddefs[i];
@@ -1204,7 +1194,7 @@ void PR_LoadProgs (void)
 
        Con_DPrintf ("Programs occupy %iK.\n", com_filesize/1024);
 
-       pr_crc = CRC_Block((byte *)progs, com_filesize);
+       pr_crc = CRC_Block((qbyte *)progs, com_filesize);
 
 // byte swap the header
        for (i=0 ; i<sizeof(*progs)/4 ; i++)
@@ -1215,20 +1205,20 @@ void PR_LoadProgs (void)
        if (progs->crc != PROGHEADER_CRC)
                Host_Error ("progs.dat system vars have been modified, progdefs.h is out of date");
 
-       pr_functions = (dfunction_t *)((byte *)progs + progs->ofs_functions);
+       pr_functions = (dfunction_t *)((qbyte *)progs + progs->ofs_functions);
        pr_strings = (char *)progs + progs->ofs_strings;
-       pr_globaldefs = (ddef_t *)((byte *)progs + progs->ofs_globaldefs);
+       pr_globaldefs = (ddef_t *)((qbyte *)progs + progs->ofs_globaldefs);
 
        // we need to expand the fielddefs list to include all the engine fields,
        // so allocate a new place for it
-       infielddefs = (ddef_t *)((byte *)progs + progs->ofs_fielddefs);
+       infielddefs = (ddef_t *)((qbyte *)progs + progs->ofs_fielddefs);
        pr_fielddefs = Mem_Alloc(progs_mempool, (progs->numfielddefs + DPFIELDS) * sizeof(ddef_t));
 
-       pr_statements = (dstatement_t *)((byte *)progs + progs->ofs_statements);
+       pr_statements = (dstatement_t *)((qbyte *)progs + progs->ofs_statements);
 
        // moved edict_size calculation down below field adding code
 
-       pr_global_struct = (globalvars_t *)((byte *)progs + progs->ofs_globals);
+       pr_global_struct = (globalvars_t *)((qbyte *)progs + progs->ofs_globals);
        pr_globals = (float *)pr_global_struct;
 
 // byte swap the lumps
@@ -1472,20 +1462,12 @@ edict_t *EDICT_NUM_ERROR(int n)
        Host_Error ("EDICT_NUM: bad number %i", n);
        return NULL;
 }
-/*
-edict_t *EDICT_NUM(int n)
-{
-       if (n < 0 || n >= sv.max_edicts)
-               Sys_Error ("EDICT_NUM: bad number %i", n);
-       return (edict_t *)((byte *)sv.edicts+ (n)*pr_edict_size);
-}
-*/
 
 int NUM_FOR_EDICT(edict_t *e)
 {
        int             b;
 
-       b = (byte *)e - (byte *)sv.edicts;
+       b = (qbyte *)e - (qbyte *)sv.edicts;
        b = b / pr_edict_size;
 
        if (b < 0 || b >= sv.num_edicts)
@@ -1497,7 +1479,8 @@ int NoCrash_NUM_FOR_EDICT(edict_t *e)
 {
        int             b;
 
-       b = (byte *)e - (byte *)sv.edicts;
+       b = (qbyte *)e - (qbyte *)sv.edicts;
        b = b / pr_edict_size;
        return b;
 }
+