Skip to content

Commit 4a0d8c9

Browse files
committed
Fixed a bug with settings being reset
1 parent b357b2f commit 4a0d8c9

1 file changed

Lines changed: 49 additions & 10 deletions

File tree

Celeste_Launcher_Gui/Services/GameService.cs

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public static async Task StartGame(bool isOffline = false)
4141
return;
4242
}
4343

44+
BackupOrRestorePlayerColors();
45+
4446
//QuickGameScan
4547
if (!isOffline || InternetUtils.IsConnectedToInternet())
4648
{
@@ -272,17 +274,8 @@ public static async Task StartGame(bool isOffline = false)
272274
arg =
273275
$"--email \"{CurrentEmail}\" --password \"{CurrentPassword.GetValue()}\" --online-ip \"{LegacyBootstrapper.UserConfig.MpSettings.PublicIp}\" --ignore_rest LauncherLang={lang} LauncherLocale=1033";
274276

275-
var playerColorsConfigPath = Path.Combine(gamePath, "Data", "playercolors.shadow.xml");
276-
var playerColorsGamePath = Path.Combine(gamePath, "Data", "playercolors.xml");
277-
278-
if (File.Exists(playerColorsConfigPath))
279-
{
280-
if (File.Exists(playerColorsGamePath))
281-
File.Delete(playerColorsGamePath);
277+
PatchPlayerColors();
282278

283-
File.Move(playerColorsConfigPath, playerColorsGamePath);
284-
}
285-
286279
Logger.Information("Starting game {@GameExecutable} at {@GamePath}", spartanPath, gamePath);
287280
var gameProcess = Process.Start(new ProcessStartInfo(spartanPath, arg) { WorkingDirectory = gamePath });
288281

@@ -299,6 +292,52 @@ public static async Task StartGame(bool isOffline = false)
299292
}
300293
}
301294

295+
private static void BackupOrRestorePlayerColors()
296+
{
297+
var backupPath = PlayerColorsBackup();
298+
var gamePath = PlayerColorsGame();
299+
var userPath = PlayerColorsPathUserModified();
300+
301+
// If a user has set settings that should be patched, we start with this flow
302+
if (File.Exists(userPath))
303+
{
304+
// If there is a backup, restore it
305+
if (File.Exists(backupPath))
306+
{
307+
File.Delete(gamePath);
308+
File.Copy(backupPath, gamePath);
309+
}
310+
else
311+
{
312+
// No backup exists, create it
313+
File.Copy(gamePath, backupPath);
314+
}
315+
}
316+
}
317+
318+
private static void PatchPlayerColors()
319+
{
320+
var playerColorsConfigPath = PlayerColorsPathUserModified();
321+
var playerColorsGamePath = PlayerColorsGame();
322+
323+
if (File.Exists(playerColorsConfigPath))
324+
{
325+
if (File.Exists(playerColorsGamePath))
326+
File.Delete(playerColorsGamePath);
327+
328+
File.Copy(playerColorsConfigPath, playerColorsGamePath);
329+
}
330+
}
331+
332+
private static string PlayerColorsPathUserModified()
333+
=> Path.Combine(LegacyBootstrapper.UserConfig.GameFilesPath, "Data", "playercolors.shadow.xml");
334+
335+
private static string PlayerColorsGame()
336+
=> Path.Combine(LegacyBootstrapper.UserConfig.GameFilesPath, "Data", "playercolors.xml");
337+
338+
private static string PlayerColorsBackup()
339+
=> Path.Combine(LegacyBootstrapper.UserConfig.GameFilesPath, "Data", "playercolors.bak.xml");
340+
302341
public static async Task WaitForGameToExit()
303342
{
304343
await ProcesInvoker.WaitForProcessToExit("Spartan");

0 commit comments

Comments
 (0)