Skip to content

Commit

Permalink
Engine: fix prescanning GUIs in saves
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-mogilko committed Nov 24, 2024
1 parent 9308f68 commit 0c702f5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Common/game/customproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,26 @@ PropertyError ReadValues(StringIMap &map, Stream *in)
return kPropertyErr_NoError;
}

PropertyError SkipValues(Stream *in)
{
PropertyVersion version = (PropertyVersion)in->ReadInt32();
if (version < kPropertyVersion_Initial || version > kPropertyVersion_Current)
{
return kPropertyErr_UnsupportedFormat;
}

int count = in->ReadInt32();
// NOTE: handle Editor's mistake where it could save empty property bag with version 1
if ((version == kPropertyVersion_Initial) && count > 0)
return kPropertyErr_UnsupportedFormat;
for (int i = 0; i < count; ++i)
{
StrUtil::SkipString(in); // name
StrUtil::SkipString(in); // value
}
return kPropertyErr_NoError;
}

void WriteValues(const StringIMap &map, Stream *out)
{
out->WriteInt32(kPropertyVersion_Current);
Expand Down
2 changes: 2 additions & 0 deletions Common/game/customproperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ namespace Properties
// Reads property values from the stream and assign them to map.
// The non-matching existing map items, if any, are NOT erased.
PropertyError ReadValues(StringIMap &map, Stream *in);
// Skip serialized properties
PropertyError SkipValues(Stream *in);
// Writes property values chunk to the stream
void WriteValues(const StringIMap &map, Stream *out);

Expand Down
5 changes: 5 additions & 0 deletions Common/gui/guimain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,11 @@ void GUIMain::SkipSavestate(Stream *in, GuiSvgVersion svg_version, std::vector<C
(*ctrl_refs)[i].second = ref_packed & 0xFFFF;
}
}

if (svg_version >= kGuiSvgVersion_400)
{
in->Seek(15 * sizeof(int32_t));
}
}

void GUIMain::WriteToSavegame(Common::Stream *out) const
Expand Down
3 changes: 3 additions & 0 deletions Engine/game/savegame_components.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,9 @@ HSaveError PrescanGUI(Stream *in, int32_t cmp_ver, soff_t /*cmp_size*/, const Pr
for (uint32_t i = 0; i < guis_read; ++i)
{
GUIMain::SkipSavestate(in, svg_ver, &guictrl_refs_old[i]);
if (svg_ver >= kGuiSvgVersion_40008)
Properties::SkipValues(in);

assert_buf.Format("GUI %u Controls", i);
if (i < guis.size() &&
!AssertGameContent(err, guictrl_refs_old[i].size(), guis[i].GetControlCount(), assert_buf.GetCStr(), r_data.Result, r_data.DataCounts.GUIControls[i]))
Expand Down

0 comments on commit 0c702f5

Please sign in to comment.