22using System . Linq ;
33
44using System . IO ;
5+ using System . Collections . Generic ;
6+ using System . Reflection . Emit ;
57
68namespace DOOMSaveManager
79{
810 public class DoomEternal
911 {
1012 public const string GameName = "Doom Eternal" ;
1113
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" ) ;
1317
1418 public const string BackupPassword = "doometernalbackup" ;
1519
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 ) ) ;
1836 }
1937
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 ) {
2140 if ( fromFile . EndsWith ( "-BACKUP" ) )
2241 return ;
2342 byte [ ] fromFileData = File . ReadAllBytes ( fromFile ) ;
2443 Directory . CreateDirectory ( Path . GetDirectoryName ( toFile ) ) ;
2544 File . WriteAllBytes ( toFile , Crypto . EncryptAndDigest ( $ "{ toUUID } PAINELEMENTAL{ Path . GetFileName ( toFile ) } ", fromFileData ) ) ;
2645 }
2746
28- public static void FileDecrypt ( string fromFile , string fromUUID , string toFile ) {
47+ public static void BnetFileDecrypt ( string fromFile , string fromUUID , string toFile ) {
2948 if ( fromFile . EndsWith ( "-BACKUP" ) )
3049 return ;
3150 byte [ ] fromFileData = Crypto . DecryptAndVerify ( $ "{ fromUUID } PAINELEMENTAL{ Path . GetFileName ( fromFile ) } ", File . ReadAllBytes ( fromFile ) ) ;
3251 Directory . CreateDirectory ( Path . GetDirectoryName ( toFile ) ) ;
3352 File . WriteAllBytes ( toFile , fromFileData ) ;
3453 }
3554
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 ) {
3756 if ( fromFile . EndsWith ( "-BACKUP" ) )
3857 return ;
3958 byte [ ] fromFileData = Crypto . DecryptAndVerify ( $ "{ fromUUID } PAINELEMENTAL{ Path . GetFileName ( fromFile ) } ", File . ReadAllBytes ( fromFile ) ) ;
4059 Directory . CreateDirectory ( Path . GetDirectoryName ( toFile ) ) ;
4160 File . WriteAllBytes ( toFile , Crypto . EncryptAndDigest ( $ "{ toUUID } PAINELEMENTAL{ Path . GetFileName ( toFile ) } ", fromFileData ) ) ;
4261 }
4362
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 ) ;
4665 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 ) ;
48120 }
49121 }
50122
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" ) ;
53126 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 ) ) ;
56128 }
57129 }
58130
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" ) ;
61134 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 ) ) ) ;
63136 }
64137 }
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
65155 }
66156}
0 commit comments