def enemygenerator(): import random import charsheet import namegen namegen.namegen() enemyname = namegen.enemyname if charsheet.level == 1: enemylevel = random.randrange(1, 4) else: enemylevel = random.randrange(charsheet.level - 1, charsheet.level + 3) enemygold = random.randint(enemylevel * 3, enemylevel * 5) enemystr = random.randint(enemylevel * 3, enemylevel * 6) enemydex = random.randint(enemylevel * 3, enemylevel * 6) enemyint = random.randint(enemylevel * 3, enemylevel * 6) enemyhp = 100 + (random.randint(enemylevel * 2, enemylevel * 5)) enemymaxhp = enemyhp import currentenemy currentenemy.name = enemyname currentenemy.level = enemylevel currentenemy.gold = enemygold currentenemy.str = enemystr currentenemy.dex = enemydex currentenemy.int = enemyint currentenemy.hp = enemyhp currentenemy.maxhp = enemymaxhp
def getpkm(): token = 'c9KcX1Cry3QKS2Ai7yxL6QiQGeBGeQKR' sent = False print 'Ready to receive from NDS' while not sent: sock, req = getReq() a = req.action if len(req.getvars) == 1: sendResp(sock, token) elif a == 'info': sendResp(sock, '\x01\x00') print 'Connection Established.' elif a == 'setProfile': sendResp(sock, '\x00' * 8) elif a == 'result': sendResp(sock, '\x05\x00') elif a == 'delete': sendResp(sock, '\x01\x00') elif a == 'search': sendResp(sock, '') elif a == 'post': sendResp(sock, '\x0c\x00') print 'Receiving Pokemon...' data = req.getvars['data'] bytes = b64decode(data.replace('-', '+').replace('_', '/')) decrypt = makepkm(bytes) filename = namegen(decrypt[0x48:0x5e]) filename += '.pkm' save(filename, decrypt) statread(decrypt) sent = True
def getpkm(): token = 'c9KcX1Cry3QKS2Ai7yxL6QiQGeBGeQKR' sent = False print 'Ready to receive from NDS' while not sent: sock, req = getReq() a = req.action if len(req.getvars) == 1: sendResp(sock, token) elif a == 'info': sendResp(sock, '\x01\x00') print 'Connection Established.' elif a == 'setProfile': sendResp(sock, '\x00' * 8) elif a == 'result': sendResp(sock, '\x05\x00') elif a == 'delete': sendResp(sock, '\x01\x00') elif a == 'search': sendResp(sock, '') elif a == 'post': sendResp(sock, '\x0c\x00') print 'Receiving Pokemon...' data = req.getvars['data'] bytes = b64decode(data.replace('-', '+').replace('_', '/')) decrypt = makepkm(bytes) filename = namegen(decrypt[0x48:0x5e]) filename += '.pkm' save(filename, decrypt) statread(decrypt) sent = True
def statread(pkm): p = array('B') p.fromstring(pkm) pid = p[0x00] + (p[0x01] << 8) + (p[0x02] << 16) + (p[0x03] << 24) nickname = namegen(pkm[0x48:0x5e]) lv = p[0x8c] nat = nature.get(pid % 25) spec = species.get((p[0x09] << 8) + p[0x08]) abil = ability.get(p[0x15]) if p[0x40] & 4: gender = '(Genderless)' elif p[0x40] & 2: gender = '(Female)' else: gender = '(Male)' otname = namegen(pkm[0x68:0x78]) otid = (p[0x0d] << 8) + p[0x0c] secid = (p[0x0f] << 8) + p[0x0e] held = items.get((p[0x0b] << 8) + p[0x0a]) ivs = ivcheck(p[0x38:0x3c]) evs = evcheck(p[0x18:0x1e]) atk = attackcheck(p[0x28:0x30]) hidden = hiddenpower(ivs) happy = p[0x14] shiny = shinycheck(pid, otid, secid) if shiny: shiny = ' Shiny!' else: shiny = '' s = '%s:%s\n ' % (nickname, shiny) s += 'Lv %d %s %s with %s %s\n\n ' % (lv, nat, spec, abil, gender) s += 'OT: %s, ID: %05d, Secret ID: %05d\n ' % (otname, otid, secid) s += 'Holding: %s, Happiness: %d\n ' % (held, happy) s += 'Hidden Power: %s-type, %d Base Power\n\n ' % hidden s += 'Attacks: %-12s %-12s\n %-12s %-12s\n\n ' % atk s += 'IVs: HP %3d, Atk %3d, Def %3d, Spe %3d, SpA %3d, SpD %3d\n ' % ivs s += 'EVs: HP %3d, Atk %3d, Def %3d, Spe %3d, SpA %3d, SpD %3d, \ Total %d\n\n' % evs s += '=' * 80 + '\n\n' with open('statlog.txt', 'a') as f: f.write(s)
def gen_php_tpl(root, name): n = namegen(name) s = Template(template.tpl) d = {} target_path = os.path.join(root,'smarty/templates',n.tpl_name()+'.tpl') print 'Start generating tpl' print "\twriting: "+target_path f = open(target_path, 'w') f.write(s.substitute(d)) f.close() return s.substitute(d)
def gen_php_model(root, name): n = namegen(name) s = Template(template.model) d = {} d['model_name'] = n.model_name() target_path = os.path.join(root,'models',n.model_name()+'.php') print 'Start generating model' print "\twriting: "+target_path f = open(target_path, 'w') f.write(s.substitute(d)) f.close() return s.substitute(d)
def gen_php_controller(root, name): n = namegen(name) s = Template(template.controller) d = {} d['controller_name'] = n.controller_name() d['model_name'] = n.model_name() d['view_name'] = 'WanhuiFrameSimpleHtmlView' d['tpl_name'] = n.tpl_name() target_path = os.path.join(root,'controllers',n.controller_name()+'.php') print 'Start generating controller' print "\twriting: "+target_path f = open(target_path, 'w') f.write(s.substitute(d)) f.close() return s.substitute(d)
def makends(gba): # Deconstructing GBA .3gpkm file pid = gba[0:4] otid = gba[4:8] nickname = convertname(gba[8:18]) nickname = extendname(nickname, False) lang = gba[18] otname = convertname(gba[20:27]) species = ord(gba[32]) + (ord(gba[33]) << 8) species = pokemonindex.get(species) gend = genderbyte(species, pid) forme = form(species, gend, pid) nicknamed = namegen.namegen(nickname) != stats.species.get(species).upper() ability = abilities.get(species) species = chr(species & 0xff) + chr((species >> 8) & 0xff) item = gba[34:36] exp = gba[36:40] ppup = ord(gba[40]) ppupa = chr(ppup & 3) ppupb = chr((ppup >> 2) & 3) ppupc = chr((ppup >> 4) & 3) ppupd = chr((ppup >> 6) & 3) happy = gba[41] atk1 = gba[44:46] atk2 = gba[46:48] atk3 = gba[48:50] atk4 = gba[50:52] pp1 = gba[52] pp2 = gba[53] pp3 = gba[54] pp4 = gba[55] hpev = gba[56] atkev = gba[57] defev = gba[58] speev = gba[59] spaev = gba[60] spdev = gba[61] pkrs = gba[68] lvmet = ord(gba[70]) & 0x7f fmlot = ord(gba[71]) & 0x80 ivs = gba[72:76] ribbons = gba[76:80] # Generating NDS .pkm file pkm = species + item + otid + exp + happy pkm += ability[ord(pid[0]) % 2] pkm += '\x00' # Markings pkm += lang + hpev + atkev + defev + speev + spaev + spdev pkm += '\x00' * 10 # Contest values, Sinnoh ribbons pkm += atk1 + atk2 + atk3 + atk4 + pp1 + pp2 + pp3 + pp4 pkm += ppupa + ppupb + ppupc + ppupd pkm += ivbytes(ivs, nicknamed) pkm += ribbons # Hoenn ribbons pkm += chr(forme) pkm += '\x00' * 5 + '\x37\x00' # Shiny leaves, padding, egg from, met at pkm += nickname pkm += '\x00\x03' # Padding, hometown (Hoenn, Emerald) pkm += '\x00' * 8 # Sinnoh Ribbons, Padding pkm += extendname(otname, True, pkm[0x40:0x50]) pkm += '\x00' * 3 # Date egg received pkm += datemet() pkm += '\x00' * 2 # Egg location pkm += '\x37\x00' # Location met (Migrated from Emerald) pkm += pkrs pkm += '\x04' # Poke ball pkm += chr(lvmet | fmlot) pkm += '\x00' # Encounter type pkm += '\x04' # Poke ball pkm += '\x00' # Padding chksm = getsum(pkm) pkm = pid + '\x00\x00' + chksm + pkm return makeparty(pkm)
def makends(gba): # Deconstructing GBA .3gpkm file pid = gba[0:4] otid = gba[4:8] nickname = convertname(gba[8:18]) nickname = extendname(nickname, False) lang = gba[18] otname = convertname(gba[20:27]) species = ord(gba[32]) + (ord(gba[33]) << 8) species = pokemonindex.get(species) gend = genderbyte(species, pid) forme = form(species, gend, pid) nicknamed = namegen.namegen(nickname) != stats.species.get(species).upper() ability = abilities.get(species) species = chr(species & 0xff) + chr((species >> 8) & 0xff) item = gba[34:36] exp = gba[36:40] ppup = ord(gba[40]) ppupa = chr(ppup & 3) ppupb = chr((ppup >> 2) & 3) ppupc = chr((ppup >> 4) & 3) ppupd = chr((ppup >> 6) & 3) happy = gba[41] atk1 = gba[44:46] atk2 = gba[46:48] atk3 = gba[48:50] atk4 = gba[50:52] pp1 = gba[52] pp2 = gba[53] pp3 = gba[54] pp4 = gba[55] hpev = gba[56] atkev = gba[57] defev = gba[58] speev = gba[59] spaev = gba[60] spdev = gba[61] pkrs = gba[68] lvmet = ord(gba[70]) & 0x7f fmlot = ord(gba[71]) & 0x80 ivs = gba[72:76] ribbons = gba[76:80] # Generating NDS .pkm file pkm = species + item + otid + exp + happy pkm += ability[ord(pid[0]) % 2] pkm += '\x00' # Markings pkm += lang + hpev + atkev + defev + speev + spaev + spdev pkm += '\x00' * 10 # Contest values, Sinnoh ribbons pkm += atk1 + atk2 + atk3 + atk4 + pp1 + pp2 + pp3 + pp4 pkm += ppupa + ppupb + ppupc + ppupd pkm += ivbytes(ivs, nicknamed) pkm += ribbons # Hoenn ribbons pkm += chr(forme) pkm += '\x00' * 5 + '\x37\x00' # Shiny leaves, padding, egg from, met at pkm += nickname pkm += '\x00\x03' # Padding, hometown (Hoenn, Emerald) pkm += '\x00' * 8 # Sinnoh Ribbons, Padding pkm += extendname(otname, True, pkm[0x40:0x50]) pkm += '\x00' * 3 # Date egg received pkm += datemet() pkm += '\x00' * 2 # Egg location pkm += '\x37\x00' # Location met (Migrated from Emerald) pkm += pkrs pkm += '\x04' # Poke ball pkm += chr(lvmet | fmlot) pkm += '\x00' # Encounter type pkm += '\x04' # Poke ball pkm += '\x00' # Padding chksm = getsum(pkm) pkm = pid + '\x00\x00' + chksm + pkm return makeparty(pkm)
def gen_php_router(name): n = namegen(name) return "'/%s' => '%s'," % (name, n.controller_name())