Skip to content

Commit

Permalink
exclude reference to unique game types
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzyhau committed Apr 27, 2024
1 parent 72bdb10 commit bbfa0a0
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Stripper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ public static void Strip(ModuleDefinition module)
{
StripType(type);
}

RemoveUncommonTypes(module, new[]{
"FezGame.Components.MockAchievement",
"FezGame.Services.MockUser",
});
}

private static void StripType(TypeDefinition type)
Expand All @@ -33,5 +38,31 @@ private static void RemoveMethodBodiesFromType(TypeDefinition type)
}
}
}

private static void RemoveUncommonTypes(ModuleDefinition module, string[] namesOfTypesToRemove)
{
foreach(var type in module.Types)
{
// clean content of types that should be removed,
// so they're not used to generate hooks
if (namesOfTypesToRemove.Contains(type.FullName))
{
type.Methods.Clear();
}

// Some methods will still reference them.
// Make sure they're removed as well.
var methodsToRemove = type.Methods.Where(
method => method.Parameters.Any(
parameter => namesOfTypesToRemove.Contains(parameter.ParameterType.FullName)
)
).ToList();

foreach(var method in methodsToRemove)
{
type.Methods.Remove(method);
}
}
}
}
}

0 comments on commit bbfa0a0

Please sign in to comment.