1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
//! [RLBot] is a framework for creating offline Rocket League bots. This crate //! exposes Rust bindings to RLBot's [RLBot_Core_Interface.dll]. It presents a //! simple, safe interface that should feel comfortable to Rust developers. //! //! [RLBot]: https://github.com/RLBot/RLBot //! [RLBot_Core_Interface.dll]: https://github.com/RLBot/RLBot/tree/master/src/main/cpp/RLBotInterface //! //! Most types in this crate come directly from RLBot, so for anything not //! documented here, you'll need to use RLBot's docs as the authoritative //! reference. //! //! When using this crate, you'll always start out by calling [`init`]. It will //! return an [`RLBot`] instance with which you can begin using the framework. //! //! Example usage: //! //! ```no_run //! # fn main() -> Result<(), Box<::std::error::Error>> { //! let rlbot = rlbot::init()?; //! rlbot.start_match(rlbot::MatchSettings::simple_1v1("Hero", "Villian"))?; //! //! let mut packets = rlbot.packeteer(); //! //! // Wait for the match to start. `packets.next()` sleeps until the next //! // packet is available, so this loop will not roast your CPU :) //! while !packets.next()?.GameInfo.RoundActive {} //! //! loop { //! let packet = packets.next()?; //! let input: rlbot::PlayerInput = Default::default(); //! rlbot.update_player_input(input, 0)?; //! } //! # } //! ``` extern crate libloading; extern crate ratelimit; use dll::RLBotCoreInterface; pub use ffi::*; pub use packeteer::Packeteer; pub use rlbot::RLBot; use std::error::Error; use std::sync::atomic::{AtomicBool, Ordering}; mod dll; mod error; mod ffi; mod ffi_impls; mod inject; mod packeteer; mod rlbot; /// Tracks whether a RLBot instance has been created. static INITIALIZED: AtomicBool = AtomicBool::new(false); /// Injects the RLBot core DLL into Rocket League, and initializes the interface /// DLL. This function might sleep for a bit while it waits for RLBot to fully /// initialize. /// /// # Panics /// /// Only one RLBot instance may be created over the life of the application. If /// you call this function more than once, it will panic. If you lose the RLBot /// instance, well, you should keep better track of your things. pub fn init() -> Result<RLBot, Box<Error>> { if INITIALIZED.swap(true, Ordering::SeqCst) { panic!("RLBot can only be initialized once"); } inject::inject_dll()?; let interface = RLBotCoreInterface::load()?; interface.wait_for_initialized()?; Ok(RLBot::new(interface)) }