Created
October 13, 2012 23:15
-
-
Save magical/3886549 to your computer and use it in GitHub Desktop.
Pokémon B/W base experience
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
import narc | |
from namedstruct import namedstruct | |
from itertools import islice | |
BaseStats = namedstruct('BaseStats', | |
"stat_hp:B stat_atk:B stat_def:B" | |
" stat_speed:B stat_spatk:B stat_spdef:B" | |
" type1:B type2:B" | |
" catch_rate:B" | |
" stage:B" | |
" effort:H" | |
" item1:H item2:H item3:H" | |
" gender_rate:B hatch_counter:B happiness:B" | |
" growth:B" | |
" egg1:B egg2:B" | |
" ability1:B ability2:B ability3:B" | |
" escape_rate:B" | |
" form_stats_start:H form_sprites_start:H form_count:B" | |
" color:B" | |
" base_exp:H" | |
" height:H weight:H", | |
endian='<') | |
with open(sys.argv[1] + "/a/0/1/6", "rb") as f: | |
chunks = list(narc.parse(f)) | |
with open("names.txt", "r") as f: | |
names = [line.strip() for line in f] | |
# built-in round is a bit too clever | |
def round(n): | |
return int(n + 0.5) | |
factors = [0, 4, 7, 9] | |
boost = [113, 242, 440, 531] | |
for i, chunk in islice(enumerate(chunks), 1, 650): | |
stats = BaseStats._unpack(chunk[:BaseStats._struct.size]) | |
total = sum([stats.stat_hp, stats.stat_atk, stats.stat_def, | |
stats.stat_speed, stats.stat_spatk, stats.stat_spdef]) | |
exp = total * factors[stats.stage] / 20 | |
if i in boost: | |
exp = round(exp) * 2.5 | |
if round(exp) != stats.base_exp: | |
print("{} {} (stage {})\t{} * {}/20 = {} != {}".format( | |
i, names[i], stats.stage, | |
total, factors[stats.stage], exp, stats.base_exp)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import namedtuple | |
from struct import Struct | |
def namedstruct(typename, fields, verbose=False, rename=False, endian='@'): | |
if isinstance(fields, str): | |
if ',' in fields: | |
fields = [x.strip() for x in fields.split(',')] | |
else: | |
fields = fields.split() | |
field_names = [] | |
field_types = [] | |
for field in fields: | |
name, sep, fmt = field.partition(':') | |
if not fmt: | |
raise ValueError("field missing format specifier: %s" % repr(field)) | |
char = fmt[-1] | |
digits = fmt[:-1] | |
if char.isdigit(): | |
raise ValueError("bad format specifier: %s" % repr(field)) | |
if digits: | |
if not digits.isdigit(): | |
raise ValueError("bad format specifier: %s" % repr(field)) | |
if char not in 'sx': | |
raise ValueError("field count can only be specified with 's' and 'x': %s" % repr(field)) | |
if char == 'x' and name: | |
raise ValueError("cannot specify field name with 'x': %s" % repr(field)) | |
if char != 'x' and not name: | |
raise ValueError("field missing name: %s" % repr(name)) | |
if name: | |
field_names.append(name) | |
field_types.append(fmt) | |
struct_format = endian + ''.join(field_types) | |
struct = Struct(struct_format) | |
cls = namedtuple(typename, field_names, verbose=verbose, rename=rename) | |
def _pack(self): | |
"""Return a string with the packed data""" | |
return self._struct.pack(*self) | |
def _pack_into(self, buffer, offset): | |
"""Pack the data into a buffer""" | |
return self._struct.pack_into(buffer, offset, *self) | |
def _unpack(cls, string): | |
"""Return a new instance of this struct with data unpacked from a string""" | |
return cls._make(cls._struct.unpack(string)) | |
def _unpack_from(cls, buffer, offset=0): | |
"""Return a new instance of this struct with data unpacked from a buffer""" | |
return cls._make(cls._struct.unpack_from(buffer, offset)) | |
def _read_from(cls, f): | |
"""Return a new instance of this struct with data read from a file""" | |
s = f.read(cls._struct.size) | |
return cls._make(cls._struct.unpack(s)) | |
cls._pack = _pack | |
cls._pack_into = _pack_into | |
cls._unpack = classmethod(_unpack) | |
cls._unpack_from = classmethod(_unpack_from) | |
cls._read_from = classmethod(_read_from) | |
cls._field_types = [x for x in field_types if x[-1] != 'x'] | |
cls._struct = struct | |
return cls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Bulbasaur | |
Ivysaur | |
Venusaur | |
Charmander | |
Charmeleon | |
Charizard | |
Squirtle | |
Wartortle | |
Blastoise | |
Caterpie | |
Metapod | |
Butterfree | |
Weedle | |
Kakuna | |
Beedrill | |
Pidgey | |
Pidgeotto | |
Pidgeot | |
Rattata | |
Raticate | |
Spearow | |
Fearow | |
Ekans | |
Arbok | |
Pikachu | |
Raichu | |
Sandshrew | |
Sandslash | |
Nidoran♀ | |
Nidorina | |
Nidoqueen | |
Nidoran♂ | |
Nidorino | |
Nidoking | |
Clefairy | |
Clefable | |
Vulpix | |
Ninetales | |
Jigglypuff | |
Wigglytuff | |
Zubat | |
Golbat | |
Oddish | |
Gloom | |
Vileplume | |
Paras | |
Parasect | |
Venonat | |
Venomoth | |
Diglett | |
Dugtrio | |
Meowth | |
Persian | |
Psyduck | |
Golduck | |
Mankey | |
Primeape | |
Growlithe | |
Arcanine | |
Poliwag | |
Poliwhirl | |
Poliwrath | |
Abra | |
Kadabra | |
Alakazam | |
Machop | |
Machoke | |
Machamp | |
Bellsprout | |
Weepinbell | |
Victreebel | |
Tentacool | |
Tentacruel | |
Geodude | |
Graveler | |
Golem | |
Ponyta | |
Rapidash | |
Slowpoke | |
Slowbro | |
Magnemite | |
Magneton | |
Farfetch'd | |
Doduo | |
Dodrio | |
Seel | |
Dewgong | |
Grimer | |
Muk | |
Shellder | |
Cloyster | |
Gastly | |
Haunter | |
Gengar | |
Onix | |
Drowzee | |
Hypno | |
Krabby | |
Kingler | |
Voltorb | |
Electrode | |
Exeggcute | |
Exeggutor | |
Cubone | |
Marowak | |
Hitmonlee | |
Hitmonchan | |
Lickitung | |
Koffing | |
Weezing | |
Rhyhorn | |
Rhydon | |
Chansey | |
Tangela | |
Kangaskhan | |
Horsea | |
Seadra | |
Goldeen | |
Seaking | |
Staryu | |
Starmie | |
Mr. Mime | |
Scyther | |
Jynx | |
Electabuzz | |
Magmar | |
Pinsir | |
Tauros | |
Magikarp | |
Gyarados | |
Lapras | |
Ditto | |
Eevee | |
Vaporeon | |
Jolteon | |
Flareon | |
Porygon | |
Omanyte | |
Omastar | |
Kabuto | |
Kabutops | |
Aerodactyl | |
Snorlax | |
Articuno | |
Zapdos | |
Moltres | |
Dratini | |
Dragonair | |
Dragonite | |
Mewtwo | |
Mew | |
Chikorita | |
Bayleef | |
Meganium | |
Cyndaquil | |
Quilava | |
Typhlosion | |
Totodile | |
Croconaw | |
Feraligatr | |
Sentret | |
Furret | |
Hoothoot | |
Noctowl | |
Ledyba | |
Ledian | |
Spinarak | |
Ariados | |
Crobat | |
Chinchou | |
Lanturn | |
Pichu | |
Cleffa | |
Igglybuff | |
Togepi | |
Togetic | |
Natu | |
Xatu | |
Mareep | |
Flaaffy | |
Ampharos | |
Bellossom | |
Marill | |
Azumarill | |
Sudowoodo | |
Politoed | |
Hoppip | |
Skiploom | |
Jumpluff | |
Aipom | |
Sunkern | |
Sunflora | |
Yanma | |
Wooper | |
Quagsire | |
Espeon | |
Umbreon | |
Murkrow | |
Slowking | |
Misdreavus | |
Unown | |
Wobbuffet | |
Girafarig | |
Pineco | |
Forretress | |
Dunsparce | |
Gligar | |
Steelix | |
Snubbull | |
Granbull | |
Qwilfish | |
Scizor | |
Shuckle | |
Heracross | |
Sneasel | |
Teddiursa | |
Ursaring | |
Slugma | |
Magcargo | |
Swinub | |
Piloswine | |
Corsola | |
Remoraid | |
Octillery | |
Delibird | |
Mantine | |
Skarmory | |
Houndour | |
Houndoom | |
Kingdra | |
Phanpy | |
Donphan | |
Porygon2 | |
Stantler | |
Smeargle | |
Tyrogue | |
Hitmontop | |
Smoochum | |
Elekid | |
Magby | |
Miltank | |
Blissey | |
Raikou | |
Entei | |
Suicune | |
Larvitar | |
Pupitar | |
Tyranitar | |
Lugia | |
Ho-Oh | |
Celebi | |
Treecko | |
Grovyle | |
Sceptile | |
Torchic | |
Combusken | |
Blaziken | |
Mudkip | |
Marshtomp | |
Swampert | |
Poochyena | |
Mightyena | |
Zigzagoon | |
Linoone | |
Wurmple | |
Silcoon | |
Beautifly | |
Cascoon | |
Dustox | |
Lotad | |
Lombre | |
Ludicolo | |
Seedot | |
Nuzleaf | |
Shiftry | |
Taillow | |
Swellow | |
Wingull | |
Pelipper | |
Ralts | |
Kirlia | |
Gardevoir | |
Surskit | |
Masquerain | |
Shroomish | |
Breloom | |
Slakoth | |
Vigoroth | |
Slaking | |
Nincada | |
Ninjask | |
Shedinja | |
Whismur | |
Loudred | |
Exploud | |
Makuhita | |
Hariyama | |
Azurill | |
Nosepass | |
Skitty | |
Delcatty | |
Sableye | |
Mawile | |
Aron | |
Lairon | |
Aggron | |
Meditite | |
Medicham | |
Electrike | |
Manectric | |
Plusle | |
Minun | |
Volbeat | |
Illumise | |
Roselia | |
Gulpin | |
Swalot | |
Carvanha | |
Sharpedo | |
Wailmer | |
Wailord | |
Numel | |
Camerupt | |
Torkoal | |
Spoink | |
Grumpig | |
Spinda | |
Trapinch | |
Vibrava | |
Flygon | |
Cacnea | |
Cacturne | |
Swablu | |
Altaria | |
Zangoose | |
Seviper | |
Lunatone | |
Solrock | |
Barboach | |
Whiscash | |
Corphish | |
Crawdaunt | |
Baltoy | |
Claydol | |
Lileep | |
Cradily | |
Anorith | |
Armaldo | |
Feebas | |
Milotic | |
Castform | |
Kecleon | |
Shuppet | |
Banette | |
Duskull | |
Dusclops | |
Tropius | |
Chimecho | |
Absol | |
Wynaut | |
Snorunt | |
Glalie | |
Spheal | |
Sealeo | |
Walrein | |
Clamperl | |
Huntail | |
Gorebyss | |
Relicanth | |
Luvdisc | |
Bagon | |
Shelgon | |
Salamence | |
Beldum | |
Metang | |
Metagross | |
Regirock | |
Regice | |
Registeel | |
Latias | |
Latios | |
Kyogre | |
Groudon | |
Rayquaza | |
Jirachi | |
Deoxys | |
Turtwig | |
Grotle | |
Torterra | |
Chimchar | |
Monferno | |
Infernape | |
Piplup | |
Prinplup | |
Empoleon | |
Starly | |
Staravia | |
Staraptor | |
Bidoof | |
Bibarel | |
Kricketot | |
Kricketune | |
Shinx | |
Luxio | |
Luxray | |
Budew | |
Roserade | |
Cranidos | |
Rampardos | |
Shieldon | |
Bastiodon | |
Burmy | |
Wormadam | |
Mothim | |
Combee | |
Vespiquen | |
Pachirisu | |
Buizel | |
Floatzel | |
Cherubi | |
Cherrim | |
Shellos | |
Gastrodon | |
Ambipom | |
Drifloon | |
Drifblim | |
Buneary | |
Lopunny | |
Mismagius | |
Honchkrow | |
Glameow | |
Purugly | |
Chingling | |
Stunky | |
Skuntank | |
Bronzor | |
Bronzong | |
Bonsly | |
Mime Jr. | |
Happiny | |
Chatot | |
Spiritomb | |
Gible | |
Gabite | |
Garchomp | |
Munchlax | |
Riolu | |
Lucario | |
Hippopotas | |
Hippowdon | |
Skorupi | |
Drapion | |
Croagunk | |
Toxicroak | |
Carnivine | |
Finneon | |
Lumineon | |
Mantyke | |
Snover | |
Abomasnow | |
Weavile | |
Magnezone | |
Lickilicky | |
Rhyperior | |
Tangrowth | |
Electivire | |
Magmortar | |
Togekiss | |
Yanmega | |
Leafeon | |
Glaceon | |
Gliscor | |
Mamoswine | |
Porygon-Z | |
Gallade | |
Probopass | |
Dusknoir | |
Froslass | |
Rotom | |
Uxie | |
Mesprit | |
Azelf | |
Dialga | |
Palkia | |
Heatran | |
Regigigas | |
Giratina | |
Cresselia | |
Phione | |
Manaphy | |
Darkrai | |
Shaymin | |
Arceus | |
Victini | |
Snivy | |
Servine | |
Serperior | |
Tepig | |
Pignite | |
Emboar | |
Oshawott | |
Dewott | |
Samurott | |
Patrat | |
Watchog | |
Lillipup | |
Herdier | |
Stoutland | |
Purrloin | |
Liepard | |
Pansage | |
Simisage | |
Pansear | |
Simisear | |
Panpour | |
Simipour | |
Munna | |
Musharna | |
Pidove | |
Tranquill | |
Unfezant | |
Blitzle | |
Zebstrika | |
Roggenrola | |
Boldore | |
Gigalith | |
Woobat | |
Swoobat | |
Drilbur | |
Excadrill | |
Audino | |
Timburr | |
Gurdurr | |
Conkeldurr | |
Tympole | |
Palpitoad | |
Seismitoad | |
Throh | |
Sawk | |
Sewaddle | |
Swadloon | |
Leavanny | |
Venipede | |
Whirlipede | |
Scolipede | |
Cottonee | |
Whimsicott | |
Petilil | |
Lilligant | |
Basculin | |
Sandile | |
Krokorok | |
Krookodile | |
Darumaka | |
Darmanitan | |
Maractus | |
Dwebble | |
Crustle | |
Scraggy | |
Scrafty | |
Sigilyph | |
Yamask | |
Cofagrigus | |
Tirtouga | |
Carracosta | |
Archen | |
Archeops | |
Trubbish | |
Garbodor | |
Zorua | |
Zoroark | |
Minccino | |
Cinccino | |
Gothita | |
Gothorita | |
Gothitelle | |
Solosis | |
Duosion | |
Reuniclus | |
Ducklett | |
Swanna | |
Vanillite | |
Vanillish | |
Vanilluxe | |
Deerling | |
Sawsbuck | |
Emolga | |
Karrablast | |
Escavalier | |
Foongus | |
Amoonguss | |
Frillish | |
Jellicent | |
Alomomola | |
Joltik | |
Galvantula | |
Ferroseed | |
Ferrothorn | |
Klink | |
Klang | |
Klinklang | |
Tynamo | |
Eelektrik | |
Eelektross | |
Elgyem | |
Beheeyem | |
Litwick | |
Lampent | |
Chandelure | |
Axew | |
Fraxure | |
Haxorus | |
Cubchoo | |
Beartic | |
Cryogonal | |
Shelmet | |
Accelgor | |
Stunfisk | |
Mienfoo | |
Mienshao | |
Druddigon | |
Golett | |
Golurk | |
Pawniard | |
Bisharp | |
Bouffalant | |
Rufflet | |
Braviary | |
Vullaby | |
Mandibuzz | |
Heatmor | |
Durant | |
Deino | |
Zweilous | |
Hydreigon | |
Larvesta | |
Volcarona | |
Cobalion | |
Terrakion | |
Virizion | |
Tornadus | |
Thundurus | |
Reshiram | |
Zekrom | |
Landorus | |
Kyurem | |
Keldeo | |
Meloetta | |
Genesect |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import os | |
from struct import pack, unpack | |
from collections import namedtuple | |
from warnings import warn | |
Header = namedtuple('Header', 'magic bom version size header_size count') | |
FATBHeader = namedtuple('fatb_header', 'magic size count') | |
FNTBHeader = namedtuple('fntb_header', 'magic size') | |
FIMGHeader = namedtuple('fimg_header', 'magic size') | |
def parse(f): | |
header = Header._make(unpack("<4sHHLHH", f.read(16))) | |
assert header.magic == b'NARC' | |
assert header.bom == 0xfffe | |
assert header.header_size == 16 | |
if header.version != 0x100: | |
warn('unknown NARC version {0:x}'.format(header.version)) | |
fatb = FATBHeader._make(unpack("<4sLL", f.read(12))) | |
assert fatb.magic == b'BTAF' | |
assert fatb.size == 12 + (fatb.count * 8) | |
records = [] | |
for _ in range(fatb.count): | |
records.append(unpack("<LL", f.read(8))) | |
fntb = FNTBHeader._make(unpack("<4sL8x", f.read(16))) | |
assert fntb.magic == b'BTNF' | |
if 16 < fntb.size: | |
warn("ignoring non-empty FNTB chunk") | |
f.seek(fntb.size - 16, os.SEEK_CUR) | |
fimg = FIMGHeader._make(unpack("<4sL", f.read(8))) | |
assert fimg.magic == b'GMIF' | |
mark = f.tell() | |
for i, (start, end) in enumerate(records): | |
if end < start: | |
warn("end < start: {0} < {1}".format(end, start)) | |
end = start | |
length = end - start | |
f.seek(mark+start) | |
data = f.read(length) | |
yield data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment