Advertisement
Zoinkity

Vigilante8.py

Apr 16th, 2016
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. #-------------------------------------------------------------------------------
  4. # Decompression routine for Vigilante 8.
  5.  
  6. def dec(data):
  7.      out = bytearray()
  8.      ring = bytearray(0x800)
  9.      src = iter(data[8:])
  10.      sz = int.from_bytes(data[4:8], 'little')
  11.      rp = 0
  12.      c = next(src) | 0x100
  13.      while len(out) < sz:
  14.          if c > 0xFFFF:
  15.              c = next(src) | 0x100
  16.          if c & 0x80:
  17.              out.append(next(src))
  18.              ring[rp] = out[-1]
  19.              rp += 1
  20.              rp &= 0x7FF
  21.          else:
  22.              p = next(src)
  23.              p |= next(src) << 8
  24.              l = (p & 0x1F) + 2
  25.              p >>= 5
  26.              for i in range(p, p+l):
  27.                  out.append(ring[i & 0x7FF])
  28.                  ring[rp] = out[-1]
  29.                  rp += 1
  30.                  rp &= 0x7FF
  31.          c <<= 1
  32.      return bytes(out)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement