Skip to content

Commit

Permalink
Rename the override flag to the update flag
Browse files Browse the repository at this point in the history
The Creation Kit calls plugins with that flag set "Update Master file", so use similar terminology.
  • Loading branch information
Ortham committed Jun 25, 2024
1 parent 78b7a7c commit 3b5db1a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 42 deletions.
14 changes: 7 additions & 7 deletions ffi/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub unsafe extern "C" fn esp_plugin_free(plugin_ptr: *mut Plugin) {
/// * [esp_plugin_do_records_overlap]
/// * [esp_plugin_records_overlap_size]
/// * [esp_plugin_is_valid_as_light_plugin]
/// * [esp_plugin_is_valid_as_override_plugin]
/// * [esp_plugin_is_valid_as_update_plugin]
///
/// Returns [ESP_OK] if successful, otherwise an `ESP_ERROR_*` code is returned.
///
Expand Down Expand Up @@ -271,17 +271,17 @@ pub unsafe extern "C" fn esp_plugin_is_medium_plugin(
}

#[no_mangle]
pub unsafe extern "C" fn esp_plugin_is_override_plugin(
pub unsafe extern "C" fn esp_plugin_is_update_plugin(
plugin_ptr: *const Plugin,
is_override_plugin: *mut bool,
is_update_plugin: *mut bool,
) -> u32 {
panic::catch_unwind(|| {
if plugin_ptr.is_null() || is_override_plugin.is_null() {
if plugin_ptr.is_null() || is_update_plugin.is_null() {
error(ESP_ERROR_NULL_POINTER, "Null pointer passed")
} else {
let plugin = &*plugin_ptr;

*is_override_plugin = plugin.is_override_plugin();
*is_update_plugin = plugin.is_update_plugin();

ESP_OK
}
Expand Down Expand Up @@ -551,7 +551,7 @@ pub unsafe extern "C" fn esp_plugin_is_valid_as_medium_plugin(
}

#[no_mangle]
pub unsafe extern "C" fn esp_plugin_is_valid_as_override_plugin(
pub unsafe extern "C" fn esp_plugin_is_valid_as_update_plugin(
plugin_ptr: *const Plugin,
is_valid: *mut bool,
) -> u32 {
Expand All @@ -561,7 +561,7 @@ pub unsafe extern "C" fn esp_plugin_is_valid_as_override_plugin(
} else {
let plugin = &*plugin_ptr;

match plugin.is_valid_as_override_plugin() {
match plugin.is_valid_as_update_plugin() {
Ok(x) => {
*is_valid = x;
ESP_OK
Expand Down
20 changes: 10 additions & 10 deletions ffi/tests/ffi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ void test_esp_plugin_is_medium_plugin() {
esp_plugin_free(plugin);
}

void test_esp_plugin_is_override_plugin() {
printf("testing esp_plugin_is_override_plugin()...\n");
void test_esp_plugin_is_update_plugin() {
printf("testing esp_plugin_is_update_plugin()...\n");
Plugin * plugin;
// The Skyrim SE light flag is the same value as the Starfield update flag.
auto return_code = esp_plugin_new(&plugin, ESP_GAME_STARFIELD, "../../testing-plugins/SkyrimSE/Data/Blank.esl");
Expand All @@ -171,10 +171,10 @@ void test_esp_plugin_is_override_plugin() {
return_code = esp_plugin_parse(plugin, true);
assert(return_code == ESP_OK);

bool is_override_plugin;
return_code = esp_plugin_is_override_plugin(plugin, &is_override_plugin);
bool is_update_plugin;
return_code = esp_plugin_is_update_plugin(plugin, &is_update_plugin);
assert(return_code == ESP_OK);
assert(!is_override_plugin);
assert(!is_update_plugin);

esp_plugin_free(plugin);
}
Expand Down Expand Up @@ -358,8 +358,8 @@ void test_esp_plugin_is_valid_as_medium_plugin() {
esp_plugin_free(plugin);
}

void test_esp_plugin_is_valid_as_override_plugin() {
printf("testing esp_plugin_is_valid_as_override_plugin()...\n");
void test_esp_plugin_is_valid_as_update_plugin() {
printf("testing esp_plugin_is_valid_as_update_plugin()...\n");
Plugin * plugin;
auto return_code = esp_plugin_new(&plugin, ESP_GAME_STARFIELD, "../../testing-plugins/Starfield/Data/Blank.full.esm");
assert(return_code == ESP_OK);
Expand All @@ -371,7 +371,7 @@ void test_esp_plugin_is_valid_as_override_plugin() {
assert(return_code == ESP_OK);

bool is_valid;
return_code = esp_plugin_is_valid_as_override_plugin(plugin, &is_valid);
return_code = esp_plugin_is_valid_as_update_plugin(plugin, &is_valid);
assert(return_code == ESP_OK);
assert(!is_valid);

Expand All @@ -390,7 +390,7 @@ int main() {
test_esp_plugin_is_master();
test_esp_plugin_is_light_plugin();
test_esp_plugin_is_medium_plugin();
test_esp_plugin_is_override_plugin();
test_esp_plugin_is_update_plugin();
test_esp_plugin_is_valid();
test_esp_plugin_description();
test_esp_plugin_header_version();
Expand All @@ -401,7 +401,7 @@ int main() {
test_esp_plugin_records_overlap_size();
test_esp_plugin_is_valid_as_light_plugin();
test_esp_plugin_is_valid_as_medium_plugin();
test_esp_plugin_is_valid_as_override_plugin();
test_esp_plugin_is_valid_as_update_plugin();

printf("SUCCESS\n");
return 0;
Expand Down
48 changes: 23 additions & 25 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ impl Plugin {
// If the inject flag is set, it prevents the .esl extension from
// causing the light flag to be forcibly set on load.
self.is_light_flag_set()
|| (!self.is_override_flag_set() && self.has_extension(FileExtension::Esl))
|| (!self.is_update_flag_set() && self.has_extension(FileExtension::Esl))
} else {
self.is_light_flag_set() || self.has_extension(FileExtension::Esl)
}
Expand All @@ -266,10 +266,10 @@ impl Plugin {
self.is_medium_flag_set() && !self.is_light_plugin()
}

pub fn is_override_plugin(&self) -> bool {
// The override flag is unset by the game if the plugin has no masters or
pub fn is_update_plugin(&self) -> bool {
// The update flag is unset by the game if the plugin has no masters or
// if the plugin's light or medium flags are set.
self.is_override_flag_set()
self.is_update_flag_set()
&& !self.is_light_flag_set()
&& !self.is_medium_flag_set()
&& self.masters().map(|m| !m.is_empty()).unwrap_or(false)
Expand Down Expand Up @@ -443,9 +443,9 @@ impl Plugin {
}
}

pub fn is_valid_as_override_plugin(&self) -> Result<bool, Error> {
pub fn is_valid_as_update_plugin(&self) -> Result<bool, Error> {
if self.game_id == GameId::Starfield {
// If an override plugin has a record that does not override an existing record, that
// If an update plugin has a record that does not override an existing record, that
// record is placed into the mod index of the plugin's first master, which risks
// overwriting an unrelated record with the same object index, so treat that case as
// invalid.
Expand Down Expand Up @@ -503,7 +503,7 @@ impl Plugin {
self.data.header_record.header().flags() & flag != 0
}

fn is_override_flag_set(&self) -> bool {
fn is_update_flag_set(&self) -> bool {
match self.game_id {
GameId::Starfield => self.data.header_record.header().flags() & 0x200 != 0,
_ => false,
Expand Down Expand Up @@ -1998,7 +1998,7 @@ mod tests {
}

#[test]
fn is_light_plugin_should_be_true_for_plugins_with_an_esl_file_extension_if_the_override_flag_is_not_set(
fn is_light_plugin_should_be_true_for_plugins_with_an_esl_file_extension_if_the_update_flag_is_not_set(
) {
// The flag won't be set because no data is loaded.
let plugin = Plugin::new(GameId::Starfield, Path::new("Blank.esp"));
Expand All @@ -2010,7 +2010,7 @@ mod tests {
}

#[test]
fn is_light_plugin_should_be_false_for_a_plugin_with_the_override_flag_set_and_an_esl_extension(
fn is_light_plugin_should_be_false_for_a_plugin_with_the_update_flag_set_and_an_esl_extension(
) {
let tmp_dir = tempdir().unwrap();
let esl_path = tmp_dir.path().join("Blank.esl");
Expand Down Expand Up @@ -2089,20 +2089,19 @@ mod tests {
}

#[test]
fn is_override_plugin_should_be_true_for_a_plugin_with_the_override_flag_set_and_at_least_one_master_and_no_light_flag(
fn is_update_plugin_should_be_true_for_a_plugin_with_the_update_flag_set_and_at_least_one_master_and_no_light_flag(
) {
let mut plugin = Plugin::new(
GameId::Starfield,
Path::new("testing-plugins/Starfield/Data/Blank - Override.full.esm"),
);
plugin.parse_file(true).unwrap();

assert!(plugin.is_override_plugin());
assert!(plugin.is_update_plugin());
}

#[test]
fn is_override_plugin_should_be_false_for_a_plugin_with_the_override_flag_set_and_no_masters(
) {
fn is_update_plugin_should_be_false_for_a_plugin_with_the_update_flag_set_and_no_masters() {
let mut plugin = Plugin::new(GameId::Starfield, Path::new("Blank.esm"));
let file_data = &[
0x54, 0x45, 0x53, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
Expand All @@ -2112,30 +2111,29 @@ mod tests {
.unwrap()
.1;

assert!(!plugin.is_override_plugin());
assert!(!plugin.is_update_plugin());
}

#[test]
fn is_override_plugin_should_be_false_for_a_plugin_with_the_override_and_light_flags_set() {
fn is_update_plugin_should_be_false_for_a_plugin_with_the_update_and_light_flags_set() {
let mut plugin = Plugin::new(
GameId::Starfield,
Path::new("testing-plugins/Starfield/Data/Blank - Override.small.esm"),
);
plugin.parse_file(true).unwrap();

assert!(!plugin.is_override_plugin());
assert!(!plugin.is_update_plugin());
}

#[test]
fn is_override_plugin_should_be_false_for_a_plugin_with_the_override_and_medium_flags_set()
{
fn is_update_plugin_should_be_false_for_a_plugin_with_the_update_and_medium_flags_set() {
let mut plugin = Plugin::new(
GameId::Starfield,
Path::new("testing-plugins/Starfield/Data/Blank - Override.medium.esm"),
);
plugin.parse_file(true).unwrap();

assert!(!plugin.is_override_plugin());
assert!(!plugin.is_update_plugin());
}

#[test]
Expand Down Expand Up @@ -2382,21 +2380,21 @@ mod tests {
}

#[test]
fn is_valid_as_override_plugin_should_be_false_if_form_ids_are_unresolved() {
fn is_valid_as_update_plugin_should_be_false_if_form_ids_are_unresolved() {
let mut plugin = Plugin::new(
GameId::Starfield,
Path::new("testing-plugins/Starfield/Data/Blank - Override.esp"),
);
assert!(plugin.parse_file(false).is_ok());

match plugin.is_valid_as_override_plugin().unwrap_err() {
match plugin.is_valid_as_update_plugin().unwrap_err() {
Error::UnresolvedFormIds(path) => assert_eq!(plugin.path, path),
_ => panic!("Expected unresolved FormIDs error"),
}
}

#[test]
fn is_valid_as_override_plugin_should_be_true_if_the_plugin_has_no_new_records() {
fn is_valid_as_update_plugin_should_be_true_if_the_plugin_has_no_new_records() {
let master_metadata = PluginMetadata {
filename: "Blank.full.esm".to_string(),
scale: PluginScale::Full,
Expand All @@ -2408,11 +2406,11 @@ mod tests {
assert!(plugin.parse_file(false).is_ok());
assert!(plugin.resolve_record_ids(&[master_metadata]).is_ok());

assert!(plugin.is_valid_as_override_plugin().unwrap());
assert!(plugin.is_valid_as_update_plugin().unwrap());
}

#[test]
fn is_valid_as_override_plugin_should_be_false_if_the_plugin_has_new_records() {
fn is_valid_as_update_plugin_should_be_false_if_the_plugin_has_new_records() {
let master_metadata = PluginMetadata {
filename: "Blank.full.esm".to_string(),
scale: PluginScale::Full,
Expand All @@ -2424,7 +2422,7 @@ mod tests {
assert!(plugin.parse_file(false).is_ok());
assert!(plugin.resolve_record_ids(&[master_metadata]).is_ok());

assert!(!plugin.is_valid_as_override_plugin().unwrap());
assert!(!plugin.is_valid_as_update_plugin().unwrap());
}

#[test]
Expand Down

0 comments on commit 3b5db1a

Please sign in to comment.