Skip to content

Commit

Permalink
Add esp_plugin_record_and_group_count() FFI function
Browse files Browse the repository at this point in the history
It'll be used instead of esp_plugin_count_override_records() to get the
record count used during sorting Morrowind load orders, since esplugin
can't count override records for Morrowind plugins.
  • Loading branch information
Ortham committed Aug 30, 2019
1 parent 149ff8a commit 07f6102
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
19 changes: 19 additions & 0 deletions ffi/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,25 @@ pub unsafe extern "C" fn esp_plugin_is_empty(
.unwrap_or(ESP_ERROR_PANICKED)
}

#[no_mangle]
pub unsafe extern "C" fn esp_plugin_record_and_group_count(
plugin_ptr: *const Plugin,
count: *mut u32,
) -> u32 {
panic::catch_unwind(|| {
if plugin_ptr.is_null() || count.is_null() {
ESP_ERROR_NULL_POINTER
} else {
let plugin = &*plugin_ptr;

*count = plugin.record_and_group_count().unwrap_or(0);

ESP_OK
}
})
.unwrap_or(ESP_ERROR_PANICKED)
}

#[no_mangle]
pub unsafe extern "C" fn esp_plugin_count_override_records(
plugin_ptr: *const Plugin,
Expand Down
18 changes: 18 additions & 0 deletions ffi/tests/ffi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,23 @@ void test_esp_plugin_is_empty() {
esp_plugin_free(plugin);
}

void test_esp_plugin_record_and_group_count() {
printf("testing esp_plugin_record_and_group_count()...\n");
Plugin * plugin;
auto return_code = esp_plugin_new(&plugin, ESP_GAME_SKYRIM, "../../testing-plugins/Skyrim/Data/Blank.esm");
assert(return_code == ESP_OK);

return_code = esp_plugin_parse(plugin, true);
assert(return_code == ESP_OK);

uint32_t count;
return_code = esp_plugin_record_and_group_count(plugin, &count);
assert(return_code == ESP_OK);
assert(count == 15);

esp_plugin_free(plugin);
}

void test_esp_plugin_count_override_records() {
printf("testing esp_plugin_count_override_records()...\n");
Plugin * plugin;
Expand Down Expand Up @@ -225,6 +242,7 @@ int main() {
test_esp_plugin_description();
test_esp_plugin_header_version();
test_esp_plugin_is_empty();
test_esp_plugin_record_and_group_count();
test_esp_plugin_count_override_records();
test_esp_plugin_do_records_overlap();
test_esp_plugin_is_valid_as_light_master();
Expand Down

0 comments on commit 07f6102

Please sign in to comment.