/
ct-fmv.cs
79 lines (65 loc) · 2.32 KB
/
ct-fmv.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System;
using System.IO;
public static class Program
{
public static void Main(string[] args)
{
var defaultColor = Console.ForegroundColor;
try
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("Chrono Trigger (Steam) FMV Encoder / Decoder\n");
Console.ForegroundColor = defaultColor;
Console.WriteLine(
"A tool that encodes or decodes the FMV files in the game (the 001-008.dat on the game root)\n");
if (args.Length != 1)
{
throw new Exception("Drag a .dat or .mp4 file into this executable");
}
var inputPath = args[0];
if (!File.Exists(inputPath))
{
throw new Exception($"{inputPath} is not a file");
}
var isDat = inputPath.EndsWith(".dat");
var isMp4 = inputPath.EndsWith(".mp4");
if (!isDat && !isMp4)
{
throw new Exception($"{inputPath} is not a .dat nor a .mp4 file");
}
var outputPath =
isDat ? inputPath.Replace(".dat", ".decoded.mp4") : inputPath.Replace(".mp4", ".encoded.dat");
if (File.Exists(outputPath))
{
throw new Exception($"There's already a file at {outputPath}, remove it first");
}
var before = File.ReadAllBytes(inputPath);
var after = Decode(before);
File.WriteAllBytes(outputPath, after);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"Converted {inputPath} into {outputPath}\n");
}
catch (Exception e)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(e.Message + "\n");
}
finally
{
Console.ForegroundColor = defaultColor;
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
}
private static byte[] Decode(byte[] input)
{
var output = new byte[input.Length];
var counter = 0xFF;
for (var i = 0; i < input.Length; i++)
{
output[i] = (byte)(input[i] ^ counter);
counter = counter == 0 ? 0xFF : counter - 1;
}
return output;
}
}