Skip to content

Commit

Permalink
Support comparing Starfield FormIDs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ortham committed Jun 21, 2024
1 parent 73c24e6 commit 156cdd8
Show file tree
Hide file tree
Showing 10 changed files with 1,152 additions and 271 deletions.
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ coveralls = { repository = "Ortham/esplugin" }
encoding_rs = "0.8.17"
nom = "7.0.0"
flate2 = { version = "1.0.1", optional = true }
unicase = "2.7.0"

[dev-dependencies]
criterion = "0.5.1"
Expand Down
4 changes: 2 additions & 2 deletions benches/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn criterion_benchmark(c: &mut Criterion) {
assert!(plugin.parse_file(false).is_ok());

b.iter(|| {
assert!(plugin.overlaps_with(&plugin));
assert!(plugin.overlaps_with(&plugin).unwrap());
});
});

Expand All @@ -43,7 +43,7 @@ fn criterion_benchmark(c: &mut Criterion) {
assert!(plugin.parse_file(false).is_ok());

b.iter(|| {
assert_eq!(plugin.count_override_records(), 1272);
assert_eq!(plugin.count_override_records().unwrap(), 1272);
});
});
}
Expand Down
6 changes: 6 additions & 0 deletions ffi/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ pub static ESP_ERROR_FILE_NOT_FOUND: u32 = 10;
#[no_mangle]
pub static ESP_ERROR_IO_PERMISSION_DENIED: u32 = 11;

#[no_mangle]
pub static ESP_ERROR_UNRESOLVED_FORM_IDS: u32 = 12;

#[no_mangle]
pub static ESP_ERROR_PLUGIN_METADATA_NOT_FOUND: u32 = 13;

#[no_mangle]
pub static ESP_GAME_OBLIVION: u32 = 0;

Expand Down
2 changes: 2 additions & 0 deletions ffi/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,7 @@ fn map_error(err: &Error) -> c_uint {
Error::ParsingIncomplete(_) => ESP_ERROR_PARSE_ERROR,
Error::ParsingError(_, _) => ESP_ERROR_PARSE_ERROR,
Error::DecodeError(_) => ESP_ERROR_TEXT_DECODE_ERROR,
Error::UnresolvedFormIds(_) => ESP_ERROR_UNRESOLVED_FORM_IDS,
Error::PluginMetadataNotFound(_) => ESP_ERROR_PLUGIN_METADATA_NOT_FOUND,
}
}
45 changes: 32 additions & 13 deletions ffi/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,13 @@ pub unsafe extern "C" fn esp_plugin_count_override_records(
} else {
let plugin = &*plugin_ptr;

*count = plugin.count_override_records();

ESP_OK
match plugin.count_override_records() {
Ok(c) => {
*count = c;
ESP_OK
}
Err(e) => handle_error(e),
}
}
})
.unwrap_or(ESP_ERROR_PANICKED)
Expand All @@ -403,9 +407,13 @@ pub unsafe extern "C" fn esp_plugin_do_records_overlap(
let plugin = &*plugin_ptr;
let other_plugin = &*other_plugin_ptr;

*overlap = plugin.overlaps_with(other_plugin);

ESP_OK
match plugin.overlaps_with(other_plugin) {
Ok(x) => {
*overlap = x;
ESP_OK
}
Err(e) => handle_error(e),
}
}
})
.unwrap_or(ESP_ERROR_PANICKED)
Expand All @@ -430,7 +438,10 @@ pub unsafe extern "C" fn esp_plugin_records_overlap_size(
.collect();

if let Some(other_plugins) = other_plugins {
*overlap_size = plugin.overlap_size(&other_plugins);
*overlap_size = match plugin.overlap_size(&other_plugins) {
Ok(x) => x,
Err(e) => return handle_error(e),
}
} else {
*overlap_size = 0;
}
Expand Down Expand Up @@ -461,9 +472,13 @@ pub unsafe extern "C" fn esp_plugin_is_valid_as_light_plugin(
} else {
let plugin = &*plugin_ptr;

*is_valid = plugin.is_valid_as_light_plugin();

ESP_OK
match plugin.is_valid_as_light_plugin() {
Ok(x) => {
*is_valid = x;
ESP_OK
}
Err(e) => handle_error(e),
}
}
})
.unwrap_or(ESP_ERROR_PANICKED)
Expand All @@ -480,9 +495,13 @@ pub unsafe extern "C" fn esp_plugin_is_valid_as_override_plugin(
} else {
let plugin = &*plugin_ptr;

*is_valid = plugin.is_valid_as_override_plugin();

ESP_OK
match plugin.is_valid_as_override_plugin() {
Ok(x) => {
*is_valid = x;
ESP_OK
}
Err(e) => handle_error(e),
}
}
})
.unwrap_or(ESP_ERROR_PANICKED)
Expand Down
4 changes: 4 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ pub enum Error {
ParsingIncomplete(MoreDataNeeded),
ParsingError(Vec<u8>, ParsingErrorKind),
DecodeError(Vec<u8>),
UnresolvedFormIds(PathBuf),
PluginMetadataNotFound(String),
}

impl From<Err<nom::error::Error<&[u8]>>> for Error {
Expand Down Expand Up @@ -73,6 +75,8 @@ impl fmt::Display for Error {
f,
"Plugin string content could not be decoded from Windows-1252, bytes are {bytes:02X?}"
),
Error::UnresolvedFormIds(path) => write!(f, "FormIDs are unresolved for plugin at {path:?}"),
Error::PluginMetadataNotFound(plugin) => write!(f, "Plugin metadata for \"{plugin}\" not found")
}
}
}
Expand Down
Loading

0 comments on commit 156cdd8

Please sign in to comment.