Skip to content

Commit

Permalink
Add support for Starfield's medium flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Ortham committed Jun 12, 2024
1 parent 8e3138b commit 39f8752
Showing 1 changed file with 107 additions and 0 deletions.
107 changes: 107 additions & 0 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ impl Plugin {
}
}

pub fn is_medium_plugin(&self) -> bool {
self.is_medium_flag_set()
}

pub fn is_override_plugin(&self) -> bool {
// The override flag is unset by the game if the plugin has no masters or
// if the plugin's light flag is set.
Expand Down Expand Up @@ -398,6 +402,15 @@ impl Plugin {
self.data.header_record.header().flags() & flag != 0
}

fn is_medium_flag_set(&self) -> bool {
let flag = match self.game_id {
GameId::Starfield => 0x10000,
_ => return false,
};

self.data.header_record.header().flags() & flag != 0
}

fn is_override_flag_set(&self) -> bool {
match self.game_id {
GameId::Starfield => self.data.header_record.header().flags() & 0x200 != 0,
Expand Down Expand Up @@ -756,6 +769,16 @@ mod tests {
assert!(!plugin.is_light_plugin());
}

#[test]
fn is_medium_plugin_should_be_false() {
let plugin = Plugin::new(GameId::Morrowind, Path::new("Blank.esp"));
assert!(!plugin.is_medium_plugin());
let plugin = Plugin::new(GameId::Morrowind, Path::new("Blank.esm"));
assert!(!plugin.is_medium_plugin());
let plugin = Plugin::new(GameId::Morrowind, Path::new("Blank.esl"));
assert!(!plugin.is_medium_plugin());
}

#[test]
fn description_should_return_plugin_header_hedr_subrecord_content() {
let mut plugin = Plugin::new(
Expand Down Expand Up @@ -954,6 +977,16 @@ mod tests {
assert!(!plugin.is_light_plugin());
}

#[test]
fn is_medium_plugin_should_be_false() {
let plugin = Plugin::new(GameId::Morrowind, Path::new("Blank.esp"));
assert!(!plugin.is_medium_plugin());
let plugin = Plugin::new(GameId::Morrowind, Path::new("Blank.esm"));
assert!(!plugin.is_medium_plugin());
let plugin = Plugin::new(GameId::Morrowind, Path::new("Blank.esl"));
assert!(!plugin.is_medium_plugin());
}

#[test]
fn header_version_should_return_plugin_header_hedr_subrecord_field() {
let mut plugin = Plugin::new(
Expand Down Expand Up @@ -1059,6 +1092,16 @@ mod tests {
assert!(!plugin.is_light_plugin());
}

#[test]
fn is_medium_plugin_should_be_false() {
let plugin = Plugin::new(GameId::Morrowind, Path::new("Blank.esp"));
assert!(!plugin.is_medium_plugin());
let plugin = Plugin::new(GameId::Morrowind, Path::new("Blank.esm"));
assert!(!plugin.is_medium_plugin());
let plugin = Plugin::new(GameId::Morrowind, Path::new("Blank.esl"));
assert!(!plugin.is_medium_plugin());
}

#[test]
fn description_should_return_plugin_description_field_content() {
let mut plugin = Plugin::new(
Expand Down Expand Up @@ -1335,6 +1378,16 @@ mod tests {
assert!(plugin.is_master_file());
}

#[test]
fn is_medium_plugin_should_be_false() {
let plugin = Plugin::new(GameId::Morrowind, Path::new("Blank.esp"));
assert!(!plugin.is_medium_plugin());
let plugin = Plugin::new(GameId::Morrowind, Path::new("Blank.esm"));
assert!(!plugin.is_medium_plugin());
let plugin = Plugin::new(GameId::Morrowind, Path::new("Blank.esl"));
assert!(!plugin.is_medium_plugin());
}

#[test]
fn header_version_should_return_plugin_header_hedr_subrecord_field() {
let mut plugin = Plugin::new(
Expand Down Expand Up @@ -1448,6 +1501,16 @@ mod tests {
assert!(!plugin.is_light_plugin());
}

#[test]
fn is_medium_plugin_should_be_false() {
let plugin = Plugin::new(GameId::Morrowind, Path::new("Blank.esp"));
assert!(!plugin.is_medium_plugin());
let plugin = Plugin::new(GameId::Morrowind, Path::new("Blank.esm"));
assert!(!plugin.is_medium_plugin());
let plugin = Plugin::new(GameId::Morrowind, Path::new("Blank.esl"));
assert!(!plugin.is_medium_plugin());
}

#[test]
fn valid_light_form_id_range_should_be_empty() {
let mut plugin = Plugin::new(
Expand Down Expand Up @@ -1485,6 +1548,16 @@ mod tests {
assert!(!plugin.is_light_plugin());
}

#[test]
fn is_medium_plugin_should_be_false() {
let plugin = Plugin::new(GameId::Morrowind, Path::new("Blank.esp"));
assert!(!plugin.is_medium_plugin());
let plugin = Plugin::new(GameId::Morrowind, Path::new("Blank.esm"));
assert!(!plugin.is_medium_plugin());
let plugin = Plugin::new(GameId::Morrowind, Path::new("Blank.esl"));
assert!(!plugin.is_medium_plugin());
}

#[test]
fn valid_light_form_id_range_should_be_empty() {
let mut plugin = Plugin::new(
Expand Down Expand Up @@ -1563,6 +1636,16 @@ mod tests {
assert!(plugin.is_light_plugin());
}

#[test]
fn is_medium_plugin_should_be_false() {
let plugin = Plugin::new(GameId::Morrowind, Path::new("Blank.esp"));
assert!(!plugin.is_medium_plugin());
let plugin = Plugin::new(GameId::Morrowind, Path::new("Blank.esm"));
assert!(!plugin.is_medium_plugin());
let plugin = Plugin::new(GameId::Morrowind, Path::new("Blank.esl"));
assert!(!plugin.is_medium_plugin());
}

#[test]
fn valid_light_form_id_range_should_be_1_to_0xfff_if_hedr_version_is_less_than_1() {
let mut plugin = Plugin::new(
Expand Down Expand Up @@ -1695,6 +1778,30 @@ mod tests {
assert!(plugin.is_light_plugin());
}

#[test]
fn is_medium_plugin_should_be_false_for_a_plugin_without_the_medium_flag_set() {
let plugin = Plugin::new(GameId::Morrowind, Path::new("Blank.esp"));
assert!(!plugin.is_medium_plugin());
let plugin = Plugin::new(GameId::Morrowind, Path::new("Blank.esm"));
assert!(!plugin.is_medium_plugin());
let plugin = Plugin::new(GameId::Morrowind, Path::new("Blank.esl"));
assert!(!plugin.is_medium_plugin());
}

#[test]
fn is_medium_plugin_should_be_true_for_a_plugin_with_the_medium_flag_set() {
let mut plugin = Plugin::new(GameId::Starfield, Path::new("Blank.esm"));
let file_data = &[
0x54, 0x45, 0x53, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0xB2, 0x2E, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
];
plugin.data.header_record = Record::parse(file_data, GameId::Starfield, false)
.unwrap()
.1;

assert!(plugin.is_medium_plugin());
}

#[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(
) {
Expand Down

0 comments on commit 39f8752

Please sign in to comment.