Skip to content

Commit

Permalink
Merge pull request #4 from risk-of-thunder/v2
Browse files Browse the repository at this point in the history
V2 continued
  • Loading branch information
xiaoxiao921 authored Feb 17, 2022
2 parents 03f0e5e + 32c2c25 commit 773a862
Show file tree
Hide file tree
Showing 30 changed files with 855 additions and 90 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/github-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: GitHub Release

on:
push:
tags:
- 'v*' # Push events to matching v*, i.e. v20.15.10

jobs:
tagged-release:
name: "Tagged Release"
runs-on: "windows-latest"

steps:

- name: Checkout
uses: actions/checkout@v2

- name: Dotnet Setup
uses: actions/setup-dotnet@v1

- name: Publish Windows x64
run: dotnet publish -c Release --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}}/
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}}

- name: Zip Windows x86 Release
uses: papeloto/action-zip@v1
with:
files: BepInEx_GUI_win_x86_${{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}}

- name: Zip Linux x64 Release
uses: papeloto/action-zip@v1
with:
files: BepInEx_GUI_linux_x64_${{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}}

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

- name: "Make GitHub Release"
uses: "marvinpinto/action-automatic-releases@latest"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
prerelease: false
files: |
*.zip
44 changes: 43 additions & 1 deletion BepInEx.GUI.Config/MainConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using BepInEx.Configuration;
using BepInEx.Configuration;
using System;
using System.IO;

namespace BepInEx.GUI.Config
{
Expand All @@ -13,6 +15,46 @@ public static class MainConfig
public const string EnableDeveloperToolsText = "Enable Developer Tools";
public static ConfigEntry<bool> EnableDeveloperToolsConfig { get; private set; }

/// <summary>
/// This is done through LocalApplicationData because
/// the BepInEx.GUI cfg file may be copied across different users
/// by r2modman profile sharing feature
/// thus they may never end up seeing the one time only disclaimer
/// </summary>
public static bool ShowOneTimeOnlyDisclaimerConfig
{
get
{
try
{
var localAppDataFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
if (string.IsNullOrWhiteSpace(localAppDataFolderPath))
{
return false;
}

var bepinexGuiAppDataFolderPath = Path.Combine(localAppDataFolderPath, "BepInEx.GUI");

var alreadyShownDisclaimer = Directory.Exists(bepinexGuiAppDataFolderPath);
if (alreadyShownDisclaimer)
{
return false;

}
else
{
Directory.CreateDirectory(bepinexGuiAppDataFolderPath);
return true;
}
}
catch (Exception)
{
}

return false;
}
}

public const string CloseWindowWhenGameLoadedConfigKey = "Close Window When Game Loaded";
public const string CloseWindowWhenGameLoadedConfigDescription = "Close the graphic user interface window when the game is loaded";
public static ConfigEntry<bool> CloseWindowWhenGameLoadedConfig { get; private set; }
Expand Down
2 changes: 1 addition & 1 deletion BepInEx.GUI.Patcher/BepInEx.GUI.Patcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BepInEx.Core" Version="5.4.17" />
<PackageReference Include="BepInEx.Core" Version="5.4.19" />
</ItemGroup>

<Import Project="..\BepInEx.GUI.Config\BepInEx.GUI.Config.projitems" Label="Shared" />
Expand Down
1 change: 0 additions & 1 deletion BepInEx.GUI.Patcher/CloseGuiOnChainloaderDone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,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)
{
Expand Down
56 changes: 39 additions & 17 deletions BepInEx.GUI.Patcher/Patcher.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BepInEx.Configuration;
using BepInEx.Configuration;
using BepInEx.Logging;
using Mono.Cecil;
using MonoMod.Utils;
Expand All @@ -10,6 +10,7 @@

namespace BepInEx.GUI.Patcher
{
[BepInDependency("PassivePicasso.WebSlog.WebSocketLogServer", BepInDependency.DependencyFlags.HardDependency)]
public static class Patcher
{
public static IEnumerable<string> TargetDLLs => Enumerable.Empty<string>();
Expand All @@ -31,16 +32,23 @@ public static void Initialize()
}
else
{
string executablePath = FindGuiExecutable();
if (executablePath != null)
{
LaunchGui(executablePath);
}
else
{
LogSource.LogMessage("BepInEx.GUI executable not found.");
LogSource.Dispose();
}
FindAndLaunchGui();
}
}

private static void FindAndLaunchGui()
{
Patcher.LogSource.LogMessage("Finding and launching GUI");

string executablePath = FindGuiExecutable();
if (executablePath != null)
{
LaunchGui(executablePath);
}
else
{
LogSource.LogMessage("BepInEx.GUI executable not found.");
LogSource.Dispose();
}
}

Expand All @@ -52,20 +60,34 @@ private static string FindGuiExecutable()

const string GuiFileName = "BepInEx.GUI";

const Platform windowsPlatform = Platform.Windows;
const Platform windowsX64Platform = Platform.Windows | Platform.Bits64;

const Platform linuxX64Platform = Platform.Linux | Platform.Bits64;

const Platform macOsX64Platform = Platform.MacOS | Platform.Bits64;

var platform = PlatformHelper.Current;

var isWindows = (platform & windowsX64Platform) == platform;
var isLinux = (platform & linuxX64Platform) == platform;
var isMacOs = (platform & macOsX64Platform) == platform;
var isWindows = (platform & windowsPlatform) == platform;
var isWindows64 = (platform & windowsX64Platform) == platform;

// linux x86 https://github.com/dotnet/runtime/issues/31180
var isLinux64 = (platform & linuxX64Platform) == platform;

var isMacOs64 = (platform & macOsX64Platform) == platform;

var filePathLower = filePath.ToLowerInvariant();

// Not the best but should work...
if ((isWindows && fileName == $"{GuiFileName}.exe") ||
(isLinux && fileName == GuiFileName && filePath.ToLowerInvariant().Contains("linux")) ||
(isMacOs && fileName == GuiFileName && filePath.ToLowerInvariant().Contains("osx")))
if (
(isWindows && fileName == $"{GuiFileName}.exe" && filePathLower.Contains("86")) ||
(isWindows64 && fileName == $"{GuiFileName}.exe" && filePathLower.Contains("64")) ||

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

(isMacOs64 && fileName == GuiFileName && filePathLower.Contains("macos64"))
)
{
return filePath;
}
Expand Down
42 changes: 41 additions & 1 deletion BepInEx.GUI/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,51 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:BepInEx.GUI"
x:Class="BepInEx.GUI.App">

<Application.DataTemplates>
<local:ViewLocator/>
</Application.DataTemplates>

<Application.Styles>
<FluentTheme Mode="Light"/>

<FluentTheme Mode="Dark"/>

<Style Selector="ScrollBar[IsExpanded=false] /template/ Grid#Root">
<Setter Property="Background" Value="{DynamicResource ScrollBarBackgroundPointerOver}" />
</Style>

<Style Selector="ScrollBar[IsExpanded=false] /template/ Thumb.thumb">
<Setter Property="RenderTransform" Value="none" />
<Setter Property="Background" Value="{DynamicResource ScrollBarThumbBackgroundColor}" />
</Style>

<Style Selector="ScrollBar[IsExpanded=false] /template/ Thumb.thumb /template/ Border#ThumbVisual">
<Setter Property="CornerRadius" Value="0" />
</Style>

<Style Selector="ScrollBar[IsExpanded=false] /template/ RepeatButton.line">
<Setter Property="Opacity" Value="1" />
</Style>

<Style Selector="ScrollBar[IsExpanded=false] /template/ RepeatButton.largeIncrease">
<Setter Property="Opacity" Value="1" />
</Style>

<Style Selector="ScrollBar[IsExpanded=false] /template/ Rectangle#TrackRect">
<Setter Property="Fill" Value="{DynamicResource ScrollBarTrackFillPointerOver}" />
<Setter Property="Stroke" Value="{DynamicResource ScrollBarTrackStrokePointerOver}" />
<Setter Property="Opacity" Value="1" />
</Style>

<Style Selector="ScrollBar /template/ RepeatButton.line /template/ Border#Root" >
<Setter Property="Background" Value="{DynamicResource ScrollBarButtonBackgroundPointerOver}" />
<Setter Property="BorderBrush" Value="{DynamicResource ScrollBarButtonBorderBrushPointerOver}" />
</Style>

<Style Selector="ScrollBar /template/ RepeatButton.line /template/ Path#Arrow" >
<Setter Property="Fill" Value="{DynamicResource ScrollBarButtonArrowForegroundPointerOver}" />
</Style>

</Application.Styles>

</Application>
26 changes: 22 additions & 4 deletions BepInEx.GUI/App.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using BepInEx.GUI.Config;
using BepInEx.GUI.Models;
using BepInEx.GUI.ViewModels;
using BepInEx.GUI.Views;
using System;
using WebSocketSharp;

namespace BepInEx.GUI
{
public class App : Application
{
private WebSocket? _webSocket;

public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
Expand All @@ -21,31 +25,45 @@ public override void OnFrameworkInitializationCompleted()
{
desktop.Startup += (sender, eventArgs) =>
{
AppDomain.CurrentDomain.UnhandledException += ShowUnhandledException;

var args = DefaultArgsIfNoneProvided(eventArgs.Args);

var platformInfo = new PlatformInfo(args);
var pathsInfo = new PathsInfo(args);
var targetInfo = new TargetInfo(args);

var webSocket = new WebSocket("ws://localhost:5892/Log");
webSocket.Connect();
_webSocket = new WebSocket("ws://localhost:5892/Log");
_webSocket.Connect();

MainConfig.Init(pathsInfo.ConfigFilePath);

desktop.MainWindow = new MainWindow
{
DataContext = new MainWindowViewModel(webSocket, pathsInfo, platformInfo, targetInfo),
DataContext = new MainWindowViewModel(_webSocket, pathsInfo, platformInfo, targetInfo),
};

// Needed or the target closes
desktop.MainWindow.Closing += (sender, e) =>
{
webSocket.Close();
_webSocket.Close();
};
};
}

base.OnFrameworkInitializationCompleted();
}

private void ShowUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
// Avalonia could possibly not be able to recover at all from this exception, thus closing the app
// the websocket if left open at this point will crash the target
_webSocket!.Close();

var ex = (Exception)e.ExceptionObject;
Debug.Message(ex.ToString());
}

private static string[] DefaultArgsIfNoneProvided(string[] args)
{
if (args.Length == 0)
Expand Down
8 changes: 6 additions & 2 deletions BepInEx.GUI/BepInEx.GUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="0.10.10" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.10" />
<PackageReference Include="BepInEx.Core" Version="5.4.17" />
<PackageReference Include="protobuf-net" Version="2.4.6" />
<PackageReference Include="BepInEx.Core" Version="5.4.19" />
<PackageReference Include="WebSocketSharp-netstandard" Version="1.0.1" />
<PackageReference Include="XamlNameReferenceGenerator" Version="1.3.4" />
</ItemGroup>
<ItemGroup>
<Reference Include="protobuf-net">
<HintPath>..\libs\protobuf-net.dll</HintPath>
</Reference>
</ItemGroup>
<Import Project="..\BepInEx.GUI.Config\BepInEx.GUI.Config.projitems" Label="Shared" />
</Project>
2 changes: 1 addition & 1 deletion BepInEx.GUI/Models/LogEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class LogEntry
}
catch (Exception e)
{
// todo
Debug.Message($"Error deserializing log entry: {e}");
}

return null;
Expand Down
4 changes: 3 additions & 1 deletion BepInEx.GUI/Models/TargetInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ public class TargetInfo

public TargetInfo(string[] args)
{
if (int.TryParse(args[6], out var id));
if (int.TryParse(args[6], out var id))
Id = id;
else
Debug.Message("Error parsing args[6] for target process id");

Process = Process.GetProcessById(Id);
}
Expand Down
Loading

0 comments on commit 773a862

Please sign in to comment.