the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 48 lines 1.3 kB view raw
1#include "stdafx.h" 2#include "ByteBuffer.h" 3#include "ZoneIo.h" 4 5ZoneIo::ZoneIo(HANDLE channel, __int64 pos) 6{ 7 this->channel = channel; 8 this->pos = pos; 9} 10 11void ZoneIo::write(byteArray bb, int size) 12{ 13 ByteBuffer *buff = ByteBuffer::wrap(bb); 14// if (bb.length != size) throw new IllegalArgumentException("Expected " + size + " bytes, got " + bb.length); // 4J - TODO 15 buff->order(ZonedChunkStorage::BYTEORDER); 16 buff->position(bb.length); 17 buff->flip(); 18 write(buff, size); 19 delete buff; 20} 21 22void ZoneIo::write(ByteBuffer *bb, int size) 23{ 24 DWORD numberOfBytesWritten; 25 SetFilePointer(channel,(int)pos,NULL,NULL); 26 WriteFile(channel,bb->getBuffer(), bb->getSize(),&numberOfBytesWritten,NULL); 27 pos += size; 28} 29 30ByteBuffer *ZoneIo::read(int size) 31{ 32 DWORD numberOfBytesRead; 33 byteArray bb = byteArray(size); 34 SetFilePointer(channel,(int)pos,NULL,NULL); 35 ByteBuffer *buff = ByteBuffer::wrap(bb); 36 // 4J - to investigate - why is this buffer flipped before anything goes in it? 37 buff->order(ZonedChunkStorage::BYTEORDER); 38 buff->position(size); 39 buff->flip(); 40 ReadFile(channel, buff->getBuffer(), buff->getSize(), &numberOfBytesRead, NULL); 41 pos += size; 42 return buff; 43} 44 45void ZoneIo::flush() 46{ 47 // 4J - was channel.force(false); 48}