From 8a9d99cae350fca6d63025a89599f793d1ea92fa Mon Sep 17 00:00:00 2001 From: Quaternions Date: Tue, 5 Sep 2023 17:45:34 -0700 Subject: [PATCH] load_roblox module --- src/lib.rs | 1 + src/load_roblox.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/load_roblox.rs diff --git a/src/lib.rs b/src/lib.rs index 88b93b0..1a053b4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,3 +2,4 @@ pub mod framework; pub mod body; pub mod zeroes; pub mod instruction; +pub mod load_roblox; diff --git a/src/load_roblox.rs b/src/load_roblox.rs new file mode 100644 index 0000000..2648c51 --- /dev/null +++ b/src/load_roblox.rs @@ -0,0 +1,28 @@ +fn class_is_a(class: &str, superclass: &str) -> bool { + if class==superclass { + return true + } + let class_descriptor=rbx_reflection_database::get().classes.get(class); + if let Some(descriptor) = &class_descriptor { + if let Some(class_super) = &descriptor.superclass { + return class_is_a(&class_super, superclass) + } + } + return false +} + +pub fn get_objects(buf_thing: std::io::BufReader<&[u8]>, superclass: &str) -> Result, Box> { + // Using buffered I/O is recommended with rbx_binary + let dom = rbx_binary::from_reader(buf_thing)?; + + let mut objects = std::vec::Vec::::new(); + //move matching instances into objects + let (_,mut instances) = dom.into_raw(); + for (_,instance) in instances.drain() { + if class_is_a(instance.class.as_str(), superclass) { + objects.push(instance); + } + } + + return Ok(objects) +}