Advertisement
CasualPokePlayer

bk2_to_dem.py

May 5th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. import sys
  3. import os
  4. import zipfile
  5.  
  6. BTN_A = 0x01
  7. BTN_B = 0x02
  8. BTN_SELECT = 0x04
  9. BTN_START = 0x08
  10. BTN_RIGHT = 0x10
  11. BTN_LEFT = 0x20
  12. BTN_UP = 0x40
  13. BTN_DOWN = 0x80
  14. BTN_POWER = 0xFF
  15.  
  16. MAPPING = (
  17. BTN_UP,
  18. BTN_DOWN,
  19. BTN_LEFT,
  20. BTN_RIGHT,
  21. BTN_START,
  22. BTN_SELECT,
  23. BTN_B,
  24. BTN_A,
  25. BTN_POWER,
  26. )
  27.  
  28. def decode_input(line):
  29. bits = 0
  30. for c, bit in zip(line, MAPPING):
  31. if c != ".":
  32. bits |= bit
  33. return bits
  34. bk2 = zipfile.ZipFile(os.path.abspath(sys.argv[1]))
  35. lines = [line.decode() for line in bk2.open('Input Log.txt')]
  36. data = [
  37. decode_input(line[1:-1])
  38. for line in lines
  39. if line.startswith("|")
  40. ]
  41. with open("bgb.dem", "wb") as f:
  42. f.write(bytes(data))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement