Example #1
0
 public void Load()
 {
     lock (FileLock)
     {
         XmlElement config = XmlHelper.LoadDocument(ConfigurationFilePath);
         GameLocation = GameLocationInfo.FromXml(config["GameLocation"]);
         WorkingLocation = WorkingLocationInfo.FromXml(config["WorkingLocation"]);
         FileCommanderSelectedNodePath = config.FindString("FileCommanderSelectedNodePath");
     }
 }
Example #2
0
        protected override async Task DoAction()
        {
            Label = PlayingLabel;
            try
            {
                Maximum = 2;

                GameLocationInfo gameLocation = PatcherService.GetGameLocation(FFXIIIGamePart.Part1);
                gameLocation.Validate();
                Position = 1;

                if (CancelEvent.WaitOne(0))
                {
                    return;
                }

                if (MusicPlayer != null && MusicPlayer.PlaybackState == NAudio.Wave.PlaybackState.Playing)
                {
                    MusicPlayer.Pause();
                }

                String args = GameSettings.GetGameProcessArguments();

                await Task.Factory.StartNew(() => Process.Start(gameLocation.ExecutablePath, args));

                Position = 2;

                if (InteractionService.LocalizatorEnvironment.Provide().ExitAfterRunGame)
                {
                    Application.Current.MainWindow.Close();
                }
            }
            finally
            {
                Label = PlayLabel;
            }
        }
Example #3
0
        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();
            }
        }