From 3d16bca6abae167016e688c2d1bbbca78a1b8c18 Mon Sep 17 00:00:00 2001 From: Henry Cheng <39224097+jazzysoggy@users.noreply.github.com> Date: Fri, 8 Jul 2022 00:57:24 -0400 Subject: [PATCH] Add notification for mismatched g2.dat entries size (#17496) Added expected number of sprites to StringIds.h and a mismatch check upon loading g2.dat in Drawing.Sprite.cpp. If the mismatch catch fails, then an error is logged and a notification is displayed * Add improper install warning --- distribution/changelog.txt | 1 + src/openrct2/drawing/Drawing.Sprite.cpp | 16 ++++++++++++++++ src/openrct2/sprites.h | 2 ++ 3 files changed, 19 insertions(+) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index a44aa836f3..e30ba62aa7 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -22,6 +22,7 @@ - Change: [#16952] Make “Object Selection” order more coherent. - Change: [#17002] Weather no longer resets when converting a save to scenario. - Change: [#17294] New ride window remembers scroll position per tab instead of highlighted ride. +- Change: [#17496] Added warning for mismatched g2.dat entry size - Removed: [#16864] Title sequence editor (replaced by plug-in). - Removed: [#16911, #17411] Residual support for pre-Vista Windows systems. - Fix: [#13997] Placing a track design interferes with other players building a ride. diff --git a/src/openrct2/drawing/Drawing.Sprite.cpp b/src/openrct2/drawing/Drawing.Sprite.cpp index b35022e685..1c30498000 100644 --- a/src/openrct2/drawing/Drawing.Sprite.cpp +++ b/src/openrct2/drawing/Drawing.Sprite.cpp @@ -282,6 +282,22 @@ bool gfx_load_g2() // Read element data _g2.data = fs.ReadArray(_g2.header.total_size); + if (_g2.header.num_entries != G2_SPRITE_COUNT) + { + std::string errorMessage = "Mismatched g2.dat size.\nExpected: " + std::to_string(G2_SPRITE_COUNT) + "\nActual: " + + std::to_string(_g2.header.num_entries) + "\ng2.dat may be installed improperly.\nPath to g2.dat: " + path; + + log_error(errorMessage.c_str()); + + if (!gOpenRCT2Headless) + { + auto uiContext = GetContext()->GetUiContext(); + uiContext->ShowMessageBox(errorMessage); + uiContext->ShowMessageBox("Warning: You may experience graphical glitches if you continue. It's recommended " + "that you update g2.dat if you're seeing this message"); + } + } + // Fix entry data offsets for (uint32_t i = 0; i < _g2.header.num_entries; i++) { diff --git a/src/openrct2/sprites.h b/src/openrct2/sprites.h index 3527d17eb2..f00aa50202 100644 --- a/src/openrct2/sprites.h +++ b/src/openrct2/sprites.h @@ -1158,6 +1158,8 @@ enum SPR_CSG_BEGIN = SPR_G2_END, SPR_CSG_END = SPR_CSG_BEGIN + RCT1::Limits::Num_LL_CSG_Entries, + G2_SPRITE_COUNT = SPR_G2_END - SPR_G2_BEGIN, + SPR_SCROLLING_TEXT_START = SPR_CSG_END, SPR_SCROLLING_TEXT_END = SPR_SCROLLING_TEXT_START + OpenRCT2::MaxScrollingTextEntries,