Skip to content

Commit c9f4ab0

Browse files
committed
fix(zq): correctly handle variable length title in all dmap reading/writing
6bd8a9a added support for variable length dmap titles, but only for the main dmap reading/writing code. This functionality is duplicated across dmap import/export and other places, but wasn't updated.
1 parent 9edf63b commit c9f4ab0

File tree

3 files changed

+49
-21
lines changed

3 files changed

+49
-21
lines changed

src/qst.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4612,6 +4612,9 @@ void clear_screen(mapscr *temp_scr)
46124612
temp_scr->zero_memory();
46134613
}
46144614

4615+
// NOTE: when modifying this, you need to also update:
4616+
// readonedmap, readdmaps, and FFScript::read_dmaps
4617+
// (and their associated write functions)
46154618
int32_t readdmaps(PACKFILE *f, zquestheader *Header, word, word, word start_dmap, word max_dmaps)
46164619
{
46174620
bool should_skip = legacy_skip_flags && get_bit(legacy_skip_flags, skip_dmaps);
@@ -4806,13 +4809,10 @@ int32_t readdmaps(PACKFILE *f, zquestheader *Header, word, word, word start_dmap
48064809
}
48074810
else
48084811
{
4809-
std::string tmptitle;
4810-
if (!p_getwstr(&tmptitle, f))
4812+
if (!p_getwstr(&tempDMap.title, f))
48114813
{
48124814
return qe_invalid;
48134815
}
4814-
tempDMap.title.reserve(tmptitle.size());
4815-
tempDMap.title = tmptitle;
48164816
}
48174817

48184818
if(!p_getstr(tempDMap.intro,sizeof(DMaps[0].intro)-1,f))

src/zc/ffscript.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48770,10 +48770,10 @@ void FFScript::write_dmaps(PACKFILE *f, int32_t vers_id)
4877048770
Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",15);
4877148771
}
4877248772

48773-
if(!pfwrite(&DMaps[i].title,sizeof(DMaps[0].title),f))
48774-
{
48775-
Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",16);
48776-
}
48773+
if(!p_putwstr(DMaps[i].title,f))
48774+
{
48775+
Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",16);
48776+
}
4877748777

4877848778
if(!pfwrite(&DMaps[i].intro,sizeof(DMaps[0].intro),f))
4877948779
{
@@ -48958,7 +48958,7 @@ void FFScript::read_dmaps(PACKFILE *f, int32_t vers_id)
4895848958
Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",15);
4895948959
}
4896048960

48961-
if(!pfread((&DMaps[i].title),sizeof(DMaps[0].title),f))
48961+
if (!p_getwstr(&DMaps[i].title, f))
4896248962
{
4896348963
Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",16);
4896448964
}

src/zq/zquest.cpp

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14558,8 +14558,8 @@ int32_t writesomedmaps(PACKFILE *f, int32_t first, int32_t last, int32_t max)
1455814558
{
1455914559
new_return(17);
1456014560
}
14561-
14562-
if(!pfwrite(&DMaps[i].title,sizeof(DMaps[0].title),f))
14561+
14562+
if(!p_putwstr(DMaps[i].title,f))
1456314563
{
1456414564
new_return(18);
1456514565
}
@@ -14753,8 +14753,7 @@ int32_t readsomedmaps(PACKFILE *f)
1475314753
dword section_cversion = 0;
1475414754
int32_t zversion = 0;
1475514755
int32_t zbuild = 0;
14756-
dmap tempdmap;
14757-
tempdmap.clear();
14756+
dmap tempdmap{};
1475814757

1475914758
int32_t first = 0, last = 0, max = 0, count = 0;
1476014759
int32_t datatype_version = 0;
@@ -14899,11 +14898,23 @@ int32_t readsomedmaps(PACKFILE *f)
1489914898
{
1490014899
return 0;
1490114900
}
14902-
14903-
if(!pfread(&tempdmap.title,sizeof(DMaps[0].title),f))
14904-
{
14905-
return 0;
14906-
}
14901+
14902+
if (section_version<20)
14903+
{
14904+
char title[22];
14905+
if (!p_getstr(title, sizeof(title) - 1, f))
14906+
{
14907+
return 0;
14908+
}
14909+
tempdmap.title.assign(title);
14910+
}
14911+
else
14912+
{
14913+
if (!p_getwstr(&tempdmap.title, f))
14914+
{
14915+
return 0;
14916+
}
14917+
}
1490714918

1490814919
if(!pfread(&tempdmap.intro,sizeof(DMaps[0].intro),f))
1490914920
{
@@ -15085,6 +15096,7 @@ int32_t readsomedmaps(PACKFILE *f)
1508515096
}
1508615097
}
1508715098
}
15099+
DMaps[i].clear();
1508815100
DMaps[i] = tempdmap;
1508915101
}
1509015102

@@ -15374,8 +15386,7 @@ int32_t readonedmap(PACKFILE *f, int32_t index)
1537415386
dword section_cversion = 0;
1537515387
int32_t zversion = 0;
1537615388
int32_t zbuild = 0;
15377-
dmap tempdmap;
15378-
tempdmap.clear();
15389+
dmap tempdmap{};
1537915390
int32_t datatype_version = 0;
1538015391
int32_t first = 0;
1538115392
int32_t last = 0;
@@ -15511,7 +15522,24 @@ int32_t readonedmap(PACKFILE *f, int32_t index)
1551115522
{
1551215523
return 0;
1551315524
}
15514-
15525+
15526+
if (section_version<20)
15527+
{
15528+
char title[22];
15529+
if (!p_getstr(title, sizeof(title) - 1, f))
15530+
{
15531+
return 0;
15532+
}
15533+
tempdmap.title.assign(title);
15534+
}
15535+
else
15536+
{
15537+
if (!p_getwstr(&tempdmap.title, f))
15538+
{
15539+
return 0;
15540+
}
15541+
}
15542+
1551515543
if(!pfread(&tempdmap.title,sizeof(DMaps[0].title),f))
1551615544
{
1551715545
return 0;

0 commit comments

Comments
 (0)