private void SetupDisablerButtonText()
            {
                if (SelectedTarget != null)
                {
                    var d3d9Path = Path.Combine(M3Directories.GetExecutableDirectory(SelectedTarget), @"d3d9.dll");
                    if (File.Exists(d3d9Path))
                    {
                        // See if it ME3Tweaks disabler or some other tool
                        var fi = new FileInspector(d3d9Path);
                        foreach (var sig in fi.GetSignatures())
                        {
                            foreach (var signChain in sig.AdditionalCertificates)
                            {
                                try
                                {
                                    var outStr = signChain.Subject.Substring(3); //remove CN=
                                    outStr = outStr.Substring(0, outStr.IndexOf(','));
                                    if (outStr == @"Michael Perez")              //My signing cert name
                                    {
                                        D3D9Status            = M3L.GetString(M3L.string_overlayDisablerInstalled);
                                        DisablerButtonText    = M3L.GetString(M3L.string_uninstallDisabler);
                                        DisablerButtonEnabled = true;
                                        return;
                                    }
                                }
                                catch
                                {
                                }
                            }
                        }

                        D3D9Status            = M3L.GetString(M3L.string_otherD3d9dllInstalledOverlayDisabled);
                        DisablerButtonText    = M3L.GetString(M3L.string_cannotUninstallOtherD3d9File);
                        DisablerButtonEnabled = false;
                        return;
                    }

                    DisablerButtonEnabled = true;
                    D3D9Status            = M3L.GetString(M3L.string_overlayDisablerNotInstalled);
                    DisablerButtonText    = M3L.GetString(M3L.string_installDisabler);
                }
                else
                {
                    DisablerButtonEnabled = false;
                    DisablerButtonText    = M3L.GetString(M3L.string_installDisabler);

                    if (Targets.Any())
                    {
                        D3D9Status = M3L.GetString(M3L.string_noTargetSelected);
                    }
                    else
                    {
                        D3D9Status = M3L.GetString(M3L.string_noOriginBasedGameTargets);
                    }
                }
            }
Beispiel #2
0
        /// <summary>
        /// Launches the game. This call is blocking as it may wait for Steam to run, so it should be run on a background thread.
        /// </summary>
        /// <param name="target"></param>
        public static void LaunchGame(GameTarget target)
        {
            // Update LODs for target
            if (Settings.AutoUpdateLODs4K || Settings.AutoUpdateLODs2K)
            {
                target.UpdateLODs(Settings.AutoUpdateLODs2K);
            }

            var exe             = M3Directories.GetExecutablePath(target);
            var exeDir          = M3Directories.GetExecutableDirectory(target);
            var environmentVars = new Dictionary <string, string>();

            if (target.GameSource != null)
            {
                // IS GAME STEAM BASED?
                if (target.GameSource.Contains(@"Steam"))
                {
                    var steamInstallPath =
                        Utilities.GetRegistrySettingString(@"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Valve\Steam",
                                                           @"InstallPath");
                    if (steamInstallPath != null && Directory.Exists(steamInstallPath))
                    {
                        environmentVars[@"SteamPath"] = steamInstallPath;

                        // Ensure steam is running and ready
                        var steamExe = Path.Combine(steamInstallPath, @"steam.exe");
                        EnsureSteamRunning(steamExe); // Can block up for some time!
                    }

                    int gameId = 0;
                    switch (target.Game)
                    {
                    case MEGame.ME1:
                        gameId = 17460;
                        break;

                    case MEGame.ME2:
                        gameId = 24980;
                        break;

                    case MEGame.ME3:
                        gameId = 1238020;
                        break;
                    }

                    environmentVars[@"SteamAppId"]         = gameId.ToString();
                    environmentVars[@"SteamGameId"]        = gameId.ToString();
                    environmentVars[@"SteamOverlayGameId"] = gameId.ToString();

                    // Make steam_appid.txt next to exe. It can help launch game if steam.exe is already running
                    var steamappidfile = Path.Combine(exeDir, @"steam_appid.txt");
                    if (!File.Exists(steamappidfile))
                    {
                        try
                        {
                            File.WriteAllText(steamappidfile, gameId.ToString());
                        }
                        catch (Exception e)
                        {
                            Log.Error($@"Could not install steam_appid.txt: {e.Message}");
                        }
                    }
                }
                else if (target.GameSource.Contains(@"Origin") && target.RegistryActive && target.Game < MEGame.ME3 && Settings.LaunchGamesThroughOrigin) // Must be registry active or origin will run the wrong game.
                {
                    // ME2 seems to have lots of problems directly running due to it's licensing system
                    // We should try to run it through Origin to avoid this problem

                    var parFile = Path.Combine(exeDir, Path.GetFileNameWithoutExtension(exe) + @".par");
                    if (target.Game == MEGame.ME2 && File.Exists(parFile))
                    {
                        var fInfo = new FileInfo(exe);
                        if (fInfo.Length < 5 * FileSize.MebiByte)
                        {
                            // Does this executable need swapped? MassEffect2.exe does not seem to reliably run through Origin and just exits early for some reason
                        }
                        var parContents = PARTools.DecodePAR(File.ReadAllBytes(parFile));
                        var contentIds  = parContents[@"Base"].GetValue(@"ContentId")?.Value;

                        if (!string.IsNullOrWhiteSpace(contentIds))
                        {
                            exe = $@"origin://launchgame/{contentIds}";
                        }
                    }
                }
            }

            Utilities.RunProcess(exe, (string)null, false, true, false, false, environmentVars);
            Thread.Sleep(3500); // Keep task alive for a bit
        }
Beispiel #3
0
        public void TestM3DirectoryResults()
        {
            GlobalTest.Init();
            List <GameTarget> targets = new List <GameTarget>();
            var root = GlobalTest.GetTestGameFoldersDirectory(MEGame.ME1);

            foreach (var d in Directory.GetDirectories(root))
            {
                GameTarget gt = new GameTarget(MEGame.ME1, d, false, false);
                gt.ValidateTarget();
                if (gt.IsValid)
                {
                    targets.Add(gt);
                }
            }
            root = GlobalTest.GetTestGameFoldersDirectory(MEGame.ME2);
            foreach (var d in Directory.GetDirectories(root))
            {
                GameTarget gt = new GameTarget(MEGame.ME2, d, false, false);
                gt.ValidateTarget();
                if (gt.IsValid)
                {
                    targets.Add(gt);
                }
            }
            root = GlobalTest.GetTestGameFoldersDirectory(MEGame.ME3);
            foreach (var d in Directory.GetDirectories(root))
            {
                GameTarget gt = new GameTarget(MEGame.ME3, d, false, false);
                gt.ValidateTarget();
                if (gt.IsValid)
                {
                    targets.Add(gt);
                }
            }

            foreach (var target in targets)
            {
                string expectedDLCPath;
                string expectedASIPath;
                string expectedBioGamePath;
                string expectedCookedPath;
                string expectedExecutableDir;
                if (target.Game == MEGame.ME1)
                {
                    expectedDLCPath       = Path.Combine(target.TargetPath, @"DLC");
                    expectedASIPath       = Path.Combine(target.TargetPath, @"Binaries", @"asi");
                    expectedBioGamePath   = Path.Combine(target.TargetPath, @"BioGame");
                    expectedCookedPath    = Path.Combine(target.TargetPath, @"BioGame", @"CookedPC");
                    expectedExecutableDir = Path.Combine(target.TargetPath, @"Binaries");
                }
                else if (target.Game == MEGame.ME2)
                {
                    expectedDLCPath       = Path.Combine(target.TargetPath, @"BioGame", @"DLC");
                    expectedASIPath       = Path.Combine(target.TargetPath, @"Binaries", @"asi");
                    expectedBioGamePath   = Path.Combine(target.TargetPath, @"BioGame");
                    expectedCookedPath    = Path.Combine(target.TargetPath, @"BioGame", @"CookedPC");
                    expectedExecutableDir = Path.Combine(target.TargetPath, @"Binaries");
                }
                else
                {
                    expectedDLCPath       = Path.Combine(target.TargetPath, @"BIOGame", @"DLC");
                    expectedASIPath       = Path.Combine(target.TargetPath, @"Binaries", @"Win32", @"asi");
                    expectedBioGamePath   = Path.Combine(target.TargetPath, @"BIOGame");
                    expectedCookedPath    = Path.Combine(target.TargetPath, @"BIOGame", @"CookedPCConsole");
                    expectedExecutableDir = Path.Combine(target.TargetPath, @"Binaries", @"Win32");
                }

                Assert.AreEqual(expectedDLCPath, M3Directories.GetDLCPath(target));
                Assert.AreEqual(expectedASIPath, M3Directories.GetASIPath(target));
                Assert.AreEqual(expectedBioGamePath, M3Directories.GetBioGamePath(target));
                Assert.AreEqual(expectedCookedPath, M3Directories.GetCookedPath(target));
                Assert.AreEqual(expectedExecutableDir, M3Directories.GetExecutableDirectory(target));
            }
        }
            private void ToggleDisabler()
            {
                NamedBackgroundWorker nbw = new NamedBackgroundWorker(@"OIGDisablerThread");

                nbw.DoWork += async(a, b) =>
                {
                    if (!Utilities.IsGameRunning(Game))
                    {
                        var d3d9Path = Path.Combine(M3Directories.GetExecutableDirectory(SelectedTarget), @"d3d9.dll");
                        if (!File.Exists(d3d9Path))
                        {
                            if (File.Exists(Utilities.GetOriginOverlayDisableFile()))
                            {
                                Log.Information(@"Installing origin overlay disabler from cache to " + d3d9Path);
                                try
                                {
                                    File.Copy(Utilities.GetOriginOverlayDisableFile(), d3d9Path);
                                }
                                catch (Exception e)
                                {
                                    Log.Error($@"Error installing d3d9.dll: {e.Message}");
                                }
                            }
                            else
                            {
                                var client = new GitHubClient(new ProductHeaderValue(@"ME3TweaksModManager"));
                                try
                                {
                                    var releases = await client.Repository.Release.GetAll(@"ME3Tweaks", @"d3d9-blank-proxy");

                                    if (releases.Count > 0)
                                    {
                                        Log.Information(@"Parsing release information from github");

                                        //The release we want to check is always the latest with assets that is not a pre-release
                                        var latestRel = releases.FirstOrDefault(x => !x.Prerelease && x.Assets.Count > 0);
                                        if (latestRel != null)
                                        {
                                            var downloadUrl        = latestRel.Assets[0].BrowserDownloadUrl;
                                            var downloadedZipAsset = OnlineContent.DownloadToMemory(downloadUrl);
                                            using var zf = new ZipArchive(downloadedZipAsset.result);
                                            var d3d9 = zf.Entries.First(x => x.FullName == @"d3d9.dll");
                                            if (d3d9 != null)
                                            {
                                                await using var data = d3d9.Open();
                                                var memStream = new MemoryStream();
                                                data.CopyTo(memStream);
                                                try
                                                {
                                                    Log.Information(@"Installing origin overlay disabler from memory to " + d3d9Path);
                                                    memStream.WriteToFile(d3d9Path); //install
                                                    Log.Information(@"Caching d3d9 disabler");
                                                    memStream.WriteToFile(Utilities.GetOriginOverlayDisableFile());
                                                }
                                                catch (Exception e)
                                                {
                                                    Log.Error(@"Cannot install/cache disabler: " + e.Message);
                                                }
                                            }
                                        }
                                    }
                                }
                                catch (Exception e)
                                {
                                    Log.Error(@"Error checking for tool update: " + e);
                                }
                            }
                        }
                        else
                        {
                            Log.Information(@"Deleting " + d3d9Path);
                            try
                            {
                                File.Delete(d3d9Path);
                            }
                            catch (Exception e)
                            {
                                Log.Error($@"Error deleting d3d9.dll: {e.Message}");
                            }
                        }
                    }
                };
                nbw.RunWorkerCompleted += (await, b) =>
                {
                    SetupDisablerButtonText();
                };
                nbw.RunWorkerAsync();
            }