diff --git a/go-hub-game-master-decompiler/gamemaster-decompile.sh b/go-hub-game-master-decompiler/gamemaster-decompile.sh index a9cf7dc..035b61d 100755 --- a/go-hub-game-master-decompiler/gamemaster-decompile.sh +++ b/go-hub-game-master-decompiler/gamemaster-decompile.sh @@ -1,5 +1,16 @@ #!/bin/bash +# Parse command line arguments +OUTPUT_FILE="" +JSON_OUTPUT=false +while [[ $# -gt 0 ]]; do + case $1 in + -o|--output) OUTPUT_FILE="$2"; shift 2 ;; + -j|--json) JSON_OUTPUT=true; shift ;; + *) shift ;; + esac +done + pogo_protos_path="./dependencies/POGOProtos-master/src/" pogo_protos_target="POGOProtos.Networking.Responses.DownloadItemTemplatesResponse" pogo_protos_template="./dependencies/POGOProtos-master/src/POGOProtos/Networking/Responses/DownloadItemTemplatesResponse.proto" @@ -7,7 +18,24 @@ pogo_gamemaster_dir="./game-master-files/" pogo_gamemaster_name=$(ls -t "$pogo_gamemaster_dir" | head -n1) pogo_gamemaster=$pogo_gamemaster_dir$(ls -t "$pogo_gamemaster_dir" | head -n1) -./dependencies/protoc-3.2.0-osx-x86_64/bin/protoc --proto_path="$pogo_protos_path" --decode="$pogo_protos_target" "$pogo_protos_template" < "$pogo_gamemaster" >> "$pogo_gamemaster_name"_output.txt +if [ -z "$OUTPUT_FILE" ]; then + OUTPUT_FILE="$pogo_gamemaster_name"_output.txt +fi + +if [ "$JSON_OUTPUT" = true ]; then + ./dependencies/protoc-3.2.0-osx-x86_64/bin/protoc --proto_path="$pogo_protos_path" --decode="$pogo_protos_target" "$pogo_protos_template" < "$pogo_gamemaster" | python3 -c " +import sys, re, json +data = re.sub(r'\s+', ' ', sys.stdin.read()) +data = re.sub(r'(\w+):(?=\s*\w)', r'\"\1\": ', data) +data = re.sub(r':\s+([a-zA-Z_]\w*)', r': \"\1', data) +data = re.sub(r'(?<=\w)(\s+)(?=\w)', r'\", \"', data) +data = re.sub(r'(?<=\"\w)\s*$', '\"', data) +data = re.sub(r'(\w):\s*([a-zA-Z_]\w*)\s*$', r'\"\1\": \"\2\"', data) +print(json.dumps(json.loads(data))) +" > "$OUTPUT_FILE" +else + ./dependencies/protoc-3.2.0-osx-x86_64/bin/protoc --proto_path="$pogo_protos_path" --decode="$pogo_protos_target" "$pogo_protos_template" < "$pogo_gamemaster" > "$OUTPUT_FILE" +fi echo "****************************************************" echo "* *"