Skip to content

Commit

Permalink
Merge pull request #5 from risk-of-thunder/single-file-release
Browse files Browse the repository at this point in the history
Fix Unity Editor not working, config option for disabling gui, fix colors, extra filters
  • Loading branch information
xiaoxiao921 authored Feb 24, 2022
2 parents 773a862 + 0034e45 commit f8bb8d2
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 29 deletions.
19 changes: 11 additions & 8 deletions .github/workflows/github-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,46 @@ jobs:
- name: Dotnet Setup
uses: actions/setup-dotnet@v1

- name: Build Patcher
run: dotnet build .\BepInEx.GUI.Patcher\BepInEx.GUI.Patcher.csproj -c Release -o .\BepInEx_GUI_Patcher_${{github.ref_name}}

- name: Publish Windows x64
run: dotnet publish -c Release --sc -r win-x64 --output ./BepInEx_GUI_win_x64_${{github.ref_name}}
run: dotnet publish .\BepInEx.GUI\BepInEx.GUI.csproj -c Release -p:PublishSingleFile=true --sc -r win-x64 --output ./BepInEx_GUI_win_x64_${{github.ref_name}}

- name: Zip Windows x64 Release
uses: papeloto/action-zip@v1
with:
files: BepInEx_GUI_win_x64_${{github.ref_name}}/
files: BepInEx_GUI_win_x64_${{github.ref_name}}/ BepInEx_GUI_Patcher_${{github.ref_name}}/
recursive: false
dest: BepInEx_GUI_win_x64_${{github.ref_name}}.zip

- name: Publish Windows x86
run: dotnet publish -c Release --sc -r win-x86 --output ./BepInEx_GUI_win_x86_${{github.ref_name}}
run: dotnet publish .\BepInEx.GUI\BepInEx.GUI.csproj -c Release -p:PublishSingleFile=true --sc -r win-x86 --output ./BepInEx_GUI_win_x86_${{github.ref_name}}

- name: Zip Windows x86 Release
uses: papeloto/action-zip@v1
with:
files: BepInEx_GUI_win_x86_${{github.ref_name}}/
files: BepInEx_GUI_win_x86_${{github.ref_name}}/ BepInEx_GUI_Patcher_${{github.ref_name}}/
recursive: false
dest: BepInEx_GUI_win_x86_${{github.ref_name}}.zip

- name: Publish Linux x64
run: dotnet publish -c Release --sc -r linux-x64 --output ./BepInEx_GUI_linux_x64_${{github.ref_name}}
run: dotnet publish .\BepInEx.GUI\BepInEx.GUI.csproj -c Release -p:PublishSingleFile=true --sc -r linux-x64 --output ./BepInEx_GUI_linux_x64_${{github.ref_name}}

- name: Zip Linux x64 Release
uses: papeloto/action-zip@v1
with:
files: BepInEx_GUI_linux_x64_${{github.ref_name}}/
files: BepInEx_GUI_linux_x64_${{github.ref_name}}/ BepInEx_GUI_Patcher_${{github.ref_name}}/
recursive: false
dest: BepInEx_GUI_linux_x64_${{github.ref_name}}.zip

- name: Publish macOS x64
run: dotnet publish -c Release --sc -r osx-x64 --output ./BepInEx_GUI_macOS_x64_${{github.ref_name}}
run: dotnet publish .\BepInEx.GUI\BepInEx.GUI.csproj -c Release -p:PublishSingleFile=true --sc -r osx-x64 --output ./BepInEx_GUI_macOS_x64_${{github.ref_name}}

- name: Zip macOS x64 Release
uses: papeloto/action-zip@v1
with:
files: BepInEx_GUI_macOS_x64_${{github.ref_name}}/
files: BepInEx_GUI_macOS_x64_${{github.ref_name}}/ BepInEx_GUI_Patcher_${{github.ref_name}}/
recursive: false
dest: BepInEx_GUI_macOS_x64_${{github.ref_name}}.zip

Expand Down
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
49 changes: 39 additions & 10 deletions BepInEx.GUI/ViewModels/ConsoleViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ public class ConsoleViewModel : ViewModelBase
public class ColoredEntry
{
public string Text { get; set; }
public string Color { get; set; }
public string BackgroundColor { get; set; }
public string ForegroundColor { get; set; }

public ColoredEntry(string text, string color)
public ColoredEntry(string text, string backgroundColor, string foregroundColor)
{
Text = text;
Color = color;
BackgroundColor = backgroundColor;
ForegroundColor = foregroundColor;
}
}

Expand Down Expand Up @@ -54,6 +56,8 @@ public bool ConsoleAutoScroll
}
}

private bool _justChangedSelectedMod;

private string _textFilter = "";
public string TextFilter
{
Expand All @@ -62,6 +66,31 @@ public string TextFilter
{
this.RaiseAndSetIfChanged(ref _textFilter, value);
UpdateConsoleBox();

if (_justChangedSelectedMod)
{
_justChangedSelectedMod = false;
}
else
{
SelectedModFilter = null;
}
}
}

private Mod? _selectedModFilter;
public Mod? SelectedModFilter
{
get { return _selectedModFilter; }
set
{
this.RaiseAndSetIfChanged(ref _selectedModFilter, value);

if (value != null)
{
_justChangedSelectedMod = true;
TextFilter = _selectedModFilter!.Name;
}
}
}

Expand Down Expand Up @@ -132,24 +161,24 @@ private void UpdateConsoleBox()
{
var logEntryString = logEntry.ToString();

string color = logEntry.LevelCode switch
var (backgroundColor, foregroundColor) = logEntry.LevelCode switch
{
Logging.LogLevel.Fatal => "Red",
Logging.LogLevel.Error => "Red",
Logging.LogLevel.Warning => "YellowGreen",
_ => "Transparent",
Logging.LogLevel.Fatal => ("Transparent", "Red"),
Logging.LogLevel.Error => ("Transparent", "Red"),
Logging.LogLevel.Warning => ("Transparent", "Yellow"),
_ => ("Transparent", "White"),
};

if (TextFilter.Length > 0)
{
if (logEntryString.ToLowerInvariant().Contains(TextFilter.ToLowerInvariant()))
{
consoleText.Add(new ColoredEntry(logEntryString, color));
consoleText.Add(new ColoredEntry(logEntryString, backgroundColor, foregroundColor));
}
}
else
{
consoleText.Add(new ColoredEntry(logEntryString, color));
consoleText.Add(new ColoredEntry(logEntryString, backgroundColor, foregroundColor));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion BepInEx.GUI/ViewModels/GeneralViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class GeneralViewModel : ViewModelBase

public string TargetIsLoadingCanCloseWindow { get; }

private string _loadedModCountText;
private string _loadedModCountText = "";
public string LoadedModCountText
{
get { return _loadedModCountText; }
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
27 changes: 23 additions & 4 deletions BepInEx.GUI/Views/ConsoleView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,27 @@
<ColumnDefinition Width="0.25*" />
</Grid.ColumnDefinitions>

<Label Grid.Column="0" Content="Text Filter" FontSize="22" Target="{Binding ElementName=TextBoxTextFilter}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>

<Grid Grid.Column="0" Margin="0, 0, 0, 20">

<Grid.RowDefinitions>
<RowDefinition Height="0.50*" />
<RowDefinition Height="0.50*" />
</Grid.RowDefinitions>

<Label Grid.Row="0" Content="Text Filter" FontSize="22" Target="{Binding ElementName=TextBoxTextFilter}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>

<StackPanel Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Center">
<ComboBox Items="{Binding GeneralViewModel.Mods}" SelectedItem="{Binding ConsoleViewModel.SelectedModFilter}" VerticalContentAlignment="Center" HorizontalContentAlignment="Center">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</StackPanel>

</Grid>

<TextBox Grid.Column="1" Name="TextBoxTextFilter" Text="{Binding ConsoleViewModel.TextFilter, Mode=TwoWay}" Margin="0, 20, 0, 20"/>

<StackPanel Grid.Column="2" Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
Expand All @@ -48,8 +67,8 @@
<ItemsRepeater.ItemTemplate>
<DataTemplate>
<StackPanel>
<Border Background="{Binding Color}" CornerRadius="4" Padding="0">
<TextBox IsReadOnly="True" Text="{Binding Text}" TextWrapping="Wrap" DoubleTapped="OnLogEntryDoubleClick" MaxHeight="40" ScrollViewer.VerticalScrollBarVisibility="Disabled"/>
<Border Background="{Binding BackgroundColor}" CornerRadius="4" Padding="0">
<TextBox IsReadOnly="True" Text="{Binding Text}" Foreground="{Binding ForegroundColor}" TextWrapping="Wrap" DoubleTapped="OnLogEntryDoubleClick" MaxHeight="40" ScrollViewer.VerticalScrollBarVisibility="Disabled"/>
</Border>
</StackPanel>
</DataTemplate>
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 f8bb8d2

Please sign in to comment.