Advertisement
Doesnt

trainerporter.py

May 12th, 2016
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. from operator import itemgetter
  2. import struct
  3.  
  4. def portTrainers(rom, moves, pokemon, csv) :
  5. index = 0
  6. freespace = 0xC60000
  7. while index < len(csv) :
  8. line = csv[index].split(',')
  9. print(line[0])
  10. tid = int(line[0], 16)
  11. ai = int(line[3])
  12. monscount = int(line[4])
  13.  
  14. trainerstruct = 0x23eac8 + (tid * 0x28)
  15. print(hex(trainerstruct))
  16.  
  17. rom.seek(trainerstruct, 0)
  18. rom.write(bytes([3])) #data type
  19. rom.seek(trainerstruct + 0x10, 0)
  20. rom.write(bytes([0, 0, 0, 0, 0, 0, 0, 0])) #clear items
  21. rom.seek(trainerstruct + 0x1C, 0)
  22. rom.write(bytes([ai])) #ai
  23. rom.seek(trainerstruct + 0x20, 0)
  24. rom.write(bytes([monscount])) #mon count
  25. rom.seek(trainerstruct + 0x24, 0)
  26. rom.write((freespace + 0x8000000).to_bytes(4, 'little')) #team
  27. print(hex(freespace))
  28.  
  29. monindex = 0
  30. while monindex < monscount :
  31. index += 1
  32. line = csv[index].split(',')
  33. speciesname = line[0]
  34. print(speciesname)
  35. species = pokemon.index(speciesname)
  36. level = int(line[1])
  37. item = 0 #TODO: implement this
  38. movea = moves.index(line[3])
  39. moveb = moves.index(line[4])
  40. movec = moves.index(line[5])
  41. moved = moves.index(line[6])
  42. ivs = int(line[7])
  43. rom.seek(freespace, 0)
  44. rom.write(ivs.to_bytes(2, 'little'))
  45. rom.write(level.to_bytes(2, 'little'))
  46. rom.write(species.to_bytes(2, 'little'))
  47. rom.write((item).to_bytes(2, 'little'))
  48. rom.write(movea.to_bytes(2, 'little'))
  49. rom.write(moveb.to_bytes(2, 'little'))
  50. rom.write(movec.to_bytes(2, 'little'))
  51. rom.write(moved.to_bytes(2, 'little'))
  52.  
  53.  
  54. freespace += 0x10
  55. monindex +=1
  56. index += 1
  57. print(" ")
  58.  
  59. def portEVs(rom, spreads) :
  60. natures = ["Arbitrary", "Lonely", "Brave", "Adamant", \
  61. "Naughty", "Bold", "Docile", "Relaxed", "Impish", \
  62. "Lax", "Timid", "Hasty", "Serious", "Jolly", \
  63. "Naive", "Modest", "Mild", "Quiet", "Bashful", \
  64. "Rash", "Calm", "Gentle", "Sassy", "Careful"]
  65. rom.seek(0xF90100)
  66. index = 0
  67. while index < len(spreads) :
  68. line = spreads[index].split(',')
  69. snature = line[2]
  70. nature = natures.index(snature)
  71.  
  72. ivs = int(line[3])
  73. hp = int(line[4])
  74. patk = int(line[5])
  75. pdef = int(line[6])
  76. satk = int(line[7])
  77. sdef = int(line[8])
  78. speed = int(line[9])
  79. abil = int(line[10])
  80. ball = int(line[11])
  81.  
  82. rom.write(bytes([nature]))
  83. rom.write(bytes([0, 0, 0]))
  84. rom.write(bytes([ivs, hp, patk, pdef, speed, satk, sdef, ball]))
  85. rom.write(bytes([abil, 0, 0, 0]))
  86. index += 1
  87.  
  88.  
  89. romname = "yafrh.gba"
  90.  
  91. pokemon = []
  92. moves = []
  93. csv = []
  94.  
  95. with open("pokemon.txt", 'r') as f :
  96. s = f.read()
  97.  
  98. badpokemon = s.split("\n")
  99. for p in badpokemon :
  100. pokemon += [p.strip()]
  101.  
  102.  
  103. with open("moves.txt", 'r') as f :
  104. s = f.read()
  105. moves = s.split("\n")
  106.  
  107.  
  108.  
  109. with open("Yafrh Data - Trainers.csv", 'r') as file :
  110. csv = file.read()
  111. csv = csv.split('\n')
  112. with open(romname, 'r+b') as file :
  113. portTrainers(file, moves, pokemon, csv)
  114.  
  115. with open("Yafrh Data - EV Spreads.csv", 'r') as file :
  116. csv = file.read()
  117. csv = csv.split('\n')
  118. with open(romname, 'r+b') as file :
  119. portEVs(file, csv)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement