From 6973ec82ba5f7e6cc978a73c44887c416fbaa498 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Wed, 2 May 2012 13:37:11 -0500 Subject: [PATCH] figuring out where a script appears based on a known address --- extras/README.md | 28 +++++++++++++++++++++++++++- extras/crystal.py | 4 ++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/extras/README.md b/extras/README.md index 63baf6d8f..240476b68 100644 --- a/extras/README.md +++ b/extras/README.md @@ -35,7 +35,7 @@ import crystal crystal.run_tests() ``` -#### Investigating scripts from a known address +#### Parsing a script at a known address Here is a demo of how to investigate a particular script, starting with only an address to a known script (0x58043). In this case, the script calls the `2writetext` command to show some dialog. This dialog will be shown at the end of the example. @@ -125,3 +125,29 @@ UnknownText_0x580c7: ; 0x580c7 ; 0x581e5 ``` +#### Figuring out where a script appears based on a known address + +Another approach is to parse the entire ROM, then check a script at a particular address. This has the advantage that the script object will have the `map_group` and `map_id` variables set. + +```python +import crystal + +# parse the ROM +crystal.run_main() + +# get the parsed script +script = crystal.script_parse_table[0x58043] + +# read its attributes to figure out map group / map id +map_group = script.map_group +map_id = script.map_id + +# MapHeader is not given all the info yet +# in the mean time "map_names" contains some metadata +map_dict = crystal.map_names[map_group][map_name] +map_header = map_dict["header_new"] + +print map_dict["name"] +# Ruins of Alph Outside +``` + diff --git a/extras/crystal.py b/extras/crystal.py index e1f83fb8c..e468ab423 100644 --- a/extras/crystal.py +++ b/extras/crystal.py @@ -2295,6 +2295,10 @@ class Script: if not label: label = self.base_label + hex(self.address) self.label = Label(name=label, address=address, object=self) + if "map_group" in kwargs.keys(): + self.map_group = kwargs["map_group"] + if "map_id" in kwargs.keys(): + self.map_id = kwargs["map_id"] #parse the script at the address if "use_old_parse" in kwargs.keys() and kwargs["use_old_parse"] == True: self.old_parse(**kwargs)