forked from rosebudai/OpenRCT2-Web
Move IStream, MemoryStream, FileStream into OpenRCT2 namespace
This commit is contained in:
1 parent
30376085cf
commit
83355e35cc
74 files changed
+828
-758
No files matched your search
@@ -280,7 +280,7 @@ private:
|
||||
TitleSequenceParkHandle* parkHandle = TitleSequenceGetParkHandle(_sequence, saveIndex);
|
||||
if (parkHandle != nullptr)
|
||||
{
|
||||
loadSuccess = LoadParkFromStream(static_cast<IStream*>(parkHandle->Stream), parkHandle->HintPath);
|
||||
loadSuccess = LoadParkFromStream(static_cast<OpenRCT2::IStream*>(parkHandle->Stream), parkHandle->HintPath);
|
||||
TitleSequenceCloseParkHandle(parkHandle);
|
||||
}
|
||||
if (!loadSuccess)
|
||||
@@ -389,7 +389,7 @@ private:
|
||||
* @param stream The stream to read the park data from.
|
||||
* @param hintPath Hint path, the extension is grabbed to determine what importer to use.
|
||||
*/
|
||||
bool LoadParkFromStream(IStream* stream, const std::string& hintPath)
|
||||
bool LoadParkFromStream(OpenRCT2::IStream* stream, const std::string& hintPath)
|
||||
{
|
||||
log_verbose("TitleSequencePlayer::LoadParkFromStream(%s)", hintPath.c_str());
|
||||
bool success = false;
|
||||
|
||||
@@ -359,7 +359,7 @@ static void window_title_editor_mouseup(rct_window* w, rct_widgetindex widgetInd
|
||||
if (w->selected_list_item >= 0 && w->selected_list_item < static_cast<int16_t>(_editingTitleSequence->NumSaves))
|
||||
{
|
||||
auto handle = TitleSequenceGetParkHandle(_editingTitleSequence, w->selected_list_item);
|
||||
auto stream = static_cast<IStream*>(handle->Stream);
|
||||
auto stream = static_cast<OpenRCT2::IStream*>(handle->Stream);
|
||||
auto hintPath = String::ToStd(handle->HintPath);
|
||||
bool isScenario = ParkImporter::ExtensionIsScenario(hintPath);
|
||||
try
|
||||
|
||||
@@ -98,7 +98,7 @@ void CheatsSerialise(DataSerialiser& ds)
|
||||
|
||||
if (ds.IsSaving())
|
||||
{
|
||||
IStream& stream = ds.GetStream();
|
||||
OpenRCT2::IStream& stream = ds.GetStream();
|
||||
|
||||
// Temporarily write 0, will be updated after every cheat is written.
|
||||
uint64_t countOffset = stream.GetPosition();
|
||||
|
||||
@@ -18,7 +18,10 @@
|
||||
INTERFACE IObjectManager;
|
||||
INTERFACE IObjectRepository;
|
||||
INTERFACE IScenarioRepository;
|
||||
INTERFACE IStream;
|
||||
namespace OpenRCT2
|
||||
{
|
||||
INTERFACE IStream;
|
||||
}
|
||||
INTERFACE ITrackDesignRepository;
|
||||
INTERFACE IGameStateSnapshots;
|
||||
|
||||
|
||||
@@ -16,15 +16,15 @@
|
||||
#include "scenario/Scenario.h"
|
||||
#include "util/SawyerCoding.h"
|
||||
|
||||
static bool TryClassifyAsS6(IStream* stream, ClassifiedFileInfo* result);
|
||||
static bool TryClassifyAsS4(IStream* stream, ClassifiedFileInfo* result);
|
||||
static bool TryClassifyAsTD4_TD6(IStream* stream, ClassifiedFileInfo* result);
|
||||
static bool TryClassifyAsS6(OpenRCT2::IStream* stream, ClassifiedFileInfo* result);
|
||||
static bool TryClassifyAsS4(OpenRCT2::IStream* stream, ClassifiedFileInfo* result);
|
||||
static bool TryClassifyAsTD4_TD6(OpenRCT2::IStream* stream, ClassifiedFileInfo* result);
|
||||
|
||||
bool TryClassifyFile(const std::string& path, ClassifiedFileInfo* result)
|
||||
{
|
||||
try
|
||||
{
|
||||
auto fs = FileStream(path, FILE_MODE_OPEN);
|
||||
auto fs = OpenRCT2::FileStream(path, OpenRCT2::FILE_MODE_OPEN);
|
||||
return TryClassifyFile(&fs, result);
|
||||
}
|
||||
catch (const std::exception&)
|
||||
@@ -33,7 +33,7 @@ bool TryClassifyFile(const std::string& path, ClassifiedFileInfo* result)
|
||||
}
|
||||
}
|
||||
|
||||
bool TryClassifyFile(IStream* stream, ClassifiedFileInfo* result)
|
||||
bool TryClassifyFile(OpenRCT2::IStream* stream, ClassifiedFileInfo* result)
|
||||
{
|
||||
// TODO Currently track designs get classified as SC4s because they use the
|
||||
// same checksum algorithm. The only way after to tell the difference
|
||||
@@ -61,7 +61,7 @@ bool TryClassifyFile(IStream* stream, ClassifiedFileInfo* result)
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool TryClassifyAsS6(IStream* stream, ClassifiedFileInfo* result)
|
||||
static bool TryClassifyAsS6(OpenRCT2::IStream* stream, ClassifiedFileInfo* result)
|
||||
{
|
||||
bool success = false;
|
||||
uint64_t originalPosition = stream->GetPosition();
|
||||
@@ -89,7 +89,7 @@ static bool TryClassifyAsS6(IStream* stream, ClassifiedFileInfo* result)
|
||||
return success;
|
||||
}
|
||||
|
||||
static bool TryClassifyAsS4(IStream* stream, ClassifiedFileInfo* result)
|
||||
static bool TryClassifyAsS4(OpenRCT2::IStream* stream, ClassifiedFileInfo* result)
|
||||
{
|
||||
bool success = false;
|
||||
uint64_t originalPosition = stream->GetPosition();
|
||||
@@ -126,7 +126,7 @@ static bool TryClassifyAsS4(IStream* stream, ClassifiedFileInfo* result)
|
||||
return success;
|
||||
}
|
||||
|
||||
static bool TryClassifyAsTD4_TD6(IStream* stream, ClassifiedFileInfo* result)
|
||||
static bool TryClassifyAsTD4_TD6(OpenRCT2::IStream* stream, ClassifiedFileInfo* result)
|
||||
{
|
||||
bool success = false;
|
||||
uint64_t originalPosition = stream->GetPosition();
|
||||
|
||||
@@ -25,7 +25,10 @@ enum
|
||||
|
||||
#include <string>
|
||||
|
||||
INTERFACE IStream;
|
||||
namespace OpenRCT2
|
||||
{
|
||||
INTERFACE IStream;
|
||||
}
|
||||
|
||||
enum class FILE_TYPE
|
||||
{
|
||||
@@ -44,6 +47,6 @@ struct ClassifiedFileInfo
|
||||
|
||||
#define FILE_TYPE_S4_CUTOFF 2
|
||||
bool TryClassifyFile(const std::string& path, ClassifiedFileInfo* result);
|
||||
bool TryClassifyFile(IStream* stream, ClassifiedFileInfo* result);
|
||||
bool TryClassifyFile(OpenRCT2::IStream* stream, ClassifiedFileInfo* result);
|
||||
|
||||
uint32_t get_file_extension_type(const utf8* path);
|
||||
@@ -28,8 +28,8 @@ struct GameStateSnapshot_t
|
||||
uint32_t tick = InvalidTick;
|
||||
uint32_t srand0 = 0;
|
||||
|
||||
MemoryStream storedSprites;
|
||||
MemoryStream parkParameters;
|
||||
OpenRCT2::MemoryStream storedSprites;
|
||||
OpenRCT2::MemoryStream parkParameters;
|
||||
|
||||
// Must pass a function that can access the sprite.
|
||||
void SerialiseSprites(std::function<rct_sprite*(const size_t)> getEntity, const size_t numSprites, bool saving)
|
||||
|
||||
@@ -19,7 +19,10 @@
|
||||
|
||||
INTERFACE IObjectManager;
|
||||
INTERFACE IObjectRepository;
|
||||
INTERFACE IStream;
|
||||
namespace OpenRCT2
|
||||
{
|
||||
INTERFACE IStream;
|
||||
}
|
||||
struct scenario_index_entry;
|
||||
|
||||
struct ParkLoadResult final
|
||||
@@ -45,7 +48,7 @@ public:
|
||||
virtual ParkLoadResult LoadSavedGame(const utf8* path, bool skipObjectCheck = false) abstract;
|
||||
virtual ParkLoadResult LoadScenario(const utf8* path, bool skipObjectCheck = false) abstract;
|
||||
virtual ParkLoadResult LoadFromStream(
|
||||
IStream * stream, bool isScenario, bool skipObjectCheck = false, const utf8* path = String::Empty) abstract;
|
||||
OpenRCT2::IStream * stream, bool isScenario, bool skipObjectCheck = false, const utf8* path = String::Empty) abstract;
|
||||
|
||||
virtual void Import() abstract;
|
||||
virtual bool GetDetails(scenario_index_entry * dst) abstract;
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace OpenRCT2
|
||||
uint32_t magic;
|
||||
uint16_t version;
|
||||
uint64_t uncompressedSize;
|
||||
MemoryStream data;
|
||||
OpenRCT2::MemoryStream data;
|
||||
};
|
||||
|
||||
struct ReplayRecordData
|
||||
@@ -80,9 +80,9 @@ namespace OpenRCT2
|
||||
uint32_t magic;
|
||||
uint16_t version;
|
||||
std::string networkId;
|
||||
MemoryStream parkData;
|
||||
MemoryStream parkParams;
|
||||
MemoryStream cheatData;
|
||||
OpenRCT2::MemoryStream parkData;
|
||||
OpenRCT2::MemoryStream parkParams;
|
||||
OpenRCT2::MemoryStream cheatData;
|
||||
std::string name; // Name of play
|
||||
std::string filePath; // File path of replay.
|
||||
uint64_t timeRecorded; // Posix Time.
|
||||
@@ -91,7 +91,7 @@ namespace OpenRCT2
|
||||
std::multiset<ReplayCommand> commands;
|
||||
std::vector<std::pair<uint32_t, rct_sprite_checksum>> checksums;
|
||||
uint32_t checksumIndex;
|
||||
MemoryStream gameStateSnapshots;
|
||||
OpenRCT2::MemoryStream gameStateSnapshots;
|
||||
};
|
||||
|
||||
class ReplayManager final : public IReplayManager
|
||||
|
||||
@@ -26,7 +26,7 @@ public:
|
||||
virtual ~ITrackImporter() = default;
|
||||
|
||||
virtual bool Load(const utf8* path) abstract;
|
||||
virtual bool LoadFromStream(IStream * stream) abstract;
|
||||
virtual bool LoadFromStream(OpenRCT2::IStream * stream) abstract;
|
||||
|
||||
virtual std::unique_ptr<TrackDesign> Import() abstract;
|
||||
};
|
||||
|
||||
@@ -341,7 +341,7 @@ void audio_init_ride_sounds_and_info()
|
||||
{
|
||||
try
|
||||
{
|
||||
auto fs = FileStream(path, FILE_MODE_OPEN);
|
||||
auto fs = OpenRCT2::FileStream(path, OpenRCT2::FILE_MODE_OPEN);
|
||||
uint32_t head = fs.ReadValue<uint32_t>();
|
||||
if (head == 0x78787878)
|
||||
{
|
||||
|
||||
@@ -96,7 +96,7 @@ private:
|
||||
std::unordered_map<std::string, std::string, StringIHash, StringICmp> _values;
|
||||
|
||||
public:
|
||||
explicit IniReader(IStream* stream)
|
||||
explicit IniReader(OpenRCT2::IStream* stream)
|
||||
{
|
||||
uint64_t length = stream->GetLength() - stream->GetPosition();
|
||||
_buffer.resize(length);
|
||||
@@ -437,7 +437,7 @@ utf8* IIniReader::GetCString(const std::string& name, const utf8* defaultValue)
|
||||
return String::Duplicate(szValue.c_str());
|
||||
}
|
||||
|
||||
IIniReader* CreateIniReader(IStream* stream)
|
||||
IIniReader* CreateIniReader(OpenRCT2::IStream* stream)
|
||||
{
|
||||
return new IniReader(stream);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,11 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
INTERFACE IStream;
|
||||
namespace OpenRCT2
|
||||
{
|
||||
INTERFACE IStream;
|
||||
}
|
||||
|
||||
template<typename T> struct IConfigEnum;
|
||||
|
||||
INTERFACE IIniReader
|
||||
@@ -43,5 +47,5 @@ INTERFACE IIniReader
|
||||
utf8* GetCString(const std::string& name, const utf8* defaultValue) const;
|
||||
};
|
||||
|
||||
IIniReader* CreateIniReader(IStream* stream);
|
||||
IIniReader* CreateIniReader(OpenRCT2::IStream* stream);
|
||||
IIniReader* CreateDefaultIniReader();
|
||||
@@ -18,11 +18,11 @@
|
||||
class IniWriter final : public IIniWriter
|
||||
{
|
||||
private:
|
||||
IStream* _stream;
|
||||
OpenRCT2::IStream* _stream;
|
||||
bool _firstSection = true;
|
||||
|
||||
public:
|
||||
explicit IniWriter(IStream* stream)
|
||||
explicit IniWriter(OpenRCT2::IStream* stream)
|
||||
: _stream(stream)
|
||||
{
|
||||
}
|
||||
@@ -103,7 +103,7 @@ void IIniWriter::WriteString(const std::string& name, const utf8* value)
|
||||
WriteString(name, String::ToStd(value));
|
||||
}
|
||||
|
||||
IIniWriter* CreateIniWriter(IStream* stream)
|
||||
IIniWriter* CreateIniWriter(OpenRCT2::IStream* stream)
|
||||
{
|
||||
return new IniWriter(stream);
|
||||
}
|
||||
@@ -13,7 +13,11 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
INTERFACE IStream;
|
||||
namespace OpenRCT2
|
||||
{
|
||||
INTERFACE IStream;
|
||||
}
|
||||
|
||||
template<typename T> struct IConfigEnum;
|
||||
|
||||
INTERFACE IIniWriter
|
||||
@@ -45,4 +49,4 @@ INTERFACE IIniWriter
|
||||
void WriteString(const std::string& name, const utf8* value);
|
||||
};
|
||||
|
||||
IIniWriter* CreateIniWriter(IStream* stream);
|
||||
IIniWriter* CreateIniWriter(OpenRCT2::IStream* stream);
|
||||
@@ -10,14 +10,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "DataSerialiserTraits.h"
|
||||
#include "MemoryStream.h"
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
class DataSerialiser
|
||||
{
|
||||
private:
|
||||
MemoryStream _stream;
|
||||
IStream& _activeStream;
|
||||
OpenRCT2::MemoryStream _stream;
|
||||
OpenRCT2::IStream& _activeStream;
|
||||
bool _isSaving = false;
|
||||
bool _isLogging = false;
|
||||
|
||||
@@ -29,7 +30,7 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
DataSerialiser(bool isSaving, IStream& stream, bool isLogging = false)
|
||||
DataSerialiser(bool isSaving, OpenRCT2::IStream& stream, bool isLogging = false)
|
||||
: _activeStream(stream)
|
||||
, _isSaving(isSaving)
|
||||
, _isLogging(isLogging)
|
||||
@@ -51,7 +52,7 @@ public:
|
||||
return _isLogging;
|
||||
}
|
||||
|
||||
IStream& GetStream()
|
||||
OpenRCT2::IStream& GetStream()
|
||||
{
|
||||
return _activeStream;
|
||||
}
|
||||
|
||||
@@ -30,25 +30,25 @@
|
||||
|
||||
template<typename T> struct DataSerializerTraits
|
||||
{
|
||||
static void encode(IStream* stream, const T& v) = delete;
|
||||
static void decode(IStream* stream, T& val) = delete;
|
||||
static void log(IStream* stream, const T& val) = delete;
|
||||
static void encode(OpenRCT2::IStream* stream, const T& v) = delete;
|
||||
static void decode(OpenRCT2::IStream* stream, T& val) = delete;
|
||||
static void log(OpenRCT2::IStream* stream, const T& val) = delete;
|
||||
};
|
||||
|
||||
template<typename T> struct DataSerializerTraitsIntegral
|
||||
{
|
||||
static void encode(IStream* stream, const T& val)
|
||||
static void encode(OpenRCT2::IStream* stream, const T& val)
|
||||
{
|
||||
T temp = ByteSwapBE(val);
|
||||
stream->Write(&temp);
|
||||
}
|
||||
static void decode(IStream* stream, T& val)
|
||||
static void decode(OpenRCT2::IStream* stream, T& val)
|
||||
{
|
||||
T temp;
|
||||
stream->Read(&temp);
|
||||
val = ByteSwapBE(temp);
|
||||
}
|
||||
static void log(IStream* stream, const T& val)
|
||||
static void log(OpenRCT2::IStream* stream, const T& val)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << std::hex << std::setw(sizeof(T) * 2) << std::setfill('0') << +val;
|
||||
@@ -60,15 +60,15 @@ template<typename T> struct DataSerializerTraitsIntegral
|
||||
|
||||
template<> struct DataSerializerTraits<bool>
|
||||
{
|
||||
static void encode(IStream* stream, const bool& val)
|
||||
static void encode(OpenRCT2::IStream* stream, const bool& val)
|
||||
{
|
||||
stream->Write(&val);
|
||||
}
|
||||
static void decode(IStream* stream, bool& val)
|
||||
static void decode(OpenRCT2::IStream* stream, bool& val)
|
||||
{
|
||||
stream->Read(&val);
|
||||
}
|
||||
static void log(IStream* stream, const bool& val)
|
||||
static void log(OpenRCT2::IStream* stream, const bool& val)
|
||||
{
|
||||
if (val)
|
||||
stream->Write("true", 4);
|
||||
@@ -111,14 +111,14 @@ template<> struct DataSerializerTraits<int64_t> : public DataSerializerTraitsInt
|
||||
|
||||
template<> struct DataSerializerTraits<std::string>
|
||||
{
|
||||
static void encode(IStream* stream, const std::string& str)
|
||||
static void encode(OpenRCT2::IStream* stream, const std::string& str)
|
||||
{
|
||||
uint16_t len = static_cast<uint16_t>(str.size());
|
||||
uint16_t swapped = ByteSwapBE(len);
|
||||
stream->Write(&swapped);
|
||||
stream->WriteArray(str.c_str(), len);
|
||||
}
|
||||
static void decode(IStream* stream, std::string& res)
|
||||
static void decode(OpenRCT2::IStream* stream, std::string& res)
|
||||
{
|
||||
uint16_t len;
|
||||
stream->Read(&len);
|
||||
@@ -129,7 +129,7 @@ template<> struct DataSerializerTraits<std::string>
|
||||
|
||||
Memory::FreeArray(str, len);
|
||||
}
|
||||
static void log(IStream* stream, const std::string& str)
|
||||
static void log(OpenRCT2::IStream* stream, const std::string& str)
|
||||
{
|
||||
stream->Write("\"", 1);
|
||||
stream->Write(str.data(), str.size());
|
||||
@@ -139,19 +139,19 @@ template<> struct DataSerializerTraits<std::string>
|
||||
|
||||
template<> struct DataSerializerTraits<NetworkPlayerId_t>
|
||||
{
|
||||
static void encode(IStream* stream, const NetworkPlayerId_t& val)
|
||||
static void encode(OpenRCT2::IStream* stream, const NetworkPlayerId_t& val)
|
||||
{
|
||||
uint32_t temp = static_cast<uint32_t>(val.id);
|
||||
temp = ByteSwapBE(temp);
|
||||
stream->Write(&temp);
|
||||
}
|
||||
static void decode(IStream* stream, NetworkPlayerId_t& val)
|
||||
static void decode(OpenRCT2::IStream* stream, NetworkPlayerId_t& val)
|
||||
{
|
||||
uint32_t temp;
|
||||
stream->Read(&temp);
|
||||
val.id = static_cast<decltype(val.id)>(ByteSwapBE(temp));
|
||||
}
|
||||
static void log(IStream* stream, const NetworkPlayerId_t& val)
|
||||
static void log(OpenRCT2::IStream* stream, const NetworkPlayerId_t& val)
|
||||
{
|
||||
char playerId[28] = {};
|
||||
snprintf(playerId, sizeof(playerId), "%u", val.id);
|
||||
@@ -174,19 +174,19 @@ template<> struct DataSerializerTraits<NetworkPlayerId_t>
|
||||
|
||||
template<> struct DataSerializerTraits<NetworkRideId_t>
|
||||
{
|
||||
static void encode(IStream* stream, const NetworkRideId_t& val)
|
||||
static void encode(OpenRCT2::IStream* stream, const NetworkRideId_t& val)
|
||||
{
|
||||
uint32_t temp = static_cast<uint32_t>(val.id);
|
||||
temp = ByteSwapBE(temp);
|
||||
stream->Write(&temp);
|
||||
}
|
||||
static void decode(IStream* stream, NetworkRideId_t& val)
|
||||
static void decode(OpenRCT2::IStream* stream, NetworkRideId_t& val)
|
||||
{
|
||||
uint32_t temp;
|
||||
stream->Read(&temp);
|
||||
val.id = static_cast<decltype(val.id)>(ByteSwapBE(temp));
|
||||
}
|
||||
static void log(IStream* stream, const NetworkRideId_t& val)
|
||||
static void log(OpenRCT2::IStream* stream, const NetworkRideId_t& val)
|
||||
{
|
||||
char rideId[28] = {};
|
||||
snprintf(rideId, sizeof(rideId), "%u", val.id);
|
||||
@@ -207,17 +207,17 @@ template<> struct DataSerializerTraits<NetworkRideId_t>
|
||||
|
||||
template<typename T> struct DataSerializerTraits<DataSerialiserTag<T>>
|
||||
{
|
||||
static void encode(IStream* stream, const DataSerialiserTag<T>& tag)
|
||||
static void encode(OpenRCT2::IStream* stream, const DataSerialiserTag<T>& tag)
|
||||
{
|
||||
DataSerializerTraits<T> s;
|
||||
s.encode(stream, tag.Data());
|
||||
}
|
||||
static void decode(IStream* stream, DataSerialiserTag<T>& tag)
|
||||
static void decode(OpenRCT2::IStream* stream, DataSerialiserTag<T>& tag)
|
||||
{
|
||||
DataSerializerTraits<T> s;
|
||||
s.decode(stream, tag.Data());
|
||||
}
|
||||
static void log(IStream* stream, const DataSerialiserTag<T>& tag)
|
||||
static void log(OpenRCT2::IStream* stream, const DataSerialiserTag<T>& tag)
|
||||
{
|
||||
const char* name = tag.Name();
|
||||
stream->Write(name, strlen(name));
|
||||
@@ -230,16 +230,16 @@ template<typename T> struct DataSerializerTraits<DataSerialiserTag<T>>
|
||||
}
|
||||
};
|
||||
|
||||
template<> struct DataSerializerTraits<MemoryStream>
|
||||
template<> struct DataSerializerTraits<OpenRCT2::MemoryStream>
|
||||
{
|
||||
static void encode(IStream* stream, const MemoryStream& val)
|
||||
static void encode(OpenRCT2::IStream* stream, const OpenRCT2::MemoryStream& val)
|
||||
{
|
||||
DataSerializerTraits<uint32_t> s;
|
||||
s.encode(stream, val.GetLength());
|
||||
|
||||
stream->Write(val.GetData(), val.GetLength());
|
||||
}
|
||||
static void decode(IStream* stream, MemoryStream& val)
|
||||
static void decode(OpenRCT2::IStream* stream, OpenRCT2::MemoryStream& val)
|
||||
{
|
||||
DataSerializerTraits<uint32_t> s;
|
||||
|
||||
@@ -251,14 +251,14 @@ template<> struct DataSerializerTraits<MemoryStream>
|
||||
|
||||
val.Write(buf.get(), length);
|
||||
}
|
||||
static void log(IStream* stream, const MemoryStream& tag)
|
||||
static void log(OpenRCT2::IStream* stream, const OpenRCT2::MemoryStream& tag)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
template<typename _Ty, size_t _Size> struct DataSerializerTraitsPODArray
|
||||
{
|
||||
static void encode(IStream* stream, const _Ty (&val)[_Size])
|
||||
static void encode(OpenRCT2::IStream* stream, const _Ty (&val)[_Size])
|
||||
{
|
||||
uint16_t len = static_cast<uint16_t>(_Size);
|
||||
uint16_t swapped = ByteSwapBE(len);
|
||||
@@ -270,7 +270,7 @@ template<typename _Ty, size_t _Size> struct DataSerializerTraitsPODArray
|
||||
s.encode(stream, sub);
|
||||
}
|
||||
}
|
||||
static void decode(IStream* stream, _Ty (&val)[_Size])
|
||||
static void decode(OpenRCT2::IStream* stream, _Ty (&val)[_Size])
|
||||
{
|
||||
uint16_t len;
|
||||
stream->Read(&len);
|
||||
@@ -285,7 +285,7 @@ template<typename _Ty, size_t _Size> struct DataSerializerTraitsPODArray
|
||||
s.decode(stream, sub);
|
||||
}
|
||||
}
|
||||
static void log(IStream* stream, const _Ty (&val)[_Size])
|
||||
static void log(OpenRCT2::IStream* stream, const _Ty (&val)[_Size])
|
||||
{
|
||||
stream->Write("{", 1);
|
||||
DataSerializerTraits<_Ty> s;
|
||||
@@ -316,7 +316,7 @@ template<size_t _Size> struct DataSerializerTraits<uint64_t[_Size]> : public Dat
|
||||
|
||||
template<typename _Ty, size_t _Size> struct DataSerializerTraits<std::array<_Ty, _Size>>
|
||||
{
|
||||
static void encode(IStream* stream, const std::array<_Ty, _Size>& val)
|
||||
static void encode(OpenRCT2::IStream* stream, const std::array<_Ty, _Size>& val)
|
||||
{
|
||||
uint16_t len = static_cast<uint16_t>(_Size);
|
||||
uint16_t swapped = ByteSwapBE(len);
|
||||
@@ -328,7 +328,7 @@ template<typename _Ty, size_t _Size> struct DataSerializerTraits<std::array<_Ty,
|
||||
s.encode(stream, sub);
|
||||
}
|
||||
}
|
||||
static void decode(IStream* stream, std::array<_Ty, _Size>& val)
|
||||
static void decode(OpenRCT2::IStream* stream, std::array<_Ty, _Size>& val)
|
||||
{
|
||||
uint16_t len;
|
||||
stream->Read(&len);
|
||||
@@ -343,7 +343,7 @@ template<typename _Ty, size_t _Size> struct DataSerializerTraits<std::array<_Ty,
|
||||
s.decode(stream, sub);
|
||||
}
|
||||
}
|
||||
static void log(IStream* stream, const std::array<_Ty, _Size>& val)
|
||||
static void log(OpenRCT2::IStream* stream, const std::array<_Ty, _Size>& val)
|
||||
{
|
||||
stream->Write("{", 1);
|
||||
DataSerializerTraits<_Ty> s;
|
||||
@@ -358,7 +358,7 @@ template<typename _Ty, size_t _Size> struct DataSerializerTraits<std::array<_Ty,
|
||||
|
||||
template<typename _Ty> struct DataSerializerTraits<std::vector<_Ty>>
|
||||
{
|
||||
static void encode(IStream* stream, const std::vector<_Ty>& val)
|
||||
static void encode(OpenRCT2::IStream* stream, const std::vector<_Ty>& val)
|
||||
{
|
||||
uint16_t len = static_cast<uint16_t>(val.size());
|
||||
uint16_t swapped = ByteSwapBE(len);
|
||||
@@ -370,7 +370,7 @@ template<typename _Ty> struct DataSerializerTraits<std::vector<_Ty>>
|
||||
s.encode(stream, sub);
|
||||
}
|
||||
}
|
||||
static void decode(IStream* stream, std::vector<_Ty>& val)
|
||||
static void decode(OpenRCT2::IStream* stream, std::vector<_Ty>& val)
|
||||
{
|
||||
uint16_t len;
|
||||
stream->Read(&len);
|
||||
@@ -384,7 +384,7 @@ template<typename _Ty> struct DataSerializerTraits<std::vector<_Ty>>
|
||||
val.push_back(sub);
|
||||
}
|
||||
}
|
||||
static void log(IStream* stream, const std::vector<_Ty>& val)
|
||||
static void log(OpenRCT2::IStream* stream, const std::vector<_Ty>& val)
|
||||
{
|
||||
stream->Write("{", 1);
|
||||
DataSerializerTraits<_Ty> s;
|
||||
@@ -399,14 +399,14 @@ template<typename _Ty> struct DataSerializerTraits<std::vector<_Ty>>
|
||||
|
||||
template<> struct DataSerializerTraits<MapRange>
|
||||
{
|
||||
static void encode(IStream* stream, const MapRange& v)
|
||||
static void encode(OpenRCT2::IStream* stream, const MapRange& v)
|
||||
{
|
||||
stream->WriteValue(ByteSwapBE(v.GetLeft()));
|
||||
stream->WriteValue(ByteSwapBE(v.GetTop()));
|
||||
stream->WriteValue(ByteSwapBE(v.GetRight()));
|
||||
stream->WriteValue(ByteSwapBE(v.GetBottom()));
|
||||
}
|
||||
static void decode(IStream* stream, MapRange& v)
|
||||
static void decode(OpenRCT2::IStream* stream, MapRange& v)
|
||||
{
|
||||
auto l = ByteSwapBE(stream->ReadValue<int32_t>());
|
||||
auto t = ByteSwapBE(stream->ReadValue<int32_t>());
|
||||
@@ -414,7 +414,7 @@ template<> struct DataSerializerTraits<MapRange>
|
||||
auto b = ByteSwapBE(stream->ReadValue<int32_t>());
|
||||
v = MapRange(l, t, r, b);
|
||||
}
|
||||
static void log(IStream* stream, const MapRange& v)
|
||||
static void log(OpenRCT2::IStream* stream, const MapRange& v)
|
||||
{
|
||||
char coords[128] = {};
|
||||
snprintf(
|
||||
@@ -427,7 +427,7 @@ template<> struct DataSerializerTraits<MapRange>
|
||||
|
||||
template<> struct DataSerializerTraits<TileElement>
|
||||
{
|
||||
static void encode(IStream* stream, const TileElement& tileElement)
|
||||
static void encode(OpenRCT2::IStream* stream, const TileElement& tileElement)
|
||||
{
|
||||
stream->WriteValue(tileElement.type);
|
||||
stream->WriteValue(tileElement.Flags);
|
||||
@@ -442,7 +442,7 @@ template<> struct DataSerializerTraits<TileElement>
|
||||
stream->WriteValue(tileElement.pad_08[i]);
|
||||
}
|
||||
}
|
||||
static void decode(IStream* stream, TileElement& tileElement)
|
||||
static void decode(OpenRCT2::IStream* stream, TileElement& tileElement)
|
||||
{
|
||||
tileElement.type = stream->ReadValue<uint8_t>();
|
||||
tileElement.Flags = stream->ReadValue<uint8_t>();
|
||||
@@ -457,7 +457,7 @@ template<> struct DataSerializerTraits<TileElement>
|
||||
tileElement.pad_08[i] = stream->ReadValue<uint8_t>();
|
||||
}
|
||||
}
|
||||
static void log(IStream* stream, const TileElement& tileElement)
|
||||
static void log(OpenRCT2::IStream* stream, const TileElement& tileElement)
|
||||
{
|
||||
char msg[128] = {};
|
||||
snprintf(
|
||||
@@ -469,18 +469,18 @@ template<> struct DataSerializerTraits<TileElement>
|
||||
|
||||
template<> struct DataSerializerTraits<CoordsXY>
|
||||
{
|
||||
static void encode(IStream* stream, const CoordsXY& coords)
|
||||
static void encode(OpenRCT2::IStream* stream, const CoordsXY& coords)
|
||||
{
|
||||
stream->WriteValue(ByteSwapBE(coords.x));
|
||||
stream->WriteValue(ByteSwapBE(coords.y));
|
||||
}
|
||||
static void decode(IStream* stream, CoordsXY& coords)
|
||||
static void decode(OpenRCT2::IStream* stream, CoordsXY& coords)
|
||||
{
|
||||
auto x = ByteSwapBE(stream->ReadValue<int32_t>());
|
||||
auto y = ByteSwapBE(stream->ReadValue<int32_t>());
|
||||
coords = CoordsXY{ x, y };
|
||||
}
|
||||
static void log(IStream* stream, const CoordsXY& coords)
|
||||
static void log(OpenRCT2::IStream* stream, const CoordsXY& coords)
|
||||
{
|
||||
char msg[128] = {};
|
||||
snprintf(msg, sizeof(msg), "CoordsXY(x = %d, y = %d)", coords.x, coords.y);
|
||||
@@ -490,14 +490,14 @@ template<> struct DataSerializerTraits<CoordsXY>
|
||||
|
||||
template<> struct DataSerializerTraits<CoordsXYZ>
|
||||
{
|
||||
static void encode(IStream* stream, const CoordsXYZ& coord)
|
||||
static void encode(OpenRCT2::IStream* stream, const CoordsXYZ& coord)
|
||||
{
|
||||
stream->WriteValue(ByteSwapBE(coord.x));
|
||||
stream->WriteValue(ByteSwapBE(coord.y));
|
||||
stream->WriteValue(ByteSwapBE(coord.z));
|
||||
}
|
||||
|
||||
static void decode(IStream* stream, CoordsXYZ& coord)
|
||||
static void decode(OpenRCT2::IStream* stream, CoordsXYZ& coord)
|
||||
{
|
||||
auto x = ByteSwapBE(stream->ReadValue<int32_t>());
|
||||
auto y = ByteSwapBE(stream->ReadValue<int32_t>());
|
||||
@@ -505,7 +505,7 @@ template<> struct DataSerializerTraits<CoordsXYZ>
|
||||
coord = CoordsXYZ{ x, y, z };
|
||||
}
|
||||
|
||||
static void log(IStream* stream, const CoordsXYZ& coord)
|
||||
static void log(OpenRCT2::IStream* stream, const CoordsXYZ& coord)
|
||||
{
|
||||
char msg[128] = {};
|
||||
snprintf(msg, sizeof(msg), "CoordsXYZ(x = %d, y = %d, z = %d)", coord.x, coord.y, coord.z);
|
||||
@@ -515,7 +515,7 @@ template<> struct DataSerializerTraits<CoordsXYZ>
|
||||
|
||||
template<> struct DataSerializerTraits<CoordsXYZD>
|
||||
{
|
||||
static void encode(IStream* stream, const CoordsXYZD& coord)
|
||||
static void encode(OpenRCT2::IStream* stream, const CoordsXYZD& coord)
|
||||
{
|
||||
stream->WriteValue(ByteSwapBE(coord.x));
|
||||
stream->WriteValue(ByteSwapBE(coord.y));
|
||||
@@ -523,7 +523,7 @@ template<> struct DataSerializerTraits<CoordsXYZD>
|
||||
stream->WriteValue(ByteSwapBE(coord.direction));
|
||||
}
|
||||
|
||||
static void decode(IStream* stream, CoordsXYZD& coord)
|
||||
static void decode(OpenRCT2::IStream* stream, CoordsXYZD& coord)
|
||||
{
|
||||
auto x = ByteSwapBE(stream->ReadValue<int32_t>());
|
||||
auto y = ByteSwapBE(stream->ReadValue<int32_t>());
|
||||
@@ -532,7 +532,7 @@ template<> struct DataSerializerTraits<CoordsXYZD>
|
||||
coord = CoordsXYZD{ x, y, z, d };
|
||||
}
|
||||
|
||||
static void log(IStream* stream, const CoordsXYZD& coord)
|
||||
static void log(OpenRCT2::IStream* stream, const CoordsXYZD& coord)
|
||||
{
|
||||
char msg[128] = {};
|
||||
snprintf(
|
||||
@@ -543,18 +543,18 @@ template<> struct DataSerializerTraits<CoordsXYZD>
|
||||
|
||||
template<> struct DataSerializerTraits<NetworkCheatType_t>
|
||||
{
|
||||
static void encode(IStream* stream, const NetworkCheatType_t& val)
|
||||
static void encode(OpenRCT2::IStream* stream, const NetworkCheatType_t& val)
|
||||
{
|
||||
uint32_t temp = ByteSwapBE(val.id);
|
||||
stream->Write(&temp);
|
||||
}
|
||||
static void decode(IStream* stream, NetworkCheatType_t& val)
|
||||
static void decode(OpenRCT2::IStream* stream, NetworkCheatType_t& val)
|
||||
{
|
||||
uint32_t temp;
|
||||
stream->Read(&temp);
|
||||
val.id = ByteSwapBE(temp);
|
||||
}
|
||||
static void log(IStream* stream, const NetworkCheatType_t& val)
|
||||
static void log(OpenRCT2::IStream* stream, const NetworkCheatType_t& val)
|
||||
{
|
||||
const char* cheatName = CheatsGetName(static_cast<CheatType>(val.id));
|
||||
stream->Write(cheatName, strlen(cheatName));
|
||||
@@ -563,13 +563,13 @@ template<> struct DataSerializerTraits<NetworkCheatType_t>
|
||||
|
||||
template<> struct DataSerializerTraits<rct_object_entry>
|
||||
{
|
||||
static void encode(IStream* stream, const rct_object_entry& val)
|
||||
static void encode(OpenRCT2::IStream* stream, const rct_object_entry& val)
|
||||
{
|
||||
uint32_t temp = ByteSwapBE(val.flags);
|
||||
stream->Write(&temp);
|
||||
stream->WriteArray(val.nameWOC, 12);
|
||||
}
|
||||
static void decode(IStream* stream, rct_object_entry& val)
|
||||
static void decode(OpenRCT2::IStream* stream, rct_object_entry& val)
|
||||
{
|
||||
uint32_t temp;
|
||||
stream->Read(&temp);
|
||||
@@ -577,7 +577,7 @@ template<> struct DataSerializerTraits<rct_object_entry>
|
||||
const char* str = stream->ReadArray<char>(12);
|
||||
memcpy(val.nameWOC, str, 12);
|
||||
}
|
||||
static void log(IStream* stream, const rct_object_entry& val)
|
||||
static void log(OpenRCT2::IStream* stream, const rct_object_entry& val)
|
||||
{
|
||||
stream->WriteArray(val.name, 8);
|
||||
}
|
||||
@@ -585,17 +585,17 @@ template<> struct DataSerializerTraits<rct_object_entry>
|
||||
|
||||
template<> struct DataSerializerTraits<TrackDesignTrackElement>
|
||||
{
|
||||
static void encode(IStream* stream, const TrackDesignTrackElement& val)
|
||||
static void encode(OpenRCT2::IStream* stream, const TrackDesignTrackElement& val)
|
||||
{
|
||||
stream->Write(&val.flags);
|
||||
stream->Write(&val.type);
|
||||
}
|
||||
static void decode(IStream* stream, TrackDesignTrackElement& val)
|
||||
static void decode(OpenRCT2::IStream* stream, TrackDesignTrackElement& val)
|
||||
{
|
||||
stream->Read(&val.flags);
|
||||
stream->Read(&val.type);
|
||||
}
|
||||
static void log(IStream* stream, const TrackDesignTrackElement& val)
|
||||
static void log(OpenRCT2::IStream* stream, const TrackDesignTrackElement& val)
|
||||
{
|
||||
char msg[128] = {};
|
||||
snprintf(msg, sizeof(msg), "TrackDesignTrackElement(type = %d, flags = %d)", val.type, val.flags);
|
||||
@@ -605,18 +605,18 @@ template<> struct DataSerializerTraits<TrackDesignTrackElement>
|
||||
|
||||
template<> struct DataSerializerTraits<TrackDesignMazeElement>
|
||||
{
|
||||
static void encode(IStream* stream, const TrackDesignMazeElement& val)
|
||||
static void encode(OpenRCT2::IStream* stream, const TrackDesignMazeElement& val)
|
||||
{
|
||||
uint32_t temp = ByteSwapBE(val.all);
|
||||
stream->Write(&temp);
|
||||
}
|
||||
static void decode(IStream* stream, TrackDesignMazeElement& val)
|
||||
static void decode(OpenRCT2::IStream* stream, TrackDesignMazeElement& val)
|
||||
{
|
||||
uint32_t temp;
|
||||
stream->Read(&temp);
|
||||
val.all = ByteSwapBE(temp);
|
||||
}
|
||||
static void log(IStream* stream, const TrackDesignMazeElement& val)
|
||||
static void log(OpenRCT2::IStream* stream, const TrackDesignMazeElement& val)
|
||||
{
|
||||
char msg[128] = {};
|
||||
snprintf(msg, sizeof(msg), "TrackDesignMazeElement(all = %d)", val.all);
|
||||
@@ -626,7 +626,7 @@ template<> struct DataSerializerTraits<TrackDesignMazeElement>
|
||||
|
||||
template<> struct DataSerializerTraits<TrackDesignEntranceElement>
|
||||
{
|
||||
static void encode(IStream* stream, const TrackDesignEntranceElement& val)
|
||||
static void encode(OpenRCT2::IStream* stream, const TrackDesignEntranceElement& val)
|
||||
{
|
||||
stream->Write(&val.x);
|
||||
stream->Write(&val.y);
|
||||
@@ -634,7 +634,7 @@ template<> struct DataSerializerTraits<TrackDesignEntranceElement>
|
||||
stream->Write(&val.direction);
|
||||
stream->Write(&val.isExit);
|
||||
}
|
||||
static void decode(IStream* stream, TrackDesignEntranceElement& val)
|
||||
static void decode(OpenRCT2::IStream* stream, TrackDesignEntranceElement& val)
|
||||
{
|
||||
stream->Read(&val.x);
|
||||
stream->Read(&val.y);
|
||||
@@ -642,7 +642,7 @@ template<> struct DataSerializerTraits<TrackDesignEntranceElement>
|
||||
stream->Read(&val.direction);
|
||||
stream->Read(&val.isExit);
|
||||
}
|
||||
static void log(IStream* stream, const TrackDesignEntranceElement& val)
|
||||
static void log(OpenRCT2::IStream* stream, const TrackDesignEntranceElement& val)
|
||||
{
|
||||
char msg[128] = {};
|
||||
snprintf(
|
||||
@@ -654,7 +654,7 @@ template<> struct DataSerializerTraits<TrackDesignEntranceElement>
|
||||
|
||||
template<> struct DataSerializerTraits<TrackDesignSceneryElement>
|
||||
{
|
||||
static void encode(IStream* stream, const TrackDesignSceneryElement& val)
|
||||
static void encode(OpenRCT2::IStream* stream, const TrackDesignSceneryElement& val)
|
||||
{
|
||||
stream->Write(&val.x);
|
||||
stream->Write(&val.y);
|
||||
@@ -665,7 +665,7 @@ template<> struct DataSerializerTraits<TrackDesignSceneryElement>
|
||||
DataSerializerTraits<rct_object_entry> s;
|
||||
s.encode(stream, val.scenery_object);
|
||||
}
|
||||
static void decode(IStream* stream, TrackDesignSceneryElement& val)
|
||||
static void decode(OpenRCT2::IStream* stream, TrackDesignSceneryElement& val)
|
||||
{
|
||||
stream->Read(&val.x);
|
||||
stream->Read(&val.y);
|
||||
@@ -676,7 +676,7 @@ template<> struct DataSerializerTraits<TrackDesignSceneryElement>
|
||||
DataSerializerTraits<rct_object_entry> s;
|
||||
s.decode(stream, val.scenery_object);
|
||||
}
|
||||
static void log(IStream* stream, const TrackDesignSceneryElement& val)
|
||||
static void log(OpenRCT2::IStream* stream, const TrackDesignSceneryElement& val)
|
||||
{
|
||||
char msg[128] = {};
|
||||
snprintf(
|
||||
@@ -689,17 +689,17 @@ template<> struct DataSerializerTraits<TrackDesignSceneryElement>
|
||||
|
||||
template<> struct DataSerializerTraits<rct_vehicle_colour>
|
||||
{
|
||||
static void encode(IStream* stream, const rct_vehicle_colour& val)
|
||||
static void encode(OpenRCT2::IStream* stream, const rct_vehicle_colour& val)
|
||||
{
|
||||
stream->Write(&val.body_colour);
|
||||
stream->Write(&val.trim_colour);
|
||||
}
|
||||
static void decode(IStream* stream, rct_vehicle_colour& val)
|
||||
static void decode(OpenRCT2::IStream* stream, rct_vehicle_colour& val)
|
||||
{
|
||||
stream->Read(&val.body_colour);
|
||||
stream->Read(&val.trim_colour);
|
||||
}
|
||||
static void log(IStream* stream, const rct_vehicle_colour& val)
|
||||
static void log(OpenRCT2::IStream* stream, const rct_vehicle_colour& val)
|
||||
{
|
||||
char msg[128] = {};
|
||||
snprintf(msg, sizeof(msg), "rct_vehicle_colour(body_colour = %d, trim_colour = %d)", val.body_colour, val.trim_colour);
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace File
|
||||
|
||||
void WriteAllBytes(const std::string& path, const void* buffer, size_t length)
|
||||
{
|
||||
auto fs = FileStream(path, FILE_MODE_WRITE);
|
||||
auto fs = OpenRCT2::FileStream(path, OpenRCT2::FILE_MODE_WRITE);
|
||||
fs.Write(buffer, length);
|
||||
}
|
||||
|
||||
|
||||
@@ -132,12 +132,12 @@ protected:
|
||||
/**
|
||||
* Serialises an index item to the given stream.
|
||||
*/
|
||||
virtual void Serialise(IStream* stream, const TItem& item) const abstract;
|
||||
virtual void Serialise(OpenRCT2::IStream* stream, const TItem& item) const abstract;
|
||||
|
||||
/**
|
||||
* Deserialises an index item from the given stream.
|
||||
*/
|
||||
virtual TItem Deserialise(IStream* stream) const abstract;
|
||||
virtual TItem Deserialise(OpenRCT2::IStream* stream) const abstract;
|
||||
|
||||
private:
|
||||
ScanResult Scan() const
|
||||
@@ -261,7 +261,7 @@ private:
|
||||
try
|
||||
{
|
||||
log_verbose("FileIndex:Loading index: '%s'", _indexPath.c_str());
|
||||
auto fs = FileStream(_indexPath, FILE_MODE_OPEN);
|
||||
auto fs = OpenRCT2::FileStream(_indexPath, OpenRCT2::FILE_MODE_OPEN);
|
||||
|
||||
// Read header, check if we need to re-scan
|
||||
auto header = fs.ReadValue<FileIndexHeader>();
|
||||
@@ -300,7 +300,7 @@ private:
|
||||
{
|
||||
log_verbose("FileIndex:Writing index: '%s'", _indexPath.c_str());
|
||||
Path::CreateDirectory(Path::GetDirectory(_indexPath));
|
||||
auto fs = FileStream(_indexPath, FILE_MODE_WRITE);
|
||||
auto fs = OpenRCT2::FileStream(_indexPath, OpenRCT2::FILE_MODE_WRITE);
|
||||
|
||||
// Write header
|
||||
FileIndexHeader header;
|
||||
|
||||
@@ -147,17 +147,17 @@ namespace OpenRCT2
|
||||
Seek(position, STREAM_SEEK_BEGIN);
|
||||
}
|
||||
|
||||
void Seek(int64_t offset, IStream::SeekType origin) override
|
||||
void Seek(int64_t offset, int32_t origin) override
|
||||
{
|
||||
switch (origin)
|
||||
{
|
||||
case IStream::SeekType.STREAM_SEEK_BEGIN:
|
||||
case STREAM_SEEK_BEGIN:
|
||||
fseeko(_file, offset, SEEK_SET);
|
||||
break;
|
||||
case IStream::SeekType.STREAM_SEEK_CURRENT:
|
||||
case STREAM_SEEK_CURRENT:
|
||||
fseeko(_file, offset, SEEK_CUR);
|
||||
break;
|
||||
case IStream::SeekType.STREAM_SEEK_END:
|
||||
case STREAM_SEEK_END:
|
||||
fseeko(_file, offset, SEEK_END);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -14,47 +14,51 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
utf8* IStream::ReadString()
|
||||
namespace OpenRCT2
|
||||
{
|
||||
std::vector<utf8> result;
|
||||
|
||||
uint8_t ch;
|
||||
while ((ch = ReadValue<uint8_t>()) != 0)
|
||||
utf8* IStream::ReadString()
|
||||
{
|
||||
result.push_back(ch);
|
||||
std::vector<utf8> result;
|
||||
|
||||
uint8_t ch;
|
||||
while ((ch = ReadValue<uint8_t>()) != 0)
|
||||
{
|
||||
result.push_back(ch);
|
||||
}
|
||||
result.push_back(0);
|
||||
|
||||
utf8* resultString = Memory::AllocateArray<utf8>(result.size());
|
||||
std::copy(result.begin(), result.end(), resultString);
|
||||
return resultString;
|
||||
}
|
||||
result.push_back(0);
|
||||
|
||||
utf8* resultString = Memory::AllocateArray<utf8>(result.size());
|
||||
std::copy(result.begin(), result.end(), resultString);
|
||||
return resultString;
|
||||
}
|
||||
|
||||
std::string IStream::ReadStdString()
|
||||
{
|
||||
std::string result;
|
||||
uint8_t ch;
|
||||
while ((ch = ReadValue<uint8_t>()) != 0)
|
||||
std::string IStream::ReadStdString()
|
||||
{
|
||||
result.push_back(ch);
|
||||
std::string result;
|
||||
uint8_t ch;
|
||||
while ((ch = ReadValue<uint8_t>()) != 0)
|
||||
{
|
||||
result.push_back(ch);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void IStream::WriteString(const utf8* str)
|
||||
{
|
||||
if (str == nullptr)
|
||||
void IStream::WriteString(const utf8* str)
|
||||
{
|
||||
WriteValue<uint8_t>(0);
|
||||
if (str == nullptr)
|
||||
{
|
||||
WriteValue<uint8_t>(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t numBytes = String::SizeOf(str) + 1;
|
||||
Write(str, numBytes);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t numBytes = String::SizeOf(str) + 1;
|
||||
Write(str, numBytes);
|
||||
}
|
||||
}
|
||||
|
||||
void IStream::WriteString(const std::string& str)
|
||||
{
|
||||
WriteString(str.c_str());
|
||||
}
|
||||
void IStream::WriteString(const std::string& str)
|
||||
{
|
||||
WriteString(str.c_str());
|
||||
}
|
||||
|
||||
} // namespace OpenRCT2
|
||||
+173
-168
@@ -17,193 +17,198 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
enum
|
||||
{
|
||||
STREAM_SEEK_BEGIN,
|
||||
STREAM_SEEK_CURRENT,
|
||||
STREAM_SEEK_END
|
||||
};
|
||||
|
||||
#ifdef __WARN_SUGGEST_FINAL_METHODS__
|
||||
# pragma GCC diagnostic push
|
||||
# pragma GCC diagnostic ignored "-Wsuggest-final-methods"
|
||||
# pragma GCC diagnostic ignored "-Wsuggest-final-types"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Represents a stream that can be read or written to. Implemented by types such as FileStream, NetworkStream or MemoryStream.
|
||||
*/
|
||||
interface IStream
|
||||
namespace OpenRCT2
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Interface methods
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual ~IStream()
|
||||
enum
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool CanRead() const abstract;
|
||||
virtual bool CanWrite() const abstract;
|
||||
|
||||
virtual uint64_t GetLength() const abstract;
|
||||
virtual uint64_t GetPosition() const abstract;
|
||||
virtual void SetPosition(uint64_t position) abstract;
|
||||
virtual void Seek(int64_t offset, int32_t origin) abstract;
|
||||
|
||||
virtual void Read(void* buffer, uint64_t length) abstract;
|
||||
virtual void Write(const void* buffer, uint64_t length) abstract;
|
||||
|
||||
virtual uint64_t TryRead(void* buffer, uint64_t length) abstract;
|
||||
|
||||
virtual const void* GetData() const abstract;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Fast path methods, class can override them to use specialised copies.
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual void Read1(void* buffer)
|
||||
{
|
||||
Read(buffer, 1);
|
||||
}
|
||||
virtual void Read2(void* buffer)
|
||||
{
|
||||
Read(buffer, 2);
|
||||
}
|
||||
virtual void Read4(void* buffer)
|
||||
{
|
||||
Read(buffer, 4);
|
||||
}
|
||||
virtual void Read8(void* buffer)
|
||||
{
|
||||
Read(buffer, 8);
|
||||
}
|
||||
virtual void Read16(void* buffer)
|
||||
{
|
||||
Read(buffer, 16);
|
||||
}
|
||||
|
||||
virtual void Write1(const void* buffer)
|
||||
{
|
||||
Write(buffer, 1);
|
||||
}
|
||||
virtual void Write2(const void* buffer)
|
||||
{
|
||||
Write(buffer, 2);
|
||||
}
|
||||
virtual void Write4(const void* buffer)
|
||||
{
|
||||
Write(buffer, 4);
|
||||
}
|
||||
virtual void Write8(const void* buffer)
|
||||
{
|
||||
Write(buffer, 8);
|
||||
}
|
||||
virtual void Write16(const void* buffer)
|
||||
{
|
||||
Write(buffer, 16);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Helper methods
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Reads the size of the given type from the stream directly into the given address.
|
||||
*/
|
||||
template<typename T> void Read(T * value)
|
||||
{
|
||||
// Selects the best path at compile time
|
||||
if constexpr (sizeof(T) == 1)
|
||||
{
|
||||
Read1(value);
|
||||
}
|
||||
else if constexpr (sizeof(T) == 2)
|
||||
{
|
||||
Read2(value);
|
||||
}
|
||||
else if constexpr (sizeof(T) == 4)
|
||||
{
|
||||
Read4(value);
|
||||
}
|
||||
else if constexpr (sizeof(T) == 8)
|
||||
{
|
||||
Read8(value);
|
||||
}
|
||||
else if constexpr (sizeof(T) == 16)
|
||||
{
|
||||
Read16(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
Read(value, sizeof(T));
|
||||
}
|
||||
}
|
||||
STREAM_SEEK_BEGIN,
|
||||
STREAM_SEEK_CURRENT,
|
||||
STREAM_SEEK_END
|
||||
};
|
||||
|
||||
/**
|
||||
* Writes the size of the given type to the stream directly from the given address.
|
||||
* Represents a stream that can be read or written to. Implemented by types such as FileStream, NetworkStream or
|
||||
* MemoryStream.
|
||||
*/
|
||||
template<typename T> void Write(const T* value)
|
||||
INTERFACE IStream
|
||||
{
|
||||
// Selects the best path at compile time
|
||||
if constexpr (sizeof(T) == 1)
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Interface methods
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual ~IStream()
|
||||
{
|
||||
Write1(value);
|
||||
}
|
||||
else if constexpr (sizeof(T) == 2)
|
||||
{
|
||||
Write2(value);
|
||||
}
|
||||
else if constexpr (sizeof(T) == 4)
|
||||
{
|
||||
Write4(value);
|
||||
}
|
||||
else if constexpr (sizeof(T) == 8)
|
||||
{
|
||||
Write8(value);
|
||||
}
|
||||
else if constexpr (sizeof(T) == 16)
|
||||
{
|
||||
Write16(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
Write(value, sizeof(T));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the given type from the stream. Use this only for small types (e.g. int8_t, int64_t, double)
|
||||
*/
|
||||
template<typename T> T ReadValue()
|
||||
{
|
||||
T buffer;
|
||||
Read(&buffer);
|
||||
return buffer;
|
||||
}
|
||||
virtual bool CanRead() const abstract;
|
||||
virtual bool CanWrite() const abstract;
|
||||
|
||||
/**
|
||||
* Writes the given type to the stream. Use this only for small types (e.g. int8_t, int64_t, double)
|
||||
*/
|
||||
template<typename T> void WriteValue(const T value)
|
||||
{
|
||||
Write(&value);
|
||||
}
|
||||
virtual uint64_t GetLength() const abstract;
|
||||
virtual uint64_t GetPosition() const abstract;
|
||||
virtual void SetPosition(uint64_t position) abstract;
|
||||
virtual void Seek(int64_t offset, int32_t origin) abstract;
|
||||
|
||||
template<typename T> T* ReadArray(size_t count)
|
||||
{
|
||||
T* buffer = Memory::AllocateArray<T>(count);
|
||||
Read(buffer, sizeof(T) * count);
|
||||
return buffer;
|
||||
}
|
||||
virtual void Read(void* buffer, uint64_t length) abstract;
|
||||
virtual void Write(const void* buffer, uint64_t length) abstract;
|
||||
|
||||
template<typename T> void WriteArray(T * buffer, size_t count)
|
||||
{
|
||||
Write(buffer, sizeof(T) * count);
|
||||
}
|
||||
virtual uint64_t TryRead(void* buffer, uint64_t length) abstract;
|
||||
|
||||
utf8* ReadString();
|
||||
std::string ReadStdString();
|
||||
void WriteString(const utf8* str);
|
||||
void WriteString(const std::string& string);
|
||||
};
|
||||
virtual const void* GetData() const abstract;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Fast path methods, class can override them to use specialised copies.
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual void Read1(void* buffer)
|
||||
{
|
||||
Read(buffer, 1);
|
||||
}
|
||||
virtual void Read2(void* buffer)
|
||||
{
|
||||
Read(buffer, 2);
|
||||
}
|
||||
virtual void Read4(void* buffer)
|
||||
{
|
||||
Read(buffer, 4);
|
||||
}
|
||||
virtual void Read8(void* buffer)
|
||||
{
|
||||
Read(buffer, 8);
|
||||
}
|
||||
virtual void Read16(void* buffer)
|
||||
{
|
||||
Read(buffer, 16);
|
||||
}
|
||||
|
||||
virtual void Write1(const void* buffer)
|
||||
{
|
||||
Write(buffer, 1);
|
||||
}
|
||||
virtual void Write2(const void* buffer)
|
||||
{
|
||||
Write(buffer, 2);
|
||||
}
|
||||
virtual void Write4(const void* buffer)
|
||||
{
|
||||
Write(buffer, 4);
|
||||
}
|
||||
virtual void Write8(const void* buffer)
|
||||
{
|
||||
Write(buffer, 8);
|
||||
}
|
||||
virtual void Write16(const void* buffer)
|
||||
{
|
||||
Write(buffer, 16);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Helper methods
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Reads the size of the given type from the stream directly into the given address.
|
||||
*/
|
||||
template<typename T> void Read(T * value)
|
||||
{
|
||||
// Selects the best path at compile time
|
||||
if constexpr (sizeof(T) == 1)
|
||||
{
|
||||
Read1(value);
|
||||
}
|
||||
else if constexpr (sizeof(T) == 2)
|
||||
{
|
||||
Read2(value);
|
||||
}
|
||||
else if constexpr (sizeof(T) == 4)
|
||||
{
|
||||
Read4(value);
|
||||
}
|
||||
else if constexpr (sizeof(T) == 8)
|
||||
{
|
||||
Read8(value);
|
||||
}
|
||||
else if constexpr (sizeof(T) == 16)
|
||||
{
|
||||
Read16(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
Read(value, sizeof(T));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the size of the given type to the stream directly from the given address.
|
||||
*/
|
||||
template<typename T> void Write(const T* value)
|
||||
{
|
||||
// Selects the best path at compile time
|
||||
if constexpr (sizeof(T) == 1)
|
||||
{
|
||||
Write1(value);
|
||||
}
|
||||
else if constexpr (sizeof(T) == 2)
|
||||
{
|
||||
Write2(value);
|
||||
}
|
||||
else if constexpr (sizeof(T) == 4)
|
||||
{
|
||||
Write4(value);
|
||||
}
|
||||
else if constexpr (sizeof(T) == 8)
|
||||
{
|
||||
Write8(value);
|
||||
}
|
||||
else if constexpr (sizeof(T) == 16)
|
||||
{
|
||||
Write16(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
Write(value, sizeof(T));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the given type from the stream. Use this only for small types (e.g. int8_t, int64_t, double)
|
||||
*/
|
||||
template<typename T> T ReadValue()
|
||||
{
|
||||
T buffer;
|
||||
Read(&buffer);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the given type to the stream. Use this only for small types (e.g. int8_t, int64_t, double)
|
||||
*/
|
||||
template<typename T> void WriteValue(const T value)
|
||||
{
|
||||
Write(&value);
|
||||
}
|
||||
|
||||
template<typename T> T* ReadArray(size_t count)
|
||||
{
|
||||
T* buffer = Memory::AllocateArray<T>(count);
|
||||
Read(buffer, sizeof(T) * count);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
template<typename T> void WriteArray(T * buffer, size_t count)
|
||||
{
|
||||
Write(buffer, sizeof(T) * count);
|
||||
}
|
||||
|
||||
utf8* ReadString();
|
||||
std::string ReadStdString();
|
||||
void WriteString(const utf8* str);
|
||||
void WriteString(const std::string& string);
|
||||
};
|
||||
|
||||
} // namespace OpenRCT2
|
||||
|
||||
#ifdef __WARN_SUGGEST_FINAL_METHODS__
|
||||
# pragma GCC diagnostic pop
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Json
|
||||
json_t* ReadFromFile(const utf8* path, size_t maxSize)
|
||||
{
|
||||
json_t* json = nullptr;
|
||||
auto fs = FileStream(path, FILE_MODE_OPEN);
|
||||
auto fs = OpenRCT2::FileStream(path, OpenRCT2::FILE_MODE_OPEN);
|
||||
|
||||
size_t fileLength = static_cast<size_t>(fs.GetLength());
|
||||
if (fileLength > maxSize)
|
||||
@@ -48,7 +48,7 @@ namespace Json
|
||||
const char* jsonOutput = json_dumps(json, flags);
|
||||
|
||||
// Write to file
|
||||
auto fs = FileStream(path, FILE_MODE_WRITE);
|
||||
auto fs = OpenRCT2::FileStream(path, OpenRCT2::FILE_MODE_WRITE);
|
||||
size_t jsonOutputSize = String::SizeOf(jsonOutput);
|
||||
fs.Write(jsonOutput, jsonOutputSize);
|
||||
}
|
||||
|
||||
+222
-218
@@ -14,243 +14,247 @@
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
MemoryStream::MemoryStream(const MemoryStream& copy)
|
||||
namespace OpenRCT2
|
||||
{
|
||||
_access = copy._access;
|
||||
_dataCapacity = copy._dataCapacity;
|
||||
_dataSize = copy._dataSize;
|
||||
|
||||
if (_access & MEMORY_ACCESS::OWNER)
|
||||
MemoryStream::MemoryStream(const MemoryStream& copy)
|
||||
{
|
||||
_data = Memory::Allocate<void>(_dataCapacity);
|
||||
std::memcpy(_data, copy._data, _dataCapacity);
|
||||
_position = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(_data) + copy.GetPosition());
|
||||
}
|
||||
}
|
||||
_access = copy._access;
|
||||
_dataCapacity = copy._dataCapacity;
|
||||
_dataSize = copy._dataSize;
|
||||
|
||||
MemoryStream::MemoryStream(size_t capacity)
|
||||
{
|
||||
_dataCapacity = capacity;
|
||||
_data = Memory::Allocate<void>(capacity);
|
||||
_position = _data;
|
||||
}
|
||||
|
||||
MemoryStream::MemoryStream(void* data, size_t dataSize, uint8_t access)
|
||||
{
|
||||
_access = access;
|
||||
_dataCapacity = dataSize;
|
||||
_dataSize = dataSize;
|
||||
_data = data;
|
||||
_position = _data;
|
||||
}
|
||||
|
||||
MemoryStream::MemoryStream(const void* data, size_t dataSize)
|
||||
: MemoryStream(const_cast<void*>(data), dataSize, MEMORY_ACCESS::READ)
|
||||
{
|
||||
}
|
||||
|
||||
MemoryStream::MemoryStream(MemoryStream&& mv) noexcept
|
||||
{
|
||||
*this = std::move(mv);
|
||||
}
|
||||
|
||||
MemoryStream::~MemoryStream()
|
||||
{
|
||||
if (_access & MEMORY_ACCESS::OWNER)
|
||||
{
|
||||
Memory::Free(_data);
|
||||
}
|
||||
_dataCapacity = 0;
|
||||
_dataSize = 0;
|
||||
_data = nullptr;
|
||||
}
|
||||
|
||||
MemoryStream& MemoryStream::operator=(MemoryStream&& mv) noexcept
|
||||
{
|
||||
_access = mv._access;
|
||||
_dataCapacity = mv._dataCapacity;
|
||||
_data = mv._data;
|
||||
_position = mv._position;
|
||||
|
||||
mv._data = nullptr;
|
||||
mv._position = nullptr;
|
||||
mv._dataCapacity = 0;
|
||||
mv._dataSize = 0;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
const void* MemoryStream::GetData() const
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
void* MemoryStream::GetDataCopy() const
|
||||
{
|
||||
auto result = Memory::Allocate<void>(_dataSize);
|
||||
std::memcpy(result, _data, _dataSize);
|
||||
return result;
|
||||
}
|
||||
|
||||
void* MemoryStream::TakeData()
|
||||
{
|
||||
_access &= ~MEMORY_ACCESS::OWNER;
|
||||
return _data;
|
||||
}
|
||||
|
||||
bool MemoryStream::CanRead() const
|
||||
{
|
||||
return (_access & MEMORY_ACCESS::READ) != 0;
|
||||
}
|
||||
|
||||
bool MemoryStream::CanWrite() const
|
||||
{
|
||||
return (_access & MEMORY_ACCESS::WRITE) != 0;
|
||||
}
|
||||
|
||||
uint64_t MemoryStream::GetLength() const
|
||||
{
|
||||
return _dataSize;
|
||||
}
|
||||
|
||||
uint64_t MemoryStream::GetPosition() const
|
||||
{
|
||||
return static_cast<uint64_t>(reinterpret_cast<uintptr_t>(_position) - reinterpret_cast<uintptr_t>(_data));
|
||||
}
|
||||
|
||||
void MemoryStream::SetPosition(uint64_t position)
|
||||
{
|
||||
Seek(position, STREAM_SEEK_BEGIN);
|
||||
}
|
||||
|
||||
void MemoryStream::Seek(int64_t offset, int32_t origin)
|
||||
{
|
||||
uint64_t newPosition;
|
||||
switch (origin)
|
||||
{
|
||||
default:
|
||||
case STREAM_SEEK_BEGIN:
|
||||
newPosition = offset;
|
||||
break;
|
||||
case STREAM_SEEK_CURRENT:
|
||||
newPosition = GetPosition() + offset;
|
||||
break;
|
||||
case STREAM_SEEK_END:
|
||||
newPosition = _dataSize + offset;
|
||||
break;
|
||||
if (_access & MEMORY_ACCESS::OWNER)
|
||||
{
|
||||
_data = Memory::Allocate<void>(_dataCapacity);
|
||||
std::memcpy(_data, copy._data, _dataCapacity);
|
||||
_position = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(_data) + copy.GetPosition());
|
||||
}
|
||||
}
|
||||
|
||||
if (newPosition > _dataSize)
|
||||
MemoryStream::MemoryStream(size_t capacity)
|
||||
{
|
||||
throw IOException("New position out of bounds.");
|
||||
}
|
||||
_position = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(_data) + static_cast<uintptr_t>(newPosition));
|
||||
}
|
||||
|
||||
void MemoryStream::Read(void* buffer, uint64_t length)
|
||||
{
|
||||
uint64_t position = GetPosition();
|
||||
if (position + length > _dataSize)
|
||||
{
|
||||
throw IOException("Attempted to read past end of stream.");
|
||||
_dataCapacity = capacity;
|
||||
_data = Memory::Allocate<void>(capacity);
|
||||
_position = _data;
|
||||
}
|
||||
|
||||
std::memcpy(buffer, _position, length);
|
||||
_position = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(_position) + length);
|
||||
}
|
||||
MemoryStream::MemoryStream(void* data, size_t dataSize, uint8_t access)
|
||||
{
|
||||
_access = access;
|
||||
_dataCapacity = dataSize;
|
||||
_dataSize = dataSize;
|
||||
_data = data;
|
||||
_position = _data;
|
||||
}
|
||||
|
||||
void MemoryStream::Read1(void* buffer)
|
||||
{
|
||||
Read<1>(buffer);
|
||||
}
|
||||
MemoryStream::MemoryStream(const void* data, size_t dataSize)
|
||||
: MemoryStream(const_cast<void*>(data), dataSize, MEMORY_ACCESS::READ)
|
||||
{
|
||||
}
|
||||
|
||||
void MemoryStream::Read2(void* buffer)
|
||||
{
|
||||
Read<2>(buffer);
|
||||
}
|
||||
MemoryStream::MemoryStream(MemoryStream&& mv) noexcept
|
||||
{
|
||||
*this = std::move(mv);
|
||||
}
|
||||
|
||||
void MemoryStream::Read4(void* buffer)
|
||||
{
|
||||
Read<4>(buffer);
|
||||
}
|
||||
|
||||
void MemoryStream::Read8(void* buffer)
|
||||
{
|
||||
Read<8>(buffer);
|
||||
}
|
||||
|
||||
void MemoryStream::Read16(void* buffer)
|
||||
{
|
||||
Read<16>(buffer);
|
||||
}
|
||||
|
||||
uint64_t MemoryStream::TryRead(void* buffer, uint64_t length)
|
||||
{
|
||||
uint64_t remainingBytes = GetLength() - GetPosition();
|
||||
uint64_t bytesToRead = std::min(length, remainingBytes);
|
||||
Read(buffer, bytesToRead);
|
||||
return bytesToRead;
|
||||
}
|
||||
|
||||
void MemoryStream::Write(const void* buffer, uint64_t length)
|
||||
{
|
||||
uint64_t position = GetPosition();
|
||||
uint64_t nextPosition = position + length;
|
||||
if (nextPosition > _dataCapacity)
|
||||
MemoryStream::~MemoryStream()
|
||||
{
|
||||
if (_access & MEMORY_ACCESS::OWNER)
|
||||
{
|
||||
EnsureCapacity(static_cast<size_t>(nextPosition));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw IOException("Attempted to write past end of stream.");
|
||||
Memory::Free(_data);
|
||||
}
|
||||
_dataCapacity = 0;
|
||||
_dataSize = 0;
|
||||
_data = nullptr;
|
||||
}
|
||||
|
||||
std::memcpy(_position, buffer, length);
|
||||
_position = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(_position) + length);
|
||||
_dataSize = std::max<size_t>(_dataSize, static_cast<size_t>(nextPosition));
|
||||
}
|
||||
|
||||
void MemoryStream::Write1(const void* buffer)
|
||||
{
|
||||
Write<1>(buffer);
|
||||
}
|
||||
|
||||
void MemoryStream::Write2(const void* buffer)
|
||||
{
|
||||
Write<2>(buffer);
|
||||
}
|
||||
|
||||
void MemoryStream::Write4(const void* buffer)
|
||||
{
|
||||
Write<4>(buffer);
|
||||
}
|
||||
|
||||
void MemoryStream::Write8(const void* buffer)
|
||||
{
|
||||
Write<8>(buffer);
|
||||
}
|
||||
|
||||
void MemoryStream::Write16(const void* buffer)
|
||||
{
|
||||
Write<16>(buffer);
|
||||
}
|
||||
|
||||
void MemoryStream::EnsureCapacity(size_t capacity)
|
||||
{
|
||||
if (_dataCapacity < capacity)
|
||||
MemoryStream& MemoryStream::operator=(MemoryStream&& mv) noexcept
|
||||
{
|
||||
size_t newCapacity = std::max<size_t>(8, _dataCapacity);
|
||||
while (newCapacity < capacity)
|
||||
_access = mv._access;
|
||||
_dataCapacity = mv._dataCapacity;
|
||||
_data = mv._data;
|
||||
_position = mv._position;
|
||||
|
||||
mv._data = nullptr;
|
||||
mv._position = nullptr;
|
||||
mv._dataCapacity = 0;
|
||||
mv._dataSize = 0;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
const void* MemoryStream::GetData() const
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
void* MemoryStream::GetDataCopy() const
|
||||
{
|
||||
auto result = Memory::Allocate<void>(_dataSize);
|
||||
std::memcpy(result, _data, _dataSize);
|
||||
return result;
|
||||
}
|
||||
|
||||
void* MemoryStream::TakeData()
|
||||
{
|
||||
_access &= ~MEMORY_ACCESS::OWNER;
|
||||
return _data;
|
||||
}
|
||||
|
||||
bool MemoryStream::CanRead() const
|
||||
{
|
||||
return (_access & MEMORY_ACCESS::READ) != 0;
|
||||
}
|
||||
|
||||
bool MemoryStream::CanWrite() const
|
||||
{
|
||||
return (_access & MEMORY_ACCESS::WRITE) != 0;
|
||||
}
|
||||
|
||||
uint64_t MemoryStream::GetLength() const
|
||||
{
|
||||
return _dataSize;
|
||||
}
|
||||
|
||||
uint64_t MemoryStream::GetPosition() const
|
||||
{
|
||||
return static_cast<uint64_t>(reinterpret_cast<uintptr_t>(_position) - reinterpret_cast<uintptr_t>(_data));
|
||||
}
|
||||
|
||||
void MemoryStream::SetPosition(uint64_t position)
|
||||
{
|
||||
Seek(position, STREAM_SEEK_BEGIN);
|
||||
}
|
||||
|
||||
void MemoryStream::Seek(int64_t offset, int32_t origin)
|
||||
{
|
||||
uint64_t newPosition;
|
||||
switch (origin)
|
||||
{
|
||||
newCapacity *= 2;
|
||||
default:
|
||||
case STREAM_SEEK_BEGIN:
|
||||
newPosition = offset;
|
||||
break;
|
||||
case STREAM_SEEK_CURRENT:
|
||||
newPosition = GetPosition() + offset;
|
||||
break;
|
||||
case STREAM_SEEK_END:
|
||||
newPosition = _dataSize + offset;
|
||||
break;
|
||||
}
|
||||
|
||||
uint64_t position = GetPosition();
|
||||
_dataCapacity = newCapacity;
|
||||
_data = Memory::Reallocate(_data, _dataCapacity);
|
||||
_position = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(_data) + static_cast<uintptr_t>(position));
|
||||
if (newPosition > _dataSize)
|
||||
{
|
||||
throw IOException("New position out of bounds.");
|
||||
}
|
||||
_position = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(_data) + static_cast<uintptr_t>(newPosition));
|
||||
}
|
||||
}
|
||||
|
||||
void MemoryStream::Read(void* buffer, uint64_t length)
|
||||
{
|
||||
uint64_t position = GetPosition();
|
||||
if (position + length > _dataSize)
|
||||
{
|
||||
throw IOException("Attempted to read past end of stream.");
|
||||
}
|
||||
|
||||
std::memcpy(buffer, _position, length);
|
||||
_position = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(_position) + length);
|
||||
}
|
||||
|
||||
void MemoryStream::Read1(void* buffer)
|
||||
{
|
||||
Read<1>(buffer);
|
||||
}
|
||||
|
||||
void MemoryStream::Read2(void* buffer)
|
||||
{
|
||||
Read<2>(buffer);
|
||||
}
|
||||
|
||||
void MemoryStream::Read4(void* buffer)
|
||||
{
|
||||
Read<4>(buffer);
|
||||
}
|
||||
|
||||
void MemoryStream::Read8(void* buffer)
|
||||
{
|
||||
Read<8>(buffer);
|
||||
}
|
||||
|
||||
void MemoryStream::Read16(void* buffer)
|
||||
{
|
||||
Read<16>(buffer);
|
||||
}
|
||||
|
||||
uint64_t MemoryStream::TryRead(void* buffer, uint64_t length)
|
||||
{
|
||||
uint64_t remainingBytes = GetLength() - GetPosition();
|
||||
uint64_t bytesToRead = std::min(length, remainingBytes);
|
||||
Read(buffer, bytesToRead);
|
||||
return bytesToRead;
|
||||
}
|
||||
|
||||
void MemoryStream::Write(const void* buffer, uint64_t length)
|
||||
{
|
||||
uint64_t position = GetPosition();
|
||||
uint64_t nextPosition = position + length;
|
||||
if (nextPosition > _dataCapacity)
|
||||
{
|
||||
if (_access & MEMORY_ACCESS::OWNER)
|
||||
{
|
||||
EnsureCapacity(static_cast<size_t>(nextPosition));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw IOException("Attempted to write past end of stream.");
|
||||
}
|
||||
}
|
||||
|
||||
std::memcpy(_position, buffer, length);
|
||||
_position = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(_position) + length);
|
||||
_dataSize = std::max<size_t>(_dataSize, static_cast<size_t>(nextPosition));
|
||||
}
|
||||
|
||||
void MemoryStream::Write1(const void* buffer)
|
||||
{
|
||||
Write<1>(buffer);
|
||||
}
|
||||
|
||||
void MemoryStream::Write2(const void* buffer)
|
||||
{
|
||||
Write<2>(buffer);
|
||||
}
|
||||
|
||||
void MemoryStream::Write4(const void* buffer)
|
||||
{
|
||||
Write<4>(buffer);
|
||||
}
|
||||
|
||||
void MemoryStream::Write8(const void* buffer)
|
||||
{
|
||||
Write<8>(buffer);
|
||||
}
|
||||
|
||||
void MemoryStream::Write16(const void* buffer)
|
||||
{
|
||||
Write<16>(buffer);
|
||||
}
|
||||
|
||||
void MemoryStream::EnsureCapacity(size_t capacity)
|
||||
{
|
||||
if (_dataCapacity < capacity)
|
||||
{
|
||||
size_t newCapacity = std::max<size_t>(8, _dataCapacity);
|
||||
while (newCapacity < capacity)
|
||||
{
|
||||
newCapacity *= 2;
|
||||
}
|
||||
|
||||
uint64_t position = GetPosition();
|
||||
_dataCapacity = newCapacity;
|
||||
_data = Memory::Reallocate(_data, _dataCapacity);
|
||||
_position = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(_data) + static_cast<uintptr_t>(position));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace OpenRCT2
|
||||
@@ -14,100 +14,104 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace MEMORY_ACCESS
|
||||
namespace OpenRCT2
|
||||
{
|
||||
constexpr uint8_t READ = 1 << 0;
|
||||
constexpr uint8_t WRITE = 1 << 1;
|
||||
constexpr uint8_t OWNER = 1 << 2;
|
||||
}; // namespace MEMORY_ACCESS
|
||||
|
||||
/**
|
||||
* A stream for reading and writing to a buffer in memory. By default this buffer can grow.
|
||||
*/
|
||||
class MemoryStream final : public IStream
|
||||
{
|
||||
private:
|
||||
uint8_t _access = MEMORY_ACCESS::READ | MEMORY_ACCESS::WRITE | MEMORY_ACCESS::OWNER;
|
||||
size_t _dataCapacity = 0;
|
||||
size_t _dataSize = 0;
|
||||
void* _data = nullptr;
|
||||
void* _position = nullptr;
|
||||
|
||||
public:
|
||||
MemoryStream() = default;
|
||||
MemoryStream(const MemoryStream& copy);
|
||||
MemoryStream(MemoryStream&& mv) noexcept;
|
||||
explicit MemoryStream(size_t capacity);
|
||||
MemoryStream(void* data, size_t dataSize, uint8_t access = MEMORY_ACCESS::READ);
|
||||
MemoryStream(const void* data, size_t dataSize);
|
||||
virtual ~MemoryStream();
|
||||
|
||||
MemoryStream& operator=(MemoryStream&& mv) noexcept;
|
||||
|
||||
const void* GetData() const override;
|
||||
void* GetDataCopy() const;
|
||||
void* TakeData();
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// ISteam methods
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
bool CanRead() const override;
|
||||
bool CanWrite() const override;
|
||||
|
||||
uint64_t GetLength() const override;
|
||||
uint64_t GetPosition() const override;
|
||||
void SetPosition(uint64_t position) override;
|
||||
void Seek(int64_t offset, int32_t origin) override;
|
||||
|
||||
void Read(void* buffer, uint64_t length) override;
|
||||
void Read1(void* buffer) override;
|
||||
void Read2(void* buffer) override;
|
||||
void Read4(void* buffer) override;
|
||||
void Read8(void* buffer) override;
|
||||
void Read16(void* buffer) override;
|
||||
|
||||
template<size_t N> void Read(void* buffer)
|
||||
namespace MEMORY_ACCESS
|
||||
{
|
||||
uint64_t position = GetPosition();
|
||||
if (position + N > _dataSize)
|
||||
constexpr uint8_t READ = 1 << 0;
|
||||
constexpr uint8_t WRITE = 1 << 1;
|
||||
constexpr uint8_t OWNER = 1 << 2;
|
||||
}; // namespace MEMORY_ACCESS
|
||||
|
||||
/**
|
||||
* A stream for reading and writing to a buffer in memory. By default this buffer can grow.
|
||||
*/
|
||||
class MemoryStream final : public IStream
|
||||
{
|
||||
private:
|
||||
uint8_t _access = MEMORY_ACCESS::READ | MEMORY_ACCESS::WRITE | MEMORY_ACCESS::OWNER;
|
||||
size_t _dataCapacity = 0;
|
||||
size_t _dataSize = 0;
|
||||
void* _data = nullptr;
|
||||
void* _position = nullptr;
|
||||
|
||||
public:
|
||||
MemoryStream() = default;
|
||||
MemoryStream(const MemoryStream& copy);
|
||||
MemoryStream(MemoryStream&& mv) noexcept;
|
||||
explicit MemoryStream(size_t capacity);
|
||||
MemoryStream(void* data, size_t dataSize, uint8_t access = MEMORY_ACCESS::READ);
|
||||
MemoryStream(const void* data, size_t dataSize);
|
||||
virtual ~MemoryStream();
|
||||
|
||||
MemoryStream& operator=(MemoryStream&& mv) noexcept;
|
||||
|
||||
const void* GetData() const override;
|
||||
void* GetDataCopy() const;
|
||||
void* TakeData();
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// ISteam methods
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
bool CanRead() const override;
|
||||
bool CanWrite() const override;
|
||||
|
||||
uint64_t GetLength() const override;
|
||||
uint64_t GetPosition() const override;
|
||||
void SetPosition(uint64_t position) override;
|
||||
void Seek(int64_t offset, int32_t origin) override;
|
||||
|
||||
void Read(void* buffer, uint64_t length) override;
|
||||
void Read1(void* buffer) override;
|
||||
void Read2(void* buffer) override;
|
||||
void Read4(void* buffer) override;
|
||||
void Read8(void* buffer) override;
|
||||
void Read16(void* buffer) override;
|
||||
|
||||
template<size_t N> void Read(void* buffer)
|
||||
{
|
||||
throw IOException("Attempted to read past end of stream.");
|
||||
uint64_t position = GetPosition();
|
||||
if (position + N > _dataSize)
|
||||
{
|
||||
throw IOException("Attempted to read past end of stream.");
|
||||
}
|
||||
|
||||
std::memcpy(buffer, _position, N);
|
||||
_position = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(_position) + N);
|
||||
}
|
||||
|
||||
std::memcpy(buffer, _position, N);
|
||||
_position = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(_position) + N);
|
||||
}
|
||||
void Write(const void* buffer, uint64_t length) override;
|
||||
void Write1(const void* buffer) override;
|
||||
void Write2(const void* buffer) override;
|
||||
void Write4(const void* buffer) override;
|
||||
void Write8(const void* buffer) override;
|
||||
void Write16(const void* buffer) override;
|
||||
|
||||
void Write(const void* buffer, uint64_t length) override;
|
||||
void Write1(const void* buffer) override;
|
||||
void Write2(const void* buffer) override;
|
||||
void Write4(const void* buffer) override;
|
||||
void Write8(const void* buffer) override;
|
||||
void Write16(const void* buffer) override;
|
||||
|
||||
template<size_t N> void Write(const void* buffer)
|
||||
{
|
||||
uint64_t position = GetPosition();
|
||||
uint64_t nextPosition = position + N;
|
||||
if (nextPosition > _dataCapacity)
|
||||
template<size_t N> void Write(const void* buffer)
|
||||
{
|
||||
if (_access & MEMORY_ACCESS::OWNER)
|
||||
uint64_t position = GetPosition();
|
||||
uint64_t nextPosition = position + N;
|
||||
if (nextPosition > _dataCapacity)
|
||||
{
|
||||
EnsureCapacity(static_cast<size_t>(nextPosition));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw IOException("Attempted to write past end of stream.");
|
||||
if (_access & MEMORY_ACCESS::OWNER)
|
||||
{
|
||||
EnsureCapacity(static_cast<size_t>(nextPosition));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw IOException("Attempted to write past end of stream.");
|
||||
}
|
||||
}
|
||||
|
||||
std::memcpy(_position, buffer, N);
|
||||
_position = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(_position) + N);
|
||||
_dataSize = std::max<size_t>(_dataSize, static_cast<size_t>(nextPosition));
|
||||
}
|
||||
|
||||
std::memcpy(_position, buffer, N);
|
||||
_position = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(_position) + N);
|
||||
_dataSize = std::max<size_t>(_dataSize, static_cast<size_t>(nextPosition));
|
||||
}
|
||||
uint64_t TryRead(void* buffer, uint64_t length) override;
|
||||
|
||||
uint64_t TryRead(void* buffer, uint64_t length) override;
|
||||
private:
|
||||
void EnsureCapacity(size_t capacity);
|
||||
};
|
||||
|
||||
private:
|
||||
void EnsureCapacity(size_t capacity);
|
||||
};
|
||||
} // namespace OpenRCT2
|
||||
@@ -77,7 +77,7 @@ public:
|
||||
utf8* fileData = nullptr;
|
||||
try
|
||||
{
|
||||
FileStream fs = FileStream(path, FILE_MODE_OPEN);
|
||||
OpenRCT2::FileStream fs = OpenRCT2::FileStream(path, OpenRCT2::FILE_MODE_OPEN);
|
||||
|
||||
size_t fileLength = static_cast<size_t>(fs.GetLength());
|
||||
if (fileLength > MAX_LANGUAGE_SIZE)
|
||||
|
||||
@@ -1430,7 +1430,7 @@ uint8_t* NetworkBase::save_for_network(size_t& out_size, const std::vector<const
|
||||
bool RLEState = gUseRLE;
|
||||
gUseRLE = false;
|
||||
|
||||
auto ms = MemoryStream();
|
||||
auto ms = OpenRCT2::MemoryStream();
|
||||
if (!SaveMap(&ms, objects))
|
||||
{
|
||||
log_warning("Failed to export map.");
|
||||
|
||||
@@ -68,7 +68,7 @@ public: // Server
|
||||
void RemovePlayer(std::unique_ptr<NetworkConnection>& connection);
|
||||
void UpdateServer();
|
||||
void ServerClientDisconnected(std::unique_ptr<NetworkConnection>& connection);
|
||||
bool SaveMap(IStream* stream, const std::vector<const ObjectRepositoryItem*>& objects) const;
|
||||
bool SaveMap(OpenRCT2::IStream* stream, const std::vector<const ObjectRepositoryItem*>& objects) const;
|
||||
uint8_t* save_for_network(size_t& out_size, const std::vector<const ObjectRepositoryItem*>& objects) const;
|
||||
std::string MakePlayerNameUnique(const std::string& name);
|
||||
|
||||
@@ -120,7 +120,7 @@ public: // Client
|
||||
bool IsDesynchronised();
|
||||
NetworkServerState_t GetServerState() const;
|
||||
void ServerClientDisconnected();
|
||||
bool LoadMap(IStream* stream);
|
||||
bool LoadMap(OpenRCT2::IStream* stream);
|
||||
void UpdateClient();
|
||||
|
||||
// Packet dispatchers.
|
||||
@@ -218,7 +218,7 @@ private: // Client Data
|
||||
std::string _chatLogPath;
|
||||
std::string _chatLogFilenameFormat = "%Y%m%d-%H%M%S.txt";
|
||||
std::string _password;
|
||||
MemoryStream _serverGameState;
|
||||
OpenRCT2::MemoryStream _serverGameState;
|
||||
NetworkServerState_t _serverState;
|
||||
uint32_t _lastSentHeartbeat = 0;
|
||||
uint32_t last_ping_sent_time = 0;
|
||||
|
||||
@@ -44,7 +44,7 @@ bool NetworkKey::Generate()
|
||||
}
|
||||
}
|
||||
|
||||
bool NetworkKey::LoadPrivate(IStream* stream)
|
||||
bool NetworkKey::LoadPrivate(OpenRCT2::IStream* stream)
|
||||
{
|
||||
Guard::ArgumentNotNull(stream);
|
||||
|
||||
@@ -76,7 +76,7 @@ bool NetworkKey::LoadPrivate(IStream* stream)
|
||||
}
|
||||
}
|
||||
|
||||
bool NetworkKey::LoadPublic(IStream* stream)
|
||||
bool NetworkKey::LoadPublic(OpenRCT2::IStream* stream)
|
||||
{
|
||||
Guard::ArgumentNotNull(stream);
|
||||
|
||||
@@ -108,7 +108,7 @@ bool NetworkKey::LoadPublic(IStream* stream)
|
||||
}
|
||||
}
|
||||
|
||||
bool NetworkKey::SavePrivate(IStream* stream)
|
||||
bool NetworkKey::SavePrivate(OpenRCT2::IStream* stream)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -127,7 +127,7 @@ bool NetworkKey::SavePrivate(IStream* stream)
|
||||
}
|
||||
}
|
||||
|
||||
bool NetworkKey::SavePublic(IStream* stream)
|
||||
bool NetworkKey::SavePublic(OpenRCT2::IStream* stream)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -18,7 +18,10 @@
|
||||
# include <string>
|
||||
# include <vector>
|
||||
|
||||
INTERFACE IStream;
|
||||
namespace OpenRCT2
|
||||
{
|
||||
INTERFACE IStream;
|
||||
}
|
||||
|
||||
namespace Crypt
|
||||
{
|
||||
@@ -31,10 +34,10 @@ public:
|
||||
NetworkKey();
|
||||
~NetworkKey();
|
||||
bool Generate();
|
||||
bool LoadPrivate(IStream* stream);
|
||||
bool LoadPublic(IStream* stream);
|
||||
bool SavePrivate(IStream* stream);
|
||||
bool SavePublic(IStream* stream);
|
||||
bool LoadPrivate(OpenRCT2::IStream* stream);
|
||||
bool LoadPublic(OpenRCT2::IStream* stream);
|
||||
bool SavePrivate(OpenRCT2::IStream* stream);
|
||||
bool SavePublic(OpenRCT2::IStream* stream);
|
||||
std::string PublicKeyString();
|
||||
std::string PublicKeyHash();
|
||||
void Unload();
|
||||
|
||||
@@ -17,14 +17,14 @@
|
||||
#include "ObjectJsonHelpers.h"
|
||||
#include "ObjectList.h"
|
||||
|
||||
void BannerObject::ReadLegacy(IReadObjectContext* context, IStream* stream)
|
||||
void BannerObject::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream)
|
||||
{
|
||||
stream->Seek(6, STREAM_SEEK_CURRENT);
|
||||
stream->Seek(6, OpenRCT2::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.scenery_tab_id = OBJECT_ENTRY_INDEX_NULL;
|
||||
stream->Seek(2, STREAM_SEEK_CURRENT);
|
||||
stream->Seek(2, OpenRCT2::STREAM_SEEK_CURRENT);
|
||||
|
||||
GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME);
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../core/IStream.hpp"
|
||||
#include "../world/Scenery.h"
|
||||
#include "SceneryObject.h"
|
||||
|
||||
@@ -28,7 +29,7 @@ public:
|
||||
return &_legacyType;
|
||||
}
|
||||
|
||||
void ReadLegacy(IReadObjectContext* context, IStream* stream) override;
|
||||
void ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream) override;
|
||||
void ReadJson(IReadObjectContext* context, const json_t* root) override;
|
||||
void Load() override;
|
||||
void Unload() override;
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
#include "../localisation/Localisation.h"
|
||||
#include "ObjectJsonHelpers.h"
|
||||
|
||||
void EntranceObject::ReadLegacy(IReadObjectContext* context, IStream* stream)
|
||||
void EntranceObject::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream)
|
||||
{
|
||||
stream->Seek(6, STREAM_SEEK_CURRENT);
|
||||
stream->Seek(6, OpenRCT2::STREAM_SEEK_CURRENT);
|
||||
_legacyType.scrolling_mode = stream->ReadValue<uint8_t>();
|
||||
_legacyType.text_height = stream->ReadValue<uint8_t>();
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ public:
|
||||
return &_legacyType;
|
||||
}
|
||||
|
||||
void ReadLegacy(IReadObjectContext* context, IStream* stream) override;
|
||||
void ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream) override;
|
||||
void ReadJson(IReadObjectContext* context, const json_t* root) override;
|
||||
void Load() override;
|
||||
void Unload() override;
|
||||
|
||||
@@ -20,15 +20,15 @@
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
void FootpathItemObject::ReadLegacy(IReadObjectContext* context, IStream* stream)
|
||||
void FootpathItemObject::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream)
|
||||
{
|
||||
stream->Seek(6, STREAM_SEEK_CURRENT);
|
||||
stream->Seek(6, OpenRCT2::STREAM_SEEK_CURRENT);
|
||||
_legacyType.path_bit.flags = 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.scenery_tab_id = OBJECT_ENTRY_INDEX_NULL;
|
||||
stream->Seek(2, STREAM_SEEK_CURRENT);
|
||||
stream->Seek(2, OpenRCT2::STREAM_SEEK_CURRENT);
|
||||
|
||||
GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME);
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ public:
|
||||
return &_legacyType;
|
||||
}
|
||||
|
||||
void ReadLegacy(IReadObjectContext* context, IStream* stream) override;
|
||||
void ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream) override;
|
||||
void ReadJson(IReadObjectContext* context, const json_t* root) override;
|
||||
void Load() override;
|
||||
void Unload() override;
|
||||
|
||||
@@ -15,13 +15,13 @@
|
||||
#include "../world/Footpath.h"
|
||||
#include "ObjectJsonHelpers.h"
|
||||
|
||||
void FootpathObject::ReadLegacy(IReadObjectContext* context, IStream* stream)
|
||||
void FootpathObject::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream)
|
||||
{
|
||||
stream->Seek(10, STREAM_SEEK_CURRENT);
|
||||
stream->Seek(10, OpenRCT2::STREAM_SEEK_CURRENT);
|
||||
_legacyType.support_type = static_cast<RailingEntrySupportType>(stream->ReadValue<uint8_t>());
|
||||
_legacyType.flags = stream->ReadValue<uint8_t>();
|
||||
_legacyType.scrolling_mode = stream->ReadValue<uint8_t>();
|
||||
stream->Seek(1, STREAM_SEEK_CURRENT);
|
||||
stream->Seek(1, OpenRCT2::STREAM_SEEK_CURRENT);
|
||||
|
||||
GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME);
|
||||
GetImageTable().Read(context, stream);
|
||||
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
return &_pathRailingsEntry;
|
||||
}
|
||||
|
||||
void ReadLegacy(IReadObjectContext* context, IStream* stream) override;
|
||||
void ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream) override;
|
||||
void ReadJson(IReadObjectContext* context, const json_t* root) override;
|
||||
void Load() override;
|
||||
void Unload() override;
|
||||
|
||||
@@ -28,7 +28,7 @@ ImageTable::~ImageTable()
|
||||
}
|
||||
}
|
||||
|
||||
void ImageTable::Read(IReadObjectContext* context, IStream* stream)
|
||||
void ImageTable::Read(IReadObjectContext* context, OpenRCT2::IStream* stream)
|
||||
{
|
||||
if (gOpenRCT2NoGraphics)
|
||||
{
|
||||
|
||||
@@ -16,7 +16,10 @@
|
||||
#include <vector>
|
||||
|
||||
INTERFACE IReadObjectContext;
|
||||
INTERFACE IStream;
|
||||
namespace OpenRCT2
|
||||
{
|
||||
INTERFACE IStream;
|
||||
}
|
||||
|
||||
class ImageTable
|
||||
{
|
||||
@@ -30,7 +33,7 @@ public:
|
||||
ImageTable& operator=(const ImageTable&) = delete;
|
||||
~ImageTable();
|
||||
|
||||
void Read(IReadObjectContext* context, IStream* stream);
|
||||
void Read(IReadObjectContext* context, OpenRCT2::IStream* stream);
|
||||
const rct_g1_element* GetImages() const
|
||||
{
|
||||
return _entries.data();
|
||||
|
||||
@@ -23,17 +23,17 @@
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
|
||||
void LargeSceneryObject::ReadLegacy(IReadObjectContext* context, IStream* stream)
|
||||
void LargeSceneryObject::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream)
|
||||
{
|
||||
stream->Seek(6, STREAM_SEEK_CURRENT);
|
||||
stream->Seek(6, OpenRCT2::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>();
|
||||
stream->Seek(5, STREAM_SEEK_CURRENT);
|
||||
stream->Seek(5, OpenRCT2::STREAM_SEEK_CURRENT);
|
||||
_legacyType.large_scenery.scenery_tab_id = OBJECT_ENTRY_INDEX_NULL;
|
||||
_legacyType.large_scenery.scrolling_mode = stream->ReadValue<uint8_t>();
|
||||
stream->Seek(4, STREAM_SEEK_CURRENT);
|
||||
stream->Seek(4, OpenRCT2::STREAM_SEEK_CURRENT);
|
||||
|
||||
GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME);
|
||||
|
||||
@@ -108,12 +108,12 @@ void LargeSceneryObject::DrawPreview(rct_drawpixelinfo* dpi, int32_t width, int3
|
||||
gfx_draw_sprite(dpi, imageId, screenCoords, 0);
|
||||
}
|
||||
|
||||
std::vector<rct_large_scenery_tile> LargeSceneryObject::ReadTiles(IStream* stream)
|
||||
std::vector<rct_large_scenery_tile> LargeSceneryObject::ReadTiles(OpenRCT2::IStream* stream)
|
||||
{
|
||||
auto tiles = std::vector<rct_large_scenery_tile>();
|
||||
while (stream->ReadValue<uint16_t>() != 0xFFFF)
|
||||
{
|
||||
stream->Seek(-2, STREAM_SEEK_CURRENT);
|
||||
stream->Seek(-2, OpenRCT2::STREAM_SEEK_CURRENT);
|
||||
auto tile = stream->ReadValue<rct_large_scenery_tile>();
|
||||
tiles.push_back(tile);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public:
|
||||
return &_legacyType;
|
||||
}
|
||||
|
||||
void ReadLegacy(IReadObjectContext* context, IStream* stream) override;
|
||||
void ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream) override;
|
||||
void ReadJson(IReadObjectContext* context, const json_t* root) override;
|
||||
void Load() override;
|
||||
void Unload() override;
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
void DrawPreview(rct_drawpixelinfo* dpi, int32_t width, int32_t height) const override;
|
||||
|
||||
private:
|
||||
static std::vector<rct_large_scenery_tile> ReadTiles(IStream* stream);
|
||||
static std::vector<rct_large_scenery_tile> ReadTiles(OpenRCT2::IStream* stream);
|
||||
static std::vector<rct_large_scenery_tile> ReadJsonTiles(const json_t* jTiles);
|
||||
static std::unique_ptr<rct_large_scenery_text> ReadJson3dFont(const json_t* j3dFont);
|
||||
static std::vector<LocationXY16> ReadJsonOffsets(const json_t* jOffsets);
|
||||
|
||||
@@ -32,7 +32,7 @@ void* Object::GetLegacyData()
|
||||
throw std::runtime_error("Not supported.");
|
||||
}
|
||||
|
||||
void Object::ReadLegacy(IReadObjectContext* context, IStream* stream)
|
||||
void Object::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream)
|
||||
{
|
||||
throw std::runtime_error("Not supported.");
|
||||
}
|
||||
|
||||
@@ -135,7 +135,10 @@ assert_struct_size(rct_object_filters, 3);
|
||||
#pragma pack(pop)
|
||||
|
||||
INTERFACE IObjectRepository;
|
||||
INTERFACE IStream;
|
||||
namespace OpenRCT2
|
||||
{
|
||||
INTERFACE IStream;
|
||||
}
|
||||
struct ObjectRepositoryItem;
|
||||
struct rct_drawpixelinfo;
|
||||
struct json_t;
|
||||
@@ -223,7 +226,7 @@ public:
|
||||
virtual void ReadJson(IReadObjectContext* /*context*/, const json_t* /*root*/)
|
||||
{
|
||||
}
|
||||
virtual void ReadLegacy(IReadObjectContext* context, IStream* stream);
|
||||
virtual void ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream);
|
||||
virtual void Load() abstract;
|
||||
virtual void Unload() abstract;
|
||||
|
||||
|
||||
@@ -179,7 +179,7 @@ namespace ObjectFactory
|
||||
return (result != LookupTable.end()) ? result->second : OBJECT_SOURCE_CUSTOM;
|
||||
}
|
||||
|
||||
static void ReadObjectLegacy(Object* object, IReadObjectContext* context, IStream* stream)
|
||||
static void ReadObjectLegacy(Object* object, IReadObjectContext* context, OpenRCT2::IStream* stream)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -203,7 +203,7 @@ namespace ObjectFactory
|
||||
Object* result = nullptr;
|
||||
try
|
||||
{
|
||||
auto fs = FileStream(path, FILE_MODE_OPEN);
|
||||
auto fs = OpenRCT2::FileStream(path, OpenRCT2::FILE_MODE_OPEN);
|
||||
auto chunkReader = SawyerChunkReader(&fs);
|
||||
|
||||
rct_object_entry entry = fs.ReadValue<rct_object_entry>();
|
||||
@@ -219,7 +219,7 @@ namespace ObjectFactory
|
||||
auto chunk = chunkReader.ReadChunk();
|
||||
log_verbose(" size: %zu", chunk->GetLength());
|
||||
|
||||
auto chunkStream = MemoryStream(chunk->GetData(), chunk->GetLength());
|
||||
auto chunkStream = OpenRCT2::MemoryStream(chunk->GetData(), chunk->GetLength());
|
||||
auto readContext = ReadObjectContext(objectRepository, objectName, !gOpenRCT2NoGraphics, nullptr);
|
||||
ReadObjectLegacy(result, &readContext, &chunkStream);
|
||||
if (readContext.WasError())
|
||||
@@ -251,7 +251,7 @@ namespace ObjectFactory
|
||||
object_entry_get_name_fixed(objectName, sizeof(objectName), entry);
|
||||
|
||||
auto readContext = ReadObjectContext(objectRepository, objectName, !gOpenRCT2NoGraphics, nullptr);
|
||||
auto chunkStream = MemoryStream(data, dataSize);
|
||||
auto chunkStream = OpenRCT2::MemoryStream(data, dataSize);
|
||||
ReadObjectLegacy(result, &readContext, &chunkStream);
|
||||
|
||||
if (readContext.WasError())
|
||||
|
||||
@@ -611,7 +611,7 @@ private:
|
||||
return String::Convert(normalisedName, CODE_PAGE::CP_1252, CODE_PAGE::CP_UTF8);
|
||||
}
|
||||
|
||||
void WritePackedObject(IStream* stream, const rct_object_entry* entry)
|
||||
void WritePackedObject(OpenRCT2::IStream* stream, const rct_object_entry* entry)
|
||||
{
|
||||
const ObjectRepositoryItem* item = FindObject(entry);
|
||||
if (item == nullptr)
|
||||
@@ -620,7 +620,7 @@ private:
|
||||
}
|
||||
|
||||
// Read object data from file
|
||||
auto fs = FileStream(item->Path, FILE_MODE_OPEN);
|
||||
auto fs = OpenRCT2::FileStream(item->Path, OpenRCT2::FILE_MODE_OPEN);
|
||||
auto fileEntry = fs.ReadValue<rct_object_entry>();
|
||||
if (!object_entry_compare(entry, &fileEntry))
|
||||
{
|
||||
|
||||
@@ -16,7 +16,11 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
INTERFACE IStream;
|
||||
namespace OpenRCT2
|
||||
{
|
||||
INTERFACE IStream;
|
||||
}
|
||||
|
||||
class Object;
|
||||
namespace OpenRCT2
|
||||
{
|
||||
@@ -76,8 +80,8 @@ INTERFACE IObjectRepository
|
||||
virtual void AddObject(const rct_object_entry* objectEntry, const void* data, size_t dataSize) abstract;
|
||||
virtual void AddObjectFromFile(const std::string_view& objectName, const void* data, size_t dataSize) abstract;
|
||||
|
||||
virtual void ExportPackedObject(IStream * stream) abstract;
|
||||
virtual void WritePackedObjects(IStream * stream, std::vector<const ObjectRepositoryItem*> & objects) abstract;
|
||||
virtual void ExportPackedObject(OpenRCT2::IStream * stream) abstract;
|
||||
virtual void WritePackedObjects(OpenRCT2::IStream * stream, std::vector<const ObjectRepositoryItem*> & objects) abstract;
|
||||
};
|
||||
|
||||
std::unique_ptr<IObjectRepository> CreateObjectRepository(const std::shared_ptr<OpenRCT2::IPlatformEnvironment>& env);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../core/IStream.hpp"
|
||||
#include "../ride/Ride.h"
|
||||
#include "Object.h"
|
||||
|
||||
@@ -34,7 +35,7 @@ public:
|
||||
}
|
||||
|
||||
void ReadJson(IReadObjectContext* context, const json_t* root) override;
|
||||
void ReadLegacy(IReadObjectContext* context, IStream* stream) override;
|
||||
void ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream) override;
|
||||
void Load() override;
|
||||
void Unload() override;
|
||||
|
||||
@@ -46,7 +47,7 @@ public:
|
||||
void SetRepositoryItem(ObjectRepositoryItem* item) const override;
|
||||
|
||||
private:
|
||||
void ReadLegacyVehicle(IReadObjectContext* context, IStream* stream, rct_ride_entry_vehicle* vehicle);
|
||||
void ReadLegacyVehicle(IReadObjectContext* context, OpenRCT2::IStream* stream, rct_ride_entry_vehicle* vehicle);
|
||||
|
||||
void ReadJsonVehicleInfo(IReadObjectContext* context, const json_t* properties);
|
||||
std::vector<rct_ride_entry_vehicle> ReadJsonCars(const json_t* jCars);
|
||||
|
||||
@@ -34,7 +34,7 @@ public:
|
||||
}
|
||||
void ReadJson(IReadObjectContext* context, const json_t* root) override;
|
||||
|
||||
void ReadLegacy(IReadObjectContext* context, IStream* stream) override;
|
||||
void ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream) override;
|
||||
void Load() override;
|
||||
void Unload() override;
|
||||
void UpdateEntryIndexes();
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
void SetRepositoryItem(ObjectRepositoryItem* item) const override;
|
||||
|
||||
private:
|
||||
static std::vector<rct_object_entry> ReadItems(IStream* stream);
|
||||
static std::vector<rct_object_entry> ReadItems(OpenRCT2::IStream* stream);
|
||||
static uint32_t ReadJsonEntertainerCostumes(const json_t* jCostumes);
|
||||
static uint32_t ParseEntertainerCostume(const std::string& s);
|
||||
static std::vector<rct_object_entry> ReadJsonEntries(const json_t* jEntries);
|
||||
|
||||
@@ -23,15 +23,15 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
void SmallSceneryObject::ReadLegacy(IReadObjectContext* context, IStream* stream)
|
||||
void SmallSceneryObject::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream)
|
||||
{
|
||||
stream->Seek(6, STREAM_SEEK_CURRENT);
|
||||
stream->Seek(6, OpenRCT2::STREAM_SEEK_CURRENT);
|
||||
_legacyType.small_scenery.flags = 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>();
|
||||
stream->Seek(4, STREAM_SEEK_CURRENT);
|
||||
stream->Seek(4, OpenRCT2::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>();
|
||||
@@ -139,7 +139,7 @@ void SmallSceneryObject::DrawPreview(rct_drawpixelinfo* dpi, int32_t width, int3
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<uint8_t> SmallSceneryObject::ReadFrameOffsets(IStream* stream)
|
||||
std::vector<uint8_t> SmallSceneryObject::ReadFrameOffsets(OpenRCT2::IStream* stream)
|
||||
{
|
||||
uint8_t frameOffset;
|
||||
auto data = std::vector<uint8_t>();
|
||||
|
||||
@@ -31,7 +31,7 @@ public:
|
||||
return &_legacyType;
|
||||
}
|
||||
|
||||
void ReadLegacy(IReadObjectContext* context, IStream* stream) override;
|
||||
void ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream) override;
|
||||
void ReadJson(IReadObjectContext* context, const json_t* root) override;
|
||||
void Load() override;
|
||||
void Unload() override;
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
void DrawPreview(rct_drawpixelinfo* dpi, int32_t width, int32_t height) const override;
|
||||
|
||||
private:
|
||||
static std::vector<uint8_t> ReadFrameOffsets(IStream* stream);
|
||||
static std::vector<uint8_t> ReadFrameOffsets(OpenRCT2::IStream* stream);
|
||||
static std::vector<uint8_t> ReadJsonFrameOffsets(const json_t* jFrameOffsets);
|
||||
void PerformFixes();
|
||||
rct_object_entry GetScgPiratHeader();
|
||||
|
||||
@@ -47,7 +47,7 @@ static bool StringIsBlank(const utf8* str)
|
||||
return true;
|
||||
}
|
||||
|
||||
void StringTable::Read(IReadObjectContext* context, IStream* stream, uint8_t id)
|
||||
void StringTable::Read(IReadObjectContext* context, OpenRCT2::IStream* stream, uint8_t id)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -16,7 +16,10 @@
|
||||
#include <vector>
|
||||
|
||||
INTERFACE IReadObjectContext;
|
||||
INTERFACE IStream;
|
||||
namespace OpenRCT2
|
||||
{
|
||||
INTERFACE IStream;
|
||||
}
|
||||
|
||||
enum OBJ_STRING_ID : uint8_t
|
||||
{
|
||||
@@ -47,7 +50,7 @@ public:
|
||||
StringTable(const StringTable&) = delete;
|
||||
StringTable& operator=(const StringTable&) = delete;
|
||||
|
||||
void Read(IReadObjectContext* context, IStream* stream, uint8_t id);
|
||||
void Read(IReadObjectContext* context, OpenRCT2::IStream* stream, uint8_t id);
|
||||
void Sort();
|
||||
std::string GetString(uint8_t id) const;
|
||||
std::string GetString(uint8_t language, uint8_t id) const;
|
||||
|
||||
@@ -17,16 +17,16 @@
|
||||
#include "../world/Banner.h"
|
||||
#include "ObjectJsonHelpers.h"
|
||||
|
||||
void WallObject::ReadLegacy(IReadObjectContext* context, IStream* stream)
|
||||
void WallObject::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream)
|
||||
{
|
||||
stream->Seek(6, STREAM_SEEK_CURRENT);
|
||||
stream->Seek(6, OpenRCT2::STREAM_SEEK_CURRENT);
|
||||
_legacyType.wall.tool_id = stream->ReadValue<uint8_t>();
|
||||
_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.scenery_tab_id = OBJECT_ENTRY_INDEX_NULL;
|
||||
stream->Seek(1, STREAM_SEEK_CURRENT);
|
||||
stream->Seek(1, OpenRCT2::STREAM_SEEK_CURRENT);
|
||||
_legacyType.wall.scrolling_mode = stream->ReadValue<uint8_t>();
|
||||
|
||||
GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME);
|
||||
|
||||
@@ -28,7 +28,7 @@ public:
|
||||
return &_legacyType;
|
||||
}
|
||||
|
||||
void ReadLegacy(IReadObjectContext* context, IStream* stream) override;
|
||||
void ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream) override;
|
||||
void ReadJson(IReadObjectContext* context, const json_t* root) override;
|
||||
void Load() override;
|
||||
void Unload() override;
|
||||
|
||||
@@ -20,9 +20,9 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
void WaterObject::ReadLegacy(IReadObjectContext* context, IStream* stream)
|
||||
void WaterObject::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream)
|
||||
{
|
||||
stream->Seek(14, STREAM_SEEK_CURRENT);
|
||||
stream->Seek(14, OpenRCT2::STREAM_SEEK_CURRENT);
|
||||
_legacyType.flags = stream->ReadValue<uint16_t>();
|
||||
|
||||
GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME);
|
||||
|
||||
@@ -31,7 +31,7 @@ public:
|
||||
}
|
||||
|
||||
void ReadJson(IReadObjectContext* context, const json_t* root) override;
|
||||
void ReadLegacy(IReadObjectContext* context, IStream* stream) override;
|
||||
void ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream) override;
|
||||
void Load() override;
|
||||
void Unload() override;
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
class TD4Importer final : public ITrackImporter
|
||||
{
|
||||
private:
|
||||
MemoryStream _stream;
|
||||
OpenRCT2::MemoryStream _stream;
|
||||
std::string _name;
|
||||
|
||||
public:
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
if (String::Equals(extension, ".td4", true))
|
||||
{
|
||||
_name = GetNameFromTrackPath(path);
|
||||
auto fs = FileStream(path, FILE_MODE_OPEN);
|
||||
auto fs = OpenRCT2::FileStream(path, OpenRCT2::FILE_MODE_OPEN);
|
||||
return LoadFromStream(&fs);
|
||||
}
|
||||
else
|
||||
@@ -51,7 +51,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
bool LoadFromStream(IStream* stream) override
|
||||
bool LoadFromStream(OpenRCT2::IStream* stream) override
|
||||
{
|
||||
auto checksumType = SawyerEncoding::ValidateTrackChecksum(stream);
|
||||
if (!gConfigGeneral.allow_loading_with_incorrect_checksum && checksumType == RCT12TrackDesignVersion::unknown)
|
||||
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
SawyerChunkReader::SawyerChunkReader(IStream* stream)
|
||||
SawyerChunkReader::SawyerChunkReader(OpenRCT2::IStream* stream)
|
||||
: _stream(stream)
|
||||
{
|
||||
}
|
||||
@@ -52,7 +52,7 @@ void SawyerChunkReader::SkipChunk()
|
||||
try
|
||||
{
|
||||
auto header = _stream->ReadValue<sawyercoding_chunk_header>();
|
||||
_stream->Seek(header.length, STREAM_SEEK_CURRENT);
|
||||
_stream->Seek(header.length, OpenRCT2::STREAM_SEEK_CURRENT);
|
||||
}
|
||||
catch (const std::exception&)
|
||||
{
|
||||
|
||||
@@ -15,7 +15,10 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
INTERFACE IStream;
|
||||
namespace OpenRCT2
|
||||
{
|
||||
INTERFACE IStream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads sawyer encoding chunks from a data stream. This can be used to read
|
||||
@@ -24,10 +27,10 @@ INTERFACE IStream;
|
||||
class SawyerChunkReader final
|
||||
{
|
||||
private:
|
||||
IStream* const _stream = nullptr;
|
||||
OpenRCT2::IStream* const _stream = nullptr;
|
||||
|
||||
public:
|
||||
explicit SawyerChunkReader(IStream* stream);
|
||||
explicit SawyerChunkReader(OpenRCT2::IStream* stream);
|
||||
|
||||
/**
|
||||
* Skips the next chunk in the stream without decoding or reading its data
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
// Maximum buffer size to store compressed data, maximum of 16 MiB
|
||||
constexpr size_t MAX_COMPRESSED_CHUNK_SIZE = 16 * 1024 * 1024;
|
||||
|
||||
SawyerChunkWriter::SawyerChunkWriter(IStream* stream)
|
||||
SawyerChunkWriter::SawyerChunkWriter(OpenRCT2::IStream* stream)
|
||||
: _stream(stream)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -14,7 +14,10 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
INTERFACE IStream;
|
||||
namespace OpenRCT2
|
||||
{
|
||||
INTERFACE IStream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes sawyer encoding chunks to a data stream. This can be used to write
|
||||
@@ -23,10 +26,10 @@ INTERFACE IStream;
|
||||
class SawyerChunkWriter final
|
||||
{
|
||||
private:
|
||||
IStream* const _stream = nullptr;
|
||||
OpenRCT2::IStream* const _stream = nullptr;
|
||||
|
||||
public:
|
||||
explicit SawyerChunkWriter(IStream* stream);
|
||||
explicit SawyerChunkWriter(OpenRCT2::IStream* stream);
|
||||
|
||||
/**
|
||||
* Writes a chunk to the stream.
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
namespace SawyerEncoding
|
||||
{
|
||||
bool ValidateChecksum(IStream* stream)
|
||||
bool ValidateChecksum(OpenRCT2::IStream* stream)
|
||||
{
|
||||
uint64_t initialPosition = stream->GetPosition();
|
||||
uint64_t dataSize = stream->GetLength() - initialPosition;
|
||||
@@ -60,7 +60,7 @@ namespace SawyerEncoding
|
||||
}
|
||||
|
||||
// Returns version number
|
||||
RCT12TrackDesignVersion ValidateTrackChecksum(IStream* stream)
|
||||
RCT12TrackDesignVersion ValidateTrackChecksum(OpenRCT2::IStream* stream)
|
||||
{
|
||||
uint64_t initialPosition = stream->GetPosition();
|
||||
uint64_t dataSize = stream->GetLength() - initialPosition;
|
||||
|
||||
@@ -11,12 +11,15 @@
|
||||
|
||||
#include "../common.h"
|
||||
|
||||
INTERFACE IStream;
|
||||
namespace OpenRCT2
|
||||
{
|
||||
INTERFACE IStream;
|
||||
}
|
||||
|
||||
enum class RCT12TrackDesignVersion : uint8_t;
|
||||
|
||||
namespace SawyerEncoding
|
||||
{
|
||||
bool ValidateChecksum(IStream* stream);
|
||||
RCT12TrackDesignVersion ValidateTrackChecksum(IStream* stream);
|
||||
bool ValidateChecksum(OpenRCT2::IStream* stream);
|
||||
RCT12TrackDesignVersion ValidateTrackChecksum(OpenRCT2::IStream* stream);
|
||||
} // namespace SawyerEncoding
|
||||
@@ -61,27 +61,27 @@ S6Exporter::S6Exporter()
|
||||
|
||||
void S6Exporter::SaveGame(const utf8* path)
|
||||
{
|
||||
auto fs = FileStream(path, FILE_MODE_WRITE);
|
||||
auto fs = OpenRCT2::FileStream(path, OpenRCT2::FILE_MODE_WRITE);
|
||||
SaveGame(&fs);
|
||||
}
|
||||
|
||||
void S6Exporter::SaveGame(IStream* stream)
|
||||
void S6Exporter::SaveGame(OpenRCT2::IStream* stream)
|
||||
{
|
||||
Save(stream, false);
|
||||
}
|
||||
|
||||
void S6Exporter::SaveScenario(const utf8* path)
|
||||
{
|
||||
auto fs = FileStream(path, FILE_MODE_WRITE);
|
||||
auto fs = OpenRCT2::FileStream(path, OpenRCT2::FILE_MODE_WRITE);
|
||||
SaveScenario(&fs);
|
||||
}
|
||||
|
||||
void S6Exporter::SaveScenario(IStream* stream)
|
||||
void S6Exporter::SaveScenario(OpenRCT2::IStream* stream)
|
||||
{
|
||||
Save(stream, true);
|
||||
}
|
||||
|
||||
void S6Exporter::Save(IStream* stream, bool isScenario)
|
||||
void S6Exporter::Save(OpenRCT2::IStream* stream, bool isScenario)
|
||||
{
|
||||
_s6.header.type = isScenario ? S6_TYPE_SCENARIO : S6_TYPE_SAVEDGAME;
|
||||
_s6.header.classic_flag = 0;
|
||||
|
||||
@@ -18,7 +18,11 @@
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
INTERFACE IStream;
|
||||
namespace OpenRCT2
|
||||
{
|
||||
INTERFACE IStream;
|
||||
}
|
||||
|
||||
struct ObjectRepositoryItem;
|
||||
struct RCT12SpriteBase;
|
||||
struct SpriteBase;
|
||||
@@ -35,9 +39,9 @@ public:
|
||||
S6Exporter();
|
||||
|
||||
void SaveGame(const utf8* path);
|
||||
void SaveGame(IStream* stream);
|
||||
void SaveGame(OpenRCT2::IStream* stream);
|
||||
void SaveScenario(const utf8* path);
|
||||
void SaveScenario(IStream* stream);
|
||||
void SaveScenario(OpenRCT2::IStream* stream);
|
||||
void Export();
|
||||
void ExportParkName();
|
||||
void ExportRides();
|
||||
@@ -54,7 +58,7 @@ private:
|
||||
rct_s6_data _s6{};
|
||||
std::vector<std::string> _userStrings;
|
||||
|
||||
void Save(IStream* stream, bool isScenario);
|
||||
void Save(OpenRCT2::IStream* stream, bool isScenario);
|
||||
static uint32_t GetLoanHash(money32 initialCash, money32 bankLoan, uint32_t maxBankLoan);
|
||||
void ExportResearchedRideTypes();
|
||||
void ExportResearchedRideEntries();
|
||||
|
||||
@@ -93,7 +93,7 @@ public:
|
||||
|
||||
ParkLoadResult LoadSavedGame(const utf8* path, bool skipObjectCheck = false) override
|
||||
{
|
||||
auto fs = FileStream(path, FILE_MODE_OPEN);
|
||||
auto fs = OpenRCT2::FileStream(path, OpenRCT2::FILE_MODE_OPEN);
|
||||
auto result = LoadFromStream(&fs, false, skipObjectCheck);
|
||||
_s6Path = path;
|
||||
return result;
|
||||
@@ -101,14 +101,14 @@ public:
|
||||
|
||||
ParkLoadResult LoadScenario(const utf8* path, bool skipObjectCheck = false) override
|
||||
{
|
||||
auto fs = FileStream(path, FILE_MODE_OPEN);
|
||||
auto fs = OpenRCT2::FileStream(path, OpenRCT2::FILE_MODE_OPEN);
|
||||
auto result = LoadFromStream(&fs, true, skipObjectCheck);
|
||||
_s6Path = path;
|
||||
return result;
|
||||
}
|
||||
|
||||
ParkLoadResult LoadFromStream(
|
||||
IStream* stream, bool isScenario, [[maybe_unused]] bool skipObjectCheck = false,
|
||||
OpenRCT2::IStream* stream, bool isScenario, [[maybe_unused]] bool skipObjectCheck = false,
|
||||
const utf8* path = String::Empty) override
|
||||
{
|
||||
if (isScenario && !gConfigGeneral.allow_loading_with_incorrect_checksum && !SawyerEncoding::ValidateChecksum(stream))
|
||||
|
||||
@@ -35,7 +35,7 @@ bool T6Exporter::SaveTrack(const utf8* path)
|
||||
{
|
||||
try
|
||||
{
|
||||
auto fs = FileStream(path, FILE_MODE_WRITE);
|
||||
auto fs = OpenRCT2::FileStream(path, OpenRCT2::FILE_MODE_WRITE);
|
||||
return SaveTrack(&fs);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
@@ -45,9 +45,9 @@ bool T6Exporter::SaveTrack(const utf8* path)
|
||||
}
|
||||
}
|
||||
|
||||
bool T6Exporter::SaveTrack(IStream* stream)
|
||||
bool T6Exporter::SaveTrack(OpenRCT2::IStream* stream)
|
||||
{
|
||||
MemoryStream tempStream;
|
||||
OpenRCT2::MemoryStream tempStream;
|
||||
tempStream.WriteValue<uint8_t>(_trackDesign->type);
|
||||
tempStream.WriteValue<uint8_t>(_trackDesign->vehicle_type);
|
||||
tempStream.WriteValue<uint32_t>(_trackDesign->flags);
|
||||
|
||||
@@ -14,7 +14,10 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
INTERFACE IStream;
|
||||
namespace OpenRCT2
|
||||
{
|
||||
INTERFACE IStream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class to export RollerCoaster Tycoon 2 track designs (*.TD6).
|
||||
@@ -25,7 +28,7 @@ public:
|
||||
T6Exporter(TrackDesign* trackDesign);
|
||||
|
||||
bool SaveTrack(const utf8* path);
|
||||
bool SaveTrack(IStream* stream);
|
||||
bool SaveTrack(OpenRCT2::IStream* stream);
|
||||
|
||||
private:
|
||||
TrackDesign* _trackDesign;
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
class TD6Importer final : public ITrackImporter
|
||||
{
|
||||
private:
|
||||
MemoryStream _stream;
|
||||
OpenRCT2::MemoryStream _stream;
|
||||
std::string _name;
|
||||
|
||||
public:
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
if (String::Equals(extension, ".td6", true))
|
||||
{
|
||||
_name = GetNameFromTrackPath(path);
|
||||
auto fs = FileStream(path, FILE_MODE_OPEN);
|
||||
auto fs = OpenRCT2::FileStream(path, OpenRCT2::FILE_MODE_OPEN);
|
||||
return LoadFromStream(&fs);
|
||||
}
|
||||
else
|
||||
@@ -49,7 +49,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
bool LoadFromStream(IStream* stream) override
|
||||
bool LoadFromStream(OpenRCT2::IStream* stream) override
|
||||
{
|
||||
if (!gConfigGeneral.allow_loading_with_incorrect_checksum
|
||||
&& SawyerEncoding::ValidateTrackChecksum(stream) != RCT12TrackDesignVersion::TD6)
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
static std::vector<utf8*> GetSaves(const utf8* path);
|
||||
static std::vector<utf8*> GetSaves(IZipArchive* zip);
|
||||
static std::vector<TitleCommand> LegacyScriptRead(utf8* script, size_t scriptLength, std::vector<utf8*> saves);
|
||||
static void LegacyScriptGetLine(IStream* stream, char* parts);
|
||||
static void LegacyScriptGetLine(OpenRCT2::IStream* stream, char* parts);
|
||||
static std::vector<uint8_t> ReadScriptFile(const utf8* path);
|
||||
static std::string LegacyScriptWrite(TitleSequence* seq);
|
||||
|
||||
@@ -131,7 +131,8 @@ TitleSequenceParkHandle* TitleSequenceGetParkHandle(TitleSequence* seq, size_t i
|
||||
auto data = zip->GetFileData(filename);
|
||||
auto dataForMs = Memory::Allocate<uint8_t>(data.size());
|
||||
std::copy_n(data.data(), data.size(), dataForMs);
|
||||
auto ms = new MemoryStream(dataForMs, data.size(), MEMORY_ACCESS::READ | MEMORY_ACCESS::OWNER);
|
||||
auto ms = new OpenRCT2::MemoryStream(
|
||||
dataForMs, data.size(), OpenRCT2::MEMORY_ACCESS::READ | OpenRCT2::MEMORY_ACCESS::OWNER);
|
||||
|
||||
handle = Memory::Allocate<TitleSequenceParkHandle>();
|
||||
handle->Stream = ms;
|
||||
@@ -148,10 +149,10 @@ TitleSequenceParkHandle* TitleSequenceGetParkHandle(TitleSequence* seq, size_t i
|
||||
String::Set(absolutePath, sizeof(absolutePath), seq->Path);
|
||||
Path::Append(absolutePath, sizeof(absolutePath), filename);
|
||||
|
||||
FileStream* fileStream = nullptr;
|
||||
OpenRCT2::FileStream* fileStream = nullptr;
|
||||
try
|
||||
{
|
||||
fileStream = new FileStream(absolutePath, FILE_MODE_OPEN);
|
||||
fileStream = new OpenRCT2::FileStream(absolutePath, OpenRCT2::FILE_MODE_OPEN);
|
||||
}
|
||||
catch (const IOException& exception)
|
||||
{
|
||||
@@ -174,7 +175,7 @@ void TitleSequenceCloseParkHandle(TitleSequenceParkHandle* handle)
|
||||
if (handle != nullptr)
|
||||
{
|
||||
Memory::Free(handle->HintPath);
|
||||
delete (static_cast<IStream*>(handle->Stream));
|
||||
delete (static_cast<OpenRCT2::IStream*>(handle->Stream));
|
||||
Memory::Free(handle);
|
||||
}
|
||||
}
|
||||
@@ -386,7 +387,7 @@ static std::vector<utf8*> GetSaves(IZipArchive* zip)
|
||||
static std::vector<TitleCommand> LegacyScriptRead(utf8* script, size_t scriptLength, std::vector<utf8*> saves)
|
||||
{
|
||||
std::vector<TitleCommand> commands;
|
||||
auto fs = MemoryStream(script, scriptLength);
|
||||
auto fs = OpenRCT2::MemoryStream(script, scriptLength);
|
||||
do
|
||||
{
|
||||
char parts[3 * 128], *token, *part1, *part2;
|
||||
@@ -472,7 +473,7 @@ static std::vector<TitleCommand> LegacyScriptRead(utf8* script, size_t scriptLen
|
||||
return commands;
|
||||
}
|
||||
|
||||
static void LegacyScriptGetLine(IStream* stream, char* parts)
|
||||
static void LegacyScriptGetLine(OpenRCT2::IStream* stream, char* parts)
|
||||
{
|
||||
for (int32_t i = 0; i < 3; i++)
|
||||
{
|
||||
@@ -543,7 +544,7 @@ static std::vector<uint8_t> ReadScriptFile(const utf8* path)
|
||||
std::vector<uint8_t> result;
|
||||
try
|
||||
{
|
||||
auto fs = FileStream(path, FILE_MODE_OPEN);
|
||||
auto fs = OpenRCT2::FileStream(path, OpenRCT2::FILE_MODE_OPEN);
|
||||
auto size = static_cast<size_t>(fs.GetLength());
|
||||
result.resize(size);
|
||||
fs.Read(result.data(), size);
|
||||
|
||||
@@ -29,7 +29,7 @@ static auto Enum_Currency = ConfigEnum<int32_t>({});
|
||||
|
||||
TEST_F(IniReaderTest, create_empty)
|
||||
{
|
||||
MemoryStream ms(0);
|
||||
OpenRCT2::MemoryStream ms(0);
|
||||
ASSERT_EQ(ms.CanRead(), true);
|
||||
ASSERT_EQ(ms.CanWrite(), true);
|
||||
IIniReader* ir = CreateIniReader(&ms);
|
||||
@@ -46,7 +46,7 @@ TEST_F(IniReaderTest, create_empty)
|
||||
|
||||
TEST_F(IniReaderTest, read_prepared)
|
||||
{
|
||||
MemoryStream ms(predefined.c_str(), predefined.size());
|
||||
OpenRCT2::MemoryStream ms(predefined.c_str(), predefined.size());
|
||||
ASSERT_EQ(ms.CanRead(), true);
|
||||
ASSERT_EQ(ms.CanWrite(), false);
|
||||
IIniReader* ir = CreateIniReader(&ms);
|
||||
@@ -76,7 +76,7 @@ TEST_F(IniReaderTest, read_prepared)
|
||||
|
||||
TEST_F(IniReaderTest, read_duplicate)
|
||||
{
|
||||
MemoryStream ms(duplicate.c_str(), duplicate.size());
|
||||
OpenRCT2::MemoryStream ms(duplicate.c_str(), duplicate.size());
|
||||
ASSERT_EQ(ms.CanRead(), true);
|
||||
ASSERT_EQ(ms.CanWrite(), false);
|
||||
IIniReader* ir = CreateIniReader(&ms);
|
||||
@@ -102,7 +102,7 @@ TEST_F(IniReaderTest, read_duplicate)
|
||||
|
||||
TEST_F(IniReaderTest, read_untrimmed)
|
||||
{
|
||||
MemoryStream ms(untrimmed.c_str(), untrimmed.size());
|
||||
OpenRCT2::MemoryStream ms(untrimmed.c_str(), untrimmed.size());
|
||||
ASSERT_EQ(ms.CanRead(), true);
|
||||
ASSERT_EQ(ms.CanWrite(), false);
|
||||
IIniReader* ir = CreateIniReader(&ms);
|
||||
@@ -120,7 +120,7 @@ TEST_F(IniReaderTest, read_untrimmed)
|
||||
|
||||
TEST_F(IniReaderTest, read_case_insensitive)
|
||||
{
|
||||
MemoryStream ms(caseInsensitive.c_str(), caseInsensitive.size());
|
||||
OpenRCT2::MemoryStream ms(caseInsensitive.c_str(), caseInsensitive.size());
|
||||
ASSERT_EQ(ms.CanRead(), true);
|
||||
ASSERT_EQ(ms.CanWrite(), false);
|
||||
IIniReader* ir = CreateIniReader(&ms);
|
||||
|
||||
@@ -26,7 +26,7 @@ static auto Enum_Currency = ConfigEnum<int32_t>({
|
||||
|
||||
TEST_F(IniWriterTest, create_empty)
|
||||
{
|
||||
MemoryStream ms(0);
|
||||
OpenRCT2::MemoryStream ms(0);
|
||||
ASSERT_EQ(ms.CanRead(), true);
|
||||
ASSERT_EQ(ms.CanWrite(), true);
|
||||
IIniWriter* iw = CreateIniWriter(&ms);
|
||||
@@ -36,7 +36,7 @@ TEST_F(IniWriterTest, create_empty)
|
||||
|
||||
TEST_F(IniWriterTest, create_one_section)
|
||||
{
|
||||
MemoryStream ms(1000);
|
||||
OpenRCT2::MemoryStream ms(1000);
|
||||
IIniWriter* iw = CreateIniWriter(&ms);
|
||||
ASSERT_NE(iw, nullptr);
|
||||
iw->WriteSection("OpenRCT2");
|
||||
@@ -54,7 +54,7 @@ TEST_F(IniWriterTest, create_one_section)
|
||||
|
||||
TEST_F(IniWriterTest, create_multiple_sections)
|
||||
{
|
||||
MemoryStream ms(1000);
|
||||
OpenRCT2::MemoryStream ms(1000);
|
||||
IIniWriter* iw = CreateIniWriter(&ms);
|
||||
ASSERT_NE(iw, nullptr);
|
||||
iw->WriteSection("OpenRCT1");
|
||||
@@ -78,7 +78,7 @@ TEST_F(IniWriterTest, create_multiple_sections)
|
||||
|
||||
TEST_F(IniWriterTest, create_loose_bool_entry)
|
||||
{
|
||||
MemoryStream ms(1000);
|
||||
OpenRCT2::MemoryStream ms(1000);
|
||||
IIniWriter* iw = CreateIniWriter(&ms);
|
||||
ASSERT_NE(iw, nullptr);
|
||||
iw->WriteBoolean("boolval", true);
|
||||
@@ -96,7 +96,7 @@ TEST_F(IniWriterTest, create_loose_bool_entry)
|
||||
|
||||
TEST_F(IniWriterTest, create_loose_enum_entry)
|
||||
{
|
||||
MemoryStream ms(1000);
|
||||
OpenRCT2::MemoryStream ms(1000);
|
||||
IIniWriter* iw = CreateIniWriter(&ms);
|
||||
ASSERT_NE(iw, nullptr);
|
||||
iw->WriteEnum("by_string", "stringval");
|
||||
@@ -115,7 +115,7 @@ TEST_F(IniWriterTest, create_loose_enum_entry)
|
||||
|
||||
TEST_F(IniWriterTest, create_loose_float_entry)
|
||||
{
|
||||
MemoryStream ms(1000);
|
||||
OpenRCT2::MemoryStream ms(1000);
|
||||
IIniWriter* iw = CreateIniWriter(&ms);
|
||||
ASSERT_NE(iw, nullptr);
|
||||
iw->WriteFloat("one", 1.);
|
||||
@@ -134,7 +134,7 @@ TEST_F(IniWriterTest, create_loose_float_entry)
|
||||
|
||||
TEST_F(IniWriterTest, create_loose_int32_t_entry)
|
||||
{
|
||||
MemoryStream ms(1000);
|
||||
OpenRCT2::MemoryStream ms(1000);
|
||||
IIniWriter* iw = CreateIniWriter(&ms);
|
||||
ASSERT_NE(iw, nullptr);
|
||||
iw->WriteInt32("one", 1);
|
||||
@@ -159,7 +159,7 @@ TEST_F(IniWriterTest, create_loose_int32_t_entry)
|
||||
|
||||
TEST_F(IniWriterTest, create_loose_string_entry)
|
||||
{
|
||||
MemoryStream ms(1000);
|
||||
OpenRCT2::MemoryStream ms(1000);
|
||||
IIniWriter* iw = CreateIniWriter(&ms);
|
||||
ASSERT_NE(iw, nullptr);
|
||||
iw->WriteString("path", u8"C:'\\some/dir\\here/神鷹暢遊");
|
||||
@@ -177,7 +177,7 @@ TEST_F(IniWriterTest, create_loose_string_entry)
|
||||
|
||||
TEST_F(IniWriterTest, create_multiple_section_with_values)
|
||||
{
|
||||
MemoryStream ms(1000);
|
||||
OpenRCT2::MemoryStream ms(1000);
|
||||
IIniWriter* iw = CreateIniWriter(&ms);
|
||||
ASSERT_NE(iw, nullptr);
|
||||
iw->WriteSection("bool");
|
||||
@@ -205,7 +205,7 @@ TEST_F(IniWriterTest, create_multiple_section_with_values)
|
||||
|
||||
TEST_F(IniWriterTest, create_duplicate_sections)
|
||||
{
|
||||
MemoryStream ms(1000);
|
||||
OpenRCT2::MemoryStream ms(1000);
|
||||
IIniWriter* iw = CreateIniWriter(&ms);
|
||||
ASSERT_NE(iw, nullptr);
|
||||
iw->WriteSection("section");
|
||||
|
||||
@@ -34,7 +34,7 @@ protected:
|
||||
ASSERT_GT(encodedDataSize, sizeof(sawyercoding_chunk_header));
|
||||
|
||||
// Decode
|
||||
MemoryStream ms(encodedDataBuffer, encodedDataSize);
|
||||
OpenRCT2::MemoryStream ms(encodedDataBuffer, encodedDataSize);
|
||||
SawyerChunkReader reader(&ms);
|
||||
auto chunk = reader.ReadChunk();
|
||||
ASSERT_EQ(static_cast<uint8_t>(chunk->GetEncoding()), chdr_in.encoding);
|
||||
@@ -51,7 +51,7 @@ protected:
|
||||
auto chdr_in = reinterpret_cast<const sawyercoding_chunk_header*>(data);
|
||||
ASSERT_EQ(chdr_in->length, expectedLength);
|
||||
|
||||
MemoryStream ms(data, size);
|
||||
OpenRCT2::MemoryStream ms(data, size);
|
||||
SawyerChunkReader reader(&ms);
|
||||
auto chunk = reader.ReadChunk();
|
||||
ASSERT_EQ(static_cast<uint8_t>(chunk->GetEncoding()), chdr_in->encoding);
|
||||
|
||||
Reference in new issue
Block a user