mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
* All libraries have been isolated from each other, and build into separate artifacts. * Project has been restructured to support isolating libraries. * CCrashHandler now calls a callback on crash (setup from core/dllmain.cpp, this can be setup in any way for any project. This callback is getting called when the apllication crashes. Useful for flushing buffers before closing handles to logging files for example). * Tier0 'CoreMsgV' function now calls a callback sink, which could be set by the user (currently setup to the SDK's internal logger in core/dllmain.cpp). TODO: * Add a batch file to autogenerate all projects. * Add support for dedicated server. * Add support for client dll. Bugs: * Game crashes on the title screen after the UI script compiler has finished (root cause unknown). * Curl error messages are getting logged twice for the dedicated server due to the removal of all "DEDICATED" preprocessor directives to support isolating projects. This has to be fixed properly!
102 lines
2.6 KiB
C++
102 lines
2.6 KiB
C++
#pragma once
|
|
|
|
class CIOStream
|
|
{
|
|
public:
|
|
enum Mode_t
|
|
{
|
|
NONE = 0,
|
|
READ = std::ios::in,
|
|
WRITE = std::ios::out,
|
|
BINARY = std::ios::binary,
|
|
};
|
|
|
|
CIOStream();
|
|
CIOStream(const fs::path& fsFileFullPath, int nFlags);
|
|
~CIOStream();
|
|
|
|
bool Open(const fs::path& fsFileFullPath, int nFlags);
|
|
void Close();
|
|
void Flush();
|
|
|
|
void ComputeFileSize();
|
|
|
|
std::streampos GetPosition(Mode_t mode);
|
|
void SetPosition(std::streampos nOffset, Mode_t mode);
|
|
|
|
const std::filebuf* GetData() const;
|
|
const std::streampos GetSize() const;
|
|
|
|
bool IsReadable();
|
|
bool IsWritable() const;
|
|
|
|
bool IsEof() const;
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose: reads any value from the file
|
|
//-----------------------------------------------------------------------------
|
|
template<typename T>
|
|
void Read(T& tValue)
|
|
{
|
|
if (IsReadable())
|
|
m_Stream.read(reinterpret_cast<char*>(&tValue), sizeof(tValue));
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose: reads any value from the file with specified size
|
|
//-----------------------------------------------------------------------------
|
|
template<typename T>
|
|
void Read(T& tValue, size_t nSize)
|
|
{
|
|
if (IsReadable())
|
|
m_Stream.read(reinterpret_cast<char*>(&tValue), nSize);
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose: reads any value from the file and returns it
|
|
//-----------------------------------------------------------------------------
|
|
template<typename T>
|
|
T Read()
|
|
{
|
|
T value{};
|
|
if (!IsReadable())
|
|
return value;
|
|
|
|
m_Stream.read(reinterpret_cast<char*>(&value), sizeof(value));
|
|
return value;
|
|
}
|
|
bool ReadString(string& svOut);
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose: writes any value to the file
|
|
//-----------------------------------------------------------------------------
|
|
template<typename T>
|
|
void Write(T tValue)
|
|
{
|
|
if (!IsWritable())
|
|
return;
|
|
|
|
m_Stream.write(reinterpret_cast<const char*>(&tValue), sizeof(tValue));
|
|
m_nSize += sizeof(tValue);
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose: writes any value to the file with specified size
|
|
//-----------------------------------------------------------------------------
|
|
template<typename T>
|
|
void Write(T tValue, size_t nSize)
|
|
{
|
|
if (!IsWritable())
|
|
return;
|
|
|
|
m_Stream.write(reinterpret_cast<const char*>(tValue), nSize);
|
|
m_nSize += nSize;
|
|
}
|
|
bool WriteString(const string& svInput);
|
|
|
|
private:
|
|
std::streampos m_nSize; // File size.
|
|
int m_nFlags; // Stream flags.
|
|
fstream m_Stream; // I/O stream.
|
|
};
|