Skip to content

Commit bc2ab74

Browse files
Allow encryption/decryption without Steam ID
for experimental home console version support
1 parent 779da3a commit bc2ab74

File tree

1 file changed

+33
-15
lines changed
  • DMFDSteamSaveTool/DMFDSteamSaveTool

1 file changed

+33
-15
lines changed

DMFDSteamSaveTool/DMFDSteamSaveTool/Form1.cs

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ public Form1()
2121

2222
private bool ValidSteamID (string steamID)
2323
{
24-
if (steamID.Length == 0 || System.Text.RegularExpressions.Regex.IsMatch(steamID, "[^0-9]"))
24+
if (System.Text.RegularExpressions.Regex.IsMatch(steamID, "[^0-9]"))
2525
{
2626
return false;
2727
}
2828

2929
return true;
30-
3130
}
31+
32+
3233
//
3334
// load input files
3435
//
@@ -106,21 +107,29 @@ private void decrypt_button_Click(object sender, EventArgs e)
106107
if (saveFileDialog.ShowDialog() == DialogResult.OK)
107108
{
108109
outputDecFilePath = saveFileDialog.FileName;
109-
110-
ulong steamID = ulong.Parse(steamID64_enc.Text) & 0xFFFFFFFF;
111110

112111
byte[] saveData;
113112

114-
// load encrypted file and read its contents
113+
// load encrypted file and read its contents into byte array
115114
using (BinaryReader inFile = new BinaryReader(File.OpenRead(encFilePath)))
116115
{
117116
inFile.BaseStream.Position = 0x10; // skip header
118117
saveData = inFile.ReadBytes((int)(inFile.BaseStream.Length - 0x10));
119118
}
120119

121-
// decrypt it
122-
dmfd.Decrypt(halfPassword0 + steamID.ToString("x" + 8), ref saveData);
123-
dmfd.Decrypt(halfPassword1 + steamID.ToString("x" + 8), ref saveData);
120+
// Steam
121+
if (steamID64_enc.Text.Length > 0)
122+
{
123+
ulong steamID = ulong.Parse(steamID64_enc.Text) & 0xFFFFFFFF;
124+
dmfd.Decrypt(halfPassword0 + steamID.ToString("x"), ref saveData);
125+
dmfd.Decrypt(halfPassword1 + steamID.ToString("x"), ref saveData);
126+
}
127+
// NS (maybe PS4 too?)
128+
else
129+
{
130+
dmfd.Decrypt(halfPassword0, ref saveData);
131+
dmfd.Decrypt(halfPassword1, ref saveData);
132+
}
124133

125134
FileMode openMode;
126135
if (File.Exists(outputDecFilePath))
@@ -164,8 +173,6 @@ private void encrypt_button_Click(object sender, EventArgs e)
164173
outputEncFilePath = saveFileDialog.FileName;
165174
// load decrypted file, encrypt and save it
166175

167-
ulong steamID = ulong.Parse(steamID64_dec.Text) & 0xFFFFFFFF;
168-
169176
// header (0x10 bytes)
170177
uint magic = 0xAE9F2304;
171178
uint unknown = 0x68;
@@ -176,14 +183,25 @@ private void encrypt_button_Click(object sender, EventArgs e)
176183
// read decrypted data
177184
saveData = File.ReadAllBytes(decFilePath);
178185

179-
// 1st checksum
186+
// calculate 1st checksum
180187
chksum0 = dmfd.Checksum(saveData);
181188

182-
// encrypt it
183-
dmfd.Encrypt(halfPassword1 + steamID.ToString("x"), ref saveData);
184-
dmfd.Encrypt(halfPassword0 + steamID.ToString("x"), ref saveData);
189+
// encrypt for Steam
190+
if (steamID64_dec.Text.Length > 0)
191+
{
192+
ulong steamID = ulong.Parse(steamID64_dec.Text) & 0xFFFFFFFF;
193+
dmfd.Encrypt(halfPassword1 + steamID.ToString("x" + 8), ref saveData);
194+
dmfd.Encrypt(halfPassword0 + steamID.ToString("x" + 8), ref saveData);
195+
}
196+
// encrypt for NS (PS4 too?)
197+
else
198+
{
199+
dmfd.Encrypt(halfPassword1, ref saveData);
200+
dmfd.Encrypt(halfPassword0, ref saveData);
201+
}
202+
185203

186-
// 2nd checksum
204+
// calculate 2nd checksum
187205
chksum1 = dmfd.Checksum(saveData);
188206

189207
FileMode openMode;

0 commit comments

Comments
 (0)