/// <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> /// 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(); }