Skip to content

Commit 8ab91f7

Browse files
loonglyliuyunlong
authored andcommitted
* PureScriptBuilder
1 parent 482d619 commit 8ab91f7

1 file changed

Lines changed: 67 additions & 47 deletions

File tree

DemoProject/Assets/Plugins/PureScript/Editor/PureScriptBuilder.cs

Lines changed: 67 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ public static class PureScriptBuilder
1919
static string ScriptEngineDir = "../ScriptEngine";
2020
static bool Inbuild = false;
2121

22-
static MethodHooker stripHooker;
23-
static MethodHooker il2cppHooker;
22+
2423

2524
[UnityEditor.Callbacks.PostProcessScene]
2625
public static void AutoInjectAssemblys()
@@ -35,30 +34,16 @@ public static void AutoInjectAssemblys()
3534
InsertBuildTask();
3635
}
3736
}
38-
[MenuItem("PureScript/TestBuild", false, 1)]
39-
public static void TestBuild()
40-
{
41-
//RunBinder(null, null, null, Application.dataPath.Replace("Assets", Path.Combine("Library", "PlayerDataCache", "Managed")));
42-
}
4337

4438
/// <summary>
4539
/// bind adapter before strip.
4640
/// called by UnityEditor when AssemblyStripper.StripAssemblies.
4741
/// "replace assembly" after strip will trigger il2cpp.exe`s error.
4842
/// </summary>
4943
///
50-
51-
public static void RunBinderBeforeStrip(System.String managedAssemblyFolderPath, object unityLinkerPlatformProvider, object il2cppPlatformProvider, object rcr, UnityEditor.ManagedStrippingLevel managedStrippingLevel)
52-
//public static void RunBinderBeforeStrip(string managedAssemblyFolderPath, object platformProvider, object rcr, ManagedStrippingLevel managedStrippingLevel)
44+
public static void RunBinderBeforeStrip(System.String managedAssemblyFolderPath)
5345
{
54-
if (stripHooker != null)
55-
{
56-
stripHooker.Dispose();
57-
stripHooker = null;
58-
}
5946
Inbuild = false;
60-
61-
6247
var managedPath = Path.Combine(ScriptEngineDir, "Managed");
6348

6449
//copy all assemblys
@@ -75,23 +60,14 @@ public static void RunBinderBeforeStrip(System.String managedAssemblyFolderPath,
7560
File.Copy(generatedAdapter, adapterGenPath, true);
7661
File.Delete(generatedAdapter);
7762
}
78-
79-
// call the realy method
80-
//StripAssemblies(managedAssemblyFolderPath, platformProvider, rcr, managedStrippingLevel);
81-
StripAssemblies(managedAssemblyFolderPath, unityLinkerPlatformProvider, il2cppPlatformProvider, rcr, managedStrippingLevel);
8263
}
8364

8465
/// <summary>
8566
/// resolve all bind task after strip.
8667
/// called by UnityEditor when IL2CPPBuilder.RunIl2CppWithArguments.
8768
/// </summary>
88-
public static void RunBinderBeforeIl2cpp(object obj, List<string> arguments, Action<System.Diagnostics.ProcessStartInfo> setupStartInfo, string workingDirectory)
69+
public static void RunBinderBeforeIl2cpp(string workingDirectory)
8970
{
90-
if (il2cppHooker != null)
91-
{
92-
il2cppHooker.Dispose();
93-
il2cppHooker = null;
94-
}
9571
Inbuild = false;
9672

9773
//copy all striped assemblys
@@ -100,10 +76,6 @@ public static void RunBinderBeforeIl2cpp(object obj, List<string> arguments, Act
10076

10177
// call binder,bind icall and adapter
10278
CallBinder("All");
103-
104-
// call the realy method
105-
if (obj != null)
106-
RunIl2CppWithArguments(obj, arguments, setupStartInfo, workingDirectory);
10779
}
10880

10981
public static void CallBinder(string mode)
@@ -192,15 +164,69 @@ static string NiceWinPath(string unityPath)
192164
return Application.platform == RuntimePlatform.WindowsEditor ? unityPath.Replace("/", @"\") : unityPath;
193165
}
194166

195-
//redirect to IL2CPPBuilder.RunIl2CppWithArguments
167+
static void CreateOrCleanDirectory(string dir)
168+
{
169+
if (Directory.Exists(dir))
170+
Directory.Delete(dir, true);
171+
Directory.CreateDirectory(dir);
172+
}
173+
174+
175+
176+
#region InsertBuildTask
177+
178+
static MethodHooker stripHooker;
179+
static MethodHooker il2cppHooker;
180+
196181
public static void RunIl2CppWithArguments(object obj, List<string> arguments, Action<System.Diagnostics.ProcessStartInfo> setupStartInfo, string workingDirectory)
182+
{
183+
if (il2cppHooker != null)
184+
{
185+
il2cppHooker.Dispose();
186+
il2cppHooker = null;
187+
}
188+
189+
RunBinderBeforeIl2cpp(workingDirectory);
190+
191+
// call the realy method
192+
if (obj != null)
193+
RunIl2CppWithArgumentsWrap(obj, arguments, setupStartInfo, workingDirectory);
194+
}
195+
196+
//redirect to IL2CPPBuilder.RunIl2CppWithArguments
197+
public static void RunIl2CppWithArgumentsWrap(object obj, List<string> arguments, Action<System.Diagnostics.ProcessStartInfo> setupStartInfo, string workingDirectory)
197198
{
198199
throw new NotImplementedException();
199200
}
200201

202+
203+
#if UNITY_2019_1_OR_NEWER
204+
public static void StripAssemblies(string managedAssemblyFolderPath, object unityLinkerPlatformProvider, object il2cppPlatformProvider, object rcr, ManagedStrippingLevel managedStrippingLevel)
205+
#else
206+
public static void StripAssemblies(string managedAssemblyFolderPath, object platformProvider, object rcr, ManagedStrippingLevel managedStrippingLevel)
207+
#endif
208+
{
209+
if (stripHooker != null)
210+
{
211+
stripHooker.Dispose();
212+
stripHooker = null;
213+
}
214+
RunBinderBeforeStrip(managedAssemblyFolderPath);
215+
216+
// call the realy method
217+
#if UNITY_2019_1_OR_NEWER
218+
StripAssembliesWrap(managedAssemblyFolderPath, unityLinkerPlatformProvider, il2cppPlatformProvider, rcr, managedStrippingLevel);
219+
#else
220+
StripAssembliesWrap(managedAssemblyFolderPath, platformProvider, rcr, managedStrippingLevel);
221+
#endif
222+
}
223+
201224
//redirect to AssemblyStripper.StripAssemblies
202-
public static void StripAssemblies(System.String managedAssemblyFolderPath, object unityLinkerPlatformProvider, object il2cppPlatformProvider, object rcr, UnityEditor.ManagedStrippingLevel managedStrippingLevel)
203-
//public static void StripAssemblies(string managedAssemblyFolderPath, object platformProvider, object rcr, ManagedStrippingLevel managedStrippingLevel)
225+
#if UNITY_2019_1_OR_NEWER
226+
public static void StripAssembliesWrap(string managedAssemblyFolderPath, object unityLinkerPlatformProvider, object il2cppPlatformProvider, object rcr, ManagedStrippingLevel managedStrippingLevel)
227+
#else
228+
public static void StripAssembliesWrap(string managedAssemblyFolderPath, object platformProvider, object rcr, ManagedStrippingLevel managedStrippingLevel)
229+
#endif
204230
{
205231
throw new NotImplementedException();
206232
}
@@ -211,31 +237,25 @@ private static void InsertBuildTask()
211237
{
212238
var builderType = typeof(Editor).Assembly.GetType("UnityEditorInternal.AssemblyStripper");
213239
MethodBase orign = builderType.GetMethod("StripAssemblies", BindingFlags.Static | BindingFlags.NonPublic);
214-
MethodBase custom = typeof(PureScriptBuilder).GetMethod("RunBinderBeforeStrip");
215-
MethodBase wrap2Orign = typeof(PureScriptBuilder).GetMethod("StripAssemblies");
240+
MethodBase custom = typeof(PureScriptBuilder).GetMethod("StripAssemblies");
241+
MethodBase wrap2Orign = typeof(PureScriptBuilder).GetMethod("StripAssembliesWrap");
216242
stripHooker = new MethodHooker(orign, custom, wrap2Orign);
217243
}
218244

219245
if (il2cppHooker == null)
220246
{
221247
var builderType = typeof(Editor).Assembly.GetType("UnityEditorInternal.IL2CPPBuilder");
222248
MethodBase orign = builderType.GetMethod("RunIl2CppWithArguments", BindingFlags.Instance | BindingFlags.NonPublic);
223-
MethodBase custom = typeof(PureScriptBuilder).GetMethod("RunBinderBeforeIl2cpp");
224-
MethodBase wrap2Orign = typeof(PureScriptBuilder).GetMethod("RunIl2CppWithArguments");
249+
MethodBase custom = typeof(PureScriptBuilder).GetMethod("RunIl2CppWithArguments");
250+
MethodBase wrap2Orign = typeof(PureScriptBuilder).GetMethod("RunIl2CppWithArgumentsWrap");
225251
il2cppHooker = new MethodHooker(orign, custom, wrap2Orign);
226252
}
227253
}
254+
#endregion
228255

229256

230-
static void CreateOrCleanDirectory(string dir)
231-
{
232-
if (Directory.Exists(dir))
233-
Directory.Delete(dir, true);
234-
Directory.CreateDirectory(dir);
235-
}
236-
237257

238-
#region internal
258+
#region internal
239259

240260
private class MethodHooker : IDisposable
241261
{
@@ -328,5 +348,5 @@ private void RedirectMethod(IntPtr pBody, IntPtr pBorrowed,bool saveResume)
328348
}
329349
}
330350
}
331-
#endregion
351+
#endregion
332352
}

0 commit comments

Comments
 (0)