utage: mission key generation and name finding
should be compatible with bingo's xdusuitecsharp
This commit is contained in:
parent
71e8c9d257
commit
6c455fe30b
6 changed files with 266 additions and 52 deletions
|
|
@ -1,3 +1,51 @@
|
|||
import io
|
||||
import os
|
||||
import traceback
|
||||
|
||||
from functools import partial
|
||||
from glob import glob
|
||||
from multiprocessing.pool import Pool
|
||||
|
||||
from . import crypt
|
||||
from . import translate
|
||||
|
||||
def crypt_dir(dir_in, key, encrypt=False, no_compress=False):
|
||||
if not encrypt:
|
||||
files = glob(os.path.join(dir_in, "**/*.utage"), recursive=True)
|
||||
else:
|
||||
files = glob(os.path.join(dir_in, "**/*.tsv"), recursive=True)
|
||||
|
||||
if len(files) == 0:
|
||||
raise FileNotFoundError("No valid files found in directory: " + dir_in)
|
||||
|
||||
pcrypt = partial(crypt_file, key=key, encrypt=encrypt, no_compress=no_compress)
|
||||
with Pool() as p:
|
||||
p.map(pcrypt, files)
|
||||
|
||||
def crypt_file(file_in, key, encrypt=False, no_compress=False):
|
||||
with open(file_in, "rb") as inf:
|
||||
in_data = inf.read()
|
||||
try:
|
||||
if encrypt:
|
||||
if not file_in.endswith(".png") and not file_in.endswith(".jpg") and not file_in.endswith(".tsv"):
|
||||
raise ValueError("Invalid File Type for {}".format(file_in))
|
||||
if not file_in.endswith(".png") and not no_compress:
|
||||
enc_data = crypt.compress(in_data)
|
||||
enc_data = crypt.xor_crypt(enc_data, key)
|
||||
with io.open(file_in + ".utage", "wb") as output:
|
||||
output.write(enc_data)
|
||||
else:
|
||||
if not file_in.endswith(".utage"):
|
||||
raise ValueError("Invalid File Type for {}".format(file_in))
|
||||
dec_data = crypt.xor_crypt(in_data, key)
|
||||
if not file_in.endswith(".png.utage") and not file_in.endswith(".jpg.utage") and not no_compress:
|
||||
dec_data = crypt.decompress(dec_data)
|
||||
with io.open(file_in.replace(".utage", ""), "wb") as output:
|
||||
output.write(dec_data)
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
print("Error processing file: " + file_in)
|
||||
|
||||
def decompress(data):
|
||||
osize = 0
|
||||
isize = len(data)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue