Skip to content

Commit 02db33d

Browse files
committed
refactor: 完全移除 mods.ini 支持,不自动生成无用目录
1 parent f8e2d49 commit 02db33d

3 files changed

Lines changed: 10 additions & 62 deletions

File tree

src/loader/metadata.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use super::state::HMODULE;
1010
#[derive(Default)]
1111
pub struct ModMetadata {
1212
pub version: Option<String>,
13-
pub author: Option<String>,
1413
pub min_loader_version: Option<String>,
1514
}
1615

@@ -27,7 +26,6 @@ unsafe fn read_string_export(handle: HMODULE, export: &'static [u8]) -> Option<S
2726
pub unsafe fn read_metadata(handle: HMODULE) -> ModMetadata {
2827
ModMetadata {
2928
version: read_string_export(handle, b"chumod_version\0"),
30-
author: read_string_export(handle, b"chumod_author\0"),
3129
min_loader_version: read_string_export(handle, b"chumod_min_loader_version\0")
3230
.filter(|v| !v.trim().is_empty()),
3331
}

src/loader/mod.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@ use self::dependency::{read_dependencies, sort_mods, PendingMod};
3131
use self::log::{log_info, write_log_inner, write_log_variadic};
3232
use self::metadata::{read_metadata, should_load_metadata};
3333
use self::pe::{get_self_base_dir, parse_game_info, read_game_version};
34-
use self::scanner::{ensure_mods_layout, scan_manifest_files, scan_mod_files};
34+
use self::scanner::{ensure_mods_dir, scan_manifest_files, scan_mod_files};
3535
use self::seh::{call_mod_init, call_mod_on_ready, call_mod_shutdown};
3636
use self::state::{LoadedMod, STATE};
3737

3838
extern "system" {
39-
fn CreateDirectoryA(path: *const u8, security: *const std::ffi::c_void) -> i32;
4039
fn FreeLibrary(module: *mut std::ffi::c_void) -> i32;
4140
}
4241

@@ -77,9 +76,8 @@ pub unsafe fn load_mods() {
7776
let game_version_c = std::ffi::CString::new(game_version).unwrap_or_default();
7877
api_impl::set_rtti_info(rdata_base, rdata_size as usize, text_base);
7978

80-
let (mods_dir, ini_path) = ensure_mods_layout(&base_dir);
79+
let mods_dir = ensure_mods_dir(&base_dir);
8180
log_info(&format!("scan mods dir: {}", mods_dir));
82-
log_info(&format!("config file: {}", ini_path));
8381
let manifests = scan_manifest_files(&base_dir);
8482
{
8583
let mut state = STATE.lock().unwrap();
@@ -90,7 +88,7 @@ pub unsafe fn load_mods() {
9088
}
9189

9290
let mut pending_mods = Vec::new();
93-
for (mod_name, full_path) in scan_mod_files(&mods_dir, &ini_path) {
91+
for (mod_name, full_path) in scan_mod_files(&mods_dir) {
9492
let full_path_c = format!("{}\0", full_path);
9593
let mod_handle = LoadLibraryA(full_path_c.as_ptr());
9694
if mod_handle.is_null() {
@@ -117,13 +115,8 @@ pub unsafe fn load_mods() {
117115
FreeLibrary(mod_handle);
118116
continue;
119117
}
120-
if metadata.version.is_some() || metadata.author.is_some() {
121-
log_info(&format!(
122-
"mod metadata: {} version={} author={}",
123-
display_name,
124-
metadata.version.as_deref().unwrap_or("unknown"),
125-
metadata.author.as_deref().unwrap_or("unknown")
126-
));
118+
if let Some(version) = &metadata.version {
119+
log_info(&format!("mod: {} v{}", display_name, version));
127120
}
128121

129122
let dependencies = read_dependencies(mod_handle);

src/loader/scanner.rs

Lines changed: 5 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::ffi::{c_char, c_void, CStr};
22

3-
use windows_sys::Win32::Foundation::{HANDLE, INVALID_HANDLE_VALUE};
3+
use windows_sys::Win32::Foundation::INVALID_HANDLE_VALUE;
44
use windows_sys::Win32::Storage::FileSystem::{
55
FindClose, FindFirstFileA, FindNextFileA, GetFileAttributesA, FILE_ATTRIBUTE_DIRECTORY,
66
INVALID_FILE_ATTRIBUTES, WIN32_FIND_DATAA,
@@ -10,59 +10,21 @@ use super::log::log_info;
1010

1111
extern "system" {
1212
fn CreateDirectoryA(path: *const u8, security: *const c_void) -> i32;
13-
fn GetPrivateProfileStringA(
14-
app: *const u8,
15-
key: *const u8,
16-
default: *const u8,
17-
ret: *mut u8,
18-
size: u32,
19-
file: *const u8,
20-
) -> u32;
2113
}
2214

23-
pub fn ensure_mods_layout(base_dir: &str) -> (String, String) {
15+
pub fn ensure_mods_dir(base_dir: &str) -> String {
2416
unsafe {
2517
let mods_dir = format!("{}\\mods", base_dir);
26-
let ini_path = format!("{}\\mods.ini", base_dir);
27-
2818
let mods_dir_c = format!("{}\0", mods_dir);
2919
if GetFileAttributesA(mods_dir_c.as_ptr()) == INVALID_FILE_ATTRIBUTES {
3020
CreateDirectoryA(mods_dir_c.as_ptr(), std::ptr::null());
3121
log_info(&format!("created mods dir: {}", mods_dir));
3222
}
33-
34-
(mods_dir, ini_path)
23+
mods_dir
3524
}
3625
}
3726

38-
pub fn is_mod_enabled(ini_path: &str, mod_name: &str) -> bool {
39-
unsafe {
40-
let mut value = [0u8; 32];
41-
let section = b"mods\0";
42-
let ini_cstr = format!("{}\0", ini_path);
43-
let mod_cstr = format!("{}\0", mod_name);
44-
let empty = b"\0";
45-
46-
GetPrivateProfileStringA(
47-
section.as_ptr(),
48-
mod_cstr.as_ptr(),
49-
empty.as_ptr(),
50-
value.as_mut_ptr(),
51-
value.len() as u32,
52-
ini_cstr.as_ptr(),
53-
);
54-
55-
if value[0] == 0 {
56-
return true;
57-
}
58-
59-
let s = CStr::from_ptr(value.as_ptr() as *const c_char);
60-
s.to_str()
61-
.map_or(true, |v| v.parse::<i32>().unwrap_or(1) != 0)
62-
}
63-
}
64-
65-
pub fn scan_mod_files(mods_dir: &str, ini_path: &str) -> Vec<(String, String)> {
27+
pub fn scan_mod_files(mods_dir: &str) -> Vec<(String, String)> {
6628
unsafe {
6729
let pattern = format!("{}\\*.dll\0", mods_dir);
6830
let mut find_data: WIN32_FIND_DATAA = std::mem::zeroed();
@@ -78,12 +40,7 @@ pub fn scan_mod_files(mods_dir: &str, ini_path: &str) -> Vec<(String, String)> {
7840
let mod_name_cstr = CStr::from_ptr(find_data.cFileName.as_ptr() as *const c_char);
7941
let mod_name = mod_name_cstr.to_string_lossy().into_owned();
8042
let full_path = format!("{}\\{}", mods_dir, mod_name);
81-
82-
if is_mod_enabled(ini_path, &mod_name) {
83-
mods.push((mod_name, full_path));
84-
} else {
85-
log_info(&format!("mod disabled: {}", full_path));
86-
}
43+
mods.push((mod_name, full_path));
8744
}
8845

8946
if FindNextFileA(find_handle, &mut find_data) == 0 {

0 commit comments

Comments
 (0)