Skip to content

Instantly share code, notes, and snippets.

@Dobby233Liu
Last active July 4, 2022 09:19
Show Gist options
  • Save Dobby233Liu/ea02526a4fd63b1403bc031febc1a161 to your computer and use it in GitHub Desktop.
Save Dobby233Liu/ea02526a4fd63b1403bc031febc1a161 to your computer and use it in GitHub Desktop.
hacky script to extract Deltarune: A Different Snowgrave text
import json
import sys
output_custom_blocks = False
def logan_string_parser(str):
actual_printed = ""
for letter in str:
if letter == "+":
# print heart???
letter = "[]"
if letter == "<":
# should pause
continue
if letter == "{" or letter == "}":
# up/down arrow
continue
if letter == ">":
letter = " " # ow text indent
elif letter == "^":
letter = "\n"
actual_printed += letter
return actual_printed
j = {}
with open(sys.argv[1], "r") as f:
j = json.load(f)
scan_pattern = {}
with open(sys.argv[2], "r") as f:
scan_pattern = json.load(f)
out = {}
protos_out = []
for target in j["targets"]:
this_out = []
for block_id, block in target["blocks"].items():
if not isinstance(block, dict):
continue
if output_custom_blocks and block["opcode"] == "procedures_prototype":
mut_orig = block["mutation"]
mut = {}
if scan_pattern.get(mut_orig["proccode"], None) is not None:
continue
mut["proccode"] = mut_orig["proccode"]
mut["children"] = mut_orig["children"]
mut["arguments"] = {}
argumentids = json.loads(mut_orig["argumentids"])
if len(argumentids) <= 0:
continue
argumentnames = json.loads(mut_orig["argumentnames"])
argumentdefaults = json.loads(mut_orig["argumentdefaults"])
for argname, argid, argdefl in zip(argumentnames, argumentids, argumentdefaults):
mut["arguments"][argname] = [argid, argdefl]
protos_out.append(mut)
if block["opcode"] == "procedures_call":
arg = scan_pattern.get(block["mutation"]["proccode"], None)
if arg is not None:
arg_input = block["inputs"][arg]
if arg_input[0] == 1:
assert arg_input[1][0] == 10
text = arg_input[1][1]
text = logan_string_parser(text)
if len(text) > 0:
this_out.append(text)
if len(this_out) > 0:
out[target["name"]] = this_out
if output_custom_blocks:
out["CUSTOM_BLOCKS"] = protos_out
print(json.dumps(out, indent=2))
{
"Menu Text: Say %s Xpos: %s Ypos: %s Color: %s": "^x$r$r5JmV}oQr60({b4",
"Overworld Skip: say %s Top/Bottom %s Dark/Light %s Expression %s": "J^ST+C@P/hsz0-Wf}Dxh",
"Dialogue: Say %s Xpos: %s Ypos: %s Wait: %s Skip: %s Sound Type: %s Bubble: %s": "]KwW2:3b`w40pwIC94OJ",
"Overworld: Say %s Top/Bottom %s Wait: %s Skip: %s Sound: %s Dark/Light %s Expression: %s": "LO.B9F+F8,@Ph}x_}VSr",
"Text: Say %s Xpos: %s Ypos: %s Wait: %s Skip: %s Sound Type: %s": "!Ie|xXNBL7pd~17fAII~",
"Skip Text: Say %s Xpos: %s Ypos: %s": "VmRErY5C$|-OAbk{x1uW",
"Skip Dialogue: Say %s Xpos: %s Ypos: %s Bubble: %s": "VD]k]ghl9nYi-5u0,SwV",
"Flavor Text: If Turn %s , print %s": "_JcQ$;/1I7[EY:0d!7^1"
}
python sc.py <project.json> <scan.json> > text.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment