-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStripper.cs
More file actions
69 lines (61 loc) · 2.05 KB
/
Copy pathStripper.cs
File metadata and controls
69 lines (61 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using Mono.Cecil;
using Mono.Cecil.Cil;
namespace FEZStripGen
{
internal static class Stripper
{
public static void Strip(ModuleDefinition module)
{
foreach (var type in module.Types)
{
StripType(type);
}
RemoveUncommonTypes(module, new[]{
"FezGame.Components.MockAchievement",
"FezGame.Services.MockUser",
"FezGame.Tools.ErrorDialog",
});
}
private static void StripType(TypeDefinition type)
{
RemoveMethodBodiesFromType(type);
foreach (TypeDefinition nested in type.NestedTypes)
{
StripType(nested);
}
}
private static void RemoveMethodBodiesFromType(TypeDefinition type)
{
foreach (MethodDefinition method in type.Methods)
{
if (method.HasBody && method.Body.Instructions.Count != 0)
{
method.Body = new MethodBody(method);
}
}
}
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);
}
}
}
}
}