public static LeagueClientInfo FromStringArray(string[] info)
        {
            if (info.Length < 5)
            {
                ThrowParseFailed(nameof(info));
            }

            LeagueClientInfo lci = new LeagueClientInfo
            {
                ProcessName = info[0],
                Password    = info[3],
                ComProtocol = info[4]
            };

            if (!int.TryParse(info[1], out lci.ProcessId))
            {
                ThrowParseFailed(nameof(ProcessId));
            }
            if (!int.TryParse(info[2], out lci.ProcessPort))
            {
                ThrowParseFailed(nameof(ProcessPort));
            }
            return(lci);
        }
Ejemplo n.º 2
0
        private static async Task Main(string[] args)
        {
            AppDomain.CurrentDomain.ProcessExit += new EventHandler(OnProcessExit);

            string programDataPath = Environment.GetEnvironmentVariable("programdata") ?? string.Empty;

            if (string.IsNullOrEmpty(programDataPath))
            {
                throw new Exception("Could not find program data. Please try again.");
            }

            string riotGamesDataFolder = Path.Combine(programDataPath, "Riot Games");

            if (Directory.Exists(riotGamesDataFolder))
            {
                string installsPath = Path.Combine(riotGamesDataFolder, "RiotClientInstalls.Json");
                if (File.Exists(installsPath))
                {
                    foreach (string line in File.ReadAllLines(installsPath))
                    {
                        if (line.Contains("rc_live"))
                        {
                            RiotServicePath = line.Substring(line.IndexOf(":") + 1).Replace("\"", "").Trim();
                        }
                    }
                }
            }

            try
            {
                string newPath = Path.Combine(Path.GetDirectoryName(RiotServicePath), "_RiotClientServices.exe");

                File.Move(RiotServicePath, newPath);
                RiotServicePath = newPath;
            }
            catch
            {
                Cleanup();
            }

            if (!HasClientPath())
            {
                Console.WriteLine("Please edit config.txt to include the install path to League of Legends and relaunch this application.\nPress enter to exit...");
                Console.ReadLine();
                return;
            }

            LeagueClientInfo lci = await GetLeagueClientInfo();

            ComClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes($"riot:{lci.Password}")));

            HttpResponseMessage response = await ComClient.GetAsync($"{lci.ComProtocol}://127.0.0.1:{lci.ProcessPort}/swagger/v2/swagger.json", HttpCompletionOption.ResponseContentRead);

            //TODO: Create swagger api generation from responses
            if (response.StatusCode == HttpStatusCode.OK)
            {
                string swaggerData = await response.Content.ReadAsStringAsync();

                Console.WriteLine(swaggerData);

                response = await ComClient.GetAsync($"{lci.ComProtocol}://127.0.0.1:{lci.ProcessPort}/Help?format=Full", HttpCompletionOption.ResponseContentRead);

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    string helpData = await response.Content.ReadAsStringAsync();

                    Console.WriteLine(helpData);
                }
            }
            else if (response.StatusCode == HttpStatusCode.NotFound)
            {
                Console.WriteLine($"Swagger not enabled. {ErrorCloseAndRelaunch}");
            }
            else
            {
                Console.WriteLine($"Unexpected error. {ErrorCloseAndRelaunch}");
            }

            Console.WriteLine("Press enter to exit...");
            Console.ReadLine();
            Cleanup();
        }
Ejemplo n.º 3
0
        private static async Task <LeagueClientInfo> GetLeagueClientInfo()
        {
            LeagueClientInfo?lci = null;

            try
            {
                lci           = LeagueClientInfo.FromFile(new FileInfo(Path.Combine(LeagueClientPath, "lockfile")));
                ClientProcess = Process.GetProcessById(lci.ProcessId);
            }
            catch (Exception ex) when(ex is ArgumentException || ex is FileNotFoundException)
            {
                ClientProcess = null;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            if (ClientProcess is null)
            {
                string localYaml = Path.Combine(Environment.CurrentDirectory, "system_swagger.yaml");
                if (!File.Exists(localYaml))
                {
                    using (FileStream sys = File.Open(Path.Combine(LeagueClientPath, "system.yaml"), FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
                        using (TextReader trSys = new StreamReader(sys))
                            using (FileStream sysCopy = File.Create(localYaml))
                                using (TextWriter tw = new StreamWriter(sysCopy))
                                {
                                    while (sys.Position < sys.Length)
                                    {
                                        string line = trSys.ReadLine() ?? string.Empty;

                                        if (line.StartsWith("enable_swagger"))
                                        {
                                            continue;
                                        }

                                        if (line.StartsWith("riotclient"))
                                        {
                                            while ((trSys.ReadLine() ?? string.Empty).StartsWith("\t"))
                                            {
                                                continue;
                                            }
                                            continue;
                                        }

                                        tw.WriteLine(line);
                                    }
                                    tw.WriteLine("enable_swagger: true");
                                }
                }

                ClientProcess = Process.Start(Path.Combine(LeagueClientPath, "LeagueClient.exe"),
                                              $"--disable-patching --headless --disable-self-update --system-yaml-override=\"{localYaml}\"");
                SelfLaunched = true;
                await Task.Delay(500);

                lci = LeagueClientInfo.FromFile(new FileInfo(Path.Combine(LeagueClientPath, "lockfile")));
            }

            if (lci is null)
            {
                Cleanup();
            }

            return(lci);
        }