pub struct Game { /* private fields */ }Expand description
A Unity Il2Cpp game: its metadata and the type table from its binary.
Implementations§
Source§impl Game
impl Game
Sourcepub fn open(dir: impl AsRef<Path>) -> Result<Self>
pub fn open(dir: impl AsRef<Path>) -> Result<Self>
Opens a game folder: the one holding GameAssembly.so and <Game>_Data.
Examples found in repository?
More examples
examples/game_info.rs (line 17)
12fn main() -> hao_il2cpp::Result<()> {
13 let mut args = std::env::args().skip(1);
14 let dir = args
15 .next()
16 .expect("usage: game_info <game folder> [type name] [method name]");
17 let game = Game::open(dir)?;
18
19 let Some(type_name) = args.next() else {
20 println!(
21 "{} types in {} assemblies:",
22 game.types().count(),
23 game.image_names().count()
24 );
25 for name in game.image_names() {
26 println!(" {}", name);
27 }
28 return Ok(());
29 };
30
31 let Some(ty) = game.find_type(&type_name) else {
32 println!("no type named {}; similar names:", type_name);
33 for t in game
34 .types()
35 .filter(|t| {
36 t.name()
37 .contains(type_name.rsplit('.').next().unwrap_or(&type_name))
38 })
39 .take(10)
40 {
41 println!(" {}", t.full_name());
42 }
43 return Ok(());
44 };
45
46 // With a method name, break every matching overload into its parts, to show
47 // that names, return types and parameters are each available separately.
48 if let Some(method_name) = args.next() {
49 let mut found = false;
50 for method in ty.methods().filter(|m| m.name() == method_name) {
51 found = true;
52 println!("{}.{}", ty.full_name(), method.name());
53 println!(" static: {}", method.is_static());
54 println!(" returns: {}", method.return_type_name());
55 let parameters: Vec<_> = method.parameters().collect();
56 if parameters.is_empty() {
57 println!(" params: (none)");
58 } else {
59 println!(" params:");
60 for (i, parameter) in parameters.iter().enumerate() {
61 println!(" {}: {} {}", i, parameter.type_name(), parameter.name());
62 }
63 }
64 println!();
65 }
66 if !found {
67 println!("no method named {} on {}", method_name, ty.full_name());
68 }
69 return Ok(());
70 }
71
72 print!("// {}\nclass {}", ty.image_name(), ty.full_name());
73 if let Some(base) = ty.base_type_name() {
74 print!(" : {}", base);
75 }
76 println!("\n{{");
77 for field in ty.fields() {
78 println!(" {};", field);
79 }
80 for method in ty.methods() {
81 println!(" {};", method);
82 }
83 for nested in ty.nested_types() {
84 println!(" class {}", nested.name());
85 }
86 println!("}}");
87 Ok(())
88}Sourcepub fn from_files(
metadata: impl AsRef<Path>,
binary: impl AsRef<Path>,
) -> Result<Self>
pub fn from_files( metadata: impl AsRef<Path>, binary: impl AsRef<Path>, ) -> Result<Self>
Opens a global-metadata.dat and its GameAssembly binary.
Sourcepub fn from_bytes(metadata: Vec<u8>, binary_bytes: &[u8]) -> Result<Self>
pub fn from_bytes(metadata: Vec<u8>, binary_bytes: &[u8]) -> Result<Self>
Reads a game from the contents of its global-metadata.dat and GameAssembly,
e.g. files uploaded to a web page.
pub fn new(metadata: Metadata, binary: Binary) -> Self
pub fn new_with_image( metadata: Metadata, binary: Binary, image_bytes: Vec<u8>, ) -> Self
pub fn metadata(&self) -> &Metadata
pub fn binary(&self) -> &Binary
Sourcepub fn types(&self) -> impl Iterator<Item = TypeView<'_>>
pub fn types(&self) -> impl Iterator<Item = TypeView<'_>>
Every type definition in the game.
Examples found in repository?
examples/game_info.rs (line 22)
12fn main() -> hao_il2cpp::Result<()> {
13 let mut args = std::env::args().skip(1);
14 let dir = args
15 .next()
16 .expect("usage: game_info <game folder> [type name] [method name]");
17 let game = Game::open(dir)?;
18
19 let Some(type_name) = args.next() else {
20 println!(
21 "{} types in {} assemblies:",
22 game.types().count(),
23 game.image_names().count()
24 );
25 for name in game.image_names() {
26 println!(" {}", name);
27 }
28 return Ok(());
29 };
30
31 let Some(ty) = game.find_type(&type_name) else {
32 println!("no type named {}; similar names:", type_name);
33 for t in game
34 .types()
35 .filter(|t| {
36 t.name()
37 .contains(type_name.rsplit('.').next().unwrap_or(&type_name))
38 })
39 .take(10)
40 {
41 println!(" {}", t.full_name());
42 }
43 return Ok(());
44 };
45
46 // With a method name, break every matching overload into its parts, to show
47 // that names, return types and parameters are each available separately.
48 if let Some(method_name) = args.next() {
49 let mut found = false;
50 for method in ty.methods().filter(|m| m.name() == method_name) {
51 found = true;
52 println!("{}.{}", ty.full_name(), method.name());
53 println!(" static: {}", method.is_static());
54 println!(" returns: {}", method.return_type_name());
55 let parameters: Vec<_> = method.parameters().collect();
56 if parameters.is_empty() {
57 println!(" params: (none)");
58 } else {
59 println!(" params:");
60 for (i, parameter) in parameters.iter().enumerate() {
61 println!(" {}: {} {}", i, parameter.type_name(), parameter.name());
62 }
63 }
64 println!();
65 }
66 if !found {
67 println!("no method named {} on {}", method_name, ty.full_name());
68 }
69 return Ok(());
70 }
71
72 print!("// {}\nclass {}", ty.image_name(), ty.full_name());
73 if let Some(base) = ty.base_type_name() {
74 print!(" : {}", base);
75 }
76 println!("\n{{");
77 for field in ty.fields() {
78 println!(" {};", field);
79 }
80 for method in ty.methods() {
81 println!(" {};", method);
82 }
83 for nested in ty.nested_types() {
84 println!(" class {}", nested.name());
85 }
86 println!("}}");
87 Ok(())
88}Sourcepub fn find_type(&self, full_name: &str) -> Option<TypeView<'_>>
pub fn find_type(&self, full_name: &str) -> Option<TypeView<'_>>
Finds a type by its full name (Namespace.Name, Outer/Nested, List1`).
Examples found in repository?
examples/game_info.rs (line 31)
12fn main() -> hao_il2cpp::Result<()> {
13 let mut args = std::env::args().skip(1);
14 let dir = args
15 .next()
16 .expect("usage: game_info <game folder> [type name] [method name]");
17 let game = Game::open(dir)?;
18
19 let Some(type_name) = args.next() else {
20 println!(
21 "{} types in {} assemblies:",
22 game.types().count(),
23 game.image_names().count()
24 );
25 for name in game.image_names() {
26 println!(" {}", name);
27 }
28 return Ok(());
29 };
30
31 let Some(ty) = game.find_type(&type_name) else {
32 println!("no type named {}; similar names:", type_name);
33 for t in game
34 .types()
35 .filter(|t| {
36 t.name()
37 .contains(type_name.rsplit('.').next().unwrap_or(&type_name))
38 })
39 .take(10)
40 {
41 println!(" {}", t.full_name());
42 }
43 return Ok(());
44 };
45
46 // With a method name, break every matching overload into its parts, to show
47 // that names, return types and parameters are each available separately.
48 if let Some(method_name) = args.next() {
49 let mut found = false;
50 for method in ty.methods().filter(|m| m.name() == method_name) {
51 found = true;
52 println!("{}.{}", ty.full_name(), method.name());
53 println!(" static: {}", method.is_static());
54 println!(" returns: {}", method.return_type_name());
55 let parameters: Vec<_> = method.parameters().collect();
56 if parameters.is_empty() {
57 println!(" params: (none)");
58 } else {
59 println!(" params:");
60 for (i, parameter) in parameters.iter().enumerate() {
61 println!(" {}: {} {}", i, parameter.type_name(), parameter.name());
62 }
63 }
64 println!();
65 }
66 if !found {
67 println!("no method named {} on {}", method_name, ty.full_name());
68 }
69 return Ok(());
70 }
71
72 print!("// {}\nclass {}", ty.image_name(), ty.full_name());
73 if let Some(base) = ty.base_type_name() {
74 print!(" : {}", base);
75 }
76 println!("\n{{");
77 for field in ty.fields() {
78 println!(" {};", field);
79 }
80 for method in ty.methods() {
81 println!(" {};", method);
82 }
83 for nested in ty.nested_types() {
84 println!(" class {}", nested.name());
85 }
86 println!("}}");
87 Ok(())
88}Sourcepub fn image_names(&self) -> impl Iterator<Item = &str>
pub fn image_names(&self) -> impl Iterator<Item = &str>
The assembly names in the game, e.g. Assembly-CSharp.dll.
Examples found in repository?
examples/game_info.rs (line 23)
12fn main() -> hao_il2cpp::Result<()> {
13 let mut args = std::env::args().skip(1);
14 let dir = args
15 .next()
16 .expect("usage: game_info <game folder> [type name] [method name]");
17 let game = Game::open(dir)?;
18
19 let Some(type_name) = args.next() else {
20 println!(
21 "{} types in {} assemblies:",
22 game.types().count(),
23 game.image_names().count()
24 );
25 for name in game.image_names() {
26 println!(" {}", name);
27 }
28 return Ok(());
29 };
30
31 let Some(ty) = game.find_type(&type_name) else {
32 println!("no type named {}; similar names:", type_name);
33 for t in game
34 .types()
35 .filter(|t| {
36 t.name()
37 .contains(type_name.rsplit('.').next().unwrap_or(&type_name))
38 })
39 .take(10)
40 {
41 println!(" {}", t.full_name());
42 }
43 return Ok(());
44 };
45
46 // With a method name, break every matching overload into its parts, to show
47 // that names, return types and parameters are each available separately.
48 if let Some(method_name) = args.next() {
49 let mut found = false;
50 for method in ty.methods().filter(|m| m.name() == method_name) {
51 found = true;
52 println!("{}.{}", ty.full_name(), method.name());
53 println!(" static: {}", method.is_static());
54 println!(" returns: {}", method.return_type_name());
55 let parameters: Vec<_> = method.parameters().collect();
56 if parameters.is_empty() {
57 println!(" params: (none)");
58 } else {
59 println!(" params:");
60 for (i, parameter) in parameters.iter().enumerate() {
61 println!(" {}: {} {}", i, parameter.type_name(), parameter.name());
62 }
63 }
64 println!();
65 }
66 if !found {
67 println!("no method named {} on {}", method_name, ty.full_name());
68 }
69 return Ok(());
70 }
71
72 print!("// {}\nclass {}", ty.image_name(), ty.full_name());
73 if let Some(base) = ty.base_type_name() {
74 print!(" : {}", base);
75 }
76 println!("\n{{");
77 for field in ty.fields() {
78 println!(" {};", field);
79 }
80 for method in ty.methods() {
81 println!(" {};", method);
82 }
83 for nested in ty.nested_types() {
84 println!(" class {}", nested.name());
85 }
86 println!("}}");
87 Ok(())
88}Sourcepub fn generate(&self) -> Result<Vec<GeneratedAssembly>>
pub fn generate(&self) -> Result<Vec<GeneratedAssembly>>
Builds a declaration assembly for every image.
Sourcepub fn write_assemblies(&self, dir: impl AsRef<Path>) -> Result<Vec<PathBuf>>
pub fn write_assemblies(&self, dir: impl AsRef<Path>) -> Result<Vec<PathBuf>>
Generates the declaration assemblies and writes them to dir, returning their paths.
Sourcepub fn bytes_at(&self, vaddr: u64, len: usize) -> Option<Vec<u8>>
pub fn bytes_at(&self, vaddr: u64, len: usize) -> Option<Vec<u8>>
Read raw bytes from the game binary at a virtual address.
Sourcepub fn method_pointer(&self, method: &MethodDefinition) -> Option<u64>
pub fn method_pointer(&self, method: &MethodDefinition) -> Option<u64>
Look up the native code address for a method definition.
Trait Implementations§
Auto Trait Implementations§
impl Forget for Game
impl Freeze for Gamewhere
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
PhantomData<(&'static str, (usize, usize))>: Freeze,
PhantomData<ImageDefinition>: Freeze,
PhantomData<AssemblyDefinition>: Freeze,
PhantomData<TypeDefinition>: Freeze,
PhantomData<MethodDefinition>: Freeze,
PhantomData<FieldDefinition>: Freeze,
PhantomData<ParameterDefinition>: Freeze,
PhantomData<PropertyDefinition>: Freeze,
PhantomData<EventDefinition>: Freeze,
PhantomData<GenericContainer>: Freeze,
PhantomData<GenericParameter>: Freeze,
PhantomData<i32>: Freeze,
PhantomData<FieldDefaultValue>: Freeze,
PhantomData<Option<i32>>: Freeze,
PhantomData<CodeGenModule>: Freeze,
PhantomData<Il2CppType>: Freeze,
PhantomData<(String, i32)>: Freeze,
impl Move for Game
impl RefUnwindSafe for Game
impl Send for Game
impl Sync for Game
impl Unpin for Game
impl UnsafeUnpin for Gamewhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<(&'static str, (usize, usize))>: UnsafeUnpin,
PhantomData<ImageDefinition>: UnsafeUnpin,
PhantomData<AssemblyDefinition>: UnsafeUnpin,
PhantomData<TypeDefinition>: UnsafeUnpin,
PhantomData<MethodDefinition>: UnsafeUnpin,
PhantomData<FieldDefinition>: UnsafeUnpin,
PhantomData<ParameterDefinition>: UnsafeUnpin,
PhantomData<PropertyDefinition>: UnsafeUnpin,
PhantomData<EventDefinition>: UnsafeUnpin,
PhantomData<GenericContainer>: UnsafeUnpin,
PhantomData<GenericParameter>: UnsafeUnpin,
PhantomData<i32>: UnsafeUnpin,
PhantomData<FieldDefaultValue>: UnsafeUnpin,
PhantomData<Option<i32>>: UnsafeUnpin,
PhantomData<CodeGenModule>: UnsafeUnpin,
PhantomData<Il2CppType>: UnsafeUnpin,
PhantomData<(String, i32)>: UnsafeUnpin,
impl UnwindSafe for Gamewhere
RawVecInner: UnwindSafe,
HashMap<&'static str, (usize, usize)>: UnwindSafe,
BoxRaw<Il2CppType>: UnwindSafe,
HashMap<String, i32>: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more