|
@@ -8,8 +8,11 @@ namespace Model
|
|
|
{
|
|
{
|
|
|
public sealed class Hotfix : Object
|
|
public sealed class Hotfix : Object
|
|
|
{
|
|
{
|
|
|
- public Assembly HotfixAssembly;
|
|
|
|
|
- public ILRuntime.Runtime.Enviorment.AppDomain AppDomain;
|
|
|
|
|
|
|
+#if ILRuntime
|
|
|
|
|
+ private ILRuntime.Runtime.Enviorment.AppDomain appDomain;
|
|
|
|
|
+#else
|
|
|
|
|
+ private Assembly assembly;
|
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
private IStaticMethod start;
|
|
private IStaticMethod start;
|
|
|
|
|
|
|
@@ -25,7 +28,7 @@ namespace Model
|
|
|
public void GotoHotfix()
|
|
public void GotoHotfix()
|
|
|
{
|
|
{
|
|
|
#if ILRuntime
|
|
#if ILRuntime
|
|
|
- ILHelper.InitILRuntime();
|
|
|
|
|
|
|
+ ILHelper.InitILRuntime(this.appDomain);
|
|
|
#endif
|
|
#endif
|
|
|
this.start.Run();
|
|
this.start.Run();
|
|
|
}
|
|
}
|
|
@@ -33,18 +36,18 @@ namespace Model
|
|
|
public Type[] GetHotfixTypes()
|
|
public Type[] GetHotfixTypes()
|
|
|
{
|
|
{
|
|
|
#if ILRuntime
|
|
#if ILRuntime
|
|
|
- if (this.AppDomain == null)
|
|
|
|
|
|
|
+ if (this.appDomain == null)
|
|
|
{
|
|
{
|
|
|
return new Type[0];
|
|
return new Type[0];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return this.AppDomain.LoadedTypes.Values.Select(x => x.ReflectionType).ToArray();
|
|
|
|
|
|
|
+ return this.appDomain.LoadedTypes.Values.Select(x => x.ReflectionType).ToArray();
|
|
|
#else
|
|
#else
|
|
|
- if (this.HotfixAssembly == null)
|
|
|
|
|
|
|
+ if (this.assembly == null)
|
|
|
{
|
|
{
|
|
|
return new Type[0];
|
|
return new Type[0];
|
|
|
}
|
|
}
|
|
|
- return this.HotfixAssembly.GetTypes();
|
|
|
|
|
|
|
+ return this.assembly.GetTypes();
|
|
|
#endif
|
|
#endif
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -53,7 +56,7 @@ namespace Model
|
|
|
{
|
|
{
|
|
|
Game.Scene.GetComponent<ResourcesComponent>().LoadBundle($"code.unity3d");
|
|
Game.Scene.GetComponent<ResourcesComponent>().LoadBundle($"code.unity3d");
|
|
|
#if ILRuntime
|
|
#if ILRuntime
|
|
|
- this.AppDomain = new ILRuntime.Runtime.Enviorment.AppDomain();
|
|
|
|
|
|
|
+ this.appDomain = new ILRuntime.Runtime.Enviorment.AppDomain();
|
|
|
GameObject code = Game.Scene.GetComponent<ResourcesComponent>().GetAsset<GameObject>("code.unity3d", "Code");
|
|
GameObject code = Game.Scene.GetComponent<ResourcesComponent>().GetAsset<GameObject>("code.unity3d", "Code");
|
|
|
byte[] assBytes = code.Get<TextAsset>("Hotfix.dll").bytes;
|
|
byte[] assBytes = code.Get<TextAsset>("Hotfix.dll").bytes;
|
|
|
byte[] mdbBytes = code.Get<TextAsset>("Hotfix.pdb").bytes;
|
|
byte[] mdbBytes = code.Get<TextAsset>("Hotfix.pdb").bytes;
|
|
@@ -61,18 +64,17 @@ namespace Model
|
|
|
using (MemoryStream fs = new MemoryStream(assBytes))
|
|
using (MemoryStream fs = new MemoryStream(assBytes))
|
|
|
using (MemoryStream p = new MemoryStream(mdbBytes))
|
|
using (MemoryStream p = new MemoryStream(mdbBytes))
|
|
|
{
|
|
{
|
|
|
- this.AppDomain.LoadAssembly(fs, p, new Mono.Cecil.Pdb.PdbReaderProvider());
|
|
|
|
|
|
|
+ this.appDomain.LoadAssembly(fs, p, new Mono.Cecil.Pdb.PdbReaderProvider());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- this.start = new ILStaticMethod(this.AppDomain, "Hotfix.Init", "Start", 0);
|
|
|
|
|
|
|
+ this.start = new ILStaticMethod(this.appDomain, "Hotfix.Init", "Start", 0);
|
|
|
#else
|
|
#else
|
|
|
GameObject code = Game.Scene.GetComponent<ResourcesComponent>().GetAsset<GameObject>("code.unity3d", "Code");
|
|
GameObject code = Game.Scene.GetComponent<ResourcesComponent>().GetAsset<GameObject>("code.unity3d", "Code");
|
|
|
byte[] assBytes = code.Get<TextAsset>("Hotfix.dll").bytes;
|
|
byte[] assBytes = code.Get<TextAsset>("Hotfix.dll").bytes;
|
|
|
byte[] mdbBytes = code.Get<TextAsset>("Hotfix.mdb").bytes;
|
|
byte[] mdbBytes = code.Get<TextAsset>("Hotfix.mdb").bytes;
|
|
|
- Assembly assembly = Assembly.Load(assBytes, mdbBytes);
|
|
|
|
|
- this.HotfixAssembly = assembly;
|
|
|
|
|
|
|
+ this.assembly = Assembly.Load(assBytes, mdbBytes);
|
|
|
|
|
|
|
|
- Type hotfixInit = this.HotfixAssembly.GetType("Hotfix.Init");
|
|
|
|
|
|
|
+ Type hotfixInit = this.assembly.GetType("Hotfix.Init");
|
|
|
this.start = new MonoStaticMethod(hotfixInit, "Start");
|
|
this.start = new MonoStaticMethod(hotfixInit, "Start");
|
|
|
#endif
|
|
#endif
|
|
|
Game.Scene.GetComponent<ResourcesComponent>().UnloadBundle($"code.unity3d");
|
|
Game.Scene.GetComponent<ResourcesComponent>().UnloadBundle($"code.unity3d");
|