aboutsummaryrefslogtreecommitdiff
path: root/games/openrct2/files/patch-bigendian
diff options
context:
space:
mode:
Diffstat (limited to 'games/openrct2/files/patch-bigendian')
-rw-r--r--games/openrct2/files/patch-bigendian707
1 files changed, 707 insertions, 0 deletions
diff --git a/games/openrct2/files/patch-bigendian b/games/openrct2/files/patch-bigendian
new file mode 100644
index 000000000000..378bfc3d5974
--- /dev/null
+++ b/games/openrct2/files/patch-bigendian
@@ -0,0 +1,707 @@
+--- src/openrct2-ui/input/KeyboardShortcuts.cpp.orig 2019-03-13 20:51:10 UTC
++++ src/openrct2-ui/input/KeyboardShortcuts.cpp
+@@ -19,6 +19,7 @@
+ #include <openrct2/core/Path.hpp>
+ #include <openrct2/core/String.hpp>
+ #include <openrct2/localisation/Localisation.h>
++#include <openrct2/util/Endian.h>
+
+ using namespace OpenRCT2;
+ using namespace OpenRCT2::Input;
+@@ -55,14 +56,14 @@ bool KeyboardShortcuts::Load()
+ if (File::Exists(path))
+ {
+ auto fs = FileStream(path, FILE_MODE_OPEN);
+- uint16_t version = fs.ReadValue<uint16_t>();
++ uint16_t version = ORCT_SwapLEu16(fs.ReadValue<uint16_t>());
+ if (version == KeyboardShortcuts::CURRENT_FILE_VERSION)
+ {
+ int32_t numShortcutsInFile = (fs.GetLength() - sizeof(uint16_t)) / sizeof(uint16_t);
+ int32_t numShortcutsToRead = std::min<int32_t>(SHORTCUT_COUNT, numShortcutsInFile);
+ for (int32_t i = 0; i < numShortcutsToRead; i++)
+ {
+- _keys[i] = fs.ReadValue<uint16_t>();
++ _keys[i] = ORCT_SwapLEu16(fs.ReadValue<uint16_t>());
+ }
+ result = true;
+ }
+--- src/openrct2/audio/Audio.cpp.orig 2019-03-13 20:51:10 UTC
++++ src/openrct2/audio/Audio.cpp
+@@ -23,6 +23,7 @@
+ #include "../peep/Peep.h"
+ #include "../ride/Ride.h"
+ #include "../ui/UiContext.h"
++#include "../util/Endian.h"
+ #include "../util/Util.h"
+ #include "AudioContext.h"
+ #include "AudioMixer.h"
+@@ -350,7 +351,7 @@ void audio_init_ride_sounds_and_info()
+ try
+ {
+ auto fs = FileStream(path, FILE_MODE_OPEN);
+- uint32_t head = fs.ReadValue<uint32_t>();
++ uint32_t head = ORCT_SwapLEu32(fs.ReadValue<uint32_t>());
+ if (head == 0x78787878)
+ {
+ rideMusicInfo.length = 0;
+--- src/openrct2/common.h.orig 2019-03-13 20:51:10 UTC
++++ src/openrct2/common.h
+@@ -75,6 +75,10 @@ const constexpr auto ror64 = ror<uint64_
+ # define RCT2_ENDIANESS __ORDER_LITTLE_ENDIAN__
+ # define LOBYTE(w) ((uint8_t)(w))
+ # define HIBYTE(w) ((uint8_t)(((uint16_t)(w) >> 8) & 0xFF))
++# else
++# define RCT2_ENDIANESS __ORDER_BIG_ENDIAN__
++# define HIBYTE(w) ((uint8_t)(w))
++# define LOBYTE(w) ((uint8_t)(((uint16_t)(w) >> 8) & 0xFF))
+ # endif // __BYTE_ORDER__
+
+ # ifndef RCT2_ENDIANESS
+--- src/openrct2/core/FileIndex.hpp.orig 2019-03-13 20:51:10 UTC
++++ src/openrct2/core/FileIndex.hpp
+@@ -10,6 +10,7 @@
+ #pragma once
+
+ #include "../common.h"
++#include "../util/Endian.h"
+ #include "Console.hpp"
+ #include "File.h"
+ #include "FileScanner.h"
+@@ -265,6 +266,14 @@ private:
+
+ // Read header, check if we need to re-scan
+ auto header = fs.ReadValue<FileIndexHeader>();
++ header.HeaderSize = ORCT_SwapLEu32(header.HeaderSize);
++ header.MagicNumber = ORCT_SwapLEu32(header.MagicNumber);
++ header.LanguageId = ORCT_SwapLEu16(header.LanguageId);
++ header.NumItems = ORCT_SwapLEu32(header.NumItems);
++ header.Stats.TotalFiles = ORCT_SwapLEu32(header.Stats.TotalFiles);
++ header.Stats.TotalFileSize = ORCT_SwapLEu64(header.Stats.TotalFileSize);
++ header.Stats.FileDateModifiedChecksum = ORCT_SwapLEu32(header.Stats.FileDateModifiedChecksum);
++ header.Stats.PathChecksum = ORCT_SwapLEu32(header.Stats.PathChecksum);
+ if (header.HeaderSize == sizeof(FileIndexHeader) && header.MagicNumber == _magicNumber
+ && header.VersionA == FILE_INDEX_VERSION && header.VersionB == _version && header.LanguageId == language
+ && header.Stats.TotalFiles == stats.TotalFiles && header.Stats.TotalFileSize == stats.TotalFileSize
+--- src/openrct2/drawing/Drawing.Sprite.cpp.orig 2019-03-13 20:51:10 UTC
++++ src/openrct2/drawing/Drawing.Sprite.cpp
+@@ -16,6 +16,7 @@
+ #include "../platform/platform.h"
+ #include "../sprites.h"
+ #include "../ui/UiContext.h"
++#include "../util/Endian.h"
+ #include "../util/Util.h"
+ #include "Drawing.h"
+
+@@ -237,6 +238,8 @@ bool gfx_load_g1(const IPlatformEnvironm
+ auto path = Path::Combine(env.GetDirectoryPath(DIRBASE::RCT2, DIRID::DATA), "g1.dat");
+ auto fs = FileStream(path, FILE_MODE_OPEN);
+ _g1.header = fs.ReadValue<rct_g1_header>();
++ _g1.header.num_entries = ORCT_SwapLEu32(_g1.header.num_entries);
++ _g1.header.total_size = ORCT_SwapLEu32(_g1.header.total_size);
+
+ log_verbose("g1.dat, number of entries: %u", _g1.header.num_entries);
+
+@@ -309,6 +312,8 @@ bool gfx_load_g2()
+ {
+ auto fs = FileStream(path, FILE_MODE_OPEN);
+ _g2.header = fs.ReadValue<rct_g1_header>();
++ _g2.header.num_entries = ORCT_SwapLEu32(_g2.header.num_entries);
++ _g2.header.total_size = ORCT_SwapLEu32(_g2.header.total_size);
+
+ // Read element headers
+ _g2.elements.resize(_g2.header.num_entries);
+--- src/openrct2/object/BannerObject.cpp.orig 2019-03-13 20:51:10 UTC
++++ src/openrct2/object/BannerObject.cpp
+@@ -14,6 +14,7 @@
+ #include "../localisation/Language.h"
+ #include "../object/Object.h"
+ #include "../object/ObjectRepository.h"
++#include "../util/Endian.h"
+ #include "ObjectJsonHelpers.h"
+ #include "ObjectList.h"
+
+@@ -22,13 +23,14 @@ void BannerObject::ReadLegacy(IReadObjec
+ stream->Seek(6, STREAM_SEEK_CURRENT);
+ _legacyType.banner.scrolling_mode = stream->ReadValue<uint8_t>();
+ _legacyType.banner.flags = stream->ReadValue<uint8_t>();
+- _legacyType.banner.price = stream->ReadValue<int16_t>();
++ _legacyType.banner.price = ORCT_SwapLEi16(stream->ReadValue<int16_t>());
+ _legacyType.banner.scenery_tab_id = stream->ReadValue<uint8_t>();
+ stream->Seek(1, STREAM_SEEK_CURRENT);
+
+ GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME);
+
+ rct_object_entry sgEntry = stream->ReadValue<rct_object_entry>();
++ sgEntry.flags = ORCT_SwapLEu32(sgEntry.flags);
+ SetPrimarySceneryGroup(&sgEntry);
+
+ GetImageTable().Read(context, stream);
+--- src/openrct2/object/FootpathItemObject.cpp.orig 2019-03-13 20:51:10 UTC
++++ src/openrct2/object/FootpathItemObject.cpp
+@@ -15,6 +15,7 @@
+ #include "../localisation/Localisation.h"
+ #include "../object/Object.h"
+ #include "../object/ObjectRepository.h"
++#include "../util/Endian.h"
+ #include "ObjectJsonHelpers.h"
+ #include "ObjectList.h"
+
+@@ -23,16 +24,17 @@
+ void FootpathItemObject::ReadLegacy(IReadObjectContext* context, IStream* stream)
+ {
+ stream->Seek(6, STREAM_SEEK_CURRENT);
+- _legacyType.path_bit.flags = stream->ReadValue<uint16_t>();
++ _legacyType.path_bit.flags = ORCT_SwapLEu16(stream->ReadValue<uint16_t>());
+ _legacyType.path_bit.draw_type = stream->ReadValue<uint8_t>();
+ _legacyType.path_bit.tool_id = stream->ReadValue<uint8_t>();
+- _legacyType.path_bit.price = stream->ReadValue<int16_t>();
++ _legacyType.path_bit.price = ORCT_SwapLEi16(stream->ReadValue<int16_t>());
+ _legacyType.path_bit.scenery_tab_id = stream->ReadValue<uint8_t>();
+ stream->Seek(1, STREAM_SEEK_CURRENT);
+
+ GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME);
+
+ rct_object_entry sgEntry = stream->ReadValue<rct_object_entry>();
++ sgEntry.flags = ORCT_SwapLEu32(sgEntry.flags);
+ SetPrimarySceneryGroup(&sgEntry);
+
+ GetImageTable().Read(context, stream);
+--- src/openrct2/object/ImageTable.cpp.orig 2019-03-13 20:51:10 UTC
++++ src/openrct2/object/ImageTable.cpp
+@@ -11,6 +11,7 @@
+
+ #include "../OpenRCT2.h"
+ #include "../core/IStream.hpp"
++#include "../util/Endian.h"
+ #include "Object.h"
+
+ #include <algorithm>
+@@ -37,8 +38,8 @@ void ImageTable::Read(IReadObjectContext
+
+ try
+ {
+- uint32_t numImages = stream->ReadValue<uint32_t>();
+- uint32_t imageDataSize = stream->ReadValue<uint32_t>();
++ uint32_t numImages = ORCT_SwapLEu32(stream->ReadValue<uint32_t>());
++ uint32_t imageDataSize = ORCT_SwapLEu32(stream->ReadValue<uint32_t>());
+
+ uint64_t headerTableSize = numImages * 16;
+ uint64_t remainingBytes = stream->GetLength() - stream->GetPosition() - headerTableSize;
+@@ -63,15 +64,15 @@ void ImageTable::Read(IReadObjectContext
+ {
+ rct_g1_element g1Element;
+
+- uintptr_t imageDataOffset = (uintptr_t)stream->ReadValue<uint32_t>();
++ uintptr_t imageDataOffset = ORCT_SwapLEu32((uintptr_t)stream->ReadValue<uint32_t>());
+ g1Element.offset = (uint8_t*)(imageDataBase + imageDataOffset);
+
+- g1Element.width = stream->ReadValue<int16_t>();
+- g1Element.height = stream->ReadValue<int16_t>();
+- g1Element.x_offset = stream->ReadValue<int16_t>();
+- g1Element.y_offset = stream->ReadValue<int16_t>();
+- g1Element.flags = stream->ReadValue<uint16_t>();
+- g1Element.zoomed_offset = stream->ReadValue<uint16_t>();
++ g1Element.width = ORCT_SwapLEi16(stream->ReadValue<int16_t>());
++ g1Element.height = ORCT_SwapLEi16(stream->ReadValue<int16_t>());
++ g1Element.x_offset = ORCT_SwapLEi16(stream->ReadValue<int16_t>());
++ g1Element.y_offset = ORCT_SwapLEi16(stream->ReadValue<int16_t>());
++ g1Element.flags = ORCT_SwapLEu16(stream->ReadValue<uint16_t>());
++ g1Element.zoomed_offset = ORCT_SwapLEu16(stream->ReadValue<uint16_t>());
+
+ newEntries.push_back(g1Element);
+ }
+--- src/openrct2/object/LargeSceneryObject.cpp.orig 2019-03-13 20:51:10 UTC
++++ src/openrct2/object/LargeSceneryObject.cpp
+@@ -16,6 +16,7 @@
+ #include "../drawing/Drawing.h"
+ #include "../interface/Cursors.h"
+ #include "../localisation/Language.h"
++#include "../util/Endian.h"
+ #include "../world/Banner.h"
+ #include "../world/Location.hpp"
+ #include "ObjectJsonHelpers.h"
+@@ -28,8 +29,8 @@ void LargeSceneryObject::ReadLegacy(IRea
+ stream->Seek(6, STREAM_SEEK_CURRENT);
+ _legacyType.large_scenery.tool_id = stream->ReadValue<uint8_t>();
+ _legacyType.large_scenery.flags = stream->ReadValue<uint8_t>();
+- _legacyType.large_scenery.price = stream->ReadValue<int16_t>();
+- _legacyType.large_scenery.removal_price = stream->ReadValue<int16_t>();
++ _legacyType.large_scenery.price = ORCT_SwapLEi16(stream->ReadValue<int16_t>());
++ _legacyType.large_scenery.removal_price = ORCT_SwapLEi16(stream->ReadValue<int16_t>());
+ stream->Seek(5, STREAM_SEEK_CURRENT);
+ _legacyType.large_scenery.scenery_tab_id = 0xFF;
+ _legacyType.large_scenery.scrolling_mode = stream->ReadValue<uint8_t>();
+@@ -38,6 +39,7 @@ void LargeSceneryObject::ReadLegacy(IRea
+ GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME);
+
+ rct_object_entry sgEntry = stream->ReadValue<rct_object_entry>();
++ sgEntry.flags = ORCT_SwapLEu32(sgEntry.flags);
+ SetPrimarySceneryGroup(&sgEntry);
+
+ if (_legacyType.large_scenery.flags & LARGE_SCENERY_FLAG_3D_TEXT)
+@@ -112,10 +114,17 @@ void LargeSceneryObject::DrawPreview(rct
+ std::vector<rct_large_scenery_tile> LargeSceneryObject::ReadTiles(IStream* stream)
+ {
+ auto tiles = std::vector<rct_large_scenery_tile>();
++ // Note: no need to swap the value here...
+ while (stream->ReadValue<uint16_t>() != 0xFFFF)
+ {
+ stream->Seek(-2, STREAM_SEEK_CURRENT);
++
+ auto tile = stream->ReadValue<rct_large_scenery_tile>();
++ tile.x_offset = ORCT_SwapLEi16(tile.x_offset);
++ tile.y_offset = ORCT_SwapLEi16(tile.y_offset);
++ tile.z_offset = ORCT_SwapLEi16(tile.z_offset);
++ tile.z_clearance = ORCT_SwapLEi16(tile.z_clearance);
++ tile.flags = ORCT_SwapLEi16(tile.flags);
+ tiles.push_back(tile);
+ }
+ tiles.push_back({ -1, -1, -1, 255, 0xFFFF });
+--- src/openrct2/object/ObjectFactory.cpp.orig 2019-03-13 20:51:10 UTC
++++ src/openrct2/object/ObjectFactory.cpp
+@@ -20,6 +20,7 @@
+ #include "../core/String.hpp"
+ #include "../core/Zip.h"
+ #include "../rct12/SawyerChunkReader.h"
++#include "../util/Endian.h"
+ #include "BannerObject.h"
+ #include "EntranceObject.h"
+ #include "FootpathItemObject.h"
+--- src/openrct2/object/ObjectRepository.cpp.orig 2019-03-13 20:51:10 UTC
++++ src/openrct2/object/ObjectRepository.cpp
+@@ -29,6 +29,7 @@
+ #include "../rct12/SawyerChunkReader.h"
+ #include "../rct12/SawyerChunkWriter.h"
+ #include "../scenario/ScenarioRepository.h"
++#include "../util/Endian.h"
+ #include "../util/SawyerCoding.h"
+ #include "../util/Util.h"
+ #include "Object.h"
+@@ -161,6 +162,7 @@ protected:
+ ObjectRepositoryItem item;
+
+ item.ObjectEntry = stream->ReadValue<rct_object_entry>();
++ item.ObjectEntry.flags = ORCT_SwapLEu32(item.ObjectEntry.flags);
+ item.Path = stream->ReadStdString();
+ item.Name = stream->ReadStdString();
+ auto sourceLength = stream->ReadValue<uint8_t>();
+@@ -186,11 +188,12 @@ protected:
+ break;
+ case OBJECT_TYPE_SCENERY_GROUP:
+ {
+- auto numEntries = stream->ReadValue<uint16_t>();
++ auto numEntries = ORCT_SwapLEu16(stream->ReadValue<uint16_t>());
+ item.SceneryGroupInfo.Entries = std::vector<rct_object_entry>(numEntries);
+ for (size_t i = 0; i < numEntries; i++)
+ {
+ item.SceneryGroupInfo.Entries[i] = stream->ReadValue<rct_object_entry>();
++ item.SceneryGroupInfo.Entries[i].flags = ORCT_SwapLEu32(item.SceneryGroupInfo.Entries[i].flags);
+ }
+ break;
+ }
+@@ -363,6 +366,7 @@ public:
+
+ // Check if we already have this object
+ rct_object_entry entry = stream->ReadValue<rct_object_entry>();
++ entry.flags = ORCT_SwapLEu32(entry.flags);
+ if (FindObject(&entry) != nullptr)
+ {
+ chunkReader.SkipChunk();
+@@ -622,6 +626,7 @@ private:
+ // Read object data from file
+ auto fs = FileStream(item->Path, FILE_MODE_OPEN);
+ auto fileEntry = fs.ReadValue<rct_object_entry>();
++ fileEntry.flags = ORCT_SwapLEu32(fileEntry.flags);
+ if (!object_entry_compare(entry, &fileEntry))
+ {
+ throw std::runtime_error("Header found in object file does not match object to pack.");
+--- src/openrct2/object/RideObject.cpp.orig 2019-03-13 20:51:10 UTC
++++ src/openrct2/object/RideObject.cpp
+@@ -22,6 +22,7 @@
+ #include "../ride/RideGroupManager.h"
+ #include "../ride/ShopItem.h"
+ #include "../ride/Track.h"
++#include "../util/Endian.h"
+ #include "ObjectJsonHelpers.h"
+ #include "ObjectRepository.h"
+
+@@ -34,7 +35,7 @@ using namespace OpenRCT2;
+ void RideObject::ReadLegacy(IReadObjectContext* context, IStream* stream)
+ {
+ stream->Seek(8, STREAM_SEEK_CURRENT);
+- _legacyType.flags = stream->ReadValue<uint32_t>();
++ _legacyType.flags = ORCT_SwapLEu32(stream->ReadValue<uint32_t>());
+ for (auto& rideType : _legacyType.ride_type)
+ {
+ rideType = stream->ReadValue<uint8_t>();
+@@ -59,7 +60,7 @@ void RideObject::ReadLegacy(IReadObjectC
+ _legacyType.intensity_multiplier = stream->ReadValue<int8_t>();
+ _legacyType.nausea_multiplier = stream->ReadValue<int8_t>();
+ _legacyType.max_height = stream->ReadValue<uint8_t>();
+- _legacyType.enabledTrackPieces = stream->ReadValue<uint64_t>();
++ _legacyType.enabledTrackPieces = ORCT_SwapLEu64(stream->ReadValue<uint64_t>());
+ _legacyType.category[0] = stream->ReadValue<uint8_t>();
+ _legacyType.category[1] = stream->ReadValue<uint8_t>();
+ _legacyType.shop_item = stream->ReadValue<uint8_t>();
+@@ -94,7 +95,7 @@ void RideObject::ReadLegacy(IReadObjectC
+ uint16_t numPeepLoadingPositions = stream->ReadValue<uint8_t>();
+ if (numPeepLoadingPositions == 255)
+ {
+- numPeepLoadingPositions = stream->ReadValue<uint16_t>();
++ numPeepLoadingPositions = ORCT_SwapLEu16(stream->ReadValue<uint16_t>());
+ }
+
+ if (_legacyType.vehicles[i].flags & VEHICLE_ENTRY_FLAG_LOADING_WAYPOINTS)
+@@ -116,7 +117,7 @@ void RideObject::ReadLegacy(IReadObjectC
+ entry[1].y = stream->ReadValue<int8_t>();
+ entry[2].x = stream->ReadValue<int8_t>();
+ entry[2].y = stream->ReadValue<int8_t>();
+- stream->ReadValue<uint16_t>(); // Skip blanks
++ stream->ReadValue<uint16_t>(); // Skip blanks, no need to swap endianess
+
+ _peepLoadingWaypoints[i].push_back(entry);
+ }
+@@ -412,19 +413,19 @@ void RideObject::SetRepositoryItem(Objec
+ void RideObject::ReadLegacyVehicle(
+ [[maybe_unused]] IReadObjectContext* context, IStream* stream, rct_ride_entry_vehicle* vehicle)
+ {
+- vehicle->rotation_frame_mask = stream->ReadValue<uint16_t>();
++ vehicle->rotation_frame_mask = ORCT_SwapLEu16(stream->ReadValue<uint16_t>());
+ stream->Seek(2 * 1, STREAM_SEEK_CURRENT);
+- vehicle->spacing = stream->ReadValue<uint32_t>();
+- vehicle->car_mass = stream->ReadValue<uint16_t>();
++ vehicle->spacing = ORCT_SwapLEu32(stream->ReadValue<uint32_t>());
++ vehicle->car_mass = ORCT_SwapLEu16(stream->ReadValue<uint16_t>());
+ vehicle->tab_height = stream->ReadValue<int8_t>();
+ vehicle->num_seats = stream->ReadValue<uint8_t>();
+- vehicle->sprite_flags = stream->ReadValue<uint16_t>();
++ vehicle->sprite_flags = ORCT_SwapLEu16(stream->ReadValue<uint16_t>());
+ vehicle->sprite_width = stream->ReadValue<uint8_t>();
+ vehicle->sprite_height_negative = stream->ReadValue<uint8_t>();
+ vehicle->sprite_height_positive = stream->ReadValue<uint8_t>();
+ vehicle->animation = stream->ReadValue<uint8_t>();
+- vehicle->flags = stream->ReadValue<uint32_t>();
+- vehicle->base_num_frames = stream->ReadValue<uint16_t>();
++ vehicle->flags = ORCT_SwapLEu32(stream->ReadValue<uint32_t>());
++ vehicle->base_num_frames = ORCT_SwapLEu16(stream->ReadValue<uint16_t>());
+ stream->Seek(15 * 4, STREAM_SEEK_CURRENT);
+ vehicle->no_seating_rows = stream->ReadValue<uint8_t>();
+ vehicle->spinning_inertia = stream->ReadValue<uint8_t>();
+--- src/openrct2/object/SceneryGroupObject.cpp.orig 2019-03-13 20:51:10 UTC
++++ src/openrct2/object/SceneryGroupObject.cpp
+@@ -18,6 +18,7 @@
+ #include "../drawing/Drawing.h"
+ #include "../localisation/Language.h"
+ #include "../peep/Staff.h"
++#include "../util/Endian.h"
+ #include "ObjectJsonHelpers.h"
+ #include "ObjectManager.h"
+ #include "ObjectRepository.h"
+@@ -34,7 +35,7 @@ void SceneryGroupObject::ReadLegacy(IRea
+ _legacyType.pad_107 = stream->ReadValue<uint8_t>();
+ _legacyType.priority = stream->ReadValue<uint8_t>();
+ _legacyType.pad_109 = stream->ReadValue<uint8_t>();
+- _legacyType.entertainer_costumes = stream->ReadValue<uint32_t>();
++ _legacyType.entertainer_costumes = ORCT_SwapLEu32(stream->ReadValue<uint32_t>());
+
+ GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME);
+ _items = ReadItems(stream);
+@@ -126,6 +127,7 @@ std::vector<rct_object_entry> SceneryGro
+ {
+ stream->Seek(-1, STREAM_SEEK_CURRENT);
+ auto entry = stream->ReadValue<rct_object_entry>();
++ entry.flags = ORCT_SwapLEu32(entry.flags);
+ items.push_back(entry);
+ }
+ return items;
+--- src/openrct2/object/SmallSceneryObject.cpp.orig 2019-03-13 20:51:10 UTC
++++ src/openrct2/object/SmallSceneryObject.cpp
+@@ -17,6 +17,7 @@
+ #include "../drawing/Drawing.h"
+ #include "../interface/Cursors.h"
+ #include "../localisation/Language.h"
++#include "../util/Endian.h"
+ #include "../world/Scenery.h"
+ #include "../world/SmallScenery.h"
+ #include "ObjectJsonHelpers.h"
+@@ -26,20 +27,21 @@
+ void SmallSceneryObject::ReadLegacy(IReadObjectContext* context, IStream* stream)
+ {
+ stream->Seek(6, STREAM_SEEK_CURRENT);
+- _legacyType.small_scenery.flags = stream->ReadValue<uint32_t>();
++ _legacyType.small_scenery.flags = ORCT_SwapLEu32(stream->ReadValue<uint32_t>());
+ _legacyType.small_scenery.height = stream->ReadValue<uint8_t>();
+ _legacyType.small_scenery.tool_id = stream->ReadValue<uint8_t>();
+- _legacyType.small_scenery.price = stream->ReadValue<int16_t>();
+- _legacyType.small_scenery.removal_price = stream->ReadValue<int16_t>();
++ _legacyType.small_scenery.price = ORCT_SwapLEu16(stream->ReadValue<int16_t>());
++ _legacyType.small_scenery.removal_price = ORCT_SwapLEu16(stream->ReadValue<int16_t>());
+ stream->Seek(4, STREAM_SEEK_CURRENT);
+- _legacyType.small_scenery.animation_delay = stream->ReadValue<uint16_t>();
+- _legacyType.small_scenery.animation_mask = stream->ReadValue<uint16_t>();
+- _legacyType.small_scenery.num_frames = stream->ReadValue<uint16_t>();
++ _legacyType.small_scenery.animation_delay = ORCT_SwapLEu16(stream->ReadValue<uint16_t>());
++ _legacyType.small_scenery.animation_mask = ORCT_SwapLEu16(stream->ReadValue<uint16_t>());
++ _legacyType.small_scenery.num_frames = ORCT_SwapLEu16(stream->ReadValue<uint16_t>());
+ _legacyType.small_scenery.scenery_tab_id = 0xFF;
+
+ GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME);
+
+ rct_object_entry sgEntry = stream->ReadValue<rct_object_entry>();
++ sgEntry.flags = ORCT_SwapLEu32(sgEntry.flags);
+ SetPrimarySceneryGroup(&sgEntry);
+
+ if (scenery_small_entry_has_flag(&_legacyType, SMALL_SCENERY_FLAG_HAS_FRAME_OFFSETS))
+--- src/openrct2/object/WallObject.cpp.orig 2019-03-13 20:51:10 UTC
++++ src/openrct2/object/WallObject.cpp
+@@ -13,6 +13,7 @@
+ #include "../drawing/Drawing.h"
+ #include "../interface/Cursors.h"
+ #include "../localisation/Language.h"
++#include "../util/Endian.h"
+ #include "../world/Banner.h"
+ #include "ObjectJsonHelpers.h"
+
+@@ -23,13 +24,14 @@ void WallObject::ReadLegacy(IReadObjectC
+ _legacyType.wall.flags = stream->ReadValue<uint8_t>();
+ _legacyType.wall.height = stream->ReadValue<uint8_t>();
+ _legacyType.wall.flags2 = stream->ReadValue<uint8_t>();
+- _legacyType.wall.price = stream->ReadValue<uint16_t>();
++ _legacyType.wall.price = ORCT_SwapLEu16(stream->ReadValue<uint16_t>());
+ _legacyType.wall.scenery_tab_id = stream->ReadValue<uint8_t>();
+ _legacyType.wall.scrolling_mode = stream->ReadValue<uint8_t>();
+
+ GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME);
+
+ rct_object_entry sgEntry = stream->ReadValue<rct_object_entry>();
++ sgEntry.flags = ORCT_SwapLEu16(sgEntry.flags);
+ SetPrimarySceneryGroup(&sgEntry);
+
+ GetImageTable().Read(context, stream);
+--- src/openrct2/object/WaterObject.cpp.orig 2019-03-13 20:51:10 UTC
++++ src/openrct2/object/WaterObject.cpp
+@@ -15,6 +15,7 @@
+ #include "../core/IStream.hpp"
+ #include "../localisation/Language.h"
+ #include "../localisation/StringIds.h"
++#include "../util/Endian.h"
+ #include "ObjectJsonHelpers.h"
+
+ #include <memory>
+@@ -22,7 +23,7 @@
+ void WaterObject::ReadLegacy(IReadObjectContext* context, IStream* stream)
+ {
+ stream->Seek(14, STREAM_SEEK_CURRENT);
+- _legacyType.flags = stream->ReadValue<uint16_t>();
++ _legacyType.flags = ORCT_SwapLEu16(stream->ReadValue<uint16_t>());
+
+ GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME);
+ GetImageTable().Read(context, stream);
+--- src/openrct2/rct12/SawyerChunkReader.cpp.orig 2019-03-13 20:51:10 UTC
++++ src/openrct2/rct12/SawyerChunkReader.cpp
+@@ -10,6 +10,7 @@
+ #include "SawyerChunkReader.h"
+
+ #include "../core/IStream.hpp"
++#include "../util/Endian.h"
+
+ // malloc is very slow for large allocations in MSVC debug builds as it allocates
+ // memory on a special debug heap and then initialises all the memory to 0xCC.
+@@ -52,6 +53,7 @@ void SawyerChunkReader::SkipChunk()
+ try
+ {
+ auto header = _stream->ReadValue<sawyercoding_chunk_header>();
++ header.length = ORCT_SwapLEu32(header.length);
+ _stream->Seek(header.length, STREAM_SEEK_CURRENT);
+ }
+ catch (const std::exception&)
+@@ -68,6 +70,7 @@ std::shared_ptr<SawyerChunk> SawyerChunk
+ try
+ {
+ auto header = _stream->ReadValue<sawyercoding_chunk_header>();
++ header.length = ORCT_SwapLEu32(header.length);
+ switch (header.encoding)
+ {
+ case CHUNK_ENCODING_NONE:
+--- src/openrct2/rct12/SawyerEncoding.cpp.orig 2019-03-13 20:51:10 UTC
++++ src/openrct2/rct12/SawyerEncoding.cpp
+@@ -10,6 +10,7 @@
+ #include "SawyerEncoding.h"
+
+ #include "../core/IStream.hpp"
++#include "../util/Endian.h"
+
+ #include <algorithm>
+
+@@ -44,7 +45,7 @@ namespace SawyerEncoding
+ } while (dataSize != 0);
+
+ // Read file checksum
+- uint32_t fileChecksum = stream->ReadValue<uint32_t>();
++ uint32_t fileChecksum = ORCT_SwapLEu32(stream->ReadValue<uint32_t>());
+
+ // Rewind back to original position
+ stream->SetPosition(initialPosition);
+--- src/openrct2/ride/TrackDesignRepository.cpp.orig 2019-03-13 20:51:10 UTC
++++ src/openrct2/ride/TrackDesignRepository.cpp
+@@ -22,6 +22,7 @@
+ #include "../localisation/LocalisationService.h"
+ #include "../object/ObjectRepository.h"
+ #include "../object/RideObject.h"
++#include "../util/Endian.h"
+ #include "RideGroupManager.h"
+ #include "TrackDesign.h"
+
+@@ -114,7 +115,7 @@ protected:
+ item.Path = stream->ReadStdString();
+ item.RideType = stream->ReadValue<uint8_t>();
+ item.ObjectEntry = stream->ReadStdString();
+- item.Flags = stream->ReadValue<uint32_t>();
++ item.Flags = ORCT_SwapLEu32(stream->ReadValue<uint32_t>());
+ return item;
+ }
+
+--- src/openrct2/scenario/ScenarioRepository.cpp.orig 2019-03-13 20:51:10 UTC
++++ src/openrct2/scenario/ScenarioRepository.cpp
+@@ -25,6 +25,7 @@
+ #include "../localisation/LocalisationService.h"
+ #include "../platform/platform.h"
+ #include "../rct12/SawyerChunkReader.h"
++#include "../util/Endian.h"
+ #include "Scenario.h"
+ #include "ScenarioSources.h"
+
+@@ -182,17 +183,17 @@ protected:
+ scenario_index_entry item;
+
+ stream->Read(item.path, sizeof(item.path));
+- item.timestamp = stream->ReadValue<uint64_t>();
++ item.timestamp = ORCT_SwapLEu64(stream->ReadValue<uint64_t>());
+
+ item.category = stream->ReadValue<uint8_t>();
+ item.source_game = stream->ReadValue<uint8_t>();
+- item.source_index = stream->ReadValue<int16_t>();
+- item.sc_id = stream->ReadValue<uint16_t>();
++ item.source_index = ORCT_SwapLEi16(stream->ReadValue<int16_t>());
++ item.sc_id = ORCT_SwapLEu16(stream->ReadValue<uint16_t>());
+
+ item.objective_type = stream->ReadValue<uint8_t>();
+ item.objective_arg_1 = stream->ReadValue<uint8_t>();
+- item.objective_arg_2 = stream->ReadValue<int32_t>();
+- item.objective_arg_3 = stream->ReadValue<int16_t>();
++ item.objective_arg_2 = ORCT_SwapLEi32(stream->ReadValue<int32_t>());
++ item.objective_arg_3 = ORCT_SwapLEi16(stream->ReadValue<int16_t>());
+ item.highscore = nullptr;
+
+ stream->Read(item.internal_name, sizeof(item.internal_name));
+@@ -587,7 +588,7 @@ private:
+ try
+ {
+ auto fs = FileStream(path, FILE_MODE_OPEN);
+- uint32_t fileVersion = fs.ReadValue<uint32_t>();
++ uint32_t fileVersion = ORCT_SwapLEu32(fs.ReadValue<uint32_t>());
+ if (fileVersion != 1)
+ {
+ Console::Error::WriteLine("Invalid or incompatible highscores file.");
+@@ -596,14 +597,14 @@ private:
+
+ ClearHighscores();
+
+- uint32_t numHighscores = fs.ReadValue<uint32_t>();
++ uint32_t numHighscores = ORCT_SwapLEu32(fs.ReadValue<uint32_t>());
+ for (uint32_t i = 0; i < numHighscores; i++)
+ {
+ scenario_highscore_entry* highscore = InsertHighscore();
+ highscore->fileName = fs.ReadString();
+ highscore->name = fs.ReadString();
+- highscore->company_value = fs.ReadValue<money32>();
+- highscore->timestamp = fs.ReadValue<datetime64>();
++ highscore->company_value = ORCT_SwapLEi32(fs.ReadValue<money32>());
++ highscore->timestamp = ORCT_SwapLEu64(fs.ReadValue<datetime64>());
+ }
+ }
+ catch (const std::exception&)
+@@ -647,6 +648,10 @@ private:
+ {
+ // Read legacy entry
+ auto scBasic = fs.ReadValue<rct_scores_entry>();
++ scBasic.objectiveArg2 = ORCT_SwapLEi32(scBasic.objectiveArg2);
++ scBasic.objectiveArg3 = ORCT_SwapLEi16(scBasic.objectiveArg3);
++ scBasic.Flags = ORCT_SwapLEi32(scBasic.Flags);
++ scBasic.CompanyValue = ORCT_SwapLEi32(scBasic.CompanyValue);
+
+ // Ignore non-completed scenarios
+ if (scBasic.Flags & SCENARIO_FLAGS_COMPLETED)
+--- src/openrct2/util/Endian.h.orig 2019-04-04 08:21:55 UTC
++++ src/openrct2/util/Endian.h
+@@ -0,0 +1,70 @@
++#include <cstdint>
++
++#pragma once
++
++// Based on SDL2
++
++#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__
++
++static inline uint16_t ORCT_Swapu16(uint16_t x)
++{
++ return static_cast<uint16_t>((x << 8) | (x >> 8));
++}
++
++static inline uint32_t ORCT_Swapu32(uint32_t x)
++{
++ return static_cast<uint32_t>(((x << 24) | ((x << 8) & 0x00FF0000) | ((x >> 8) & 0x0000FF00) | (x >> 24)));
++}
++
++static inline uint64_t ORCT_Swapu64(uint64_t x)
++{
++ uint32_t hi, lo;
++
++ /* Separate into high and low 32-bit values and swap them */
++ lo = static_cast<uint32_t>(x & 0xFFFFFFFF);
++ x >>= 32;
++ hi = static_cast<uint32_t>(x & 0xFFFFFFFF);
++ x = ORCT_Swapu32(lo);
++ x <<= 32;
++ x |= ORCT_Swapu32(hi);
++ return (x);
++}
++
++static inline int16_t ORCT_Swapi16(int16_t x)
++{
++ return static_cast<uint16_t>((x << 8) | (x >> 8));
++}
++
++static inline int32_t ORCT_Swapi32(int32_t x)
++{
++ return static_cast<uint32_t>(((x << 24) | ((x << 8) & 0x00FF0000) | ((x >> 8) & 0x0000FF00) | (x >> 24)));
++}
++
++static inline int64_t ORCT_Swapi64(int64_t x)
++{
++ uint32_t hi, lo;
++
++ /* Separate into high and low 32-bit values and swap them */
++ lo = static_cast<uint32_t>(x & 0xFFFFFFFF);
++ x >>= 32;
++ hi = static_cast<uint32_t>(x & 0xFFFFFFFF);
++ x = ORCT_Swapu32(lo);
++ x <<= 32;
++ x |= ORCT_Swapu32(hi);
++ return (x);
++}
++
++# define ORCT_SwapLEi16(X) ORCT_Swapi16(X)
++# define ORCT_SwapLEi32(X) ORCT_Swapi32(X)
++# define ORCT_SwapLEi64(X) ORCT_Swapi64(X)
++# define ORCT_SwapLEu16(X) ORCT_Swapu16(X)
++# define ORCT_SwapLEu32(X) ORCT_Swapu32(X)
++# define ORCT_SwapLEu64(X) ORCT_Swapu64(X)
++#else
++# define ORCT_SwapLEi16(X) (X)
++# define ORCT_SwapLEi32(X) (X)
++# define ORCT_SwapLEi64(X) (X)
++# define ORCT_SwapLEu16(X) (X)
++# define ORCT_SwapLEu32(X) (X)
++# define ORCT_SwapLEu64(X) (X)
++#endif