Created
December 2, 2023 13:22
-
-
Save the-byte-bender/a41e413e3ef92c3c9aa0cc5c106cd660 to your computer and use it in GitHub Desktop.
Script to encrypt/decrypt sounds for mist world
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:io'; | |
import 'dart:convert'; | |
List<int> applyXOR(List<int> data, int soundId) { | |
List<int> XOR_KEY = [8, 5, 13, 5, 97, 4, 63, 27]; | |
XOR_KEY[0] ^= (soundId & 0xFF); | |
XOR_KEY[6] ^= ((soundId >> 8) & 0xFF); | |
for (int i = 0; i < data.length; i += 32) { | |
data[i] = data[i] ^ XOR_KEY[(i >> 5) & 7]; | |
} | |
return data; | |
} | |
Future<void> main(List<String> args) async { | |
if (args.isEmpty) { | |
print('Usage: ${Platform.resolvedExecutable} file1 [file2 ...]'); | |
return; | |
} | |
for (var fileName in args) { | |
String outFileExt = filename.endsWith(".ab") ? ".ogg" : ".ab"; | |
if (fileName.endsWith('.ab') || filename.endsWith(".ogg")) { | |
String soundIdStr = fileName.split('.').first; | |
int soundId = int.tryParse(soundIdStr) ?? 0; | |
List<int> fileData = await File(fileName).readAsBytes(); | |
List<int> decryptedData = applyXOR(fileData, soundId); | |
String outputPath = fileName.replaceFirst( | |
filename.endsWith(".ab") ? '.ab' : ".ogg", outFileExt); | |
await File(outputPath).writeAsBytes(decryptedData); | |
print('Operation done for $fileName and saved to $outputPath'); | |
} else { | |
print('Skipping $fileName: Invalid file format'); | |
} | |
} | |
} |
Shadowcat42
commented
Dec 6, 2023
via email
Hello,
Thanks for this! This'll be pretty useful too. It is not quite what I
am looking for, though. What I would like to do is decrypt the voice
files from specifically the Chinese version of the game, assuming the
key is the same. I haven't tested just yet. Can this script be used to
batch decrypt? Because while this archive would give me all of the IDs
for the voicelines, I would still have to run the Chinese audio files
through one by one if I can't just target the entire folder.
Thanks for answering all the questions. Your help is much appreciated.
…On Tue, Dec 5, 2023 at 2:53 PM the-byte-bender ***@***.***> wrote:
@the-byte-bender commented on this gist.
________________________________
@blindninja97 Sadly, not on windows; not unless you modify the code. However, I did that for you. The following is a link to an archive containing all the sounds in their decrypted form, with their ID's intact. I think it is just what you want.
https://www.dropbox.com/scl/fi/4wn3p6er6liqu37cz6k5i/oggs.7z?rlkey=t686ubepb3xj1bbrj7q2bnj8d&dl=1
Sorry for the late reply, and I hope that helps
—
Reply to this email directly, view it on GitHub or unsubscribe.
You are receiving this email because you were mentioned.
Triage notifications on the go with GitHub Mobile for iOS or Android.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment