Skip to content

Instantly share code, notes, and snippets.

@apple1417
Created January 30, 2019 09:28
Show Gist options
  • Save apple1417/c092eae69ef05b0f290cf601ae2a2ab3 to your computer and use it in GitHub Desktop.
Save apple1417/c092eae69ef05b0f290cf601ae2a2ab3 to your computer and use it in GitHub Desktop.
import os
import re
import shutil
import zipfile
EXTRACT_FILES = False
if EXTRACT_FILES:
if os.path.isdir("tmp"):
shutil.rmtree("tmp")
os.mkdir("tmp")
for path in os.listdir():
if path.endswith(".gro"):
gro = zipfile.ZipFile(path)
for zipPath in gro.namelist():
if zipPath.endswith(".dlg") or zipPath.endswith(".lua"):
# This overwrites duplicates in the same way the game does
file = open("tmp/" + zipPath.split("/")[-1], "wb")
file.write(gro.read(zipPath))
file.close()
allFlags = {}
def addFlag(flag, source):
flag = flag.decode("utf-8")
if flag in allFlags:
if source not in allFlags[flag]:
allFlags[flag].append(source)
else:
allFlags[flag] = [source]
for path in os.listdir("tmp"):
file = open("tmp/" + path, "rb")
if path.endswith(".lua"):
for match in re.finditer(b":(Set|Get|Is)(Var|Code)(Value|Set)?\((?P<args>.*?)\)", file.read(), flags=re.I):
# Need to do this in two parts to make sure quotes match
argMatch = re.match(b"\s*\"([^\"]+)\"\s*?,?.*?", match.group("args"))
argMatch2 = re.match(b"\s*'([^']+)'\s*?,?.*?", match.group("args"))
if argMatch:
addFlag(argMatch.group(1), path)
elif argMatch2:
addFlag(argMatch2.group(1), path)
else:
addFlag(b"<code>", path)
elif path.endswith(".dlg"):
for match in re.finditer(b"set:\s?(.*?)\s", file.read(), flags=re.I):
addFlag(match.group(1), path)
file.close()
file = open("out.csv", "w")
file.write("Flag,Source File(s)\n")
for flag in sorted(allFlags.keys()):
file.write(flag + "," + ",".join(allFlags[flag]) + "\n")
file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment