@@ -2447,6 +2447,7 @@ recomp::mods::CodeModLoadError recomp::mods::ModContext::resolve_code_dependenci
24472447 GenericFunction func = mod.code_handle ->get_function_handle (callback.function_index );
24482448 size_t event_index = 0 ;
24492449 bool did_find_event = false ;
2450+ bool optional = false ;
24502451
24512452 if (dependency_id == N64Recomp::DependencyBaseRecomp) {
24522453 event_index = recomp::overlays::get_base_event_index (dependency_event.event_name );
@@ -2458,23 +2459,40 @@ recomp::mods::CodeModLoadError recomp::mods::ModContext::resolve_code_dependenci
24582459 did_find_event = mod.get_global_event_index (dependency_event.event_name , event_index);
24592460 }
24602461 else {
2462+ // Check if the dependency is optional.
24612463 auto find_mod_it = loaded_mods_by_id.find (dependency_id);
24622464 if (find_mod_it == loaded_mods_by_id.end ()) {
2463- error_param = " Failed to find callback dependency while loading code: " + dependency_id;
2464- // This should never happen, as dependencies are scanned before mod code is loaded and the symbol dependency list
2465- // is validated against the manifest's.
2466- return CodeModLoadError::InternalError;
2465+ // Get the manifest's version of the dependency.
2466+ auto find_manifest_dep = mod.manifest .dependencies_by_id .find (dependency_id);
2467+ // This should always be found, but just in case validate that the find was successful.
2468+ // This will get treated as an error if it wasn't found in the manifest.
2469+ if (find_manifest_dep != mod.manifest .dependencies_by_id .end ()) {
2470+ const auto & manifest_dep = mod.manifest .dependencies [find_manifest_dep->second ];
2471+ if (manifest_dep.optional ) {
2472+ optional = true ;
2473+ }
2474+ }
2475+
2476+ if (!optional) {
2477+ error_param = " Failed to find callback dependency while loading code: " + dependency_id;
2478+ // This should never happen, as dependencies are scanned before mod code is loaded and the symbol dependency list
2479+ // is validated against the manifest's.
2480+ return CodeModLoadError::InternalError;
2481+ }
2482+ }
2483+ else {
2484+ const auto & dependency_mod = opened_mods[find_mod_it->second ];
2485+ did_find_event = dependency_mod.get_global_event_index (dependency_event.event_name , event_index);
24672486 }
2468- const auto & dependency_mod = opened_mods[find_mod_it->second ];
2469- did_find_event = dependency_mod.get_global_event_index (dependency_event.event_name , event_index);
24702487 }
24712488
2472- if (!did_find_event) {
2489+ if (did_find_event) {
2490+ recomp::mods::register_event_callback (event_index, mod_index, func);
2491+ }
2492+ else if (!optional) {
24732493 error_param = dependency_id + " :" + dependency_event.event_name ;
24742494 return CodeModLoadError::InvalidCallbackEvent;
24752495 }
2476-
2477- recomp::mods::register_event_callback (event_index, mod_index, func);
24782496 }
24792497
24802498 // Register hooks.
0 commit comments