Advertisement
Doesnt

badnikmovepoolporter.py

May 12th, 2016
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. from operator import itemgetter
  2. import struct
  3.  
  4. def loadMovepools(csv, movepools) :
  5. emptymons = ["","","","","",""]
  6. mons = ["","","","","",""]
  7. for line in csv :
  8. text = line.split(',')
  9. if mons == emptymons :
  10. print(line)
  11. mons[0] = text[1]
  12. mons[1] = text[2]
  13. mons[2] = text[3]
  14. mons[3] = text[4]
  15. mons[4] = text[5]
  16. mons[5] = text[6]
  17. movepools[mons[0]] = []
  18. movepools[mons[1]] = []
  19. movepools[mons[2]] = []
  20. movepools[mons[3]] = []
  21. movepools[mons[4]] = []
  22. movepools[mons[5]] = []
  23. elif text[0] == "Evolution" :
  24. continue
  25. elif text[0] == "" :
  26. mons = ["","","","","",""]
  27. else :
  28. move = text[0]
  29. for i in range(0,6) :
  30. if mons[i] != '' and text[i+1] != '':
  31. movepools[mons[i]] += (text[i+1], text[0])
  32.  
  33. def insertMovepools(rom, pokemon, moves, movepools) :
  34. freespace = 0xC80000
  35. movepooltable = 0x25D7B4
  36. for i in range(0, len(pokemon)) :
  37. if not (pokemon[i] in movepools) :
  38. continue
  39. else :
  40. print(pokemon[i])
  41. index = 0
  42. offset = freespace
  43.  
  44. rom.seek(movepooltable + (4 * i))
  45. rom.write((0x8000000 + freespace).to_bytes(4, 'little'))
  46.  
  47. while index < len(movepools[pokemon[i]]) :
  48. level = movepools[pokemon[i]][index]
  49. move = movepools[pokemon[i]][index+1]
  50. moveno = moves.index(move)
  51. data = (int(level) << 9) + moveno
  52. rom.seek(freespace)
  53. rom.write(data.to_bytes(2, 'little'))
  54. print(data)
  55.  
  56. freespace += 2
  57. index += 2
  58. rom.write((0xFFFF).to_bytes(2, 'little'))
  59. freespace += 2
  60. rom.seek(freespace)
  61. rom.write((0x7777).to_bytes(2, 'little'))
  62.  
  63.  
  64.  
  65. romname = "badnik.gba"
  66.  
  67. pokemon = []
  68. moves = []
  69. csv = []
  70. movepools = dict()
  71.  
  72. with open("pokemon.txt", 'r') as f :
  73. s = f.read()
  74.  
  75. badpokemon = s.split("\n")
  76. for p in badpokemon :
  77. pokemon += [p.strip()]
  78.  
  79.  
  80. with open("moves.txt", 'r') as f :
  81. s = f.read()
  82. moves = s.split("\n")
  83.  
  84.  
  85. with open("badnik template - Sheet1.csv", 'r') as file :
  86. csv = file.read()
  87.  
  88. csv = csv.split('\n')
  89.  
  90. loadMovepools(csv, movepools)
  91. print(movepools)
  92.  
  93. with open(romname, 'r+b') as file :
  94. insertMovepools(file, pokemon, moves, movepools)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement