Skip to content

Commit

Permalink
Update interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Milkitic committed Jan 31, 2024
1 parent 3836f5f commit fbd34e6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
1 change: 1 addition & 0 deletions unlockfps_gui/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public override void RegisterServices()
services.AddTransient<MainWindow>();
services.AddTransient<SettingsWindow>();
services.AddSingleton<ConfigService>();
services.AddSingleton<ProcessService>();
DefaultServices = services.BuildServiceProvider();
}

Expand Down
49 changes: 29 additions & 20 deletions unlockfps_gui/Services/ProcessService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Threading;
using Microsoft.Extensions.DependencyInjection;
using UnlockFps.Gui.Model;
using UnlockFps.Gui.Utils;
Expand Down Expand Up @@ -64,9 +65,9 @@ public async ValueTask<bool> StartAsync()
{
if (IsGameRunning())
{
var infoWindow = App.DefaultServices.GetRequiredService<AlertWindow>();
infoWindow.Text = "An instance of the game is already running.";
await infoWindow.ShowDialog(App.CurrentMainWindow!);
await ShowErrorMessage(
"An instance of the game is already running."
);
return false;
}

Expand Down Expand Up @@ -123,19 +124,17 @@ private async Task Worker()

if (!Native.CreateProcess(_config.GamePath, BuildCommandLine(), IntPtr.Zero, IntPtr.Zero, false, creationFlag, IntPtr.Zero, gameFolder, ref si, out var pi))
{
var infoWindow = App.DefaultServices.GetRequiredService<AlertWindow>();
infoWindow.Text =
$"CreateProcess failed ({Marshal.GetLastWin32Error()}){Environment.NewLine} {Marshal.GetLastPInvokeErrorMessage()}";
await infoWindow.ShowDialog(App.CurrentMainWindow!);
await ShowErrorMessage(
$"CreateProcess failed ({Marshal.GetLastWin32Error()}){Environment.NewLine} {Marshal.GetLastPInvokeErrorMessage()}"
);
return;
}

if (!ProcessUtils.InjectDlls(pi.hProcess, _config.DllList))
{
var infoWindow = App.DefaultServices.GetRequiredService<AlertWindow>();
infoWindow.Text =
$"Dll Injection failed ({Marshal.GetLastWin32Error()}){Environment.NewLine} {Marshal.GetLastPInvokeErrorMessage()}";
await infoWindow.ShowDialog(App.CurrentMainWindow!);
await ShowErrorMessage(
$"Dll Injection failed ({Marshal.GetLastWin32Error()}){Environment.NewLine} {Marshal.GetLastPInvokeErrorMessage()}"
);
}

if (_config.SuspendLoad)
Expand Down Expand Up @@ -212,9 +211,9 @@ private unsafe bool SetupData()

if (!pUnityPlayer || !pUserAssembly)
{
var infoWindow = App.DefaultServices.GetRequiredService<AlertWindow>();
infoWindow.Text = "Failed to load UnityPlayer.dll or UserAssembly.dll";
infoWindow.ShowDialog(App.CurrentMainWindow!);
ShowErrorMessage(
"Failed to load UnityPlayer.dll or UserAssembly.dll"
);
return false;
}

Expand Down Expand Up @@ -281,9 +280,9 @@ private unsafe bool SetupData()
return true;

BAD_PATTERN:
var infoWindow1 = App.DefaultServices.GetRequiredService<AlertWindow>();
infoWindow1.Text = "outdated fps pattern";
infoWindow1.ShowDialog(App.CurrentMainWindow!);
ShowErrorMessage(
"outdated fps pattern"
);
return false;
}

Expand All @@ -308,13 +307,23 @@ private async Task<bool> UpdateRemoteModules()

if (_remoteUnityPlayer == IntPtr.Zero || _remoteUserAssembly == IntPtr.Zero)
{
var infoWindow1 = App.DefaultServices.GetRequiredService<AlertWindow>();
infoWindow1.Text = "Failed to get remote module base address";
await infoWindow1.ShowDialog(App.CurrentMainWindow!);
await ShowErrorMessage(
"Failed to get remote module base address"
);
return false;
}

return true;
}

private static async Task ShowErrorMessage(string infoWindowText)
{
await Dispatcher.UIThread.InvokeAsync(async () =>
{
var infoWindow = App.DefaultServices.GetRequiredService<AlertWindow>();
infoWindow.Text =
infoWindowText;
await infoWindow.ShowDialog(App.CurrentMainWindow!);
});
}
}
1 change: 1 addition & 0 deletions unlockfps_gui/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ private async void BtnLaunchGame_OnClick(object? sender, RoutedEventArgs e)
await MainWindowViewModel.ShowWindow<InitializationWindow>();
}

if (!File.Exists(_viewModel.Config.GamePath)) return;
if (await _processService.StartAsync())
{
WindowState = WindowState.Minimized;
Expand Down

0 comments on commit fbd34e6

Please sign in to comment.