Giter VIP home page Giter VIP logo

bevy_assetio_zip's Introduction

bevy_assetio_zip

Crates.io Docs.rs Katharos License

A Bevy AssetIo implementation that allows reading from optionally obfuscated zip asset bundles. Using the bevy_assetio_zip_bundler crate you can also automatically bundle your assets in the desired format in your build.rs script.

Usage

Simply enable the plugin when setting up your Bevy app to enable loading from asset bundle files.

App::build()
    // Any config must be inserted before adding plugins. This is optional.
    .add_resource(AssetIoZipConfig {
        // The name of the asset bundle file, excluding the extension, to load
        file_name: "assets".into(), // This is the default
    })
    // Add the default plugins
    .add_plugins_with(DefaultPlugins, |group| {
        // With our additinoal asset IO plugin
        group.add_before::<bevy::asset::AssetPlugin, _>(AssetIoZipPlugin)
    })
    .run();

Once enabling the plugin, the game will now search for assets.zip and assets.bin files adjacent to the executable when attempting to load assets. If an asset is not found in the zip file, it will attempt to load the asset using the default Bevy asset loader for the target platform.

Types of Asset Bundles

There are two kinds of asset bundle files supported by this plugin, plain .zip files and obfuscated zip files ( which have a .bin extension ). Plain .zip files are typical zip files that can be created with normal zip software. Obfuscated zip files can be created with bevy_assetio_zip_bundler and are simply a normal zip file that has had the bytes XOR-ed by 0b01010101.

โš ๏ธ WARNING: Obfuscated zip files provide no real security or protection for your assets. It is trivial to decript the asset bundle even if it is obfuscated. Obfuscation of the zip is only a measure to prevent casual users from being able to immediately introspect the data.

Bundling Assets

To bundle your bevy assets you can use the bevy_assetio_zip_bundler crate. The easiest way to use it is to add this to your build.rs file:

fn main() {
    bevy_assetio_zip_bundler::bundle_crate_assets();
}

This will automatically zip up your crate's assets folder and put it in your target/ dir when compiling release builds. When distributing your application simply take your asset bundle and place it adjacent to the executable and Bevy will attempt to load assets from the bundle before falling back to the assets dir.

You can configure the name, obfuscation, and compression of the bundle by creating and asset_config.toml file next to your Cargo.toml file:

# Bundle assets even for debug builds
bundle-for-debug-builds = true # Default: false

# Obfuscate assets. This doesn't protect from reverse-engineering, but it makes it a little harder
# for the average user to read them.
obfuscate = true # Default: false

# Compress the asset bundle using Bzip2 compression. Other options are "deflate" and "none".
compression = "bzip2" # Default: "bzip2"

# The name of the file, not counting the exention, which will be different based on the `obfuscate`
# setting. Obfuscated bundles will end in `.bin` and non-obfuscated bundles will end in `.zip`.
file-name = "assets" # Default: "assets"

# Set the directory that asset bundle should be placed.
out-dir = "../target" # Default "./target"

Alternatively, if you want to create your own tooling or customize the asset bundling process, you can manually bundle the assets using the bevy_assetio_zip_bundler::bundle_assets function.

Bevy Versions

Supported bevy versions per plugin version:

Bevy Version Plugin Version
0.4 0.1
master 0.1 with the bevy-unstable feature ( see below )

Using Bevy From Master

You can use this crate with Bevy master by adding a patch to your Cargo.toml and by adding the bevy-unstable feature to this crate:

[dependencies]
# Bevy version must be set to "0.4" and we will
# override it in the patch below.
bevy = "0.4"
bevy_assetio_zip = { version = "0.1", features = ["bevy-unstable"] }

[patch.crates-io]
bevy = { git = "https://github.com/bevyengine/bevy.git" }

Note that as Bevy master may or may not introduce breaking API changes, this crate may or may not compile when using the bevy-unstable feature.

License

This crate is licensed under the Katharos License which places certain restrictions on what you are allowed to use it for. Please read and understand the terms before using this crate for your project.

bevy_assetio_zip's People

Contributors

zicklag avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.