Skip to content

Commit

Permalink
first tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AratorRL committed Jul 5, 2020
0 parents commit 8046c13
Show file tree
Hide file tree
Showing 6 changed files with 320 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.x86_64-pc-windows-msvc]
rustflags = ["-Ctarget-feature=+crt-static"]
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
240 changes: 240 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "rustplugin"
version = "0.1.0"
authors = ["Arator"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
log = "0.4"
simplelog = "^0.7.4"

[lib]
name = "rustplugin"
crate_type = ["cdylib"]
4 changes: 4 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() {
println!("cargo:rustc-link-search=C:\\rocketleague\\bakkesmod\\Bakkesmod-rewrite\\x64\\Release");
println!("cargo:rustc-link-lib=pluginsdk");
}
58 changes: 58 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#[macro_use] extern crate log;
use simplelog::{WriteLogger, LevelFilter, Config};
use std::fs::File;

fn notifier_callback() {
bakkesmod::log("this is the callback for rust_notifier!");
}

#[no_mangle]
pub extern "C" fn InitPlugin(id: u64) {
let _ = WriteLogger::init(LevelFilter::Info, Config::default(), File::create("rustplugin.log").unwrap());
info!("Hello from a Rust plugin!");

bakkesmod::set_id(id);

bakkesmod::log("henlo from rust");
bakkesmod::register_notifier("rust_notifier", notifier_callback);

info!("finished initialization");
}

mod bakkesmod {
static mut GLOBAL_ID: u64 = 0;

pub fn set_id(id: u64) {
unsafe { GLOBAL_ID = id; }
}

pub fn get_id() -> u64 {
unsafe { GLOBAL_ID }
}

use std::ffi::CString;
use std::os::raw::c_char;

pub fn log(text: &str) {
info!("trying to log...");
let id = get_id();
info!("id: {}", id);
let c_text: *const c_char = CString::new(text).unwrap().as_ptr();
info!("c_text: {:?}", c_text);
unsafe { LogConsole(id, c_text); }
}

pub fn register_notifier(name: &str, callback: fn() -> ()) {
let id = get_id();
let c_name: *const c_char = CString::new(name).unwrap().as_ptr();
let c_callback = callback as usize;
let c_description: *const c_char = CString::new("").unwrap().as_ptr();
unsafe { RegisterNotifier(id, c_name, c_callback, c_description, 0) }
}

extern "C" {
// fn BakkesModAPI_BM_GetLocalCar() -> usize;
fn LogConsole(id: u64, text: *const c_char);
fn RegisterNotifier(id: u64, cvar: *const c_char, callback: usize, description: *const c_char, permissions: u8);
}
}

0 comments on commit 8046c13

Please sign in to comment.