/// <summary> /// Writes all of the game individual mod configurations for the currently selected game. /// </summary> /// <param name="gameConfigurations">List of game configurations to be written back.</param> public void WriteAllMods(List <GameConfigParser.GameConfig> gameConfigurations) { // Read each game configuration foreach (GameConfigParser.GameConfig gameConfiguration in gameConfigurations) { GameConfigParser.WriteConfig(gameConfiguration); } }
/// <summary> /// Checks whether the supplied argument for the config path ends with Config.json and strips /// the argument if it does to obtain the game configuration from the parser. /// </summary> private static GameConfigParser.GameConfig CheckConfigJson(string argument) { // Accept the supplied config path if it ends on Config.json. if (argument.EndsWith(Strings.Parsers.ConfigFile)) { return(GameConfigParser.ParseConfig(Path.GetDirectoryName(argument))); } // Otherwise get the game config from the vanilla argument. return(GameConfigParser.ParseConfig(argument)); }
/// <summary> /// Retrieves all of the game individual game configurations, including the global /// game configuration containing global mods. /// </summary> public List <GameConfigParser.GameConfig> GetAllGameConfigs() { // Retrieves the name of all directories in the 'Games' folder. string[] directories = Directory.GetDirectories(LoaderPaths.GetModLoaderGamesDirectory()); // Retrieve the game configurations List <GameConfigParser.GameConfig> gameConfigurations = new List <GameConfigParser.GameConfig>(directories.Length); // Read each game configuration foreach (string directory in directories) { try { gameConfigurations.Add(GameConfigParser.ParseConfig(directory)); } catch (Exception ex) { MessageBox.Show("One of your game configurations is missing or corrupt: " + ex.Message); } } // Return. return(gameConfigurations); }
/// <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> /// Saves the mods from their listview onto the mod configuration for the game. /// </summary> private void SaveMods() { // Stores the currently enabled mods. List <string> enabledMods = new List <string>(); // Cycle each row of the DataGridView for (int x = 0; x < box_ModList.Rows.Count; x++) { // Assign DataGridView Row DataGridViewRow row = box_ModList.Rows[x]; // Check if the mod in the row is enabled. bool modEnabled = (string)row.Cells[0].Value == TextButtons.ButtonEnabled; // If the mod is enabled. if (modEnabled) { // Find the mod configuration from the set row and column. // Match by mod title and version. ModConfigParser.ModConfig modConfiguration = FindModConfiguration((string)row.Cells[1].Value, (string)row.Cells[4].Value); // Append the folder name only to the list of mods. // Reloaded-Mods/SA2/Testmod => Testmod enabledMods.Add(Path.GetFileName(Path.GetDirectoryName(modConfiguration.ModLocation))); } } // Reverse the mod order such that mods on top take priority. enabledMods.Reverse(); // Assign the currently enabled mods for the game. Global.CurrentGameConfig.EnabledMods = enabledMods; // Save the game configuration. GameConfigParser.WriteConfig(Global.CurrentGameConfig); }
/// <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(); }