/// <summary> /// Allow user to select a new banner image. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SelectNewGameBanner(object sender, EventArgs e) { // Dialog for launching executables. CommonOpenFileDialog imageDialog = new CommonOpenFileDialog(); imageDialog.Title = "Select the new banner image for the game."; imageDialog.Multiselect = false; // Open dialog. if (imageDialog.ShowDialog() == CommonFileDialogResult.Ok) { // Get current selected game. GameComboBoxDetails comboBoxDetails = GetSelectedGame(); // Find current config by details. GameConfigParser.GameConfig gameConfig = Global.GameConfigurations.First ( x => x.GameName == comboBoxDetails.GameName && x.ExecutableLocation == comboBoxDetails.ExecutableRelativeLocation && x.GameVersion == comboBoxDetails.GameVersion ); // Copy the banner to new location. File.Copy(imageDialog.FileName, GameConfigParser.GameConfig.GetBannerPath(gameConfig), true); // Set new image. box_GameBanner.BackgroundImage = Image.FromFile(GameConfigParser.GameConfig.GetBannerPath(gameConfig)); } // Dispose dialog. imageDialog.Dispose(); }
/// <summary> /// Parses the arguments passed into the application. /// </summary> /// <param name="arguments"></param> private static void ParseArguments(string[] arguments) { // Go over known arguments. for (int x = 0; x < arguments.Length; x++) { if (arguments[x] == $"{Strings.Common.LoaderSettingConfig}") { _gameConfig = CheckConfigJson(arguments[x + 1]); } if (arguments[x] == $"{Strings.Common.LoaderSettingAttach}") { _attachTargetName = arguments[x + 1]; } if (arguments[x] == $"{Strings.Common.LoaderSettingLog}") { Logger.Setup(arguments[x + 1]); } } // Check game config if (_gameConfig == null) { Banner.DisplayWarning(); } }
/// <summary> /// Retrieves the list of games from their configurations. /// </summary> private void LoadGames() { // Save current game config GameConfigParser.GameConfig currentConfig = Global.CurrentGameConfig; // Clear the current listview. box_GameList.Rows.Clear(); // Retrieve current game list the into Global. Global.GameConfigurations = Global.ConfigurationManager.GetAllGameConfigs(); // For each config, append it. foreach (GameConfigParser.GameConfig gameConfig in Global.GameConfigurations) { // Stores the path of the mod for display. string modPath = LoaderPaths.GetModLoaderModDirectory() + "\\" + gameConfig.ModDirectory; // Retrieves the relative path for presentation. string relativeModPath = LoaderPaths.GetModLoaderRelativePath(modPath); // Add the relative path. box_GameList.Rows.Add(gameConfig.GameName, relativeModPath); } // Re-select the currently selected game. ReselectCurrentGame(currentConfig); }
/// <summary> /// Re-selects the currently selected game upon entering the Main Menu. /// </summary> /// <param name="gameConfiguration">The game configuration to try and re-select.</param> private void ReselectCurrentGame(GameConfigParser.GameConfig gameConfiguration) { // Find and select the last highlighted game. string currentGameName = gameConfiguration?.GameName; string currentRelativeModDirectory = LoaderPaths.GetModLoaderRelativePath(LoaderPaths.GetModLoaderModDirectory() + "\\" + gameConfiguration?.ModDirectory); foreach (DataGridViewRow row in box_GameList.Rows) { // Cells[0] = Game Name // Cells[1] = Mod Location if ((string)row.Cells[0].Value == currentGameName && (string)row.Cells[1].Value == currentRelativeModDirectory) { row.Selected = true; } } }
/// <summary> /// Retrieves all of the game individual mod configurations for the currently selected game. /// </summary> public List <ModConfigParser.ModConfig> GetAllMods(GameConfigParser.GameConfig gameConfiguration) { // Retrieves the name of all directories in the 'Mods' folder for the game. string[] modDirectories = Directory.GetDirectories(LoaderPaths.GetModLoaderModDirectory() + "\\" + gameConfiguration.ModDirectory); // Retrieve the game configurations List <ModConfigParser.ModConfig> modConfigurations = new List <ModConfigParser.ModConfig>(modDirectories.Length); // Read each game configuration foreach (string directory in modDirectories) { try { modConfigurations.Add(ModConfigParser.ParseConfig(directory)); } catch (Exception ex) { MessageBox.Show("One of your mod configurations is missing or corrupt: " + ex.Message); } } // Return. return(modConfigurations); }
/// <summary> /// Creates the new game configuration for the combobox /// dropdown and selects it. /// </summary> /// <param name="configDirectory">The absolute directory where the game configuration will be stored. (Subdirectory of Reloaded-Config/Games</param> private void CreateNewGameConfig(string configDirectory) { // Get current index. int nextGameIndex = borderless_CurrentGame.Items.Count; // Add a new game onto the configurations. Global.GameConfigurations.Add ( new GameConfigParser.GameConfig { GameName = "New Game " + nextGameIndex, GameDirectory = "", GameVersion = "", EnabledMods = new List <string>(), ModDirectory = "", ConfigLocation = configDirectory, ExecutableLocation = "" } ); // Get latest gameconfig GameConfigParser.GameConfig gameConfig = Global.GameConfigurations.Last(); // Write latest gameconfig GameConfigParser.WriteConfig(gameConfig); // Add a new configuration. borderless_CurrentGame.Items.Add ( gameConfig.GameName + " " + Theme.ThemeProperties.TitleProperties.LoaderTitleDelimiter + " " + gameConfig.ExecutableLocation + " " + Theme.ThemeProperties.TitleProperties.LoaderTitleDelimiter + " " + gameConfig.GameVersion ); // Select last item. borderless_CurrentGame.SelectedIndex = nextGameIndex; }
/// <summary> /// Loads the details of the currently loaded game. /// </summary> private void SelectedGameChanged(object sender, EventArgs e) { // Get current selected game. GameComboBoxDetails comboBoxDetails = GetSelectedGame(); // Find by details. GameConfigParser.GameConfig gameConfig = Global.GameConfigurations.First ( x => x.GameName == comboBoxDetails.GameName && x.ExecutableLocation == comboBoxDetails.ExecutableRelativeLocation && x.GameVersion == comboBoxDetails.GameVersion ); // Populate fields. borderless_GameName.Text = gameConfig.GameName; borderless_GameModDirectory.Text = gameConfig.ModDirectory; borderless_GameVersion.Text = gameConfig.GameVersion; borderless_GameExecutableDirectory.Text = gameConfig.ExecutableLocation; borderless_GameDirectory.Text = gameConfig.GameDirectory; // Load the game image. try { box_GameBanner.BackgroundImage = Image.FromFile(GameConfigParser.GameConfig.GetBannerPath(gameConfig)); } catch { box_GameBanner.BackgroundImage = null; } }
/// <summary> /// Finds the mods that are currently enabled for the game and injects into the target process. /// </summary> /// <param name="gameConfiguration">The game configuration which contains the current directory and list of mods to load.</param> /// <param name="reloadedProcess">The reloaded process to inject the modifications into.</param> public static void LoadMods(GameConfigParser.GameConfig gameConfiguration, ReloadedProcess reloadedProcess) { // Get directory containing the global mod list. GameConfigParser.GameConfig globalModConfig = GameConfigParser.ParseConfig(LoaderPaths.GetGlobalGameConfigDirectory()); // Get directory containing the game's mod list string gameModDirectory = Path.Combine(LoaderPaths.GetModLoaderModDirectory(), gameConfiguration.ModDirectory); string globalModDirectory = LoaderPaths.GetGlobalModDirectory(); // Get directories containing enabled mods. List <string> modLibraries = new List <string>(gameConfiguration.EnabledMods.Count); // Get the game mod dll locations. foreach (string modDirectory in gameConfiguration.EnabledMods) { // Add native or not native. if (ReloadedArchitecture.IsGame32Bit) { modLibraries.Add(Path.Combine(gameModDirectory, modDirectory, Strings.Loader.Mod32BitDllFile)); } else { modLibraries.Add(Path.Combine(gameModDirectory, modDirectory, Strings.Loader.Mod64BitDllFile)); } } // Get the global mod dll locations. foreach (string modDirectory in globalModConfig.EnabledMods) { // Add native or not native. if (ReloadedArchitecture.IsGame32Bit) { modLibraries.Add(Path.Combine(globalModDirectory, modDirectory, Strings.Loader.Mod32BitDllFile)); } else { modLibraries.Add(Path.Combine(globalModDirectory, modDirectory, Strings.Loader.Mod64BitDllFile)); } } // Initialize DLL Injector DllInjector reloadedDllInjector = new DllInjector(reloadedProcess); // If the main.dll exists, load it. foreach (string modLibrary in modLibraries) { // If the DLL Exists, Try to Load It if (File.Exists(modLibrary)) { // Allocate Memory for Server Port In Game Memory IntPtr parameterAddress = reloadedProcess.AllocateMemory(IntPtr.Size); // Write Server Port to Game Memory reloadedProcess.WriteMemoryExternal(parameterAddress, BitConverter.GetBytes(LoaderServer.ServerPort)); // Inject the individual DLL. reloadedDllInjector.InjectDll(modLibrary, parameterAddress); } } // Resume game after injection. reloadedProcess.ResumeAllThreads(); }