load_demo/
load_demo.rs

1use maple_rs::{Maple, Result};
2use std::fs;
3use std::path::Path;
4
5fn main() -> Result<()> {
6    let demo_path = Path::new("test/demo.exe");
7    let dll_path = Path::new("test/makcu-cpp.dll");
8
9    if !demo_path.exists() {
10        eprintln!("demo.exe not found in test directory");
11        return Ok(());
12    }
13
14    if !dll_path.exists() {
15        eprintln!("makcu-cpp.dll not found in test directory");
16        return Ok(());
17    }
18
19    println!("First, copy makcu-cpp.dll to current directory so demo.exe can find it...");
20    if dll_path.exists() {
21        let _ = fs::copy(dll_path, "makcu-cpp.dll");
22    }
23
24    println!("Loading demo.exe from memory...");
25    let demo_data = fs::read(demo_path)?;
26
27    println!("Creating memory module...");
28    match Maple::load_executable_from_memory(&demo_data) {
29        Ok(module) => {
30            println!("Successfully loaded demo.exe into memory");
31            println!("Base address: {:p}", module.base_address());
32            println!("Size: {} bytes", module.size());
33            println!("Is loaded: {}", module.is_loaded());
34
35            println!("Executing entry point...");
36            match module.execute_entry_point() {
37                Ok(_) => println!("Entry point executed successfully"),
38                Err(e) => eprintln!("Failed to execute entry point: {}", e),
39            }
40        }
41        Err(e) => {
42            eprintln!("Failed to load demo.exe: {}", e);
43        }
44    }
45
46    println!("\nLoading makcu-cpp.dll from memory...");
47    let dll_data = fs::read(dll_path)?;
48
49    match Maple::load_library_from_memory(&dll_data) {
50        Ok(module) => {
51            println!("Successfully loaded makcu-cpp.dll into memory");
52            println!("Base address: {:p}", module.base_address());
53            println!("Size: {} bytes", module.size());
54            println!("Is loaded: {}", module.is_loaded());
55        }
56        Err(e) => {
57            eprintln!("Failed to load makcu-cpp.dll: {}", e);
58        }
59    }
60
61    // Clean up the copied DLL
62    if Path::new("makcu-cpp.dll").exists() {
63        println!("\nCleaning up copied DLL...");
64        if let Err(e) = fs::remove_file("makcu-cpp.dll") {
65            eprintln!("Warning: Failed to clean up makcu-cpp.dll: {}", e);
66        } else {
67            println!("Cleaned up makcu-cpp.dll");
68        }
69    }
70
71    Ok(())
72}