Doesnt

habitatporter.py

May 12th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. from operator import itemgetter
  2. import struct
  3.  
  4. def portHabitats(rom, pokemon, text) :
  5. freespace = 0xF001A0
  6.  
  7. i = 0
  8. category = 0
  9. while i < len(text) :
  10. line = text[i].split(',')
  11. numpages = int(line[1])
  12. print(numpages)
  13. page = 0
  14. categoryaddr = freespace
  15. freespace += (0x8 * numpages)
  16.  
  17. rom.seek(0x452C4C + (category * 0x8), 0)
  18. rom.write((0x8000000 + categoryaddr).to_bytes(4, 'little'))
  19. rom.write(numpages.to_bytes(4, 'little'))
  20.  
  21. while page < numpages :
  22. page += 1
  23. i += 1
  24. line = text[i].split(',')
  25. numpokes = 0
  26.  
  27. rom.seek(freespace, 0)
  28. j = 0
  29. while j < len(line) :
  30. if line[j] != '' :
  31. rom.write(pokemon.index(line[j]).to_bytes(2, 'little'))
  32. numpokes += 1
  33. j += 1
  34.  
  35. rom.seek(categoryaddr, 0)
  36. rom.write((0x8000000 + freespace).to_bytes(4, 'little'))
  37. rom.write(numpokes.to_bytes(4, 'little'))
  38. categoryaddr += 0x8
  39. freespace += 0x8
  40. i += 1
  41. category += 1
  42.  
  43.  
  44. romname = "yafrh.gba"
  45.  
  46. pokemon = []
  47. moves = []
  48. csv = []
  49.  
  50. with open("pokemon.txt", 'r') as f :
  51. s = f.read()
  52.  
  53. badpokemon = s.split("\n")
  54. for p in badpokemon :
  55. pokemon += [p.strip()]
  56.  
  57.  
  58. with open("Yafrh Data - Habitats.csv", 'r') as file :
  59. csv = file.read()
  60.  
  61. csv = csv.split('\n')
  62.  
  63. with open(romname, 'r+b') as file :
  64. portHabitats(file, pokemon, csv)
Add Comment
Please, Sign In to add comment