public static FileCopier TryGetFileCopier(Deploy deployTask) { try { GameLocationInfo gameLocation = GameLocationSteamRegistryProvider.TryLoad(); if (gameLocation == null) { LogWarning(deployTask, "Cannot find the game folder."); return(null); } Boolean isX64Exists = Directory.Exists(gameLocation.ManagedPathX64); Boolean isX86Exists = Directory.Exists(gameLocation.ManagedPathX86); if (isX64Exists) { return(isX86Exists ? new FileCopier(deployTask, gameLocation.ManagedPathX64, gameLocation.ManagedPathX86) : new FileCopier(deployTask, gameLocation.ManagedPathX64, null)); } if (isX86Exists) { return(new FileCopier(deployTask, null, gameLocation.ManagedPathX86)); } LogWarning(deployTask, $"Cannot find an assembly directory in the game folder [{gameLocation.RootDirectory}]."); return(null); } catch (FileNotFoundException ex) { LogWarning(deployTask, $"Cannot find a launcher in the game folder [{ex.FileName}]."); return(null); } catch (Exception ex) { LogWarning(deployTask, "Cannot find the game folder."); deployTask._log.LogWarningFromException(ex, showStackTrace: true); return(null); } }
public static void Main(String[] args) { try { GameLocationInfo gameLocation = GameLocationSteamRegistryProvider.TryLoad(); if (gameLocation == null) { return; } if (!Directory.Exists(gameLocation.ManagedPath)) { return; } String executablePath = gameLocation.LauncherPath; String backupPath = Path.ChangeExtension(executablePath, ".bak"); String unityPath = gameLocation.RootDirectory + "\\Unity.exe"; if (!File.Exists(unityPath)) { if (!File.Exists(backupPath)) { File.Copy(executablePath, backupPath); File.SetLastWriteTimeUtc(backupPath, File.GetLastWriteTimeUtc(executablePath)); } File.Copy(executablePath, unityPath); File.SetLastWriteTimeUtc(unityPath, File.GetLastWriteTimeUtc(executablePath)); File.Delete(executablePath); if (!Kernel32.CreateHardLink(executablePath, unityPath, IntPtr.Zero)) { throw new Win32Exception(); } } executablePath = unityPath; String dataPath = gameLocation.DataPath; String unityDataPath = Path.GetFullPath(gameLocation.RootDirectory + "\\Unity_Data"); if (!Directory.Exists(unityDataPath)) { JunctionPoint.Create(unityDataPath, dataPath, true); } else { try { foreach (String item in Directory.EnumerateFileSystemEntries(unityDataPath)) { break; } } catch { JunctionPoint.Delete(unityDataPath); JunctionPoint.Create(unityDataPath, dataPath, true); } } ChangeUnityDebugger("1", out String oldValue); try { ProcessStartInfo gameStartInfo = new ProcessStartInfo(executablePath) { UseShellExecute = false }; gameStartInfo.EnvironmentVariables["UNITY_GIVE_CHANCE_TO_ATTACH_DEBUGGER"] = "1"; gameStartInfo.WorkingDirectory = gameLocation.RootDirectory; Process gameProcess = new Process { StartInfo = gameStartInfo }; gameProcess.Start(); Byte[] unicodeDllPath = PrepareDllPath(); TimeSpan timeout = GetTimeout(args); CancellationTokenSource cts = new CancellationTokenSource(); Console.CancelKeyPress += (o, s) => { Console.WriteLine(); Console.WriteLine("Stopping..."); cts.Cancel(); }; Task task = Task.Factory.StartNew(() => MainLoop(unicodeDllPath, cts, timeout), cts.Token, TaskCreationOptions.LongRunning, TaskScheduler.Current); Console.WriteLine("Waiting for an debug invitation."); Console.WriteLine("Type 'help' to show an documenantion or press Ctrl+C to exit."); while (!(cts.IsCancellationRequested || task.IsCompleted)) { Task <String> readLine = Task.Factory.StartNew(() => Console.ReadLine()?.ToLower(), cts.Token, TaskCreationOptions.LongRunning, TaskScheduler.Current); readLine.Wait(cts.Token); switch (readLine.Result) { case "help": Console.WriteLine(); Console.WriteLine("help\t\t This message."); Console.WriteLine("stop\t\t Stop waiting and close the application."); break; case "stop": Console.WriteLine(); Console.WriteLine("Stopping..."); cts.Cancel(); task.Wait(cts.Token); break; default: Console.WriteLine(); Console.WriteLine("Unrecognized command."); break; } } } finally { ChangeUnityDebugger(oldValue, out oldValue); } } catch (OperationCanceledException) { } catch (Exception ex) { Console.WriteLine(); Console.WriteLine("Unexpected error has occurred."); Console.WriteLine(ex); Console.WriteLine(); Console.WriteLine("Press enter to exit..."); Console.ReadLine(); } }