Skip to content

Commit

Permalink
Automatically fixup Steam G1.DAT
Browse files Browse the repository at this point in the history
  • Loading branch information
rwjuk committed Jan 22, 2018
1 parent 4e7c48c commit a9b6d8d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
25 changes: 24 additions & 1 deletion src/openloco/graphics/gfx.cpp
@@ -1,4 +1,5 @@
#include <fstream>
#include <iostream>

#include "../interop/interop.hpp"
#include "../environment.h"
Expand Down Expand Up @@ -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)))
{
Expand All @@ -52,12 +63,24 @@ 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)
{
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));
memcpy(&_g1Elements[3898], &_g1Elements[1788], sizeof(g1_element_t) * 223);

}
}
catch (const std::exception &e)
{
Expand Down
3 changes: 2 additions & 1 deletion src/openloco/graphics/gfx.h
Expand Up @@ -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
{
Expand Down

0 comments on commit a9b6d8d

Please sign in to comment.