From aa0a34afeef91d11c5042be4e9bc69f8685efd6a Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Tue, 14 Jan 2025 18:28:06 +0000 Subject: [PATCH] Add support for OpenMW .omwaddon and .omwgame plugins --- ffi/src/constants.rs | 4 ++ ffi/src/helpers.rs | 1 + ffi/tests/ffi.cpp | 1 + src/function/eval.rs | 2 +- src/function/path.rs | 111 +++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 2 + 6 files changed, 120 insertions(+), 1 deletion(-) diff --git a/ffi/src/constants.rs b/ffi/src/constants.rs index 8cb80a9..5c190cc 100644 --- a/ffi/src/constants.rs +++ b/ffi/src/constants.rs @@ -76,3 +76,7 @@ pub static LCI_GAME_FALLOUT_4_VR: c_int = 7; /// Game code for Starfield. #[no_mangle] pub static LCI_GAME_STARFIELD: c_int = 9; + +/// Game code for OpenMW. +#[no_mangle] +pub static LCI_GAME_OPENMW: c_int = 10; diff --git a/ffi/src/helpers.rs b/ffi/src/helpers.rs index ef5229f..8e6c992 100644 --- a/ffi/src/helpers.rs +++ b/ffi/src/helpers.rs @@ -33,6 +33,7 @@ fn map_error(err: &Error) -> c_int { pub fn map_game_type(game_type: c_int) -> Result { match game_type { + x if x == LCI_GAME_OPENMW => Ok(GameType::OpenMW), x if x == LCI_GAME_MORROWIND => Ok(GameType::Morrowind), x if x == LCI_GAME_OBLIVION => Ok(GameType::Oblivion), x if x == LCI_GAME_SKYRIM => Ok(GameType::Skyrim), diff --git a/ffi/tests/ffi.cpp b/ffi/tests/ffi.cpp index fadcaf8..6374f1f 100644 --- a/ffi/tests/ffi.cpp +++ b/ffi/tests/ffi.cpp @@ -22,6 +22,7 @@ void test_game_id_values() { assert(LCI_GAME_FALLOUT_4 == 6); assert(LCI_GAME_FALLOUT_4_VR == 7); assert(LCI_GAME_STARFIELD == 9); + assert(LCI_GAME_OPENMW == 10); } void test_lci_condition_parse() { diff --git a/src/function/eval.rs b/src/function/eval.rs index fcc07a9..6a84fdd 100644 --- a/src/function/eval.rs +++ b/src/function/eval.rs @@ -123,7 +123,7 @@ fn evaluate_is_master(state: &State, file_path: &Path) -> Result { use esplugin::GameId; let game_id = match state.game_type { - GameType::Morrowind => GameId::Morrowind, + GameType::Morrowind | GameType::OpenMW => GameId::Morrowind, GameType::Oblivion => GameId::Oblivion, GameType::Skyrim => GameId::Skyrim, GameType::SkyrimSE | GameType::SkyrimVR => GameId::SkyrimSE, diff --git a/src/function/path.rs b/src/function/path.rs index 6c2bace..508f3d2 100644 --- a/src/function/path.rs +++ b/src/function/path.rs @@ -12,6 +12,9 @@ fn is_unghosted_plugin_file_extension(game_type: GameType, extension: &OsStr) -> extension.eq_ignore_ascii_case("esp") || extension.eq_ignore_ascii_case("esm") || (game_type.supports_light_plugins() && extension.eq_ignore_ascii_case("esl")) + || (game_type == GameType::OpenMW + && (extension.eq_ignore_ascii_case("omwaddon") + || extension.eq_ignore_ascii_case("omwgame"))) } fn has_unghosted_plugin_file_extension(game_type: GameType, path: &Path) -> bool { @@ -97,6 +100,10 @@ mod tests { fn is_unghosted_plugin_file_extension_should_be_true_for_esp_for_all_game_types() { let extension = OsStr::new("Esp"); + assert!(is_unghosted_plugin_file_extension( + GameType::OpenMW, + extension + )); assert!(is_unghosted_plugin_file_extension( GameType::Morrowind, extension @@ -139,6 +146,10 @@ mod tests { fn is_unghosted_plugin_file_extension_should_be_true_for_esm_for_all_game_types() { let extension = OsStr::new("Esm"); + assert!(is_unghosted_plugin_file_extension( + GameType::OpenMW, + extension + )); assert!(is_unghosted_plugin_file_extension( GameType::Morrowind, extension @@ -203,6 +214,10 @@ mod tests { fn is_unghosted_plugin_file_extension_should_be_false_for_esl_for_tes3_to_5_fo3_and_fonv() { let extension = OsStr::new("Esl"); + assert!(!is_unghosted_plugin_file_extension( + GameType::OpenMW, + extension + )); assert!(!is_unghosted_plugin_file_extension( GameType::Morrowind, extension @@ -225,10 +240,102 @@ mod tests { )); } + #[test] + fn is_unghosted_plugin_file_extension_should_be_true_for_omwaddon_and_only_openmw() { + let extension = OsStr::new("omwaddon"); + + assert!(is_unghosted_plugin_file_extension(GameType::OpenMW, extension)); + + assert!(!is_unghosted_plugin_file_extension( + GameType::Morrowind, + extension + )); + assert!(!is_unghosted_plugin_file_extension( + GameType::Oblivion, + extension + )); + assert!(!is_unghosted_plugin_file_extension( + GameType::Skyrim, + extension + )); + assert!(!is_unghosted_plugin_file_extension( + GameType::SkyrimSE, + extension + )); + assert!(!is_unghosted_plugin_file_extension( + GameType::SkyrimVR, + extension + )); + assert!(!is_unghosted_plugin_file_extension( + GameType::Fallout3, + extension + )); + assert!(!is_unghosted_plugin_file_extension( + GameType::FalloutNV, + extension + )); + assert!(!is_unghosted_plugin_file_extension( + GameType::Fallout4, + extension + )); + assert!(!is_unghosted_plugin_file_extension( + GameType::Fallout4VR, + extension + )); + } + + #[test] + fn is_unghosted_plugin_file_extension_should_be_true_for_omwgame_and_only_openmw() { + let extension = OsStr::new("omwgame"); + + assert!(is_unghosted_plugin_file_extension(GameType::OpenMW, extension)); + + assert!(!is_unghosted_plugin_file_extension( + GameType::Morrowind, + extension + )); + assert!(!is_unghosted_plugin_file_extension( + GameType::Oblivion, + extension + )); + assert!(!is_unghosted_plugin_file_extension( + GameType::Skyrim, + extension + )); + assert!(!is_unghosted_plugin_file_extension( + GameType::SkyrimSE, + extension + )); + assert!(!is_unghosted_plugin_file_extension( + GameType::SkyrimVR, + extension + )); + assert!(!is_unghosted_plugin_file_extension( + GameType::Fallout3, + extension + )); + assert!(!is_unghosted_plugin_file_extension( + GameType::FalloutNV, + extension + )); + assert!(!is_unghosted_plugin_file_extension( + GameType::Fallout4, + extension + )); + assert!(!is_unghosted_plugin_file_extension( + GameType::Fallout4VR, + extension + )); + } + #[test] fn is_unghosted_plugin_file_extension_should_be_false_for_ghost_for_all_game_types() { let extension = OsStr::new("Ghost"); + assert!(!is_unghosted_plugin_file_extension( + GameType::OpenMW, + extension + )); assert!(!is_unghosted_plugin_file_extension( GameType::Morrowind, extension @@ -271,6 +378,10 @@ mod tests { fn is_unghosted_plugin_file_extension_should_be_false_for_non_esp_esm_esl_for_all_game_types() { let extension = OsStr::new("txt"); + assert!(!is_unghosted_plugin_file_extension( + GameType::OpenMW, + extension + )); assert!(!is_unghosted_plugin_file_extension( GameType::Morrowind, extension diff --git a/src/lib.rs b/src/lib.rs index c8b9c5c..5c21005 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -36,6 +36,7 @@ pub enum GameType { Fallout4VR, Morrowind, Starfield, + OpenMW, } impl GameType { @@ -316,6 +317,7 @@ mod tests { #[test] fn game_type_supports_light_master_should_be_false_for_tes3_to_5_fo3_and_fonv() { + assert!(!GameType::OpenMW.supports_light_plugins()); assert!(!GameType::Morrowind.supports_light_plugins()); assert!(!GameType::Oblivion.supports_light_plugins()); assert!(!GameType::Skyrim.supports_light_plugins());