2
2
using System . Linq ;
3
3
4
4
using System . IO ;
5
+ using System . Collections . Generic ;
6
+ using System . Reflection . Emit ;
5
7
6
8
namespace DOOMSaveManager
7
9
{
8
10
public class DoomEternal
9
11
{
10
12
public const string GameName = "Doom Eternal" ;
11
13
12
- public static string SavePath = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . UserProfile ) , "Saved Games" , "id Software" , "DOOMEternal" , "base" , "savegame" ) ;
14
+ public const int SteamGameID = 782330 ;
15
+ public static string SteamSavePath = Path . Combine ( Utilities . GetSteamPath ( ) , "userdata" ) ;
16
+ public static string BnetSavePath = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . UserProfile ) , "Saved Games" , "id Software" , "DOOMEternal" , "base" , "savegame" ) ;
13
17
14
18
public const string BackupPassword = "doometernalbackup" ;
15
19
16
- public static string [ ] GetUserIDs ( ) {
17
- return Directory . GetDirectories ( SavePath , "*.*" , SearchOption . TopDirectoryOnly ) . Select ( single => Path . GetFileNameWithoutExtension ( single ) ) . Where ( single => Utilities . CheckUUID ( single ) ) . ToArray ( ) ;
20
+ public static DoomEternalSaveCollection Saves ;
21
+
22
+ public static void EnumerateSaves ( ) {
23
+ Saves = new DoomEternalSaveCollection ( ) ;
24
+ foreach ( var single in Directory . GetDirectories ( BnetSavePath , "*.*" , SearchOption . TopDirectoryOnly ) ) {
25
+ if ( Utilities . CheckUUID ( Path . GetFileNameWithoutExtension ( single ) ) )
26
+ Saves . Add ( new DoomEternalSave ( Path . GetFileNameWithoutExtension ( single ) , BnetSavePath , DoomEternalSavePlatform . BethesdaNet ) ) ;
27
+ }
28
+ foreach ( var steamId3 in Directory . GetDirectories ( SteamSavePath , "*.*" , SearchOption . TopDirectoryOnly ) ) {
29
+ Console . WriteLine ( Path . GetFileNameWithoutExtension ( steamId3 ) ) ;
30
+ foreach ( var single in Directory . GetDirectories ( steamId3 , "*.*" , SearchOption . TopDirectoryOnly ) ) {
31
+ if ( Path . GetFileNameWithoutExtension ( single ) == SteamGameID . ToString ( ) )
32
+ Saves . Add ( new DoomEternalSave ( ( int . Parse ( Path . GetFileNameWithoutExtension ( steamId3 ) ) + 76561197960265728 ) . ToString ( ) , SteamSavePath , DoomEternalSavePlatform . Steam ) ) ;
33
+ }
34
+ }
35
+ Saves . Add ( new DoomEternalSave ( "savegame.unencrypted" , BnetSavePath , DoomEternalSavePlatform . BethesdaNet ) ) ;
18
36
}
19
37
20
- public static void FileEncrypt ( string fromFile , string toFile , string toUUID ) {
38
+ #region Bethesda.net
39
+ public static void BnetFileEncrypt ( string fromFile , string toFile , string toUUID ) {
21
40
if ( fromFile . EndsWith ( "-BACKUP" ) )
22
41
return ;
23
42
byte [ ] fromFileData = File . ReadAllBytes ( fromFile ) ;
24
43
Directory . CreateDirectory ( Path . GetDirectoryName ( toFile ) ) ;
25
44
File . WriteAllBytes ( toFile , Crypto . EncryptAndDigest ( $ "{ toUUID } PAINELEMENTAL{ Path . GetFileName ( toFile ) } ", fromFileData ) ) ;
26
45
}
27
46
28
- public static void FileDecrypt ( string fromFile , string fromUUID , string toFile ) {
47
+ public static void BnetFileDecrypt ( string fromFile , string fromUUID , string toFile ) {
29
48
if ( fromFile . EndsWith ( "-BACKUP" ) )
30
49
return ;
31
50
byte [ ] fromFileData = Crypto . DecryptAndVerify ( $ "{ fromUUID } PAINELEMENTAL{ Path . GetFileName ( fromFile ) } ", File . ReadAllBytes ( fromFile ) ) ;
32
51
Directory . CreateDirectory ( Path . GetDirectoryName ( toFile ) ) ;
33
52
File . WriteAllBytes ( toFile , fromFileData ) ;
34
53
}
35
54
36
- public static void FileTransfer ( string fromFile , string fromUUID , string toFile , string toUUID ) {
55
+ public static void BnetFileTransfer ( string fromFile , string fromUUID , string toFile , string toUUID ) {
37
56
if ( fromFile . EndsWith ( "-BACKUP" ) )
38
57
return ;
39
58
byte [ ] fromFileData = Crypto . DecryptAndVerify ( $ "{ fromUUID } PAINELEMENTAL{ Path . GetFileName ( fromFile ) } ", File . ReadAllBytes ( fromFile ) ) ;
40
59
Directory . CreateDirectory ( Path . GetDirectoryName ( toFile ) ) ;
41
60
File . WriteAllBytes ( toFile , Crypto . EncryptAndDigest ( $ "{ toUUID } PAINELEMENTAL{ Path . GetFileName ( toFile ) } ", fromFileData ) ) ;
42
61
}
43
62
44
- public static void BulkTransfer ( string fromUUID , string toUUID ) {
45
- string fromDir = Path . Combine ( SavePath , fromUUID ) ;
63
+ public static void BnetBulkTransfer ( string fromUUID , string toUUID ) {
64
+ string fromDir = Path . Combine ( BnetSavePath , fromUUID ) ;
46
65
foreach ( var single in Directory . GetFiles ( fromDir , "*.*" , SearchOption . AllDirectories ) ) {
47
- FileTransfer ( single , fromUUID , single . Replace ( fromUUID , toUUID ) , toUUID ) ;
66
+ BnetFileTransfer ( single , fromUUID , single . Replace ( fromUUID , toUUID ) , toUUID ) ;
67
+ }
68
+ }
69
+
70
+ public static void BnetBulkEncrypt ( string fromDir , string toUUID ) {
71
+ string toDir = Path . Combine ( BnetSavePath , toUUID ) ;
72
+ foreach ( var single in Directory . GetFiles ( fromDir , "*.*" , SearchOption . AllDirectories ) ) {
73
+ BnetFileEncrypt ( single , Path . Combine ( toDir , single . Replace ( fromDir , "" ) . Substring ( 1 ) ) , toUUID ) ;
74
+ }
75
+ }
76
+
77
+ public static void BnetBulkDecrypt ( string fromUUID , string toDir ) {
78
+ string fromDir = Path . Combine ( BnetSavePath , fromUUID ) ;
79
+ foreach ( var single in Directory . GetFiles ( fromDir , "*.*" , SearchOption . AllDirectories ) ) {
80
+ BnetFileDecrypt ( single , fromUUID , Path . Combine ( toDir , single . Replace ( Path . Combine ( BnetSavePath , fromUUID ) , "" ) . Substring ( 1 ) ) ) ;
81
+ }
82
+ }
83
+ #endregion
84
+
85
+ #region Steam
86
+ public static void SteamFileEncrypt ( string fromFile , string toFile , string toId ) {
87
+ //toId = Utilities.Id64ToId3(toId);
88
+ if ( fromFile . EndsWith ( "-BACKUP" ) )
89
+ return ;
90
+ byte [ ] fromFileData = File . ReadAllBytes ( fromFile ) ;
91
+ Directory . CreateDirectory ( Path . GetDirectoryName ( toFile ) ) ;
92
+ File . WriteAllBytes ( toFile , Crypto . EncryptAndDigest ( $ "{ toId } MANCUBUS{ Path . GetFileName ( toFile ) } ", fromFileData ) ) ;
93
+ }
94
+
95
+ public static void SteamFileDecrypt ( string fromFile , string fromId , string toFile ) {
96
+ //fromId = Utilities.Id64ToId3(fromId);
97
+ if ( fromFile . EndsWith ( "-BACKUP" ) )
98
+ return ;
99
+ byte [ ] fromFileData = Crypto . DecryptAndVerify ( $ "{ fromId } MANCUBUS{ Path . GetFileName ( fromFile ) } ", File . ReadAllBytes ( fromFile ) ) ;
100
+ Directory . CreateDirectory ( Path . GetDirectoryName ( toFile ) ) ;
101
+ File . WriteAllBytes ( toFile , fromFileData ) ;
102
+ }
103
+
104
+ public static void SteamFileTransfer ( string fromFile , string fromId , string toFile , string toId ) {
105
+ fromId = Utilities . Id64ToId3 ( fromId ) ;
106
+ toId = Utilities . Id64ToId3 ( toId ) ;
107
+ if ( fromFile . EndsWith ( "-BACKUP" ) )
108
+ return ;
109
+ byte [ ] fromFileData = Crypto . DecryptAndVerify ( $ "{ Utilities . Id3ToId64 ( fromId ) } MANCUBUS{ Path . GetFileName ( fromFile ) } ", File . ReadAllBytes ( fromFile ) ) ;
110
+ Directory . CreateDirectory ( Path . GetDirectoryName ( toFile ) ) ;
111
+ File . WriteAllBytes ( toFile , Crypto . EncryptAndDigest ( $ "{ Utilities . Id3ToId64 ( toId ) } MANCUBUS{ Path . GetFileName ( toFile ) } ", fromFileData ) ) ;
112
+ }
113
+
114
+ public static void SteamBulkTransfer ( string fromId , string toId ) {
115
+ fromId = Utilities . Id64ToId3 ( fromId ) ;
116
+ toId = Utilities . Id64ToId3 ( toId ) ;
117
+ string fromDir = Path . Combine ( BnetSavePath , fromId ) ;
118
+ foreach ( var single in Directory . GetFiles ( fromDir , "*.*" , SearchOption . AllDirectories ) ) {
119
+ SteamFileTransfer ( single , fromId , single . Replace ( fromId , toId ) , toId ) ;
48
120
}
49
121
}
50
122
51
- public static void BulkEncrypt ( string fromDir , string toUUID ) {
52
- string toDir = Path . Combine ( SavePath , toUUID ) ;
123
+ public static void SteamBulkEncrypt ( string fromDir , string toId ) {
124
+ toId = Utilities . Id64ToId3 ( toId ) ;
125
+ string toDir = Path . Combine ( SteamSavePath , toId , SteamGameID . ToString ( ) , "remote" ) ;
53
126
foreach ( var single in Directory . GetFiles ( fromDir , "*.*" , SearchOption . AllDirectories ) ) {
54
- Console . WriteLine ( Path . Combine ( toDir , single . Replace ( fromDir , "" ) . Substring ( 1 ) ) ) ;
55
- FileEncrypt ( single , Path . Combine ( toDir , single . Replace ( fromDir , "" ) . Substring ( 1 ) ) , toUUID ) ;
127
+ SteamFileEncrypt ( single , Path . Combine ( toDir , single . Replace ( fromDir , "" ) . Substring ( 1 ) ) , Utilities . Id3ToId64 ( toId ) ) ;
56
128
}
57
129
}
58
130
59
- public static void BulkDecrypt ( string fromUUID , string toDir ) {
60
- string fromDir = Path . Combine ( SavePath , fromUUID ) ;
131
+ public static void SteamBulkDecrypt ( string fromId , string toDir ) {
132
+ fromId = Utilities . Id64ToId3 ( fromId ) ;
133
+ string fromDir = Path . Combine ( SteamSavePath , fromId , SteamGameID . ToString ( ) , "remote" ) ;
61
134
foreach ( var single in Directory . GetFiles ( fromDir , "*.*" , SearchOption . AllDirectories ) ) {
62
- FileDecrypt ( single , fromUUID , Path . Combine ( toDir , single . Replace ( Path . Combine ( SavePath , fromUUID ) , "" ) . Substring ( 1 ) ) ) ;
135
+ SteamFileDecrypt ( single , Utilities . Id3ToId64 ( fromId ) , Path . Combine ( toDir , single . Replace ( Path . Combine ( SteamSavePath , fromId , SteamGameID . ToString ( ) , "remote" ) , "" ) . Substring ( 1 ) ) ) ;
63
136
}
64
137
}
138
+ #endregion
139
+
140
+ #region Both
141
+ public static void BnetToSteamTransfer ( string fromId , string toId ) {
142
+ Directory . CreateDirectory ( "tmp" ) ;
143
+ BnetBulkDecrypt ( fromId , "tmp" ) ;
144
+ SteamBulkEncrypt ( "tmp" , toId ) ;
145
+ Directory . Delete ( "tmp" , true ) ;
146
+ }
147
+
148
+ public static void SteamToBnetTransfer ( string fromId , string toId ) {
149
+ Directory . CreateDirectory ( "tmp" ) ;
150
+ SteamBulkDecrypt ( fromId , "tmp" ) ;
151
+ BnetBulkEncrypt ( "tmp" , toId ) ;
152
+ Directory . Delete ( "tmp" , true ) ;
153
+ }
154
+ #endregion
65
155
}
66
156
}
0 commit comments