Skip to content

Commit

Permalink
[Big Changes] Switch to MetadataV3
Browse files Browse the repository at this point in the history
  • Loading branch information
neon-nyan committed Apr 3, 2024
1 parent 6228e4d commit e7c8d7f
Show file tree
Hide file tree
Showing 63 changed files with 1,798 additions and 1,147 deletions.
29 changes: 17 additions & 12 deletions CollapseLauncher/Classes/CachesManagement/Honkai/Fetch.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CollapseLauncher.Interfaces;
using CollapseLauncher.Helper.Metadata;
using CollapseLauncher.Interfaces;
using Hi3Helper;
using Hi3Helper.EncTool;
using Hi3Helper.EncTool.Parser.KianaDispatch;
Expand All @@ -14,7 +15,6 @@
using static Hi3Helper.Data.ConverterTool;
using static Hi3Helper.Locale;
using static Hi3Helper.Logger;
using static Hi3Helper.Preset.ConfigV2Store;

namespace CollapseLauncher
{
Expand Down Expand Up @@ -86,15 +86,9 @@ private async Task BuildGameRepoURL(CancellationToken token)
try
{
// Init the key and decrypt it if exist.
string key = null;
if (_gameVersionManager.GamePreset.DispatcherKey != null)
{
mhyEncTool Decryptor = new mhyEncTool();
Decryptor.InitMasterKey(ConfigV2!.MasterKey, ConfigV2.MasterKeyBitLength, RSAEncryptionPadding.Pkcs1);

key = _gameVersionManager.GamePreset.DispatcherKey;
Decryptor.DecryptStringWithMasterKey(ref key);
}
if (string.IsNullOrEmpty(_gameVersionManager.GamePreset.DispatcherKey))
throw new NullReferenceException($"Dispatcher key is null or empty!");
string key = _gameVersionManager.GamePreset.DispatcherKey;

// Try assign dispatcher
dispatch = await KianaDispatch.GetDispatch(baseURL, _gameVersionManager.GamePreset.GameDispatchURLTemplate, _gameVersionManager.GamePreset.GameDispatchChannelName, key, _gameVersion.VersionArray, token);
Expand Down Expand Up @@ -239,7 +233,18 @@ private void BuildDataPatchConfig(MemoryStream stream, List<CacheAsset> assetInd
private byte[] GetAssetIndexSalt(string data)
{
// Get the salt from the string and return as byte[]
mhyEncTool saltTool = new mhyEncTool(data, ConfigV2!.MasterKey);
byte[] key;
if (DataCooker.IsServeV3Data(LauncherMetadataHelper.CurrentMasterKey.Key))

Check warning on line 237 in CollapseLauncher/Classes/CachesManagement/Honkai/Fetch.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Possible 'System.NullReferenceException'

Possible 'System.NullReferenceException'
{
DataCooker.GetServeV3DataSize(LauncherMetadataHelper.CurrentMasterKey.Key, out long keyCompSize, out long keyDecompSize);
key = new byte[keyCompSize];
DataCooker.ServeV3Data(LauncherMetadataHelper.CurrentMasterKey.Key, key, (int)keyCompSize, (int)keyDecompSize, out _);
}
else
{
key = LauncherMetadataHelper.CurrentMasterKey.Key;
}
mhyEncTool saltTool = new mhyEncTool(data, key);
return saltTool.GetSalt();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ private async Task<bool> CheckRoutine()

// Reset status and progress
// ResetStatusAndProgress();
_token = new CancellationTokenSourceWrapper();

// Step 1: Fetch asset indexes
_assetIndex = await Fetch(_token!.Token);
Expand Down
13 changes: 10 additions & 3 deletions CollapseLauncher/Classes/ClassesContext.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
using CollapseLauncher.Interfaces;
using CollapseLauncher.Helper.Metadata;
using CollapseLauncher.Interfaces;
using Hi3Helper.EncTool.Parser.AssetMetadata;
using Hi3Helper.Shared.ClassStruct;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace CollapseLauncher
{
[JsonSourceGenerationOptions(IncludeFields = false, GenerationMode = JsonSourceGenerationMode.Metadata, IgnoreReadOnlyFields = true)]
// [JsonSourceGenerationOptions(IncludeFields = false, GenerationMode = JsonSourceGenerationMode.Metadata, IgnoreReadOnlyFields = true)]
[JsonSerializable(typeof(RegionResourcePluginValidate))]
[JsonSerializable(typeof(CommunityToolsProperty))]
[JsonSerializable(typeof(AppUpdateVersionProp))]
[JsonSerializable(typeof(RegionResourceProp))]
[JsonSerializable(typeof(NotificationPush))]
[JsonSerializable(typeof(CacheAsset))]
[JsonSerializable(typeof(GeneralDataProp))]
[JsonSerializable(typeof(MasterKeyConfig))]
[JsonSerializable(typeof(AudioPCKType[]))]
[JsonSerializable(typeof(PresetConfig))]
[JsonSerializable(typeof(List<Stamp>))]
[JsonSerializable(typeof(CacheAsset))]
[JsonSerializable(typeof(BHI3LInfo))]
[JsonSerializable(typeof(int[]))]
internal sealed partial class InternalAppJSONContext : JsonSerializerContext;
}
1 change: 0 additions & 1 deletion CollapseLauncher/Classes/CoCreateInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

#pragma warning disable IL2050
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#if !DISABLEDISCORD
using CollapseLauncher.Helper.Metadata;
using DiscordRPC;
using Hi3Helper.Preset;
using Hi3Helper;
using System;
using static Hi3Helper.Locale;
using static Hi3Helper.Shared.Region.LauncherConfig;

namespace Hi3Helper.DiscordPresence
namespace CollapseLauncher.DiscordPresence
{
#region Enums
public enum ActivityType
Expand All @@ -21,7 +22,6 @@ public enum ActivityType
}
#endregion


public class DiscordPresenceManager : IDisposable
{
#region Properties
Expand Down Expand Up @@ -231,12 +231,12 @@ private void BuildActivityGameStatus(string activityName, bool isGameStatusEnabl
{
_presence = new RichPresence
{
Details = $"{activityName} {(!isGameStatusEnabled ? ConfigV2Store.CurrentConfigV2GameCategory : null)}",
State = $"{Lang._Misc.DiscordRP_Region} {ConfigV2Store.CurrentConfigV2GameRegion}",
Details = $"{activityName} {(!isGameStatusEnabled ? LauncherMetadataHelper.CurrentMetadataConfigGameName : null)}",
State = $"{Lang._Misc.DiscordRP_Region} {LauncherMetadataHelper.CurrentMetadataConfigGameRegion}",
Assets = new Assets
{
LargeImageKey = $"game-{ConfigV2Store.CurrentConfigV2.GameType.ToString().ToLower()}-logo",
LargeImageText = $"{ConfigV2Store.CurrentConfigV2GameCategory} - {ConfigV2Store.CurrentConfigV2GameRegion}",
LargeImageKey = $"game-{LauncherMetadataHelper.CurrentMetadataConfig.GameType.ToString().ToLower()}-logo",

Check warning on line 238 in CollapseLauncher/Classes/DiscordPresence/DiscordPresenceManager.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Possible 'System.NullReferenceException'

Possible 'System.NullReferenceException'
LargeImageText = $"{LauncherMetadataHelper.CurrentMetadataConfigGameName} - {LauncherMetadataHelper.CurrentMetadataConfigGameRegion}",
SmallImageKey = "launcher-logo",
SmallImageText = $"Collapse Launcher v{AppCurrentVersionString} {(IsPreview ? "Preview" : "Stable")}"
},
Expand All @@ -258,11 +258,11 @@ private void BuildActivityAppStatus(string activityName)
_presence = new RichPresence()
{
Details = activityName,
State = $"{Lang._Misc.DiscordRP_Region} {ConfigV2Store.CurrentConfigV2GameRegion}",
State = $"{Lang._Misc.DiscordRP_Region} {LauncherMetadataHelper.CurrentMetadataConfigGameRegion}",
Assets = new Assets
{
LargeImageKey = $"game-{ConfigV2Store.CurrentConfigV2.GameType.ToString().ToLower()}-logo",
LargeImageText = $"{ConfigV2Store.CurrentConfigV2GameCategory}",
LargeImageKey = $"game-{LauncherMetadataHelper.CurrentMetadataConfig.GameType.ToString().ToLower()}-logo",

Check warning on line 264 in CollapseLauncher/Classes/DiscordPresence/DiscordPresenceManager.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Possible 'System.NullReferenceException'

Possible 'System.NullReferenceException'
LargeImageText = $"{LauncherMetadataHelper.CurrentMetadataConfigGameName}",
SmallImageKey = "launcher-logo",
SmallImageText = $"Collapse Launcher v{AppCurrentVersionString} {(IsPreview ? "Preview" : "Stable")}"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using CollapseLauncher.Extension;
using CollapseLauncher.Helper.Metadata;
using CollapseLauncher.Interfaces;
using CollapseLauncher.Statics;
using Hi3Helper;
using Hi3Helper.Data;
using Hi3Helper.Preset;
using Hi3Helper.Shared.Region;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
Expand Down Expand Up @@ -92,10 +92,10 @@ private static void AttachEventToNotification(int hashID, IBackgroundActivity ac
{
Source = new BitmapImage(new Uri(CurrentGameProperty!._GameVersion!.GameType switch
{
GameType.Honkai => "ms-appx:///Assets/Images/GameLogo/honkai-logo.png",
GameType.Genshin => "ms-appx:///Assets/Images/GameLogo/genshin-logo.png",
GameType.StarRail => "ms-appx:///Assets/Images/GameLogo/starrail-logo.png",
GameType.Zenless => "ms-appx:///Assets/Images/GameLogo/zenless-logo.png",
GameNameType.Honkai => "ms-appx:///Assets/Images/GameLogo/honkai-logo.png",
GameNameType.Genshin => "ms-appx:///Assets/Images/GameLogo/genshin-logo.png",
GameNameType.StarRail => "ms-appx:///Assets/Images/GameLogo/starrail-logo.png",
GameNameType.Zenless => "ms-appx:///Assets/Images/GameLogo/zenless-logo.png",
_ => "ms-appx:///Assets/Images/GameMascot/PaimonWhat.png"
}))
}.WithWidthAndHeight(64));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using CollapseLauncher.Interfaces;
using Hi3Helper.Preset;
using CollapseLauncher.Helper.Metadata;
using CollapseLauncher.Interfaces;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -66,7 +66,7 @@ public Preset(string presetJSONPath, TObjectType jsonContext)
/// <param name="gameType">The type of the game</param>
/// <param name="jsonContext">JSON source generation context</param>
/// <returns>The instance of preset</returns>
public static Preset<T1, TObjectType> LoadPreset(GameType gameType, TObjectType jsonContext)
public static Preset<T1, TObjectType> LoadPreset(GameNameType gameType, TObjectType jsonContext)
{
string presetPath = Path.Combine(AppFolder, $"Assets\\Presets\\{gameType}\\", $"{typeof(T1).Name}.json");
return new Preset<T1, TObjectType>(presetPath, jsonContext);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using CollapseLauncher.GameSettings.Base;
using CollapseLauncher.GameSettings.Honkai.Context;
using CollapseLauncher.GameSettings.Universal;
using CollapseLauncher.Helper.Metadata;
using CollapseLauncher.Interfaces;
using Hi3Helper.Preset;
using Microsoft.Win32;
using System.IO;
// ReSharper disable PossibleNullReferenceException
Expand Down Expand Up @@ -56,7 +56,7 @@ private void InitializeSettings()
SettingsCollapseMisc = CollapseMiscSetting.Load();

// Load Preset
Preset_SettingsGraphics = Preset<PersonalGraphicsSettingV2, HonkaiSettingsJSONContext>.LoadPreset(GameType.Honkai, HonkaiSettingsJSONContext.Default);
Preset_SettingsGraphics = Preset<PersonalGraphicsSettingV2, HonkaiSettingsJSONContext>.LoadPreset(GameNameType.Honkai, HonkaiSettingsJSONContext.Default);
}

public void ReloadSettings() => InitializeSettings();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using CollapseLauncher.Helper.Metadata;
using CollapseLauncher.Interfaces;
using Hi3Helper.Data;
using Hi3Helper.Preset;
using Hi3Helper.Shared.ClassStruct;
using Hi3Helper.Shared.Region;
using Microsoft.UI.Xaml;
Expand All @@ -20,8 +20,8 @@ internal class GameVersionBase : IGameVersionCheck
private const string _defaultIniVersionSection = "General";
private string _defaultGameDirPath { get => Path.Combine(LauncherConfig.AppGameFolder, GamePreset.ProfileName, GamePreset.GameDirectoryName); }

Check warning on line 21 in CollapseLauncher/Classes/GameManagement/GameVersion/BaseClass/GameVersionBase.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Possible 'null' assignment to non-nullable entity

Possible 'null' assignment to non-nullable entity

Check warning on line 21 in CollapseLauncher/Classes/GameManagement/GameVersion/BaseClass/GameVersionBase.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Possible 'null' assignment to non-nullable entity

Possible 'null' assignment to non-nullable entity

private int gameChannelID => GamePreset.ChannelID;
private int gameSubChannelID => GamePreset.SubChannelID;
private int gameChannelID => GamePreset.ChannelID ?? 0;
private int gameSubChannelID => GamePreset.SubChannelID ?? 0;

private IniSection _defaultIniProfile
{
Expand Down Expand Up @@ -90,9 +90,9 @@ protected string GameIniVersionPath
}
protected string GameConfigDirPath { get; set; }
public GameVersionBase AsVersionBase => this;
public PresetConfigV2 GamePreset { get; set; }
public PresetConfig GamePreset { get; set; }
public RegionResourceProp GameAPIProp { get; set; }
public GameType GameType => GamePreset.GameType;
public GameNameType GameType => GamePreset.GameType;
public GameVendorProp VendorTypeProp { get; private set; }
public string GameDirPath
{
Expand All @@ -111,8 +111,8 @@ public string GameOutputLogName
{
get => GameType switch
{
GameType.Genshin => "output_log.txt",
GameType.Honkai => "output_log.txt",
GameNameType.Genshin => "output_log.txt",
GameNameType.Honkai => "output_log.txt",
_ => "Player.log"
};
}
Expand Down Expand Up @@ -206,7 +206,7 @@ protected Dictionary<int, GameVersion> PluginVersionsInstalled
protected DeltaPatchProperty GameDeltaPatchProp { get => CheckDeltaPatchUpdate(GameDirPath, GamePreset.ProfileName, GameVersionAPI); }
#endregion

protected GameVersionBase(UIElement parentUIElement, RegionResourceProp gameRegionProp, PresetConfigV2 gamePreset)
protected GameVersionBase(UIElement parentUIElement, RegionResourceProp gameRegionProp, PresetConfig gamePreset)
{
GamePreset = gamePreset;
ParentUIElement = parentUIElement;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using CollapseLauncher.Interfaces;
using Hi3Helper.Preset;
using CollapseLauncher.Helper.Metadata;
using CollapseLauncher.Interfaces;
using Microsoft.UI.Xaml;
using System.Collections.Generic;

Expand All @@ -11,7 +11,7 @@ internal class GameTypeGenshinVersion : GameVersionBase, IGameVersionCheck
public readonly List<string> _audioVoiceLanguageList = new List<string> { "Chinese", "English(US)", "Japanese", "Korean" };
#endregion

public GameTypeGenshinVersion(UIElement parentUIElement, RegionResourceProp gameRegionProp, PresetConfigV2 gamePreset)
public GameTypeGenshinVersion(UIElement parentUIElement, RegionResourceProp gameRegionProp, PresetConfig gamePreset)
: base(parentUIElement, gameRegionProp, gamePreset)
{
// Try check for reinitializing game version.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using CollapseLauncher.Helper.Metadata;
using CollapseLauncher.Interfaces;
using Hi3Helper.Preset;
using Microsoft.UI.Xaml;
using System;

Expand All @@ -17,7 +17,7 @@ internal class GameTypeHonkaiVersion : GameVersionBase, IGameVersionCheck
public bool IsPreloadSenadinaVersion { get => GameVersionAPIPreload.HasValue ? GameVersionAPIPreload.Value.ToVersion() >= senadinaVersion : false; }
#endregion

public GameTypeHonkaiVersion(UIElement parentUIElement, RegionResourceProp gameRegionProp, PresetConfigV2 gamePreset)
public GameTypeHonkaiVersion(UIElement parentUIElement, RegionResourceProp gameRegionProp, PresetConfig gamePreset)
: base(parentUIElement, gameRegionProp, gamePreset)
{
// Try check for reinitializing game version from XMF file.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using CollapseLauncher.Interfaces;
using CollapseLauncher.Helper.Metadata;
using CollapseLauncher.Interfaces;
using Hi3Helper.EncTool.Parser.AssetMetadata;
using Hi3Helper.EncTool.Proto.StarRail;
using Hi3Helper.Preset;
using Microsoft.UI.Xaml;
using System.Text;

Expand All @@ -13,7 +13,7 @@ internal class GameTypeStarRailVersion : GameVersionBase, IGameVersionCheck
public SRMetadata StarRailMetadataTool { get; set; }
#endregion

public GameTypeStarRailVersion(UIElement parentUIElement, RegionResourceProp gameRegionProp, PresetConfigV2 gamePreset)
public GameTypeStarRailVersion(UIElement parentUIElement, RegionResourceProp gameRegionProp, PresetConfig gamePreset)
: base(parentUIElement, gameRegionProp, gamePreset)
{
// Try check for reinitializing game version.
Expand Down
Loading

0 comments on commit e7c8d7f

Please sign in to comment.