From b691c43c44ff180d10e7d4a9afc83b98551ff586 Mon Sep 17 00:00:00 2001 From: daoge_cmd <3523206925@qq.com> Date: Sun, 1 Mar 2026 12:16:08 +0800 Subject: Initial commit --- Minecraft.World/ZoneIo.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Minecraft.World/ZoneIo.cpp (limited to 'Minecraft.World/ZoneIo.cpp') diff --git a/Minecraft.World/ZoneIo.cpp b/Minecraft.World/ZoneIo.cpp new file mode 100644 index 00000000..f1838c86 --- /dev/null +++ b/Minecraft.World/ZoneIo.cpp @@ -0,0 +1,48 @@ +#include "stdafx.h" +#include "ByteBuffer.h" +#include "ZoneIo.h" + +ZoneIo::ZoneIo(HANDLE channel, __int64 pos) +{ + this->channel = channel; + this->pos = pos; +} + +void ZoneIo::write(byteArray bb, int size) +{ + ByteBuffer *buff = ByteBuffer::wrap(bb); +// if (bb.length != size) throw new IllegalArgumentException("Expected " + size + " bytes, got " + bb.length); // 4J - TODO + buff->order(ZonedChunkStorage::BYTEORDER); + buff->position(bb.length); + buff->flip(); + write(buff, size); + delete buff; +} + +void ZoneIo::write(ByteBuffer *bb, int size) +{ + DWORD numberOfBytesWritten; + SetFilePointer(channel,(int)pos,NULL,NULL); + WriteFile(channel,bb->getBuffer(), bb->getSize(),&numberOfBytesWritten,NULL); + pos += size; +} + +ByteBuffer *ZoneIo::read(int size) +{ + DWORD numberOfBytesRead; + byteArray bb = byteArray(size); + SetFilePointer(channel,(int)pos,NULL,NULL); + ByteBuffer *buff = ByteBuffer::wrap(bb); + // 4J - to investigate - why is this buffer flipped before anything goes in it? + buff->order(ZonedChunkStorage::BYTEORDER); + buff->position(size); + buff->flip(); + ReadFile(channel, buff->getBuffer(), buff->getSize(), &numberOfBytesRead, NULL); + pos += size; + return buff; +} + +void ZoneIo::flush() +{ + // 4J - was channel.force(false); +} \ No newline at end of file -- cgit v1.2.3