Skip to content

Commit

Permalink
Update parser.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Captian-obvious authored Dec 5, 2023
1 parent 76cd59a commit 8ee8fce
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,37 @@ def createTable(length,val):
##end
return arr
##end
def Chunk(buffer, chunkIndex):
chunk={}
chunk['InternalID']=chunkIndex
chunk['Header']=buffer.read(4)
if (chunk['Header'] not in VALID_CHUNK_IDENTIFIERS):
raise ValueError(f"Invalid chunk identifier {chunk['Header']} on chunk id {chunkIndex}")
##endif
data=None
lz4Header=buffer.read(16, False)
compressed=int.from_bytes(lz4Header[:4], 'little')
decompressed=int.from_bytes(lz4Header[4:8], 'little')
reserved=lz4Header[8:12]
zstd_check=lz4Header[12:16]
if (reserved!=b'\x00\x00\x00\x00'):
raise ValueError(f"Invalid chunk header on chunk id {chunkIndex} of identifier {chunk['Header']}")
##endif
if (compressed == 0):
data = buffer.read(decompressed)
else:
if (zstd_check==ZSTD_HEADER):
raise ValueError(f"Chunk id {chunkIndex} of identifier {chunk['Header']} is a ZSTD compressed chunk and cannot be decompressed")
##endif
data = LZ4.decompress(buffer.read(compressed + 12))
##endif
chunk['Data']=Buffer.new(data, False)
def error(self, msg):
raise ValueError(f"[{self['Header']}:{self['InternalID']}]: {msg}")
##end
chunk['Error']=error
return chunk
##end
def procChunkType(chunkStore,id,rbxm):
chunks=chunkStore[id]
f=CHUNK_MODULES[id]
Expand Down

0 comments on commit 8ee8fce

Please sign in to comment.