Skip to content

Instantly share code, notes, and snippets.

@pineapplemachine
Created January 22, 2018 12:45
Show Gist options
  • Select an option

  • Save pineapplemachine/80053cd70cb5c4a275edd3464a6d7818 to your computer and use it in GitHub Desktop.

Select an option

Save pineapplemachine/80053cd70cb5c4a275edd3464a6d7818 to your computer and use it in GitHub Desktop.
Determine TM/HM learnset flag data from Emerald disassembly
"""
Written to determine from a subset of known examples a likely pattern for which flags in an Emerald disassembly pertained
to the ability to learn which TM/HM. With 23 examples taken from Bulbapedia pages I was able to find a pattern and extrapolate
with some confidence the purpose of flags that were not narrowed down to one possible TM/HM.
Due to either an error in my copying the reference TM/HM learnset data from Bulbapedia, or an error in the data itself, this
script interestingly and erroneously concludes that no flags could possibly correlate to TM12 (Taunt) or TM20 (Safeguard).
The discovered pattern was that the bits such as this one represented, *from right-to-left*, TMs 1-50 then HMs 1-8.
Or, from left-to-right: HMs 8-1 then TMs 50-1.
0b0011100100000111100000100010000100001101010000011100100000 @ Bulbasaur
In order to run the script, this source file:
https://github.com/pret/pokeemerald/blob/a793e62d8364996a276c048bc55ae072a285053a/data/tm_hm_learnsets.inc
Must be present at this relative file path:
pokeemerald-master/data/tm_hm_learnsets.inc
"""
examples = {
"Bulbasaur": """
TM06
TM09
TM10
TM11
TM17
TM19
TM21
TM22
TM27
TM32
TM36
TM42
TM43
TM44
TM45
HM01
HM04
HM05
HM06
""",
"Baltoy": """
TM06
TM10
TM11
TM13
TM16
TM17
TM18
TM21
TM22
TM26
TM27
TM28
TM29
TM30
TM32
TM33
TM37
TM39
TM42
TM43
TM44
TM48
HM05
""",
"Seel": """
TM03
TM06
TM07
TM10
TM13
TM14
TM17
TM18
TM20
TM21
TM27
TM32
TM42
TM43
TM44
TM45
TM46
HM03
HM07
HM08
""",
"Cloyster": """
TM03
TM06
TM07
TM10
TM13
TM14
TM15
TM17
TM18
TM20
TM21
TM27
TM32
TM41
TM42
TM43
TM44
TM45
HM03
HM08
""",
"Vaporeon": """
TM03
TM05
TM06
TM07
TM10
TM11
TM13
TM14
TM15
TM17
TM18
TM21
TM23
TM27
TM28
TM30
TM32
TM42
TM43
TM44
TM45
HM03
HM07
HM08
""",
"Nosepass": """
TM06
TM10
TM11
TM12
TM17
TM21
TM24
TM25
TM26
TM27
TM32
TM34
TM37
TM39
TM41
TM42
TM43
TM44
TM45
HM04
HM06
""",
"Lugia": """
TM03
TM04
TM05
TM06
TM07
TM10
TM11
TM12
TM13
TM14
TM15
TM16
TM17
TM18
TM19
TM20
TM21
TM23
TM24
TM25
TM26
TM27
TM29
TM30
TM32
TM33
TM34
TM37
TM40
TM42
TM43
TM44
TM47
TM48
HM02
HM03
HM04
HM06
HM07
HM08
""",
"Glalie": """
TM03
TM06
TM07
TM10
TM12
TM13
TM14
TM15
TM16
TM17
TM18
TM21
TM26
TM27
TM30
TM32
TM41
TM42
TM43
TM44
TM45
HM05
""",
"Lapras": """
TM03
TM05
TM06
TM07
TM10
TM13
TM14
TM15
TM17
TM18
TM20
TM21
TM23
TM24
TM25
TM27
TM29
TM32
TM34
TM42
TM43
TM44
TM45
HM03
HM04
HM06
HM07
HM08
""",
"Torkoal": """
TM06
TM10
TM11
TM17
TM21
TM23
TM27
TM32
TM35
TM36
TM38
TM42
TM43
TM44
TM45
TM50
HM04
HM06
""",
"Scyther": """
TM06
TM10
TM11
TM15
TM17
TM18
TM21
TM27
TM32
TM40
TM42
TM43
TM44
TM45
TM46
TM47
HM01
HM06
""",
"Vulpix": """
TM05
TM06
TM10
TM11
TM17
TM20
TM21
TM23
TM27
TM28
TM32
TM35
TM38
TM42
TM43
TM44
TM45
TM50
""",
"Natu": """
TM04
TM06
TM10
TM11
TM16
TM17
TM18
TM19
TM21
TM22
TM27
TM29
TM30
TM32
TM33
TM40
TM42
TM43
TM44
TM45
TM46
TM47
TM48
HM05
""",
"Gengar": """
TM01
TM06
TM10
TM11
TM12
TM15
TM17
TM18
TM19
TM21
TM24
TM25
TM27
TM29
TM30
TM31
TM32
TM36
TM41
TM42
TM43
TM44
TM45
TM46
TM48
TM49
HM04
HM06
""",
"Beedrill": """
TM06
TM10
TM11
TM15
TM17
TM19
TM21
TM22
TM27
TM31
TM32
TM36
TM40
TM42
TM43
TM44
TM45
TM46
HM01
HM06
""",
"Clefairy": """
TM01
TM03
TM04
TM06
TM10
TM11
TM13
TM14
TM16
TM17
TM18
TM20
TM21
TM22
TM23
TM24
TM25
TM27
TM28
TM29
TM30
TM31
TM32
TM33
TM34
TM35
TM38
TM42
TM43
TM44
TM45
TM49
HM04
HM05
""",
"Mewtwo": """
TM01
TM03
TM04
TM06
TM07
TM08
TM10
TM11
TM12
TM13
TM14
TM15
TM16
TM17
TM18
TM20
TM21
TM22
TM23
TM24
TM25
TM26
TM27
TM29
TM30
TM31
TM32
TM33
TM34
TM35
TM37
TM38
TM39
TM40
TM41
TM42
TM43
TM44
TM48
TM49
HM04
HM05
HM06
""",
"Sunflora": """
TM06
TM09
TM10
TM11
TM15
TM16
TM17
TM19
TM20
TM21
TM22
TM27
TM32
TM36
TM42
TM43
TM44
TM45
HM01
HM05
""",
"Flygon": """
TM02
TM06
TM10
TM11
TM15
TM17
TM19
TM21
TM22
TM23
TM26
TM27
TM28
TM32
TM35
TM37
TM38
TM39
TM42
TM43
TM44
TM45
TM47
HM02
HM04
HM06
""",
"Geodude": """
TM01
TM06
TM10
TM11
TM17
TM21
TM26
TM27
TM28
TM31
TM32
TM35
TM37
TM38
TM39
TM42
TM43
TM44
TM45
HM04
HM06
""",
"Squirtle": """
TM01
TM03
TM06
TM07
TM10
TM13
TM14
TM17
TM18
TM21
TM23
TM27
TM28
TM31
TM32
TM42
TM43
TM44
TM45
HM03
HM04
HM06
HM07
HM08
""",
"Magneton": """
TM06
TM10
TM11
TM15
TM17
TM18
TM21
TM24
TM25
TM27
TM32
TM33
TM34
TM42
TM43
TM44
HM05
""",
"Banette": """
TM04
TM06
TM10
TM11
TM12
TM15
TM17
TM18
TM21
TM24
TM25
TM27
TM29
TM30
TM32
TM34
TM41
TM42
TM43
TM44
TM45
TM46
TM48
TM49
HM05
""",
}
tm_list = []
for i in range(1, 10):
tm_list.append("TM0%s" % i)
for i in range(10, 51):
tm_list.append("TM%s" % i)
for i in range(1, 9):
tm_list.append("HM0%s" % i)
for poke_name, learnset in examples.items():
move_list = filter(None, map(
lambda line: line.strip(), learnset.split("\n")
))
examples[poke_name] = {}
for move in tm_list:
examples[poke_name][move] = False
for move in move_list:
examples[poke_name][move] = True
possible_tms = []
for j in range(0, 58):
possible_tms.append({})
for i in range(1, 10):
possible_tms[j]["TM0%s" % i] = True
for i in range(10, 51):
possible_tms[j]["TM%s" % i] = True
for i in range(1, 9):
possible_tms[j]["HM0%s" % i] = True
with open("pokeemerald-master/data/tm_hm_learnsets.inc", "r") as f:
content = f.read()
for line in content.split("\n"):
line = line.strip()
if line.startswith(".8byte"):
poke_name = line.rsplit(" ", 1)[-1]
if poke_name in examples:
print "Checking %s..." % poke_name
bits = line[9:].split(" ", 1)[0]
for i, bit_char in enumerate(bits):
bit = bit_char == "1"
for tm in tm_list:
if bit != examples[poke_name][tm]:
possible_tms[i][tm] = False
for i in range(0, 58):
move_list = []
for key, value in possible_tms[i].items():
if value:
move_list.append(key)
print "Possibilities for flag %s: %s" % (i, ", ".join(move_list))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment