# Script to patch Pokemon GSC to replace Red's team with Twitch's team.

# By default, it uses the same levels as Red's pokemon, but you can change

# it to use Twtich's levels instead. Also, the Docs claim Lapras's second move

# is Body Slam, not Mist, so you can change that too if you wish.

# Requires Python 2.6+

import sys

if len ( sys . argv ) < 2 or not sys . argv [ 1 ] . endswith ( '.gbc' ) :

print 'Please enter the rom name on the command line. Example:'

print 'python patch.py PokeSilver.gsc'

sys . exit ( )

fname = sys . argv [ 1 ]

with open ( fname , 'rb' ) as f:

data = f. read ( )

offset = data. find ( ' \x 51 \x 19 \x cc \x 62 \x 55 \x 57 \x 49 \x c4 \x bd' , 0x39900 )

if offset <= 0x39900 :

print "Error: could not locate Red's data in the rom. Are you sure you have the right rom?"

sys . exit ( )

redlevels = [ 73 , 75 , 77 , 77 , 77 , 81 ]

twitchlevels = [ 31 , 39 , 52 , 54 , 69 , 81 ]

levels = redlevels

mist = ' \x 46'

bodyslam = ' \x 22'

lapras2nd = mist

newdata = '' . join ( [

'{0[0]} \x 83 \x 6d{1} \x 39 \x 46' ,

'{0[1]} \x 31 \x 32 \x 4d \x 8d \x 4e' ,

'{0[2]} \x 8b \x 38 \x 6e \x 39 \x 1e' ,

'{0[3]} \x 22 \x 39 \x 28 \x 46 \x 1f' ,

'{0[4]} \x 12 \x 77 \x 1c \x 62 \x 8f' ,

'{0[5]} \x 91 \x 54 \x 41 \x 24 \x 57'

] ) . format ( map ( chr , levels ) , lapras2nd )

data = data. replace ( data [ offset:offset+ len ( newdata ) ] , newdata )

with open ( fname , 'wb' ) as f: