#bevy #asset #assets #bundler

bevy_assets_bundler

Assets Bundler for bevy, with content encryption support

3 unstable releases

Uses new Rust 2021

0.2.1 Jan 13, 2022
0.2.0 Jan 12, 2022
0.1.0 Aug 16, 2021

#150 in Cryptography

Download history 2/week @ 2021-10-02 1/week @ 2021-10-09 2/week @ 2021-10-16 2/week @ 2021-10-23 2/week @ 2021-10-30 1/week @ 2021-11-06 2/week @ 2021-11-13 5/week @ 2021-11-20 2/week @ 2021-11-27 3/week @ 2021-12-04 2/week @ 2021-12-11 1/week @ 2021-12-18 1/week @ 2021-12-25 1/week @ 2022-01-01 64/week @ 2022-01-08 18/week @ 2022-01-15

84 downloads per month

MIT license

24KB
457 lines

Bevy Assets Bundler

github action travis codecov dependency status loc License

crates.io docs.rs

Assets Bundler for bevy, with content encryption support. Current archive format is tar and encryption algorithm is AES

Features

  • Bundle asset folder into a single assets.bin file
  • Asset encryption with custom key
  • Asset file names encoding (base58 when ecryption is off, AES+base58 otherwise)
  • One simple switch to turn off bundling on debug build

Installation

# Cargo.toml
[dependencies]
bevy = "0.6"
bevy_assets_bundler = "0.1"

[build-dependencies]
bevy_assets_bundler = "0.1"

Build Script

You can generate a random key with this playground

// build.rs
// encryption key: [u8; 16] array
// make sure the key is consistent between build.rs and main.rs
// or follow the example code to share code between build.rs and main.rs
let key = [30, 168, 132, 180, 250, 203, 124, 96, 221, 206, 64, 239, 102, 20, 139, 79];
let mut options = AssetBundlingOptions::default();
options.set_encryption_key(key);
options.encode_file_names = true;
options.enabled_on_debug_build = true;
AssetBundler::from(options).build().unwrap();

Bevy Setup

use bevy_assets_bundler::*;
use bevy::asset::AssetPlugin;

fn main() {
    // encryption key: [u8; 16] array
    // make sure the key is consistent between build.rs and main.rs
    // or follow the example code to share code between build.rs and main.rs
    let key = [30, 168, 132, 180, 250, 203, 124, 96, 221, 206, 64, 239, 102, 20, 139, 79];
    let mut options = AssetBundlingOptions::default();
    options.set_encryption_key(key);
    options.encode_file_names = true;
    options.enabled_on_debug_build = true;

    App::new()
        .add_plugins_with(DefaultPlugins, |group| {
            group.add_before::<AssetPlugin, _>(BundledAssetIoPlugin::from(
                options.clone(),
            ))
        })
        .add_startup_system(setup)
        .run();
}

Options

#[derive(Debug, Clone)]
pub struct AssetBundlingOptions {
    #[cfg(feature = "encryption")]
    pub encryption_on: bool,
    #[cfg(feature = "encryption")]
    pub encryption_key: Option<[u8; 16]>,
    #[cfg(feature = "compression")]
    pub enable_compression: bool,
    pub enabled_on_debug_build: bool,
    pub encode_file_names: bool,
    pub asset_bundle_name: String,
}

TODO

  • Compression
  • More encryption algorithms

Bevy Version Supported

bevy bevy_assets_bundler
0.5 0.1
0.6 0.2

Examples

Check out example and E2E test

To run example: cargo run -p example

go to target/release folder, now you can move example(.exe) and assets.bin to some other place and run, just keep the relative path between them.

Disclaimer

The encryption mechnism this library provides does not protect your assets from ALL kinds of reverse engineering as long as the game executable and the assets bundle are distributed to end users.

License

MIT

Dependencies

~9–15MB
~309K SLoC

a