Skip to content

feat: add pack command, video TEX support, .mpkg support, and bugfixes#73

Open
addallno wants to merge 5 commits into
notscuffed:masterfrom
addallno:pr-changes
Open

feat: add pack command, video TEX support, .mpkg support, and bugfixes#73
addallno wants to merge 5 commits into
notscuffed:masterfrom
addallno:pr-changes

Conversation

@addallno

@addallno addallno commented Jun 5, 2026

Copy link
Copy Markdown

Summary

This PR adds a pack command for creating .pkg/.mpkg packages and .tex textures from images, GIFs, and video files. It also adds .mpkg extension support to existing commands (info, extract) and fixes a Unicode path bug in the PKG writer.

Commits

1. fix: use UTF-8 byte count in WriteStringI32Size

WriteStringI32Size used input.Length (character count) instead of UTF-8 bytes.Length. Non-ASCII filenames (e.g., Chinese) had incorrect length prefix, corrupting PKG headers.

2. build: add net8.0 target framework

Dual-target net472;net8.0 for cross-platform compatibility. Conditional Microsoft.CSharp reference.

3. fix: improve TexToImageConverter crop/resize logic

Handle case where mipmap dimensions are smaller than header dimensions by resizing.

4. fix: support .mpkg extension in info and extract commands

  • Recognize .mpkg files in single-file mode (was only .pkg)
  • Merge duplicate .pkg/.mpkg directory enumeration into single Concat calls

5. feat: add pack command and video TEX support

New pack command:

  • repkg pack <dir> — pack directory to .pkg/.mpkg with auto-magic detection
  • repkg pack <file> — convert image (PNG/JPG/GIF) or video (MP4/WebM) to .tex
  • --mpkg flag / .mpkg output extension → auto PKGM0019 magic (Android)
  • .pkg output → auto PKGV0005 magic (desktop)
  • Options: --format, --lz4, --no-gif, --video-width/height, -m magic override

New ImageToTexConverter:

  • PNG/JPG → RGBA8888/R8/RG88 TEX textures
  • GIF → multi-frame TEX with TEXS0003 frame info
  • Video → V4 video texture TEX (MP4 wrapped, FIF_UNKNOWN + isVideoMp4=0 + V3 mipmap fallback)

V4 container writer:

  • TEXB0004 container header with Format + isVideoMp4 flag
  • WriteMipmapV4 with extra metadata fields (param1, param2, conditionJson, param3)
  • Non-MP4 V4 containers fall back to V3 mipmap format

addallno and others added 5 commits June 5, 2026 16:44
The previous code wrote input.Length (character count) instead of
Encoding.UTF8.GetBytes(input).Length (byte count). This caused path
strings containing non-ASCII characters (e.g., Chinese) to be written
with incorrect length prefix, corrupting the PKG header.
- Add net8.0 alongside net472 for cross-platform support
- Conditional Microsoft.CSharp reference for net472 only
When source mipmap dimensions differ from header dimensions, resize
instead of only cropping. Also handle the case where source is smaller
than header dimensions.
- Info.cs: recognize .mpkg files when processing single file input
- Info.cs: merge .pkg and .mpkg directory enumeration
- Extract.cs: recognize .mpkg files in single file mode
- Extract.cs: merge recursive and non-recursive .pkg/.mpkg enumeration
Pack command (repkg pack):
  - Directory mode: pack directory to .pkg or .mpkg
  - File mode: convert image/gif/video to .tex texture
  - Auto-detect magic: .pkg -> PKGV0005, .mpkg -> PKGM0019
  - Options: --format, --lz4, --no-gif, --video-width/height

ImageToTexConverter:
  - Convert PNG, JPEG, GIF to TEX textures (RGBA8888/R8/RG88)
  - Convert GIF animations to multi-frame TEX with frame info
  - Convert MP4/WebM/MOV/AVI to video TEX (MP4 wrapped in TEX container)

V4 texture container support:
  - TexImageContainerWriter: write V4 header (Format + isVideoMp4 flag)
  - TexImageWriter: add WriteMipmapV4 with extra metadata fields
  - For non-MP4 V4 containers, fall back to V3 mipmap format (matching
    official Wallpaper Engine TEX structure)
  - ITexImageWriter interface updated to pass FreeImageFormat

Program.cs: register PackOptions verb for CLI dispatch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant