Skip to content

Commit

Permalink
Add test mode (#3012)
Browse files Browse the repository at this point in the history
  • Loading branch information
pizzaboxer committed Oct 2, 2024
1 parent 0b15b62 commit 0cd8736
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 21 deletions.
19 changes: 13 additions & 6 deletions Bloxstrap/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public class Bootstrapper
private readonly CancellationTokenSource _cancelTokenSource = new();

private readonly IAppData AppData;
private readonly LaunchMode _launchMode;

private string _launchCommandLine = App.LaunchSettings.RobloxLaunchArgs;
private LaunchMode _launchMode = App.LaunchSettings.RobloxLaunchMode;
private string _latestVersionGuid = null!;
private PackageManifest _versionPackageManifest = null!;

Expand All @@ -59,8 +59,10 @@ public class Bootstrapper
#endregion

#region Core
public Bootstrapper()
public Bootstrapper(LaunchMode launchMode)
{
_launchMode = launchMode;

// this is now always enabled as of v2.8.0
if (Dialog is not null)
Dialog.CancelEnabled = true;
Expand Down Expand Up @@ -382,18 +384,23 @@ private void StartRoblox()
autoclosePids.Add(pid);
}

string args = _appPid.ToString();
string argPids = _appPid.ToString();

if (autoclosePids.Any())
args += $";{String.Join(',', autoclosePids)}";
argPids += $";{String.Join(',', autoclosePids)}";

if (App.Settings.Prop.EnableActivityTracking || autoclosePids.Any())
if (App.Settings.Prop.EnableActivityTracking || App.LaunchSettings.TestModeFlag.Active || autoclosePids.Any())
{
using var ipl = new InterProcessLock("Watcher", TimeSpan.FromSeconds(5));

string args = $"-watcher \"{argPids}\"";

if (App.LaunchSettings.TestModeFlag.Active)
args += " -testmode";

// TODO: look into if this needs to be launched *before* roblox starts
if (ipl.IsAcquired)
Process.Start(Paths.Process, $"-watcher \"{args}\"");
Process.Start(Paths.Process, args);
}
}

Expand Down
12 changes: 7 additions & 5 deletions Bloxstrap/LaunchHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ public static void ProcessNextAction(NextAction action, bool isUnfinishedInstall
break;

case NextAction.LaunchRoblox:
App.LaunchSettings.RobloxLaunchMode = LaunchMode.Player;
LaunchRoblox();
LaunchRoblox(LaunchMode.Player);
break;

default:
Expand All @@ -39,7 +38,7 @@ public static void ProcessLaunchArgs()
else if (App.LaunchSettings.WatcherFlag.Active)
LaunchWatcher();
else if (App.LaunchSettings.RobloxLaunchMode != LaunchMode.None)
LaunchRoblox();
LaunchRoblox(App.LaunchSettings.RobloxLaunchMode);
else if (!App.LaunchSettings.QuietFlag.Active)
LaunchMenu();
else
Expand Down Expand Up @@ -163,10 +162,13 @@ public static void LaunchMenu()
ProcessNextAction(dialog.CloseAction);
}

public static void LaunchRoblox()
public static void LaunchRoblox(LaunchMode launchMode)
{
const string LOG_IDENT = "LaunchHandler::LaunchRoblox";

if (launchMode == LaunchMode.None)
throw new InvalidOperationException("No Roblox launch mode set");

if (!File.Exists(Path.Combine(Paths.System, "mfplat.dll")))
{
Frontend.ShowMessageBox(Strings.Bootstrapper_WMFNotFound, MessageBoxImage.Error);
Expand Down Expand Up @@ -194,7 +196,7 @@ public static void LaunchRoblox()

// start bootstrapper and show the bootstrapper modal if we're not running silently
App.Logger.WriteLine(LOG_IDENT, "Initializing bootstrapper");
var bootstrapper = new Bootstrapper();
var bootstrapper = new Bootstrapper(launchMode);
IBootstrapperDialog? dialog = null;

if (!App.LaunchSettings.QuietFlag.Active)
Expand Down
2 changes: 2 additions & 0 deletions Bloxstrap/LaunchSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class LaunchSettings
public LaunchFlag UninstallFlag { get; } = new("uninstall");

public LaunchFlag NoLaunchFlag { get; } = new("nolaunch");

public LaunchFlag TestModeFlag { get; } = new("testmode");

public LaunchFlag NoGPUFlag { get; } = new("nogpu");

Expand Down
22 changes: 22 additions & 0 deletions Bloxstrap/Resources/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions Bloxstrap/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1237,4 +1237,14 @@ Please manually delete Bloxstrap.exe from the install location or try restarting
<data name="Dialog.Exception.Report" xml:space="preserve">
<value>Report exception</value>
</data>
<data name="Menu.TestMode" xml:space="preserve">
<value>Test mode</value>
</data>
<data name="Menu.TestMode.Prompt" xml:space="preserve">
<value>Test mode makes it easier to iteratively test how your settings affect Roblox.

While enabled, it will automatically launch Roblox after closing Settings, and reopen Settings after closing Roblox, in a cycle until you disable it.

Would you like to enable test mode?</value>
</data>
</root>
3 changes: 2 additions & 1 deletion Bloxstrap/UI/Elements/About/Pages/AboutPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
xmlns:resources="clr-namespace:Bloxstrap.Resources"
mc:Ignorable="d"
d:DesignHeight="1500" d:DesignWidth="800"
d:DataContext="{d:DesignInstance dmodels:AboutViewModel, IsDesignTimeCreatable=True}"
Title="AboutPage"
Scrollable="True">
<!--d:DataContext="{d:DesignInstance dmodels:AboutViewModel, IsDesignTimeCreatable=True}"-->

<StackPanel Margin="0,0,14,14">
<StackPanel.Resources>
Expand Down Expand Up @@ -126,6 +126,7 @@
<controls:MarkdownTextBlock MarkdownText="[toyoda165](https://www.roblox.com/users/923416649/profile)" />
<controls:MarkdownTextBlock MarkdownText="[ShadowCodeX](https://github.com/ShadowCodeX-debug)" />
<controls:MarkdownTextBlock MarkdownText="[cub-has-injected](https://github.com/cub-has-injected)" />
<controls:MarkdownTextBlock MarkdownText="[AskaLangly](https://github.com/AskaLangly)" />
</StackPanel>
</controls:Expander>

Expand Down
6 changes: 3 additions & 3 deletions Bloxstrap/UI/Elements/ContextMenu/MenuContainer.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ public MenuContainer(Watcher watcher)
_activityWatcher.OnLogOpen += ActivityWatcher_OnLogOpen;
_activityWatcher.OnGameJoin += ActivityWatcher_OnGameJoin;
_activityWatcher.OnGameLeave += ActivityWatcher_OnGameLeave;

if (!App.Settings.Prop.UseDisableAppPatch)
GameHistoryMenuItem.Visibility = Visibility.Visible;
}

if (_watcher.RichPresence is not null)
RichPresenceMenuItem.Visibility = Visibility.Visible;

if (!App.Settings.Prop.UseDisableAppPatch)
GameHistoryMenuItem.Visibility = Visibility.Visible;

VersionTextBlock.Text = $"{App.ProjectName} v{App.Version}";
}

Expand Down
16 changes: 13 additions & 3 deletions Bloxstrap/UI/Elements/Settings/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
xmlns:base="clr-namespace:Bloxstrap.UI.Elements.Base"
xmlns:resources="clr-namespace:Bloxstrap.Resources"
xmlns:dmodels="clr-namespace:Bloxstrap.UI.ViewModels.Settings"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance dmodels:MainWindowViewModel, IsDesignTimeCreatable=True}"
Title="{x:Static resources:Strings.Menu_Title}"
MinWidth="960"
Width="980"
Expand All @@ -16,7 +18,8 @@
ExtendsContentIntoTitleBar="True"
WindowBackdropType="Mica"
WindowStartupLocation="CenterScreen"
Closing="WpfUiWindow_Closing">
Closing="WpfUiWindow_Closing"
Closed="WpfUiWindow_Closed">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
Expand Down Expand Up @@ -84,17 +87,24 @@
<ItemsPanelTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
</Grid>
</ItemsPanelTemplate>
</StatusBar.ItemsPanel>
<StatusBarItem Grid.Column="1" Padding="0,0,4,0">
<StatusBarItem Grid.Column="0">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<ui:ToggleSwitch IsChecked="{Binding TestModeEnabled, Mode=TwoWay}" />
<TextBlock Padding="12,0,0,0" Text="{x:Static resources:Strings.Menu_TestMode}" VerticalAlignment="Center" FontSize="14" />
</StackPanel>
</StatusBarItem>
<StatusBarItem Grid.Column="2" Padding="0,0,4,0">
<ui:Button Content="{x:Static resources:Strings.Menu_Save}" Appearance="Primary" Command="{Binding SaveSettingsCommand, Mode=OneWay}" />
</StatusBarItem>
<StatusBarItem Grid.Column="2" Padding="4,0,0,0">
<StatusBarItem Grid.Column="3" Padding="4,0,0,0">
<ui:Button Content="{x:Static resources:Strings.Common_Close}" Command="{Binding CloseWindowCommand, Mode=OneWay}" />
</StatusBarItem>
</StatusBar>
Expand Down
7 changes: 6 additions & 1 deletion Bloxstrap/UI/Elements/Settings/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,13 @@ private void WpfUiWindow_Closing(object sender, CancelEventArgs e)
_state.Left = this.Left;

App.State.Save();
}

if (!e.Cancel)
private void WpfUiWindow_Closed(object sender, EventArgs e)
{
if (App.LaunchSettings.TestModeFlag.Active)
LaunchHandler.LaunchRoblox(LaunchMode.Player);
else
App.SoftTerminate();
}
}
Expand Down
20 changes: 19 additions & 1 deletion Bloxstrap/UI/ViewModels/Settings/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Windows.Input;
using System.Windows;
using System.Windows.Input;
using Bloxstrap.UI.Elements.About;
using CommunityToolkit.Mvvm.Input;

Expand All @@ -16,6 +17,23 @@ public class MainWindowViewModel : NotifyPropertyChangedViewModel

public EventHandler? RequestCloseWindowEvent;

public bool TestModeEnabled
{
get => App.LaunchSettings.TestModeFlag.Active;
set
{
if (value)
{
var result = Frontend.ShowMessageBox(Strings.Menu_TestMode_Prompt, MessageBoxImage.Information, MessageBoxButton.YesNo);

if (result != MessageBoxResult.Yes)
return;
}

App.LaunchSettings.TestModeFlag.Active = value;
}
}

private void OpenAbout() => new MainWindow().ShowDialog();

private void CloseWindow() => RequestCloseWindowEvent?.Invoke(this, EventArgs.Empty);
Expand Down
5 changes: 4 additions & 1 deletion Bloxstrap/Watcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public Watcher()

if (App.Settings.Prop.UseDisableAppPatch)
{
ActivityWatcher.OnAppClose += (_, _) =>
ActivityWatcher.OnAppClose += delegate
{
App.Logger.WriteLine(LOG_IDENT, "Received desktop app exit, closing Roblox");
using var process = Process.GetProcessById(_gameClientPid);
Expand Down Expand Up @@ -125,6 +125,9 @@ public async Task Run()

foreach (int pid in _autoclosePids)
CloseProcess(pid);

if (App.LaunchSettings.TestModeFlag.Active)
Process.Start(Paths.Process, "-settings -testmode");
}

public void Dispose()
Expand Down

0 comments on commit 0cd8736

Please sign in to comment.