the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 97 lines 2.3 kB view raw
1#pragma once 2#include "compression.h" 3#include "InputOutputStream.h" 4using namespace std; 5 6class FileEntry; 7class ConsoleSaveFile; 8 9class RegionFile 10{ 11// 4J Stu TEMP FOR TESTING 12private: 13 FileEntry *fileEntry; 14 15private: 16 static const int VERSION_GZIP = 1; 17 static const int VERSION_DEFLATE = 2; 18 static const int VERSION_XBOX = 3; 19 20 static const int SECTOR_BYTES = 4096; 21 static const int SECTOR_INTS = SECTOR_BYTES / 4; 22 23 static const int CHUNK_HEADER_SIZE = 8; 24 static byteArray emptySector; 25 26 File *fileName; 27 //HANDLE file; 28 ConsoleSaveFile *m_saveFile; 29 30 int *offsets; 31 int *chunkTimestamps; 32 vector<bool> *sectorFree; 33 int sizeDelta; 34 __int64 _lastModified; 35 bool m_bIsEmpty; // 4J added 36 37public: 38 RegionFile(ConsoleSaveFile *saveFile, File *path); 39 ~RegionFile(); 40 41 /* the modification date of the region file when it was first opened */ 42 __int64 lastModified(); 43 44 /* gets how much the region file has grown since it was last checked */ 45 int getSizeDelta(); 46 47 /* 48 * gets an (uncompressed) stream representing the chunk data returns null if 49 * the chunk is not found or an error occurs 50 */ 51 DataInputStream *getChunkDataInputStream(int x, int z); 52 DataOutputStream *getChunkDataOutputStream(int x, int z); 53 54 class ChunkBuffer : public ByteArrayOutputStream 55 { 56 private: 57 RegionFile *rf; 58 int x, z; 59 public: 60 ChunkBuffer( RegionFile *rf, int x, int z ) : ByteArrayOutputStream(8096) 61 { 62 this->rf = rf; 63 this->x = x; 64 this->z = z; 65 } 66 void close() 67 { 68 rf->write(x,z,buf.data,count); 69 } 70 }; 71 72 /* write a chunk at (x,z) with length bytes of data to disk */ 73protected: 74 void write(int x, int z, byte *data, int length); 75 76 /* write a chunk data to the region file at specified sector number */ 77private: 78 void write(int sectorNumber, byte *data, int length, unsigned int compLength); 79 void zero(int sectorNumber, int length); // 4J added 80 81 /* is this an invalid chunk coordinate? */ 82 bool outOfBounds(int x, int z); 83 84 int getOffset(int x, int z); 85 86public: 87 bool hasChunk(int x, int z); 88 89private: 90 void insertInitialSectors(); // 4J added 91 void setOffset(int x, int z, int offset); 92 void setTimestamp(int x, int z, int value); 93 94public: 95 void writeAllOffsets(); 96 void close(); 97};