private IEnumerator replaceStockContractApp() { while (!ApplicationLauncher.Ready || ContractsApp.Instance == null || ContractsApp.Instance.appLauncherButton == null) { yield return(null); } if (toolbarButton == null) { DMC_MBE.LogFormatted("Contracts Window + App Launcher Button Not Initialized; Starting It Now"); toolbarButton = ApplicationLauncher.Instance.AddModApplication(open, close, null, null, null, null, (ApplicationLauncher.AppScenes) 63, contractLoader.ToolbarIcon); } stockAppButton = ContractsApp.Instance.appLauncherButton; if (stockAppButton != null) { stockAppButton.onDisable(); stockAppButton.onTrue = toolbarButton.onTrue; stockAppButton.onFalse = toolbarButton.onFalse; stockAppButton.onHover = toolbarButton.onHover; stockAppButton.onHoverOut = toolbarButton.onHoverOut; stockAppButton.onEnable = toolbarButton.onEnable; stockAppButton.onDisable = toolbarButton.onDisable; ApplicationLauncher.Instance.DisableMutuallyExclusive(stockAppButton); DMC_MBE.LogFormatted("Stock Contracts App Replaced With Contracts Window +"); try { removeButton(HighLogic.LoadedScene); } catch (Exception e) { DMC_MBE.LogFormatted("Error In Removing Contracts Window + Toolbar App After Replacing Stock App: {0}", e); } } else { DMC_MBE.LogFormatted("Something went wrong while replacing the stock contract; attempting to add standard toolbar button"); if (toolbarButton != null) { GameEvents.onGUIApplicationLauncherUnreadifying.Add(removeButton); } else { StartCoroutine(addButton()); } } }