示例#1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Multiselect = false;
            ofd.Filter      = "Unity Game exe| *.exe";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                // create a SupportedGame
                SupportedGame newGame = new SupportedGame();
                newGame.ExeName       = Path.GetFileName(ofd.FileName);
                newGame.Library       = Path.GetDirectoryName(Path.GetDirectoryName(ofd.FileName));
                newGame.GameDirectory = Path.GetFileName(Path.GetDirectoryName(ofd.FileName));
                newGame.GameName      = Path.GetFileNameWithoutExtension(ofd.FileName);
                newGame.ConfigName    = null;

                // if newly added game is in the supported game list
                foreach (SupportedGame game in supportedGameList)
                {
                    if (game.ExeName == newGame.ExeName)
                    {
                        newGame.ConfigName = game.ConfigName;
                        break;
                    }
                }

                // if we couldn't find it, we use default.zip
                if (newGame.ConfigName == null)
                {
                    newGame.ConfigName = "default.zip";
                }
                lstBox.Items.Add(newGame, true);
                supportedGameList.Add(newGame);
                SaveGameList();
            }
        }
示例#2
0
        private void btnPatch_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < lstBox.Items.Count; i++)
            {
                foreach (string filename in files)
                {
                    if (!File.Exists(filename))
                    {
                        MessageBox.Show("Install files are missing! Please download ViewR Mod Installer again.");
                        return;
                    }
                }

                if (lstBox.GetItemChecked(i))
                {
                    // do game patching here
                    SupportedGame sg = lstBox.Items[i] as SupportedGame;
                    if (sg != null)
                    {
                        string directory = $"{sg.Library}\\{sg.GameDirectory}";
                        //MessageBox.Show($"patching in {directory}");

                        int result = -1;
                        try
                        {
                            if (!File.Exists($"{directory}\\IPA.exe") && !File.Exists($"{directory}\\Mono.Cecil.dll") && !Directory.Exists($"{directory}\\IPA"))
                            {
                                //only if the entire ipa is missing, do we try using our own
                                ZipFile.ExtractToDirectory(@"assets\IPA.zip", directory);
                            }

                            Process IPA = Process.Start($"{directory}\\IPA.exe", $"\"{directory}\\{sg.ExeName}\"");
                            IPA.WaitForExit();
                            result = IPA.ExitCode;
                            if (result != 0)
                            {
                                MessageBox.Show($"IPA failed to patch {sg.GameName}");
                                continue;
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show($"Something went wrong while installing IPA{Environment.NewLine}{ex.ToString()}");
                            continue;
                        }
                        if (!Directory.Exists($"{directory}\\Plugins"))
                        {
                            // we failed to install ipa even tho ipa says it installed
                            MessageBox.Show($"IPA failed to patch {sg.GameName}");
                            continue;
                        }

                        //copy plugin
                        try
                        {
                            // make missing folders if they're missing!
                            string appName = Path.GetFileNameWithoutExtension(sg.ExeName);
                            if (!Directory.Exists($"{directory}\\{appName}_Data\\Plugins\\"))
                            {
                                Directory.CreateDirectory($"{directory}\\{appName}_Data\\Plugins\\");
                            }
                            if (!Directory.Exists($"{directory}\\{appName}_Data\\StreamingAssets\\"))
                            {
                                Directory.CreateDirectory($"{directory}\\{appName}_Data\\StreamingAssets\\");
                            }

                            // copy files
                            File.Copy(@"assets\gfxplugin-viewr.dll", $"{directory}\\{appName}_Data\\Plugins\\gfxplugin-viewr.dll", true);
                            File.Copy(@"assets\viewr.asset", $"{directory}\\{appName}_Data\\StreamingAssets\\viewr.asset", true);
                            File.Copy(@"assets\ViewRMod.dll", $"{directory}\\Plugins\\ViewRMod.dll", true);
                        }
                        catch
                        {
                            MessageBox.Show($"Could not copy files, please ensure that the game is not running or download installer again.");
                        }

                        if ((!File.Exists($"{directory}\\viewrcamera.cfg") &&  // there's no cameracfg
                             !File.Exists($"{directory}\\viewrplugin.cfg")) || // and there's no plugincfg
                            checkBox1.Checked)
                        {
                            string cfg = "default.zip";
                            if (sg.ConfigName != null && sg.ConfigName != "")
                            {
                                cfg = sg.ConfigName;
                            }

                            if (File.Exists($"assets\\configs\\{cfg}"))
                            {
                                if (File.Exists($"{directory}\\viewrcamera.cfg"))
                                {
                                    File.Delete($"{directory}\\viewrcamera.cfg");
                                }
                                if (File.Exists($"{directory}\\viewrplugin.cfg"))
                                {
                                    File.Delete($"{directory}\\viewrplugin.cfg");
                                }
                                ZipFile.ExtractToDirectory($"assets\\configs\\{cfg}", directory);
                            }
                        }
                    }
                }
            }
            MessageBox.Show("Finished running installer.");
        }