Add support for FastFlag mods (#98)

This commit is contained in:
pizzaboxer 2023-03-10 00:00:53 +00:00
parent d5d95872bb
commit 04fd634784
8 changed files with 117 additions and 24 deletions

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using System.Net.Http; using System.Net.Http;
@ -46,6 +47,7 @@ namespace Bloxstrap
public static readonly DeployManager DeployManager = new(); public static readonly DeployManager DeployManager = new();
public static readonly JsonManager<Settings> Settings = new(); public static readonly JsonManager<Settings> Settings = new();
public static readonly JsonManager<State> State = new(); public static readonly JsonManager<State> State = new();
public static readonly JsonManager<Dictionary<string, object>> FastFlags = new();
public static readonly HttpClient HttpClient = new(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.All }); public static readonly HttpClient HttpClient = new(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.All });
// shorthand // shorthand
@ -154,6 +156,7 @@ namespace Bloxstrap
} }
Directories.Initialize(BaseDirectory); Directories.Initialize(BaseDirectory);
FastFlags.AltFileLocation = Path.Combine(Directories.Modifications, "ClientSettings\\ClientAppSettings.json");
// we shouldn't save settings on the first run until the first installation is finished, // we shouldn't save settings on the first run until the first installation is finished,
// just in case the user decides to cancel the install // just in case the user decides to cancel the install

View File

@ -153,7 +153,10 @@ namespace Bloxstrap
_versionFolder = Path.Combine(Directories.Versions, App.State.Prop.VersionGuid); _versionFolder = Path.Combine(Directories.Versions, App.State.Prop.VersionGuid);
if (App.IsFirstRun) if (App.IsFirstRun)
{
App.ShouldSaveConfigs = true; App.ShouldSaveConfigs = true;
App.FastFlags.Save();
}
await ApplyModifications(); await ApplyModifications();
@ -733,6 +736,8 @@ namespace Bloxstrap
{ {
SetStatus("Applying Roblox modifications..."); SetStatus("Applying Roblox modifications...");
// set executable flags for fullscreen optimizations
App.Logger.WriteLine("[Bootstrapper::ApplyModifications] Checking executable flags...");
using (RegistryKey appFlagsKey = Registry.CurrentUser.CreateSubKey($"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers")) using (RegistryKey appFlagsKey = Registry.CurrentUser.CreateSubKey($"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers"))
{ {
const string flag = " DISABLEDXMAXIMIZEDWINDOWEDMODE"; const string flag = " DISABLEDXMAXIMIZEDWINDOWEDMODE";
@ -757,6 +762,7 @@ namespace Bloxstrap
} }
// handle file mods // handle file mods
App.Logger.WriteLine("[Bootstrapper::ApplyModifications] Checking file mods...");
string modFolder = Path.Combine(Directories.Modifications); string modFolder = Path.Combine(Directories.Modifications);
// manifest has been moved to State.json // manifest has been moved to State.json
@ -831,6 +837,7 @@ namespace Bloxstrap
// package doesn't exist, likely mistakenly placed file // package doesn't exist, likely mistakenly placed file
string versionFileLocation = Path.Combine(_versionFolder, fileLocation); string versionFileLocation = Path.Combine(_versionFolder, fileLocation);
if (File.Exists(versionFileLocation))
File.Delete(versionFileLocation); File.Delete(versionFileLocation);
continue; continue;

View File

@ -16,15 +16,11 @@ namespace Bloxstrap.Helpers
public class JsonManager<T> where T : new() public class JsonManager<T> where T : new()
{ {
public T Prop { get; set; } = new(); public T Prop { get; set; } = new();
//public bool ShouldSave { get; set; } = true; public string FileLocation => AltFileLocation ?? Path.Combine(Directories.Base, $"{typeof(T).Name}.json");
public string FileLocation => Path.Combine(Directories.Base, $"{typeof(T).Name}.json"); public string? AltFileLocation { get; set; }
//public string? FileLocation { get; set; } = null;
public void Load() public void Load()
{ {
//if (String.IsNullOrEmpty(FileLocation))
// throw new ArgumentNullException("No FileLocation has been set");
App.Logger.WriteLine($"[JsonManager<{typeof(T).Name}>::Load] Loading JSON from {FileLocation}..."); App.Logger.WriteLine($"[JsonManager<{typeof(T).Name}>::Load] Loading JSON from {FileLocation}...");
try try
@ -32,7 +28,6 @@ namespace Bloxstrap.Helpers
T? settings = JsonSerializer.Deserialize<T>(File.ReadAllText(FileLocation)); T? settings = JsonSerializer.Deserialize<T>(File.ReadAllText(FileLocation));
Prop = settings ?? throw new ArgumentNullException("Deserialization returned null"); Prop = settings ?? throw new ArgumentNullException("Deserialization returned null");
App.Logger.WriteLine($"[JsonManager<{typeof(T).Name}>::Load] JSON loaded successfully!"); App.Logger.WriteLine($"[JsonManager<{typeof(T).Name}>::Load] JSON loaded successfully!");
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -40,25 +35,18 @@ namespace Bloxstrap.Helpers
} }
} }
public void Save() public void Save(bool saveOverride = false)
{ {
App.Logger.WriteLine($"[JsonManager<{typeof(T).Name}>::Save] Attempting to save JSON to {FileLocation}..."); App.Logger.WriteLine($"[JsonManager<{typeof(T).Name}>::Save] Attempting to save JSON to {FileLocation}...");
//if (!ShouldSave || String.IsNullOrEmpty(FileLocation)) if (!App.ShouldSaveConfigs && !saveOverride)
//{
// App.Logger.WriteLine($"[JsonManager<{typeof(T).Name}>] Aborted save (ShouldSave set to false or FileLocation not set)");
// return;
//}
//if (!ShouldSave)
if (!App.ShouldSaveConfigs)
{ {
App.Logger.WriteLine($"[JsonManager<{typeof(T).Name}>::Save] Aborted save (ShouldSave set to false)"); App.Logger.WriteLine($"[JsonManager<{typeof(T).Name}>::Save] Aborted save (ShouldSave set to false)");
return; return;
} }
string json = JsonSerializer.Serialize(Prop, new JsonSerializerOptions { WriteIndented = true }); Directory.CreateDirectory(Path.GetDirectoryName(FileLocation)!);
File.WriteAllText(FileLocation, json); File.WriteAllText(FileLocation, JsonSerializer.Serialize(Prop, new JsonSerializerOptions { WriteIndented = true }));
App.Logger.WriteLine($"[JsonManager<{typeof(T).Name}>::Save] JSON saved!"); App.Logger.WriteLine($"[JsonManager<{typeof(T).Name}>::Save] JSON saved!");
} }

View File

@ -69,7 +69,7 @@ namespace Bloxstrap.Integrations
else if (_logEntriesRead % 100 == 0) else if (_logEntriesRead % 100 == 0)
App.Logger.WriteLine($"[DiscordRichPresence::ExamineLogEntry] Read {_logEntriesRead} log entries"); App.Logger.WriteLine($"[DiscordRichPresence::ExamineLogEntry] Read {_logEntriesRead} log entries");
if (entry.Contains(GameJoiningEntry) && !_activityInGame && _activityPlaceId == 0) if (!_activityInGame && _activityPlaceId == 0 && entry.Contains(GameJoiningEntry))
{ {
Match match = Regex.Match(entry, GameJoiningEntryPattern); Match match = Regex.Match(entry, GameJoiningEntryPattern);
@ -121,7 +121,7 @@ namespace Bloxstrap.Integrations
await SetPresence(); await SetPresence();
} }
} }
else if (entry.Contains(GameDisconnectedEntry) && _activityInGame && _activityPlaceId != 0) else if (_activityInGame && _activityPlaceId != 0 && entry.Contains(GameDisconnectedEntry))
{ {
App.Logger.WriteLine($"[DiscordRichPresence::ExamineLogEntry] Disconnected from Game ({_activityPlaceId}/{_activityJobId}/{_activityMachineAddress})"); App.Logger.WriteLine($"[DiscordRichPresence::ExamineLogEntry] Disconnected from Game ({_activityPlaceId}/{_activityJobId}/{_activityMachineAddress})");

View File

@ -59,7 +59,6 @@ namespace Bloxstrap.ViewModels
if (!App.IsFirstRun) if (!App.IsFirstRun)
{ {
//App.Settings.ShouldSave = true;
App.ShouldSaveConfigs = true; App.ShouldSaveConfigs = true;
if (App.BaseDirectory != _originalBaseDirectory) if (App.BaseDirectory != _originalBaseDirectory)

View File

@ -1,4 +1,5 @@
using System.Diagnostics; using System.Collections.Generic;
using System.Diagnostics;
using System.Windows.Input; using System.Windows.Input;
using Bloxstrap.Helpers; using Bloxstrap.Helpers;
using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Input;
@ -32,6 +33,70 @@ namespace Bloxstrap.ViewModels
set => App.Settings.Prop.UseDisableAppPatch = value; set => App.Settings.Prop.UseDisableAppPatch = value;
} }
// only one missing here is Metal because lol
public IReadOnlyDictionary<string, string> RenderingModes { get; set; } = new Dictionary<string, string>()
{
{ "Automatic", "" },
{ "Direct3D 11", "FFlagDebugGraphicsPreferD3D11" },
{ "OpenGL", "FFlagDebugGraphicsPreferOpenGL" },
{ "Vulkan", "FFlagDebugGraphicsPreferVulkan" }
};
// if i ever need to do more fflag handling i'll just add an fflag handler that abstracts away all this boilerplate
// but for now this is fine
public bool ExclusiveFullscreenEnabled
{
get
{
return App.FastFlags.Prop.ContainsKey("FFlagHandleAltEnterFullscreenManually") && App.FastFlags.Prop["FFlagHandleAltEnterFullscreenManually"].ToString() == "False";
}
set
{
if (!App.IsFirstRun)
App.FastFlags.Load();
if (value)
App.FastFlags.Prop["FFlagHandleAltEnterFullscreenManually"] = false;
else
App.FastFlags.Prop.Remove("FFlagHandleAltEnterFullscreenManually");
if (!App.IsFirstRun)
App.FastFlags.Save(true);
}
}
public string SelectedRenderingMode
{
get
{
foreach (var mode in RenderingModes)
{
if (App.FastFlags.Prop.ContainsKey(mode.Value))
return mode.Key;
}
return "Automatic";
}
set
{
if (!App.IsFirstRun)
App.FastFlags.Load();
foreach (var mode in RenderingModes)
{
App.FastFlags.Prop.Remove(mode.Value);
}
if (value != "Automatic")
App.FastFlags.Prop[RenderingModes[value]] = true;
if (!App.IsFirstRun)
App.FastFlags.Save(true);
}
}
public bool DisableFullscreenOptimizationsEnabled public bool DisableFullscreenOptimizationsEnabled
{ {
get => App.Settings.Prop.DisableFullscreenOptimizations; get => App.Settings.Prop.DisableFullscreenOptimizations;

View File

@ -94,6 +94,34 @@
</ui:CardControl> </ui:CardControl>
</Grid> </Grid>
<TextBlock Text="FastFlags" FontSize="16" FontWeight="Medium" Margin="0,16,0,0" />
<TextBlock Text="Note that these changes automatically save to allow for ClientAppSettings.json to be manually edited." FontSize="12" Foreground="{DynamicResource TextFillColorSecondaryBrush}" />
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<ui:CardControl Grid.Row="0" Margin="0,8,0,0" Padding="16,13,16,12">
<ui:CardControl.Header>
<StackPanel>
<TextBlock FontSize="14" Text="Use exclusive fullscreen" />
<TextBlock Margin="0,2,0,0" FontSize="12" Text="Enables using Alt + Enter to enter exclusive fullscreen. Requires Direct3D 11." Foreground="{DynamicResource TextFillColorTertiaryBrush}" />
</StackPanel>
</ui:CardControl.Header>
<ui:ToggleSwitch IsChecked="{Binding ExclusiveFullscreenEnabled, Mode=TwoWay}" />
</ui:CardControl>
<ui:CardControl Grid.Row="1" Margin="0,8,0,0" Padding="16,13,16,12">
<ui:CardControl.Header>
<StackPanel>
<TextBlock FontSize="14" Text="Rendering mode" />
<TextBlock Margin="0,2,0,0" FontSize="12" Text="Choose which renderer Roblox should use. ReShade requires Direct3D 11." Foreground="{DynamicResource TextFillColorTertiaryBrush}" />
</StackPanel>
</ui:CardControl.Header>
<ComboBox Margin="5,0,0,0" Padding="10,5,10,5" Width="200" ItemsSource="{Binding RenderingModes.Keys, Mode=OneTime}" Text="{Binding SelectedRenderingMode, Mode=TwoWay}" />
</ui:CardControl>
</Grid>
<StackPanel x:Name="MiscellaneousOptions"> <StackPanel x:Name="MiscellaneousOptions">
<TextBlock Text="Miscellaneous" FontSize="16" FontWeight="Medium" Margin="0,16,0,0" /> <TextBlock Text="Miscellaneous" FontSize="16" FontWeight="Medium" Margin="0,16,0,0" />
<ui:CardControl Margin="0,8,0,0" Padding="16,13,16,12"> <ui:CardControl Margin="0,8,0,0" Padding="16,13,16,12">
@ -101,7 +129,7 @@
<StackPanel> <StackPanel>
<TextBlock FontSize="14" Text="Disable full-screen optimizations" /> <TextBlock FontSize="14" Text="Disable full-screen optimizations" />
<TextBlock Margin="0,2,0,0" FontSize="12" Foreground="{DynamicResource TextFillColorTertiaryBrush}"> <TextBlock Margin="0,2,0,0" FontSize="12" Foreground="{DynamicResource TextFillColorTertiaryBrush}">
A Windows feature that can potentially cause problems - <Hyperlink Foreground="{DynamicResource TextFillColorPrimaryBrush}" Command="models:GlobalViewModel.OpenWebpageCommand" CommandParameter="https://devblogs.microsoft.com/directx/demystifying-full-screen-optimizations/">see more info.</Hyperlink>. A Windows feature that can potentially cause problems - <Hyperlink Foreground="{DynamicResource TextFillColorPrimaryBrush}" Command="models:GlobalViewModel.OpenWebpageCommand" CommandParameter="https://devblogs.microsoft.com/directx/demystifying-full-screen-optimizations/">click here for more info</Hyperlink>.
</TextBlock> </TextBlock>
</StackPanel> </StackPanel>
</ui:CardControl.Header> </ui:CardControl.Header>

View File

@ -11,6 +11,9 @@ namespace Bloxstrap.Views.Pages
{ {
public ModsPage() public ModsPage()
{ {
if (!App.IsFirstRun)
App.FastFlags.Load();
DataContext = new ModsViewModel(); DataContext = new ModsViewModel();
InitializeComponent(); InitializeComponent();