Skip to content

Commit 54ab8fd

Browse files
committed
fix: 音频导入全面修复 + 游戏 OPT 结构完善
音频: - 用 XV2-Tools 的 ConvertStream.ConvertFile 替代 VGAudio NuGet 的 HcaWriter - 用 ACB_File + ACB_Wrapper 正确生成 ACB+AWB 对 - 去掉 VGAudio NuGet 包, 统一用 LB_Common 内置版本 - 添加 YAXLib 2.15.0 依赖 游戏 OPT 结构: - 生成 CueFile.xml / Event.xml / ReleaseTag.xml / MusicSort.xml - Event.xml 支持追加多曲目, 删除时移除 - MusicSort.xml 同步追加/移除 - Music.xml 格式对齐官方 (type/data, artistName/id, cueFileName/id 等) 封面: - DDS 格式改为 BC1 (DXT1), 和官方一致 - 尺寸自动对齐 4 的倍数 - ConvertDdsToPng 不翻转 (官方 DDS 是 top-down) - 封面文件名改为 D4 (CHU_UI_Jacket_XXXX.dds) 导入: - C2S header 修正 (VERSION/MUSIC/SEQUENCEID/DIFFICULT) - ImportMusicExecute 参数 nullable 化 + SuppressModelStateInvalidFilter - Kestrel MaxRequestBodySize 取消限制 - isA000 改用 selectedSource 判断 - 导入目标 Option 默认当前选择 - ImportMusicCheck 返回等级/难度/作者信息 其他: - 播放器: 去掉双击播放, 切换 source 停止播放 - LB_Common alias 改为 global,LBCommon
1 parent 9b0115f commit 54ab8fd

10 files changed

Lines changed: 336 additions & 131 deletions

File tree

ChuChartManager/AudioHelper.cs

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
using VGAudio.Codecs.CriHca;
66
using VGAudio.Containers.Hca;
77
using VGAudio.Containers.Wave;
8+
using VGAudio.Cli;
9+
using Xv2CoreLib.ACB;
810

911
namespace ChuChartManager;
1012

@@ -170,14 +172,13 @@ public static void ExportMp3(byte[] wavData, string outputPath)
170172
wavStream.CopyTo(mp3Writer);
171173
}
172174

175+
private const ulong ChuniHcaKey = 32931609366120192;
176+
173177
public static byte[]? EncodeWavToHca(byte[] wavData)
174178
{
175-
var waveReader = new VGAudio.Containers.Wave.WaveReader();
176-
var audioData = waveReader.Read(wavData);
177-
178-
var hcaWriter = new HcaWriter();
179-
hcaWriter.Configuration.EncryptionKey = Keys[0];
180-
return hcaWriter.GetFile(audioData);
179+
using var wavStream = new MemoryStream(wavData);
180+
var options = new Options { KeyCode = ChuniHcaKey };
181+
return ConvertStream.ConvertFile(options, wavStream, FileType.Wave, FileType.Hca);
181182
}
182183

183184
public static void ImportAudioToMusic(MusicXml music, string audioPath)
@@ -201,29 +202,25 @@ public static void ImportAudioToMusic(MusicXml music, string audioPath)
201202
if (hcaBytes == null || hcaBytes.Length == 0)
202203
throw new InvalidOperationException("Failed to encode audio to HCA");
203204

204-
var hcaTempPath = Path.Combine(Path.GetTempPath(), $"ccm_hca_{Guid.NewGuid():N}.hca");
205-
try
206-
{
207-
File.WriteAllBytes(hcaTempPath, hcaBytes);
205+
var sourceRoot = Path.GetDirectoryName(Path.GetDirectoryName(music.MusicDirectory));
206+
if (sourceRoot == null) throw new InvalidOperationException("Cannot determine option root");
208207

209-
var sourceRoot = Path.GetDirectoryName(Path.GetDirectoryName(music.MusicDirectory));
210-
if (sourceRoot == null) throw new InvalidOperationException("Cannot determine option root");
208+
var cueFileName = $"music{music.Id:D4}";
209+
var cueFileDir = Path.Combine(sourceRoot, "cueFile", $"cueFile{music.Id:D6}");
210+
Directory.CreateDirectory(cueFileDir);
211211

212-
var cueFileName = $"music{music.Id:D4}";
213-
var cueFileDir = Path.Combine(sourceRoot, "cueFile", $"cueFile{music.Id:D6}");
214-
Directory.CreateDirectory(cueFileDir);
215-
var awbPath = Path.Combine(cueFileDir, $"{cueFileName}.awb");
212+
RepackAcbWithHca(cueFileDir, cueFileName, hcaBytes);
213+
}
216214

217-
var archive = new CriAfs2Archive();
218-
archive.Add(new CriAfs2Entry { Id = 0, FilePath = new FileInfo(hcaTempPath) });
215+
public static void RepackAcbWithHca(string cueFileDir, string cueFileName, byte[] hcaBytes)
216+
{
217+
var acbTemplatePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", "template_music.acb");
218+
var acbSavePath = Path.Combine(cueFileDir, $"{cueFileName}.acb");
219219

220-
using var awbStream = File.Create(awbPath);
221-
archive.Write(awbStream);
222-
}
223-
finally
224-
{
225-
try { File.Delete(hcaTempPath); } catch { }
226-
}
220+
var acbTemplate = ACB_File.Load(File.ReadAllBytes(acbTemplatePath), null);
221+
var wrapper = new ACB_Wrapper(acbTemplate);
222+
wrapper.Cues[0].AddTrackToCue(hcaBytes, true, false, EncodeType.HCA);
223+
wrapper.AcbFile.Save(acbSavePath);
227224
}
228225

229226
public void Dispose()

ChuChartManager/ChuChartManager.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<PackageReference Include="Pfim" Version="0.11.4" />
3333
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.12" />
3434
<PackageReference Include="Tomlyn" Version="2.4.0" />
35-
<PackageReference Include="VGAudio" Version="2.2.1" />
35+
<PackageReference Include="YAXLib" Version="2.15.0" />
3636
</ItemGroup>
3737
<ItemGroup>
3838
<ProjectReference Include="..\SonicAudioTools\Source\SonicAudioLib\SonicAudioLib.csproj" />
@@ -41,7 +41,7 @@
4141
<ReferenceOutputAssembly>true</ReferenceOutputAssembly>
4242
</ProjectReference>
4343
<ProjectReference Include="..\XV2-Tools\LB_Common\LB_Common.csproj">
44-
<Aliases>LBCommon</Aliases>
44+
<Aliases>global,LBCommon</Aliases>
4545
</ProjectReference>
4646
<ProjectReference Include="..\XV2-Tools\Xv2CoreLib\Xv2CoreLib.csproj" />
4747
<ProjectReference Include="..\DDSExtractor\DDSExtractor\DDSExtractor.vbproj">

0 commit comments

Comments
 (0)