diff --git a/Cargo.lock b/Cargo.lock index 0aacccfb..a67b585c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -418,7 +418,6 @@ dependencies = [ "libc", "libloading", "log", - "once_cell", "regex-cursor", "regex-lite", "serde", @@ -436,7 +435,6 @@ dependencies = [ "ctor", "dobby-rs", "lovely-core", - "once_cell", ] [[package]] @@ -447,7 +445,6 @@ dependencies = [ "itertools", "libc", "lovely-core", - "once_cell", "retour", "widestring", "windows", diff --git a/crates/lovely-core/Cargo.toml b/crates/lovely-core/Cargo.toml index 133361ae..1feef11e 100644 --- a/crates/lovely-core/Cargo.toml +++ b/crates/lovely-core/Cargo.toml @@ -8,7 +8,6 @@ dirs = "5.0.1" getargs = "0.5.0" libc = "0.2.153" libloading = "0.8.3" -once_cell = "1.19.0" toml = "0.8.10" serde = { version = "1.0.197", features = ["derive"] } sha2 = "0.10.8" diff --git a/crates/lovely-core/src/log.rs b/crates/lovely-core/src/log.rs index 15d51355..50daba2b 100644 --- a/crates/lovely-core/src/log.rs +++ b/crates/lovely-core/src/log.rs @@ -1,7 +1,7 @@ -use std::sync::RwLock; use std::path::Path; use std::io::Write; use std::fs::{self, File}; +use std::sync::{OnceLock, RwLock}; use chrono::Local; @@ -9,9 +9,8 @@ use chrono::Local; pub use log::{info, error, warn, debug, trace, LevelFilter}; use log::{Level, Log, Metadata, Record, SetLoggerError}; -use once_cell::sync::OnceCell; -static LOGGER: OnceCell = OnceCell::new(); +static LOGGER: OnceLock = OnceLock::new(); struct LovelyLogger { use_console: bool, diff --git a/crates/lovely-core/src/patch/vars.rs b/crates/lovely-core/src/patch/vars.rs index 74452466..04d44e55 100644 --- a/crates/lovely-core/src/patch/vars.rs +++ b/crates/lovely-core/src/patch/vars.rs @@ -1,13 +1,12 @@ -use std::collections::HashMap; +use std::{collections::HashMap, sync::LazyLock}; -use once_cell::sync::Lazy; use regex_lite::{Regex, Captures}; /// Apply valid var interpolations to the provided line. /// Interpolation targets are of form {{lovely:VAR_NAME}}. pub fn apply_var_interp(line: &mut String, vars: &HashMap) { // Cache the compiled regex. - let re: Lazy = Lazy::new(|| Regex::new(r"\{\{lovely:(\w+)\}\}").unwrap()); + let re: LazyLock = LazyLock::new(|| Regex::new(r"\{\{lovely:(\w+)\}\}").unwrap()); let line_replaced = re.replace_all(line, |captures: &Captures| { let (_, [var]) = captures.extract(); diff --git a/crates/lovely-core/src/sys.rs b/crates/lovely-core/src/sys.rs index 5fa917ae..2d46e8d9 100644 --- a/crates/lovely-core/src/sys.rs +++ b/crates/lovely-core/src/sys.rs @@ -2,12 +2,12 @@ use std::{ collections::VecDeque, ffi::{c_void, CString}, ptr, slice, + sync::LazyLock, }; use itertools::Itertools; use libloading::{Library, Symbol}; use log::info; -use once_cell::sync::Lazy; pub const LUA_GLOBALSINDEX: isize = -10002; @@ -17,61 +17,64 @@ pub const LUA_TBOOLEAN: isize = 1; pub type LuaState = c_void; #[cfg(target_os = "windows")] -pub static LUA_LIB: Lazy = Lazy::new(|| unsafe { Library::new("lua51.dll").unwrap() }); +pub static LUA_LIB: LazyLock = + LazyLock::new(|| unsafe { Library::new("lua51.dll").unwrap() }); #[cfg(target_os = "macos")] -pub static LUA_LIB: Lazy = - Lazy::new(|| unsafe { Library::new("../Frameworks/Lua.framework/Versions/A/Lua").unwrap() }); +pub static LUA_LIB: LazyLock = LazyLock::new(|| unsafe { + Library::new("../Frameworks/Lua.framework/Versions/A/Lua").unwrap() +}); -pub static lua_call: Lazy> = - Lazy::new(|| unsafe { LUA_LIB.get(b"lua_call").unwrap() }); +pub static lua_call: LazyLock> = + LazyLock::new(|| unsafe { LUA_LIB.get(b"lua_call").unwrap() }); #[cfg(target_os = "linux")] -pub static LUA_LIB: Lazy = - Lazy::new(|| unsafe { Library::new("libluajit-5.1.so.2").unwrap() }); +pub static LUA_LIB: LazyLock = + LazyLock::new(|| unsafe { Library::new("libluajit-5.1.so.2").unwrap() }); -pub static lua_pcall: Lazy< +pub static lua_pcall: LazyLock< Symbol isize>, -> = Lazy::new(|| unsafe { LUA_LIB.get(b"lua_pcall").unwrap() }); +> = LazyLock::new(|| unsafe { LUA_LIB.get(b"lua_pcall").unwrap() }); -pub static lua_getfield: Lazy> = - Lazy::new(|| unsafe { LUA_LIB.get(b"lua_getfield").unwrap() }); +pub static lua_getfield: LazyLock> = + LazyLock::new(|| unsafe { LUA_LIB.get(b"lua_getfield").unwrap() }); -pub static lua_setfield: Lazy> = - Lazy::new(|| unsafe { LUA_LIB.get(b"lua_setfield").unwrap() }); +pub static lua_setfield: LazyLock> = + LazyLock::new(|| unsafe { LUA_LIB.get(b"lua_setfield").unwrap() }); -pub static lua_gettop: Lazy isize>> = - Lazy::new(|| unsafe { LUA_LIB.get(b"lua_gettop").unwrap() }); +pub static lua_gettop: LazyLock isize>> = + LazyLock::new(|| unsafe { LUA_LIB.get(b"lua_gettop").unwrap() }); -pub static lua_settop: Lazy isize>> = - Lazy::new(|| unsafe { LUA_LIB.get(b"lua_settop").unwrap() }); +pub static lua_settop: LazyLock isize>> = + LazyLock::new(|| unsafe { LUA_LIB.get(b"lua_settop").unwrap() }); -pub static lua_pushvalue: Lazy> = - Lazy::new(|| unsafe { LUA_LIB.get(b"lua_pushvalue").unwrap() }); +pub static lua_pushvalue: LazyLock> = + LazyLock::new(|| unsafe { LUA_LIB.get(b"lua_pushvalue").unwrap() }); -pub static lua_pushcclosure: Lazy< +pub static lua_pushcclosure: LazyLock< Symbol, -> = Lazy::new(|| unsafe { LUA_LIB.get(b"lua_pushcclosure").unwrap() }); +> = LazyLock::new(|| unsafe { LUA_LIB.get(b"lua_pushcclosure").unwrap() }); -pub static lua_tolstring: Lazy< +pub static lua_tolstring: LazyLock< Symbol *const char>, -> = Lazy::new(|| unsafe { LUA_LIB.get(b"lua_tolstring").unwrap() }); +> = LazyLock::new(|| unsafe { LUA_LIB.get(b"lua_tolstring").unwrap() }); -pub static lua_toboolean: Lazy bool>> = - Lazy::new(|| unsafe { LUA_LIB.get(b"lua_toboolean").unwrap() }); +pub static lua_toboolean: LazyLock bool>> = + LazyLock::new(|| unsafe { LUA_LIB.get(b"lua_toboolean").unwrap() }); -pub static lua_topointer: Lazy< +pub static lua_topointer: LazyLock< Symbol *const c_void>, -> = Lazy::new(|| unsafe { LUA_LIB.get(b"lua_topointer").unwrap() }); +> = LazyLock::new(|| unsafe { LUA_LIB.get(b"lua_topointer").unwrap() }); -pub static lua_type: Lazy isize>> = - Lazy::new(|| unsafe { LUA_LIB.get(b"lua_type").unwrap() }); +pub static lua_type: LazyLock isize>> = + LazyLock::new(|| unsafe { LUA_LIB.get(b"lua_type").unwrap() }); -pub static lua_typename: Lazy *const char>> = - Lazy::new(|| unsafe { LUA_LIB.get(b"lua_typename").unwrap() }); +pub static lua_typename: LazyLock< + Symbol *const char>, +> = LazyLock::new(|| unsafe { LUA_LIB.get(b"lua_typename").unwrap() }); -pub static lua_isstring: Lazy isize>> = - Lazy::new(|| unsafe { LUA_LIB.get(b"lua_isstring").unwrap() }); +pub static lua_isstring: LazyLock isize>> = + LazyLock::new(|| unsafe { LUA_LIB.get(b"lua_isstring").unwrap() }); /// Load the provided buffer as a lua module with the specified name. /// # Safety diff --git a/crates/lovely-unix/Cargo.toml b/crates/lovely-unix/Cargo.toml index a2767c25..b0ae408c 100644 --- a/crates/lovely-unix/Cargo.toml +++ b/crates/lovely-unix/Cargo.toml @@ -10,6 +10,5 @@ crate-type = ["cdylib"] [dependencies] lovely-core = { version ="0.7.1", path = "../lovely-core" } -once_cell = "1.19.0" dobby-rs = "0.1.0" ctor = "0.2.7" diff --git a/crates/lovely-unix/src/lib.rs b/crates/lovely-unix/src/lib.rs index 64d9ce86..c6cd90d5 100644 --- a/crates/lovely-unix/src/lib.rs +++ b/crates/lovely-unix/src/lib.rs @@ -1,15 +1,14 @@ use lovely_core::log::*; use lovely_core::sys::{LuaState, LUA_LIB}; -use std::{env, ffi::c_void, mem, panic}; +use std::{env, ffi::c_void, mem, panic, sync::{LazyLock, OnceLock}}; use lovely_core::Lovely; -use once_cell::sync::{Lazy, OnceCell}; -static RUNTIME: OnceCell = OnceCell::new(); +static RUNTIME: OnceLock = OnceLock::new(); -static RECALL: Lazy< +static RECALL: LazyLock< unsafe extern "C" fn(*mut LuaState, *const u8, isize, *const u8, *const u8) -> u32, -> = Lazy::new(|| unsafe { +> = LazyLock::new(|| unsafe { let lua_loadbufferx: unsafe extern "C" fn( *mut LuaState, *const u8, @@ -33,7 +32,7 @@ unsafe extern "C" fn luaL_loadbuffer( size: isize, name_ptr: *const u8, ) -> u32 { - let rt = RUNTIME.get_unchecked(); + let rt = RUNTIME.get().unwrap_unchecked(); rt.apply_buffer_patches(state, buf_ptr, size, name_ptr, std::ptr::null()) } @@ -44,7 +43,7 @@ unsafe extern "C" fn lua_loadbufferx_detour( name_ptr: *const u8, mode_ptr: *const u8, ) -> u32 { - let rt = RUNTIME.get_unchecked(); + let rt = RUNTIME.get().unwrap_unchecked(); rt.apply_buffer_patches(state, buf_ptr, size, name_ptr, mode_ptr) } diff --git a/crates/lovely-win/Cargo.toml b/crates/lovely-win/Cargo.toml index a7f307c3..37648da7 100644 --- a/crates/lovely-win/Cargo.toml +++ b/crates/lovely-win/Cargo.toml @@ -12,7 +12,6 @@ lovely-core = { version ="0.7.1", path = "../lovely-core" } itertools = "0.13.0" libc = "0.2.141" -once_cell = "1.19.0" widestring = "1.0.2" diff --git a/crates/lovely-win/src/lib.rs b/crates/lovely-win/src/lib.rs index ec34c73b..6f99bede 100644 --- a/crates/lovely-win/src/lib.rs +++ b/crates/lovely-win/src/lib.rs @@ -1,6 +1,7 @@ use std::env; use std::ffi::c_void; use std::panic; +use std::sync::{LazyLock, OnceLock}; use itertools::Itertools; use lovely_core::log::*; @@ -8,8 +9,6 @@ use lovely_core::sys::LuaState; use lovely_core::Lovely; use lovely_core::LOVELY_VERSION; -use once_cell::sync::Lazy; -use once_cell::sync::OnceCell; use retour::static_detour; use widestring::U16CString; use windows::core::{s, w, PCWSTR}; @@ -18,14 +17,14 @@ use windows::Win32::System::Console::{AllocConsole, SetConsoleTitleW}; use windows::Win32::System::LibraryLoader::{GetProcAddress, LoadLibraryW}; use windows::Win32::UI::WindowsAndMessaging::{MessageBoxW, MESSAGEBOX_STYLE}; -static RUNTIME: OnceCell = OnceCell::new(); +static RUNTIME: OnceLock = OnceLock::new(); static_detour! { pub static LuaLoadbufferx_Detour: unsafe extern "C" fn(*mut LuaState, *const u8, isize, *const u8,*const u8) -> u32; } -static WIN_TITLE: Lazy = - Lazy::new(|| U16CString::from_str(format!("Lovely {LOVELY_VERSION}")).unwrap()); +static WIN_TITLE: LazyLock = + LazyLock::new(|| U16CString::from_str(format!("Lovely {LOVELY_VERSION}")).unwrap()); unsafe extern "C" fn lua_loadbufferx_detour( state: *mut LuaState, @@ -34,7 +33,7 @@ unsafe extern "C" fn lua_loadbufferx_detour( name_ptr: *const u8, mode_ptr: *const u8, ) -> u32 { - let rt = RUNTIME.get_unchecked(); + let rt = RUNTIME.get().unwrap_unchecked(); rt.apply_buffer_patches(state, buf_ptr, size, name_ptr, mode_ptr) }