Skip to content

Commit

Permalink
[Feature] Pre-Launch and Post-Exit Commands Launching (#398)
Browse files Browse the repository at this point in the history
* Update CsWinRT

This PR adds ability to run command before and after the game exits, values are saved to `CollapseSettings_Misc` registry on each region keys.

Command outputs recorded in the console, and it WILL NOT be interactable from the console. Also supports running GUI applications.

2.0.6 -> 2.0.7
https://github.com/microsoft/CsWinRT/releases/tag/2.0.7.240207.1

* (GSP) Move all GSPs into its own folder

Getting crowded up there on Pages main dir

* (GLC) Introduce GameLaunchCommand Backend

* Defer StarRail unnecesarry settings load on region load

* Avoid unnecessary UniversalGameSettings call on GameRunningWatcher

* (GLC) Introduce prototype in HSR GSP

* (GLC) Fix title

* (GLC) Backend Changes

- Rename PostLaunch to PostExit to better reflect the function
- Skip GLC if provided string is empty
- Change GLC console tag color to light red
- Adjust ErrorSender message
- Make consoleWidth and barwidth
available for private use
- Move `GAME STOPPED` bar into GameRunningWatcher
- Remove unused Window Restore inside ReadOutputLog (already available in GameRunningWatcher

* (GLC) Localization!

* (GLC) Frontends!

This also fixes warnings about OneWay bindings (WMC1506) for Genshin and StarRail GSPs by implementing INotifyPropertyChanged in the Ext

* (GLC) Fix main toggle margin and style

* (GSP) Fix HSR Character Quality selector

The enum is weird...

* (GSP) HSR: Disable VSync when selecting 120FPS

* Fix typos and CodeQA

* (GLC) Sanitize command for escape

Co-authored-by: Shatyuka <958182453@qq.com>

* Remove CsWinRT as its not needed anymore

Code generated is already on CoCreateInstance.cs

i forgor

* (GSP) HSR: Fix CharQual enum values

- Also renamed the enum name to avoid confusion
- Also clamped the values to avoid IndexOutOfRangeException

Co-authored-by: Kemal Setya Adhi <dev.kemalsetyaa@gmail.com>

* [skip ci] (GSP) HSR: Adjust CharQ summary

* (GLC) Honkai: Fix panel not collapsing when disabled

---------

Co-authored-by: Shatyuka <958182453@qq.com>
Co-authored-by: Kemal Setya Adhi <dev.kemalsetyaa@gmail.com>
  • Loading branch information
3 people authored Feb 14, 2024
1 parent b5fe4bc commit c9dfe14
Show file tree
Hide file tree
Showing 25 changed files with 3,723 additions and 1,728 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ public enum AntialiasingMode // TypeDefIndex: 25409
TAA = 1,
FXAA = 2
}

public enum CharacterQualityEnum
{
Low = 2,
Medium = 3,
High = 4
}
#endregion

internal class Model : IGameSettingsValue<Model>
Expand Down Expand Up @@ -97,7 +104,7 @@ private static Dictionary<int, int> GenerateStaticFPSIndexDict()
/// Options: Low (2), Medium(3), High(4)
/// Default: Medium
/// </summary>
public Quality CharacterQuality { get; set; } = Quality.Medium;
public CharacterQualityEnum CharacterQuality { get; set; } = CharacterQualityEnum.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
1 change: 0 additions & 1 deletion CollapseLauncher/CollapseLauncher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@
<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.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

0 comments on commit c9dfe14

Please sign in to comment.