Environment

Struct Environment 

Source
pub struct Environment { /* private fields */ }
Expand description

Unified environment for managing Unity assets

Implementations§

Source§

impl Environment

Source

pub fn bundle_container_entries<P: AsRef<Path>>( &self, bundle_path: P, ) -> Result<Vec<BundleContainerEntry>>

Extract best-effort m_Container entries from a loaded bundle source path.

This scans for AssetBundle objects (class id 142) inside the bundle and parses them to find m_Container entries.

Source

pub fn bundle_container_entries_source( &self, bundle_source: &BinarySource, ) -> Result<Vec<BundleContainerEntry>>

Source

pub fn find_bundle_container_entries( &self, pattern: &str, ) -> Vec<BundleContainerEntry>

Find container entries across all loaded bundles whose asset_path contains pattern.

Source

pub fn find_binary_object_keys_in_bundle_container( &self, pattern: &str, ) -> Vec<(String, BinaryObjectKey)>

Find resolved BinaryObjectKeys from bundle containers by path substring.

Source§

impl Environment

Source

pub fn load<P: AsRef<Path>>(&mut self, path: P) -> Result<()>

Load assets from a path (file or directory).

Source

pub fn load_file<P: AsRef<Path>>(&mut self, path: P) -> Result<()>

Load a single file.

Source

pub fn load_directory<P: AsRef<Path>>(&mut self, path: P) -> Result<()>

Load all supported files from a directory.

Source§

impl Environment

Source

pub fn binary_object_infos(&self) -> impl Iterator<Item = BinaryObjectRef<'_>>

Iterate binary object references across all loaded bundles and standalone serialized files.

Source

pub fn binary_sources(&self) -> Vec<(BinarySourceKind, BinarySource)>

List all loaded binary sources (standalone serialized files + bundles).

Source

pub fn find_binary_objects(&self, path_id: i64) -> Vec<BinaryObjectRef<'_>>

Find binary objects by path_id across all loaded assets/bundles.

Note: path_id is unique within a single SerializedFile, but not globally unique across files.

Source

pub fn find_binary_object(&self, path_id: i64) -> Option<BinaryObjectRef<'_>>

Find the first matching binary object by path_id (best-effort).

Source

pub fn find_binary_objects_in_source<P: AsRef<Path>>( &self, source: P, path_id: i64, ) -> Vec<BinaryObjectRef<'_>>

Find binary objects by path_id within a specific loaded source (bundle path or .assets path).

Source

pub fn find_binary_objects_in_source_id( &self, source: &BinarySource, path_id: i64, ) -> Vec<BinaryObjectRef<'_>>

Find binary objects by path_id within a specific loaded source (including WebFile entries).

Source

pub fn find_binary_object_in_source<P: AsRef<Path>>( &self, source: P, path_id: i64, ) -> Option<BinaryObjectRef<'_>>

Find the first binary object by path_id within a specific source.

Source

pub fn find_binary_object_in_source_id( &self, source: &BinarySource, path_id: i64, ) -> Option<BinaryObjectRef<'_>>

Source

pub fn find_binary_object_in_bundle_asset<P: AsRef<Path>>( &self, bundle_path: P, asset_index: usize, path_id: i64, ) -> Option<BinaryObjectRef<'_>>

Find a binary object by path_id within a specific bundle + asset index.

Source

pub fn find_binary_object_in_bundle_asset_source( &self, bundle_source: &BinarySource, asset_index: usize, path_id: i64, ) -> Option<BinaryObjectRef<'_>>

Source

pub fn find_binary_object_keys(&self, path_id: i64) -> Vec<BinaryObjectKey>

Find globally-unique keys for all matching objects by path_id (best-effort).

Source

pub fn find_binary_object_keys_in_source<P: AsRef<Path>>( &self, source: P, path_id: i64, ) -> Vec<BinaryObjectKey>

Find globally-unique keys for all matching objects by path_id within a specific source.

Source

pub fn read_binary_object_key( &self, key: &BinaryObjectKey, ) -> Result<UnityObject>

Read a UnityObject from a globally-unique key.

Source

pub fn peek_binary_object_name( &self, key: &BinaryObjectKey, ) -> Result<Option<String>>

Best-effort peek of m_Name/name for a binary object key.

This uses a TypeTree prefix fast path (when possible) and returns Ok(None) when the object has no TypeTree or does not expose a name field.

Source§

impl Environment

Source

pub fn resolve_binary_pptr( &self, context: &BinaryObjectRef<'_>, file_id: i32, path_id: i64, ) -> Option<BinaryObjectKey>

Resolve a Unity PPtr (fileID, pathID) into a globally-unique object key.

Notes:

  • file_id == 0 points to the same SerializedFile as the context object.
  • file_id > 0 indexes into the context file’s externals list (Unity convention: file_id - 1).
  • External resolution is best-effort and currently only matches already-loaded standalone serialized files.
Source

pub fn read_binary_pptr( &self, context: &BinaryObjectRef<'_>, file_id: i32, path_id: i64, ) -> Result<UnityObject>

Resolve and parse a Unity PPtr (fileID, pathID) using a context object for external mapping.

Source§

impl Environment

Source

pub fn read_bundle_stream_data<P: AsRef<Path>>( &self, bundle_path: P, stream_path: &str, offset: u64, size: u32, ) -> Result<Vec<u8>>

Read streamed resource bytes from a loaded bundle.

This is primarily used for AudioClip / Texture2D stream data (m_StreamData) when the referenced resource file is contained inside the same bundle (e.g. .resS / .resource).

Source

pub fn read_bundle_stream_data_source( &self, bundle_source: &BinarySource, stream_path: &str, offset: u64, size: u32, ) -> Result<Vec<u8>>

Source

pub fn read_stream_data<P: AsRef<Path>>( &self, source_path: P, source_kind: BinarySourceKind, stream_path: &str, offset: u64, size: u32, ) -> Result<Vec<u8>>

Read streamed resource bytes (best-effort) using the current environment context.

Resolution strategy:

  • If source_kind is AssetBundle, try to read from resource nodes inside the same bundle.
  • Fall back to reading from the filesystem (same directory / StreamingAssets/), which matches UnityPy’s ResourceReader-like behavior.
Source

pub fn read_stream_data_source( &self, source: &BinarySource, source_kind: BinarySourceKind, stream_path: &str, offset: u64, size: u32, ) -> Result<Vec<u8>>

Source

pub fn read_stream_data_from_fs<P: AsRef<Path>>( &self, source_path: P, stream_path: &str, offset: u64, size: u32, ) -> Result<Vec<u8>>

Read streamed resource bytes from the filesystem (best-effort).

This is useful when StreamedResource.m_Source points to an external .resS/.resource file that is not embedded in the current bundle.

Source§

impl Environment

Source

pub fn new() -> Self

Create a new environment

Source

pub fn with_options(options: EnvironmentOptions) -> Self

Source

pub fn set_reporter(&mut self, reporter: Option<Arc<dyn EnvironmentReporter>>)

Source

pub fn set_type_tree_registry( &mut self, registry: Option<Arc<dyn TypeTreeRegistry>>, )

Source

pub fn options(&self) -> EnvironmentOptions

Source

pub fn warnings(&self) -> Vec<EnvironmentWarning>

Source

pub fn take_warnings(&self) -> Vec<EnvironmentWarning>

Source

pub fn yaml_objects(&self) -> impl Iterator<Item = &UnityClass>

Iterate YAML Unity objects.

Source

pub fn find_yaml_by_anchor(&self, anchor: &str) -> Option<&UnityClass>

Find a YAML object by its YAML anchor (the &<id> part).

Source

pub fn objects(&self) -> Box<dyn Iterator<Item = EnvironmentObjectRef<'_>> + '_>

Iterate all objects (YAML + binary) as lightweight references.

Source

pub fn binary_objects(&self) -> impl Iterator<Item = Result<UnityObject>> + '_

Iterate parsed binary UnityObjects (best-effort).

Source

pub fn filter_by_class(&self, class_name: &str) -> Vec<&UnityClass>

Filter YAML objects by class name.

Source

pub fn yaml_documents(&self) -> &HashMap<PathBuf, YamlDocument>

Get loaded YAML documents

Source

pub fn binary_assets(&self) -> &HashMap<BinarySource, SerializedFile>

Get loaded standalone SerializedFiles.

Source

pub fn bundles(&self) -> &HashMap<BinarySource, AssetBundle>

Get loaded AssetBundles.

Source

pub fn webfiles(&self) -> &HashMap<PathBuf, WebFile>

Get loaded WebFiles (containers).

Trait Implementations§

Source§

impl Default for Environment

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.