Files
MinecraftConsoles/Minecraft.World/ZoneIo.cpp
ModMaker101 a9be52c41a Project modernization (#630)
* Fixed boats falling and a TP glitch #266

* Replaced every C-style cast with C++ ones

* Replaced every C-style cast with C++ ones

* Fixed boats falling and a TP glitch #266

* Updated NULL to nullptr and fixing some type issues

* Modernized and fixed a few bugs

- Replaced most instances of `NULL` with `nullptr`.
- Replaced most `shared_ptr(new ...)` with `make_shared`.
- Removed the `nullptr` macro as it was interfering with the actual nullptr keyword in some instances.

* Fixing more conflicts

* Replace int loops with size_t and start work on overrides
2026-03-08 09:56:03 +07:00

48 lines
1.3 KiB
C++

#include "stdafx.h"
#include "ByteBuffer.h"
#include "ZoneIo.h"
ZoneIo::ZoneIo(HANDLE channel, int64_t 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,static_cast<int>(pos),nullptr,nullptr);
WriteFile(channel,bb->getBuffer(), bb->getSize(),&numberOfBytesWritten,nullptr);
pos += size;
}
ByteBuffer *ZoneIo::read(int size)
{
DWORD numberOfBytesRead;
byteArray bb = byteArray(size);
SetFilePointer(channel,static_cast<int>(pos),nullptr,nullptr);
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, nullptr);
pos += size;
return buff;
}
void ZoneIo::flush()
{
// 4J - was channel.force(false);
}