示例#1
0
        private void CloneItem_OnClick(object sender, RoutedEventArgs e)
        {
            if (InstalledAssembliesDataGrid.SelectedItems.Count <= 0)
            {
                return;
            }
            var selectedAssembly = (LeagueSharpAssembly)InstalledAssembliesDataGrid.SelectedItems[0];

            try
            {
                var source      = Path.GetDirectoryName(selectedAssembly.PathToProjectFile);
                var destination = Path.Combine(Directories.LocalRepoDir, selectedAssembly.Name) + "_clone_" +
                                  Environment.TickCount.GetHashCode().ToString("X");
                Utility.CopyDirectory(source, destination);
                var leagueSharpAssembly = new LeagueSharpAssembly(
                    selectedAssembly.Name + "_clone",
                    Path.Combine(destination, Path.GetFileName(selectedAssembly.PathToProjectFile)), "");
                leagueSharpAssembly.Compile();
                Config.SelectedProfile.InstalledAssemblies.Add(leagueSharpAssembly);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
示例#2
0
        internal static bool Update(LeagueSharpAssembly assembly)
        {
            if (Repository.IsValid(assembly.PathToRepository))
            {
                try
                {
                    Fetch(assembly.PathToRepository, "origin");
                }
                catch (Exception e)
                {
                    Log.WarnFormat("Download failed {0} - {1}\n{2}", assembly.Name, assembly.Location, e);
                    return(false);
                }

                try
                {
                    Checkout(assembly.PathToRepository, "origin/master");
                }
                catch (Exception e)
                {
                    Log.Warn(e);
                }

                return(true);
            }

            return(false);
        }
示例#3
0
        private static void UpdateAssembly(LeagueSharpAssembly assembly)
        {
            if (Repository.IsValid(assembly.PathToRepository))
            {
                var versions = new List <AssemblyVersion>();

                using (var repo = new Repository(assembly.PathToRepository))
                {
                    var commits = repo.Head.Commits.ToList();
                    var id      = commits.Count;
                    foreach (var commit in commits)
                    {
                        versions.Add(
                            new AssemblyVersion
                        {
                            Id      = id--,
                            Date    = commit.Committer.When,
                            Message = commit.MessageShort,
                            Hash    = commit.Sha
                        });
                    }
                }

                assembly.Versions = versions;
            }
        }
        private void InstalledAssembliesDataGrid_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            rowIndex = GetCurrentRowIndex(e.GetPosition);
            if (rowIndex < 0)
            {
                return;
            }
            InstalledAssembliesDataGrid.SelectedIndex = rowIndex;
            LeagueSharpAssembly selectedAssembly = InstalledAssembliesDataGrid.Items[rowIndex] as LeagueSharpAssembly;

            if (selectedAssembly == null)
            {
                return;
            }
            if (DragDrop.DoDragDrop(InstalledAssembliesDataGrid, selectedAssembly, DragDropEffects.Move) !=
                DragDropEffects.None)
            {
                //InstalledAssembliesDataGrid.SelectedItem = selectedAssembly;
            }
        }
        private void InstalledAssembliesDataGrid_Drop(object sender, DragEventArgs e)
        {
            if (rowIndex < 0)
            {
                return;
            }
            int index = GetCurrentRowIndex(e.GetPosition);

            if (index < 0)
            {
                return;
            }
            if (index == rowIndex)
            {
                return;
            }
            LeagueSharpAssembly changedAssembly = Config.SelectedProfile.InstalledAssemblies[rowIndex];

            Config.SelectedProfile.InstalledAssemblies.RemoveAt(rowIndex);
            Config.SelectedProfile.InstalledAssemblies.Insert(index, changedAssembly);
        }
示例#6
0
        protected override void OnStartup(StartupEventArgs e)
        {
            if (File.Exists(Updater.SetupFile))
            {
                Thread.Sleep(1000);
            }

            bool createdNew;

            _mutex = new Mutex(true, Utility.Md5Hash(Environment.UserName), out createdNew);

            Utility.CreateFileFromResource(Directories.ConfigFilePath, "LeagueSharp.Loader.Resources.config.xml");

            var configCorrupted = false;

            try
            {
                Config.Instance = ((Config)Utility.MapXmlFileToClass(typeof(Config), Directories.ConfigFilePath));
            }
            catch (Exception)
            {
                configCorrupted = true;
            }

            if (!configCorrupted)
            {
                try
                {
                    if (File.Exists(Directories.ConfigFilePath + ".bak"))
                    {
                        File.Delete(Directories.ConfigFilePath + ".bak");
                    }
                    File.Copy(Directories.ConfigFilePath, Directories.ConfigFilePath + ".bak");
                    File.SetAttributes(Directories.ConfigFilePath + ".bak", FileAttributes.Hidden);
                }
                catch (Exception)
                {
                    //ignore
                }
            }
            else
            {
                try
                {
                    Config.Instance = ((Config)Utility.MapXmlFileToClass(typeof(Config), Directories.ConfigFilePath + ".bak"));
                    File.Delete(Directories.ConfigFilePath);
                    File.Copy(Directories.ConfigFilePath + ".bak", Directories.ConfigFilePath);
                    File.SetAttributes(Directories.ConfigFilePath, FileAttributes.Normal);
                }
                catch (Exception)
                {
                    File.Delete(Directories.ConfigFilePath + ".bak");
                    File.Delete(Directories.ConfigFilePath);
                    MessageBox.Show("Couldn't load config.xml.");
                    Environment.Exit(0);
                }
            }

            #region Add GameSetting DisableDrawings

            if (Config.Instance.Settings.GameSettings.All(x => x.Name != "Show Drawings"))
            {
                Config.Instance.Settings.GameSettings.Add(new GameSettings
                {
                    Name          = "Show Drawings",
                    PosibleValues = new List <string> {
                        "True", "False"
                    },
                    SelectedValue = "True"
                });
            }

            if (Config.Instance.Settings.GameSettings.All(x => x.Name != "Show Ping"))
            {
                Config.Instance.Settings.GameSettings.Add(new GameSettings
                {
                    Name          = "Show Ping",
                    PosibleValues = new List <string> {
                        "True", "False"
                    },
                    SelectedValue = "True"
                });
            }

            if (Config.Instance.Settings.GameSettings.All(x => x.Name != "Send Anonymous Assembly Statistics"))
            {
                Config.Instance.Settings.GameSettings.Add(new GameSettings
                {
                    Name          = "Send Anonymous Assembly Statistics",
                    PosibleValues = new List <string> {
                        "True", "False"
                    },
                    SelectedValue = "True"
                });
            }

            try
            {
                if (Config.Instance.Profiles.First().InstalledAssemblies.All(a => a.Name != "LeagueSharp.SDK"))
                {
                    var sdk = new LeagueSharpAssembly
                    {
                        Name              = "LeagueSharp.SDK",
                        DisplayName       = "LeagueSharp.SDK",
                        SvnUrl            = "https://github.com/LeagueSharp/LeagueSharp.SDK",
                        InjectChecked     = true,
                        InstallChecked    = true,
                        PathToProjectFile = Path.Combine(Directories.RepositoryDir, "8443D874", "trunk", "LeagueSharp.SDK.csproj")
                    };

                    sdk.Update();
                    sdk.Compile();

                    Config.Instance.Profiles.First().InstalledAssemblies.Add(sdk);
                }
            }
            catch
            {
                // wtf
            }

            #endregion

            #region Remove the old loader

            try
            {
                if (String.Compare(
                        Process.GetCurrentProcess().ProcessName, "LeagueSharp.Loader.exe",
                        StringComparison.InvariantCultureIgnoreCase) != 0 && File.Exists(Path.Combine(Directories.CurrentDirectory, "LeagueSharp.Loader.exe")))
                {
                    File.Delete(Path.Combine(Directories.CurrentDirectory, "LeagueSharp.Loader.exe"));
                    File.Delete(Path.Combine(Directories.CurrentDirectory, "LeagueSharp.Loader.exe.config"));
                }
            }
            catch (Exception ex)
            {
                //ignore
            }

            #endregion

            #region AppData randomization

            try
            {
                if (!Directory.Exists(Directories.AppDataDirectory))
                {
                    Directory.CreateDirectory(Directories.AppDataDirectory);

                    var oldPath = Path.Combine(Environment.GetFolderPath(
                                                   Environment.SpecialFolder.ApplicationData), "LeagueSharp" + Environment.UserName.GetHashCode().ToString("X"));

                    var oldPath2 = Path.Combine(Environment.GetFolderPath(
                                                    Environment.SpecialFolder.ApplicationData), "LeagueSharp");

                    if (Directory.Exists(oldPath))
                    {
                        Utility.CopyDirectory(oldPath, Directories.AppDataDirectory, true, true);
                        Utility.ClearDirectory(oldPath);
                        Directory.Delete(oldPath, true);
                    }

                    if (Directory.Exists(oldPath2))
                    {
                        Utility.CopyDirectory(oldPath2, Directories.AppDataDirectory, true, true);
                        Utility.ClearDirectory(oldPath2);
                        Directory.Delete(oldPath2, true);
                    }
                }
            }
            catch (Exception ex)
            {
                //ignore
            }

            #endregion

            //Load the language resources.
            var dict = new ResourceDictionary();

            if (Config.Instance.SelectedLanguage != null)
            {
                dict.Source = new Uri(
                    "..\\Resources\\Language\\" + Config.Instance.SelectedLanguage + ".xaml", UriKind.Relative);
            }
            else
            {
                var lid = Thread.CurrentThread.CurrentCulture.ToString().Contains("-")
                    ? Thread.CurrentThread.CurrentCulture.ToString().Split('-')[0].ToUpperInvariant()
                    : Thread.CurrentThread.CurrentCulture.ToString().ToUpperInvariant();
                switch (lid)
                {
                case "DE":
                    dict.Source = new Uri("..\\Resources\\Language\\German.xaml", UriKind.Relative);
                    break;

                case "AR":
                    dict.Source = new Uri("..\\Resources\\Language\\Arabic.xaml", UriKind.Relative);
                    break;

                case "ES":
                    dict.Source = new Uri("..\\Resources\\Language\\Spanish.xaml", UriKind.Relative);
                    break;

                case "FR":
                    dict.Source = new Uri("..\\Resources\\Language\\French.xaml", UriKind.Relative);
                    break;

                case "IT":
                    dict.Source = new Uri("..\\Resources\\Language\\Italian.xaml", UriKind.Relative);
                    break;

                case "KO":
                    dict.Source = new Uri("..\\Resources\\Language\\Korean.xaml", UriKind.Relative);
                    break;

                case "NL":
                    dict.Source = new Uri("..\\Resources\\Language\\Dutch.xaml", UriKind.Relative);
                    break;

                case "PL":
                    dict.Source = new Uri("..\\Resources\\Language\\Polish.xaml", UriKind.Relative);
                    break;

                case "PT":
                    dict.Source = new Uri("..\\Resources\\Language\\Portuguese.xaml", UriKind.Relative);
                    break;

                case "RO":
                    dict.Source = new Uri("..\\Resources\\Language\\Romanian.xaml", UriKind.Relative);
                    break;

                case "RU":
                    dict.Source = new Uri("..\\Resources\\Language\\Russian.xaml", UriKind.Relative);
                    break;

                case "SE":
                    dict.Source = new Uri("..\\Resources\\Language\\Swedish.xaml", UriKind.Relative);
                    break;

                case "TR":
                    dict.Source = new Uri("..\\Resources\\Language\\Turkish.xaml", UriKind.Relative);
                    break;

                case "VI":
                    dict.Source = new Uri("..\\Resources\\Language\\Vietnamese.xaml", UriKind.Relative);
                    break;

                case "ZH":
                    dict.Source = new Uri("..\\Resources\\Language\\Chinese.xaml", UriKind.Relative);
                    break;

                case "LT":
                    dict.Source = new Uri("..\\Resources\\Language\\Lithuanian.xaml", UriKind.Relative);
                    break;

                default:
                    dict.Source = new Uri("..\\Resources\\Language\\English.xaml", UriKind.Relative);
                    break;
                }
            }

            if (Config.Instance.SelectedColor != null)
            {
                ThemeManager.ChangeAppStyle(Application.Current, ThemeManager.GetAccent(Config.Instance.SelectedColor), ThemeManager.GetAppTheme("BaseLight"));
            }

            Resources.MergedDictionaries.Add(dict);

            #region Executable Randomization

            if (Assembly.GetExecutingAssembly().Location.EndsWith("loader.exe") || Assembly.GetExecutingAssembly().Location.EndsWith("Loader.exe"))
            {
                try
                {
                    if (Config.Instance.RandomName != null)
                    {
                        try
                        {
                            var oldFile       = Path.Combine(Directories.CurrentDirectory, Config.Instance.RandomName);
                            var oldConfigFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Config.Instance.RandomName + ".config");

                            if (File.Exists(oldFile))
                            {
                                File.SetAttributes(oldFile, FileAttributes.Normal);
                                File.Delete(oldFile);
                            }

                            if (File.Exists(oldConfigFile))
                            {
                                File.SetAttributes(oldConfigFile, FileAttributes.Normal);
                                File.Delete(oldConfigFile);
                            }
                        }
                        catch
                        {
                        }

                        if (!createdNew)
                        {
                            if (e.Args.Length > 0)
                            {
                                var loader = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(Config.Instance.RandomName)).FirstOrDefault();
                                if (loader != null && loader.MainWindowHandle != IntPtr.Zero)
                                {
                                    Clipboard.SetText(e.Args[0]);
                                    ShowWindow(loader.MainWindowHandle, 5);
                                    SetForegroundWindow(loader.MainWindowHandle);
                                }
                            }

                            _mutex = null;
                            Environment.Exit(0);
                        }
                    }

                    Config.Instance.RandomName = Utility.GetUniqueKey(6) + ".exe";
                    var filePath   = Path.Combine(Directories.CurrentDirectory, "loader.exe");
                    var rndExePath = Path.Combine(Directories.CurrentDirectory, Config.Instance.RandomName);
                    Utility.MapClassToXmlFile(typeof(Config), Config.Instance, Directories.ConfigFilePath);

                    File.Copy(filePath, rndExePath);
                    File.Copy(filePath + ".config", rndExePath + ".config");
                    Process.Start(rndExePath);
                    Environment.Exit(0);
                }
                catch (Exception)
                {
                    // restart
                }
            }

            AppDomain.CurrentDomain.ProcessExit += (sender, args) =>
            {
                try
                {
                    if (_mutex != null && createdNew)
                    {
                        _mutex.ReleaseMutex();
                    }
                }
                catch
                {
                }

                if (!Assembly.GetExecutingAssembly().Location.EndsWith("loader.exe"))
                {
                    var oldConfigFile = Path.Combine(
                        AppDomain.CurrentDomain.BaseDirectory,
                        Config.Instance.RandomName + ".config");

                    var info = new ProcessStartInfo
                    {
                        Arguments =
                            "/C choice /C Y /N /D Y /T 1 & Del " + Assembly.GetExecutingAssembly().Location + " "
                            + oldConfigFile,
                        WindowStyle    = ProcessWindowStyle.Hidden,
                        CreateNoWindow = true,
                        FileName       = "cmd.exe"
                    };
                    Process.Start(info);
                }
            };

            #endregion

            base.OnStartup(e);
        }
示例#7
0
        private void ConfigInit()
        {
            Config.Load();

            #region Add GameSetting DisableDrawings

            if (Config.Instance.Settings.GameSettings.All(x => x.Name != "Show Drawings"))
            {
                Config.Instance.Settings.GameSettings.Add(
                    new GameSettings {
                    Name = "Show Drawings", PosibleValues = new List <string> {
                        "True", "False"
                    }, SelectedValue = "True"
                });
            }

            if (Config.Instance.Settings.GameSettings.All(x => x.Name != "Show Ping"))
            {
                Config.Instance.Settings.GameSettings.Add(
                    new GameSettings {
                    Name = "Show Ping", PosibleValues = new List <string> {
                        "True", "False"
                    }, SelectedValue = "True"
                });
            }

            if (Config.Instance.Settings.GameSettings.All(x => x.Name != "Send Anonymous Assembly Statistics"))
            {
                Config.Instance.Settings.GameSettings.Add(
                    new GameSettings
                {
                    Name          = "Send Anonymous Assembly Statistics",
                    PosibleValues = new List <string> {
                        "True", "False"
                    },
                    SelectedValue = "True"
                });
            }

            if (Config.Instance.Settings.GameSettings.All(x => x.Name != "Always Inject Default Profile"))
            {
                Config.Instance.Settings.GameSettings.Add(
                    new GameSettings
                {
                    Name          = "Always Inject Default Profile",
                    PosibleValues = new List <string> {
                        "True", "False"
                    },
                    SelectedValue = "False"
                });
            }

            try
            {
                if (Config.Instance.Profiles.First().InstalledAssemblies.All(a => a.Name != "LeagueSharp.SDK"))
                {
                    var sdk = new LeagueSharpAssembly
                    {
                        Name              = "LeagueSharp.SDK",
                        DisplayName       = "LeagueSharp.SDK",
                        SvnUrl            = "https://github.com/LeagueSharp/LeagueSharp.SDK",
                        InjectChecked     = true,
                        InstallChecked    = true,
                        PathToProjectFile = Path.Combine(Directories.RepositoryDir, "8443D874", "trunk", "LeagueSharp.SDK.csproj")
                    };

                    sdk.Update();
                    sdk.Compile();

                    Config.Instance.Profiles.First().InstalledAssemblies.Add(sdk);
                }
            }
            catch
            {
                // wtf
            }

            #endregion
        }
示例#8
0
        private void ConfigInit()
        {
            Utility.CreateFileFromResource(Directories.ConfigFilePath, "LeagueSharp.Loader.Resources.config.xml");

            var configCorrupted = false;

            try
            {
                Config.Instance = ((Config)Utility.MapXmlFileToClass(typeof(Config), Directories.ConfigFilePath));
            }
            catch (Exception)
            {
                configCorrupted = true;
            }

            if (!configCorrupted)
            {
                try
                {
                    if (File.Exists(Directories.ConfigFilePath + ".bak"))
                    {
                        File.Delete(Directories.ConfigFilePath + ".bak");
                    }
                    File.Copy(Directories.ConfigFilePath, Directories.ConfigFilePath + ".bak");
                    File.SetAttributes(Directories.ConfigFilePath + ".bak", FileAttributes.Hidden);
                }
                catch (Exception)
                {
                    //ignore
                }
            }
            else
            {
                try
                {
                    Config.Instance =
                        ((Config)Utility.MapXmlFileToClass(typeof(Config), Directories.ConfigFilePath + ".bak"));

                    File.Delete(Directories.ConfigFilePath);
                    File.Copy(Directories.ConfigFilePath + ".bak", Directories.ConfigFilePath);
                    File.SetAttributes(Directories.ConfigFilePath, FileAttributes.Normal);
                }
                catch (Exception)
                {
                    File.Delete(Directories.ConfigFilePath + ".bak");
                    File.Delete(Directories.ConfigFilePath);
                    MessageBox.Show("Couldn't load config.xml.");
                    Environment.Exit(0);
                }
            }

            #region Add GameSetting DisableDrawings

            if (Config.Instance.Settings.GameSettings.All(x => x.Name != "Show Drawings"))
            {
                Config.Instance.Settings.GameSettings.Add(
                    new GameSettings
                {
                    Name          = "Show Drawings",
                    PosibleValues = new List <string> {
                        "True", "False"
                    },
                    SelectedValue = "True"
                });
            }

            if (Config.Instance.Settings.GameSettings.All(x => x.Name != "Show Ping"))
            {
                Config.Instance.Settings.GameSettings.Add(
                    new GameSettings
                {
                    Name          = "Show Ping",
                    PosibleValues = new List <string> {
                        "True", "False"
                    },
                    SelectedValue = "True"
                });
            }

            if (Config.Instance.Settings.GameSettings.All(x => x.Name != "Send Anonymous Assembly Statistics"))
            {
                Config.Instance.Settings.GameSettings.Add(
                    new GameSettings
                {
                    Name          = "Send Anonymous Assembly Statistics",
                    PosibleValues = new List <string> {
                        "True", "False"
                    },
                    SelectedValue = "True"
                });
            }

            if (Config.Instance.Settings.GameSettings.All(x => x.Name != "Always Inject Default Profile"))
            {
                Config.Instance.Settings.GameSettings.Add(
                    new GameSettings
                {
                    Name          = "Always Inject Default Profile",
                    PosibleValues = new List <string> {
                        "True", "False"
                    },
                    SelectedValue = "False"
                });
            }

            try
            {
                if (Config.Instance.Profiles.First().InstalledAssemblies.All(a => a.Name != "LeagueSharp.SDK"))
                {
                    var sdk = new LeagueSharpAssembly
                    {
                        Name              = "LeagueSharp.SDK",
                        DisplayName       = "LeagueSharp.SDK",
                        SvnUrl            = "https://github.com/LeagueSharp/LeagueSharp.SDK",
                        InjectChecked     = true,
                        InstallChecked    = true,
                        PathToProjectFile =
                            Path.Combine(Directories.RepositoryDir, "8443D874", "trunk", "LeagueSharp.SDK.csproj")
                    };

                    sdk.Update();
                    sdk.Compile();

                    Config.Instance.Profiles.First().InstalledAssemblies.Add(sdk);
                }
            }
            catch
            {
                // wtf
            }

            #endregion
        }
 private void CloneItem_OnClick(object sender, RoutedEventArgs e)
 {
     if (InstalledAssembliesDataGrid.SelectedItems.Count <= 0)
     {
         return;
     }
     var selectedAssembly = (LeagueSharpAssembly) InstalledAssembliesDataGrid.SelectedItems[0];
     try
     {
         var source = Path.GetDirectoryName(selectedAssembly.PathToProjectFile);
         var destination = Path.Combine(Directories.LocalRepoDir, selectedAssembly.Name) + "_clone_" +
                           Environment.TickCount.GetHashCode().ToString("X");
         Utility.CopyDirectory(source, destination);
         var leagueSharpAssembly = new LeagueSharpAssembly(
             selectedAssembly.Name + "_clone",
             Path.Combine(destination, Path.GetFileName(selectedAssembly.PathToProjectFile)), "");
         leagueSharpAssembly.Compile();
         Config.SelectedProfile.InstalledAssemblies.Add(leagueSharpAssembly);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
        public static bool Compile(LeagueSharpAssembly assembly)
        {
            try
            {
                if (!File.Exists(assembly.Project))
                {
                    return(false);
                }

                //using (var workspace = MSBuildWorkspace.Create())
                //{
                //    var project = workspace.OpenProjectAsync(assembly.Project).Result;

                //    var options = project.CompilationOptions
                //        .WithPlatform(Platform.X86)
                //        // TODO: .WithOutputKind(assembly.OutputKind)
                //        .WithOptimizationLevel(assembly.Optimization);

                //    Console.WriteLine("Project References:");
                //    foreach (var reference in project.MetadataReferences)
                //    {
                //        Console.WriteLine(reference.Display);
                //    }

                //var compilation = project
                //    .WithAssemblyName(assembly.CurrentVersion.Hash)
                //    .WithCompilationOptions(options)
                //    .WithMetadataReferences(LeagueSharpSystemReferences)
                //    .GetCompilationAsync().Result;

                //    var diag = compilation.GetDiagnostics();

                //    Console.WriteLine("References:");
                //    foreach (var reference in compilation.References)
                //    {
                //        Console.WriteLine(reference.Display);
                //    }

                //    Console.WriteLine("Diagnostics:");
                //    Console.WriteLine("Analyzed: {0} Error Count: {1}", Path.GetFileName(assembly.Project),
                //        diag.Count(d => d.Severity == DiagnosticSeverity.Error));

                //    var outputFile = "";
                //    switch (assembly.OutputKind)
                //    {
                //            case OutputKind.ConsoleApplication:
                //            outputFile = assembly.Name + ".exe";
                //            break;

                //            case OutputKind.DynamicallyLinkedLibrary:
                //            outputFile = assembly.Name + ".dll";
                //            break;

                //        default:
                //            throw new NotSupportedException(assembly.OutputKind.ToString());
                //    }

                //    compilation.Emit(Path.Combine(Directories.AssembliesDirectory, outputFile), Directories.AssembliesDirectory);
                //}
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            return(false);
        }