Skip to main content

generate_dlls/
generate_dlls.rs

1//! Writes a declaration assembly ("dummy DLL") for every image of an Il2Cpp game.
2//!
3//! An Il2Cpp game ships no .NET assemblies: its C# was compiled to C++ and then
4//! to native code in `GameAssembly`. What's left of the original assemblies is
5//! `global-metadata.dat`, with every type, method and field name, but no code.
6//!
7//! This rebuilds one ordinary .NET assembly per original assembly from that
8//! metadata: every class, struct, enum, interface, field, constant, property,
9//! event and method signature, with method bodies that just throw. They're
10//! useful for:
11//!
12//! - browsing the game in ILSpy, dnSpy or Rider to find the classes, methods and
13//!   fields a mod should hook or read, with their exact signatures;
14//! - compiling C# against the game's API, e.g. for tooling or to check a mod's
15//!   references, since the declarations match the real types;
16//! - comparing game versions to see what an update changed.
17//!
18//! They contain no game logic: for that you'd disassemble `GameAssembly`.
19//!
20//! ```sh
21//! cargo run --release -p hao-il2cpp --example generate_dlls -- <game folder> <output folder>
22//! ```
23
24use hao_il2cpp::Game;
25
26fn main() -> hao_il2cpp::Result<()> {
27    let mut args = std::env::args().skip(1);
28    let (Some(game), Some(out)) = (args.next(), args.next()) else {
29        panic!("usage: generate_dlls <game folder> <output folder>");
30    };
31    let paths = Game::open(game)?.write_assemblies(&out)?;
32    println!("wrote {} assemblies to {}", paths.len(), out);
33    Ok(())
34}