Last active
January 19, 2018 08:00
-
-
Save samizzo/9161cb157aea9c15c930a0f4a555e580 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[PostProcessBuild] | |
public static void OnPostProcessBuild(BuildTarget buildTarget, string pathToBuildProject) | |
{ | |
if (buildTarget != BuildTarget.iOS) | |
return; | |
StripMethods(pathToBuiltProject); | |
} | |
private static string[] s_stripList = | |
{ | |
// Strip some unused Unity methods. | |
"UnityWebRequest_", | |
"Collision_", | |
"Collision2D_", | |
"Physics_", | |
"Physics2D_", | |
// Strip some unused .NET class library methods. | |
"FtpWebRequest_", | |
"FtpWebResponse_", | |
"FileWebRequest_" | |
"X509", | |
"BigInteger_" | |
}; | |
private static void StripMethods(string pathToBuiltProject) | |
{ | |
var methodPointerTable = Path.Combine(pathToBuiltProject, | |
"Classes/Native/Il2CppMethodPointerTable.cpp"); | |
var lines = File.ReadAllLines(methodPointerTable); | |
var inMethodPointerTable = false; | |
for (var i = 0; i < lines.Length; i++) | |
{ | |
var line = lines[i]; | |
if (line.StartsWith("extern const Il2CppMethodPointer g_MethodPointers")) | |
{ | |
inMethodPointerTable = true; | |
// Skip the opening brace. | |
i++; | |
} | |
else if (inMethodPointerTable) | |
{ | |
if (line.StartsWith("};")) | |
{ | |
// Finished parsing the method pointer table! | |
inMethodPointerTable = false; | |
} | |
else | |
{ | |
lines[i] = PatchLine(line); | |
} | |
} | |
} | |
File.WriteAllLines(methodPointerTable, lines); | |
} | |
private static string PatchLine(string line) | |
{ | |
var trimmed = line.Trim(); | |
foreach (var s in s_stripList) | |
{ | |
if (trimmed.StartsWith(s)) | |
{ | |
line = "\t0, //" + line; | |
return line; | |
} | |
} | |
return line; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment