Skip to content

Commit

Permalink
fix warnings and improve cplayer/squirrel
Browse files Browse the repository at this point in the history
  • Loading branch information
catornot committed Apr 27, 2024
1 parent 3ba1de7 commit e29d3c2
Show file tree
Hide file tree
Showing 14 changed files with 130 additions and 70 deletions.
99 changes: 53 additions & 46 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion examples/squirrel_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ entry!(ExamplePlugin);
fn great_person(function: SQHandle<SQClosure>) -> Result<String, rrplug::errors::CallError> {
// non type safe way of getting a return from a function
// this could be changed if the crate gets some attention
let name = call_sq_object_function(sqvm, sq_functions, function)?;
let name = call_sq_object_function(sqvm, sq_functions, function, ())?;

log::info!("hello, {}", name);

Expand Down
4 changes: 3 additions & 1 deletion src/bindings/class_types/cplayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ offset_struct! {
vec_abs_origin: Vector3 where offset(0x100490),
is_performing_boost_action: bool where offset(0x25BE),
zipline_valid3p_weapon_layer_anim: bool where offset(0x240C),
player_script_net_data_global: i32 where offset(0x345C),
zooming: i32 where offset(0x1598), // this is like a bool but a i32. what?
zoom_toggle_on: bool where offset(0x1599),
zoom_base_frac: f32 where offset(0x159C),
Expand All @@ -101,6 +100,9 @@ offset_struct! {
camo_index: i32 where offset(0xA04),
decal_index: i32 where offset(0xA08),
team: i32 where offset(0x5E4),
current_command: *const c_void where offset(0x21d8),
player_script_net_data_global: i32 where offset(0x345c),
player_script_net_data_exclusive: i32 where offset(0x3460),
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/bindings/squirrelclasstypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ impl TryFrom<i32> for ScriptContext {

fn try_from(value: i32) -> Result<Self, Self::Error> {
if value <= Self::UI as i32 && value >= Self::SERVER as i32 {
Ok(unsafe { std::mem::transmute(value) })
Ok(unsafe { std::mem::transmute::<i32, ScriptContext>(value) })
} else {
Err(value)
}
Expand Down Expand Up @@ -396,3 +396,5 @@ pub type RegisterSquirrelFuncType_External = unsafe extern "C" fn(
funcReg: *mut SQFuncRegistration,
unknown: ::std::os::raw::c_char,
) -> i64;
pub type sq_createscriptinstanceType =
unsafe extern "C" fn(ent: *mut ::std::os::raw::c_void) -> *mut SQObject;
1 change: 0 additions & 1 deletion src/bindings/squirreldatatypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1518,7 +1518,6 @@ fn bindgen_test_layout_SQArray() {
);
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct HSquirrelVM {
pub vftable: *mut ::std::os::raw::c_void,
pub uiRef: ::std::os::raw::c_int,
Expand Down
5 changes: 5 additions & 0 deletions src/bindings/squirrelfunctions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ offset_functions! {

sq_get_entity_constant_cbase_entity = sq_GetEntityConstantType where offset(0x418AF0);
sq_getentityfrominstance = sq_getentityfrominstanceType where offset(0x1E920);
sq_create_script_instance = sq_createscriptinstanceType where offset(0x43f2f0);

sq_getfunction = sq_getfunctionType where offset(0x6c80);
sq_stackinfos = sq_stackinfosType where offset(0x35920);
Expand Down Expand Up @@ -100,6 +101,7 @@ offset_functions! {

sq_get_entity_constant_cbase_entity = sq_GetEntityConstantType where offset(0x3E49B0);
sq_getentityfrominstance = sq_getentityfrominstanceType where offset(0x114F0);
sq_create_script_instance = sq_createscriptinstanceType where offset(0xc20e0);

sq_getfunction = sq_getfunctionType where offset(0x06cb0);
sq_stackinfos = sq_stackinfosType where offset(0x35970);
Expand Down Expand Up @@ -147,6 +149,7 @@ pub struct SquirrelFunctions {
pub sq_getfunction: sq_getfunctionType,
pub sq_getentityfrominstance: sq_getentityfrominstanceType,
pub sq_get_entity_constant_cbase_entity: sq_GetEntityConstantType,
pub sq_create_script_instance: sq_createscriptinstanceType,
pub sq_pushnewstructinstance: sq_pushnewstructinstanceType,
pub sq_sealstructslot: sq_sealstructslotType,
}
Expand Down Expand Up @@ -189,6 +192,7 @@ impl From<&ClientSQFunctions> for SquirrelFunctions {
sq_getfunction: val.sq_getfunction,
sq_getentityfrominstance: val.sq_getentityfrominstance,
sq_get_entity_constant_cbase_entity: val.sq_get_entity_constant_cbase_entity,
sq_create_script_instance: val.sq_create_script_instance,
sq_pushnewstructinstance: val.sq_pushnewstructinstance,
sq_sealstructslot: val.sq_sealstructslot,
}
Expand Down Expand Up @@ -233,6 +237,7 @@ impl From<&ServerSQFunctions> for SquirrelFunctions {
sq_getfunction: val.sq_getfunction,
sq_getentityfrominstance: val.sq_getentityfrominstance,
sq_get_entity_constant_cbase_entity: val.sq_get_entity_constant_cbase_entity,
sq_create_script_instance: val.sq_create_script_instance,
sq_pushnewstructinstance: val.sq_pushnewstructinstance,
sq_sealstructslot: val.sq_sealstructslot,
}
Expand Down
11 changes: 6 additions & 5 deletions src/high/engine/convars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
use std::{
alloc::{GlobalAlloc, Layout},
borrow::Cow,
ffi::{c_char, CStr},
ffi::{c_char, c_void, CStr},
mem,
ptr::addr_of_mut,
};
Expand Down Expand Up @@ -228,7 +228,7 @@ impl ConVarStruct {
.write(convar_classes.iconvar_vtable);

#[allow(clippy::crosspointer_transmute)] // its what c++ this->convar_malloc is
(convar_classes.convar_malloc)(mem::transmute(addr_of_mut!((*convar).m_pMalloc)), 0, 0); // Allocate new memory for ConVar.
(convar_classes.convar_malloc)(addr_of_mut!((*convar).m_pMalloc).cast(), 0, 0); // Allocate new memory for ConVar.

convar
};
Expand Down Expand Up @@ -426,7 +426,7 @@ impl ConVarStruct {
let set_value_int = vtable_array[14];
// the index for SetValue for ints; weird stuff

let func = mem::transmute::<_, fn(*const ConVar, i32)>(set_value_int);
let func = mem::transmute::<*const c_void, fn(*const ConVar, i32)>(set_value_int);

func(self.inner, new_value)
}
Expand All @@ -449,7 +449,7 @@ impl ConVarStruct {
let set_value_float = vtable_array[13];
// the index for SetValue for floats; weird stuff

let func = mem::transmute::<_, fn(*const ConVar, f32)>(set_value_float);
let func = mem::transmute::<*const c_void, fn(*const ConVar, f32)>(set_value_float);

func(self.inner, new_value)
}
Expand All @@ -469,7 +469,8 @@ impl ConVarStruct {
let set_value_string = vtable_array[12];
// the index for SetValue for strings; weird stuff

let func = mem::transmute::<_, fn(*const ConVar, *const c_char)>(set_value_string);
let func =
mem::transmute::<*const c_void, fn(*const ConVar, *const c_char)>(set_value_string);

let string_value = to_cstring(new_value.as_ref());
func(self.inner, string_value.as_ptr())
Expand Down
Loading

0 comments on commit e29d3c2

Please sign in to comment.