diff --git a/src/openloco/graphics/gfx.cpp b/src/openloco/graphics/gfx.cpp index 680e77b363..717200540d 100644 --- a/src/openloco/graphics/gfx.cpp +++ b/src/openloco/graphics/gfx.cpp @@ -1,4 +1,5 @@ #include +#include #include "../interop/interop.hpp" #include "../environment.h" @@ -22,7 +23,7 @@ namespace openloco::gfx { auto g1Path = environment::get_path(environment::path_id::g1); - std::ifstream stream(g1Path.make_preferred().u8string().c_str(), std::ios::in | std::ios::binary); + std::ifstream stream(g1Path, std::ios::in | std::ios::binary); gfx::g1_header_t header; void * g1Buffer; @@ -38,6 +39,16 @@ namespace openloco::gfx throw std::runtime_error("Reading g1 file header failed."); } + if (header.num_entries != LOCO_G1_ELEMENT_COUNT) + { + std::cout << "G1 element count doesn't match expected value: "; + std::cout << "Expected " << LOCO_G1_ELEMENT_COUNT << "; Got " << header.num_entries << std::endl; + if (header.num_entries == LOCO_G1_ELEMENT_COUNT_STEAM) + { + std::cout << "Got Steam G1.DAT variant, will fix elements automatically." << std::endl; + } + } + // Read element headers if (!stream.read((char *)_g1Elements.get(), header.num_entries * sizeof(g1_element_t))) { @@ -52,12 +63,27 @@ namespace openloco::gfx throw std::runtime_error("Reading g1 elements failed."); } + stream.close(); + // Adjust memory offsets for (uint32_t i = 0; i < header.num_entries; i++) { _g1Elements[i].offset += (int32_t)g1Buffer; } - stream.close(); + + // The steam G1.DAT is missing two localised tutorial icons, and a smaller font variant + // This code copies the closest variants into their place, and moves other elements accordingly + if (header.num_entries == LOCO_G1_ELEMENT_COUNT_STEAM) + { + // Extra two tutorial images + memmove(&_g1Elements[3551], &_g1Elements[3549], sizeof(g1_element_t) * (header.num_entries - 3549)); + memcpy(&_g1Elements[3549], &_g1Elements[3551], sizeof(g1_element_t)); + memcpy(&_g1Elements[3550], &_g1Elements[3551], sizeof(g1_element_t)); + + // Extra font variant + memcpy(&_g1Elements[3898], &_g1Elements[1788], sizeof(g1_element_t) * 223); + + } } catch (const std::exception &e) { diff --git a/src/openloco/graphics/gfx.h b/src/openloco/graphics/gfx.h index 5db70099c2..76953176b4 100644 --- a/src/openloco/graphics/gfx.h +++ b/src/openloco/graphics/gfx.h @@ -4,7 +4,8 @@ #include "../localisation/stringmgr.h" #include "../openloco.h" -#define LOCO_G1_ELEMENT_COUNT 0x1A10 +#define LOCO_G1_ELEMENT_COUNT 0x101A +#define LOCO_G1_ELEMENT_COUNT_STEAM 0x0F38 namespace openloco::gfx {