Skip to content

Instantly share code, notes, and snippets.

@RGamberini
Created November 28, 2020 03:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RGamberini/e4892bfb215d2d9b33f6e9f13f903313 to your computer and use it in GitHub Desktop.
Save RGamberini/e4892bfb215d2d9b33f6e9f13f903313 to your computer and use it in GitHub Desktop.
import zlib
class BoundBuffer(object):
buff = b''
cursor = 0
def __init__(self, data=b""):
self.write(data)
def read(self, length):
if length > len(self):
print("things are bad!")
return None
out = self.buff[self.cursor:self.cursor + length]
self.cursor += length
return out
def write(self, data):
self.buff += data
def sub_buffer(self, pos):
return BoundBuffer(self.buff[pos:])
def __len__(self):
return len(self.buff) - self.cursor
def readChunk(buffer, i):
# print(f"Loading chunk {i}...")
chunk_length = int.from_bytes(buffer.read(4), byteorder="big")
# print(f"Chunk {i} has a length of {chunk_length}")
buffer.read(1)
chunk = zlib.decompress(buffer.read(chunk_length))
# print(f"Checking chunk {i} for Crystalline Quartz")
if "cinderscapes:crystalline_quartz" in str(chunk):
with open(f"decompressed_{i}.dat", 'wb') as file_out:
file_out.write(chunk)
print("ABBA QUARTZ FOUND")
with open('C:\\Modded Minecraft\\backup\\world\\DIM-1\\region\\r.0.0.mca', 'rb') as f:
region = BoundBuffer(f.read())
for i in range(1024):
offset = int.from_bytes(region.read(3), byteorder="big")
print(f"Found offset for chunk {i}: {offset}")
offset = offset * 4096
readChunk(region.sub_buffer(offset), i)
region.read(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment