Line 0
Link Here
|
|
|
1 |
--- src/openrct2-ui/input/KeyboardShortcuts.cpp.orig 2018-08-26 20:20:13 UTC |
2 |
+++ src/openrct2-ui/input/KeyboardShortcuts.cpp |
3 |
@@ -19,6 +19,7 @@ |
4 |
#include <openrct2/core/Path.hpp> |
5 |
#include <openrct2/core/String.hpp> |
6 |
#include <openrct2/localisation/Localisation.h> |
7 |
+#include <openrct2/util/Endian.h> |
8 |
|
9 |
using namespace OpenRCT2; |
10 |
using namespace OpenRCT2::Input; |
11 |
@@ -55,14 +56,14 @@ bool KeyboardShortcuts::Load() |
12 |
if (File::Exists(path)) |
13 |
{ |
14 |
auto fs = FileStream(path, FILE_MODE_OPEN); |
15 |
- uint16_t version = fs.ReadValue<uint16_t>(); |
16 |
+ uint16_t version = ORCT_SwapLEu16(fs.ReadValue<uint16_t>()); |
17 |
if (version == KeyboardShortcuts::CURRENT_FILE_VERSION) |
18 |
{ |
19 |
int32_t numShortcutsInFile = (fs.GetLength() - sizeof(uint16_t)) / sizeof(uint16_t); |
20 |
int32_t numShortcutsToRead = std::min<int32_t>(SHORTCUT_COUNT, numShortcutsInFile); |
21 |
for (int32_t i = 0; i < numShortcutsToRead; i++) |
22 |
{ |
23 |
- _keys[i] = fs.ReadValue<uint16_t>(); |
24 |
+ _keys[i] = ORCT_SwapLEu16(fs.ReadValue<uint16_t>()); |
25 |
} |
26 |
result = true; |
27 |
} |
28 |
--- src/openrct2/audio/Audio.cpp.orig 2018-08-26 20:20:13 UTC |
29 |
+++ src/openrct2/audio/Audio.cpp |
30 |
@@ -22,6 +22,7 @@ |
31 |
#include "../localisation/StringIds.h" |
32 |
#include "../ride/Ride.h" |
33 |
#include "../ui/UiContext.h" |
34 |
+#include "../util/Endian.h" |
35 |
#include "../util/Util.h" |
36 |
#include "AudioContext.h" |
37 |
#include "AudioMixer.h" |
38 |
@@ -349,7 +350,7 @@ void audio_init_ride_sounds_and_info() |
39 |
try |
40 |
{ |
41 |
auto fs = FileStream(path, FILE_MODE_OPEN); |
42 |
- uint32_t head = fs.ReadValue<uint32_t>(); |
43 |
+ uint32_t head = ORCT_SwapLEu32(fs.ReadValue<uint32_t>()); |
44 |
if (head == 0x78787878) |
45 |
{ |
46 |
rideMusicInfo.length = 0; |
47 |
--- src/openrct2/common.h.orig 2018-08-26 20:20:13 UTC |
48 |
+++ src/openrct2/common.h |
49 |
@@ -71,6 +71,10 @@ using colour_t = uint8_t; |
50 |
# define RCT2_ENDIANESS __ORDER_LITTLE_ENDIAN__ |
51 |
# define LOBYTE(w) ((uint8_t)(w)) |
52 |
# define HIBYTE(w) ((uint8_t)(((uint16_t)(w) >> 8) & 0xFF)) |
53 |
+# else |
54 |
+# define RCT2_ENDIANESS __ORDER_BIG_ENDIAN__ |
55 |
+# define HIBYTE(w) ((uint8_t)(w)) |
56 |
+# define LOBYTE(w) ((uint8_t)(((uint16_t)(w) >> 8) & 0xFF)) |
57 |
# endif // __BYTE_ORDER__ |
58 |
|
59 |
# ifndef RCT2_ENDIANESS |
60 |
--- src/openrct2/core/FileIndex.hpp.orig 2018-08-26 20:20:13 UTC |
61 |
+++ src/openrct2/core/FileIndex.hpp |
62 |
@@ -10,6 +10,7 @@ |
63 |
#pragma once |
64 |
|
65 |
#include "../common.h" |
66 |
+#include "../util/Endian.h" |
67 |
#include "Console.hpp" |
68 |
#include "File.h" |
69 |
#include "FileScanner.h" |
70 |
@@ -264,6 +265,14 @@ template<typename TItem> class FileIndex (private) |
71 |
|
72 |
// Read header, check if we need to re-scan |
73 |
auto header = fs.ReadValue<FileIndexHeader>(); |
74 |
+ header.HeaderSize = ORCT_SwapLEu32(header.HeaderSize); |
75 |
+ header.MagicNumber = ORCT_SwapLEu32(header.MagicNumber); |
76 |
+ header.LanguageId = ORCT_SwapLEu16(header.LanguageId); |
77 |
+ header.NumItems = ORCT_SwapLEu32(header.NumItems); |
78 |
+ header.Stats.TotalFiles = ORCT_SwapLEu32(header.Stats.TotalFiles); |
79 |
+ header.Stats.TotalFileSize = ORCT_SwapLEu64(header.Stats.TotalFileSize); |
80 |
+ header.Stats.FileDateModifiedChecksum = ORCT_SwapLEu32(header.Stats.FileDateModifiedChecksum); |
81 |
+ header.Stats.PathChecksum = ORCT_SwapLEu32(header.Stats.PathChecksum); |
82 |
if (header.HeaderSize == sizeof(FileIndexHeader) && header.MagicNumber == _magicNumber |
83 |
&& header.VersionA == FILE_INDEX_VERSION && header.VersionB == _version && header.LanguageId == language |
84 |
&& header.Stats.TotalFiles == stats.TotalFiles && header.Stats.TotalFileSize == stats.TotalFileSize |
85 |
--- src/openrct2/drawing/Drawing.Sprite.cpp.orig 2018-08-26 20:20:13 UTC |
86 |
+++ src/openrct2/drawing/Drawing.Sprite.cpp |
87 |
@@ -16,6 +16,7 @@ |
88 |
#include "../platform/platform.h" |
89 |
#include "../sprites.h" |
90 |
#include "../ui/UiContext.h" |
91 |
+#include "../util/Endian.h" |
92 |
#include "../util/Util.h" |
93 |
#include "Drawing.h" |
94 |
|
95 |
@@ -237,6 +238,8 @@ bool gfx_load_g1(const IPlatformEnvironment& env) |
96 |
auto path = Path::Combine(env.GetDirectoryPath(DIRBASE::RCT2, DIRID::DATA), "g1.dat"); |
97 |
auto fs = FileStream(path, FILE_MODE_OPEN); |
98 |
_g1.header = fs.ReadValue<rct_g1_header>(); |
99 |
+ _g1.header.num_entries = ORCT_SwapLEu32(_g1.header.num_entries); |
100 |
+ _g1.header.total_size = ORCT_SwapLEu32(_g1.header.total_size); |
101 |
|
102 |
log_verbose("g1.dat, number of entries: %u", _g1.header.num_entries); |
103 |
|
104 |
@@ -309,6 +312,8 @@ bool gfx_load_g2() |
105 |
{ |
106 |
auto fs = FileStream(path, FILE_MODE_OPEN); |
107 |
_g2.header = fs.ReadValue<rct_g1_header>(); |
108 |
+ _g2.header.num_entries = ORCT_SwapLEu32(_g2.header.num_entries); |
109 |
+ _g2.header.total_size = ORCT_SwapLEu32(_g2.header.total_size); |
110 |
|
111 |
// Read element headers |
112 |
_g2.elements.resize(_g2.header.num_entries); |
113 |
--- src/openrct2/object/BannerObject.cpp.orig 2018-08-26 20:20:13 UTC |
114 |
+++ src/openrct2/object/BannerObject.cpp |
115 |
@@ -14,6 +14,7 @@ |
116 |
#include "../localisation/Language.h" |
117 |
#include "../object/Object.h" |
118 |
#include "../object/ObjectRepository.h" |
119 |
+#include "../util/Endian.h" |
120 |
#include "ObjectJsonHelpers.h" |
121 |
#include "ObjectList.h" |
122 |
|
123 |
@@ -22,13 +23,14 @@ void BannerObject::ReadLegacy(IReadObjectContext* cont |
124 |
stream->Seek(6, STREAM_SEEK_CURRENT); |
125 |
_legacyType.banner.scrolling_mode = stream->ReadValue<uint8_t>(); |
126 |
_legacyType.banner.flags = stream->ReadValue<uint8_t>(); |
127 |
- _legacyType.banner.price = stream->ReadValue<int16_t>(); |
128 |
+ _legacyType.banner.price = ORCT_SwapLEi16(stream->ReadValue<int16_t>()); |
129 |
_legacyType.banner.scenery_tab_id = stream->ReadValue<uint8_t>(); |
130 |
stream->Seek(1, STREAM_SEEK_CURRENT); |
131 |
|
132 |
GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME); |
133 |
|
134 |
rct_object_entry sgEntry = stream->ReadValue<rct_object_entry>(); |
135 |
+ sgEntry.flags = ORCT_SwapLEu32(sgEntry.flags); |
136 |
SetPrimarySceneryGroup(&sgEntry); |
137 |
|
138 |
GetImageTable().Read(context, stream); |
139 |
--- src/openrct2/object/FootpathItemObject.cpp.orig 2018-08-26 20:20:13 UTC |
140 |
+++ src/openrct2/object/FootpathItemObject.cpp |
141 |
@@ -15,6 +15,7 @@ |
142 |
#include "../localisation/Localisation.h" |
143 |
#include "../object/Object.h" |
144 |
#include "../object/ObjectRepository.h" |
145 |
+#include "../util/Endian.h" |
146 |
#include "ObjectJsonHelpers.h" |
147 |
#include "ObjectList.h" |
148 |
|
149 |
@@ -23,16 +24,17 @@ |
150 |
void FootpathItemObject::ReadLegacy(IReadObjectContext* context, IStream* stream) |
151 |
{ |
152 |
stream->Seek(6, STREAM_SEEK_CURRENT); |
153 |
- _legacyType.path_bit.flags = stream->ReadValue<uint16_t>(); |
154 |
+ _legacyType.path_bit.flags = ORCT_SwapLEu16(stream->ReadValue<uint16_t>()); |
155 |
_legacyType.path_bit.draw_type = stream->ReadValue<uint8_t>(); |
156 |
_legacyType.path_bit.tool_id = stream->ReadValue<uint8_t>(); |
157 |
- _legacyType.path_bit.price = stream->ReadValue<int16_t>(); |
158 |
+ _legacyType.path_bit.price = ORCT_SwapLEi16(stream->ReadValue<int16_t>()); |
159 |
_legacyType.path_bit.scenery_tab_id = stream->ReadValue<uint8_t>(); |
160 |
stream->Seek(1, STREAM_SEEK_CURRENT); |
161 |
|
162 |
GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME); |
163 |
|
164 |
rct_object_entry sgEntry = stream->ReadValue<rct_object_entry>(); |
165 |
+ sgEntry.flags = ORCT_SwapLEu32(sgEntry.flags); |
166 |
SetPrimarySceneryGroup(&sgEntry); |
167 |
|
168 |
GetImageTable().Read(context, stream); |
169 |
--- src/openrct2/object/ImageTable.cpp.orig 2018-08-26 20:20:13 UTC |
170 |
+++ src/openrct2/object/ImageTable.cpp |
171 |
@@ -11,6 +11,7 @@ |
172 |
|
173 |
#include "../OpenRCT2.h" |
174 |
#include "../core/IStream.hpp" |
175 |
+#include "../util/Endian.h" |
176 |
#include "Object.h" |
177 |
|
178 |
#include <algorithm> |
179 |
@@ -37,8 +38,8 @@ void ImageTable::Read(IReadObjectContext* context, ISt |
180 |
|
181 |
try |
182 |
{ |
183 |
- uint32_t numImages = stream->ReadValue<uint32_t>(); |
184 |
- uint32_t imageDataSize = stream->ReadValue<uint32_t>(); |
185 |
+ uint32_t numImages = ORCT_SwapLEu32(stream->ReadValue<uint32_t>()); |
186 |
+ uint32_t imageDataSize = ORCT_SwapLEu32(stream->ReadValue<uint32_t>()); |
187 |
|
188 |
uint64_t headerTableSize = numImages * 16; |
189 |
uint64_t remainingBytes = stream->GetLength() - stream->GetPosition() - headerTableSize; |
190 |
@@ -63,15 +64,15 @@ void ImageTable::Read(IReadObjectContext* context, ISt |
191 |
{ |
192 |
rct_g1_element g1Element; |
193 |
|
194 |
- uintptr_t imageDataOffset = (uintptr_t)stream->ReadValue<uint32_t>(); |
195 |
+ uintptr_t imageDataOffset = ORCT_SwapLEu32((uintptr_t)stream->ReadValue<uint32_t>()); |
196 |
g1Element.offset = (uint8_t*)(imageDataBase + imageDataOffset); |
197 |
|
198 |
- g1Element.width = stream->ReadValue<int16_t>(); |
199 |
- g1Element.height = stream->ReadValue<int16_t>(); |
200 |
- g1Element.x_offset = stream->ReadValue<int16_t>(); |
201 |
- g1Element.y_offset = stream->ReadValue<int16_t>(); |
202 |
- g1Element.flags = stream->ReadValue<uint16_t>(); |
203 |
- g1Element.zoomed_offset = stream->ReadValue<uint16_t>(); |
204 |
+ g1Element.width = ORCT_SwapLEi16(stream->ReadValue<int16_t>()); |
205 |
+ g1Element.height = ORCT_SwapLEi16(stream->ReadValue<int16_t>()); |
206 |
+ g1Element.x_offset = ORCT_SwapLEi16(stream->ReadValue<int16_t>()); |
207 |
+ g1Element.y_offset = ORCT_SwapLEi16(stream->ReadValue<int16_t>()); |
208 |
+ g1Element.flags = ORCT_SwapLEu16(stream->ReadValue<uint16_t>()); |
209 |
+ g1Element.zoomed_offset = ORCT_SwapLEu16(stream->ReadValue<uint16_t>()); |
210 |
|
211 |
newEntries.push_back(g1Element); |
212 |
} |
213 |
--- src/openrct2/object/LargeSceneryObject.cpp.orig 2018-08-26 20:20:13 UTC |
214 |
+++ src/openrct2/object/LargeSceneryObject.cpp |
215 |
@@ -17,6 +17,7 @@ |
216 |
#include "../drawing/Drawing.h" |
217 |
#include "../interface/Cursors.h" |
218 |
#include "../localisation/Language.h" |
219 |
+#include "../util/Endian.h" |
220 |
#include "../world/Location.hpp" |
221 |
#include "ObjectJsonHelpers.h" |
222 |
|
223 |
@@ -27,8 +28,8 @@ void LargeSceneryObject::ReadLegacy(IReadObjectContext |
224 |
stream->Seek(6, STREAM_SEEK_CURRENT); |
225 |
_legacyType.large_scenery.tool_id = stream->ReadValue<uint8_t>(); |
226 |
_legacyType.large_scenery.flags = stream->ReadValue<uint8_t>(); |
227 |
- _legacyType.large_scenery.price = stream->ReadValue<int16_t>(); |
228 |
- _legacyType.large_scenery.removal_price = stream->ReadValue<int16_t>(); |
229 |
+ _legacyType.large_scenery.price = ORCT_SwapLEi16(stream->ReadValue<int16_t>()); |
230 |
+ _legacyType.large_scenery.removal_price = ORCT_SwapLEi16(stream->ReadValue<int16_t>()); |
231 |
stream->Seek(5, STREAM_SEEK_CURRENT); |
232 |
_legacyType.large_scenery.scenery_tab_id = 0xFF; |
233 |
_legacyType.large_scenery.scrolling_mode = stream->ReadValue<uint8_t>(); |
234 |
@@ -37,6 +38,7 @@ void LargeSceneryObject::ReadLegacy(IReadObjectContext |
235 |
GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME); |
236 |
|
237 |
rct_object_entry sgEntry = stream->ReadValue<rct_object_entry>(); |
238 |
+ sgEntry.flags = ORCT_SwapLEu32(sgEntry.flags); |
239 |
SetPrimarySceneryGroup(&sgEntry); |
240 |
|
241 |
if (_legacyType.large_scenery.flags & LARGE_SCENERY_FLAG_3D_TEXT) |
242 |
@@ -111,10 +113,17 @@ void LargeSceneryObject::DrawPreview(rct_drawpixelinfo |
243 |
std::vector<rct_large_scenery_tile> LargeSceneryObject::ReadTiles(IStream* stream) |
244 |
{ |
245 |
auto tiles = std::vector<rct_large_scenery_tile>(); |
246 |
+ // Note: no need to swap the value here... |
247 |
while (stream->ReadValue<uint16_t>() != 0xFFFF) |
248 |
{ |
249 |
stream->Seek(-2, STREAM_SEEK_CURRENT); |
250 |
+ |
251 |
auto tile = stream->ReadValue<rct_large_scenery_tile>(); |
252 |
+ tile.x_offset = ORCT_SwapLEi16(tile.x_offset); |
253 |
+ tile.y_offset = ORCT_SwapLEi16(tile.y_offset); |
254 |
+ tile.z_offset = ORCT_SwapLEi16(tile.z_offset); |
255 |
+ tile.z_clearance = ORCT_SwapLEi16(tile.z_clearance); |
256 |
+ tile.flags = ORCT_SwapLEi16(tile.flags); |
257 |
tiles.push_back(tile); |
258 |
} |
259 |
tiles.push_back({ -1, -1, -1, 255, 0xFFFF }); |
260 |
--- src/openrct2/object/ObjectFactory.cpp.orig 2018-08-26 20:20:13 UTC |
261 |
+++ src/openrct2/object/ObjectFactory.cpp |
262 |
@@ -20,6 +20,7 @@ |
263 |
#include "../core/String.hpp" |
264 |
#include "../core/Zip.h" |
265 |
#include "../rct12/SawyerChunkReader.h" |
266 |
+#include "../util/Endian.h" |
267 |
#include "BannerObject.h" |
268 |
#include "EntranceObject.h" |
269 |
#include "FootpathItemObject.h" |
270 |
--- src/openrct2/object/ObjectRepository.cpp.orig 2018-08-26 20:20:13 UTC |
271 |
+++ src/openrct2/object/ObjectRepository.cpp |
272 |
@@ -29,6 +29,7 @@ |
273 |
#include "../rct12/SawyerChunkReader.h" |
274 |
#include "../rct12/SawyerChunkWriter.h" |
275 |
#include "../scenario/ScenarioRepository.h" |
276 |
+#include "../util/Endian.h" |
277 |
#include "../util/SawyerCoding.h" |
278 |
#include "../util/Util.h" |
279 |
#include "Object.h" |
280 |
@@ -162,6 +163,7 @@ class ObjectFileIndex final : public FileIndex<ObjectR |
281 |
ObjectRepositoryItem item; |
282 |
|
283 |
item.ObjectEntry = stream->ReadValue<rct_object_entry>(); |
284 |
+ item.ObjectEntry.flags = ORCT_SwapLEu32(item.ObjectEntry.flags); |
285 |
item.Path = stream->ReadStdString(); |
286 |
item.Name = stream->ReadStdString(); |
287 |
auto sourceLength = stream->ReadValue<uint8_t>(); |
288 |
@@ -187,11 +189,12 @@ class ObjectFileIndex final : public FileIndex<ObjectR |
289 |
break; |
290 |
case OBJECT_TYPE_SCENERY_GROUP: |
291 |
{ |
292 |
- auto numEntries = stream->ReadValue<uint16_t>(); |
293 |
+ auto numEntries = ORCT_SwapLEu16(stream->ReadValue<uint16_t>()); |
294 |
item.SceneryGroupInfo.Entries = std::vector<rct_object_entry>(numEntries); |
295 |
for (size_t i = 0; i < numEntries; i++) |
296 |
{ |
297 |
item.SceneryGroupInfo.Entries[i] = stream->ReadValue<rct_object_entry>(); |
298 |
+ item.SceneryGroupInfo.Entries[i].flags = ORCT_SwapLEu32(item.SceneryGroupInfo.Entries[i].flags); |
299 |
} |
300 |
break; |
301 |
} |
302 |
@@ -346,6 +349,7 @@ class ObjectRepository final : public IObjectRepositor |
303 |
|
304 |
// Check if we already have this object |
305 |
rct_object_entry entry = stream->ReadValue<rct_object_entry>(); |
306 |
+ entry.flags = ORCT_SwapLEu32(entry.flags); |
307 |
if (FindObject(&entry) != nullptr) |
308 |
{ |
309 |
chunkReader.SkipChunk(); |
310 |
@@ -605,6 +609,7 @@ class ObjectRepository final : public IObjectRepositor |
311 |
// Read object data from file |
312 |
auto fs = FileStream(item->Path, FILE_MODE_OPEN); |
313 |
auto fileEntry = fs.ReadValue<rct_object_entry>(); |
314 |
+ fileEntry.flags = ORCT_SwapLEu32(fileEntry.flags); |
315 |
if (!object_entry_compare(entry, &fileEntry)) |
316 |
{ |
317 |
throw std::runtime_error("Header found in object file does not match object to pack."); |
318 |
--- src/openrct2/object/RideObject.cpp.orig 2018-08-26 20:20:13 UTC |
319 |
+++ src/openrct2/object/RideObject.cpp |
320 |
@@ -23,6 +23,7 @@ |
321 |
#include "../ride/RideGroupManager.h" |
322 |
#include "../ride/ShopItem.h" |
323 |
#include "../ride/Track.h" |
324 |
+#include "../util/Endian.h" |
325 |
#include "ObjectJsonHelpers.h" |
326 |
#include "ObjectRepository.h" |
327 |
|
328 |
@@ -34,7 +35,7 @@ using namespace OpenRCT2; |
329 |
void RideObject::ReadLegacy(IReadObjectContext* context, IStream* stream) |
330 |
{ |
331 |
stream->Seek(8, STREAM_SEEK_CURRENT); |
332 |
- _legacyType.flags = stream->ReadValue<uint32_t>(); |
333 |
+ _legacyType.flags = ORCT_SwapLEu32(stream->ReadValue<uint32_t>()); |
334 |
for (auto& rideType : _legacyType.ride_type) |
335 |
{ |
336 |
rideType = stream->ReadValue<uint8_t>(); |
337 |
@@ -59,7 +60,7 @@ void RideObject::ReadLegacy(IReadObjectContext* contex |
338 |
_legacyType.intensity_multiplier = stream->ReadValue<int8_t>(); |
339 |
_legacyType.nausea_multiplier = stream->ReadValue<int8_t>(); |
340 |
_legacyType.max_height = stream->ReadValue<uint8_t>(); |
341 |
- _legacyType.enabledTrackPieces = stream->ReadValue<uint64_t>(); |
342 |
+ _legacyType.enabledTrackPieces = ORCT_SwapLEu64(stream->ReadValue<uint64_t>()); |
343 |
_legacyType.category[0] = stream->ReadValue<uint8_t>(); |
344 |
_legacyType.category[1] = stream->ReadValue<uint8_t>(); |
345 |
_legacyType.shop_item = stream->ReadValue<uint8_t>(); |
346 |
@@ -94,7 +95,7 @@ void RideObject::ReadLegacy(IReadObjectContext* contex |
347 |
uint16_t numPeepLoadingPositions = stream->ReadValue<uint8_t>(); |
348 |
if (numPeepLoadingPositions == 255) |
349 |
{ |
350 |
- numPeepLoadingPositions = stream->ReadValue<uint16_t>(); |
351 |
+ numPeepLoadingPositions = ORCT_SwapLEu16(stream->ReadValue<uint16_t>()); |
352 |
} |
353 |
|
354 |
if (_legacyType.vehicles[i].flags & VEHICLE_ENTRY_FLAG_LOADING_WAYPOINTS) |
355 |
@@ -116,7 +117,7 @@ void RideObject::ReadLegacy(IReadObjectContext* contex |
356 |
entry[1].y = stream->ReadValue<int8_t>(); |
357 |
entry[2].x = stream->ReadValue<int8_t>(); |
358 |
entry[2].y = stream->ReadValue<int8_t>(); |
359 |
- stream->ReadValue<uint16_t>(); // Skip blanks |
360 |
+ stream->ReadValue<uint16_t>(); // Skip blanks, no need to swap endianess |
361 |
|
362 |
_peepLoadingWaypoints[i].push_back(entry); |
363 |
} |
364 |
@@ -412,19 +413,19 @@ void RideObject::SetRepositoryItem(ObjectRepositoryIte |
365 |
void RideObject::ReadLegacyVehicle( |
366 |
[[maybe_unused]] IReadObjectContext* context, IStream* stream, rct_ride_entry_vehicle* vehicle) |
367 |
{ |
368 |
- vehicle->rotation_frame_mask = stream->ReadValue<uint16_t>(); |
369 |
+ vehicle->rotation_frame_mask = ORCT_SwapLEu16(stream->ReadValue<uint16_t>()); |
370 |
stream->Seek(2 * 1, STREAM_SEEK_CURRENT); |
371 |
- vehicle->spacing = stream->ReadValue<uint32_t>(); |
372 |
- vehicle->car_mass = stream->ReadValue<uint16_t>(); |
373 |
+ vehicle->spacing = ORCT_SwapLEu32(stream->ReadValue<uint32_t>()); |
374 |
+ vehicle->car_mass = ORCT_SwapLEu16(stream->ReadValue<uint16_t>()); |
375 |
vehicle->tab_height = stream->ReadValue<int8_t>(); |
376 |
vehicle->num_seats = stream->ReadValue<uint8_t>(); |
377 |
- vehicle->sprite_flags = stream->ReadValue<uint16_t>(); |
378 |
+ vehicle->sprite_flags = ORCT_SwapLEu16(stream->ReadValue<uint16_t>()); |
379 |
vehicle->sprite_width = stream->ReadValue<uint8_t>(); |
380 |
vehicle->sprite_height_negative = stream->ReadValue<uint8_t>(); |
381 |
vehicle->sprite_height_positive = stream->ReadValue<uint8_t>(); |
382 |
vehicle->animation = stream->ReadValue<uint8_t>(); |
383 |
- vehicle->flags = stream->ReadValue<uint32_t>(); |
384 |
- vehicle->base_num_frames = stream->ReadValue<uint16_t>(); |
385 |
+ vehicle->flags = ORCT_SwapLEu32(stream->ReadValue<uint32_t>()); |
386 |
+ vehicle->base_num_frames = ORCT_SwapLEu16(stream->ReadValue<uint16_t>()); |
387 |
stream->Seek(15 * 4, STREAM_SEEK_CURRENT); |
388 |
vehicle->no_seating_rows = stream->ReadValue<uint8_t>(); |
389 |
vehicle->spinning_inertia = stream->ReadValue<uint8_t>(); |
390 |
--- src/openrct2/object/SceneryGroupObject.cpp.orig 2018-08-26 20:20:13 UTC |
391 |
+++ src/openrct2/object/SceneryGroupObject.cpp |
392 |
@@ -18,6 +18,7 @@ |
393 |
#include "../drawing/Drawing.h" |
394 |
#include "../localisation/Language.h" |
395 |
#include "../peep/Staff.h" |
396 |
+#include "../util/Endian.h" |
397 |
#include "ObjectJsonHelpers.h" |
398 |
#include "ObjectManager.h" |
399 |
#include "ObjectRepository.h" |
400 |
@@ -34,7 +35,7 @@ void SceneryGroupObject::ReadLegacy(IReadObjectContext |
401 |
_legacyType.pad_107 = stream->ReadValue<uint8_t>(); |
402 |
_legacyType.priority = stream->ReadValue<uint8_t>(); |
403 |
_legacyType.pad_109 = stream->ReadValue<uint8_t>(); |
404 |
- _legacyType.entertainer_costumes = stream->ReadValue<uint32_t>(); |
405 |
+ _legacyType.entertainer_costumes = ORCT_SwapLEu32(stream->ReadValue<uint32_t>()); |
406 |
|
407 |
GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME); |
408 |
_items = ReadItems(stream); |
409 |
@@ -126,6 +127,7 @@ std::vector<rct_object_entry> SceneryGroupObject::Read |
410 |
{ |
411 |
stream->Seek(-1, STREAM_SEEK_CURRENT); |
412 |
auto entry = stream->ReadValue<rct_object_entry>(); |
413 |
+ entry.flags = ORCT_SwapLEu32(entry.flags); |
414 |
items.push_back(entry); |
415 |
} |
416 |
return items; |
417 |
--- src/openrct2/object/SmallSceneryObject.cpp.orig 2018-08-26 20:20:13 UTC |
418 |
+++ src/openrct2/object/SmallSceneryObject.cpp |
419 |
@@ -17,6 +17,7 @@ |
420 |
#include "../drawing/Drawing.h" |
421 |
#include "../interface/Cursors.h" |
422 |
#include "../localisation/Language.h" |
423 |
+#include "../util/Endian.h" |
424 |
#include "../world/Scenery.h" |
425 |
#include "../world/SmallScenery.h" |
426 |
#include "ObjectJsonHelpers.h" |
427 |
@@ -26,20 +27,21 @@ |
428 |
void SmallSceneryObject::ReadLegacy(IReadObjectContext* context, IStream* stream) |
429 |
{ |
430 |
stream->Seek(6, STREAM_SEEK_CURRENT); |
431 |
- _legacyType.small_scenery.flags = stream->ReadValue<uint32_t>(); |
432 |
+ _legacyType.small_scenery.flags = ORCT_SwapLEu32(stream->ReadValue<uint32_t>()); |
433 |
_legacyType.small_scenery.height = stream->ReadValue<uint8_t>(); |
434 |
_legacyType.small_scenery.tool_id = stream->ReadValue<uint8_t>(); |
435 |
- _legacyType.small_scenery.price = stream->ReadValue<int16_t>(); |
436 |
- _legacyType.small_scenery.removal_price = stream->ReadValue<int16_t>(); |
437 |
+ _legacyType.small_scenery.price = ORCT_SwapLEu16(stream->ReadValue<int16_t>()); |
438 |
+ _legacyType.small_scenery.removal_price = ORCT_SwapLEu16(stream->ReadValue<int16_t>()); |
439 |
stream->Seek(4, STREAM_SEEK_CURRENT); |
440 |
- _legacyType.small_scenery.animation_delay = stream->ReadValue<uint16_t>(); |
441 |
- _legacyType.small_scenery.animation_mask = stream->ReadValue<uint16_t>(); |
442 |
- _legacyType.small_scenery.num_frames = stream->ReadValue<uint16_t>(); |
443 |
+ _legacyType.small_scenery.animation_delay = ORCT_SwapLEu16(stream->ReadValue<uint16_t>()); |
444 |
+ _legacyType.small_scenery.animation_mask = ORCT_SwapLEu16(stream->ReadValue<uint16_t>()); |
445 |
+ _legacyType.small_scenery.num_frames = ORCT_SwapLEu16(stream->ReadValue<uint16_t>()); |
446 |
_legacyType.small_scenery.scenery_tab_id = 0xFF; |
447 |
|
448 |
GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME); |
449 |
|
450 |
rct_object_entry sgEntry = stream->ReadValue<rct_object_entry>(); |
451 |
+ sgEntry.flags = ORCT_SwapLEu32(sgEntry.flags); |
452 |
SetPrimarySceneryGroup(&sgEntry); |
453 |
|
454 |
if (scenery_small_entry_has_flag(&_legacyType, SMALL_SCENERY_FLAG_HAS_FRAME_OFFSETS)) |
455 |
--- src/openrct2/object/WallObject.cpp.orig 2018-08-26 20:20:13 UTC |
456 |
+++ src/openrct2/object/WallObject.cpp |
457 |
@@ -13,6 +13,7 @@ |
458 |
#include "../drawing/Drawing.h" |
459 |
#include "../interface/Cursors.h" |
460 |
#include "../localisation/Language.h" |
461 |
+#include "../util/Endian.h" |
462 |
#include "ObjectJsonHelpers.h" |
463 |
|
464 |
void WallObject::ReadLegacy(IReadObjectContext* context, IStream* stream) |
465 |
@@ -22,13 +23,14 @@ void WallObject::ReadLegacy(IReadObjectContext* contex |
466 |
_legacyType.wall.flags = stream->ReadValue<uint8_t>(); |
467 |
_legacyType.wall.height = stream->ReadValue<uint8_t>(); |
468 |
_legacyType.wall.flags2 = stream->ReadValue<uint8_t>(); |
469 |
- _legacyType.wall.price = stream->ReadValue<uint16_t>(); |
470 |
+ _legacyType.wall.price = ORCT_SwapLEu16(stream->ReadValue<uint16_t>()); |
471 |
_legacyType.wall.scenery_tab_id = stream->ReadValue<uint8_t>(); |
472 |
_legacyType.wall.scrolling_mode = stream->ReadValue<uint8_t>(); |
473 |
|
474 |
GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME); |
475 |
|
476 |
rct_object_entry sgEntry = stream->ReadValue<rct_object_entry>(); |
477 |
+ sgEntry.flags = ORCT_SwapLEu16(sgEntry.flags); |
478 |
SetPrimarySceneryGroup(&sgEntry); |
479 |
|
480 |
GetImageTable().Read(context, stream); |
481 |
--- src/openrct2/object/WaterObject.cpp.orig 2018-08-26 20:20:13 UTC |
482 |
+++ src/openrct2/object/WaterObject.cpp |
483 |
@@ -15,6 +15,7 @@ |
484 |
#include "../core/IStream.hpp" |
485 |
#include "../localisation/Language.h" |
486 |
#include "../localisation/StringIds.h" |
487 |
+#include "../util/Endian.h" |
488 |
#include "ObjectJsonHelpers.h" |
489 |
|
490 |
#include <memory> |
491 |
@@ -22,7 +23,7 @@ |
492 |
void WaterObject::ReadLegacy(IReadObjectContext* context, IStream* stream) |
493 |
{ |
494 |
stream->Seek(14, STREAM_SEEK_CURRENT); |
495 |
- _legacyType.flags = stream->ReadValue<uint16_t>(); |
496 |
+ _legacyType.flags = ORCT_SwapLEu16(stream->ReadValue<uint16_t>()); |
497 |
|
498 |
GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME); |
499 |
GetImageTable().Read(context, stream); |
500 |
--- src/openrct2/rct12/SawyerChunkReader.cpp.orig 2018-08-26 20:20:13 UTC |
501 |
+++ src/openrct2/rct12/SawyerChunkReader.cpp |
502 |
@@ -10,6 +10,7 @@ |
503 |
#include "SawyerChunkReader.h" |
504 |
|
505 |
#include "../core/IStream.hpp" |
506 |
+#include "../util/Endian.h" |
507 |
|
508 |
// malloc is very slow for large allocations in MSVC debug builds as it allocates |
509 |
// memory on a special debug heap and then initialises all the memory to 0xCC. |
510 |
@@ -51,6 +52,7 @@ void SawyerChunkReader::SkipChunk() |
511 |
try |
512 |
{ |
513 |
auto header = _stream->ReadValue<sawyercoding_chunk_header>(); |
514 |
+ header.length = ORCT_SwapLEu32(header.length); |
515 |
_stream->Seek(header.length, STREAM_SEEK_CURRENT); |
516 |
} |
517 |
catch (const std::exception&) |
518 |
@@ -67,6 +69,7 @@ std::shared_ptr<SawyerChunk> SawyerChunkReader::ReadCh |
519 |
try |
520 |
{ |
521 |
auto header = _stream->ReadValue<sawyercoding_chunk_header>(); |
522 |
+ header.length = ORCT_SwapLEu32(header.length); |
523 |
switch (header.encoding) |
524 |
{ |
525 |
case CHUNK_ENCODING_NONE: |
526 |
--- src/openrct2/rct12/SawyerEncoding.cpp.orig 2018-08-26 20:20:13 UTC |
527 |
+++ src/openrct2/rct12/SawyerEncoding.cpp |
528 |
@@ -10,6 +10,7 @@ |
529 |
#include "SawyerEncoding.h" |
530 |
|
531 |
#include "../core/IStream.hpp" |
532 |
+#include "../util/Endian.h" |
533 |
|
534 |
#include <algorithm> |
535 |
|
536 |
@@ -44,7 +45,7 @@ namespace SawyerEncoding |
537 |
} while (dataSize != 0); |
538 |
|
539 |
// Read file checksum |
540 |
- uint32_t fileChecksum = stream->ReadValue<uint32_t>(); |
541 |
+ uint32_t fileChecksum = ORCT_SwapLEu32(stream->ReadValue<uint32_t>()); |
542 |
|
543 |
// Rewind back to original position |
544 |
stream->SetPosition(initialPosition); |
545 |
--- src/openrct2/ride/TrackDesignRepository.cpp.orig 2018-08-26 20:20:13 UTC |
546 |
+++ src/openrct2/ride/TrackDesignRepository.cpp |
547 |
@@ -22,6 +22,7 @@ |
548 |
#include "../localisation/LocalisationService.h" |
549 |
#include "../object/ObjectRepository.h" |
550 |
#include "../object/RideObject.h" |
551 |
+#include "../util/Endian.h" |
552 |
#include "RideGroupManager.h" |
553 |
#include "TrackDesign.h" |
554 |
|
555 |
@@ -114,7 +115,7 @@ class TrackDesignFileIndex final : public FileIndex<Tr |
556 |
item.Path = stream->ReadStdString(); |
557 |
item.RideType = stream->ReadValue<uint8_t>(); |
558 |
item.ObjectEntry = stream->ReadStdString(); |
559 |
- item.Flags = stream->ReadValue<uint32_t>(); |
560 |
+ item.Flags = ORCT_SwapLEu32(stream->ReadValue<uint32_t>()); |
561 |
return item; |
562 |
} |
563 |
|
564 |
--- src/openrct2/scenario/ScenarioRepository.cpp.orig 2018-08-26 20:20:13 UTC |
565 |
+++ src/openrct2/scenario/ScenarioRepository.cpp |
566 |
@@ -26,6 +26,7 @@ |
567 |
#include "../localisation/LocalisationService.h" |
568 |
#include "../platform/platform.h" |
569 |
#include "../rct12/SawyerChunkReader.h" |
570 |
+#include "../util/Endian.h" |
571 |
#include "Scenario.h" |
572 |
#include "ScenarioSources.h" |
573 |
|
574 |
@@ -183,17 +184,17 @@ class ScenarioFileIndex final : public FileIndex<scena |
575 |
scenario_index_entry item; |
576 |
|
577 |
stream->Read(item.path, sizeof(item.path)); |
578 |
- item.timestamp = stream->ReadValue<uint64_t>(); |
579 |
+ item.timestamp = ORCT_SwapLEu64(stream->ReadValue<uint64_t>()); |
580 |
|
581 |
item.category = stream->ReadValue<uint8_t>(); |
582 |
item.source_game = stream->ReadValue<uint8_t>(); |
583 |
- item.source_index = stream->ReadValue<int16_t>(); |
584 |
- item.sc_id = stream->ReadValue<uint16_t>(); |
585 |
+ item.source_index = ORCT_SwapLEi16(stream->ReadValue<int16_t>()); |
586 |
+ item.sc_id = ORCT_SwapLEu16(stream->ReadValue<uint16_t>()); |
587 |
|
588 |
item.objective_type = stream->ReadValue<uint8_t>(); |
589 |
item.objective_arg_1 = stream->ReadValue<uint8_t>(); |
590 |
- item.objective_arg_2 = stream->ReadValue<int32_t>(); |
591 |
- item.objective_arg_3 = stream->ReadValue<int16_t>(); |
592 |
+ item.objective_arg_2 = ORCT_SwapLEi32(stream->ReadValue<int32_t>()); |
593 |
+ item.objective_arg_3 = ORCT_SwapLEi16(stream->ReadValue<int16_t>()); |
594 |
item.highscore = nullptr; |
595 |
|
596 |
stream->Read(item.internal_name, sizeof(item.internal_name)); |
597 |
@@ -588,7 +589,7 @@ class ScenarioRepository final : public IScenarioRepos |
598 |
try |
599 |
{ |
600 |
auto fs = FileStream(path, FILE_MODE_OPEN); |
601 |
- uint32_t fileVersion = fs.ReadValue<uint32_t>(); |
602 |
+ uint32_t fileVersion = ORCT_SwapLEu32(fs.ReadValue<uint32_t>()); |
603 |
if (fileVersion != 1) |
604 |
{ |
605 |
Console::Error::WriteLine("Invalid or incompatible highscores file."); |
606 |
@@ -597,14 +598,14 @@ class ScenarioRepository final : public IScenarioRepos |
607 |
|
608 |
ClearHighscores(); |
609 |
|
610 |
- uint32_t numHighscores = fs.ReadValue<uint32_t>(); |
611 |
+ uint32_t numHighscores = ORCT_SwapLEu32(fs.ReadValue<uint32_t>()); |
612 |
for (uint32_t i = 0; i < numHighscores; i++) |
613 |
{ |
614 |
scenario_highscore_entry* highscore = InsertHighscore(); |
615 |
highscore->fileName = fs.ReadString(); |
616 |
highscore->name = fs.ReadString(); |
617 |
- highscore->company_value = fs.ReadValue<money32>(); |
618 |
- highscore->timestamp = fs.ReadValue<datetime64>(); |
619 |
+ highscore->company_value = ORCT_SwapLEi32(fs.ReadValue<money32>()); |
620 |
+ highscore->timestamp = ORCT_SwapLEu64(fs.ReadValue<datetime64>()); |
621 |
} |
622 |
} |
623 |
catch (const std::exception&) |
624 |
@@ -648,6 +649,10 @@ class ScenarioRepository final : public IScenarioRepos |
625 |
{ |
626 |
// Read legacy entry |
627 |
auto scBasic = fs.ReadValue<rct_scores_entry>(); |
628 |
+ scBasic.objectiveArg2 = ORCT_SwapLEi32(scBasic.objectiveArg2); |
629 |
+ scBasic.objectiveArg3 = ORCT_SwapLEi16(scBasic.objectiveArg3); |
630 |
+ scBasic.Flags = ORCT_SwapLEi32(scBasic.Flags); |
631 |
+ scBasic.CompanyValue = ORCT_SwapLEi32(scBasic.CompanyValue); |
632 |
|
633 |
// Ignore non-completed scenarios |
634 |
if (scBasic.Flags & SCENARIO_FLAGS_COMPLETED) |
635 |
--- src/openrct2/util/Endian.h.orig 2018-11-22 13:14:25 UTC |
636 |
+++ src/openrct2/util/Endian.h |
637 |
@@ -0,0 +1,70 @@ |
638 |
+#include <cstdint> |
639 |
+ |
640 |
+#pragma once |
641 |
+ |
642 |
+// Based on SDL2 |
643 |
+ |
644 |
+#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__ |
645 |
+ |
646 |
+static inline uint16_t ORCT_Swapu16(uint16_t x) |
647 |
+{ |
648 |
+ return static_cast<uint16_t>((x << 8) | (x >> 8)); |
649 |
+} |
650 |
+ |
651 |
+static inline uint32_t ORCT_Swapu32(uint32_t x) |
652 |
+{ |
653 |
+ return static_cast<uint32_t>(((x << 24) | ((x << 8) & 0x00FF0000) | ((x >> 8) & 0x0000FF00) | (x >> 24))); |
654 |
+} |
655 |
+ |
656 |
+static inline uint64_t ORCT_Swapu64(uint64_t x) |
657 |
+{ |
658 |
+ uint32_t hi, lo; |
659 |
+ |
660 |
+ /* Separate into high and low 32-bit values and swap them */ |
661 |
+ lo = static_cast<uint32_t>(x & 0xFFFFFFFF); |
662 |
+ x >>= 32; |
663 |
+ hi = static_cast<uint32_t>(x & 0xFFFFFFFF); |
664 |
+ x = ORCT_Swapu32(lo); |
665 |
+ x <<= 32; |
666 |
+ x |= ORCT_Swapu32(hi); |
667 |
+ return (x); |
668 |
+} |
669 |
+ |
670 |
+static inline int16_t ORCT_Swapi16(int16_t x) |
671 |
+{ |
672 |
+ return static_cast<uint16_t>((x << 8) | (x >> 8)); |
673 |
+} |
674 |
+ |
675 |
+static inline int32_t ORCT_Swapi32(int32_t x) |
676 |
+{ |
677 |
+ return static_cast<uint32_t>(((x << 24) | ((x << 8) & 0x00FF0000) | ((x >> 8) & 0x0000FF00) | (x >> 24))); |
678 |
+} |
679 |
+ |
680 |
+static inline int64_t ORCT_Swapi64(int64_t x) |
681 |
+{ |
682 |
+ uint32_t hi, lo; |
683 |
+ |
684 |
+ /* Separate into high and low 32-bit values and swap them */ |
685 |
+ lo = static_cast<uint32_t>(x & 0xFFFFFFFF); |
686 |
+ x >>= 32; |
687 |
+ hi = static_cast<uint32_t>(x & 0xFFFFFFFF); |
688 |
+ x = ORCT_Swapu32(lo); |
689 |
+ x <<= 32; |
690 |
+ x |= ORCT_Swapu32(hi); |
691 |
+ return (x); |
692 |
+} |
693 |
+ |
694 |
+# define ORCT_SwapLEi16(X) ORCT_Swapi16(X) |
695 |
+# define ORCT_SwapLEi32(X) ORCT_Swapi32(X) |
696 |
+# define ORCT_SwapLEi64(X) ORCT_Swapi64(X) |
697 |
+# define ORCT_SwapLEu16(X) ORCT_Swapu16(X) |
698 |
+# define ORCT_SwapLEu32(X) ORCT_Swapu32(X) |
699 |
+# define ORCT_SwapLEu64(X) ORCT_Swapu64(X) |
700 |
+#else |
701 |
+# define ORCT_SwapLEi16(X) (X) |
702 |
+# define ORCT_SwapLEi32(X) (X) |
703 |
+# define ORCT_SwapLEi64(X) (X) |
704 |
+# define ORCT_SwapLEu16(X) (X) |
705 |
+# define ORCT_SwapLEu32(X) (X) |
706 |
+# define ORCT_SwapLEu64(X) (X) |
707 |
+#endif |