From 35c8f20efc6a5e0fd5e26f95307d2c5a1bff4b71 Mon Sep 17 00:00:00 2001 From: Mitchell Merry Date: Fri, 26 Dec 2025 20:45:15 +1100 Subject: [PATCH 1/3] Add some helper functions to get the scene name as a string --- src/game_engine/unity/scene_manager/scene.rs | 31 ++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/game_engine/unity/scene_manager/scene.rs b/src/game_engine/unity/scene_manager/scene.rs index c081ead..605b4a9 100644 --- a/src/game_engine/unity/scene_manager/scene.rs +++ b/src/game_engine/unity/scene_manager/scene.rs @@ -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. @@ -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( &self, process: &Process, @@ -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 { + let path = self.path::(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 { + // 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()) + } } From dc668510bffbb531aec40c70b503d33547daef7d Mon Sep 17 00:00:00 2001 From: Mitchell Merry Date: Thu, 25 Jun 2026 00:23:54 +1000 Subject: [PATCH 2/3] Gate behind alloc --- src/game_engine/unity/scene_manager/scene.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/game_engine/unity/scene_manager/scene.rs b/src/game_engine/unity/scene_manager/scene.rs index 605b4a9..08db10a 100644 --- a/src/game_engine/unity/scene_manager/scene.rs +++ b/src/game_engine/unity/scene_manager/scene.rs @@ -41,6 +41,7 @@ impl Scene { } /// Returns the full path of the scene, as a [String](alloc::string::String). + #[cfg(feature = "alloc")] pub fn path_as_string( &self, process: &Process, @@ -53,6 +54,7 @@ impl Scene { } /// Returns the name of the scene, as a [String](alloc::string::String). + #[cfg(feature = "alloc")] pub fn name( &self, process: &Process, From 6d48da131b3be72e3b5704c0b2cbda65ed9775d5 Mon Sep 17 00:00:00 2001 From: Mitchell Merry Date: Thu, 25 Jun 2026 00:25:17 +1000 Subject: [PATCH 3/3] use rsplit instead of split --- src/game_engine/unity/scene_manager/scene.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game_engine/unity/scene_manager/scene.rs b/src/game_engine/unity/scene_manager/scene.rs index 08db10a..caae805 100644 --- a/src/game_engine/unity/scene_manager/scene.rs +++ b/src/game_engine/unity/scene_manager/scene.rs @@ -64,6 +64,6 @@ impl Scene { 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()) + Ok(cs.rsplit_once('.').unwrap_or((cs, "")).0.into()) } }