From 66b28a26a1923eba6523ee0da19e9a2d0b8fb40c Mon Sep 17 00:00:00 2001 From: lordhavoc Date: Sun, 28 Apr 2002 19:37:59 +0000 Subject: [PATCH] fix for savegames containing newlines inside strings (now they are converted to escape codes, which COM_Parse will happily dismantle again when loading) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@1779 d7cf8633-e32d-0410-b094-e92efae38249 --- pr_edict.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/pr_edict.c b/pr_edict.c index 78fd1176..23a05d1f 100644 --- a/pr_edict.c +++ b/pr_edict.c @@ -452,10 +452,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 +474,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 +510,7 @@ char *PR_UglyValueString (etype_t type, eval_t *val) sprintf (line, "bad type %i", type); break; } - + return line; } @@ -645,7 +668,7 @@ void ED_Write (QFile *f, edict_t *ed) Qprintf (f, "}\n"); return; } - + for (i=1 ; inumfielddefs ; i++) { d = &pr_fielddefs[i]; -- 2.39.2