Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions src/game_engine/unity/scene_manager/scene.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::SceneManager;
use super::{SceneManager, CSTR};
use crate::{string::ArrayCString, Address, Error, Process};

/// A scene loaded in the attached game.
Expand All @@ -24,7 +24,9 @@ impl Scene {
process.read(self.address + scene_manager.offsets.build_index)
}

/// Returns the full path to the scene.
/// Returns the full asset path of the scene.
///
/// Usually looks like "`Assets/some/path/scene.unity`".
pub fn path<const N: usize>(
&self,
process: &Process,
Expand All @@ -37,4 +39,29 @@ impl Scene {
)
.and_then(|addr| process.read(addr))
}

/// Returns the full path of the scene, as a [String](alloc::string::String).
pub fn path_as_string(
&self,
process: &Process,
scene_manager: &SceneManager,
) -> Result<alloc::string::String, Error> {
let path = self.path::<CSTR>(process, scene_manager)?;
let str = path.validate_utf8().map_err(|_| Error {})?;

Ok(str.into())
}

/// Returns the name of the scene, as a [String](alloc::string::String).
pub fn name(
&self,
process: &Process,
scene_manager: &SceneManager,
) -> Result<alloc::string::String, Error> {
// The name is also stored in memory, but it's just easier to interpret the path
let path = self.path_as_string(process, scene_manager)?;
// if for some reason the path has no /, or doesn't end in a .unity, just safely default
let cs = path.rsplit_once('/').unwrap_or(("", &path)).1;
Ok(cs.split_once('.').unwrap_or((cs, "")).0.into())
}
}
Loading