Function rglua::interface::get_from_interface [−][src]
pub fn get_from_interface(
iface: &str,
factory: CreateInterfaceFn
) -> Result<*mut (), InterfaceError>Expand description
Tries to get source interface from given interface name, and handle to it acquired from get_interface_handle
Arguments
iface- name of the interface to get, for example “VGUI_Panel009”factory- handle to the interface, acquired from get_interface_handle
Examples
Getting the raw PaintTraverse function from vgui:
// Wrappers to these interfaces are already provided but they do not give raw function pointers which is needed to detour / modify the functions
// in any way, which you may want to do here, especially for painttraverse since you can safely run lua here if you queue it from a thread to avoid crashes.
use rglua::interface::{get_interface_handle, get_from_interface, IPanel};
type PaintTraverseFn = extern "fastcall" fn(&'static IPanel, usize, bool, bool);
let handle = unsafe { get_interface_handle("vgui2.dll").unwrap() };
let vgui_interface = get_from_interface("VGUI_Panel009", handle)
.unwrap() as *mut IPanel;
unsafe {
// Use as_ref to access fields of the interface
let panel_iface = vgui_interface
.as_ref() // Unsafe as Rust doesn't know whether the interface is really valid or not
.unwrap();
// Transmute the function address from the offset into our known signature
// You should use Interface.get_raw for this though
let paint_traverse: PaintTraverseFn = std::mem::transmute(
(panel_iface.vtable as *mut *mut std::ffi::c_void)
.offset(41) // vtable offset as seen in [interface/panel.rs]
.read()
);
}