2021-04-08 20:09:59 +08:00
|
|
|
|
using ET;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
2021-04-20 00:25:04 +08:00
|
|
|
|
|
|
|
|
|
#if UNITY
|
2021-04-08 20:09:59 +08:00
|
|
|
|
using UnityEngine;
|
2021-04-20 00:25:04 +08:00
|
|
|
|
#endif
|
2021-04-08 20:09:59 +08:00
|
|
|
|
|
|
|
|
|
namespace ET
|
|
|
|
|
{
|
|
|
|
|
public sealed class Hotfix : Object
|
|
|
|
|
{
|
|
|
|
|
private static Hotfix _instance;
|
|
|
|
|
public static Hotfix instance => _instance = _instance ?? new Hotfix();
|
|
|
|
|
#if ILRuntime
|
|
|
|
|
private ILRuntime.Runtime.Enviorment.AppDomain appDomain;
|
|
|
|
|
private MemoryStream dllStream;
|
|
|
|
|
private MemoryStream pdbStream;
|
|
|
|
|
#else
|
|
|
|
|
private Assembly assembly;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
private IStaticMethod start;
|
|
|
|
|
private List<Type> hotfixTypes;
|
|
|
|
|
|
|
|
|
|
public Assembly hotfix;
|
|
|
|
|
public Assembly hotfixView;
|
|
|
|
|
|
|
|
|
|
//public Action Update;
|
|
|
|
|
//public Action LateUpdate;
|
|
|
|
|
//public Action OnApplicationQuit;
|
|
|
|
|
|
|
|
|
|
public void GotoHotfix()
|
|
|
|
|
{
|
|
|
|
|
Log.Info($"开始加载热更逻辑");
|
|
|
|
|
Log.Info($"{start}");
|
|
|
|
|
this.start.Run();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Type> GetHotfixTypes()
|
|
|
|
|
{
|
|
|
|
|
return this.hotfixTypes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async ETTask LoadHotfixAssembly()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2021-04-20 00:25:04 +08:00
|
|
|
|
#if UNITY
|
2021-04-08 20:09:59 +08:00
|
|
|
|
byte[] assBytes = (await ResourceHelper.LoadAssetAsync<TextAsset>(PathHelper.HotfixDll)).bytes;
|
|
|
|
|
byte[] pdbBytes = (await ResourceHelper.LoadAssetAsync<TextAsset>(PathHelper.HotfixPdb)).bytes;
|
|
|
|
|
byte[] assViewBytes = (await ResourceHelper.LoadAssetAsync<TextAsset>(PathHelper.HotfixViewDll)).bytes;
|
2021-04-20 00:25:04 +08:00
|
|
|
|
byte[] pdbViewBytes = (await ResourceHelper.LoadAssetAsync<TextAsset>(PathHelper.HotfixViewPdb)).bytes;
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (!Define.IsEditorMode)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
string key = GameKeyComponent.Instance.key;
|
|
|
|
|
string keyIV = GameKeyComponent.Instance.keyIV;
|
2021-04-08 20:09:59 +08:00
|
|
|
|
assBytes = Utility.Encryption.AesCBCDecrypt(assBytes,key ,keyIV);
|
|
|
|
|
pdbBytes = Utility.Encryption.AesCBCDecrypt(pdbBytes, key,keyIV);
|
|
|
|
|
assViewBytes = Utility.Encryption.AesCBCDecrypt(assViewBytes,key ,keyIV);
|
|
|
|
|
pdbViewBytes = Utility.Encryption.AesCBCDecrypt(pdbViewBytes, key,keyIV);
|
|
|
|
|
}
|
2021-04-20 00:25:04 +08:00
|
|
|
|
#else
|
|
|
|
|
byte[] assBytes = null;
|
|
|
|
|
byte[] pdbBytes = null;
|
|
|
|
|
byte[] assViewBytes = null;
|
|
|
|
|
byte[] pdbViewBytes = null;
|
|
|
|
|
#endif
|
2021-04-08 20:09:59 +08:00
|
|
|
|
hotfix = Assembly.Load(assBytes, pdbBytes);
|
|
|
|
|
|
|
|
|
|
Type hotfixInit = hotfix.GetType("ET.InitHotfix");
|
|
|
|
|
this.start = new MonoStaticMethod(hotfixInit, "Start");
|
|
|
|
|
//this.hotfixTypes = assembly.GetTypes().ToList();
|
|
|
|
|
|
|
|
|
|
hotfixView = Assembly.Load(assViewBytes, pdbViewBytes);
|
|
|
|
|
//this.hotfixTypes.AddRange(viewAssembly.GetTypes());
|
2022-01-22 20:06:58 +08:00
|
|
|
|
|
|
|
|
|
|
2021-04-08 20:09:59 +08:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|