Пример #1
0
        private static void InjectDLLDefault(ReloadedProcess reloadedProcess, DllInjector dllInjector, string dllPath, string dllMethodName)
        {
            // Allocate Memory for Server Port In Game Memory
            IntPtr parameterAddress = reloadedProcess.AllocateMemory(IntPtr.Size);

            // Write Server Port to Game Memory
            byte[] serverPort = BitConverter.GetBytes(LoaderServer.ServerPort);
            reloadedProcess.WriteMemoryExternal(parameterAddress, ref serverPort);

            // Inject the individual DLL.
            dllInjector.InjectDll(dllPath, parameterAddress, dllMethodName);
        }
Пример #2
0
        /// <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();
        }