Skip to content

Commit

Permalink
Add config option to disable the gui (for people who want neither the…
Browse files Browse the repository at this point in the history
… regular conhost and this)
  • Loading branch information
xiaoxiao921 committed Feb 24, 2022
1 parent 70a72a1 commit e43a640
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 6 deletions.
6 changes: 6 additions & 0 deletions BepInEx.GUI.Config/MainConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public static bool ShowOneTimeOnlyDisclaimerConfig
public const string CloseWindowWhenGameClosesConfigDescription = "Close the graphic user interface window when the game closes";
public static ConfigEntry<bool> CloseWindowWhenGameClosesConfig { get; private set; }

public const string EnableBepInExGUIConfigKey = "Enable BepInEx GUI";
public const string EnableBepInExGUIConfigDescription = "Enable the custom BepInEx GUI";
public static ConfigEntry<bool> EnableBepInExGUIConfig { get; private set; }

public static void Init(string configFilePath)
{
File = new ConfigFile(configFilePath, true);
Expand All @@ -72,6 +76,8 @@ public static void Init(string configFilePath)
CloseWindowWhenGameLoadedConfig = File.Bind("Settings", CloseWindowWhenGameLoadedConfigKey, false, CloseWindowWhenGameLoadedConfigDescription);

CloseWindowWhenGameClosesConfig = File.Bind("Settings", CloseWindowWhenGameClosesConfigKey, true, CloseWindowWhenGameClosesConfigDescription);

EnableBepInExGUIConfig = File.Bind("Settings", EnableBepInExGUIConfigKey, true, EnableBepInExGUIConfigDescription);
}
}

Expand Down
2 changes: 0 additions & 2 deletions BepInEx.GUI.Patcher/CloseGuiOnChainloaderDone.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using BepInEx.GUI.Config;
using BepInEx.Logging;
using System;
using System.IO;

namespace BepInEx.GUI.Patcher
{
Expand All @@ -23,7 +22,6 @@ public void LogEvent(object sender, LogEventArgs eventArgs)

if (eventArgs.Data.ToString() == "Chainloader startup complete" && eventArgs.Level.Equals(LogLevel.Message))
{
MainConfig.Init(Path.Combine(Paths.ConfigPath, MainConfig.FileName));
if (MainConfig.CloseWindowWhenGameLoadedConfig.Value)
{
Patcher.LogSource.LogMessage("Closing BepInEx.GUI");
Expand Down
14 changes: 11 additions & 3 deletions BepInEx.GUI.Patcher/Patcher.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BepInEx.Configuration;
using BepInEx.GUI.Config;
using BepInEx.Logging;
using Mono.Cecil;
using MonoMod.Utils;
Expand All @@ -24,16 +25,23 @@ public static void Initialize()
{
LogSource = Logger.CreateLogSource("BepInEx.GUI.Patcher");

MainConfig.Init(Path.Combine(Paths.ConfigPath, MainConfig.FileName));

var consoleConfig = (ConfigEntry<bool>)typeof(BepInPlugin).Assembly.GetType("BepInEx.ConsoleManager", true).GetField("ConfigConsoleEnabled", BindingFlags.Static | BindingFlags.Public).GetValue(null);
if (consoleConfig.Value)
{
LogSource.LogMessage("Console is enabled, not using BepInEx.GUI");
LogSource.Dispose();
}
else
else if (MainConfig.EnableBepInExGUIConfig.Value)
{
FindAndLaunchGui();
}
else
{
LogSource.LogMessage("BepInEx.GUI is disabled in the config, aborting launch.");
LogSource.Dispose();
}
}

private static void FindAndLaunchGui()
Expand Down Expand Up @@ -84,9 +92,9 @@ private static string FindGuiExecutable()
(isWindows && fileName == $"{GuiFileName}.exe" && filePathLower.Contains("86")) ||
(isWindows64 && fileName == $"{GuiFileName}.exe" && filePathLower.Contains("64")) ||

(isLinux64 && fileName == GuiFileName && filePathLower.Contains("linux64")) ||
(isLinux64 && fileName == GuiFileName && filePathLower.Contains("linux_x64")) ||

(isMacOs64 && fileName == GuiFileName && filePathLower.Contains("macos64"))
(isMacOs64 && fileName == GuiFileName && filePathLower.Contains("macos_x64"))
)
{
return filePath;
Expand Down
13 changes: 13 additions & 0 deletions BepInEx.GUI/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ public bool CloseWindowWhenGameCloses
}
}

private bool _enableBepInExGUI;
public bool EnableBepInExGUI
{
get { return _enableBepInExGUI; }
set
{
MainConfig.EnableBepInExGUIConfig.Value = this.RaiseAndSetIfChanged(ref _enableBepInExGUI, value);
MainConfig.File.Save();
}
}

public CancellationTokenSource CancellationTokenSource { get; private set; }

#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
Expand All @@ -64,6 +75,8 @@ private void SetConfigBindings()
CloseWindowWhenGameLoaded = MainConfig.CloseWindowWhenGameLoadedConfig.Value;

CloseWindowWhenGameCloses = MainConfig.CloseWindowWhenGameClosesConfig.Value;

EnableBepInExGUI = MainConfig.EnableBepInExGUIConfig.Value;
}

private void InitBackgroundTask()
Expand Down
21 changes: 20 additions & 1 deletion BepInEx.GUI/Views/SettingsView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>

<Grid Grid.Row="0">
Expand Down Expand Up @@ -43,7 +44,7 @@
Name="StackPanel2"
Orientation="Horizontal">
<Viewbox Height="{Binding Path=ActualHeight, ElementName=StackPanel2}">
<CheckBox Content="Close this window when game is loaded" IsChecked="{Binding SettingsViewModel.CloseWindowWhenGameLoaded, Mode=TwoWay}" />
<CheckBox Content="Close this window when the game is loaded" IsChecked="{Binding SettingsViewModel.CloseWindowWhenGameLoaded, Mode=TwoWay}" />
</Viewbox>
</StackPanel>

Expand All @@ -67,6 +68,24 @@

</Grid>

<Grid Grid.Row="3">

<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

<StackPanel
Grid.Column="0"
Height="80"
Name="StackPanel4"
Orientation="Horizontal">
<Viewbox Height="{Binding Path=ActualHeight, ElementName=StackPanel4}">
<CheckBox Content="Show this window when the game starts" IsChecked="{Binding SettingsViewModel.EnableBepInExGUI, Mode=TwoWay}" />
</Viewbox>
</StackPanel>

</Grid>

</Grid>

</UserControl>

0 comments on commit e43a640

Please sign in to comment.