From c457216294b7c078a9157010845aa2d354118a9b Mon Sep 17 00:00:00 2001 From: Jennifer Taylor Date: Thu, 12 Aug 2021 15:57:54 +0000 Subject: [PATCH] Give various utilities a bit of a refresh help-wise. --- bemani/utils/api.py | 2 +- bemani/utils/frontend.py | 2 +- bemani/utils/psmap.py | 4 +-- bemani/utils/responsegen.py | 2 +- bemani/utils/services.py | 2 +- bemani/utils/struct.py | 55 +++++++++++++++++++++---------------- bemani/utils/twodxutils.py | 16 +++++++---- 7 files changed, 49 insertions(+), 34 deletions(-) diff --git a/bemani/utils/api.py b/bemani/utils/api.py index c47a569..bb333ba 100644 --- a/bemani/utils/api.py +++ b/bemani/utils/api.py @@ -16,7 +16,7 @@ def main() -> None: parser = argparse.ArgumentParser(description="An API services provider for eAmusement games, conforming to BEMAPI specs.") parser.add_argument("-p", "--port", help="Port to listen on. Defaults to 80", type=int, default=80) parser.add_argument("-c", "--config", help="Core configuration. Defaults to server.yaml", type=str, default="server.yaml") - parser.add_argument("-r", "--profile", help="Turn on profiling for API", action="store_true") + parser.add_argument("-r", "--profile", help="Turn on profiling for API, writing CProfile data to the currenct directory", action="store_true") args = parser.parse_args() # Set up app diff --git a/bemani/utils/frontend.py b/bemani/utils/frontend.py index f51e1d4..d76dc3f 100644 --- a/bemani/utils/frontend.py +++ b/bemani/utils/frontend.py @@ -85,7 +85,7 @@ def main() -> None: parser = argparse.ArgumentParser(description="A front end services provider for eAmusement games.") parser.add_argument("-p", "--port", help="Port to listen on. Defaults to 80", type=int, default=80) parser.add_argument("-c", "--config", help="Core configuration. Defaults to server.yaml", type=str, default="server.yaml") - parser.add_argument("-r", "--profile", help="Turn on profiling for front end", action="store_true") + parser.add_argument("-r", "--profile", help="Turn on profiling for front end, writing CProfile data to the currenct directory", action="store_true") args = parser.parse_args() # Set up app diff --git a/bemani/utils/psmap.py b/bemani/utils/psmap.py index 2b4c7af..b159dc7 100644 --- a/bemani/utils/psmap.py +++ b/bemani/utils/psmap.py @@ -200,7 +200,7 @@ def main() -> None: ) parser.add_argument( "--offset", - help="Hex offset into the file.", + help="Hex offset into the file. This can be specified as either a raw offset into the DLL or as a virtual offset.", type=str, default=None, required=True, @@ -215,7 +215,7 @@ def main() -> None: ) parser.add_argument( "--root", - help="Root node name.", + help="Root node name to be used for the generated code.", type=str, default="root", ) diff --git a/bemani/utils/responsegen.py b/bemani/utils/responsegen.py index b713a06..81200ff 100644 --- a/bemani/utils/responsegen.py +++ b/bemani/utils/responsegen.py @@ -130,7 +130,7 @@ def generate_code(infile: str, outfile: str, encoding: str) -> None: def main() -> None: - parser = argparse.ArgumentParser(description="A utility to generate code that will generate a packet.") + parser = argparse.ArgumentParser(description="A utility to generate code that will generate a packet given an example packet from a log or binary dump.") parser.add_argument("-i", "--infile", help="File containing an XML or binary node structure. Use - for stdin.", type=str, default=None, required=True) parser.add_argument("-o", "--outfile", help="File to write python code to. Use - for stdout.", type=str, default=None, required=True) parser.add_argument("-e", "--encoding", help="Encoding for the packet, defaults to UTF-8.", type=str, default='utf-8') diff --git a/bemani/utils/services.py b/bemani/utils/services.py index ecb1272..33544cb 100644 --- a/bemani/utils/services.py +++ b/bemani/utils/services.py @@ -157,7 +157,7 @@ if __name__ == '__main__': parser = argparse.ArgumentParser(description="A backend services provider for eAmusement games") parser.add_argument("-p", "--port", help="Port to listen on. Defaults to 80", type=int, default=80) parser.add_argument("-c", "--config", help="Core configuration. Defaults to server.yaml", type=str, default="server.yaml") - parser.add_argument("-r", "--profile", help="Turn on profiling for front end", action="store_true") + parser.add_argument("-r", "--profile", help="Turn on profiling for services, writing CProfile data to the currenct directory", action="store_true") args = parser.parse_args() # Set up global configuration, overriding config port for convenience diff --git a/bemani/utils/struct.py b/bemani/utils/struct.py index ffc1ea5..efe0293 100644 --- a/bemani/utils/struct.py +++ b/bemani/utils/struct.py @@ -5,20 +5,6 @@ import sys from typing import Optional, Tuple, List, Any -""" -Some examples of valid format specifiers and what they do are as follows: - -*z&+0x200# = Decodes an array of string pointers, and includes the count - alongside the string, starting at 0x200, and displayed in - hex. Broken down, it has the following parts: - - *z = Dereference the current value (*) and treat that integer - as a pointer to a null-terminated string (z). - &+0x200# = Print the current line number (#), offset by the - value 0x200 (+0x200) as a hex number (&). -""" - - class LineNumber: def __init__(self, offset: int, hex: bool) -> None: self.offset = offset @@ -227,7 +213,29 @@ class StructPrinter: def main() -> int: - parser = argparse.ArgumentParser(description="A utility to print structs out of a DLL.") + parser = argparse.ArgumentParser( + formatter_class=argparse.RawDescriptionHelpFormatter, + description="A utility to print structs out of a DLL.", + epilog=(""" +Some examples of valid format specifiers and what they do are as follows: + +*h = Decodes an array of short pointers, decoding the resulting shorts for each pointer in the array. + +*(hbb) = Decodes an array of pointers to a structure containing a short and two bytes, decoding that short and both bytes for each entry in the array. + +*z = Decodes an array null-terminated string pointers. + +Ih&h = Decodes an array of structures containing an unsigned integer and two shorts, displaying the second short in hex instead of decimal. + +#I = Decodes an array of unsigned integers, displaying the array entry number and the integer. + ++64#h = Decodes an array of shorts, displaying the array entry number starting at 64 and the integer. + +*z&+0x200# = Decodes an array of null-terminated string pointers, displaying the array entry number in hex starting at 0x200 and string. Broken down, it has the following parts: + *z = Dereference the current value (*) and treat that integer as a pointer to a null-terminated string (z). + &+0x200# = Print the current line number (#), offset by the value 0x200 (+0x200) as a hex number (&). +"""), + ) parser.add_argument( "--file", help="DLL file to extract from.", @@ -237,20 +245,20 @@ def main() -> int: ) parser.add_argument( "--start", - help="Hex offset into the file we should start at.", + help="Hex offset into the file we should start at. This can be specified as either a raw offset into the DLL or as a virtual offset.", type=str, default=None, required=True, ) parser.add_argument( "--end", - help="Hex offset into the file we should go until. Alternatively you can use --count", + help="Hex offset into the file we should go until. Alternatively you can use --count and the end offset will be calclated based on the start and format size.", type=str, default=None, ) parser.add_argument( "--count", - help="Number of entries to parse, as a decimal or hex integer. Alternatively you can use --end", + help="Number of entries to parse, as a decimal or hex integer. Alternatively you can use --end and the count will be calculated based on the start, end and format size.", type=str, default=None, ) @@ -259,11 +267,12 @@ def main() -> int: help=( "Python struct format we should print using. See https://docs.python.org/3/library/struct.html " "for details. Additionally, prefixing a format specifier with * allows dereferencing pointers. " - "Surround a chunk of format specifiers with parenthesis to dereference complex structures. For " - "ease of unpacking C string pointers, the specifier \"z\" is recognzied to mean null-terminated " - "string. A & preceeding a format specifier means that we should convert to hex before displaying." - "For the ease of decoding enumerations, the specifier \"#\" is recognized to mean entry number." - "You can provide it a offset value such as \"+20#\" to start at a certain number." + "Surround a chunk of format specifiers with parenthesis to dereference structures. Note that " + "structures can be arbitrarily nested to decode complex data types. For ease of unpacking C string " + "pointers, the specifier \"z\" is recognzied to mean null-terminated string. A & preceeding a " + "format specifier means that we should convert to hex before displaying. For the ease of decoding " + "enumerations, the specifier \"#\" is recognized to mean entry number. You can provide it an " + "offset value such as \"+20#\" to start at a certain number." ), type=str, default=None, diff --git a/bemani/utils/twodxutils.py b/bemani/utils/twodxutils.py index 7aaef42..c80741e 100644 --- a/bemani/utils/twodxutils.py +++ b/bemani/utils/twodxutils.py @@ -14,20 +14,25 @@ def main() -> None: parser.add_argument( "-d", "--directory", - help="Directory to extract to.", + help="Directory to extract to. Specify this parameter if you want to extract an existing 2dx file.", default=None, ) parser.add_argument( "-w", "--wavfile", - help="ADPCM wave file to add to archive.", + help=( + "ADPCM wave file to add to a new or existing archive. Specify this parameter to update an " + "existing 2dx file with a new wav file or build a new archive containing a particular wav file. " + "Note that you can specify this parameter multiple times to bundle multiple wav files into one " + "archive." + ), action="append", default=[], ) parser.add_argument( "-n", "--name", - help="Name of the archive when updating.", + help="Name of the archive when creating a new 2dx file from scratch.", default=None, ) args = parser.parse_args() @@ -51,8 +56,7 @@ def main() -> None: os.makedirs(dirof, exist_ok=True) with open(realfn, 'wb') as fp: fp.write(twodx.read_file(fn)) - - if len(args.wavfile) > 0: + elif len(args.wavfile) > 0: try: fp = open(args.file, 'rb') data = fp.read() @@ -76,6 +80,8 @@ def main() -> None: fp = open(args.file, 'wb') fp.write(twodx.get_new_data()) fp.close() + else: + raise Exception("Please provide either a directory to extract to, or a wav file to build into a 2dx file!") if __name__ == '__main__':