]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Properly unescape escaped characters in save file when loading (#185)
authorITdevkc <132387209+ITdevkc@users.noreply.github.com>
Mon, 22 Jul 2024 20:27:37 +0000 (16:27 -0400)
committerGitHub <noreply@github.com>
Mon, 22 Jul 2024 20:27:37 +0000 (06:27 +1000)
Modified PRVM_ED_ParseEdict to determine whether it is loading a save or
not, and unescape variables if loading a save.
Fixes https://github.com/DarkPlacesEngine/darkplaces/issues/81

---------

Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
Co-authored-by: bones_was_here <bones_was_here@xonotic.au>
progsvm.h
prvm_cmds.c
prvm_edict.c
sv_save.c

index 32632f30f9799e100fe30abb693f4da95e5b0db0..fbbb7a0a028a82c208d5d1ec862833d9db2b51bf 100644 (file)
--- a/progsvm.h
+++ b/progsvm.h
@@ -850,7 +850,7 @@ void PRVM_ED_ClearEdict(prvm_prog_t *prog, prvm_edict_t *e);
 void PRVM_PrintFunctionStatements(prvm_prog_t *prog, const char *name);
 void PRVM_ED_Print(prvm_prog_t *prog, prvm_edict_t *ed, const char *wildcard_fieldname);
 void PRVM_ED_Write(prvm_prog_t *prog, struct qfile_s *f, prvm_edict_t *ed);
-const char *PRVM_ED_ParseEdict(prvm_prog_t *prog, const char *data, prvm_edict_t *ent);
+const char *PRVM_ED_ParseEdict(prvm_prog_t *prog, const char *data, prvm_edict_t *ent, qbool saveload);
 
 void PRVM_ED_WriteGlobals(prvm_prog_t *prog, struct qfile_s *f);
 void PRVM_ED_ParseGlobals(prvm_prog_t *prog, const char *data);
index 1fb432c9824d4db3f4727924035e7c910df685ad..dbbd947a667c8889748e21d81339f616c738b326 100644 (file)
@@ -3069,7 +3069,7 @@ void VM_parseentitydata(prvm_prog_t *prog)
        if (!COM_ParseToken_Simple(&data, false, false, true) || com_token[0] != '{' )
                prog->error_cmd("VM_parseentitydata: %s: Couldn't parse entity data:\n%s", prog->name, data );
 
-       PRVM_ED_ParseEdict (prog, data, ent);
+       PRVM_ED_ParseEdict (prog, data, ent, false);
 }
 
 /*
index 4b732742fada18c2a07e3c8665dca09defbe47a8..d4a2120f2075970fb7361114ea3965c8f118eec9 100644 (file)
@@ -1276,7 +1276,7 @@ ed should be a properly initialized empty edict.
 Used for initial level load and for savegames.
 ====================
 */
-const char *PRVM_ED_ParseEdict (prvm_prog_t *prog, const char *data, prvm_edict_t *ent)
+const char *PRVM_ED_ParseEdict (prvm_prog_t *prog, const char *data, prvm_edict_t *ent, qbool saveload)
 {
        mdef_t *key;
        qbool anglehack;
@@ -1322,7 +1322,9 @@ const char *PRVM_ED_ParseEdict (prvm_prog_t *prog, const char *data, prvm_edict_
                }
 
        // parse value
-               if (!COM_ParseToken_Simple(&data, false, false, true))
+               // If loading a save, unescape characters (they're escaped when saving).
+               // Otherwise, load them as they are (BSP compilers don't support escaping).
+               if (!COM_ParseToken_Simple(&data, false, saveload, true))
                        prog->error_cmd("PRVM_ED_ParseEdict: EOF without closing brace");
                if (developer_entityparsing.integer)
                        Con_Printf(" \"%s\"\n", com_token);
@@ -1355,7 +1357,7 @@ const char *PRVM_ED_ParseEdict (prvm_prog_t *prog, const char *data, prvm_edict_
                        dpsnprintf (com_token, sizeof(com_token), "0 %s 0", temp);
                }
 
-               if (!PRVM_ED_ParseEpair(prog, ent, key, com_token, strcmp(keyname, "wad") != 0))
+               if (!PRVM_ED_ParseEpair(prog, ent, key, com_token, false))
                        prog->error_cmd("PRVM_ED_ParseEdict: parse error");
        }
 
@@ -1526,7 +1528,7 @@ void PRVM_ED_LoadFromFile (prvm_prog_t *prog, const char *data)
                if (ent != prog->edicts)        // hack
                        memset (ent->fields.fp, 0, prog->entityfields * sizeof(prvm_vec_t));
 
-               data = PRVM_ED_ParseEdict (prog, data, ent);
+               data = PRVM_ED_ParseEdict (prog, data, ent, false);
                parsed++;
 
                // remove the entity ?
index 414e97a9b7a4716fee30f3bbc36cdb7a47cf1ee5..39e1f78352dab7c666753526264486cedc4476b9 100644 (file)
--- a/sv_save.c
+++ b/sv_save.c
@@ -434,7 +434,7 @@ void SV_Loadgame_f(cmd_state_t *cmd)
                        if(developer_entityparsing.integer)
                                Con_Printf("SV_Loadgame_f: loading edict %d\n", entnum);
 
-                       PRVM_ED_ParseEdict (prog, start, ent);
+                       PRVM_ED_ParseEdict (prog, start, ent, true);
 
                        // link it into the bsp tree
                        if (!ent->free)