Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Pre-Launch and Post-Exit Commands Launching #398

Merged
merged 19 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,16 @@ public enum AntialiasingMode // TypeDefIndex: 25409
TAA = 1,
FXAA = 2
}
#endregion

public enum CharacterQuality
{
Placeholder,
Low = 1,
Placeholder2,
Medium = 3,
High = 4
}
bagusnl marked this conversation as resolved.
Show resolved Hide resolved
#endregion-
bagusnl marked this conversation as resolved.
Show resolved Hide resolved

internal class Model : IGameSettingsValue<Model>
{
Expand Down Expand Up @@ -94,10 +103,10 @@ private static Dictionary<int, int> GenerateStaticFPSIndexDict()

/// <summary>
/// This defines "<c>Character Quality</c>" combobox In-game settings. <br/>
/// Options: Low (2), Medium(3), High(4)
/// Options: Low (1), Medium(3), High(4)
bagusnl marked this conversation as resolved.
Show resolved Hide resolved
/// Default: Medium
/// </summary>
public Quality CharacterQuality { get; set; } = Quality.Medium;
public CharacterQuality CharacterQuality { get; set; } = CharacterQuality.Medium;

/// <summary>
/// This defines "<c>Environment Quality</c>" combobox In-game settings. <br/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,26 @@ public StarRailSettings(IGameVersionCheck GameVersionManager)

private void InitializeSettings()
{
// Load Settings
// Load Settings required for MainPage
SettingsCustomArgument = CustomArgs.Load();
GraphicsSettings = Model.Load();
SettingsCollapseScreen = CollapseScreenSetting.Load();
SettingsCollapseMisc = CollapseMiscSetting.Load();
SettingsScreen = PCResolution.Load();
AudioSettings_BGM = BGMVolume.Load();
AudioSettings_Master = MasterVolume.Load();
AudioSettings_SFX = SFXVolume.Load();
AudioSettings_VO = VOVolume.Load();
AudioLanguage = LocalAudioLanguage.Load();
TextLanguage = LocalTextLanguage.Load();
SettingsCollapseMisc = CollapseMiscSetting.Load();
SettingsScreen = PCResolution.Load();

}

public void ReloadSettings() => InitializeSettings();
public void ReloadSettings()
{
// Load rest of the settings for GSP
AudioSettings_BGM = BGMVolume.Load();
AudioSettings_Master = MasterVolume.Load();
AudioSettings_SFX = SFXVolume.Load();
AudioSettings_VO = VOVolume.Load();
AudioLanguage = LocalAudioLanguage.Load();
TextLanguage = LocalTextLanguage.Load();
GraphicsSettings = Model.Load();
InitializeSettings();
}

public void SaveSettings()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ internal class CollapseMiscSetting : IGameSettingsValue<CollapseMiscSetting>
private const string _ValueName = "CollapseLauncher_Misc";

private bool _UseCustomArguments = true;

private static bool _IsDeserializing;
#endregion

#region Properties
Expand All @@ -34,9 +36,45 @@ public bool UseCustomArguments
set
{
_UseCustomArguments = value;
Save();
// Stop saving if Load() is not yet done.
if (!_IsDeserializing) Save();
}
}

/// <summary>
/// This define if Advanced Game Settings should be shown in respective GSP and used.<br/><br/>
/// Default: false
/// </summary>
public bool UseAdvancedGameSettings { get; set; } = false;

/// <summary>
/// This control if GamePreLaunchCommand is going to be used. <br/><br/>
/// Default: false
/// </summary>
public bool UseGamePreLaunchCommand { get; set; } = false;

/// <summary>
/// This sets the command that is going to be launched before the game process is invoked.<br/><br/>
/// Command is launched as a shell with no window.<br/><br/>
/// </summary>
public string GamePreLaunchCommand { get; set; } = "";

/// <summary>
/// Close GamePreLaunch process when game is stopped.<br/><br/>
/// </summary>
public bool GamePreLaunchExitOnGameStop { get; set; } = false;

/// <summary>
/// This control if GamePostLaunchCommand is going to be used. <br/><br/>
/// Default: false
/// </summary>
public bool UseGamePostExitCommand { get; set; } = false;

/// <summary>
/// This sets the command that is going to be launched after the game process is closed.<br/><br/>
/// Command is launched as a shell with no window.<br/><br/>
/// </summary>
public string GamePostExitCommand { get; set; } = "";
#endregion

#region Methods
Expand All @@ -45,23 +83,28 @@ public static CollapseMiscSetting Load()
{
try
{
_IsDeserializing = true;
if (RegistryRoot == null) throw new NullReferenceException($"Cannot load {_ValueName} RegistryKey is unexpectedly not initialized!");

object? value = RegistryRoot.GetValue(_ValueName, null);

if (value != null)
{
ReadOnlySpan<byte> byteStr = (byte[])value;
#if DEBUG
#if DEBUG
LogWriteLine($"Loaded Collapse Misc Settings:\r\n{Encoding.UTF8.GetString(byteStr.TrimEnd((byte)0))}", LogType.Debug, true);
#endif
#endif
return byteStr.Deserialize<CollapseMiscSetting>(UniversalSettingsJSONContext.Default) ?? new CollapseMiscSetting();
}
}
catch (Exception ex)
catch ( Exception ex )
{
LogWriteLine($"Failed while reading {_ValueName}\r\n{ex}", LogType.Error, true);
}
finally
{
_IsDeserializing = false;
}

return new CollapseMiscSetting();
}
Expand Down
2 changes: 1 addition & 1 deletion CollapseLauncher/CollapseLauncher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
<PackageReference Include="Microsoft.Graphics.Win2D" Version="1.1.1" />
<PackageReference Include="Microsoft.NETCore.Platforms" Version="8.0.0-preview.7.23375.6" />
<PackageReference Include="Microsoft.NETCore.Targets" Version="6.0.0-preview.4.21253.7" />
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.6" />
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.7" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.2428" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.4.231219000" />
<PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" Version="2.0.9" />
Expand Down
8 changes: 4 additions & 4 deletions CollapseLauncher/XAMLs/MainApp/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ private void InitializeNavigationItems(bool ResetSelection = true)
{
case GameType.Honkai:
NavigationViewControl.MenuItems.Add(new NavigationViewItem()
{ Content = Lang._GameSettingsPage.PageTitle, Icon = IconGameSettings, Tag = "gamesettings" });
{ Content = Lang._GameSettingsPage.PageTitle, Icon = IconGameSettings, Tag = "honkaigamesettings" });
break;
case GameType.StarRail:
NavigationViewControl.MenuItems.Add(new NavigationViewItem()
Expand Down Expand Up @@ -1141,8 +1141,8 @@ void NavigateInnerSwitch(string itemTag)
Navigate(typeof(UnavailablePage), itemTag);
break;

case "gamesettings":
Navigate(IsGameInstalled() ? typeof(GameSettingsPage) : typeof(NotInstalledPage), itemTag);
case "honkaigamesettings":
Navigate(IsGameInstalled() ? typeof(HonkaiGameSettingsPage) : typeof(NotInstalledPage), itemTag);
break;

case "starrailgamesettings":
Expand Down Expand Up @@ -1726,7 +1726,7 @@ private void GoGameSettings_Invoked(KeyboardAccelerator sender, KeyboardAccelera
switch (CurrentGameProperty._GamePreset.GameType)
{
case GameType.Honkai:
Navigate(typeof(GameSettingsPage), "gamesettings");
Navigate(typeof(HonkaiGameSettingsPage), "honkaigamesettings");
break;
case GameType.Genshin:
Navigate(typeof(GenshinGameSettingsPage), "genshingamesettings");
Expand Down
Loading
Loading