Added simple python script to unpack game.

This commit is contained in:
Filipe Rodrigues 2021-08-17 07:36:53 +01:00
parent 4922c8ca15
commit 0a91758a7d
3 changed files with 62 additions and 0 deletions

3
.gitignore vendored
View File

@ -8,6 +8,9 @@
# Logs
/latest.log
# Default output directory for unpack
/game
# Resources
/resources/*

4
.style.yapf Normal file
View File

@ -0,0 +1,4 @@
[style]
based_on_style = yapf
use_tabs = true
column_limit = 120

55
unpack.py Normal file
View File

@ -0,0 +1,55 @@
#!/bin/env python3
# Imports
import sys
import subprocess
# Print usage
def print_usage():
print(f"Usage: {sys.argv[0]} <game-file> [output-dir]")
# Retrieves the arguments
def get_args():
try:
game_file = sys.argv[1]
except:
print_usage()
exit(1)
try:
output_dir = sys.argv[2]
except:
output_dir = "./game"
return (game_file, output_dir)
# Extracts the card table
def extract_card_table(game_file, output_file):
with open(output_file, 'w') as f:
args = ["cargo", "run", "--bin", "dcb-extract-card-table", "--", game_file]
proc = subprocess.Popen(args, stdout=f)
if proc.wait() != 0:
print("Failed to extract card table")
exit(1)
# Main
def main():
# Get arguments
(game_file, output_dir) = get_args()
# If the game file isn't a `.bin`, exit
if not game_file.lower().endswith('.bin'):
print("The game file must bea `.bin` file")
exit(1)
# Extract the card and deck table
extract_card_table(game_file, f"{output_dir}/card_table.json")
print(game_file, output_dir)
if __name__ == "__main__":
main()