Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from operator import itemgetter
- import struct
- def portTrainers(rom, moves, pokemon, csv) :
- index = 0
- freespace = 0xC60000
- while index < len(csv) :
- line = csv[index].split(',')
- print(line[0])
- tid = int(line[0], 16)
- ai = int(line[3])
- monscount = int(line[4])
- trainerstruct = 0x23eac8 + (tid * 0x28)
- print(hex(trainerstruct))
- rom.seek(trainerstruct, 0)
- rom.write(bytes([3])) #data type
- rom.seek(trainerstruct + 0x10, 0)
- rom.write(bytes([0, 0, 0, 0, 0, 0, 0, 0])) #clear items
- rom.seek(trainerstruct + 0x1C, 0)
- rom.write(bytes([ai])) #ai
- rom.seek(trainerstruct + 0x20, 0)
- rom.write(bytes([monscount])) #mon count
- rom.seek(trainerstruct + 0x24, 0)
- rom.write((freespace + 0x8000000).to_bytes(4, 'little')) #team
- print(hex(freespace))
- monindex = 0
- while monindex < monscount :
- index += 1
- line = csv[index].split(',')
- speciesname = line[0]
- print(speciesname)
- species = pokemon.index(speciesname)
- level = int(line[1])
- item = 0 #TODO: implement this
- movea = moves.index(line[3])
- moveb = moves.index(line[4])
- movec = moves.index(line[5])
- moved = moves.index(line[6])
- ivs = int(line[7])
- rom.seek(freespace, 0)
- rom.write(ivs.to_bytes(2, 'little'))
- rom.write(level.to_bytes(2, 'little'))
- rom.write(species.to_bytes(2, 'little'))
- rom.write((item).to_bytes(2, 'little'))
- rom.write(movea.to_bytes(2, 'little'))
- rom.write(moveb.to_bytes(2, 'little'))
- rom.write(movec.to_bytes(2, 'little'))
- rom.write(moved.to_bytes(2, 'little'))
- freespace += 0x10
- monindex +=1
- index += 1
- print(" ")
- def portEVs(rom, spreads) :
- natures = ["Arbitrary", "Lonely", "Brave", "Adamant", \
- "Naughty", "Bold", "Docile", "Relaxed", "Impish", \
- "Lax", "Timid", "Hasty", "Serious", "Jolly", \
- "Naive", "Modest", "Mild", "Quiet", "Bashful", \
- "Rash", "Calm", "Gentle", "Sassy", "Careful"]
- rom.seek(0xF90100)
- index = 0
- while index < len(spreads) :
- line = spreads[index].split(',')
- snature = line[2]
- nature = natures.index(snature)
- ivs = int(line[3])
- hp = int(line[4])
- patk = int(line[5])
- pdef = int(line[6])
- satk = int(line[7])
- sdef = int(line[8])
- speed = int(line[9])
- abil = int(line[10])
- ball = int(line[11])
- rom.write(bytes([nature]))
- rom.write(bytes([0, 0, 0]))
- rom.write(bytes([ivs, hp, patk, pdef, speed, satk, sdef, ball]))
- rom.write(bytes([abil, 0, 0, 0]))
- index += 1
- romname = "yafrh.gba"
- pokemon = []
- moves = []
- csv = []
- with open("pokemon.txt", 'r') as f :
- s = f.read()
- badpokemon = s.split("\n")
- for p in badpokemon :
- pokemon += [p.strip()]
- with open("moves.txt", 'r') as f :
- s = f.read()
- moves = s.split("\n")
- with open("Yafrh Data - Trainers.csv", 'r') as file :
- csv = file.read()
- csv = csv.split('\n')
- with open(romname, 'r+b') as file :
- portTrainers(file, moves, pokemon, csv)
- with open("Yafrh Data - EV Spreads.csv", 'r') as file :
- csv = file.read()
- csv = csv.split('\n')
- with open(romname, 'r+b') as file :
- portEVs(file, csv)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement