/// <summary> /// Retrieves the properties of the special "global" configuration, a master above /// all configuration which is used to load mods for all games. /// </summary> /// <returns>The global configuration properties</returns> public static GameConfig GetGlobalConfigProperties() { // Creates the global mod directory if it does not exist. // This is just to ensure safe usage of the global config. LoaderPaths.GetGlobalModDirectory(); return(new GameConfig() { ExecutableLocation = "All Executables", ModDirectory = Strings.Common.GlobalModFolder, ConfigLocation = LoaderPaths.GetGlobalGameConfigDirectory() + $"\\{Strings.Parsers.ConfigFile}", GameDirectory = "Between Time and Space", GameName = Strings.Common.GlobalModName, GameVersion = "Reloaded" }); }
/// <summary> /// Copies the default Mod Loader configuration and theme files upon first launch. /// </summary> private void CopyDefaultFiles() { // Copy without replacement. // Source directory = App Directory string sourceDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\Files"; string targetDirectory = LoaderPaths.GetModLoaderDirectory(); // Copy without replacement. // Source directory = App Directory string sourceDirectoryDefaultMods = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\Default-Mods"; string targetDirectoryDefaultMods = LoaderPaths.GetGlobalModDirectory(); try { RelativePaths.CopyByRelativePath(sourceDirectory, targetDirectory, RelativePaths.FileCopyMethod.Copy, false); RelativePaths.CopyByRelativePath(sourceDirectoryDefaultMods, targetDirectoryDefaultMods, RelativePaths.FileCopyMethod.Copy, true); // Nuke remaining files. Directory.Delete(sourceDirectory, true); Directory.Delete(sourceDirectoryDefaultMods, true); } catch (Exception) { /* ¯\_(ツ)_/¯ */ } }
/// <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(); }
/// <summary> /// Copies the default Mod Loader configuration and theme files upon first launch. /// </summary> private void CopyDefaultFiles() { // Copy without replacement. // Source directory = App Directory string sourceDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + $"\\{Strings.Launcher.CopyOnLaunchFolders.DefaultConfigFolder}"; string targetDirectory = LoaderPaths.GetModLoaderDirectory(); // Copy without replacement. // Source directory = App Directory string sourceDirectoryDefaultPlugins = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + $"\\{Strings.Launcher.CopyOnLaunchFolders.DefaultPluginsFolder}"; string targetDirectoryDefaultPlugins = LoaderPaths.GetPluginsDirectory(); string sourceDirectoryDefaultMods = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + $"\\{Strings.Launcher.CopyOnLaunchFolders.DefaultModsFolder}"; string targetDirectoryDefaultMods = LoaderPaths.GetGlobalModDirectory(); string sourceDirectoryDefaultTemplates = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + $"\\{Strings.Launcher.CopyOnLaunchFolders.DefaultTemplatesFolder}"; string targetDirectoryDefaultTemplates = LoaderPaths.GetTemplatesDirectory(); // Files try { RelativePaths.CopyByRelativePath(sourceDirectory, targetDirectory, RelativePaths.FileCopyMethod.Copy, false, true); Directory.Delete(sourceDirectory, true); } catch (Exception) { /* ¯\_(ツ)_/¯ */ } // Mods try { RelativePaths.CopyByRelativePath(sourceDirectoryDefaultMods, targetDirectoryDefaultMods, RelativePaths.FileCopyMethod.Copy, true, true); // We want to avoid deleting symbols. #if DEBUG // Do nothing. #else // Delete default mods directory. Directory.Delete(sourceDirectoryDefaultMods, true); #endif } catch (Exception) { /* ¯\_(ツ)_/¯ */ } // Plugins try { RelativePaths.CopyByRelativePath(sourceDirectoryDefaultPlugins, targetDirectoryDefaultPlugins, RelativePaths.FileCopyMethod.Copy, true, true); #if DEBUG // Do nothing. #else // Delete default plugins directory. Directory.Delete(sourceDirectoryDefaultPlugins, true); #endif } catch (Exception) { /* ¯\_(ツ)_/¯ */ } // Templates try { RelativePaths.CopyByRelativePath(sourceDirectoryDefaultTemplates, targetDirectoryDefaultTemplates, RelativePaths.FileCopyMethod.Copy, true, true); #if DEBUG // Do nothing. #else // Delete default plugins directory. Directory.Delete(sourceDirectoryDefaultPlugins, true); #endif } catch (Exception) { /* ¯\_(ツ)_/¯ */ } }