Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.

Commit ea39387

Browse files
yogwoggfvurvdev
andauthored
Fix IMaterialSystem vtable offsets (#15)
Co-authored-by: Vurv <56230599+Vurv78@users.noreply.github.com>
1 parent 934a049 commit ea39387

3 files changed

Lines changed: 25 additions & 12 deletions

File tree

examples/interfaces/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## ``interfaces``
2+
Generic binary module to display usage of a few source interfaces.
3+
4+
## interfaces.reloadTextures()
5+
Reloads gmod's texture system

examples/interfaces/src/lib.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
11
use rglua::prelude::*;
2-
use rglua::interface::{self, LuaShared};
2+
use rglua::interface;
33

4-
#[derive(Debug, thiserror::Error)]
5-
enum GenericError {
6-
#[error("Couldn't get interface {0}")]
7-
NoInterface(String),
4+
#[lua_function]
5+
fn reload_textures(_l: LuaState) -> Result<i32, interface::Error> {
6+
let matsys = iface!(MaterialSystem)?;
7+
matsys.ReloadTextures();
88

9-
#[error("Couldn't get interface as reference {0}")]
10-
AsMut(String)
9+
Ok(0)
1110
}
1211

1312
#[gmod_open]
14-
fn open(l: LuaState) -> Result<i32, GenericError> {
13+
fn open(l: LuaState) -> Result<i32, interface::Error> {
1514
// Access the lua state when you aren't directly given it.
1615
let lua_shared = iface!(LuaShared)?;
17-
let menu = unsafe { lua_shared.GetLuaInterface(2).as_mut() }
16+
17+
// 0 to get client state. this will error if you try and run the binary module on the server or menu realms.
18+
let client = unsafe { lua_shared.GetLuaInterface(0).as_mut() }
1819
.ok_or(interface::Error::AsMut)?;
1920

20-
printgm!(menu.base as _, "Hello from ILuaShared!");
21+
printgm!(client.base as _, "Hello from ILuaShared!");
22+
23+
let lib = reg! [
24+
"reloadTextures" => reload_textures
25+
];
26+
27+
luaL_register(l, cstr!("interfaces"), lib.as_ptr());
28+
2129
Ok(0)
2230
}
2331

rglua/src/interface/materials.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub type MaterialHandle = c_ushort;
3232
/// "materialsystem.dll"
3333
#[vtable]
3434
pub struct MaterialSystem {
35-
#[offset(70)]
35+
#[offset(72)]
3636
pub ReloadTextures: extern "C" fn(),
3737
pub ReloadMaterials: extern "C" fn(pSubString: *const c_char),
3838

@@ -45,7 +45,7 @@ pub struct MaterialSystem {
4545
complain_prefix: *const c_char
4646
) -> *mut c_void,
4747

48-
#[offset(75)]
48+
#[offset(77)]
4949
pub FirstMaterial: extern "C" fn() -> MaterialHandle,
5050
pub NextMaterial: extern "C" fn(handle: MaterialHandle) -> MaterialHandle,
5151
pub InvalidMaterial: extern "C" fn() -> MaterialHandle,

0 commit comments

Comments
 (0)