Upload Files

This commit is contained in:
Cainan 2024-04-02 23:38:00 +01:00
commit 13073b3957
8 changed files with 330 additions and 0 deletions

View File

@ -0,0 +1,14 @@
# Taiko no Tatsujin - Simple Fumen Encryption and Decryption Tools
Simple Python 3 script to allows you to quickly decrypt and decompress or re-compress encrypt fumen files.
Needed for some newer Taiko no Tatsujin titles.
Usage: Drag and Drop your Fumen files on `dec.py` to decrypt them
Decrypted Files will be output in a folder called `decrypted`
Or
Drag and Drop your Fumen files on `enc.py` to encrypt them
Encrypted files will be output in a folder called `encrypted`
No Encryption keys will be provided with this tool.
Define your encryption key in `config.toml`

View File

@ -0,0 +1 @@
key = ""

View File

@ -0,0 +1,86 @@
import os
import sys
import toml
import gzip
from Crypto.Cipher import AES
from Crypto.Util.Padding import unpad
def decrypt_and_rename_to_gz(input_file, key):
# Read the encrypted file
with open(input_file, 'rb') as file:
encrypted_bytes = file.read()
# Extract IV from the first 16 bytes of the encrypted file
iv = encrypted_bytes[:16]
# Decrypt the rest of the file
cipher = AES.new(key, AES.MODE_CBC, iv)
decrypted_bytes = unpad(cipher.decrypt(encrypted_bytes[16:]), AES.block_size)
# Generate the new filename with .gz extension
output_file = os.path.splitext(input_file)[0] + ".gz"
# Write decrypted data to the new .gz file
with open(output_file, 'wb') as file:
file.write(decrypted_bytes)
print(f"Decryption successful. Renamed and decrypted file saved as: {output_file}")
return output_file
def decompress_gz_file(input_file):
# Generate the output filename without the .gz extension
output_file = os.path.splitext(input_file)[0]
# Decompress the .gz file
with gzip.open(input_file, 'rb') as f_in, open(output_file, 'wb') as f_out:
f_out.write(f_in.read())
print(f"Decompression successful. Decompressed file saved as: {output_file}")
return output_file
def move_to_decrypted_folder(input_file, output_file):
# Create the decrypted folder if it doesn't exist
decrypted_folder = os.path.join(os.path.dirname(input_file), "decrypted")
os.makedirs(decrypted_folder, exist_ok=True)
# Generate the output filename within the decrypted folder with .bin extension
output_bin_file = os.path.join(decrypted_folder, os.path.splitext(os.path.basename(output_file))[0] + ".bin")
# Move the decrypted and decompressed file to the decrypted folder
os.rename(output_file, output_bin_file)
print(f"Decrypted file moved to folder 'decrypted'. Decrypted file saved as: {output_bin_file}")
def main():
# Check if there are any files dragged and dropped
if len(sys.argv) < 2:
print("Please drag and drop the AES-256-CBC encrypted .bin file(s) onto this program.")
return
# Load configuration from config.toml
config_file = "config.toml"
with open(config_file, "r") as file:
config = toml.load(file)
# Get key from configuration and convert it to bytes
key_hex = config["key"]
key = bytes.fromhex(key_hex)
for input_file in sys.argv[1:]:
# Decrypt the file and get the renamed .gz file
gz_file = decrypt_and_rename_to_gz(input_file, key)
# Decompress the .gz file and get the output filename
output_file = decompress_gz_file(gz_file)
# Move the decrypted and decompressed file to the decrypted folder
move_to_decrypted_folder(input_file, output_file)
# Remove the .gz file
os.remove(gz_file)
print(f"Removed the .gz file: {gz_file}")
if __name__ == "__main__":
main()

View File

@ -0,0 +1,87 @@
import os
import sys
import toml
import gzip
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad
def compress_file(input_file):
# Generate the output filename with .gz extension
output_file = os.path.splitext(input_file)[0] + ".gz"
# Compress the input file
with open(input_file, 'rb') as f_in, gzip.open(output_file, 'wb') as f_out:
f_out.write(f_in.read())
print(f"Compression successful. Compressed file saved as: {output_file}")
return output_file
def encrypt_file(input_file, key, iv):
# Read the compressed file
with open(input_file, 'rb') as file:
plaintext = file.read()
# Encrypt the file
cipher = AES.new(key, AES.MODE_CBC, iv)
ciphertext = cipher.encrypt(pad(plaintext, AES.block_size))
# Prepend the IV to the ciphertext
encrypted_data = iv + ciphertext
# Generate the output filename
output_file = os.path.splitext(input_file)[0] + ".encrypted.bin"
# Write the encrypted data to the output file
with open(output_file, 'wb') as file:
file.write(encrypted_data)
print(f"Encryption successful. Encrypted file saved as: {output_file}")
return output_file
def move_to_encrypted_folder(input_file, output_file):
# Create the encrypted folder if it doesn't exist
encrypted_folder = os.path.join(os.path.dirname(input_file), "encrypted")
os.makedirs(encrypted_folder, exist_ok=True)
# Generate the output filename within the encrypted folder
output_encrypted_file = os.path.join(encrypted_folder, os.path.basename(input_file))
# Move the encrypted file to the encrypted folder
os.rename(output_file, output_encrypted_file)
print(f"Encrypted file moved to folder 'encrypted'. Encrypted file saved as: {output_encrypted_file}")
def main():
# Check if there are any files dragged and dropped
if len(sys.argv) < 2:
print("Please drag and drop the files you want to re-compress and re-encrypt onto this program.")
return
# Load configuration from config.toml
config_file = "config.toml"
with open(config_file, "r") as file:
config = toml.load(file)
# Get key and IV from configuration and convert them to bytes
key_hex = config["key"]
key = bytes.fromhex(key_hex)
iv = bytes.fromhex("FF" * 16) # IV set to FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
for input_file in sys.argv[1:]:
# Compress the file
compressed_file = compress_file(input_file)
# Encrypt the compressed file
encrypted_file = encrypt_file(compressed_file, key, iv)
# Move the encrypted file to the encrypted folder
move_to_encrypted_folder(input_file, encrypted_file)
# Remove the compressed file
os.remove(compressed_file)
print(f"Removed the compressed file: {compressed_file}")
if __name__ == "__main__":
main()

View File

@ -0,0 +1,22 @@
# Taiko no Tatsujin - Fumen Timing Window Replace Script
Simple Python 3 script to replace that can replace the timing windows in a Taiko Gen 3 fumen
Usage: replace_timing.py inFile outFile timingWindow
Timing Options: Standard, Hitnarrow, Hitwide or a User Defined Option.
Detects what difficulty timing window to use based on the Input's filename.
Easy(\_e) and Normal(\_n) will use the easy timing
Hard(\_h), Extreme(\_e) and Ura(\_x) will use hard timing
If it fails to detect difficulty, it'll use the hard timing values instead.
To add custom timing values, add a new section to timing.ini and define it's name and add values for each judgement.
A template can be found [here](TaikoFumenTimingReplace/resource/template.ini)
# Credits
swigz27 - Initial code.
Yuki [(Nerdy-boi)](https://github.com/Nerdy-boi) - Code optimisations and tweaks.

View File

@ -0,0 +1,90 @@
#Python script that replaces the timing values in a Fumen and spits out a new file.
import configparser, struct, sys
#Function to handle converting a float to a binary array
def convert_to_bytearray(f):
val = hex(struct.unpack('>I', struct.pack('<f', f))[0])
Fixed_hex = val[2:]
return bytes.fromhex(Fixed_hex)
#Load ini file
config = configparser.ConfigParser()
config.sections()
config.read('timing.ini')
# Define possible endings of file name and their difficulties.
easy = '_e'
normal = '_n'
hard = '_h'
extreme = '_m'
ura = '_x'
# Check to see if anything (other than the python file) has been entered.
# If two files/the timing window haven't been entered, it'll just throw a normal Python error.
if len(sys.argv) > 1:
#Check if standard/hitwide/hitnarrow/custom was typed in the console
if sys.argv[3].lower() == 'standard':
GOOD = config.getfloat('standard', 'good')
OK = config.getfloat('standard', 'ok')
BAD = config.getfloat('standard', 'bad')
GOOD_EASY = config.getfloat('standard', 'good_easy')
OK_EASY = config.getfloat('standard', 'ok_easy')
BAD_EASY = config.getfloat('standard', 'bad_easy')
else:
try:
GOOD = config.getfloat(sys.argv[3].lower(), 'good')
OK = config.getfloat(sys.argv[3].lower(), 'ok')
BAD = config.getfloat(sys.argv[3].lower(), 'bad')
GOOD_EASY = config.getfloat(sys.argv[3].lower(), 'good_easy')
OK_EASY = config.getfloat(sys.argv[3].lower(), 'ok_easy')
BAD_EASY = config.getfloat(sys.argv[3].lower(), 'bad_easy')
except:
print("Invalid Input")
exit()
#Convert the floats to a binary array
GOOD_BYTES = (convert_to_bytearray(GOOD))
OK_BYTES = (convert_to_bytearray(OK))
BAD_BYTES = (convert_to_bytearray(BAD))
GOOD_EASY_BYTES = (convert_to_bytearray(GOOD_EASY))
OK_EASY_BYTES = (convert_to_bytearray(OK_EASY))
BAD_EASY_BYTES = (convert_to_bytearray(BAD_EASY))
#Define binary arrays
timing_window_hard = (GOOD_BYTES + OK_BYTES + BAD_BYTES) * 36
timing_window_easy = (GOOD_EASY_BYTES + OK_EASY_BYTES + BAD_EASY_BYTES) * 36
# Define the input and output files.
inFile = sys.argv[1]
outFile = sys.argv[2]
# Opens the input file, saves it as the output,
# This was the only way I managed was able to acomplish the right output.
with open(inFile, "rb") as old, open(outFile, "wb") as new:
old.seek(0)
new.write(old.read())
# Actually replaces the timing windows
chart_new = open(outFile, "rb+")
chart_new.seek(0)
# Checks if _e, _n, etc is present in the file name:
# If it is, it'll use timing_easy,
# If it isn't present, it will use timing_hard instead.
if easy in inFile:
chart_new.write(timing_window_easy)
chart_new.close()
elif normal in inFile:
chart_new.write(timing_window_easy)
chart_new.close()
else:
chart_new.write(timing_window_hard)
chart_new.close()
else:
print("TaikoFumenTimingReplace\nUsage:",sys.argv[0], "inFile outFile timingWindow",
"\n\nTiming Options: Standard, Hitnarrow, Hitwide or a User Defined Option.")

View File

@ -0,0 +1,7 @@
[Template]
good = 0.0
ok = 0.0
bad = 0.0
good_easy = 0.0
ok_easy = 0.0
bad_easy = 0.0

View File

@ -0,0 +1,23 @@
[standard]
good = 25.0250015258789
ok = 75.0750045776367
bad = 108.441665649414
good_easy = 41.7083358764648
ok_easy = 108.441665649414
bad_easy = 125.125
[hitnarrow]
good = 25.0250015258789
ok = 58.3916664123535
bad = 108.441665649414
good_easy = 41.7083358764648
ok_easy = 75.0750045776367
bad_easy = 125.125
[hitwide]
good = 75.0750045776367
ok = 91.7583312988281
bad = 108.441665649414
good_easy = 91.7583312988281
ok_easy = 108.441665649414
bad_easy = 125.125