commonlibsse_ng\skse\impls/
stab.rs

1// https://github.com/alandtse/CommonLibVR/blob/ng/include/SKSE/Impl/Stubs.h
2#![allow(improper_ctypes)]
3#![allow(non_camel_case_types)]
4#![allow(non_snake_case)]
5#![allow(non_upper_case_globals)]
6
7use core::ffi::{c_char, c_void};
8
9/// Represents a handle for a plugin, which is a 32-bit unsigned integer.
10///
11/// Internally implemented, this number represents the index of the order in which plugins are loaded.
12#[repr(transparent)]
13#[derive(Debug, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
14pub struct PluginHandle(pub u32);
15
16/// The invalid plugin handle value, set to the maximum possible `u32` value.
17pub const INVALID_PLUGIN_HANDLE: PluginHandle = PluginHandle(u32::MAX);
18
19/// Structure representing the information about a plugin.
20#[repr(C)]
21#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
22pub struct PluginInfo {
23    /// The version of the plugin information structure.
24    pub infoVersion: u32,
25    /// A pointer to a C-style string containing the plugin's name.
26    pub name: *const c_char,
27    /// The version of the plugin.
28    pub version: u32,
29}
30
31impl PluginInfo {
32    /// Plugin information version.
33    pub const VERSION: u32 = 1;
34}
35
36impl Default for PluginInfo {
37    /// Creates a new instance of `PluginInfo` with default values.
38    fn default() -> Self {
39        Self { infoVersion: 0, name: c"".as_ptr(), version: 0 }
40    }
41}
42
43/// The main SKSE interface structure that provides access to various SKSE functionality.
44#[repr(C)]
45#[derive(Debug)]
46pub struct SKSEInterface {
47    /// The version of SKSE being used.
48    pub(crate) skseVersion: u32,
49    /// The version of the runtime environment.
50    pub(crate) runtimeVersion: u32,
51    /// The version of the editor environment.
52    pub(crate) editorVersion: u32,
53    /// A flag indicating whether the environment is the editor or not.
54    pub(crate) isEditor: u32,
55    /// Function for querying interface.
56    pub(crate) QueryInterface: unsafe extern "C" fn(u32) -> *mut c_void,
57    /// Function to get the plugin handle.
58    pub(crate) GetPluginHandle: unsafe extern "C" fn() -> PluginHandle,
59    /// Function to get the release index.
60    pub(crate) GetReleaseIndex: unsafe extern "C" fn() -> u32,
61    /// Function to get the plugin information.
62    pub(crate) GetPluginInfo: unsafe extern "C" fn(*const c_char) -> *const PluginInfo,
63}
64
65/// Available for `SKSEInterface::QueryInterface` id.
66#[repr(u32)]
67#[derive(Debug)]
68pub enum InterfaceKind {
69    Invalid = 0,
70    ScaleForm,
71    Papyrus,
72    Serialization,
73    Task,
74    Messaging,
75    Object,
76    Trampoline,
77    /// Max
78    Total,
79}
80
81/// The messaging interface for SKSE that allows plugin communication.
82#[repr(C)]
83#[derive(Debug)]
84pub struct SKSEMessagingInterface {
85    /// The version of the messaging interface.
86    pub interfaceVersion: u32,
87    /// Registers a listener for messages.
88    pub RegisterListener: unsafe extern "C" fn(PluginHandle, *const c_char, *mut c_void) -> bool,
89    /// Dispatches a message.
90    pub Dispatch: unsafe extern "C" fn(PluginHandle, u32, *mut c_void, u32, *const c_char) -> bool,
91    /// Gets the event dispatcher for the messaging interface.
92    pub GetEventDispatcher: unsafe extern "C" fn(u32) -> *mut c_void,
93}
94
95/// Interface for interacting with SKSE objects.
96#[repr(C)]
97#[derive(Debug)]
98pub struct SKSEObjectInterface {
99    /// The version of the interface.
100    pub interfaceVersion: u32,
101    /// Retrieves the delay functor manager.
102    pub GetDelayFunctorManager: unsafe extern "C" fn() -> *mut SKSEDelayFunctorManager,
103    /// Retrieves the object registry.
104    pub GetObjectRegistry: unsafe extern "C" fn() -> *mut SKSEObjectRegistry,
105    /// Retrieves the persistent object storage.
106    pub GetPersistentObjectStorage: unsafe extern "C" fn() -> *mut SKSEPersistentObjectStorage,
107}
108
109/// Interface for registering papyrus scripts.
110#[repr(C)]
111#[derive(Debug)]
112pub struct SKSEPapyrusInterface {
113    /// The version of the interface.
114    pub interfaceVersion: u32,
115    /// Registers a papyrus script.
116    pub Register: unsafe extern "C" fn(*mut c_void) -> bool,
117}
118
119/// Interface for interacting with Scaleform movies in SKSE.
120#[repr(C)]
121#[derive(Debug)]
122pub struct SKSEScaleformInterface {
123    /// The version of the Scaleform interface.
124    pub interfaceVersion: u32,
125    /// Registers a Scaleform movie.
126    pub Register: unsafe extern "C" fn(*const c_char, *mut c_void) -> bool,
127    /// Registers a Scaleform movie for inventory purposes.
128    pub RegisterForInventory: unsafe extern "C" fn(*mut c_void),
129}
130
131/// Interface for managing serialization in SKSE.
132#[repr(C)]
133#[derive(Debug)]
134pub struct SKSESerializationInterface {
135    /// The version of the serialization interface.
136    pub version: u32,
137    /// Sets a unique identifier for a plugin.
138    pub SetUniqueId: unsafe extern "C" fn(PluginHandle, u32),
139    /// Sets the callback for reverting changes.
140    pub SetRevertCallback: unsafe extern "C" fn(PluginHandle, *mut c_void),
141    /// Sets the callback for saving data.
142    pub SetSaveCallback: unsafe extern "C" fn(PluginHandle, *mut c_void),
143    /// Sets the callback for loading data.
144    pub SetLoadCallback: unsafe extern "C" fn(PluginHandle, *mut c_void),
145    /// Sets the callback for handling form deletions.
146    pub SetFormDeleteCallback: unsafe extern "C" fn(PluginHandle, *mut c_void),
147    /// Writes a record to the serialization system.
148    pub WriteRecord: unsafe extern "C" fn(u32, u32, *const c_void, u32) -> bool,
149    /// Opens a record for reading or writing.
150    pub OpenRecord: unsafe extern "C" fn(u32, u32) -> bool,
151    /// Writes data to a record.
152    pub WriteRecordData: unsafe extern "C" fn(*const c_void, u32) -> bool,
153    /// Retrieves information for the next record.
154    pub GetNextRecordInfo: unsafe extern "C" fn(*mut u32, *mut u32, *mut u32) -> bool,
155    /// Reads data from a record.
156    pub ReadRecordData: unsafe extern "C" fn(*mut c_void, u32) -> u32,
157    /// Resolves a handle to a new value.
158    pub ResolveHandle: unsafe extern "C" fn(u64, *mut u64) -> bool,
159    /// Resolves a form ID to a new value.
160    pub ResolveFormId: unsafe extern "C" fn(u32, *mut u32) -> bool,
161}
162
163/// Interface for managing tasks in SKSE.
164#[repr(C)]
165#[derive(Debug)]
166pub struct SKSETaskInterface {
167    /// The version of the task interface.
168    pub interfaceVersion: u32,
169    /// Adds a task to the task queue.
170    pub AddTask: unsafe extern "C" fn(*mut c_void),
171    /// Adds a UI task to the UI task queue.
172    pub AddUiTask: unsafe extern "C" fn(*mut c_void),
173}
174
175/// Interface for managing trampoline functions in SKSE.
176#[repr(C)]
177#[derive(Debug)]
178pub struct SKSETrampolineInterface {
179    /// The version of the trampoline interface.
180    pub interfaceVersion: u32,
181    /// Allocates memory from the branch pool.
182    pub AllocateFromBranchPool: unsafe extern "C" fn(PluginHandle, usize) -> *mut c_void,
183    /// Allocates memory from the local pool.
184    pub AllocateFromLocalPool: unsafe extern "C" fn(PluginHandle, usize) -> *mut c_void,
185}
186
187/// Dummy structure representing the delay functor manager.
188#[repr(C)]
189#[derive(Debug)]
190pub struct SKSEDelayFunctorManager;
191
192/// Dummy structure representing the object registry.
193#[repr(C)]
194#[derive(Debug)]
195pub struct SKSEObjectRegistry;
196
197/// Dummy structure representing persistent object storage.
198#[repr(C)]
199#[derive(Debug)]
200pub struct SKSEPersistentObjectStorage;
201
202/// A delegate structure for task execution in SKSE.
203#[repr(C)]
204#[derive(Debug)]
205pub struct TaskDelegate {
206    pub vtbl: *const TaskDelegateVirtualTable,
207}
208
209/// A delegate structure for UI task execution in SKSE.
210#[repr(C)]
211#[derive(Debug)]
212pub struct UiDelegateV1 {
213    pub vtbl: *const UiDelegateV1VirtualTable,
214}
215
216/// Virtual table for task delegate functions.
217#[repr(C)]
218pub struct TaskDelegateVirtualTable {
219    /// Executes the task.
220    pub Run: unsafe extern "C" fn(this: *const c_void),
221    /// Disposes of the task delegate.
222    pub Dispose: fn(this: *const c_void),
223}
224
225/// Virtual table for UI task delegate functions.
226#[repr(C)]
227pub struct UiDelegateV1VirtualTable {
228    /// Executes the UI task.
229    pub Run: fn(this: *const c_void),
230    /// Disposes of the UI task delegate.
231    pub Dispose: fn(this: *const c_void),
232}