Skip to content

Commit

Permalink
Move reflection method outside of loop
Browse files Browse the repository at this point in the history
  • Loading branch information
cheese3660 committed Dec 21, 2023
1 parent 612ac57 commit 2f9458e
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/SpaceWarp.Core/Patching/PartOwnerComponentOnFixedUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,20 @@ private static bool PerformBackgroundCalculationsForRegisteredModules(double uni
PartOwnerComponent __instance)
{
var isModulePresent = false;
var hasPartModuleMethod = __instance.GetType().GetMethod("HasPartModule");

// Go through each registered module and check if it's present in PartOwnerComponent modules
foreach (var moduleType in PartComponentModuleOverride.RegisteredPartComponentOverrides)
if (hasPartModuleMethod != null)
{
var hasPartModuleMethod = __instance.GetType().GetMethod("HasPartModule");

if (hasPartModuleMethod != null)
// Go through each registered module and check if it's present in PartOwnerComponent modules
foreach (var moduleType in PartComponentModuleOverride.RegisteredPartComponentOverrides)
{
var genericMethod = hasPartModuleMethod.MakeGenericMethod(moduleType);
var genericMethod = hasPartModuleMethod.MakeGenericMethod(moduleType);

if ((bool)genericMethod.Invoke(__instance, null))
{
isModulePresent = true;
break;
}
if ((bool)genericMethod.Invoke(__instance, null))
{
isModulePresent = true;
break;
}
}
}

Expand Down

0 comments on commit 2f9458e

Please sign in to comment.