Skip to content

Commit

Permalink
Add esp_plugin_is_valid_as_medium_plugin()
Browse files Browse the repository at this point in the history
  • Loading branch information
Ortham committed Jun 21, 2024
1 parent 156cdd8 commit 0253df8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
24 changes: 24 additions & 0 deletions ffi/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,30 @@ pub unsafe extern "C" fn esp_plugin_is_valid_as_light_plugin(
.unwrap_or(ESP_ERROR_PANICKED)
}

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

match plugin.is_valid_as_medium_plugin() {
Ok(x) => {
*is_valid = x;
ESP_OK
}
Err(e) => handle_error(e),
}
}
})
.unwrap_or(ESP_ERROR_PANICKED)
}


#[no_mangle]
pub unsafe extern "C" fn esp_plugin_is_valid_as_override_plugin(
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 @@ -311,6 +311,23 @@ void test_esp_plugin_is_valid_as_light_plugin() {
esp_plugin_free(plugin);
}

void test_esp_plugin_is_valid_as_medium_plugin() {
printf("testing esp_plugin_is_valid_as_medium_plugin()...\n");
Plugin * plugin;
auto return_code = esp_plugin_new(&plugin, ESP_GAME_STARFIELD, "../../testing-plugins/Starfield/Data/Blank.medium.esm");
assert(return_code == ESP_OK);

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

bool is_valid;
return_code = esp_plugin_is_valid_as_medium_plugin(plugin, &is_valid);
assert(return_code == ESP_OK);
assert(is_valid);

esp_plugin_free(plugin);
}

void test_esp_plugin_is_valid_as_override_plugin() {
printf("testing esp_plugin_is_valid_as_override_plugin()...\n");
Plugin * plugin;
Expand Down Expand Up @@ -349,6 +366,7 @@ int main() {
test_esp_plugin_records_overlap_size();
test_esp_plugin_is_valid_as_light_master();
test_esp_plugin_is_valid_as_light_plugin();
test_esp_plugin_is_valid_as_medium_plugin();
test_esp_plugin_is_valid_as_override_plugin();

printf("SUCCESS\n");
Expand Down

0 comments on commit 0253df8

Please sign in to comment.