LiteLoaderBDS-1.16.40/LiteLoader/Kernel/Network/ReadOnlyBinaryStreamAPI.cpp
2022-09-25 01:17:11 +08:00

46 lines
1.3 KiB
C++

#include <MC/ReadOnlyBinaryStream.hpp>
#include <MC/CompoundTag.hpp>
#include <MC/NbtIo.hpp>
std::string const& ReadOnlyBinaryStream::getData() const {
return *pBuf;
}
size_t ReadOnlyBinaryStream::getLength() const {
return pBuf->size();
}
size_t ReadOnlyBinaryStream::getReadPointer() const {
return readPointer;
}
size_t ReadOnlyBinaryStream::getUnreadLength() const {
return getLength() - getReadPointer();
}
void ReadOnlyBinaryStream::setReadPointer(std::size_t size) {
auto len = getLength();
if (size <= len)
readPointer = size;
else
readPointer = len;
}
struct IDataInput{
void* pVT;
ReadOnlyBinaryStream* pReadOnlyBinaryStream;
};
std::unique_ptr<class CompoundTag> ReadOnlyBinaryStream::getCompoundTag() {
// auto tag = CompoundTag::create();
// class CompoundTag& (*rv)(class CompoundTag&, class ReadOnlyBinaryStream&);
// *((void**)&rv) = dlsym("?read@?$serialize@VCompoundTag@@@@SA?AVCompoundTag@@AEAVReadOnlyBinaryStream@@@Z");
// (*rv)(*tag, *this);
IDataInput pVTVarIntDataInput;
pVTVarIntDataInput.pVT = dlsym("??_7VarIntDataInput@@6B@");
pVTVarIntDataInput.pReadOnlyBinaryStream = this;
return std::move(NbtIo::read(pVTVarIntDataInput));
}
// static_assert(offsetof(ReadOnlyBinaryStream, pBuf) == 56);