From 948b270a83dce5f985cf347e88cd3ed0b110e1c1 Mon Sep 17 00:00:00 2001 From: Andrew Martinek Date: Thu, 12 Sep 2019 12:29:47 -0400 Subject: Script reversing --- tools/script_extractor.py | 174 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 tools/script_extractor.py (limited to 'tools/script_extractor.py') diff --git a/tools/script_extractor.py b/tools/script_extractor.py new file mode 100644 index 0000000..efe98a4 --- /dev/null +++ b/tools/script_extractor.py @@ -0,0 +1,174 @@ +#!/usr/bin/env python3 + +import argparse + +#TODO: +# - Add arguments to all functions (have fun lol) +# - implement text +# - (Possibly) add new type of word that looks for matches in the sym file +# - enter to continually generate more lines of the script +# - full script mode? +# - Make pretty!! + +def decodeLine(scriptList, game_data, loc, ignore_broken): + currLine = scriptList[game_data[loc]] + ret = "\trun_script " + currLine[0] + "\n" + loc+=1 + quit = currLine[2] + for c in currLine[1]: + if c == "b": + ret += "\tdb $" + format(game_data[loc],"02x") + "\n" + loc += 1 + elif c == "w": + ret += "\tdb $" + format((game_data[loc] + (game_data[loc+1]<<8)),"04x") + "\n" + loc += 2 + elif c == "t": + ret += "\ttx Text" + format((game_data[loc] + (game_data[loc+1]<<8)),"04x") + "\n" + loc += 2 + elif c == "q": + print("haven't updated data for this yet") + if not ignore_broken: + quit = True + return (loc, ret, quit) + + +def main(): + scriptList = createList() + + with open("tcg.gbc", "rb") as file: + game_data = file.read() + loc = 0xd52e + auto = True + end = False + ignore_broken = True + script = "" + if game_data[loc] != 0xe7: + print("Error: first byte was not start_script") + else: + + # TODO this is hacky please don't do this + ls = format(loc,"04x") + lsa = format(loc-0x8000,"04x") + print("OWSequence_" + ls + ": ; " + ls + " (3:" + lsa + ")" ) + loc += 1 + print("\tstart_script") + while not end: + loc, outstr, end = decodeLine(scriptList,game_data,loc,ignore_broken) + outstr = outstr[:-1] # [:-1] strips the newline at the end + if auto: + print(outstr) + else: + input(outstr) + print("; " + hex(loc)) + + +def createList(): # this is a func just so all this can go at the bottom + # name, arg list, is an ender + return [ + ("OWScript_EndScriptLoop1", "", True), + ("OWScript_CloseTextBox", "", False), + ("OWScript_PrintTextString", "t", False), + ("Func_ccdc", "bb", False), + ("OWScript_AskQuestionJump", "bbbb", False), # more complex behavior too (jumping) + ("OWScript_StartBattle", "bbb", False), + ("Func_cd83", "bbbb", False), + ("Func_cda8", "bbbb", False), + ("OWScript_PrintTextCloseBox", "t", False), + ("Func_cdcb", "bb", False), + ("Func_ce26", "bb", False), + ("Func_ce84", "", False), + ("OWScript_GiveBoosterPacks", "bbb", False), + ("Func_cf0c", "bbb", False), # more complex behavior too (jumping) + ("Func_cf12", "bbb", False), + ("Func_cf3f", "b", False), + ("Func_cf4c", "b", False), + ("Func_cf53", "d", False), # more complex behavior too (jumping) + ("Func_cf7b", "", False), + ("Func_cf2d", "bbbb", False), # more complex behavior too (jumping + ??) + ("Func_cf96", "d", False), # only jumps? still needs args to do that though + ("Func_cfc6", "b", False), + ("Func_cfd4", "", False), + ("Func_d00b", "", False), # includes something with random and extra data + ("Func_d025", "d", False), # possibly only jumps, still needs args + ("Func_d032", "d", False), # see above + ("Func_d03f", "", False), + ("OWScript_ScriptJump", "d", False), # jumps to d + ("Func_d04f", "", False), + ("Func_d055", "b", False), + ("OWScript_MovePlayer", "bb", False), + ("Func_cee2", "b", False), + ("OWScript_SetDialogName", "b", False), + ("Func_d088", "bbb", False), + ("Func_d095", "bbb", False), + ("Func_d0be", "bb", False), + ("Func_d0ce", "b", False), + ("Func_d0d9", "bbb", False), # jumps but still needs args + ("Func_d0f2", "bbb", False), # jumps but still needs args + ("Func_ce4a", "bb", False), + ("Func_ceba", "q", False), + ("Func_d103", "q", False), + ("Func_d125", "q", False), + ("Func_d135", "q", False), + ("Func_d16b", "q", False), + ("Func_cd4f", "q", False), + ("Func_cd94", "q", False), + ("Func_ce52", "q", False), + ("Func_cdd8", "q", False), + ("Func_cdf5", "q", False), + ("Func_d195", "q", False), + ("Func_d1ad", "q", False), + ("Func_d1b3", "q", False), + ("OWScript_EndScriptCloseText", "", True), # it calls inc twice but it ends anyway? + ("Func_d244", "q", False), + ("Func_d24c", "q", False), + ("OWScript_OpenDeckMachine", "q", False), + ("Func_d271", "q", False), + ("Func_d36d", "bbbbb", False), + ("Func_ce6f", "q", False), + ("Func_d209", "q", False), + ("Func_d38f", "q", False), + ("Func_d396", "q", False), + ("Func_cd76", "q", False), + ("Func_d39d", "q", False), + ("Func_d3b9", "q", False), + ("Func_d3c9", "q", False), + ("Func_d3d1", "q", False), + ("Func_d3d4", "q", False), + ("Func_d3e0", "", False), + ("Func_d3fe", "q", False), + ("Func_d408", "q", False), + ("Func_d40f", "q", False), + ("Func_d416", "q", False), + ("Func_d423", "q", False), + ("Func_d429", "q", False), + ("Func_d41d", "q", False), + ("Func_d42f", "q", False), + ("Func_d435", "q", False), + ("Func_cce4", "q", False), + ("Func_d2f6", "q", False), + ("Func_d317", "q", False), + ("Func_d43d", "q", False), + ("OWScript_EndScriptLoop2", "q", True), + ("OWScript_EndScriptLoop3", "q", True), + ("OWScript_EndScriptLoop4", "q", True), + ("OWScript_EndScriptLoop5", "q", True), + ("OWScript_EndScriptLoop6", "q", True), + ("OWScript_CustomModifyEventFlags", "q", False), + ("Func_d460", "q", False), + ("OWScript_JumpIfFlagSet", "q", False), + ("Func_d484", "q", False), + ("Func_d49e", "q", False), + ("Func_d4a6", "q", False), + ("Func_d4ae", "q", False), + ("OWScript_SetEventFlags", "q", False), + ("Func_d4c3", "q", False), + ("Func_d4ca", "q", False), + ("OWScript_JumpIfFlagNotSet", "q", False), + ("Func_d452", "q", False), + ("OWScript_EndScriptLoop7", "q", True), + ("OWScript_EndScriptLoop8", "q", True), + ("OWScript_EndScriptLoop9", "q", True), + ("OWScript_EndScriptLoop10", "q", True) + ] + +main() -- cgit v1.2.3 From 751b28d4fee472af4d0de83ef22a1f11ec6fade6 Mon Sep 17 00:00:00 2001 From: Andrew Martinek Date: Sun, 15 Sep 2019 21:55:11 -0400 Subject: Lots of NPC data, some temp. comments on mapdatapointers --- tools/script_extractor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/script_extractor.py') diff --git a/tools/script_extractor.py b/tools/script_extractor.py index efe98a4..d9cea6b 100644 --- a/tools/script_extractor.py +++ b/tools/script_extractor.py @@ -101,7 +101,7 @@ def createList(): # this is a func just so all this can go at the bottom ("Func_d088", "bbb", False), ("Func_d095", "bbb", False), ("Func_d0be", "bb", False), - ("Func_d0ce", "b", False), + ("OWScript_DoFrames", "b", False), ("Func_d0d9", "bbb", False), # jumps but still needs args ("Func_d0f2", "bbb", False), # jumps but still needs args ("Func_ce4a", "bb", False), -- cgit v1.2.3 From f3f374e6b7e26bc93c8428c8cb7b8c210223b2f4 Mon Sep 17 00:00:00 2001 From: Andrew Martinek Date: Mon, 23 Sep 2019 12:27:12 -0400 Subject: Fleshed out flags a lot --- tools/script_extractor.py | 82 +++++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 38 deletions(-) (limited to 'tools/script_extractor.py') diff --git a/tools/script_extractor.py b/tools/script_extractor.py index d9cea6b..809b391 100644 --- a/tools/script_extractor.py +++ b/tools/script_extractor.py @@ -2,14 +2,8 @@ import argparse -#TODO: -# - Add arguments to all functions (have fun lol) -# - implement text # - (Possibly) add new type of word that looks for matches in the sym file -# - enter to continually generate more lines of the script -# - full script mode? -# - Make pretty!! - +# - add new one for event flag def decodeLine(scriptList, game_data, loc, ignore_broken): currLine = scriptList[game_data[loc]] ret = "\trun_script " + currLine[0] + "\n" @@ -20,7 +14,7 @@ def decodeLine(scriptList, game_data, loc, ignore_broken): ret += "\tdb $" + format(game_data[loc],"02x") + "\n" loc += 1 elif c == "w": - ret += "\tdb $" + format((game_data[loc] + (game_data[loc+1]<<8)),"04x") + "\n" + ret += "\tdw $" + format((game_data[loc] + (game_data[loc+1]<<8)),"04x") + "\n" loc += 2 elif c == "t": ret += "\ttx Text" + format((game_data[loc] + (game_data[loc+1]<<8)),"04x") + "\n" @@ -29,15 +23,27 @@ def decodeLine(scriptList, game_data, loc, ignore_broken): print("haven't updated data for this yet") if not ignore_broken: quit = True + else: + print("UNACCEPTED CHARACTER: " + c) return (loc, ret, quit) +def main_2(): # temp + with open("tcg.gbc", "rb") as file: + game_data = file.read() + loc = 0xcb37 + start = 0 + end = 0x33 # inclusive + for i in range(start,end+1): + print("\tflag_def EVENT_FLAG_" + format(i,"02X") + ","+(" "*7)+"$"\ + + format(game_data[loc+2*i],"02x") + ", %" + format(game_data[loc+2*i + 1],"08b")) + print("; " + format(loc + 2*(end+1),"02x")) def main(): scriptList = createList() with open("tcg.gbc", "rb") as file: game_data = file.read() - loc = 0xd52e + loc = 0xe2d1 auto = True end = False ignore_broken = True @@ -66,48 +72,48 @@ def createList(): # this is a func just so all this can go at the bottom # name, arg list, is an ender return [ ("OWScript_EndScriptLoop1", "", True), - ("OWScript_CloseTextBox", "", False), + ("OWScript_CloseAdvancedTextBox", "", False), ("OWScript_PrintTextString", "t", False), ("Func_ccdc", "bb", False), - ("OWScript_AskQuestionJump", "bbbb", False), # more complex behavior too (jumping) + ("OWScript_AskQuestionJump", "tw", False), # more complex behavior too (jumping) ("OWScript_StartBattle", "bbb", False), - ("Func_cd83", "bbbb", False), + ("OWScript_PrintVariableText", "tt", False), ("Func_cda8", "bbbb", False), ("OWScript_PrintTextCloseBox", "t", False), ("Func_cdcb", "bb", False), ("Func_ce26", "bb", False), - ("Func_ce84", "", False), + ("OWScript_CloseTextBox", "", False), ("OWScript_GiveBoosterPacks", "bbb", False), ("Func_cf0c", "bbb", False), # more complex behavior too (jumping) ("Func_cf12", "bbb", False), ("Func_cf3f", "b", False), ("Func_cf4c", "b", False), - ("Func_cf53", "d", False), # more complex behavior too (jumping) + ("Func_cf53", "w", False), # more complex behavior too (jumping) ("Func_cf7b", "", False), ("Func_cf2d", "bbbb", False), # more complex behavior too (jumping + ??) - ("Func_cf96", "d", False), # only jumps? still needs args to do that though + ("Func_cf96", "w", False), # only jumps? still needs args to do that though ("Func_cfc6", "b", False), ("Func_cfd4", "", False), ("Func_d00b", "", False), # includes something with random and extra data - ("Func_d025", "d", False), # possibly only jumps, still needs args - ("Func_d032", "d", False), # see above + ("Func_d025", "w", False), # possibly only jumps, still needs args + ("Func_d032", "w", False), # see above ("Func_d03f", "", False), - ("OWScript_ScriptJump", "d", False), # jumps to d + ("OWScript_Jump", "w", True), # jumps to d ("Func_d04f", "", False), ("Func_d055", "b", False), ("OWScript_MovePlayer", "bb", False), ("Func_cee2", "b", False), ("OWScript_SetDialogName", "b", False), - ("Func_d088", "bbb", False), + ("Func_d088", "bw", False), ("Func_d095", "bbb", False), ("Func_d0be", "bb", False), ("OWScript_DoFrames", "b", False), - ("Func_d0d9", "bbb", False), # jumps but still needs args - ("Func_d0f2", "bbb", False), # jumps but still needs args + ("Func_d0d9", "bbw", False), # jumps but still needs args + ("Func_d0f2", "bbw", False), # jumps but still needs args ("Func_ce4a", "bb", False), ("Func_ceba", "q", False), ("Func_d103", "q", False), - ("Func_d125", "q", False), + ("Func_d125", "b", False), ("Func_d135", "q", False), ("Func_d16b", "q", False), ("Func_cd4f", "q", False), @@ -116,7 +122,7 @@ def createList(): # this is a func just so all this can go at the bottom ("Func_cdd8", "q", False), ("Func_cdf5", "q", False), ("Func_d195", "q", False), - ("Func_d1ad", "q", False), + ("Func_d1ad", "", False), ("Func_d1b3", "q", False), ("OWScript_EndScriptCloseText", "", True), # it calls inc twice but it ends anyway? ("Func_d244", "q", False), @@ -124,14 +130,14 @@ def createList(): # this is a func just so all this can go at the bottom ("OWScript_OpenDeckMachine", "q", False), ("Func_d271", "q", False), ("Func_d36d", "bbbbb", False), - ("Func_ce6f", "q", False), + ("Func_ce6f", "bbb", False), ("Func_d209", "q", False), ("Func_d38f", "q", False), ("Func_d396", "q", False), ("Func_cd76", "q", False), ("Func_d39d", "q", False), ("Func_d3b9", "q", False), - ("Func_d3c9", "q", False), + ("OWScript_GivePCPack", "b", False), ("Func_d3d1", "q", False), ("Func_d3d4", "q", False), ("Func_d3e0", "", False), @@ -143,7 +149,7 @@ def createList(): # this is a func just so all this can go at the bottom ("Func_d429", "q", False), ("Func_d41d", "q", False), ("Func_d42f", "q", False), - ("Func_d435", "q", False), + ("Func_d435", "b", False), ("Func_cce4", "q", False), ("Func_d2f6", "q", False), ("Func_d317", "q", False), @@ -153,18 +159,18 @@ def createList(): # this is a func just so all this can go at the bottom ("OWScript_EndScriptLoop4", "q", True), ("OWScript_EndScriptLoop5", "q", True), ("OWScript_EndScriptLoop6", "q", True), - ("OWScript_CustomModifyEventFlags", "q", False), - ("Func_d460", "q", False), - ("OWScript_JumpIfFlagSet", "q", False), - ("Func_d484", "q", False), - ("Func_d49e", "q", False), - ("Func_d4a6", "q", False), - ("Func_d4ae", "q", False), - ("OWScript_SetEventFlags", "q", False), - ("Func_d4c3", "q", False), - ("Func_d4ca", "q", False), - ("OWScript_JumpIfFlagNotSet", "q", False), - ("Func_d452", "q", False), + ("OWScript_SetFlagValue", "bb", False), + ("OWScript_JumpIfFlagZero1", "q", False), + ("OWScript_JumpIfFlagNonzero1", "q", False), + ("OWScript_JumpIfFlagEqual", "bbw", False), # also capable of jumping + ("OWScript_JumpIfFlagNotEqual", "bbw", False), # jumps + ("OWScript_JumpIfFlagNotLessThan", "q", False), + ("OWScript_JumpIfFlagLessThan", "q", False), + ("OWScript_MaxOutFlagValue", "b", False), + ("OWScript_ZeroOutFlagValue", "q", False), + ("OWScript_JumpIfFlagNonzero2", "bw", False), + ("OWScript_JumpIfFlagZero2", "q", False), + ("OWScript_IncrementFlagValue", "b", False), ("OWScript_EndScriptLoop7", "q", True), ("OWScript_EndScriptLoop8", "q", True), ("OWScript_EndScriptLoop9", "q", True), -- cgit v1.2.3 From 516f47dd3efc34ee938b14f74e4c7eda0c19fc2d Mon Sep 17 00:00:00 2001 From: Andrew Martinek Date: Wed, 2 Oct 2019 23:50:47 -0400 Subject: layout another NPC script, make some assumptions about flags --- tools/script_extractor.py | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) (limited to 'tools/script_extractor.py') diff --git a/tools/script_extractor.py b/tools/script_extractor.py index 809b391..ce8764c 100644 --- a/tools/script_extractor.py +++ b/tools/script_extractor.py @@ -4,7 +4,7 @@ import argparse # - (Possibly) add new type of word that looks for matches in the sym file # - add new one for event flag -def decodeLine(scriptList, game_data, loc, ignore_broken): +def decodeLine(scriptList, game_data, loc, ignore_broken, branchList): currLine = scriptList[game_data[loc]] ret = "\trun_script " + currLine[0] + "\n" loc+=1 @@ -16,6 +16,14 @@ def decodeLine(scriptList, game_data, loc, ignore_broken): elif c == "w": ret += "\tdw $" + format((game_data[loc] + (game_data[loc+1]<<8)),"04x") + "\n" loc += 2 + elif c == "j": + wordLoc = (game_data[loc] + (game_data[loc+1]<<8)) + if wordLoc == 0000: + ret += "\tdw NO_JUMP\n" + else: + ret += "\tdw .ows_" + format(wordLoc+0x8000,"04x") + "\n" + branchList.append(wordLoc) + loc += 2 elif c == "t": ret += "\ttx Text" + format((game_data[loc] + (game_data[loc+1]<<8)),"04x") + "\n" loc += 2 @@ -27,14 +35,14 @@ def decodeLine(scriptList, game_data, loc, ignore_broken): print("UNACCEPTED CHARACTER: " + c) return (loc, ret, quit) -def main_2(): # temp +def main2(): # temp with open("tcg.gbc", "rb") as file: game_data = file.read() loc = 0xcb37 - start = 0 - end = 0x33 # inclusive + start = 0x36 + end = 0x76 # inclusive for i in range(start,end+1): - print("\tflag_def EVENT_FLAG_" + format(i,"02X") + ","+(" "*7)+"$"\ + print("\tflag_def EVENT_FLAG_" + format(i,"02X") + ","+(" "*11)+"$"\ + format(game_data[loc+2*i],"02x") + ", %" + format(game_data[loc+2*i + 1],"08b")) print("; " + format(loc + 2*(end+1),"02x")) @@ -43,13 +51,19 @@ def main(): with open("tcg.gbc", "rb") as file: game_data = file.read() - loc = 0xe2d1 auto = True end = False ignore_broken = True + branchList = [0x65ee] # all are bank 3 offsets + while (len(branchList) > 0): + loc = branchList.pop(0) + 0x8000 + printScript(game_data, loc, auto, end, ignore_broken, scriptList, branchList) + +def printScript(game_data, loc, auto, end, ignore_broken, scriptList, branchList): script = "" if game_data[loc] != 0xe7: - print("Error: first byte was not start_script") + #print("Error: first byte was not start_script") + print(".ows_" + format(loc,"04x")) else: # TODO this is hacky please don't do this @@ -59,7 +73,7 @@ def main(): loc += 1 print("\tstart_script") while not end: - loc, outstr, end = decodeLine(scriptList,game_data,loc,ignore_broken) + loc, outstr, end = decodeLine(scriptList,game_data,loc,ignore_broken,branchList) outstr = outstr[:-1] # [:-1] strips the newline at the end if auto: print(outstr) @@ -75,11 +89,11 @@ def createList(): # this is a func just so all this can go at the bottom ("OWScript_CloseAdvancedTextBox", "", False), ("OWScript_PrintTextString", "t", False), ("Func_ccdc", "bb", False), - ("OWScript_AskQuestionJump", "tw", False), # more complex behavior too (jumping) + ("OWScript_AskQuestionJump", "tj", False), # more complex behavior too (jumping) ("OWScript_StartBattle", "bbb", False), ("OWScript_PrintVariableText", "tt", False), ("Func_cda8", "bbbb", False), - ("OWScript_PrintTextCloseBox", "t", False), + ("OWScript_PrintTextCloseBox", "t", True), ("Func_cdcb", "bb", False), ("Func_ce26", "bb", False), ("OWScript_CloseTextBox", "", False), @@ -162,14 +176,14 @@ def createList(): # this is a func just so all this can go at the bottom ("OWScript_SetFlagValue", "bb", False), ("OWScript_JumpIfFlagZero1", "q", False), ("OWScript_JumpIfFlagNonzero1", "q", False), - ("OWScript_JumpIfFlagEqual", "bbw", False), # also capable of jumping - ("OWScript_JumpIfFlagNotEqual", "bbw", False), # jumps - ("OWScript_JumpIfFlagNotLessThan", "q", False), - ("OWScript_JumpIfFlagLessThan", "q", False), + ("OWScript_JumpIfFlagEqual", "bbj", False), # also capable of jumping + ("OWScript_JumpIfFlagNotEqual", "bbj", False), # jumps + ("OWScript_JumpIfFlagNotLessThan", "bbj", False), + ("OWScript_JumpIfFlagLessThan", "bbj", False), ("OWScript_MaxOutFlagValue", "b", False), ("OWScript_ZeroOutFlagValue", "q", False), - ("OWScript_JumpIfFlagNonzero2", "bw", False), - ("OWScript_JumpIfFlagZero2", "q", False), + ("OWScript_JumpIfFlagNonzero2", "bj", False), + ("OWScript_JumpIfFlagZero2", "bj", False), ("OWScript_IncrementFlagValue", "b", False), ("OWScript_EndScriptLoop7", "q", True), ("OWScript_EndScriptLoop8", "q", True), -- cgit v1.2.3 From 8c416b556348fe9a98e28fd0ba5628b5c74edcc8 Mon Sep 17 00:00:00 2001 From: Andrew Martinek Date: Thu, 3 Oct 2019 22:04:51 -0400 Subject: Ronald scripts and overworld data routines. Also made script extractor better --- tools/script_extractor.py | 53 +++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 22 deletions(-) (limited to 'tools/script_extractor.py') diff --git a/tools/script_extractor.py b/tools/script_extractor.py index ce8764c..e588bc1 100644 --- a/tools/script_extractor.py +++ b/tools/script_extractor.py @@ -1,9 +1,18 @@ #!/usr/bin/env python3 - +############################################################################### +###### Use: python3 tools/script_extractor --noauto --error location ###### +###### --noauto turns off automatic script parsing (enter to continue) ###### +###### --error stops execution if an error occurs ###### +###### location can be local to bank or global. This program assumes ###### +###### every script is in bank 3, which seems to be the case. ###### +###### ###### +###### Script list is a work in progress. The following arguments are ###### +###### accepted and accounted for. ###### +###### b - byte w - word j - jump (within script) t - text (tx) ###### +###### q - Used when the script's arguments have not been determined yet ###### +############################################################################### import argparse -# - (Possibly) add new type of word that looks for matches in the sym file -# - add new one for event flag def decodeLine(scriptList, game_data, loc, ignore_broken, branchList): currLine = scriptList[game_data[loc]] ret = "\trun_script " + currLine[0] + "\n" @@ -34,27 +43,27 @@ def decodeLine(scriptList, game_data, loc, ignore_broken, branchList): else: print("UNACCEPTED CHARACTER: " + c) return (loc, ret, quit) - -def main2(): # temp - with open("tcg.gbc", "rb") as file: - game_data = file.read() - loc = 0xcb37 - start = 0x36 - end = 0x76 # inclusive - for i in range(start,end+1): - print("\tflag_def EVENT_FLAG_" + format(i,"02X") + ","+(" "*11)+"$"\ - + format(game_data[loc+2*i],"02x") + ", %" + format(game_data[loc+2*i + 1],"08b")) - print("; " + format(loc + 2*(end+1),"02x")) def main(): scriptList = createList() + branchList = [] + + parser = argparse.ArgumentParser(description='Pokemon TCG Script Extractor') + parser.add_argument('--noauto', action='store_true', help='turns off automatic script parsing') + parser.add_argument('--error', action='store_true', help='stops execution if an error occurs') + parser.add_argument('location', help='location to extract from. May be local to bank or global.') + args = parser.parse_args() + loc = int(args.location,0) + if loc > 0x7fff: + # Must be a global location + loc -= 0x8000 + branchList.append(loc) with open("tcg.gbc", "rb") as file: game_data = file.read() auto = True end = False ignore_broken = True - branchList = [0x65ee] # all are bank 3 offsets while (len(branchList) > 0): loc = branchList.pop(0) + 0x8000 printScript(game_data, loc, auto, end, ignore_broken, scriptList, branchList) @@ -94,14 +103,14 @@ def createList(): # this is a func just so all this can go at the bottom ("OWScript_PrintVariableText", "tt", False), ("Func_cda8", "bbbb", False), ("OWScript_PrintTextCloseBox", "t", True), - ("Func_cdcb", "bb", False), + ("Func_cdcb", "", False), ("Func_ce26", "bb", False), ("OWScript_CloseTextBox", "", False), ("OWScript_GiveBoosterPacks", "bbb", False), ("Func_cf0c", "bbb", False), # more complex behavior too (jumping) ("Func_cf12", "bbb", False), - ("Func_cf3f", "b", False), - ("Func_cf4c", "b", False), + ("OWScript_GiveCard", "b", False), + ("OWScript_TakeCard", "b", False), ("Func_cf53", "w", False), # more complex behavior too (jumping) ("Func_cf7b", "", False), ("Func_cf2d", "bbbb", False), # more complex behavior too (jumping + ??) @@ -112,7 +121,7 @@ def createList(): # this is a func just so all this can go at the bottom ("Func_d025", "w", False), # possibly only jumps, still needs args ("Func_d032", "w", False), # see above ("Func_d03f", "", False), - ("OWScript_Jump", "w", True), # jumps to d + ("OWScript_Jump", "j", True), # jumps to d ("Func_d04f", "", False), ("Func_d055", "b", False), ("OWScript_MovePlayer", "bb", False), @@ -128,7 +137,7 @@ def createList(): # this is a func just so all this can go at the bottom ("Func_ceba", "q", False), ("Func_d103", "q", False), ("Func_d125", "b", False), - ("Func_d135", "q", False), + ("Func_d135", "b", False), ("Func_d16b", "q", False), ("Func_cd4f", "q", False), ("Func_cd94", "q", False), @@ -161,10 +170,10 @@ def createList(): # this is a func just so all this can go at the bottom ("Func_d416", "q", False), ("Func_d423", "q", False), ("Func_d429", "q", False), - ("Func_d41d", "q", False), + ("Func_d41d", "", False), ("Func_d42f", "q", False), ("Func_d435", "b", False), - ("Func_cce4", "q", False), + ("Func_cce4", "tj", False), ("Func_d2f6", "q", False), ("Func_d317", "q", False), ("Func_d43d", "q", False), -- cgit v1.2.3 From fda59356c20813bb57d59de8d9b2b100f0fe275d Mon Sep 17 00:00:00 2001 From: Andrew Martinek Date: Sun, 6 Oct 2019 11:24:18 -0400 Subject: Uncovered a lot of NPC map data and loading functions. --- tools/script_extractor.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'tools/script_extractor.py') diff --git a/tools/script_extractor.py b/tools/script_extractor.py index e588bc1..49d5e58 100644 --- a/tools/script_extractor.py +++ b/tools/script_extractor.py @@ -59,16 +59,25 @@ def main(): loc -= 0x8000 branchList.append(loc) - with open("tcg.gbc", "rb") as file: + # this is a list of every start location we've read to avoid infinite loops + exploredList = [] + + with open("baserom.gbc", "rb") as file: game_data = file.read() + auto = True end = False ignore_broken = True while (len(branchList) > 0): loc = branchList.pop(0) + 0x8000 - printScript(game_data, loc, auto, end, ignore_broken, scriptList, branchList) + printScript(game_data, loc, auto, end, ignore_broken, scriptList,\ + branchList, exploredList) -def printScript(game_data, loc, auto, end, ignore_broken, scriptList, branchList): +def printScript(game_data, loc, auto, end, ignore_broken, scriptList, \ + branchList, exploredList): + if loc in exploredList: + return + exploredList.append(loc) script = "" if game_data[loc] != 0xe7: #print("Error: first byte was not start_script") @@ -89,7 +98,7 @@ def printScript(game_data, loc, auto, end, ignore_broken, scriptList, branchList else: input(outstr) print("; " + hex(loc)) - + def createList(): # this is a func just so all this can go at the bottom # name, arg list, is an ender @@ -127,7 +136,7 @@ def createList(): # this is a func just so all this can go at the bottom ("OWScript_MovePlayer", "bb", False), ("Func_cee2", "b", False), ("OWScript_SetDialogName", "b", False), - ("Func_d088", "bw", False), + ("Func_d088", "bj", False), ("Func_d095", "bbb", False), ("Func_d0be", "bb", False), ("OWScript_DoFrames", "b", False), @@ -161,7 +170,7 @@ def createList(): # this is a func just so all this can go at the bottom ("Func_d39d", "q", False), ("Func_d3b9", "q", False), ("OWScript_GivePCPack", "b", False), - ("Func_d3d1", "q", False), + ("OWScript_nop", "", False), ("Func_d3d4", "q", False), ("Func_d3e0", "", False), ("Func_d3fe", "q", False), @@ -175,7 +184,7 @@ def createList(): # this is a func just so all this can go at the bottom ("Func_d435", "b", False), ("Func_cce4", "tj", False), ("Func_d2f6", "q", False), - ("Func_d317", "q", False), + ("Func_d317", "", False), ("Func_d43d", "q", False), ("OWScript_EndScriptLoop2", "q", True), ("OWScript_EndScriptLoop3", "q", True), -- cgit v1.2.3 From cb88ee5a13498f060da1be80eb0cc0fcd1357a05 Mon Sep 17 00:00:00 2001 From: Andrew Martinek Date: Tue, 8 Oct 2019 00:20:52 -0400 Subject: Created python script to calculate progress and documented some scripts --- tools/script_extractor.py | 245 +++++++++++++++++++++++++--------------------- 1 file changed, 136 insertions(+), 109 deletions(-) (limited to 'tools/script_extractor.py') diff --git a/tools/script_extractor.py b/tools/script_extractor.py index 49d5e58..7f80b01 100644 --- a/tools/script_extractor.py +++ b/tools/script_extractor.py @@ -9,10 +9,18 @@ ###### Script list is a work in progress. The following arguments are ###### ###### accepted and accounted for. ###### ###### b - byte w - word j - jump (within script) t - text (tx) ###### +###### f - flag d - direction i - decimal byte ###### ###### q - Used when the script's arguments have not been determined yet ###### ############################################################################### import argparse +# Quit Types +DO_NOT_QUIT = 0 +QUIT_CONTINUE_CODE = 1 +QUIT_JUMP = 2 +QUIT_SPECIAL = 3 +QUIT_DEBUG = -1 + def decodeLine(scriptList, game_data, loc, ignore_broken, branchList): currLine = scriptList[game_data[loc]] ret = "\trun_script " + currLine[0] + "\n" @@ -22,6 +30,9 @@ def decodeLine(scriptList, game_data, loc, ignore_broken, branchList): if c == "b": ret += "\tdb $" + format(game_data[loc],"02x") + "\n" loc += 1 + elif c == "i": + ret += "\tdb " + str(game_data[loc]) + "\n" + loc += 1 elif c == "w": ret += "\tdw $" + format((game_data[loc] + (game_data[loc+1]<<8)),"04x") + "\n" loc += 2 @@ -34,12 +45,23 @@ def decodeLine(scriptList, game_data, loc, ignore_broken, branchList): branchList.append(wordLoc) loc += 2 elif c == "t": - ret += "\ttx Text" + format((game_data[loc] + (game_data[loc+1]<<8)),"04x") + "\n" + addr = (game_data[loc] + (game_data[loc+1]<<8)) + if addr == 0: + ret += "\tdw $0000\n" + else: + ret += "\ttx Text" + format(addr,"04x") + "\n" loc += 2 + elif c == "f": + ret += "\tdb EVENT_FLAG_" + format(game_data[loc],"02X") + "\n" + loc += 1 + elif c == "d": + dir_list = ["NORTH","EAST","SOUTH","WEST"] + ret += "\tdb " + dir_list[game_data[loc]] + "\n" + loc += 1 elif c == "q": print("haven't updated data for this yet") if not ignore_broken: - quit = True + quit = QUIT_DEBUG else: print("UNACCEPTED CHARACTER: " + c) return (loc, ret, quit) @@ -69,6 +91,7 @@ def main(): end = False ignore_broken = True while (len(branchList) > 0): + branchList.sort() # export parts in order somewhat loc = branchList.pop(0) + 0x8000 printScript(game_data, loc, auto, end, ignore_broken, scriptList,\ branchList, exploredList) @@ -90,123 +113,127 @@ def printScript(game_data, loc, auto, end, ignore_broken, scriptList, \ print("OWSequence_" + ls + ": ; " + ls + " (3:" + lsa + ")" ) loc += 1 print("\tstart_script") - while not end: + while end == DO_NOT_QUIT: loc, outstr, end = decodeLine(scriptList,game_data,loc,ignore_broken,branchList) outstr = outstr[:-1] # [:-1] strips the newline at the end if auto: print(outstr) else: input(outstr) - print("; " + hex(loc)) - + warning = "" + if end == QUIT_CONTINUE_CODE: + warning = " WARNING: There is probably regular assembly here" + #elif end == QUIT_SPECIAL: + # warning = "\nWARNING: This will return to the place that began this Sequence" + print("; " + hex(loc) + warning) def createList(): # this is a func just so all this can go at the bottom # name, arg list, is an ender return [ - ("OWScript_EndScriptLoop1", "", True), - ("OWScript_CloseAdvancedTextBox", "", False), - ("OWScript_PrintTextString", "t", False), - ("Func_ccdc", "bb", False), - ("OWScript_AskQuestionJump", "tj", False), # more complex behavior too (jumping) - ("OWScript_StartBattle", "bbb", False), - ("OWScript_PrintVariableText", "tt", False), - ("Func_cda8", "bbbb", False), - ("OWScript_PrintTextCloseBox", "t", True), - ("Func_cdcb", "", False), - ("Func_ce26", "bb", False), - ("OWScript_CloseTextBox", "", False), - ("OWScript_GiveBoosterPacks", "bbb", False), - ("Func_cf0c", "bbb", False), # more complex behavior too (jumping) - ("Func_cf12", "bbb", False), - ("OWScript_GiveCard", "b", False), - ("OWScript_TakeCard", "b", False), - ("Func_cf53", "w", False), # more complex behavior too (jumping) - ("Func_cf7b", "", False), - ("Func_cf2d", "bbbb", False), # more complex behavior too (jumping + ??) - ("Func_cf96", "w", False), # only jumps? still needs args to do that though - ("Func_cfc6", "b", False), - ("Func_cfd4", "", False), - ("Func_d00b", "", False), # includes something with random and extra data - ("Func_d025", "w", False), # possibly only jumps, still needs args - ("Func_d032", "w", False), # see above - ("Func_d03f", "", False), - ("OWScript_Jump", "j", True), # jumps to d - ("Func_d04f", "", False), - ("Func_d055", "b", False), - ("OWScript_MovePlayer", "bb", False), - ("Func_cee2", "b", False), - ("OWScript_SetDialogName", "b", False), - ("Func_d088", "bj", False), - ("Func_d095", "bbb", False), - ("Func_d0be", "bb", False), - ("OWScript_DoFrames", "b", False), - ("Func_d0d9", "bbw", False), # jumps but still needs args - ("Func_d0f2", "bbw", False), # jumps but still needs args - ("Func_ce4a", "bb", False), - ("Func_ceba", "q", False), - ("Func_d103", "q", False), - ("Func_d125", "b", False), - ("Func_d135", "b", False), - ("Func_d16b", "q", False), - ("Func_cd4f", "q", False), - ("Func_cd94", "q", False), - ("Func_ce52", "q", False), - ("Func_cdd8", "q", False), - ("Func_cdf5", "q", False), - ("Func_d195", "q", False), - ("Func_d1ad", "", False), - ("Func_d1b3", "q", False), - ("OWScript_EndScriptCloseText", "", True), # it calls inc twice but it ends anyway? - ("Func_d244", "q", False), - ("Func_d24c", "q", False), - ("OWScript_OpenDeckMachine", "q", False), - ("Func_d271", "q", False), - ("Func_d36d", "bbbbb", False), - ("Func_ce6f", "bbb", False), - ("Func_d209", "q", False), - ("Func_d38f", "q", False), - ("Func_d396", "q", False), - ("Func_cd76", "q", False), - ("Func_d39d", "q", False), - ("Func_d3b9", "q", False), - ("OWScript_GivePCPack", "b", False), - ("OWScript_nop", "", False), - ("Func_d3d4", "q", False), - ("Func_d3e0", "", False), - ("Func_d3fe", "q", False), - ("Func_d408", "q", False), - ("Func_d40f", "q", False), - ("Func_d416", "q", False), - ("Func_d423", "q", False), - ("Func_d429", "q", False), - ("Func_d41d", "", False), - ("Func_d42f", "q", False), - ("Func_d435", "b", False), - ("Func_cce4", "tj", False), - ("Func_d2f6", "q", False), - ("Func_d317", "", False), - ("Func_d43d", "q", False), - ("OWScript_EndScriptLoop2", "q", True), - ("OWScript_EndScriptLoop3", "q", True), - ("OWScript_EndScriptLoop4", "q", True), - ("OWScript_EndScriptLoop5", "q", True), - ("OWScript_EndScriptLoop6", "q", True), - ("OWScript_SetFlagValue", "bb", False), - ("OWScript_JumpIfFlagZero1", "q", False), - ("OWScript_JumpIfFlagNonzero1", "q", False), - ("OWScript_JumpIfFlagEqual", "bbj", False), # also capable of jumping - ("OWScript_JumpIfFlagNotEqual", "bbj", False), # jumps - ("OWScript_JumpIfFlagNotLessThan", "bbj", False), - ("OWScript_JumpIfFlagLessThan", "bbj", False), - ("OWScript_MaxOutFlagValue", "b", False), - ("OWScript_ZeroOutFlagValue", "q", False), - ("OWScript_JumpIfFlagNonzero2", "bj", False), - ("OWScript_JumpIfFlagZero2", "bj", False), - ("OWScript_IncrementFlagValue", "b", False), - ("OWScript_EndScriptLoop7", "q", True), - ("OWScript_EndScriptLoop8", "q", True), - ("OWScript_EndScriptLoop9", "q", True), - ("OWScript_EndScriptLoop10", "q", True) + ("OWScript_EndScriptLoop1", "", QUIT_CONTINUE_CODE), + ("OWScript_CloseAdvancedTextBox", "", DO_NOT_QUIT), + ("OWScript_PrintTextString", "t", DO_NOT_QUIT), + ("Func_ccdc", "bb", DO_NOT_QUIT), + ("OWScript_AskQuestionJump", "tj", DO_NOT_QUIT), # more complex behavior too (jumping) + ("OWScript_StartBattle", "bbb", DO_NOT_QUIT), + ("OWScript_PrintVariableText", "tt", DO_NOT_QUIT), + ("Func_cda8", "bbbb", DO_NOT_QUIT), + ("OWScript_PrintTextCloseBox", "t", QUIT_CONTINUE_CODE), + ("Func_cdcb", "", DO_NOT_QUIT), + ("Func_ce26", "bb", DO_NOT_QUIT), + ("OWScript_CloseTextBox", "", DO_NOT_QUIT), + ("OWScript_GiveBoosterPacks", "bbb", DO_NOT_QUIT), + ("Func_cf0c", "bbb", DO_NOT_QUIT), # more complex behavior too (jumping) + ("Func_cf12", "bbb", DO_NOT_QUIT), + ("OWScript_GiveCard", "b", DO_NOT_QUIT), + ("OWScript_TakeCard", "b", DO_NOT_QUIT), + ("Func_cf53", "w", DO_NOT_QUIT), # more complex behavior too (jumping) + ("Func_cf7b", "", DO_NOT_QUIT), + ("Func_cf2d", "bbbb", DO_NOT_QUIT), # more complex behavior too (jumping + ??) + ("Func_cf96", "w", DO_NOT_QUIT), # only jumps? still needs args to do that though + ("Func_cfc6", "b", DO_NOT_QUIT), + ("Func_cfd4", "", DO_NOT_QUIT), + ("Func_d00b", "", DO_NOT_QUIT), # includes something with random and extra data + ("Func_d025", "w", DO_NOT_QUIT), # possibly only jumps, still needs args + ("Func_d032", "w", DO_NOT_QUIT), # see above + ("Func_d03f", "", DO_NOT_QUIT), + ("OWScript_Jump", "j", QUIT_JUMP), # jumps to d + ("Func_d04f", "", DO_NOT_QUIT), + ("OWScript_SetPlayerDirection", "d", DO_NOT_QUIT), + ("OWScript_MovePlayer", "db", DO_NOT_QUIT), + ("OWScript_ShowCardReceivedScreen", "b", DO_NOT_QUIT), + ("OWScript_SetDialogName", "b", DO_NOT_QUIT), + ("OWScript_SetNextNPCandOWSequence", "bj", DO_NOT_QUIT), + ("Func_d095", "bbb", DO_NOT_QUIT), + ("Func_d0be", "bb", DO_NOT_QUIT), + ("OWScript_DoFrames", "b", DO_NOT_QUIT), + ("Func_d0d9", "bbw", DO_NOT_QUIT), # jumps but still needs args + ("OWScript_JumpIfPlayerCoordMatches", "iij", DO_NOT_QUIT), # jumps but still needs args + ("Func_ce4a", "bb", DO_NOT_QUIT), + ("OWScript_GiveOneOfEachTrainerBooster", "", DO_NOT_QUIT), + ("Func_d103", "q", DO_NOT_QUIT), + ("Func_d125", "b", DO_NOT_QUIT), + ("Func_d135", "b", DO_NOT_QUIT), + ("Func_d16b", "q", DO_NOT_QUIT), + ("Func_cd4f", "q", DO_NOT_QUIT), + ("Func_cd94", "q", DO_NOT_QUIT), + ("Func_ce52", "q", DO_NOT_QUIT), + ("Func_cdd8", "q", DO_NOT_QUIT), + ("Func_cdf5", "q", DO_NOT_QUIT), + ("Func_d195", "q", DO_NOT_QUIT), + ("Func_d1ad", "", DO_NOT_QUIT), + ("Func_d1b3", "q", DO_NOT_QUIT), + ("OWScript_QuitScriptFully", "", QUIT_SPECIAL), # it calls inc twice but it ends anyway? + ("Func_d244", "q", DO_NOT_QUIT), + ("Func_d24c", "q", DO_NOT_QUIT), + ("OWScript_OpenDeckMachine", "q", DO_NOT_QUIT), + ("Func_d271", "q", DO_NOT_QUIT), + ("OWScript_EnterMap", "bbood", DO_NOT_QUIT), + ("Func_ce6f", "bbb", DO_NOT_QUIT), + ("Func_d209", "q", DO_NOT_QUIT), + ("Func_d38f", "q", DO_NOT_QUIT), + ("Func_d396", "q", DO_NOT_QUIT), + ("Func_cd76", "q", DO_NOT_QUIT), + ("Func_d39d", "q", DO_NOT_QUIT), + ("Func_d3b9", "q", DO_NOT_QUIT), + ("OWScript_GivePCPack", "b", DO_NOT_QUIT), + ("OWScript_nop", "", DO_NOT_QUIT), + ("Func_d3d4", "q", DO_NOT_QUIT), + ("Func_d3e0", "", DO_NOT_QUIT), + ("Func_d3fe", "q", DO_NOT_QUIT), + ("Func_d408", "b", DO_NOT_QUIT), + ("Func_d40f", "q", DO_NOT_QUIT), + ("Func_d416", "q", DO_NOT_QUIT), + ("Func_d423", "q", DO_NOT_QUIT), + ("Func_d429", "q", DO_NOT_QUIT), + ("Func_d41d", "", DO_NOT_QUIT), + ("Func_d42f", "q", DO_NOT_QUIT), + ("Func_d435", "b", DO_NOT_QUIT), + ("OWScript_AskQuestionJumpDefaultYes", "tj", DO_NOT_QUIT), + ("Func_d2f6", "q", DO_NOT_QUIT), + ("Func_d317", "", DO_NOT_QUIT), + ("Func_d43d", "q", DO_NOT_QUIT), + ("OWScript_EndScriptLoop2", "q", QUIT_CONTINUE_CODE), + ("OWScript_EndScriptLoop3", "q", QUIT_CONTINUE_CODE), + ("OWScript_EndScriptLoop4", "q", QUIT_CONTINUE_CODE), + ("OWScript_EndScriptLoop5", "q", QUIT_CONTINUE_CODE), + ("OWScript_EndScriptLoop6", "q", QUIT_CONTINUE_CODE), + ("OWScript_SetFlagValue", "fb", DO_NOT_QUIT), + ("OWScript_JumpIfFlagZero1", "q", DO_NOT_QUIT), + ("OWScript_JumpIfFlagNonzero1", "q", DO_NOT_QUIT), + ("OWScript_JumpIfFlagEqual", "fbj", DO_NOT_QUIT), # also capable of jumping + ("OWScript_JumpIfFlagNotEqual", "fbj", DO_NOT_QUIT), # jumps + ("OWScript_JumpIfFlagNotLessThan", "fbj", DO_NOT_QUIT), + ("OWScript_JumpIfFlagLessThan", "fbj", DO_NOT_QUIT), + ("OWScript_MaxOutFlagValue", "f", DO_NOT_QUIT), + ("OWScript_ZeroOutFlagValue", "q", DO_NOT_QUIT), + ("OWScript_JumpIfFlagNonzero2", "fj", DO_NOT_QUIT), + ("OWScript_JumpIfFlagZero2", "fj", DO_NOT_QUIT), + ("OWScript_IncrementFlagValue", "f", DO_NOT_QUIT), + ("OWScript_EndScriptLoop7", "q", QUIT_CONTINUE_CODE), + ("OWScript_EndScriptLoop8", "q", QUIT_CONTINUE_CODE), + ("OWScript_EndScriptLoop9", "q", QUIT_CONTINUE_CODE), + ("OWScript_EndScriptLoop10", "q", QUIT_CONTINUE_CODE) ] main() -- cgit v1.2.3 From 6a51305cf5ad95f93bc80122939744ad77b30b79 Mon Sep 17 00:00:00 2001 From: Andrew Martinek Date: Wed, 9 Oct 2019 00:27:25 -0400 Subject: More features for progress.py, added better argparsing for both! --- tools/script_extractor.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'tools/script_extractor.py') diff --git a/tools/script_extractor.py b/tools/script_extractor.py index 7f80b01..a4e933e 100644 --- a/tools/script_extractor.py +++ b/tools/script_extractor.py @@ -73,6 +73,7 @@ def main(): parser = argparse.ArgumentParser(description='Pokemon TCG Script Extractor') parser.add_argument('--noauto', action='store_true', help='turns off automatic script parsing') parser.add_argument('--error', action='store_true', help='stops execution if an error occurs') + parser.add_argument('-r', '--rom', default="baserom.gbc", help='rom file to extract script from') parser.add_argument('location', help='location to extract from. May be local to bank or global.') args = parser.parse_args() loc = int(args.location,0) @@ -84,12 +85,12 @@ def main(): # this is a list of every start location we've read to avoid infinite loops exploredList = [] - with open("baserom.gbc", "rb") as file: + with open(args.rom, "rb") as file: game_data = file.read() - auto = True + auto = not args.noauto end = False - ignore_broken = True + ignore_broken = not args.error while (len(branchList) > 0): branchList.sort() # export parts in order somewhat loc = branchList.pop(0) + 0x8000 -- cgit v1.2.3 From 299f013b8b14184b9f06da3b89ba87ce2ba9e0f3 Mon Sep 17 00:00:00 2001 From: Andrew Martinek Date: Sun, 13 Oct 2019 19:39:13 -0400 Subject: More scripts, start to figure out mapscripts --- tools/script_extractor.py | 54 ++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 24 deletions(-) (limited to 'tools/script_extractor.py') diff --git a/tools/script_extractor.py b/tools/script_extractor.py index a4e933e..c55b8cd 100644 --- a/tools/script_extractor.py +++ b/tools/script_extractor.py @@ -89,20 +89,21 @@ def main(): game_data = file.read() auto = not args.noauto - end = False + end = DO_NOT_QUIT ignore_broken = not args.error - while (len(branchList) > 0): + while (len(branchList) > 0 and end != QUIT_DEBUG): branchList.sort() # export parts in order somewhat loc = branchList.pop(0) + 0x8000 - printScript(game_data, loc, auto, end, ignore_broken, scriptList,\ + end = printScript(game_data, loc, auto, ignore_broken, scriptList,\ branchList, exploredList) -def printScript(game_data, loc, auto, end, ignore_broken, scriptList, \ +def printScript(game_data, loc, auto, ignore_broken, scriptList, \ branchList, exploredList): if loc in exploredList: return exploredList.append(loc) script = "" + end = DO_NOT_QUIT if game_data[loc] != 0xe7: #print("Error: first byte was not start_script") print(".ows_" + format(loc,"04x")) @@ -124,28 +125,33 @@ def printScript(game_data, loc, auto, end, ignore_broken, scriptList, \ warning = "" if end == QUIT_CONTINUE_CODE: warning = " WARNING: There is probably regular assembly here" - #elif end == QUIT_SPECIAL: - # warning = "\nWARNING: This will return to the place that began this Sequence" + print("; " + hex(loc) + warning) + # if the next byte is a ret, print it for the continue_code case + if game_data[loc] == 0xc9: + print("\tret") + + return end + def createList(): # this is a func just so all this can go at the bottom # name, arg list, is an ender return [ ("OWScript_EndScriptLoop1", "", QUIT_CONTINUE_CODE), ("OWScript_CloseAdvancedTextBox", "", DO_NOT_QUIT), ("OWScript_PrintTextString", "t", DO_NOT_QUIT), - ("Func_ccdc", "bb", DO_NOT_QUIT), + ("Func_ccdc", "t", DO_NOT_QUIT), ("OWScript_AskQuestionJump", "tj", DO_NOT_QUIT), # more complex behavior too (jumping) ("OWScript_StartBattle", "bbb", DO_NOT_QUIT), ("OWScript_PrintVariableText", "tt", DO_NOT_QUIT), ("Func_cda8", "bbbb", DO_NOT_QUIT), - ("OWScript_PrintTextCloseBox", "t", QUIT_CONTINUE_CODE), + ("OWScript_PrintTextQuitFully", "t", QUIT_SPECIAL), ("Func_cdcb", "", DO_NOT_QUIT), ("Func_ce26", "bb", DO_NOT_QUIT), ("OWScript_CloseTextBox", "", DO_NOT_QUIT), ("OWScript_GiveBoosterPacks", "bbb", DO_NOT_QUIT), - ("Func_cf0c", "bbb", DO_NOT_QUIT), # more complex behavior too (jumping) - ("Func_cf12", "bbb", DO_NOT_QUIT), + ("Func_cf0c", "bj", DO_NOT_QUIT), # more complex behavior too (jumping) + ("Func_cf12", "bj", DO_NOT_QUIT), ("OWScript_GiveCard", "b", DO_NOT_QUIT), ("OWScript_TakeCard", "b", DO_NOT_QUIT), ("Func_cf53", "w", DO_NOT_QUIT), # more complex behavior too (jumping) @@ -159,12 +165,12 @@ def createList(): # this is a func just so all this can go at the bottom ("Func_d032", "w", DO_NOT_QUIT), # see above ("Func_d03f", "", DO_NOT_QUIT), ("OWScript_Jump", "j", QUIT_JUMP), # jumps to d - ("Func_d04f", "", DO_NOT_QUIT), + ("OWScript_TryGiveMedalPCPacks", "", DO_NOT_QUIT), ("OWScript_SetPlayerDirection", "d", DO_NOT_QUIT), ("OWScript_MovePlayer", "db", DO_NOT_QUIT), ("OWScript_ShowCardReceivedScreen", "b", DO_NOT_QUIT), ("OWScript_SetDialogName", "b", DO_NOT_QUIT), - ("OWScript_SetNextNPCandOWSequence", "bj", DO_NOT_QUIT), + ("OWScript_SetNextNPCandOWSequence", "bw", DO_NOT_QUIT), ("Func_d095", "bbb", DO_NOT_QUIT), ("Func_d0be", "bb", DO_NOT_QUIT), ("OWScript_DoFrames", "b", DO_NOT_QUIT), @@ -184,31 +190,31 @@ def createList(): # this is a func just so all this can go at the bottom ("Func_d195", "q", DO_NOT_QUIT), ("Func_d1ad", "", DO_NOT_QUIT), ("Func_d1b3", "q", DO_NOT_QUIT), - ("OWScript_QuitScriptFully", "", QUIT_SPECIAL), # it calls inc twice but it ends anyway? + ("OWScript_QuitScriptFully", "", QUIT_SPECIAL), ("Func_d244", "q", DO_NOT_QUIT), ("Func_d24c", "q", DO_NOT_QUIT), - ("OWScript_OpenDeckMachine", "q", DO_NOT_QUIT), + ("OWScript_OpenDeckMachine", "b", DO_NOT_QUIT), ("Func_d271", "q", DO_NOT_QUIT), ("OWScript_EnterMap", "bbood", DO_NOT_QUIT), - ("Func_ce6f", "bbb", DO_NOT_QUIT), + ("Func_ce6f", "bd", DO_NOT_QUIT), ("Func_d209", "q", DO_NOT_QUIT), ("Func_d38f", "q", DO_NOT_QUIT), - ("Func_d396", "q", DO_NOT_QUIT), - ("Func_cd76", "q", DO_NOT_QUIT), - ("Func_d39d", "q", DO_NOT_QUIT), + ("Func_d396", "b", DO_NOT_QUIT), + ("Func_cd76", "", DO_NOT_QUIT), + ("Func_d39d", "b", DO_NOT_QUIT), ("Func_d3b9", "q", DO_NOT_QUIT), - ("OWScript_GivePCPack", "b", DO_NOT_QUIT), + ("OWScript_TryGivePCPack", "b", DO_NOT_QUIT), ("OWScript_nop", "", DO_NOT_QUIT), ("Func_d3d4", "q", DO_NOT_QUIT), ("Func_d3e0", "", DO_NOT_QUIT), ("Func_d3fe", "q", DO_NOT_QUIT), ("Func_d408", "b", DO_NOT_QUIT), ("Func_d40f", "q", DO_NOT_QUIT), - ("Func_d416", "q", DO_NOT_QUIT), - ("Func_d423", "q", DO_NOT_QUIT), - ("Func_d429", "q", DO_NOT_QUIT), + ("OWScript_PlaySFX", "b", DO_NOT_QUIT), + ("OWScript_PauseSong", "q", DO_NOT_QUIT), + ("OWScript_ResumeSong", "q", DO_NOT_QUIT), ("Func_d41d", "", DO_NOT_QUIT), - ("Func_d42f", "q", DO_NOT_QUIT), + ("OWScript_WaitForSongToFinish", "q", DO_NOT_QUIT), ("Func_d435", "b", DO_NOT_QUIT), ("OWScript_AskQuestionJumpDefaultYes", "tj", DO_NOT_QUIT), ("Func_d2f6", "q", DO_NOT_QUIT), @@ -227,7 +233,7 @@ def createList(): # this is a func just so all this can go at the bottom ("OWScript_JumpIfFlagNotLessThan", "fbj", DO_NOT_QUIT), ("OWScript_JumpIfFlagLessThan", "fbj", DO_NOT_QUIT), ("OWScript_MaxOutFlagValue", "f", DO_NOT_QUIT), - ("OWScript_ZeroOutFlagValue", "q", DO_NOT_QUIT), + ("OWScript_ZeroOutFlagValue", "f", DO_NOT_QUIT), ("OWScript_JumpIfFlagNonzero2", "fj", DO_NOT_QUIT), ("OWScript_JumpIfFlagZero2", "fj", DO_NOT_QUIT), ("OWScript_IncrementFlagValue", "f", DO_NOT_QUIT), -- cgit v1.2.3 From 2a3071d3fec01901f5e0122d47072495bcf54945 Mon Sep 17 00:00:00 2001 From: Andrew Martinek Date: Thu, 24 Oct 2019 17:46:14 -0400 Subject: Updated script extractor to work with Movements --- tools/script_extractor.py | 88 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 63 insertions(+), 25 deletions(-) (limited to 'tools/script_extractor.py') diff --git a/tools/script_extractor.py b/tools/script_extractor.py index c55b8cd..69d4ccd 100644 --- a/tools/script_extractor.py +++ b/tools/script_extractor.py @@ -9,7 +9,7 @@ ###### Script list is a work in progress. The following arguments are ###### ###### accepted and accounted for. ###### ###### b - byte w - word j - jump (within script) t - text (tx) ###### -###### f - flag d - direction i - decimal byte ###### +###### f - flag d - direction i - decimal byte m - npc move ptr ###### ###### q - Used when the script's arguments have not been determined yet ###### ############################################################################### import argparse @@ -21,7 +21,39 @@ QUIT_JUMP = 2 QUIT_SPECIAL = 3 QUIT_DEBUG = -1 -def decodeLine(scriptList, game_data, loc, ignore_broken, branchList): +dir_list = ["NORTH","EAST","SOUTH","WEST"] + +def printHeader(loc, prefix): + ls = format(loc,"04x") + lsa = format(loc-0x8000,"04x") + print(prefix + ls + ": ; " + ls + " (3:" + lsa + ")" ) + +def extractMovement(game_data, loc, errQuit): + printHeader(loc, "NPCMovement_") + loc -= 1 # so we can continue without breaking things + while game_data[loc+1] != 0xff: + loc += 1 + dirLow = game_data[loc] & 0x0f + if dirLow > 3: + print("ERROR: [" + format(loc,"04x") + "] was not a valid direction. Got: " + format(game_data[loc],"02x")) + if errQuit: + return QUIT_DEBUG + continue + lineStr = "\tdb " + dir_list[dirLow] + dirHigh = game_data[loc] & 0xf0 + if dirHigh == 0x80: + lineStr += " | NO_MOVE" + elif dirHigh != 0x00: + print("ERROR: [" + format(loc,"04x") + "] was not a valid direction. Got: " + format(game_data[loc],"02x")) + if errQuit: + return QUIT_DEBUG + continue + print(lineStr) + print("\tdb $ff") + print("; " + format(loc+2,"04x")) + return DO_NOT_QUIT + +def decodeLine(scriptList, game_data, loc, ignore_broken, locList): currLine = scriptList[game_data[loc]] ret = "\trun_script " + currLine[0] + "\n" loc+=1 @@ -42,7 +74,7 @@ def decodeLine(scriptList, game_data, loc, ignore_broken, branchList): ret += "\tdw NO_JUMP\n" else: ret += "\tdw .ows_" + format(wordLoc+0x8000,"04x") + "\n" - branchList.append(wordLoc) + locList.append(wordLoc) loc += 2 elif c == "t": addr = (game_data[loc] + (game_data[loc+1]<<8)) @@ -55,9 +87,12 @@ def decodeLine(scriptList, game_data, loc, ignore_broken, branchList): ret += "\tdb EVENT_FLAG_" + format(game_data[loc],"02X") + "\n" loc += 1 elif c == "d": - dir_list = ["NORTH","EAST","SOUTH","WEST"] ret += "\tdb " + dir_list[game_data[loc]] + "\n" loc += 1 + elif c == "m": + wordLoc = (game_data[loc] + (game_data[loc+1]<<8)) + ret += "\tdw NPCMovement_" + format(wordLoc + 0x8000, "04x") + "\n" + loc += 2 elif c == "q": print("haven't updated data for this yet") if not ignore_broken: @@ -68,19 +103,21 @@ def decodeLine(scriptList, game_data, loc, ignore_broken, branchList): def main(): scriptList = createList() - branchList = [] + locList = [] parser = argparse.ArgumentParser(description='Pokemon TCG Script Extractor') parser.add_argument('--noauto', action='store_true', help='turns off automatic script parsing') parser.add_argument('--error', action='store_true', help='stops execution if an error occurs') + parser.add_argument('-m', '--movement', action='store_true', help='interprets bytes as a movement script rather than an OWSequence') parser.add_argument('-r', '--rom', default="baserom.gbc", help='rom file to extract script from') - parser.add_argument('location', help='location to extract from. May be local to bank or global.') + parser.add_argument('locations', nargs="+", help='locations to extract from. May be local to bank or global.') args = parser.parse_args() - loc = int(args.location,0) - if loc > 0x7fff: - # Must be a global location - loc -= 0x8000 - branchList.append(loc) + for locStr in args.locations: + loc = int(locStr,0) + if loc > 0x7fff: + # Must be a global location + loc -= 0x8000 + locList.append(loc) # this is a list of every start location we've read to avoid infinite loops exploredList = [] @@ -91,14 +128,17 @@ def main(): auto = not args.noauto end = DO_NOT_QUIT ignore_broken = not args.error - while (len(branchList) > 0 and end != QUIT_DEBUG): - branchList.sort() # export parts in order somewhat - loc = branchList.pop(0) + 0x8000 - end = printScript(game_data, loc, auto, ignore_broken, scriptList,\ - branchList, exploredList) + while (len(locList) > 0 and end != QUIT_DEBUG): + locList.sort() # export parts in order somewhat + loc = locList.pop(0) + 0x8000 + if args.movement: + end = extractMovement(game_data,loc, args.error) + else: + end = printScript(game_data, loc, auto, ignore_broken, scriptList,\ + locList, exploredList) def printScript(game_data, loc, auto, ignore_broken, scriptList, \ - branchList, exploredList): + locList, exploredList): if loc in exploredList: return exploredList.append(loc) @@ -110,13 +150,11 @@ def printScript(game_data, loc, auto, ignore_broken, scriptList, \ else: # TODO this is hacky please don't do this - ls = format(loc,"04x") - lsa = format(loc-0x8000,"04x") - print("OWSequence_" + ls + ": ; " + ls + " (3:" + lsa + ")" ) + printHeader(loc, "OWSequence_") loc += 1 print("\tstart_script") while end == DO_NOT_QUIT: - loc, outstr, end = decodeLine(scriptList,game_data,loc,ignore_broken,branchList) + loc, outstr, end = decodeLine(scriptList,game_data,loc,ignore_broken,locList) outstr = outstr[:-1] # [:-1] strips the newline at the end if auto: print(outstr) @@ -176,7 +214,7 @@ def createList(): # this is a func just so all this can go at the bottom ("OWScript_DoFrames", "b", DO_NOT_QUIT), ("Func_d0d9", "bbw", DO_NOT_QUIT), # jumps but still needs args ("OWScript_JumpIfPlayerCoordMatches", "iij", DO_NOT_QUIT), # jumps but still needs args - ("Func_ce4a", "bb", DO_NOT_QUIT), + ("OWScript_MoveActiveNPC", "m", DO_NOT_QUIT), ("OWScript_GiveOneOfEachTrainerBooster", "", DO_NOT_QUIT), ("Func_d103", "q", DO_NOT_QUIT), ("Func_d125", "b", DO_NOT_QUIT), @@ -197,12 +235,12 @@ def createList(): # this is a func just so all this can go at the bottom ("Func_d271", "q", DO_NOT_QUIT), ("OWScript_EnterMap", "bbood", DO_NOT_QUIT), ("Func_ce6f", "bd", DO_NOT_QUIT), - ("Func_d209", "q", DO_NOT_QUIT), - ("Func_d38f", "q", DO_NOT_QUIT), + ("Func_d209", "", DO_NOT_QUIT), + ("Func_d38f", "b", DO_NOT_QUIT), ("Func_d396", "b", DO_NOT_QUIT), ("Func_cd76", "", DO_NOT_QUIT), ("Func_d39d", "b", DO_NOT_QUIT), - ("Func_d3b9", "q", DO_NOT_QUIT), + ("Func_d3b9", "", DO_NOT_QUIT), ("OWScript_TryGivePCPack", "b", DO_NOT_QUIT), ("OWScript_nop", "", DO_NOT_QUIT), ("Func_d3d4", "q", DO_NOT_QUIT), -- cgit v1.2.3 From e58e93fdb14173ae7a9edcd782f70fe67402c42f Mon Sep 17 00:00:00 2001 From: Andrew Martinek Date: Fri, 25 Oct 2019 19:41:50 -0400 Subject: a bit more scripting stuff, figured out more npc data --- tools/script_extractor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tools/script_extractor.py') diff --git a/tools/script_extractor.py b/tools/script_extractor.py index 69d4ccd..ad91ae5 100644 --- a/tools/script_extractor.py +++ b/tools/script_extractor.py @@ -185,7 +185,7 @@ def createList(): # this is a func just so all this can go at the bottom ("Func_cda8", "bbbb", DO_NOT_QUIT), ("OWScript_PrintTextQuitFully", "t", QUIT_SPECIAL), ("Func_cdcb", "", DO_NOT_QUIT), - ("Func_ce26", "bb", DO_NOT_QUIT), + ("OWScript_MoveActiveNPCByDirection", "bb", DO_NOT_QUIT), ("OWScript_CloseTextBox", "", DO_NOT_QUIT), ("OWScript_GiveBoosterPacks", "bbb", DO_NOT_QUIT), ("Func_cf0c", "bj", DO_NOT_QUIT), # more complex behavior too (jumping) @@ -234,7 +234,7 @@ def createList(): # this is a func just so all this can go at the bottom ("OWScript_OpenDeckMachine", "b", DO_NOT_QUIT), ("Func_d271", "q", DO_NOT_QUIT), ("OWScript_EnterMap", "bbood", DO_NOT_QUIT), - ("Func_ce6f", "bd", DO_NOT_QUIT), + ("OWScript_MoveArbitraryNPC", "bd", DO_NOT_QUIT), ("Func_d209", "", DO_NOT_QUIT), ("Func_d38f", "b", DO_NOT_QUIT), ("Func_d396", "b", DO_NOT_QUIT), -- cgit v1.2.3 From 3f99d5555ce7b8a2467aef9d24d7192f993343d9 Mon Sep 17 00:00:00 2001 From: Andrew Martinek Date: Mon, 28 Oct 2019 17:25:50 -0400 Subject: extracted a lot of challenge hall scripts --- tools/script_extractor.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'tools/script_extractor.py') diff --git a/tools/script_extractor.py b/tools/script_extractor.py index ad91ae5..18d5908 100644 --- a/tools/script_extractor.py +++ b/tools/script_extractor.py @@ -185,7 +185,7 @@ def createList(): # this is a func just so all this can go at the bottom ("Func_cda8", "bbbb", DO_NOT_QUIT), ("OWScript_PrintTextQuitFully", "t", QUIT_SPECIAL), ("Func_cdcb", "", DO_NOT_QUIT), - ("OWScript_MoveActiveNPCByDirection", "bb", DO_NOT_QUIT), + ("OWScript_MoveActiveNPCByDirection", "w", DO_NOT_QUIT), ("OWScript_CloseTextBox", "", DO_NOT_QUIT), ("OWScript_GiveBoosterPacks", "bbb", DO_NOT_QUIT), ("Func_cf0c", "bj", DO_NOT_QUIT), # more complex behavior too (jumping) @@ -208,10 +208,10 @@ def createList(): # this is a func just so all this can go at the bottom ("OWScript_MovePlayer", "db", DO_NOT_QUIT), ("OWScript_ShowCardReceivedScreen", "b", DO_NOT_QUIT), ("OWScript_SetDialogName", "b", DO_NOT_QUIT), - ("OWScript_SetNextNPCandOWSequence", "bw", DO_NOT_QUIT), + ("OWScript_SetNextNPCandOWSequence", "bj", DO_NOT_QUIT), ("Func_d095", "bbb", DO_NOT_QUIT), ("Func_d0be", "bb", DO_NOT_QUIT), - ("OWScript_DoFrames", "b", DO_NOT_QUIT), + ("OWScript_DoFrames", "i", DO_NOT_QUIT), ("Func_d0d9", "bbw", DO_NOT_QUIT), # jumps but still needs args ("OWScript_JumpIfPlayerCoordMatches", "iij", DO_NOT_QUIT), # jumps but still needs args ("OWScript_MoveActiveNPC", "m", DO_NOT_QUIT), @@ -219,22 +219,22 @@ def createList(): # this is a func just so all this can go at the bottom ("Func_d103", "q", DO_NOT_QUIT), ("Func_d125", "b", DO_NOT_QUIT), ("Func_d135", "b", DO_NOT_QUIT), - ("Func_d16b", "q", DO_NOT_QUIT), - ("Func_cd4f", "q", DO_NOT_QUIT), + ("Func_d16b", "b", DO_NOT_QUIT), + ("Func_cd4f", "bbb", DO_NOT_QUIT), ("Func_cd94", "q", DO_NOT_QUIT), - ("Func_ce52", "q", DO_NOT_QUIT), - ("Func_cdd8", "q", DO_NOT_QUIT), - ("Func_cdf5", "q", DO_NOT_QUIT), - ("Func_d195", "q", DO_NOT_QUIT), + ("OWScript_MoveWramNPC", "m", DO_NOT_QUIT), + ("Func_cdd8", "", DO_NOT_QUIT), + ("Func_cdf5", "bb", DO_NOT_QUIT), + ("Func_d195", "", DO_NOT_QUIT), ("Func_d1ad", "", DO_NOT_QUIT), - ("Func_d1b3", "q", DO_NOT_QUIT), + ("Func_d1b3", "", DO_NOT_QUIT), ("OWScript_QuitScriptFully", "", QUIT_SPECIAL), ("Func_d244", "q", DO_NOT_QUIT), ("Func_d24c", "q", DO_NOT_QUIT), ("OWScript_OpenDeckMachine", "b", DO_NOT_QUIT), ("Func_d271", "q", DO_NOT_QUIT), ("OWScript_EnterMap", "bbood", DO_NOT_QUIT), - ("OWScript_MoveArbitraryNPC", "bd", DO_NOT_QUIT), + ("OWScript_MoveArbitraryNPC", "bm", DO_NOT_QUIT), ("Func_d209", "", DO_NOT_QUIT), ("Func_d38f", "b", DO_NOT_QUIT), ("Func_d396", "b", DO_NOT_QUIT), -- cgit v1.2.3 From adc5a467eeccb0e44f4fcd2ed14d2b185ca1c14c Mon Sep 17 00:00:00 2001 From: Andrew Martinek Date: Tue, 29 Oct 2019 16:35:04 -0400 Subject: Finished extracting Challenge Hall scripts --- tools/script_extractor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/script_extractor.py') diff --git a/tools/script_extractor.py b/tools/script_extractor.py index 18d5908..2f68ee7 100644 --- a/tools/script_extractor.py +++ b/tools/script_extractor.py @@ -264,7 +264,7 @@ def createList(): # this is a func just so all this can go at the bottom ("OWScript_EndScriptLoop5", "q", QUIT_CONTINUE_CODE), ("OWScript_EndScriptLoop6", "q", QUIT_CONTINUE_CODE), ("OWScript_SetFlagValue", "fb", DO_NOT_QUIT), - ("OWScript_JumpIfFlagZero1", "q", DO_NOT_QUIT), + ("OWScript_JumpIfFlagZero1", "fj", DO_NOT_QUIT), ("OWScript_JumpIfFlagNonzero1", "q", DO_NOT_QUIT), ("OWScript_JumpIfFlagEqual", "fbj", DO_NOT_QUIT), # also capable of jumping ("OWScript_JumpIfFlagNotEqual", "fbj", DO_NOT_QUIT), # jumps -- cgit v1.2.3 From b7f47ca621716938cfc6df7d4eea90b2be909eaf Mon Sep 17 00:00:00 2001 From: Andrew Martinek Date: Sun, 3 May 2020 12:06:02 -0400 Subject: add challenge machine --- tools/script_extractor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/script_extractor.py') diff --git a/tools/script_extractor.py b/tools/script_extractor.py index 2f68ee7..5fcfbac 100644 --- a/tools/script_extractor.py +++ b/tools/script_extractor.py @@ -257,7 +257,7 @@ def createList(): # this is a func just so all this can go at the bottom ("OWScript_AskQuestionJumpDefaultYes", "tj", DO_NOT_QUIT), ("Func_d2f6", "q", DO_NOT_QUIT), ("Func_d317", "", DO_NOT_QUIT), - ("Func_d43d", "q", DO_NOT_QUIT), + ("Func_d43d", "", DO_NOT_QUIT), ("OWScript_EndScriptLoop2", "q", QUIT_CONTINUE_CODE), ("OWScript_EndScriptLoop3", "q", QUIT_CONTINUE_CODE), ("OWScript_EndScriptLoop4", "q", QUIT_CONTINUE_CODE), -- cgit v1.2.3 From 29ed945c4adce0b6bc45be3964f95393d8248390 Mon Sep 17 00:00:00 2001 From: Andrew Martinek Date: Sat, 9 May 2020 15:49:35 -0400 Subject: changed run_script and updated script extraction tool --- tools/script_extractor.py | 118 +++++++++++++++++++++++----------------------- 1 file changed, 59 insertions(+), 59 deletions(-) (limited to 'tools/script_extractor.py') diff --git a/tools/script_extractor.py b/tools/script_extractor.py index 5fcfbac..f043010 100644 --- a/tools/script_extractor.py +++ b/tools/script_extractor.py @@ -55,7 +55,7 @@ def extractMovement(game_data, loc, errQuit): def decodeLine(scriptList, game_data, loc, ignore_broken, locList): currLine = scriptList[game_data[loc]] - ret = "\trun_script " + currLine[0] + "\n" + ret = "\trun_command " + currLine[0] + "\n" loc+=1 quit = currLine[2] for c in currLine[1]: @@ -108,7 +108,7 @@ def main(): parser = argparse.ArgumentParser(description='Pokemon TCG Script Extractor') parser.add_argument('--noauto', action='store_true', help='turns off automatic script parsing') parser.add_argument('--error', action='store_true', help='stops execution if an error occurs') - parser.add_argument('-m', '--movement', action='store_true', help='interprets bytes as a movement script rather than an OWSequence') + parser.add_argument('-m', '--movement', action='store_true', help='interprets bytes as a movement sequence rather than a Script') parser.add_argument('-r', '--rom', default="baserom.gbc", help='rom file to extract script from') parser.add_argument('locations', nargs="+", help='locations to extract from. May be local to bank or global.') args = parser.parse_args() @@ -150,7 +150,7 @@ def printScript(game_data, loc, auto, ignore_broken, scriptList, \ else: # TODO this is hacky please don't do this - printHeader(loc, "OWSequence_") + printHeader(loc, "Script_") loc += 1 print("\tstart_script") while end == DO_NOT_QUIT: @@ -175,23 +175,23 @@ def printScript(game_data, loc, auto, ignore_broken, scriptList, \ def createList(): # this is a func just so all this can go at the bottom # name, arg list, is an ender return [ - ("OWScript_EndScriptLoop1", "", QUIT_CONTINUE_CODE), - ("OWScript_CloseAdvancedTextBox", "", DO_NOT_QUIT), - ("OWScript_PrintTextString", "t", DO_NOT_QUIT), + ("ScriptCommand_EndScriptLoop1", "", QUIT_CONTINUE_CODE), + ("ScriptCommand_CloseAdvancedTextBox", "", DO_NOT_QUIT), + ("ScriptCommand_PrintTextString", "t", DO_NOT_QUIT), ("Func_ccdc", "t", DO_NOT_QUIT), - ("OWScript_AskQuestionJump", "tj", DO_NOT_QUIT), # more complex behavior too (jumping) - ("OWScript_StartBattle", "bbb", DO_NOT_QUIT), - ("OWScript_PrintVariableText", "tt", DO_NOT_QUIT), + ("ScriptCommand_AskQuestionJump", "tj", DO_NOT_QUIT), # more complex behavior too (jumping) + ("ScriptCommand_StartBattle", "bbb", DO_NOT_QUIT), + ("ScriptCommand_PrintVariableText", "tt", DO_NOT_QUIT), ("Func_cda8", "bbbb", DO_NOT_QUIT), - ("OWScript_PrintTextQuitFully", "t", QUIT_SPECIAL), + ("ScriptCommand_PrintTextQuitFully", "t", QUIT_SPECIAL), ("Func_cdcb", "", DO_NOT_QUIT), - ("OWScript_MoveActiveNPCByDirection", "w", DO_NOT_QUIT), - ("OWScript_CloseTextBox", "", DO_NOT_QUIT), - ("OWScript_GiveBoosterPacks", "bbb", DO_NOT_QUIT), + ("ScriptCommand_MoveActiveNPCByDirection", "w", DO_NOT_QUIT), + ("ScriptCommand_CloseTextBox", "", DO_NOT_QUIT), + ("ScriptCommand_GiveBoosterPacks", "bbb", DO_NOT_QUIT), ("Func_cf0c", "bj", DO_NOT_QUIT), # more complex behavior too (jumping) ("Func_cf12", "bj", DO_NOT_QUIT), - ("OWScript_GiveCard", "b", DO_NOT_QUIT), - ("OWScript_TakeCard", "b", DO_NOT_QUIT), + ("ScriptCommand_GiveCard", "b", DO_NOT_QUIT), + ("ScriptCommand_TakeCard", "b", DO_NOT_QUIT), ("Func_cf53", "w", DO_NOT_QUIT), # more complex behavior too (jumping) ("Func_cf7b", "", DO_NOT_QUIT), ("Func_cf2d", "bbbb", DO_NOT_QUIT), # more complex behavior too (jumping + ??) @@ -202,83 +202,83 @@ def createList(): # this is a func just so all this can go at the bottom ("Func_d025", "w", DO_NOT_QUIT), # possibly only jumps, still needs args ("Func_d032", "w", DO_NOT_QUIT), # see above ("Func_d03f", "", DO_NOT_QUIT), - ("OWScript_Jump", "j", QUIT_JUMP), # jumps to d - ("OWScript_TryGiveMedalPCPacks", "", DO_NOT_QUIT), - ("OWScript_SetPlayerDirection", "d", DO_NOT_QUIT), - ("OWScript_MovePlayer", "db", DO_NOT_QUIT), - ("OWScript_ShowCardReceivedScreen", "b", DO_NOT_QUIT), - ("OWScript_SetDialogName", "b", DO_NOT_QUIT), - ("OWScript_SetNextNPCandOWSequence", "bj", DO_NOT_QUIT), + ("ScriptCommand_Jump", "j", QUIT_JUMP), # jumps to d + ("ScriptCommand_TryGiveMedalPCPacks", "", DO_NOT_QUIT), + ("ScriptCommand_SetPlayerDirection", "d", DO_NOT_QUIT), + ("ScriptCommand_MovePlayer", "db", DO_NOT_QUIT), + ("ScriptCommand_ShowCardReceivedScreen", "b", DO_NOT_QUIT), + ("ScriptCommand_SetDialogName", "b", DO_NOT_QUIT), + ("ScriptCommand_SetNextNPCandScript", "bj", DO_NOT_QUIT), ("Func_d095", "bbb", DO_NOT_QUIT), ("Func_d0be", "bb", DO_NOT_QUIT), - ("OWScript_DoFrames", "i", DO_NOT_QUIT), + ("ScriptCommand_DoFrames", "i", DO_NOT_QUIT), ("Func_d0d9", "bbw", DO_NOT_QUIT), # jumps but still needs args - ("OWScript_JumpIfPlayerCoordMatches", "iij", DO_NOT_QUIT), # jumps but still needs args - ("OWScript_MoveActiveNPC", "m", DO_NOT_QUIT), - ("OWScript_GiveOneOfEachTrainerBooster", "", DO_NOT_QUIT), + ("ScriptCommand_JumpIfPlayerCoordMatches", "iij", DO_NOT_QUIT), # jumps but still needs args + ("ScriptCommand_MoveActiveNPC", "m", DO_NOT_QUIT), + ("ScriptCommand_GiveOneOfEachTrainerBooster", "", DO_NOT_QUIT), ("Func_d103", "q", DO_NOT_QUIT), ("Func_d125", "b", DO_NOT_QUIT), ("Func_d135", "b", DO_NOT_QUIT), ("Func_d16b", "b", DO_NOT_QUIT), ("Func_cd4f", "bbb", DO_NOT_QUIT), ("Func_cd94", "q", DO_NOT_QUIT), - ("OWScript_MoveWramNPC", "m", DO_NOT_QUIT), + ("ScriptCommand_MoveWramNPC", "m", DO_NOT_QUIT), ("Func_cdd8", "", DO_NOT_QUIT), ("Func_cdf5", "bb", DO_NOT_QUIT), ("Func_d195", "", DO_NOT_QUIT), ("Func_d1ad", "", DO_NOT_QUIT), ("Func_d1b3", "", DO_NOT_QUIT), - ("OWScript_QuitScriptFully", "", QUIT_SPECIAL), + ("ScriptCommand_QuitScriptFully", "", QUIT_SPECIAL), ("Func_d244", "q", DO_NOT_QUIT), ("Func_d24c", "q", DO_NOT_QUIT), - ("OWScript_OpenDeckMachine", "b", DO_NOT_QUIT), + ("ScriptCommand_OpenDeckMachine", "b", DO_NOT_QUIT), ("Func_d271", "q", DO_NOT_QUIT), - ("OWScript_EnterMap", "bbood", DO_NOT_QUIT), - ("OWScript_MoveArbitraryNPC", "bm", DO_NOT_QUIT), + ("ScriptCommand_EnterMap", "bbood", DO_NOT_QUIT), + ("ScriptCommand_MoveArbitraryNPC", "bm", DO_NOT_QUIT), ("Func_d209", "", DO_NOT_QUIT), ("Func_d38f", "b", DO_NOT_QUIT), ("Func_d396", "b", DO_NOT_QUIT), ("Func_cd76", "", DO_NOT_QUIT), ("Func_d39d", "b", DO_NOT_QUIT), ("Func_d3b9", "", DO_NOT_QUIT), - ("OWScript_TryGivePCPack", "b", DO_NOT_QUIT), - ("OWScript_nop", "", DO_NOT_QUIT), + ("ScriptCommand_TryGivePCPack", "b", DO_NOT_QUIT), + ("ScriptCommand_nop", "", DO_NOT_QUIT), ("Func_d3d4", "q", DO_NOT_QUIT), ("Func_d3e0", "", DO_NOT_QUIT), ("Func_d3fe", "q", DO_NOT_QUIT), ("Func_d408", "b", DO_NOT_QUIT), ("Func_d40f", "q", DO_NOT_QUIT), - ("OWScript_PlaySFX", "b", DO_NOT_QUIT), - ("OWScript_PauseSong", "q", DO_NOT_QUIT), - ("OWScript_ResumeSong", "q", DO_NOT_QUIT), + ("ScriptCommand_PlaySFX", "b", DO_NOT_QUIT), + ("ScriptCommand_PauseSong", "q", DO_NOT_QUIT), + ("ScriptCommand_ResumeSong", "q", DO_NOT_QUIT), ("Func_d41d", "", DO_NOT_QUIT), - ("OWScript_WaitForSongToFinish", "q", DO_NOT_QUIT), + ("ScriptCommand_WaitForSongToFinish", "q", DO_NOT_QUIT), ("Func_d435", "b", DO_NOT_QUIT), - ("OWScript_AskQuestionJumpDefaultYes", "tj", DO_NOT_QUIT), + ("ScriptCommand_AskQuestionJumpDefaultYes", "tj", DO_NOT_QUIT), ("Func_d2f6", "q", DO_NOT_QUIT), ("Func_d317", "", DO_NOT_QUIT), ("Func_d43d", "", DO_NOT_QUIT), - ("OWScript_EndScriptLoop2", "q", QUIT_CONTINUE_CODE), - ("OWScript_EndScriptLoop3", "q", QUIT_CONTINUE_CODE), - ("OWScript_EndScriptLoop4", "q", QUIT_CONTINUE_CODE), - ("OWScript_EndScriptLoop5", "q", QUIT_CONTINUE_CODE), - ("OWScript_EndScriptLoop6", "q", QUIT_CONTINUE_CODE), - ("OWScript_SetFlagValue", "fb", DO_NOT_QUIT), - ("OWScript_JumpIfFlagZero1", "fj", DO_NOT_QUIT), - ("OWScript_JumpIfFlagNonzero1", "q", DO_NOT_QUIT), - ("OWScript_JumpIfFlagEqual", "fbj", DO_NOT_QUIT), # also capable of jumping - ("OWScript_JumpIfFlagNotEqual", "fbj", DO_NOT_QUIT), # jumps - ("OWScript_JumpIfFlagNotLessThan", "fbj", DO_NOT_QUIT), - ("OWScript_JumpIfFlagLessThan", "fbj", DO_NOT_QUIT), - ("OWScript_MaxOutFlagValue", "f", DO_NOT_QUIT), - ("OWScript_ZeroOutFlagValue", "f", DO_NOT_QUIT), - ("OWScript_JumpIfFlagNonzero2", "fj", DO_NOT_QUIT), - ("OWScript_JumpIfFlagZero2", "fj", DO_NOT_QUIT), - ("OWScript_IncrementFlagValue", "f", DO_NOT_QUIT), - ("OWScript_EndScriptLoop7", "q", QUIT_CONTINUE_CODE), - ("OWScript_EndScriptLoop8", "q", QUIT_CONTINUE_CODE), - ("OWScript_EndScriptLoop9", "q", QUIT_CONTINUE_CODE), - ("OWScript_EndScriptLoop10", "q", QUIT_CONTINUE_CODE) + ("ScriptCommand_EndScriptLoop2", "q", QUIT_CONTINUE_CODE), + ("ScriptCommand_EndScriptLoop3", "q", QUIT_CONTINUE_CODE), + ("ScriptCommand_EndScriptLoop4", "q", QUIT_CONTINUE_CODE), + ("ScriptCommand_EndScriptLoop5", "q", QUIT_CONTINUE_CODE), + ("ScriptCommand_EndScriptLoop6", "q", QUIT_CONTINUE_CODE), + ("ScriptCommand_SetFlagValue", "fb", DO_NOT_QUIT), + ("ScriptCommand_JumpIfFlagZero1", "fj", DO_NOT_QUIT), + ("ScriptCommand_JumpIfFlagNonzero1", "q", DO_NOT_QUIT), + ("ScriptCommand_JumpIfFlagEqual", "fbj", DO_NOT_QUIT), # also capable of jumping + ("ScriptCommand_JumpIfFlagNotEqual", "fbj", DO_NOT_QUIT), # jumps + ("ScriptCommand_JumpIfFlagNotLessThan", "fbj", DO_NOT_QUIT), + ("ScriptCommand_JumpIfFlagLessThan", "fbj", DO_NOT_QUIT), + ("ScriptCommand_MaxOutFlagValue", "f", DO_NOT_QUIT), + ("ScriptCommand_ZeroOutFlagValue", "f", DO_NOT_QUIT), + ("ScriptCommand_JumpIfFlagNonzero2", "fj", DO_NOT_QUIT), + ("ScriptCommand_JumpIfFlagZero2", "fj", DO_NOT_QUIT), + ("ScriptCommand_IncrementFlagValue", "f", DO_NOT_QUIT), + ("ScriptCommand_EndScriptLoop7", "q", QUIT_CONTINUE_CODE), + ("ScriptCommand_EndScriptLoop8", "q", QUIT_CONTINUE_CODE), + ("ScriptCommand_EndScriptLoop9", "q", QUIT_CONTINUE_CODE), + ("ScriptCommand_EndScriptLoop10", "q", QUIT_CONTINUE_CODE) ] main() -- cgit v1.2.3