Skip to content

feat: Native Binary Compilation & Encryption Support with Key ManagementΒ #27

@Bli-AIk

Description

@Bli-AIk

πŸ”— Is your feature request related to a specific issue?

Currently, the Mortar compiler outputs dialogue scripts as plain-text JSON.

For narrative-driven games using external scripting languages, this poses a significant risk: players can easily open script files to read spoilers, plot twists, or datamine hidden mechanics. Narrative designers often need a way to "seal" their logic and text to protect the player experience.

Furthermore, while protection is necessary, we must also support authorized third-party access, such as localization teams. There needs to be a mechanism where the original author can securely provide a key/method for translators to decode and edit the scripts without exposing the raw source to the general public.


πŸ’‘ Feature Description

Implement a native encryption and binary compilation pipeline within the Mortar CLI and Runtime.

1. Binary Compilation Target (.mb)

  • Extend the compiler to support a binary serialization format (e.g., Bincode) instead of standard JSON.
  • This provides immediate performance benefits (smaller size, faster parsing) and basic obfuscation against casual text editors.

2. "Sealing" (Encryption) with Keys

  • Add a --seal or --encrypt flag to the CLI, accepting a user-defined key.
  • The compiler should obfuscate/encrypt the output using this key (e.g., XOR with a magic header).
  • Localization Support: Provide a corresponding --decrypt or --unlock command in the CLI. If a translator is given the correct key by the author, they can convert the binary back to editable source/JSON, perform translations, and re-compile.

3. Runtime Support

  • Update the mortar runtime library to handle encrypted streams.
  • The load function should accept an optional key parameter to decode assets on the fly.

βš– Alternatives Considered

1. Relying on Host Engine Encryption:

  • Most generic game engines (or custom frameworks) require complex asset packing plugins to handle encryption.
  • By handling this at the language compiler level, Mortar provides "out-of-the-box" protection regardless of whether the host engine is Bevy, Unity, Godot, or a custom framework.

2. Plain Text JSON:

  • Leaving scripts as JSON makes the narrative extremely vulnerable to datamining, which is unacceptable for story-heavy commercial or fan projects.

πŸ“ Additional Information

Proposed Workflow:

# Author builds the game:
mortar build main.mortar --format binary --seal --key "secret-key-123"

# Runtime loading (in Rust):
let script = Mortar::load_bytes(data, Some("secret-key-123"));

# Localization Workflow:
# Author sends the encrypted file and key to the translator.
# Translator runs:
mortar tool decrypt main.mb --key "secret-key-123" --out main_translated.mortar

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions