Skip to content

Commit 488284f

Browse files
committed
Adding support for ZZZ audio file preload
+ Also fix a bug where the preload is not available for ZZZ
1 parent 1c557a1 commit 488284f

File tree

3 files changed

+145
-6
lines changed

3 files changed

+145
-6
lines changed

CollapseLauncher/Classes/GamePropertyVault.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ internal GamePresetProperty(UIElement UIElementParent, RegionResourceProp APIRes
6060
_GameSettings = new ZenlessSettings(_GameVersion);
6161
_GameCache = null;
6262
_GameRepair = null;
63-
_GameInstall = new ZenlessInstall(UIElementParent, _GameVersion);
63+
_GameInstall = new ZenlessInstall(UIElementParent, _GameVersion, _GameSettings as ZenlessSettings);
6464
break;
6565
default:
6666
throw new NotSupportedException($"[GamePresetProperty.Ctor] Game type: {GamePreset.GameType} ({GamePreset.ProfileName} - {GamePreset.ZoneName}) is not supported!");

CollapseLauncher/Classes/InstallManagement/BaseClass/InstallManagerBase.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3372,9 +3372,9 @@ protected virtual async ValueTask TryAddOtherInstalledVoicePacks(
33723372
if (TryGetVoiceOverResourceByLocaleCode(packs, localeCode, out RegionResourceVersion outRes))
33733373
{
33743374
// Check if the existing package is already exist or not.
3375-
RegionResourceVersion outResDup =
3376-
packs.FirstOrDefault(x => x.language != null &&
3377-
x.language.Equals(outRes.language,
3375+
GameInstallPackage outResDup =
3376+
packageList.FirstOrDefault(x => x.LanguageID != null &&
3377+
x.LanguageID.Equals(outRes.language,
33783378
StringComparison.OrdinalIgnoreCase));
33793379
if (outResDup != null)
33803380
{

CollapseLauncher/Classes/InstallManagement/Zenless/ZenlessInstall.cs

Lines changed: 141 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
using CollapseLauncher.GameSettings.Zenless;
2+
using CollapseLauncher.GameSettings.Zenless.Enums;
13
using CollapseLauncher.InstallManager.Base;
24
using CollapseLauncher.Interfaces;
35
using Microsoft.UI.Xaml;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.IO;
9+
using System.Linq;
410

511
// ReSharper disable GrammarMistakeInComment
612
// ReSharper disable CommentTypo
@@ -11,19 +17,151 @@
1117
// ReSharper disable InconsistentNaming
1218
// ReSharper disable ConvertToPrimaryConstructor
1319

20+
#nullable enable
1421
namespace CollapseLauncher.InstallManager.Zenless
1522
{
1623
internal class ZenlessInstall : InstallManagerBase
1724
{
25+
#region Private Properties
26+
private ZenlessSettings? ZenlessSettings { get; set; }
27+
#endregion
28+
1829
#region Override Properties
30+
protected override int _gameVoiceLanguageID
31+
{
32+
get => ZenlessSettings?.GeneralData?.DeviceLanguageVoiceType switch
33+
{
34+
LanguageVoice.zh_cn => 0,
35+
LanguageVoice.en_us => 1,
36+
LanguageVoice.ja_jp => 2,
37+
LanguageVoice.ko_kr => 3,
38+
LanguageVoice.Unset => 2, // Default to ja_jp
39+
_ => throw new NotSupportedException("Type of the language voice type is not valid!")
40+
};
41+
}
1942

43+
protected override string? _gameAudioLangListPath
44+
{
45+
get
46+
{
47+
// If the persistent folder is not exist, then return null
48+
if (!Directory.Exists(_gameDataPersistentPath))
49+
return null;
50+
51+
// Get the audio lang path index
52+
string audioLangPath = _gameAudioLangListPathStatic;
53+
return File.Exists(audioLangPath) ? audioLangPath : null;
54+
}
55+
}
56+
57+
private string? _gameAudioLangListPathAlternate
58+
{
59+
get
60+
{
61+
// If the persistent folder is not exist, then return null
62+
if (!Directory.Exists(_gameDataPersistentPath))
63+
return null;
64+
65+
// Get the audio lang path index
66+
string audioLangPath = _gameAudioLangListPathAlternateStatic;
67+
return File.Exists(audioLangPath) ? audioLangPath : null;
68+
}
69+
}
70+
71+
protected override string _gameAudioLangListPathStatic =>
72+
Path.Combine(_gameDataPersistentPath, "audio_lang_launcher");
73+
private string _gameAudioLangListPathAlternateStatic =>
74+
Path.Combine(_gameDataPersistentPath, "audio_lang");
2075
#endregion
2176

22-
public ZenlessInstall(UIElement parentUI, IGameVersionCheck GameVersionManager)
77+
public ZenlessInstall(UIElement parentUI, IGameVersionCheck GameVersionManager, ZenlessSettings zenlessSettings)
2378
: base(parentUI, GameVersionManager)
2479
{
80+
ZenlessSettings = zenlessSettings;
81+
}
82+
83+
#region Override Methods - Audio Lang List
84+
protected override void WriteAudioLangList(List<GameInstallPackage> gamePackage)
85+
{
86+
// Run the writing method from the base first
87+
base.WriteAudioLangList(gamePackage);
88+
89+
// Then create the one from the alternate one
90+
// Read all the existing list
91+
List<string> langList = File.Exists(_gameAudioLangListPathAlternateStatic)
92+
? File.ReadAllLines(_gameAudioLangListPathAlternateStatic).ToList()
93+
: [];
94+
95+
// Try lookup if there is a new language list, then add it to the list
96+
foreach (GameInstallPackage package in
97+
_assetIndex.Where(x => x.PackageType == GameInstallPackageType.Audio))
98+
{
99+
string langString = GetLanguageStringByLocaleCodeAlternate(package.LanguageID);
100+
if (!langList.Contains(langString, StringComparer.OrdinalIgnoreCase))
101+
{
102+
langList.Add(langString);
103+
}
104+
}
105+
106+
// Create the audio lang list file
107+
using StreamWriter sw = new StreamWriter(_gameAudioLangListPathAlternateStatic,
108+
new FileStreamOptions
109+
{ Mode = FileMode.Create, Access = FileAccess.Write });
110+
// Iterate the package list
111+
foreach (string langString in langList)
112+
{
113+
// Write the language string as per ID
114+
sw.WriteLine(langString);
115+
}
25116
}
26117

118+
protected override void WriteAudioLangListSophon(List<string> sophonVOList)
119+
{
120+
// Run the writing method from the base first
121+
base.WriteAudioLangListSophon(sophonVOList);
122+
123+
// Then create the one from the alternate one
124+
// Read all the existing list
125+
List<string> langList = File.Exists(_gameAudioLangListPathAlternateStatic)
126+
? File.ReadAllLines(_gameAudioLangListPathAlternateStatic).ToList()
127+
: [];
128+
129+
// Try lookup if there is a new language list, then add it to the list
130+
for (int index = 0; index < sophonVOList.Count; index++)
131+
{
132+
var packageLocaleCodeString = sophonVOList[index];
133+
string langString = GetLanguageStringByLocaleCodeAlternate(packageLocaleCodeString);
134+
if (!langList.Contains(langString, StringComparer.OrdinalIgnoreCase))
135+
{
136+
langList.Add(langString);
137+
}
138+
}
139+
140+
// Create the audio lang list file
141+
using var sw = new StreamWriter(_gameAudioLangListPathAlternateStatic,
142+
new FileStreamOptions
143+
{ Mode = FileMode.Create, Access = FileAccess.Write });
144+
// Iterate the package list
145+
foreach (var voIds in langList)
146+
// Write the language string as per ID
147+
{
148+
sw.WriteLine(voIds);
149+
}
150+
}
151+
152+
private string GetLanguageStringByLocaleCodeAlternate(string localeCode)
153+
{
154+
return localeCode switch
155+
{
156+
"zh-cn" => "Cn",
157+
"en-us" => "En",
158+
"ja-jp" => "Jp",
159+
"ko-kr" => "Kr",
160+
_ => throw new KeyNotFoundException($"Alternate locale code: {localeCode} is not supported!")
161+
};
162+
}
163+
#endregion
164+
27165
#region Override Methods - UninstallGame
28166

29167
protected override UninstallGameProperty AssignUninstallFolders()
@@ -43,4 +181,5 @@ protected override UninstallGameProperty AssignUninstallFolders()
43181

44182
#endregion
45183
}
46-
}
184+
}
185+
#nullable restore

0 commit comments

Comments
 (0)