Beispiel #1
0
        public MainWindow()
        {
            String launcherVersion = "1.05";

            InitializeComponent();
            settings = Load();
            String versionString = "Version " + launcherVersion;

            LogTexBox.AppendText(versionString);
            logFile.WriteLine(versionString);
            GameVersion version = GetGameVersion();

            if (version == GameVersion.JABIA)
            {
                LogTexBox.AppendText(" (BIA)");
            }
            else if (version == GameVersion.JAC)
            {
                LogTexBox.AppendText(" (CF)");
            }
            else
            {
                String errorMissing = "\nMissing game launcher. Make sure mod launcher is installed in correct directory.";
                LogTexBox.AppendText(errorMissing);
                logFile.WriteLine(errorMissing);

                LaunchButton.IsEnabled = false;
            }
            foreach (Mod mod in settings.mods)
            {
                System.Diagnostics.Debug.WriteLine(mod.dllName);
                logFile.WriteLine(mod.dllName);
                AddModToView(mod);
            }
        }
Beispiel #2
0
        private void injectMods()
        {
            GameVersion version      = GetGameVersion();
            string      ProcName     = "";
            string      LauncherName = "";

            ModListBox.Dispatcher.Invoke((Action) delegate
            {
                ModListBox.IsEnabled = false;
            });

            String launcherName = "\nStarting: ";

            //IntPtr ThreadHandle = IntPtr.Zero;
            if (version == GameVersion.JABIA)
            {
                LaunchButton.Dispatcher.Invoke((Action) delegate
                {
                    LogTexBox.AppendText(launcherName + JABIA_LAUNCHER);
                    logFile.WriteLine(launcherName + JABIA_LAUNCHER);
                });
                System.Diagnostics.Process.Start(JABIA_LAUNCHER);

                /*
                 * STARTUPINFO si = new STARTUPINFO();
                 * PROCESS_INFORMATION pi = new PROCESS_INFORMATION();
                 * bool success = NativeMethods.CreateProcess(JABIA_PROCESS+".exe", null,
                 *  IntPtr.Zero, IntPtr.Zero, false,
                 *  ProcessCreationFlags.CREATE_SUSPENDED,
                 *  IntPtr.Zero, null, ref si, out pi);
                 * ThreadHandle = pi.hThread;
                 * NativeMethods.ResumeThread(ThreadHandle);
                 * Thread.Sleep(1000);
                 * NativeMethods.SuspendThread(ThreadHandle);
                 */
            }
            else
            {
                LaunchButton.Dispatcher.Invoke((Action) delegate
                {
                    LogTexBox.AppendText(launcherName + JAC_LAUNCHER);
                    logFile.WriteLine(launcherName + JAC_LAUNCHER);
                });
                System.Diagnostics.Process.Start(JAC_LAUNCHER);
            }

            String waitForProcess = "\nWaiting for proces to start: ";

            if (version == GameVersion.JABIA)
            {
                waitForProcess += JABIA_PROCESS;
                ProcName        = JABIA_PROCESS;
                LauncherName    = JABIA_LAUNCHER;
            }
            if (version == GameVersion.JAC)
            {
                waitForProcess += JAC_PROCESS;
                ProcName        = JAC_PROCESS;
                LauncherName    = JAC_LAUNCHER;
            }

            LaunchButton.Dispatcher.Invoke((Action) delegate
            {
                LogTexBox.AppendText(waitForProcess);
                logFile.WriteLine(waitForProcess);
            });

            LaunchButton.Dispatcher.Invoke((Action) delegate
            {
                LaunchButton.IsEnabled = false;
            });

            // wait for launcher to start
            Process[] _procs = Process.GetProcesses();
            for (int j = 0; j < _procs.Length; j++)
            {
                if (_procs[j].ProcessName == LauncherName)
                {
                    break;
                }
            }


            if (settings.mods.Count != 0)
            {
                bool procFound = false;
                for (int i = 0; i < 10; i++)
                {
                    _procs = Process.GetProcesses();
                    for (int j = 0; j < _procs.Length; j++)
                    {
                        if (_procs[j].ProcessName == ProcName)
                        {
                            procFound = true;
                            break;
                        }
                    }
                    System.Threading.Thread.Sleep(settings.delay);
                    if (procFound)
                    {
                        break;
                    }
                }
                if (!procFound)
                {
                    LaunchButton.Dispatcher.Invoke((Action) delegate
                    {
                        String errorProcessNotFound = "\nProcess not found. Exiting";
                        LogTexBox.AppendText(errorProcessNotFound);
                        logFile.WriteLine(launcherName + JABIA_LAUNCHER);
                    });
                    System.Threading.Thread.Sleep(settings.delay);
                    Environment.Exit(0);
                }

                DllInjector inj = DllInjector.GetInstance;
                foreach (Mod mod in settings.mods)
                {
                    if (mod.enabled)
                    {
                        LaunchButton.Dispatcher.Invoke((Action) delegate
                        {
                            String injectMod = "\nInjecting " + mod.modPath;
                            LogTexBox.AppendText(injectMod);
                            logFile.WriteLine(injectMod);
                        });
                        DllInjectionResult result = inj.Inject(ProcName, mod.modPath);
                    }
                }
            }
            logFile.Close();
            //NativeMethods.ResumeThread(ThreadHandle);
            System.Threading.Thread.Sleep(settings.delay);
            Environment.Exit(0);
        }