Skip to content

Commit bd26158

Browse files
committed
Refactor Hi3 CG metadata parser
+ Reduce check time for CG files as it should parse the CG category correctly
1 parent f87ef76 commit bd26158

3 files changed

Lines changed: 30 additions & 29 deletions

File tree

CollapseLauncher/Classes/RepairManagement/HonkaiV2/HonkaiRepairV2.AsbExt.Video.cs

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using Hi3Helper.Data;
66
using Hi3Helper.EncTool;
77
using Hi3Helper.EncTool.Parser.AssetMetadata;
8-
using Hi3Helper.EncTool.Parser.Cache;
8+
using Hi3Helper.EncTool.Parser.CacheParser;
99
using Hi3Helper.EncTool.Parser.KianaDispatch;
1010
using Hi3Helper.Preset;
1111
using Hi3Helper.Shared.ClassStruct;
@@ -14,12 +14,9 @@
1414
using System.IO;
1515
using System.Linq;
1616
using System.Net.Http;
17-
using System.Text;
1817
using System.Threading;
1918
using System.Threading.Tasks;
2019

21-
using CGMetadataHashId = Hi3Helper.EncTool.Parser.Cache.HashID;
22-
2320
// ReSharper disable CheckNamespace
2421
// ReSharper disable IdentifierTypo
2522
// ReSharper disable StringLiteralTypo
@@ -32,6 +29,7 @@ namespace CollapseLauncher.RepairManagement;
3229
internal static partial class AssetBundleExtension
3330
{
3431
internal const string RelativePathVideo = @"BH3_Data\StreamingAssets\Video\";
32+
internal const string MetadataFilename = "107438912";
3533

3634
internal static async Task<List<FilePropertiesRemote>>
3735
GetVideoAssetListAsync<T>(
@@ -57,11 +55,11 @@ await GetCacheAssetBundleListAsync(assetBundleHttpClient,
5755
token);
5856

5957
CacheAssetInfo? cgMetadataFile = assetInfoList
60-
.FirstOrDefault(x => x.Asset.N.EndsWith(CGMetadataHashId.CgMetadataFilename));
58+
.FirstOrDefault(x => x.Asset.N.EndsWith(MetadataFilename));
6159

6260
if (cgMetadataFile == null)
6361
{
64-
Logger.LogWriteLine($"[AssetBundleExtension::GetVideoAssetListAsync] Cannot find CG Metadata file with Asset ID: {CGMetadataHashId.CgMetadataFilename}",
62+
Logger.LogWriteLine($"[AssetBundleExtension::GetVideoAssetListAsync] Cannot find CG Metadata file with Asset ID: {MetadataFilename}",
6563
LogType.Error,
6664
true);
6765
return [];
@@ -83,11 +81,11 @@ await GetCacheAssetBundleListAsync(assetBundleHttpClient,
8381
cgFileStreamMemory.Position = 0;
8482

8583
await using CacheStream dechipheredCgStream =
86-
new CacheStream(cgFileStreamMemory, preSeed: cgMetadataFile.MhyMersenneTwisterSeed);
84+
new(cgFileStreamMemory, preSeed: cgMetadataFile.MhyMersenneTwisterSeed);
8785

8886
List<FilePropertiesRemote> cgEntries = [];
8987
await Parallel
90-
.ForEachAsync(CGMetadata.Enumerate(dechipheredCgStream, Encoding.UTF8),
88+
.ForEachAsync(KianaCgMetadata.Parse(dechipheredCgStream),
9189
new ParallelOptions
9290
{
9391
CancellationToken = token,
@@ -97,22 +95,22 @@ await Parallel
9795

9896
return cgEntries;
9997

100-
async ValueTask ImplCheckAndAdd(CGMetadata entry, CancellationToken innerToken)
98+
async ValueTask ImplCheckAndAdd(KeyValuePair<int, KianaCgMetadata> entry, CancellationToken innerToken)
10199
{
102-
if (entry.InStreamingAssets ||
103-
ignoredCgHashset.Contains(entry.CgSubCategory))
100+
if (entry.Value.DownloadMode == CGDownloadMode.DownloadTipAlways ||
101+
ignoredCgHashset.Contains(entry.Value.SubCategoryId))
104102
{
105103
return;
106104
}
107105

108-
string assetName = gameLanguageType == AudioLanguageType.Japanese
109-
? entry.CgPathHighBitrateJP
110-
: entry.CgPathHighBitrateCN;
106+
string assetName = (gameLanguageType == AudioLanguageType.Japanese
107+
? entry.Value.PathJp
108+
: entry.Value.PathCn) ?? throw new NullReferenceException();
111109
assetName += ".usm";
112110

113111
long assetFilesize = gameLanguageType == AudioLanguageType.Japanese
114-
? entry.FileSizeHighBitrateJP
115-
: entry.FileSizeHighBitrateCN;
112+
? entry.Value.SizeJp
113+
: entry.Value.SizeCn;
116114

117115
foreach (string baseUrl in gameServerInfo.ExternalAssetUrls)
118116
{
@@ -130,23 +128,26 @@ async ValueTask ImplCheckAndAdd(CGMetadata entry, CancellationToken innerToken)
130128
// Update status
131129
if (progressibleInstance != null)
132130
{
133-
progressibleInstance.Status.ActivityStatus = string.Format(Locale.Current.Lang?._GameRepairPage?.Status14 ?? "", entry.CgExtraKey);
131+
progressibleInstance.Status.ActivityStatus = string.Format(Locale.Current.Lang?._GameRepairPage?.Status14 ?? "", assetName);
134132
progressibleInstance.Status.IsProgressAllIndetermined = true;
135133
progressibleInstance.Status.IsProgressPerFileIndetermined = true;
136134
progressibleInstance.UpdateStatus();
137135
}
138136

139-
UrlStatus urlStatus = await assetBundleHttpClient.GetURLStatusCode(assetUrl, innerToken);
140-
Logger.LogWriteLine($"The CG asset: {assetName} " +
141-
(urlStatus.IsSuccessStatusCode ? "is" : "is not") + $" available (Status code: {urlStatus.StatusCode})", LogType.Default, true);
142-
if (!urlStatus.IsSuccessStatusCode)
137+
if (entry.Value.Category is CGCategory.Birthday or CGCategory.Activity or CGCategory.VersionPV)
143138
{
144-
continue;
145-
}
139+
UrlStatus urlStatus = await assetBundleHttpClient.GetURLStatusCode(assetUrl, innerToken);
140+
Logger.LogWriteLine($"The CG asset: {assetName} " +
141+
(urlStatus.IsSuccessStatusCode ? "is" : "is not") + $" available (Status code: {urlStatus.StatusCode})", LogType.Default, true);
142+
if (!urlStatus.IsSuccessStatusCode)
143+
{
144+
continue;
145+
}
146146

147-
if (urlStatus.FileSize > 0)
148-
{
149-
assetFilesize = urlStatus.FileSize;
147+
if (urlStatus.FileSize > 0)
148+
{
149+
assetFilesize = urlStatus.FileSize;
150+
}
150151
}
151152

152153
lock (cgEntries)

CollapseLauncher/Classes/RepairManagement/HonkaiV2/HonkaiRepairV2.Fetch.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using Hi3Helper.Data;
66
using Hi3Helper.EncTool;
77
using Hi3Helper.EncTool.Parser.AssetMetadata;
8-
using Hi3Helper.EncTool.Parser.Cache;
8+
using Hi3Helper.EncTool.Parser.CacheParser;
99
using Hi3Helper.EncTool.Parser.KianaDispatch;
1010
using Hi3Helper.EncTool.Parser.Senadina;
1111
using Hi3Helper.Shared.ClassStruct;
@@ -276,7 +276,7 @@ private void FinalizeVideoAssetsPath(List<FilePropertiesRemote> assetList)
276276
{
277277
string relativePath = Path.Combine(AssetBundleExtension.RelativePathVideo, asset.N);
278278
ConverterTool.NormalizePathInplaceNoTrim(relativePath);
279-
if (asset.AssociatedObject is CGMetadata { InStreamingAssets: false })
279+
if (asset.AssociatedObject is KianaCgMetadata { DownloadMode: CGDownloadMode.DownloadTipAlways })
280280
{
281281
versionStreamWriter.WriteLine($"Video/{asset.N}\t1");
282282
}

0 commit comments

Comments
 (0)