HMX Forge (RB4/DCS/Amp16/FME) save game decryptor/encryptor
1using davesave;
2using davesave.Saves;
3using LibForge.Util;
4
5static void PrintUsage(bool showInfo = true)
6{
7 if (showInfo)
8 {
9 Console.WriteLine("davesave - 2024-2025 Emma / InvoxiPlayGames");
10 Console.WriteLine(" uses parts of DtxCS and LibForge by maxton");
11 Console.WriteLine(" https://github.com/InvoxiPlayGames/davesave");
12 }
13 Console.WriteLine();
14 Console.WriteLine("available commands: info, decrypt, encrypt");
15 Console.WriteLine("supported games: Amplitude 2016 (1.0/1.1), Rock Band 4 (2.3.7)");
16 Console.WriteLine();
17 Console.WriteLine("- davesave info [filename]");
18 Console.WriteLine(" will display savegame info from the file provided");
19 Console.WriteLine();
20 Console.WriteLine("- davesave convert [input file] [output file]");
21 Console.WriteLine(" Amplitude 2016 ONLY!! will convert between PS4 and PS3 save file formats");
22 Console.WriteLine();
23 Console.WriteLine("- davesave decrypt [input file] [output file] (optional: ps3/360/ps4/xb1/pc)");
24 Console.WriteLine(" will decrypt the encrypted save from the input file into the output");
25 Console.WriteLine(" platform must be provided if working with an unsupported game");
26 Console.WriteLine();
27 Console.WriteLine("- davesave encrypt [input file] [output file] (optional: ps3/360/ps4/xb1/pc)");
28 Console.WriteLine(" will encrypt a decrypted save from the input file into the output");
29 Console.WriteLine(" platform must be provided if working with an unsupported game");
30 Console.WriteLine();
31}
32
33if (args.Length < 1)
34{
35 PrintUsage(true);
36 return;
37}
38
39string verb = args[0].ToLower();
40
41if (verb == "help" || verb == "about" || verb == "-h" || verb == "/?")
42{
43 PrintUsage(true);
44 return;
45}
46else if (verb == "info")
47{
48 if (args.Length < 2)
49 {
50 Console.WriteLine("Error: no filename provided.");
51 PrintUsage(false);
52 return;
53 }
54 await InfoPrint.SaveInfo(args[1]);
55 return;
56}
57else if (verb == "decrypt")
58{
59 if (args.Length < 3)
60 {
61 Console.WriteLine("Error: missing arguments.");
62 PrintUsage(false);
63 return;
64 }
65 FileStream inStream = File.OpenRead(args[1]);
66 SaveDetection.SaveType type = await SaveDetection.DetectSaveTypeAsync(inStream);
67 string platform = InfoPrint.SaveDescriptions[type];
68 bool isBigEndian = false;
69 if (type == SaveDetection.SaveType.AmpPS3 || type == SaveDetection.SaveType.AmpPS3_Decrypted)
70 {
71 isBigEndian = true;
72 } else if (type == SaveDetection.SaveType.NotASave || type == SaveDetection.SaveType.Unsupported ||
73 type == SaveDetection.SaveType.Failed)
74 {
75 if (args.Length < 4)
76 {
77 Console.WriteLine("Game type couldn't be detected and no platform was provided.");
78 PrintUsage(false);
79 return;
80 }
81 platform = args[3].ToLower();
82 isBigEndian = platform == "ps3" || platform == "360";
83 if (!isBigEndian && platform != "xb1" && platform != "ps4" && platform != "pc")
84 {
85 Console.WriteLine("Invalid platform provided (valid options are: xb1, 360, ps3, ps4, pc)");
86 PrintUsage(false);
87 return;
88 }
89 }
90 Console.WriteLine("Decrypting {0} endian {1} save...", isBigEndian ? "big" : "little", platform);
91
92 FileStream outStream = File.OpenWrite(args[2]);
93 EncryptedReadRevisionStream ers = new EncryptedReadRevisionStream(inStream, isBigEndian);
94 ers.CopyTo(outStream);
95 outStream.Close();
96 ers.FinishReading();
97 ers.Close();
98 return;
99}
100else if (verb == "encrypt")
101{
102 if (args.Length < 3)
103 {
104 Console.WriteLine("Error: missing arguments.");
105 PrintUsage(false);
106 return;
107 }
108 FileStream inStream = File.OpenRead(args[1]);
109 SaveDetection.SaveType type = await SaveDetection.DetectSaveTypeAsync(inStream);
110 bool isBigEndian = false;
111 string platform = InfoPrint.SaveDescriptions[type];
112 if (type == SaveDetection.SaveType.AmpPS3 || type == SaveDetection.SaveType.AmpPS3_Decrypted)
113 {
114 isBigEndian = true;
115 }
116 else if (type == SaveDetection.SaveType.NotASave || type == SaveDetection.SaveType.Unsupported ||
117 type == SaveDetection.SaveType.Failed)
118 {
119 if (args.Length < 4)
120 {
121 Console.WriteLine("Game type couldn't be detected and no platform was provided.");
122 PrintUsage(false);
123 return;
124 }
125 platform = args[3].ToLower();
126 isBigEndian = platform == "ps3" || platform == "360";
127 if (!isBigEndian && platform != "xb1" && platform != "ps4" && platform != "pc")
128 {
129 Console.WriteLine("Invalid platform provided (valid options are: xb1, 360, ps3, ps4, pc)");
130 PrintUsage(false);
131 return;
132 }
133 }
134 Console.WriteLine("Encrypting {0} endian {1} save...", isBigEndian ? "big" : "little", platform);
135
136 FileStream outStream = File.OpenWrite(args[2]);
137 EncryptedWriteRevisionStream ews = new EncryptedWriteRevisionStream(outStream, 0x69696969, isBigEndian);
138 inStream.CopyTo(ews);
139 inStream.Close();
140 ews.FinishWriting();
141 ews.Close();
142 outStream.Close();
143 return;
144}
145else if (verb == "convert")
146{
147 if (args.Length < 3)
148 {
149 Console.WriteLine("Error: not enough filenames provided.");
150 PrintUsage(false);
151 return;
152 }
153 await AmpConversion.ConvertAmpSave(args[1], args[2]);
154 return;
155}
156else
157{
158 Console.WriteLine("Error: unknown command");
159 PrintUsage(false);
160 return;
161}