OpenKh icon indicating copy to clipboard operation
OpenKh copied to clipboard

Cherry picked Linux fixes and improvements from pr #1096

Open Delta-473 opened this issue 5 months ago • 2 comments

As that pr is still a draft, I have cherry picked all the non Godot code from the branch as it has some nice improvements for native Linux support and cleanups. Unfortunately I don't know how to do a partial cherry pick and keep Frozenreflex as the author of the other commits.

Summary by CodeRabbit

  • New Features

    • SCD extraction now produces per-stream decoded media (Ogg Vorbis, MSADPCM WAV) alongside raw data.
    • Added CVBL loader for KH1, enabling mesh and vertex parsing.
    • Added KH2 BGM reader with per-track payload support.
    • Added KH2 BOP reader for structured entry parsing.
    • Extraction tool gains output-mode to place original/remastered files adjacent or in separate folders.
    • Added placeholder KH2 Wd class.
  • Documentation

    • KH2 model docs: “UVSC option” now links to the UV scroll section.

Delta-473 avatar Aug 24 '25 20:08 Delta-473

Walkthrough

Reworks SCD to instance-based headers and per-stream StreamHeaders/StreamFiles/MediaFiles with codec-specific decoding for codecs 6 and 12. Adds EGS Extract outputMode to control output paths. Introduces KH1 Cvbl mesh/vertex/joint loader. Adds KH2 Bgm and Bop parsers and an empty Wd class. Minor docs header->link tweak.

Changes

Cohort / File(s) Summary
SCD parser refactor + per-codec media
OpenKh.Bbs/Scd.cs
Replaces static headers with instance FileHeader and tableOffsetHeader; adds StreamHeaders, StreamFiles, MediaFiles; adds AuxChunkCount to stream header; Read() now populates per-stream data and decodes codecs: 6 (XOR-decrypt Ogg), 12 (wrap MSADPCM in WAV); preserves raw stream bytes.
EGS extract output mode
OpenKh.Egs/EgsTools.cs
Adds ExtractFileOutputMode enum and extends Extract(...) with outputMode parameter; adjusts original and remastered output paths for SeparateRoot vs Adjacent modes.
KH1 CVBL loader
OpenKh.Kh1/Cvbl.cs
Adds Cvbl parser and data model: CvblHeader, MeshEntry, Submesh, vertex formats (styles 8/9/10) implementing IVertex; parses vertices, faces, joint mappings; optional MDLS-based transforms to compute global vertex positions.
KH2 audio and data models
OpenKh.Kh2/Bgm.cs, OpenKh.Kh2/Bop.cs, OpenKh.Kh2/Wd.cs
Adds Bgm with header, per-track raw payloads, command enum and helper; adds Bop reader with BopEntry binary-mapped records and Entries list; adds empty Wd class.
Docs link tweak
docs/kh2/file/model.md
Changes “UVSC option:” header to linked form “UVSC option:”.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant App
  participant Scd as Scd.Read
  participant Codec as CodecHandler
  App->>Scd: Read(stream)
  Scd->>Scd: Parse FileHeader, tableOffsetHeader
  loop For each stream
    Scd->>Scd: Read StreamHeader + raw bytes
    alt Codec 6 (Ogg)
      Scd->>Codec: XOR decrypt + extract vorbis headers
      Codec-->>Scd: Ogg bytes -> MediaFiles
    else Codec 12 (MSADPCM)
      Scd->>Codec: Wrap RIFF/WAV
      Codec-->>Scd: WAV bytes -> MediaFiles
    else Other
      Scd-->>Scd: MediaFiles add null
    end
  end
  Scd-->>App: Return Scd (FileHeader, StreamHeaders, StreamFiles, MediaFiles)
sequenceDiagram
  autonumber
  participant Tool as EgsTools.Extract
  participant FS as File System
  Note over Tool: outputMode: SeparateRoot | Adjacent
  Tool->>Tool: Compute originalPath (based on outputMode)
  Tool->>Tool: Compute remasteredPath (based on outputMode)
  Tool->>FS: Write original file
  Tool->>FS: Write remastered file (if present)
sequenceDiagram
  autonumber
  participant App
  participant BGM as Bgm.Read
  App->>BGM: Read(stream)
  BGM->>BGM: Read header
  loop TrackCount
    BGM->>BGM: Read length + payload
    BGM-->>BGM: Tracks.Add(raw)
  end
  BGM-->>App: Return Bgm (header + Tracks)

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120 minutes

Poem

I nibble bytes and hop through streams,
Ogg and WAV spill sunlight beams,
Meshes sprout joints, faces align,
Tracks and entries stack in line,
A tiny link nudges docs—hooray! 🥕✨

[!TIP]

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • [ ] 📝 Generate Docstrings
🧪 Generate unit tests
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Aug 24 '25 20:08 coderabbitai[bot]

About the build error Invalid expression term '[',

2025-08-27_22h06_23

It comes from <TargetFramework>net6.0</TargetFramework> of OpenKh.Kh1/OpenKh.Kh1.csproj.

The collection expressions [JointSlotId] is available since net8.0.

The array reference type - C# reference | Microsoft Learn

Many of the examples in this article use collection expressions (which use square brackets) to initialize the arrays. Collection expressions were first introduced in C# 12, which shipped with .NET 8. If you can't upgrade to C# 12 yet, use { and } to initialize the arrays instead.

Fix it with a traditional expression new ushort[] { JointSlotId }, or just merge .net8.0 merge request first.

kenjiuno avatar Aug 27 '25 13:08 kenjiuno