mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-16 01:37:03 +00:00
CVarManager: Bring back de/serialization
This commit is contained in:
@@ -17,6 +17,7 @@ void CMemoryStreamOut::Write(const u8* ptr, u32 len) {
|
||||
|
||||
if (len != 0) {
|
||||
memcpy(x7c_ptr + x84_position, ptr, len);
|
||||
x84_position += len;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,5 +21,6 @@ public:
|
||||
~CMemoryStreamOut() override;
|
||||
|
||||
void Write(const u8* ptr, u32 len) override;
|
||||
u32 GetWritePosition() const { return x84_position; }
|
||||
};
|
||||
} // namespace metaforce
|
||||
24
Runtime/Streams/CTextInStream.cpp
Normal file
24
Runtime/Streams/CTextInStream.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include "Runtime/Streams/CTextInStream.hpp"
|
||||
#include <algorithm>
|
||||
|
||||
namespace metaforce {
|
||||
CTextInStream::CTextInStream(CInputStream& in, int len) : m_in(&in), m_len(len) {}
|
||||
|
||||
std::string CTextInStream::GetNextLine() {
|
||||
std::string ret;
|
||||
while (true) {
|
||||
auto chr = m_in->ReadChar();
|
||||
ret += chr;
|
||||
if (ret.back() == '\r' || ret.back() == '\n') {
|
||||
if (ret.back() == '\r') {
|
||||
m_in->ReadChar();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ret.erase(std::remove(ret.begin(), ret.end(), '\r'), ret.end());
|
||||
ret.erase(std::remove(ret.begin(), ret.end(), '\n'), ret.end());
|
||||
return ret;
|
||||
}
|
||||
} // namespace metaforce
|
||||
14
Runtime/Streams/CTextInStream.hpp
Normal file
14
Runtime/Streams/CTextInStream.hpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
#include "Runtime/Streams/CInputStream.hpp"
|
||||
|
||||
namespace metaforce {
|
||||
class CTextInStream {
|
||||
CInputStream* m_in;
|
||||
s32 m_len;
|
||||
public:
|
||||
CTextInStream(CInputStream& in, int len);
|
||||
|
||||
bool IsEOF() { return m_in->GetReadPosition() >= m_len; }
|
||||
std::string GetNextLine();
|
||||
};
|
||||
}
|
||||
29
Runtime/Streams/CTextOutStream.cpp
Normal file
29
Runtime/Streams/CTextOutStream.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include "Runtime/Streams/CTextOutStream.hpp"
|
||||
|
||||
namespace metaforce {
|
||||
CTextOutStream::CTextOutStream(COutputStream& out) : m_out(&out) {}
|
||||
|
||||
void CTextOutStream::WriteString(const std::string& str) { CTextOutStream::WriteString(str.c_str(), str.length()); }
|
||||
void CTextOutStream::WriteString(const char* str, u32 len) {
|
||||
bool wroteCarriageReturn = false;
|
||||
bool wroteLineFeed = false;
|
||||
for (u32 i = 0; i < len; ++i) {
|
||||
if (str[i] == '\r') {
|
||||
wroteCarriageReturn = true;
|
||||
} else if (str[i] == '\n' && !wroteCarriageReturn) {
|
||||
m_out->WriteChar('\r');
|
||||
wroteLineFeed = true;
|
||||
}
|
||||
m_out->WriteChar(str[i]);
|
||||
}
|
||||
|
||||
/* If we didn't write either a line feed or carriage return we need to do that now */
|
||||
if (!wroteCarriageReturn && !wroteLineFeed) {
|
||||
m_out->WriteChar('\r');
|
||||
m_out->WriteChar('\n');
|
||||
}
|
||||
|
||||
/* Since this is a text buffer, we always want to flush after writing a string */
|
||||
m_out->Flush();
|
||||
}
|
||||
} // namespace metaforce
|
||||
14
Runtime/Streams/CTextOutStream.hpp
Normal file
14
Runtime/Streams/CTextOutStream.hpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
#include "Runtime/Streams/COutputStream.hpp"
|
||||
|
||||
namespace metaforce {
|
||||
class CTextOutStream {
|
||||
COutputStream* m_out;
|
||||
public:
|
||||
CTextOutStream(COutputStream& out);
|
||||
|
||||
void WriteString(const std::string& str);
|
||||
void WriteString(const char* str, u32 len);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user