Skip to content

Instantly share code, notes, and snippets.

@the-byte-bender
Created December 2, 2023 13:22
Show Gist options
  • Save the-byte-bender/a41e413e3ef92c3c9aa0cc5c106cd660 to your computer and use it in GitHub Desktop.
Save the-byte-bender/a41e413e3ef92c3c9aa0cc5c106cd660 to your computer and use it in GitHub Desktop.
Script to encrypt/decrypt sounds for mist world
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
Copy link

Thanks! I'm semi-familiar with command line use, but I guess I was just doing something wrong. I'll try again a little later.
Is there any way to use this script to batch convert? What I would like to do is replace all of the English voice lines with the original Chinese ones, but I would rather not have to do every single sound one at a time, then search through them to find only the voicelines and repackage them.

@the-byte-bender
Copy link
Author

@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

@Shadowcat42
Copy link

Shadowcat42 commented Dec 6, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment